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