14from ROOT
import Belle2
15import modularAnalysis
as ma
16from array
import array
19from heapq
import nlargest
20from effCalculation
import EffCalculation
22RadToDeg = 180.0 / math.pi
28 sys.exit(
"ztsim02.py> # of arg is strange. Exit.")
31def Count_mcpart(parts):
36 pdglist = [11, 13, 2212, 321, 211]
37 pdg = math.fabs(part.getPDG())
38 theta = part.getMomentum().Theta() * RadToDeg
39 if theta > dec_cdc[0]
and theta < dec_cdc[1]:
43 if math.fabs(pdg) == 22:
44 if theta > dec_ecl[0]
and theta < dec_ecl[1]:
49def Count_part_inDetector(parts):
53 charge = part.getCharge()
56 if math.fabs(charge) > 0:
58 elif math.fabs(pdg) == 22:
63def Theta_MCTruth(part):
64 theta = part.getMomentum().Theta() * RadToDeg
68def NeutralCluster(clusters):
70 for cluster
in clusters:
71 if cluster.getRelatedFrom(
'TRGNNTracks'):
74 neutral_cluster.append(cluster)
75 return neutral_cluster
78def Vec_Cluster(cluster):
79 x = cluster.getPositionX()
80 y = cluster.getPositionY()
81 z = cluster.getPositionZ()
82 e = cluster.getEnergyDep()
83 vec = ROOT.TVector3(x, y, z)
84 v_mom = e * ROOT.Math.PxPyPzEVector(x / vec.Mag(), y / vec.Mag(), z / vec.Mag(), 1)
85 new_theta = v_mom.Theta() * RadToDeg
86 new_phi = v_mom.Phi() * RadToDeg
88 new_phi += 2 * math.pi
90 NVC = [new_e, new_theta, new_phi]
94def Max_Cluster(neuclus, CMS, n):
96 for neuclu
in neuclus:
97 NV = Vec_Cluster(neuclu)
99 if E
and len(E) >= (n + 1):
100 seqen = nlargest(n + 1, E, key=
lambda item: item[0])
103 return [-1, -999, -999]
106def Etot_Cluster(eclcluster):
108 for clu
in eclcluster:
109 e = clu.getEnergyDep()
114def Max_DeltPhi_trk(trk_2d_list):
116 for i, trk
in enumerate(trk_2d_list):
117 phi1 = (trk.getPhi0()) * RadToDeg
118 for j, trk2
in enumerate(trk_2d_list):
122 phi2 = (trk2.getPhi0()) * RadToDeg
123 Delt_phi = math.fabs(phi1 - phi2)
124 Delt.append(Delt_phi)
125 return max(Delt
or [-100.0])
128def BhabhaVeto1(matchtrks):
130 if len(matchtrks) <= 1:
132 for i, matchtrk1
in enumerate(matchtrks):
133 if i == len(matchtrks) - 1:
135 cdctrk1 = matchtrk1.getRelatedTo(
'TRGNNTracks')
136 cluster1 = matchtrk1.getRelatedTo(
'TRGECLClusters')
137 if cdctrk1
and cluster1:
138 tanLam1 = cdctrk1.getTanLambda()
139 theta1 = math.acos(tanLam1 / math.sqrt(1. + tanLam1 * tanLam1)) * RadToDeg
140 phi1 = (cdctrk1.getPhi0()) * RadToDeg
143 e1 = cluster1.getEnergyDep()
144 for j, matchtrk2
in enumerate(matchtrks):
148 cdctrk2 = matchtrk2.getRelatedTo(
'TRGNNTracks')
149 cluster2 = matchtrk2.getRelatedTo(
'TRGECLClusters')
150 if cdctrk2
and cluster2:
151 tanLam2 = cdctrk2.getTanLambda()
152 theta2 = math.acos(tanLam2 / math.sqrt(1. + tanLam2 * tanLam2)) * RadToDeg
153 phi2 = (cdctrk2.getPhi0()) * RadToDeg
156 e2 = cluster2.getEnergyDep()
157 Delt_theta = theta1 + theta2 - 180
158 Delt_phi = math.fabs(phi1 - phi2) - 180
159 DeltArray = [Delt_theta, Delt_phi, e1, e2, e1 + e2]
160 Delt.append(DeltArray)
164 return [-999., -999., -999., -999., -999]
167def SBhabhaVeto(matchtrks):
169 if len(matchtrks) <= 1:
171 for i, matchtrk1
in enumerate(matchtrks):
172 cdctrk1 = matchtrk1.getRelatedTo(
'TRGNNTracks')
173 cluster1 = matchtrk1.getRelatedTo(
'TRGECLClusters')
174 if cdctrk1
and cluster1:
175 e1 = cluster1.getEnergyDep()
183def eclBhabhaVeto(eclclusters):
185 for i, cluster1
in enumerate(eclclusters):
186 if i == len(eclclusters) - 1:
188 e1 = cluster1.getEnergyDep()
189 x1 = cluster1.getPositionX()
190 y1 = cluster1.getPositionY()
191 z1 = cluster1.getPositionZ()
192 vec1 = ROOT.TVector3(x1, y1, z1)
193 theta1 = vec1.Theta()
197 for j, cluster2
in enumerate(eclclusters):
198 e2 = cluster2.getEnergyDep()
201 x2 = cluster2.getPositionX()
202 y2 = cluster2.getPositionY()
203 z2 = cluster2.getPositionZ()
204 vec2 = ROOT.TVector3(x2, y2, z2)
205 theta2 = vec2.Theta()
209 delt_theta = math.fabs((theta1 + theta2) * RadToDeg - 180.0)
210 delt_phi = math.fabs(phi1 - phi2) * RadToDeg - 180.0
217 bhacl = [delt_theta, delt_phi, efr, ebr, efr + ebr]
218 neclBhabha.append(bhacl)
222def Max_DeltPhi_cluster(eclclusters):
224 for i, cluster1
in enumerate(eclclusters):
225 e1 = cluster1.getEnergyDep()
228 x1 = cluster1.getPositionX()
229 y1 = cluster1.getPositionY()
230 z1 = cluster1.getPositionZ()
231 vec1 = ROOT.TVector3(x1, y1, z1)
235 for j, cluster2
in enumerate(eclclusters):
236 e2 = cluster2.getEnergyDep()
241 x2 = cluster2.getPositionX()
242 y2 = cluster2.getPositionY()
243 z2 = cluster2.getPositionZ()
244 vec2 = ROOT.TVector3(x2, y2, z2)
248 delt_phi = math.fabs(phi1 - phi2) * RadToDeg
249 eclphi_col.append(delt_phi)
250 return max(eclphi_col
or [-1.0])
253def Time_Window(clusters, eventtime):
257 event_time = ev.m_eventtiming
258 event_tot = ev.m_etot
259 energy.append([event_time, event_tot])
261 tmp = max(energy, key=
lambda item: item[1])
264 event_time = -999999.
265 for cluster
in clusters:
266 ctime_ori = cluster.getTimeAve()
267 ctime = ctime_ori - event_time
268 if math.fabs(ctime) < 100:
269 new_clusters.append(cluster)
273def Cluster_Threshold(clusters, threshold, CMS):
275 for cluster
in clusters:
278 newv = Vec_Cluster(cluster)
281 eng = cluster.getEnergyDep()
283 new_clusters.append(cluster)
287def Back_to_Back(clusters1, clusters2):
289 for cluster1
in clusters1:
290 cid1 = cluster1.getClusterId()
291 vec1 = Vec_Cluster(cluster1)
294 for cluster2
in clusters2:
295 cid2 = cluster2.getClusterId()
298 vec2 = Vec_Cluster(cluster2)
301 delttheta = math.fabs(theta1 + theta2 - 180)
302 deltphi = math.fabs(math.fabs(phi1 - phi2) - 180)
303 if delttheta < 100
and deltphi < 100:
308def Time_Cluster(clusters, eventtime):
313 event_time = ev.m_eventtiming
314 event_tot = ev.m_etot
315 energy.append([event_time, event_tot])
317 tmp = max(energy, key=
lambda item: item[1])
319 for cluster
in clusters:
320 ctime_ori = cluster.getTimeAve()
321 ctime = ctime_ori - event_time
322 time_list.append(ctime)
328 print(
'ntrk_2dfinder: # 2d finder track')
329 print(
'ntrk_2dfitter: # 2d fitter track')
330 print(
'ntrk_3dfitter: # 3d fitter track')
331 print(
'ntrk_NN : # Neuro network track')
332 print(
'ntrk_2Dmatch : # 2d finder track w/ associated ecl cluster')
333 print(
'ntrk_3Dmatch : # 3d finder track w/ associated ecl cluster')
334 print(
'ntrk_klm : # KLM track')
335 print(
'nhit_klm : # KLM hit',
'\n')
337 print(
'ncluster: # ecl cluster')
338 print(
'ncluster_1000b: # ecl cluster with threshold >1.0GeV, exclude TC ID 1,2, 17')
339 print(
'ncluster_2000e: # ecl cluster with threshold >2.0GeV in TC ID 1, 17')
340 print(
'max_cluster[3]: [energy, theta, phi] of the largest energetic ecl cluster')
341 print(
'smax_cluster[3]: [energy, theta, phi] of the secondary energetic ecl cluster')
342 print(
'ncluster_neutral: # ecl cluster w/o associated cdc track')
343 print(
'max_cluster_neutral[3]: [energy, theta, phi] of the largest energetic ecl neutral cluster')
344 print(
'smax_cluster_neutral[3]: [energy, theta, phi] of the secondary energetic ecl neutral cluster')
345 print(
'time_cluster: the cluster timing obtained with cluster.timing-event.timing',
'\n')
347 print(
'nbbc: # back to back cluster pairs')
348 print(
'nbbtc: # back to back track and cluster pairs')
349 print(
'bhabha: bhabha veto logic, 1: bhabha, 0: non bhabha')
350 print(
'sbhabha: bhabha with single track veto logic, 1: bhabha, 0: non bhabha')
351 print(
'eclbhabha: eclbhabha veto logic, 1: bhabha, 0: non bhabha')
352 print(
'bhabha_var[5]: variables used in bhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]')
353 print(
' For two tracks: Delt_theta: theta1+theta2-180, Delt_phi: |phi1-phi2|-180')
354 print(
' E1, E2 are the ecl clusters energy accociated with the two tracks')
355 print(
'eclbhabha_var[5]: variables used in eclbhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]')
356 print(
' For two eclclusers: Delt_theta: theta1+theta2-180, Delt_phi: |phi1-phi2|-180')
357 print(
' E1, E2 are the ecl clusters energy')
362 """This module is to calculate some variables which are useful for the trigger development"""
364 file = ROOT.TFile(argvs[2],
'recreate')
366 tgrl = ROOT.TTree(
'tgrl',
'tree with GRL_Logic')
368 ntrk_2dfinder_t = array(
'i', [-1])
370 ntrk_2dfitter_t = array(
'i', [-1])
372 ntrk_3dfitter_t = array(
'i', [-1])
374 ntrk_NN_t = array(
'i', [-1])
376 ntrk_2Dmatch_t = array(
'i', [-1])
378 ntrk_3Dmatch_t = array(
'i', [-1])
380 max_deltphi_2dfinder_t = array(
'f', [0.0])
382 cpair_t = array(
'i', 8 * [0])
386 etot_t = array(
'f', [0.0])
388 ncluster_1000b_t = array(
'i', [-1])
390 ncluster_2000e_t = array(
'i', [-1])
392 ncluster_t = array(
'i', [-1])
394 ncluster_neutral_t = array(
'i', [-1])
396 max_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
398 max_cms_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
400 max_cluster_t = array(
'f', ncomp_clu * [0.0])
402 max_cms_cluster_t = array(
'f', ncomp_clu * [0.0])
404 smax_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
406 smax_cms_cluster_neutral_t = array(
'f', ncomp_clu * [0.0])
408 smax_cluster_t = array(
'f', ncomp_clu * [0.0])
410 smax_cms_cluster_t = array(
'f', ncomp_clu * [0.0])
412 max_deltphi_cluster_t = array(
'f', [0.0])
414 time_cluster_t = array(
'f', 100 * [-99999.])
416 ntrk_klm_t = array(
'i', [-1])
418 nhit_klm_t = array(
'i', [-1])
420 npair_tc_t = array(
'i', [-1])
422 npair_cc_t = array(
'i', [-1])
426 bhabha_t = array(
'i', [0])
428 sbhabha_t = array(
'i', [0])
430 eclbhabha_t = array(
'i', [0])
432 bhabha_var_t = array(
'f', nbha_var * [0.0])
434 eclbhabha_var_t = array(
'f', nbha_var * [0.0])
437 tgrl.Branch(
'ntrk_2dfinder', ntrk_2dfinder_t,
'ntrk_2dfinder/i')
438 tgrl.Branch(
'ntrk_2dfitter', ntrk_2dfitter_t,
'ntrk_2dfitter/i')
439 tgrl.Branch(
'ntrk_3dfitter', ntrk_3dfitter_t,
'ntrk_3dfitter/i')
440 tgrl.Branch(
'ntrk_NN', ntrk_NN_t,
'ntrk_NN/i')
441 tgrl.Branch(
'ntrk_2Dmatch', ntrk_2Dmatch_t,
'ntrk_2Dmatch/i')
442 tgrl.Branch(
'ntrk_3Dmatch', ntrk_3Dmatch_t,
'ntrk_3Dmatch/i')
443 tgrl.Branch(
'npair_tc', npair_tc_t,
'npair_tc/i')
444 tgrl.Branch(
'npair_cc', npair_cc_t,
'npair_cc/i')
445 tgrl.Branch(
'max_deltphi_2dfinder', max_deltphi_2dfinder_t,
'max_deltphi_2dfinder/f')
448 tgrl.Branch(
'etot', etot_t,
'etot/f')
449 tgrl.Branch(
'ncluster', ncluster_t,
'ncluster/i')
450 tgrl.Branch(
'ncluster_1000b', ncluster_1000b_t,
'ncluster_1000b/i')
451 tgrl.Branch(
'ncluster_2000e', ncluster_2000e_t,
'ncluster_2000e/i')
452 tgrl.Branch(
'ncluster_neutral', ncluster_neutral_t,
'ncluster_neutral/i')
453 tgrl.Branch(
'max_cluster_neutral', max_cluster_neutral_t,
'max_cluster_neutral[3]/f')
455 tgrl.Branch(
'max_cluster', max_cluster_t,
'max_cluster[3]/f')
457 tgrl.Branch(
'smax_cluster_neutral', smax_cluster_neutral_t,
'smax_cluster_neutral[3]/f')
459 tgrl.Branch(
'smax_cluster', smax_cluster_t,
'smax_cluster[3]/f')
461 tgrl.Branch(
'max_deltphi_cluster', max_deltphi_cluster_t,
'max_deltphi_cluster/f')
462 tgrl.Branch(
'time_cluster', time_cluster_t,
'time_cluster[100]/f')
465 tgrl.Branch(
'ntrk_klm', ntrk_klm_t,
'ntrk_klm/i')
466 tgrl.Branch(
'nhit_klm', nhit_klm_t,
'nhit_klm/i')
469 tgrl.Branch(
'bhabha', bhabha_t,
'bhabha/i')
470 tgrl.Branch(
'sbhabha', sbhabha_t,
'sbhabha/i')
471 tgrl.Branch(
'eclbhabha', eclbhabha_t,
'eclbhabha/i')
472 tgrl.Branch(
'bhabha_var', bhabha_var_t,
'bhabha_var[5]/f')
473 tgrl.Branch(
'eclbhabha_var', eclbhabha_var_t,
'eclbhabha_var[5]/f')
475 tgrl.Branch(
'cpair', cpair_t,
'cpair[8]/i')
481 self.eplus_t[0]=Theta_MCTruth(MCPart[2])
482 self.eminus_t[0]=Theta_MCTruth(MCPart[3])
483 if self.eplus_t[0] > self.eminus_t[0]:
484 self.efrd_t[0]=self.eminus_t[0]
485 self.ebkd_t[0]=self.eplus_t[0]
487 self.efrd_t[0]=self.eplus_t[0]
488 self.ebkd_t[0]=self.eminus_t[0]
489 count_part = Count_part_inDetector(MCPart)
490 self.n_par_t[0]=count_part[0]
491 self.n_par_t[1]=count_part[1]
492 count_mcpart = Count_mcpart(MCPart)
493 self.n_mcpar_t[0]=count_mcpart[0]
494 self.n_mcpar_t[1]=count_mcpart[1]
509 clusters = Time_Window(clusters_original, eventtime)
512 time_clu_list = Time_Cluster(clusters_original, eventtime)
513 for i
in range(len(time_clu_list)):
517 clusters_300_cms = Cluster_Threshold(clusters, 0.3,
False)
518 clusters_400_cms = Cluster_Threshold(clusters, 0.4,
False)
519 clusters_500_cms = Cluster_Threshold(clusters, 0.5,
False)
520 clusters_700_cms = Cluster_Threshold(clusters, 0.7,
False)
521 clusters_1000_cms = Cluster_Threshold(clusters, 1.0,
False)
522 clusters_2000_cms = Cluster_Threshold(clusters, 2.0,
False)
523 clusters_2500_cms = Cluster_Threshold(clusters, 2.5,
False)
524 self.
cpair_t[0] = Back_to_Back(clusters, clusters)
525 self.
cpair_t[1] = Back_to_Back(clusters_300_cms, clusters)
526 self.
cpair_t[2] = Back_to_Back(clusters_400_cms, clusters)
527 self.
cpair_t[3] = Back_to_Back(clusters_500_cms, clusters)
528 self.
cpair_t[4] = Back_to_Back(clusters_700_cms, clusters)
529 self.
cpair_t[5] = Back_to_Back(clusters_1000_cms, clusters)
530 self.
cpair_t[6] = Back_to_Back(clusters_2000_cms, clusters)
531 self.
cpair_t[7] = Back_to_Back(clusters_2500_cms, clusters)
542 self.
npair_tc_t[0] = trginfo.getNbbTrkCluster()
548 neutral_clusters = NeutralCluster(clusters)
550 max_cluster_neu = Max_Cluster(neutral_clusters, 0)
551 max_cluster = Max_Cluster(clusters, 0)
554 smax_cluster_neu = Max_Cluster(neutral_clusters, 1)
555 smax_cluster = Max_Cluster(clusters, 1)
568 self.
etot_t[0] = Etot_Cluster(clusters)
571 bhabhaveto_1 = BhabhaVeto1(matchlist)
573 for bha
in bhabhaveto_1:
574 if math.fabs(bha[0]) < 50
and math.fabs(bha[0]) > 10
and math.fabs(bha[1]) < 20:
575 if bha[2] > 2.0
and bha[3] > 2.0
and bha[4] > 6.0:
576 if bha[2] > 3.0
or bha[3] > 3.0:
577 if len(trk_2d_finder) == 2:
581 if len(bhabhaveto_1) >= 1:
586 eclbhabhaveto = eclBhabhaVeto(clusters)
588 for eclbha
in eclbhabhaveto:
589 if math.fabs(eclbha[0]) < 50
and math.fabs(eclbha[1]) < 50:
590 if eclbha[2] > 2.0
and eclbha[3] > 2.0
and eclbha[4] > 6.0:
591 if eclbha[2] > 3.0
or eclbha[3] > 3.0:
597 if len(trk_2d_finder) == 1:
598 if eclbha_logic == 1:
599 ecol = SBhabhaVeto(matchlist)
606 if len(eclbhabhaveto) >= 1:
612 """Write and close the file"""
619if __name__ ==
"__main__":
620 main = b2.create_path()
621 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.
array bhabha_t
bhabha veto logic, 1: bhabha, 0: non bhabha
array smax_cluster_t
[energy, theta, phi] of the secondary energetic ecl cluster
array smax_cluster_neutral_t
[energy, theta, phi] of the secondary energetic ecl neutral cluster
array nhit_klm_t
number of KLM hits
array ntrk_2dfinder_t
#2d finder tracks
array max_cluster_neutral_t
[energy, theta, phi] of the largest energetic ecl neutral cluster
ROOT tgrl
the tree in the output file
array eclbhabha_t
eclbhabha veto logic, 1: bhabha, 0: non bhabha
array cpair_t
number of cluster pairs with different energy threshold
array eclbhabha_var_t
variables used in eclbhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]
array max_deltphi_2dfinder_t
max phi angle between two 2d finder tracks
array ntrk_klm_t
number of KLM tracks
array ntrk_2dfitter_t
#2d fitter tracks
array bhabha_var_t
variables used in bhabha logic, [Delt_theta, Delt_phi, E1, E2, E1+E2]
array ntrk_3dfitter_t
#3d fitter tracks
int ncomp_clu
number of array components
array max_deltphi_cluster_t
max delt phi angle between two clusters
array sbhabha_t
bhabha with single track veto logic, 1: bhabha, 0: non bhabha
array max_cluster_t
[energy, theta, phi] of the largest energetic ecl cluster
array time_cluster_t
the timing of clusters
array etot_t
the total deposited cluster energy in ecl
array ntrk_3Dmatch_t
#3d matched tracks
int nbha_var
number of array components
array ntrk_NN_t
number of NN tracks
array ncluster_1000b_t
number of ecl cluster with threshold >1.0GeV, exclude TC ID 1,2, 17