1 from __future__
import print_function
4 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
5 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
6 from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer
import NTupleVariable
7 import PhysicsTools.HeppyCore.framework.config
as cfg
10 def __init__(self, cfg_ana, cfg_comp, looperName ):
11 super(TriggerBitAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
12 self.
processName = getattr(self.cfg_ana,
"processName",
"HLT")
14 self.
fallbackName = getattr(self.cfg_ana,
"fallbackProcessName",
None)
17 self.
unrollbits = ( hasattr(self.cfg_ana,
"unrollbits")
and self.cfg_ana.unrollbits )
22 print(
'Cannot save prescale information in MC: will put everything to unprescaled')
31 self.handles[
'TriggerResults'] = AutoHandle( (
'TriggerResults',
'',self.
processName),
'edm::TriggerResults', fallbackLabel=fallback )
33 self.handles[
"TriggerPrescales"] = AutoHandle( (
'patTrigger',
'',self.
prescaleProcessName),
'pat::PackedTriggerPrescales', fallbackLabel=prescaleFallback )
39 super(TriggerBitAnalyzer,self).
beginLoop(setup)
45 for T, TL
in self.cfg_ana.triggerBits.items():
46 trigVec = ROOT.vector(ROOT.string)()
52 trigVecBit = ROOT.vector(ROOT.string)()
53 trigVecBit.push_back(TP)
55 if not hasattr(setup ,
"globalVariables") :
56 setup.globalVariables = []
57 if outname[-1] ==
'*' :
59 setup.globalVariables.append( NTupleVariable(outname, eval(
"lambda ev: ev.%s" % outname), int, help=
"Trigger bit %s"%TP) )
60 if self.
saveIsUnprescaled or self.
force1prescale: setup.globalVariables.append( NTupleVariable(outname+
'_isUnprescaled', eval(
"lambda ev: ev.%s_isUnprescaled" % outname), int, help=
"Trigger bit %s isUnprescaled flag"%TP) )
61 if self.
saveIsUnprescaled or self.
force1prescale: setup.globalVariables.append( NTupleVariable(outname+
'_Prescale', eval(
"lambda ev: ev.%s_Prescale" % outname), int, help=
"get prescale %s "%TP) )
65 if not hasattr(setup ,
"globalVariables") :
66 setup.globalVariables = []
67 setup.globalVariables.append( NTupleVariable(outname, eval(
"lambda ev: ev.%s" % outname), int, help=
"OR of %s"%TL) )
68 if self.
saveIsUnprescaled or self.
force1prescale: setup.globalVariables.append( NTupleVariable(outname+
'_isUnprescaled', eval(
"lambda ev: ev.%s_isUnprescaled" % outname), int, help=
"OR of %s is Unprescaled flag"%TL) )
73 self.readCollections( event.input )
74 triggerResults = self.handles[
'TriggerResults'].product()
76 triggerPrescales = self.handles[
"TriggerPrescales"].product()
78 triggerPrescales_min = self.handles[
"TriggerPrescales_l1min"].product()
79 triggerPrescales_max = self.handles[
"TriggerPrescales_l1max"].product()
82 setattr(event,outname, TC.check(event.input.object(), triggerResults))
84 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
86 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
87 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
88 setattr(event,outname+
'_isUnprescaled', unpr)
89 if self.
force1prescale: setattr(event,outname+
'_isUnprescaled',
True)
93 if outname[-1] ==
'*' :
95 setattr(event,outname, TC.check(event.input.object(), triggerResults))
97 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
98 getpr = TC.getprescale(event.input.object(), triggerResults, triggerPrescales)
100 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
101 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
102 getprl1min = TC.getprescale(event.input.object(), triggerResults, triggerPrescales_min)
103 getprl1max = TC.getprescale(event.input.object(), triggerResults, triggerPrescales_max)
104 if (getprl1min != getprl1max):
107 getpr = getprl1min*getpr
108 setattr(event,outname+
'_isUnprescaled', unpr)
109 setattr(event,outname+
'_Prescale', getpr)
111 setattr(event,outname+
'_isUnprescaled',
True)
112 setattr(event,outname+
'_Prescale', 1)
117 setattr(TriggerBitAnalyzer,
"defaultConfig",cfg.Analyzer(
118 TriggerBitAnalyzer, name=
"TriggerFlags",
120 prescaleProcessName =
'PAT',
121 prescaleFallbackProcessName =
'RECO',
123 saveIsUnprescaled =
False,
124 checkL1prescale =
False,
130 setattr(TriggerBitAnalyzer,
"defaultEventFlagsConfig",cfg.Analyzer(
131 TriggerBitAnalyzer, name=
"EventFlags",
133 fallbackProcessName =
'RECO',
135 saveIsUnprescaled =
False,
138 "HBHENoiseFilter" : [
"Flag_HBHENoiseFilter" ],
139 "HBHENoiseIsoFilter" : [
"Flag_HBHENoiseIsoFilter" ],
140 "CSCTightHaloFilter" : [
"Flag_CSCTightHaloFilter" ],
141 "CSCTightHalo2015Filter" : [
"Flag_CSCTightHalo2015Filter" ],
142 "hcalLaserEventFilter" : [
"Flag_hcalLaserEventFilter" ],
143 "EcalDeadCellTriggerPrimitiveFilter" : [
"Flag_EcalDeadCellTriggerPrimitiveFilter" ],
144 "goodVertices" : [
"Flag_goodVertices" ],
145 "trackingFailureFilter" : [
"Flag_trackingFailureFilter" ],
146 "eeBadScFilter" : [
"Flag_eeBadScFilter" ],
147 "ecalLaserCorrFilter" : [
"Flag_ecalLaserCorrFilter" ],
148 "trkPOGFilters" : [
"Flag_trkPOGFilters" ],
149 "trkPOG_manystripclus53X" : [
"Flag_trkPOG_manystripclus53X" ],
150 "trkPOG_toomanystripclus53X" : [
"Flag_trkPOG_toomanystripclus53X" ],
151 "trkPOG_logErrorTooManyClusters" : [
"Flag_trkPOG_logErrorTooManyClusters" ],
152 "METFilters" : [
"Flag_METFilters" ],
def __init__(self, cfg_ana, cfg_comp, looperName)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
triggerBitCheckersSingleBits
def beginLoop(self, setup)