Belle II Software  release-08-01-10
effCalculation.py
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 
11 
12 from basf2 import Module
13 from ROOT import Belle2
14 
15 
16 class EffModule(Module):
17  """
18  This module is to calculate and print out the efficiency of each L1 trigger line with
19  the trigger result from object 'TRGGDLResults'
20  """
21 
22  Ntot_event = 0
23 
24  Ntrg_event = 0
25 
26  Nsubtrg_event = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
27 
28  prescale_phase2 = [1, 1, 20, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
29 
30  prescale_phase3 = [1, 1, 20, 2, 1, 1, 1, 1, 2, 1, 1, 20, 20, 1, 5, 1, 3, 5, 1, 1, 1, 1, 1]
31 # trglog = ['n_2d_finder>=3', 'n_2d_finder==2&&BhabhaVeto==0',
32 
33  trglog_phase2 = ['3 or more 3D tracks',
34  '2 3D tracks, ≥1 within 25 cm, not a trkBhabha',
35  '2 3D tracks, not a trkBhabha',
36  '2 3D tracks, trkBhabha',
37  '1 track, <25cm, clust same hemi, no 2 GeV clust',
38  '1 track, <25cm, clust opp hemi, no 2 GeV clust',
39  '≥3 clusters inc. ≥1 300 MeV, not an eclBhabha',
40  '2 GeV E* in [4,14], not a trkBhabha',
41  '2 GeV E* in [4,14], trkBhabha',
42  '2 GeV E* in 2,3,15 or 16, not a trkBhabha or eclBhabha',
43  '2 GeV E* in 2,3,15 or 16, trkBhabha or eclBhabha',
44  '2 GeV E* in 1 or 17, not a trkBhabha or eclBhabha',
45  '2 GeV E* in 1 or 17, trkBhabha or eclBhabha',
46  'exactly 1 E*>1 GeV and 1 E>300 MeV, in [4,15]',
47  'exactly 1 E*>1 GeV and 1 E>300 MeV, in 2,3 or 16',
48  'clusters back-to-back in phi, both >250 MeV, no 2 GeV',
49  'clusters back-to-back in phi, 1 <250 MeV, no 2 GeV',
50  'clusters back-to-back in 3D, no 2 GeV',
51  'eed: two matched & cluster b2b',
52  'fed: one track & one matched & cluster b2b',
53  'fp: one track & track-cluster b2b',
54  'eeb: two matched & track b2b',
55  'fep: one track & one matched & track-cluster b2b'
56  ]
57 
58 
59  trglog_phase3 = ['3 or more 3D tracks',
60  '2 3D tracks, ≥1 within 10 cm, not a trkBhabha',
61  '2 3D tracks, not a trkBhabha',
62  '2 3D tracks, trkBhabha',
63  '1 track, <10cm, clust same hemi, no 2 GeV clust',
64  '1 track, <10cm, clust opp hemi, no 2 GeV clust',
65  '≥3 clusters inc. ≥2 300 MeV, not an eclBhabha',
66  '2 GeV E* in [4,14], not a trkBhabha',
67  '2 GeV E* in [4,14], trkBhabha',
68  '2 GeV E* in 2,3,15 or 16, not a trkBhabha or eclBhabha',
69  '2 GeV E* in 2,3,15 or 16, trkBhabha or eclBhabha',
70  '2 GeV E* in 1 or 17, not a trkBhabha or eclBhabha',
71  '2 GeV E* in 1 or 17, trkBhabha or eclBhabha',
72  'exactly 1 E*>1 GeV and 1 E>300 MeV, in [4,15]',
73  'exactly 1 E*>1 GeV and 1 E>300 MeV, in 2,3 or 16',
74  'clusters back-to-back in phi, both >250 MeV, no 2 GeV',
75  'clusters back-to-back in phi, 1 <250 MeV, no 2 GeV, TrkZ25 is 3D track',
76  'clusters back-to-back in 3D, no 2 GeV',
77  'eed: two matched & cluster b2b',
78  'fed: one track & one matched & cluster b2b',
79  'fp: one track & track-cluster b2b',
80  'eeb: two matched & track b2b',
81  'fep: one track & one matched & track-cluster b2b'
82  ]
83  # ---add new trigger line by users---
84  # ---add a component with initial value 0 in Nsubtrg_event
85  # Nsubtrg_event+=[0]
86  # ---add the prescale factor in prescale list
87  # prescale += [1]
88  # ---add the description of new trigger logics in trglog
89  # trglog+=['new trg logics']
90 
91  def __init__(self, Belle2Phase):
92  """Initialization of EffModule"""
93  super(EffModule, self).__init__()
94 
95  self.Belle2PhaseBelle2Phase = Belle2Phase
96 
97  def event(self):
98  """
99  Event function to count the numbers of events passing each trigger line
100  """
101  self.Ntot_eventNtot_eventNtot_event += 1
102  trgresult = Belle2.PyStoreObj('TRGSummary')
103  summary = trgresult.getPsnmBits(0)
104  if summary >= 1:
105  self.Ntrg_eventNtrg_event += 1
106  sum_bin = bin(summary)
107  for i in range(len(sum_bin) - 2):
108  trg = int(sum_bin[len(sum_bin) - 1 - i])
109  if trg == 1:
110  self.Nsubtrg_eventNsubtrg_event[i] += 1
111 
112  def terminate(self):
113  """
114  Calculate the efficiency of each trigger line with the statistical values in event function
115  """
116  trglog = []
117  prescale = []
118  if self.Belle2PhaseBelle2Phase == "Phase2":
119  trglog = self.trglog_phase2trglog_phase2
120  prescale = self.prescale_phase2prescale_phase2
121  else:
122  trglog = self.trglog_phase3trglog_phase3
123  prescale = self.prescale_phase3prescale_phase3
124 
125 
126  if self.Ntot_eventNtot_eventNtot_event == 0:
127  return
128  sp = ' '
129  print('\n')
130  eff_tot = self.Ntrg_eventNtrg_event / self.Ntot_eventNtot_eventNtot_event * 100.0
131  print('L1 Trigger efficiency(%%): %6.2f' % (eff_tot))
132  print('Trigger Line', 5 * sp, 'PreScale Factor', 3 * sp, 'Efficiency(%)', 3 * sp, 'Logics')
133  ntrg = len(self.Nsubtrg_eventNsubtrg_event)
134  if self.Ntot_eventNtot_eventNtot_event != 0:
135  for i in range(ntrg):
136  eff = self.Nsubtrg_eventNsubtrg_event[i] / self.Ntot_eventNtot_eventNtot_event * 100.0
137  print('T%3d %4d %6.2f %s ' % (i, prescale[i], eff, trglog[i]))
138 
139 
140 def EffCalculation(path, Belle2Phase="Phase2"):
141  path.add_module(EffModule(Belle2Phase))
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:67
list trglog_phase3
trigger bit log for phase3
list prescale_phase3
prescale factors for phase3
def __init__(self, Belle2Phase)
list trglog_phase2
trigger bit log for phase2
int Ntot_event
The total number of events.
Ntot_event
Total number of events.
int Ntrg_event
The number of events passing L1 trigger.
list prescale_phase2
prescale factors for phase2
list Nsubtrg_event
The number of events passing each L1 trigger line.