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
8 import PhysicsTools.HeppyCore.framework.config
as cfg
11 def __init__(self, cfg_ana, cfg_comp, looperName ):
12 super(TriggerBitAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
13 self.
processName = getattr(self.cfg_ana,
"processName",
"HLT")
15 self.
fallbackName = getattr(self.cfg_ana,
"fallbackProcessName",
None)
18 self.
unrollbits = ( hasattr(self.cfg_ana,
"unrollbits")
and self.cfg_ana.unrollbits )
23 print(
'Cannot save prescale information in MC: will put everything to unprescaled')
32 self.handles[
'TriggerResults'] = AutoHandle( (
'TriggerResults',
'',self.
processName),
'edm::TriggerResults', fallbackLabel=fallback )
34 self.handles[
"TriggerPrescales"] = AutoHandle( (
'patTrigger',
'',self.
prescaleProcessName),
'pat::PackedTriggerPrescales', fallbackLabel=prescaleFallback )
40 super(TriggerBitAnalyzer,self).
beginLoop(setup)
46 for T, TL
in six.iteritems(self.cfg_ana.triggerBits):
47 trigVec = ROOT.vector(ROOT.string)()
53 trigVecBit = ROOT.vector(ROOT.string)()
54 trigVecBit.push_back(TP)
56 if not hasattr(setup ,
"globalVariables") :
57 setup.globalVariables = []
58 if outname[-1] ==
'*' :
60 setup.globalVariables.append( NTupleVariable(outname, eval(
"lambda ev: ev.%s" % outname), int, help=
"Trigger bit %s"%TP) )
61 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) )
62 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) )
66 if not hasattr(setup ,
"globalVariables") :
67 setup.globalVariables = []
68 setup.globalVariables.append( NTupleVariable(outname, eval(
"lambda ev: ev.%s" % outname), int, help=
"OR of %s"%TL) )
69 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) )
74 self.readCollections( event.input )
75 triggerResults = self.handles[
'TriggerResults'].product()
77 triggerPrescales = self.handles[
"TriggerPrescales"].product()
79 triggerPrescales_min = self.handles[
"TriggerPrescales_l1min"].product()
80 triggerPrescales_max = self.handles[
"TriggerPrescales_l1max"].product()
83 setattr(event,outname, TC.check(event.input.object(), triggerResults))
85 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
87 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
88 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
89 setattr(event,outname+
'_isUnprescaled', unpr)
90 if self.
force1prescale: setattr(event,outname+
'_isUnprescaled',
True)
94 if outname[-1] ==
'*' :
96 setattr(event,outname, TC.check(event.input.object(), triggerResults))
98 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
99 getpr = TC.getprescale(event.input.object(), triggerResults, triggerPrescales)
101 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
102 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
103 getprl1min = TC.getprescale(event.input.object(), triggerResults, triggerPrescales_min)
104 getprl1max = TC.getprescale(event.input.object(), triggerResults, triggerPrescales_max)
105 if (getprl1min != getprl1max):
108 getpr = getprl1min*getpr
109 setattr(event,outname+
'_isUnprescaled', unpr)
110 setattr(event,outname+
'_Prescale', getpr)
112 setattr(event,outname+
'_isUnprescaled',
True)
113 setattr(event,outname+
'_Prescale', 1)
118 setattr(TriggerBitAnalyzer,
"defaultConfig",cfg.Analyzer(
119 TriggerBitAnalyzer, name=
"TriggerFlags",
121 prescaleProcessName =
'PAT',
122 prescaleFallbackProcessName =
'RECO',
124 saveIsUnprescaled =
False,
125 checkL1prescale =
False,
131 setattr(TriggerBitAnalyzer,
"defaultEventFlagsConfig",cfg.Analyzer(
132 TriggerBitAnalyzer, name=
"EventFlags",
134 fallbackProcessName =
'RECO',
136 saveIsUnprescaled =
False,
139 "HBHENoiseFilter" : [
"Flag_HBHENoiseFilter" ],
140 "HBHENoiseIsoFilter" : [
"Flag_HBHENoiseIsoFilter" ],
141 "CSCTightHaloFilter" : [
"Flag_CSCTightHaloFilter" ],
142 "CSCTightHalo2015Filter" : [
"Flag_CSCTightHalo2015Filter" ],
143 "hcalLaserEventFilter" : [
"Flag_hcalLaserEventFilter" ],
144 "EcalDeadCellTriggerPrimitiveFilter" : [
"Flag_EcalDeadCellTriggerPrimitiveFilter" ],
145 "goodVertices" : [
"Flag_goodVertices" ],
146 "trackingFailureFilter" : [
"Flag_trackingFailureFilter" ],
147 "eeBadScFilter" : [
"Flag_eeBadScFilter" ],
148 "ecalLaserCorrFilter" : [
"Flag_ecalLaserCorrFilter" ],
149 "trkPOGFilters" : [
"Flag_trkPOGFilters" ],
150 "trkPOG_manystripclus53X" : [
"Flag_trkPOG_manystripclus53X" ],
151 "trkPOG_toomanystripclus53X" : [
"Flag_trkPOG_toomanystripclus53X" ],
152 "trkPOG_logErrorTooManyClusters" : [
"Flag_trkPOG_logErrorTooManyClusters" ],
153 "METFilters" : [
"Flag_METFilters" ],