3 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
4 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
5 from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer
import NTupleVariable
6 import PhysicsTools.HeppyCore.framework.config
as cfg
9 def __init__(self, cfg_ana, cfg_comp, looperName ):
10 super(TriggerBitAnalyzer,self).
__init__(cfg_ana,cfg_comp,looperName)
13 self.
fallbackName = getattr(self.cfg_ana,
"fallbackProcessName",
None)
16 self.
unrollbits = ( hasattr(self.cfg_ana,
"unrollbits")
and self.cfg_ana.unrollbits )
21 print 'Cannot save prescale information in MC: will put everything to unprescaled'
30 self.handles[
'TriggerResults'] = AutoHandle( (
'TriggerResults',
'',self.
processName),
'edm::TriggerResults', fallbackLabel=fallback )
32 self.handles[
"TriggerPrescales"] = AutoHandle( (
'patTrigger',
'',self.
prescaleProcessName),
'pat::PackedTriggerPrescales', fallbackLabel=prescaleFallback )
38 super(TriggerBitAnalyzer,self).
beginLoop(setup)
44 for T, TL
in self.cfg_ana.triggerBits.iteritems():
45 trigVec = ROOT.vector(ROOT.string)()
50 self.allPaths.update([TP])
51 trigVecBit = ROOT.vector(ROOT.string)()
52 trigVecBit.push_back(TP)
54 if not hasattr(setup ,
"globalVariables") :
55 setup.globalVariables = []
56 if outname[-1] ==
'*' :
58 setup.globalVariables.append( NTupleVariable(outname, eval(
"lambda ev: ev.%s" % outname), int, help=
"Trigger bit %s"%TP) )
59 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) )
60 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) )
61 self.triggerBitCheckersSingleBits.append( (TP, ROOT.heppy.TriggerBitChecker(trigVecBit)) )
64 if not hasattr(setup ,
"globalVariables") :
65 setup.globalVariables = []
66 setup.globalVariables.append( NTupleVariable(outname, eval(
"lambda ev: ev.%s" % outname), int, help=
"OR of %s"%TL) )
67 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) )
68 self.triggerBitCheckers.append( (T, ROOT.heppy.TriggerBitChecker(trigVec)) )
72 self.readCollections( event.input )
73 triggerResults = self.handles[
'TriggerResults'].product()
75 triggerPrescales = self.handles[
"TriggerPrescales"].product()
77 triggerPrescales_min = self.handles[
"TriggerPrescales_l1min"].product()
78 triggerPrescales_max = self.handles[
"TriggerPrescales_l1max"].product()
81 setattr(event,outname, TC.check(event.input.object(), triggerResults))
83 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
85 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
86 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
87 setattr(event,outname+
'_isUnprescaled', unpr)
88 if self.
force1prescale: setattr(event,outname+
'_isUnprescaled',
True)
92 if outname[-1] ==
'*' :
94 setattr(event,outname, TC.check(event.input.object(), triggerResults))
96 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
97 getpr = TC.getprescale(event.input.object(), triggerResults, triggerPrescales)
99 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
100 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
101 getprl1min = TC.getprescale(event.input.object(), triggerResults, triggerPrescales_min)
102 getprl1max = TC.getprescale(event.input.object(), triggerResults, triggerPrescales_max)
103 if (getprl1min != getprl1max):
106 getpr = getprl1min*getpr
107 setattr(event,outname+
'_isUnprescaled', unpr)
108 setattr(event,outname+
'_Prescale', getpr)
110 setattr(event,outname+
'_isUnprescaled',
True)
111 setattr(event,outname+
'_Prescale', 1)
116 setattr(TriggerBitAnalyzer,
"defaultConfig",cfg.Analyzer(
117 TriggerBitAnalyzer, name=
"TriggerFlags",
119 prescaleProcessName =
'PAT',
120 prescaleFallbackProcessName =
'RECO',
122 saveIsUnprescaled =
False,
123 checkL1prescale =
False,
129 setattr(TriggerBitAnalyzer,
"defaultEventFlagsConfig",cfg.Analyzer(
130 TriggerBitAnalyzer, name=
"EventFlags",
132 fallbackProcessName =
'RECO',
134 saveIsUnprescaled =
False,
137 "HBHENoiseFilter" : [
"Flag_HBHENoiseFilter" ],
138 "HBHENoiseIsoFilter" : [
"Flag_HBHENoiseIsoFilter" ],
139 "CSCTightHaloFilter" : [
"Flag_CSCTightHaloFilter" ],
140 "CSCTightHalo2015Filter" : [
"Flag_CSCTightHalo2015Filter" ],
141 "hcalLaserEventFilter" : [
"Flag_hcalLaserEventFilter" ],
142 "EcalDeadCellTriggerPrimitiveFilter" : [
"Flag_EcalDeadCellTriggerPrimitiveFilter" ],
143 "goodVertices" : [
"Flag_goodVertices" ],
144 "trackingFailureFilter" : [
"Flag_trackingFailureFilter" ],
145 "eeBadScFilter" : [
"Flag_eeBadScFilter" ],
146 "ecalLaserCorrFilter" : [
"Flag_ecalLaserCorrFilter" ],
147 "trkPOGFilters" : [
"Flag_trkPOGFilters" ],
148 "trkPOG_manystripclus53X" : [
"Flag_trkPOG_manystripclus53X" ],
149 "trkPOG_toomanystripclus53X" : [
"Flag_trkPOG_toomanystripclus53X" ],
150 "trkPOG_logErrorTooManyClusters" : [
"Flag_trkPOG_logErrorTooManyClusters" ],
151 "METFilters" : [
"Flag_METFilters" ],
string prescaleProcessName
triggerBitCheckersSingleBits