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), 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), help=
"Trigger bit %s isUnprescaled flag"%TP) )
60 self.triggerBitCheckersSingleBits.append( (TP, ROOT.heppy.TriggerBitChecker(trigVecBit)) )
63 if not hasattr(setup ,
"globalVariables") :
64 setup.globalVariables = []
65 setup.globalVariables.append( NTupleVariable(outname, eval(
"lambda ev: ev.%s" % outname), help=
"OR of %s"%TL) )
66 if self.
saveIsUnprescaled or self.
force1prescale: setup.globalVariables.append( NTupleVariable(outname+
'_isUnprescaled', eval(
"lambda ev: ev.%s_isUnprescaled" % outname), help=
"OR of %s is Unprescaled flag"%TL) )
67 self.triggerBitCheckers.append( (T, ROOT.heppy.TriggerBitChecker(trigVec)) )
71 self.readCollections( event.input )
72 triggerResults = self.handles[
'TriggerResults'].product()
74 triggerPrescales = self.handles[
"TriggerPrescales"].product()
76 triggerPrescales_min = self.handles[
"TriggerPrescales_l1min"].product()
77 triggerPrescales_max = self.handles[
"TriggerPrescales_l1max"].product()
80 setattr(event,outname, TC.check(event.input.object(), triggerResults))
82 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
84 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
85 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
86 setattr(event,outname+
'_isUnprescaled', unpr)
87 if self.
force1prescale: setattr(event,outname+
'_isUnprescaled',
True)
91 if outname[-1] ==
'*' :
93 setattr(event,outname, TC.check(event.input.object(), triggerResults))
95 unpr = TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales)
97 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_min)
98 unpr = unpr
and TC.check_unprescaled(event.input.object(), triggerResults, triggerPrescales_max)
99 setattr(event,outname+
'_isUnprescaled', unpr)
100 if self.
force1prescale: setattr(event,outname+
'_isUnprescaled',
True)
105 setattr(TriggerBitAnalyzer,
"defaultConfig",cfg.Analyzer(
106 TriggerBitAnalyzer, name=
"TriggerFlags",
108 prescaleProcessName =
'PAT',
109 prescaleFallbackProcessName =
'RECO',
111 saveIsUnprescaled =
False,
112 checkL1prescale =
False,
118 setattr(TriggerBitAnalyzer,
"defaultEventFlagsConfig",cfg.Analyzer(
119 TriggerBitAnalyzer, name=
"EventFlags",
121 fallbackProcessName =
'RECO',
123 saveIsUnprescaled =
False,
126 "HBHENoiseFilter" : [
"Flag_HBHENoiseFilter" ],
127 "HBHENoiseIsoFilter" : [
"Flag_HBHENoiseIsoFilter" ],
128 "CSCTightHaloFilter" : [
"Flag_CSCTightHaloFilter" ],
129 "hcalLaserEventFilter" : [
"Flag_hcalLaserEventFilter" ],
130 "EcalDeadCellTriggerPrimitiveFilter" : [
"Flag_EcalDeadCellTriggerPrimitiveFilter" ],
131 "goodVertices" : [
"Flag_goodVertices" ],
132 "trackingFailureFilter" : [
"Flag_trackingFailureFilter" ],
133 "eeBadScFilter" : [
"Flag_eeBadScFilter" ],
134 "ecalLaserCorrFilter" : [
"Flag_ecalLaserCorrFilter" ],
135 "trkPOGFilters" : [
"Flag_trkPOGFilters" ],
136 "trkPOG_manystripclus53X" : [
"Flag_trkPOG_manystripclus53X" ],
137 "trkPOG_toomanystripclus53X" : [
"Flag_trkPOG_toomanystripclus53X" ],
138 "trkPOG_logErrorTooManyClusters" : [
"Flag_trkPOG_logErrorTooManyClusters" ],
139 "METFilters" : [
"Flag_METFilters" ],
string prescaleProcessName
triggerBitCheckersSingleBits