15 from ROOT
import Belle2
16 import modularAnalysis
as ma
17 from array
import array
20 from heapq
import nlargest
21 from effCalculation
import EffCalculation
23 RadToDeg = 180.0 / math.pi
29 sys.exit(
"ztsim02.py> # of arg is strange. Exit.")
32 def Count_mcpart(parts):
37 pdglist = [11, 13, 2212, 321, 211]
38 pdg = math.fabs(part.getPDG())
39 theta = part.getMomentum().Theta() * RadToDeg
40 if theta > dec_cdc[0]
and theta < dec_cdc[1]:
44 if math.fabs(pdg) == 22:
45 if theta > dec_ecl[0]
and theta < dec_ecl[1]:
50 def Count_part_inDetector(parts):
54 charge = part.getCharge()
57 if math.fabs(charge) > 0:
59 elif math.fabs(pdg) == 22:
64 def Theta_MCTruth(part):
65 theta = part.getMomentum().Theta() * RadToDeg
69 def NeutralCluster(clusters):
71 for cluster
in clusters:
72 if cluster.getRelatedFrom(
'TRGNNTracks'):
75 neutral_cluster.append(cluster)
76 return neutral_cluster
79 def Vec_Cluster(cluster):
80 x = cluster.getPositionX()
81 y = cluster.getPositionY()
82 z = cluster.getPositionZ()
83 e = cluster.getEnergyDep()
84 vec = ROOT.TVector3(x, y, z)
85 v_mom = e * ROOT.Math.PxPyPzEVector(x / vec.Mag(), y / vec.Mag(), z / vec.Mag(), 1)
86 new_theta = v_mom.Theta() * RadToDeg
87 new_phi = v_mom.Phi() * RadToDeg
89 new_phi += 2 * math.pi
91 NVC = [new_e, new_theta, new_phi]
95 def Max_Cluster(neuclus, CMS, n):
97 for neuclu
in neuclus:
98 NV = Vec_Cluster(neuclu)
100 if E
and len(E) >= (n + 1):
101 seqen = nlargest(n + 1, E, key=
lambda item: item[0])
104 return [-1, -999, -999]
107 def Etot_Cluster(eclcluster):
109 for clu
in eclcluster:
110 e = clu.getEnergyDep()
115 def Max_DeltPhi_trk(trk_2d_list):
117 for i, trk
in enumerate(trk_2d_list):
118 phi1 = (trk.getPhi0()) * RadToDeg
119 for j, trk2
in enumerate(trk_2d_list):
123 phi2 = (trk2.getPhi0()) * RadToDeg
124 Delt_phi = math.fabs(phi1 - phi2)
125 Delt.append(Delt_phi)
126 return max(Delt
or [-100.0])
129 def BhabhaVeto1(matchtrks):
131 if len(matchtrks) <= 1:
133 for i, matchtrk1
in enumerate(matchtrks):
134 if i == len(matchtrks) - 1:
136 cdctrk1 = matchtrk1.getRelatedTo(
'TRGNNTracks')
137 cluster1 = matchtrk1.getRelatedTo(
'TRGECLClusters')
138 if cdctrk1
and cluster1:
139 tanLam1 = cdctrk1.getTanLambda()
140 theta1 = math.acos(tanLam1 / math.sqrt(1. + tanLam1 * tanLam1)) * RadToDeg
141 phi1 = (cdctrk1.getPhi0()) * RadToDeg
144 e1 = cluster1.getEnergyDep()
145 for j, matchtrk2
in enumerate(matchtrks):
149 cdctrk2 = matchtrk2.getRelatedTo(
'TRGNNTracks')
150 cluster2 = matchtrk2.getRelatedTo(
'TRGECLClusters')
151 if cdctrk2
and cluster2:
152 tanLam2 = cdctrk2.getTanLambda()
153 theta2 = math.acos(tanLam2 / math.sqrt(1. + tanLam2 * tanLam2)) * RadToDeg
154 phi2 = (cdctrk2.getPhi0()) * RadToDeg
157 e2 = cluster2.getEnergyDep()
158 Delt_theta = theta1 + theta2 - 180
159 Delt_phi = math.fabs(phi1 - phi2) - 180
160 DeltArray = [Delt_theta, Delt_phi, e1, e2, e1 + e2]
161 Delt.append(DeltArray)
165 return [-999., -999., -999., -999., -999]
168 def SBhabhaVeto(matchtrks):
170 if len(matchtrks) <= 1:
172 for i, matchtrk1
in enumerate(matchtrks):
173 cdctrk1 = matchtrk1.getRelatedTo(
'TRGNNTracks')
174 cluster1 = matchtrk1.getRelatedTo(
'TRGECLClusters')
175 if cdctrk1
and cluster1:
176 e1 = cluster1.getEnergyDep()
184 def eclBhabhaVeto(eclclusters):
186 for i, cluster1
in enumerate(eclclusters):
187 if i == len(eclclusters) - 1:
189 e1 = cluster1.getEnergyDep()
190 x1 = cluster1.getPositionX()
191 y1 = cluster1.getPositionY()
192 z1 = cluster1.getPositionZ()
193 vec1 = ROOT.TVector3(x1, y1, z1)
194 theta1 = vec1.Theta()
198 for j, cluster2
in enumerate(eclclusters):
199 e2 = cluster2.getEnergyDep()
202 x2 = cluster2.getPositionX()
203 y2 = cluster2.getPositionY()
204 z2 = cluster2.getPositionZ()
205 vec2 = ROOT.TVector3(x2, y2, z2)
206 theta2 = vec2.Theta()
210 delt_theta = math.fabs((theta1 + theta2) * RadToDeg - 180.0)
211 delt_phi = math.fabs(phi1 - phi2) * RadToDeg - 180.0
218 bhacl = [delt_theta, delt_phi, efr, ebr, efr + ebr]
219 neclBhabha.append(bhacl)
223 def Max_DeltPhi_cluster(eclclusters):
225 for i, cluster1
in enumerate(eclclusters):
226 e1 = cluster1.getEnergyDep()
229 x1 = cluster1.getPositionX()
230 y1 = cluster1.getPositionY()
231 z1 = cluster1.getPositionZ()
232 vec1 = ROOT.TVector3(x1, y1, z1)
236 for j, cluster2
in enumerate(eclclusters):
237 e2 = cluster2.getEnergyDep()
242 x2 = cluster2.getPositionX()
243 y2 = cluster2.getPositionY()
244 z2 = cluster2.getPositionZ()
245 vec2 = ROOT.TVector3(x2, y2, z2)
249 delt_phi = math.fabs(phi1 - phi2) * RadToDeg
250 eclphi_col.append(delt_phi)
251 return max(eclphi_col
or [-1.0])
254 def Time_Window(clusters, eventtime):
258 event_time = ev.m_eventtiming
259 event_tot = ev.m_etot
260 energy.append([event_time, event_tot])
262 tmp = max(energy, key=
lambda item: item[1])
265 event_time = -999999.
266 for cluster
in clusters:
267 ctime_ori = cluster.getTimeAve()
268 ctime = ctime_ori - event_time
269 if math.fabs(ctime) < 100:
270 new_clusters.append(cluster)
274 def Cluster_Threshold(clusters, threshold, CMS):
276 for cluster
in clusters:
279 newv = Vec_Cluster(cluster)
282 eng = cluster.getEnergyDep()
284 new_clusters.append(cluster)
288 def Back_to_Back(clusters1, clusters2):
290 for cluster1
in clusters1:
291 cid1 = cluster1.getClusterId()
292 vec1 = Vec_Cluster(cluster1)
295 for cluster2
in clusters2:
296 cid2 = cluster2.getClusterId()
299 vec2 = Vec_Cluster(cluster2)
302 delttheta = math.fabs(theta1 + theta2 - 180)
303 deltphi = math.fabs(math.fabs(phi1 - phi2) - 180)
304 if delttheta < 100
and deltphi < 100:
309 def Time_Cluster(clusters, eventtime):
314 event_time = ev.m_eventtiming
315 event_tot = ev.m_etot
316 energy.append([event_time, event_tot])
318 tmp = max(energy, key=
lambda item: item[1])
320 for cluster
in clusters:
321 ctime_ori = cluster.getTimeAve()
322 ctime = ctime_ori - event_time
323 time_list.append(ctime)
327 def PrintBranchDef():
329 print(
'ntrk_2dfinder: # 2d finder track')
330 print(
'ntrk_2dfitter: # 2d fitter track')
331 print(
'ntrk_3dfitter: # 3d fitter track')
332 print(
'ntrk_NN : # Neuro network track')
333 print(
'ntrk_2Dmatch : # 2d finder track w/ associated ecl cluster')
334 print(
'ntrk_3Dmatch : # 3d finder track w/ associated ecl cluster')
335 print(
'ntrk_klm : # KLM track')
336 print(
'nhit_klm : # KLM hit',
'\n')
338 print(
'ncluster: # ecl cluster')
339 print(
'ncluster_1000b: # ecl cluster with threshold >1.0GeV, exclude TC ID 1,2, 17')
340 print(
'ncluster_2000e: # ecl cluster with threshold >2.0GeV in TC ID 1, 17')
341 print(
'max_cluster[3]: [energy, theta, phi] of the largest energetic ecl cluster')
342 print(
'smax_cluster[3]: [energy, theta, phi] of the secondary energetic ecl cluster')
343 print(
'ncluster_neutral: # ecl cluster w/o associated cdc track')
344 print(
'max_cluster_neutral[3]: [energy, theta, phi] of the largest energetic ecl neutral cluster')
345 print(
'smax_cluster_neutral[3]: [energy, theta, phi] of the secondary energetic ecl neutral cluster')
346 print(
'time_cluster: the cluster timing obtained with cluster.timing-event.timing',
'\n')
348 print(
'nbbc: # back to back cluster pairs')
349 print(
'nbbtc: # back to back track and cluster pairs')
350 print(
'bhabha: bhabha veto logic, 1: bhabha, 0: non bhabha')
351 print(
'sbhabha: bhabha with single track veto logic, 1: bhabha, 0: non bhabha')
352 print(
'eclbhabha: eclbhabha veto logic, 1: bhabha, 0: non bhabha')
353 print(
'bhabha_var[5]: variables used in bhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]')
354 print(
' For two tracks: Delt_theta: theta1+theta2-180, Delt_phi: |phi1-phi2|-180')
355 print(
' E1, E2 are the ecl clusters energy accociated with the two tracks')
356 print(
'eclbhabha_var[5]: variables used in eclbhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]')
357 print(
' For two eclclusers: Delt_theta: theta1+theta2-180, Delt_phi: |phi1-phi2|-180')
358 print(
' E1, E2 are the ecl clusters energy')
363 """This module is to calculate some variables which are useful for the trigger development"""
365 file = ROOT.TFile(argvs[2],
'recreate')
367 tgrl = ROOT.TTree(
'tgrl',
'tree with GRL_Logic')
369 ntrk_2dfinder_t = array(
'i', [-1])
371 ntrk_2dfitter_t = array(
'i', [-1])
373 ntrk_3dfitter_t = array(
'i', [-1])
375 ntrk_NN_t = array(
'i', [-1])
377 ntrk_2Dmatch_t = array(
'i', [-1])
379 ntrk_3Dmatch_t = array(
'i', [-1])
381 max_deltphi_2dfinder_t = array(
'f', [0.0])
383 cpair_t = array(
'i', 8 * [0])
387 etot_t = array(
'f', [0.0])
389 ncluster_1000b_t = array(
'i', [-1])
391 ncluster_2000e_t = array(
'i', [-1])
393 ncluster_t = array(
'i', [-1])
395 ncluster_neutral_t = array(
'i', [-1])
397 max_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
399 max_cms_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
401 max_cluster_t = array(
'f', ncomp_clu * [0.0])
403 max_cms_cluster_t = array(
'f', ncomp_clu * [0.0])
405 smax_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
407 smax_cms_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
409 smax_cluster_t = array(
'f', ncomp_clu * [0.0])
411 smax_cms_cluster_t = array(
'f', ncomp_clu * [0.0])
413 max_deltphi_cluster_t = array(
'f', [0.0])
415 time_cluster_t = array(
'f', 100 * [-99999.])
417 ntrk_klm_t = array(
'i', [-1])
419 nhit_klm_t = array(
'i', [-1])
421 npair_tc_t = array(
'i', [-1])
423 npair_cc_t = array(
'i', [-1])
427 bhabha_t = array(
'i', [0])
429 sbhabha_t = array(
'i', [0])
431 eclbhabha_t = array(
'i', [0])
433 bhabha_var_t = array(
'f', nbha_var * [0.0])
435 eclbhabha_var_t = array(
'f', nbha_var * [0.0])
438 tgrl.Branch(
'ntrk_2dfinder', ntrk_2dfinder_t,
'ntrk_2dfinder/i')
439 tgrl.Branch(
'ntrk_2dfitter', ntrk_2dfitter_t,
'ntrk_2dfitter/i')
440 tgrl.Branch(
'ntrk_3dfitter', ntrk_3dfitter_t,
'ntrk_3dfitter/i')
441 tgrl.Branch(
'ntrk_NN', ntrk_NN_t,
'ntrk_NN/i')
442 tgrl.Branch(
'ntrk_2Dmatch', ntrk_2Dmatch_t,
'ntrk_2Dmatch/i')
443 tgrl.Branch(
'ntrk_3Dmatch', ntrk_3Dmatch_t,
'ntrk_3Dmatch/i')
444 tgrl.Branch(
'npair_tc', npair_tc_t,
'npair_tc/i')
445 tgrl.Branch(
'npair_cc', npair_cc_t,
'npair_cc/i')
446 tgrl.Branch(
'max_deltphi_2dfinder', max_deltphi_2dfinder_t,
'max_deltphi_2dfinder/f')
449 tgrl.Branch(
'etot', etot_t,
'etot/f')
450 tgrl.Branch(
'ncluster', ncluster_t,
'ncluster/i')
451 tgrl.Branch(
'ncluster_1000b', ncluster_1000b_t,
'ncluster_1000b/i')
452 tgrl.Branch(
'ncluster_2000e', ncluster_2000e_t,
'ncluster_2000e/i')
453 tgrl.Branch(
'ncluster_neutral', ncluster_neutral_t,
'ncluster_neutral/i')
454 tgrl.Branch(
'max_cluster_neutral', max_cluster_neutral_t,
'max_cluster_neutral[3]/f')
456 tgrl.Branch(
'max_cluster', max_cluster_t,
'max_cluster[3]/f')
458 tgrl.Branch(
'smax_cluster_neutral', smax_cluster_neutral_t,
'smax_cluster_neutral[3]/f')
460 tgrl.Branch(
'smax_cluster', smax_cluster_t,
'smax_cluster[3]/f')
462 tgrl.Branch(
'max_deltphi_cluster', max_deltphi_cluster_t,
'max_deltphi_cluster/f')
463 tgrl.Branch(
'time_cluster', time_cluster_t,
'time_cluster[100]/f')
466 tgrl.Branch(
'ntrk_klm', ntrk_klm_t,
'ntrk_klm/i')
467 tgrl.Branch(
'nhit_klm', nhit_klm_t,
'nhit_klm/i')
470 tgrl.Branch(
'bhabha', bhabha_t,
'bhabha/i')
471 tgrl.Branch(
'sbhabha', sbhabha_t,
'sbhabha/i')
472 tgrl.Branch(
'eclbhabha', eclbhabha_t,
'eclbhabha/i')
473 tgrl.Branch(
'bhabha_var', bhabha_var_t,
'bhabha_var[5]/f')
474 tgrl.Branch(
'eclbhabha_var', eclbhabha_var_t,
'eclbhabha_var[5]/f')
476 tgrl.Branch(
'cpair', cpair_t,
'cpair[8]/i')
480 MCPart = Belle2.PyStoreArray('MCParticles')
482 self.eplus_t[0]=Theta_MCTruth(MCPart[2])
483 self.eminus_t[0]=Theta_MCTruth(MCPart[3])
484 if self.eplus_t[0] > self.eminus_t[0]:
485 self.efrd_t[0]=self.eminus_t[0]
486 self.ebkd_t[0]=self.eplus_t[0]
488 self.efrd_t[0]=self.eplus_t[0]
489 self.ebkd_t[0]=self.eminus_t[0]
490 count_part = Count_part_inDetector(MCPart)
491 self.n_par_t[0]=count_part[0]
492 self.n_par_t[1]=count_part[1]
493 count_mcpart = Count_mcpart(MCPart)
494 self.n_mcpar_t[0]=count_mcpart[0]
495 self.n_mcpar_t[1]=count_mcpart[1]
510 clusters = Time_Window(clusters_original, eventtime)
513 time_clu_list = Time_Cluster(clusters_original, eventtime)
514 for i
in range(len(time_clu_list)):
518 clusters_300_cms = Cluster_Threshold(clusters, 0.3,
False)
519 clusters_400_cms = Cluster_Threshold(clusters, 0.4,
False)
520 clusters_500_cms = Cluster_Threshold(clusters, 0.5,
False)
521 clusters_700_cms = Cluster_Threshold(clusters, 0.7,
False)
522 clusters_1000_cms = Cluster_Threshold(clusters, 1.0,
False)
523 clusters_2000_cms = Cluster_Threshold(clusters, 2.0,
False)
524 clusters_2500_cms = Cluster_Threshold(clusters, 2.5,
False)
525 self.
cpair_tcpair_t[0] = Back_to_Back(clusters, clusters)
526 self.
cpair_tcpair_t[1] = Back_to_Back(clusters_300_cms, clusters)
527 self.
cpair_tcpair_t[2] = Back_to_Back(clusters_400_cms, clusters)
528 self.
cpair_tcpair_t[3] = Back_to_Back(clusters_500_cms, clusters)
529 self.
cpair_tcpair_t[4] = Back_to_Back(clusters_700_cms, clusters)
530 self.
cpair_tcpair_t[5] = Back_to_Back(clusters_1000_cms, clusters)
531 self.
cpair_tcpair_t[6] = Back_to_Back(clusters_2000_cms, clusters)
532 self.
cpair_tcpair_t[7] = Back_to_Back(clusters_2500_cms, clusters)
543 self.
npair_tc_tnpair_tc_t[0] = trginfo.getNbbTrkCluster()
544 self.
npair_cc_tnpair_cc_t[0] = trginfo.getNbbCluster()
549 neutral_clusters = NeutralCluster(clusters)
551 max_cluster_neu = Max_Cluster(neutral_clusters, 0)
552 max_cluster = Max_Cluster(clusters, 0)
555 smax_cluster_neu = Max_Cluster(neutral_clusters, 1)
556 smax_cluster = Max_Cluster(clusters, 1)
569 self.
etot_tetot_t[0] = Etot_Cluster(clusters)
572 bhabhaveto_1 = BhabhaVeto1(matchlist)
574 for bha
in bhabhaveto_1:
575 if math.fabs(bha[0]) < 50
and math.fabs(bha[0]) > 10
and math.fabs(bha[1]) < 20:
576 if bha[2] > 2.0
and bha[3] > 2.0
and bha[4] > 6.0:
577 if bha[2] > 3.0
or bha[3] > 3.0:
578 if len(trk_2d_finder) == 2:
580 self.
bhabha_tbhabha_t[0] = bha_logic
582 if len(bhabhaveto_1) >= 1:
583 for i
in range(self.
nbha_varnbha_var):
587 eclbhabhaveto = eclBhabhaVeto(clusters)
589 for eclbha
in eclbhabhaveto:
590 if math.fabs(eclbha[0]) < 50
and math.fabs(eclbha[1]) < 50:
591 if eclbha[2] > 2.0
and eclbha[3] > 2.0
and eclbha[4] > 6.0:
592 if eclbha[2] > 3.0
or eclbha[3] > 3.0:
598 if len(trk_2d_finder) == 1:
599 if eclbha_logic == 1:
600 ecol = SBhabhaVeto(matchlist)
607 if len(eclbhabhaveto) >= 1:
608 for i
in range(self.
nbha_varnbha_var):
613 """Write and close the file"""
615 self.
filefile.Write()
616 self.
filefile.Close()
620 if __name__ ==
"__main__":
621 main = b2.create_path()
622 ma.inputMdst(argvs[1], main)
The DetectorSet class for sets of detector IDs in the form of EDetector values.
A (simplified) python wrapper for StoreArray.
a (simplified) python wrapper for StoreObjPtr.
ntrk_NN_t
number of NN tracks
cpair_t
number of cluster pairs with different energy threshold
eclbhabha_var_t
variables used in eclbhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]
ncluster_1000b_t
number of ecl cluster with threshold >1.0GeV, exclude TC ID 1,2, 17
max_cluster_neutral_t
[energy, theta, phi] of the largest energetic ecl neutral cluster
nhit_klm_t
number of KLM hits
ntrk_3dfitter_t
#3d fitter tracks
eclbhabha_t
eclbhabha veto logic, 1: bhabha, 0: non bhabha
etot_t
the total deposited cluster energy in ecl
smax_cluster_neutral_t
[energy, theta, phi] of the secondary energetic ecl neutral cluster
int ncomp_clu
number of array components
ntrk_klm_t
number of KLM tracks
smax_cluster_t
[energy, theta, phi] of the secondary energetic ecl cluster
tgrl
the tree in the output file
ntrk_2dfinder_t
#2d finder tracks
ntrk_3Dmatch_t
#3d matched tracks
time_cluster_t
the timing of clusters
bhabha_t
bhabha veto logic, 1: bhabha, 0: non bhabha
ntrk_2dfitter_t
#2d fitter tracks
max_cluster_t
[energy, theta, phi] of the largest energetic ecl cluster
int nbha_var
number of array components
sbhabha_t
bhabha with single track veto logic, 1: bhabha, 0: non bhabha
max_deltphi_cluster_t
max delt phi angle between two clusters
bhabha_var_t
variables used in bhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]
max_deltphi_2dfinder_t
max phi angle between two 2d finder tracks