File indexing completed on 2024-04-06 12:23:27
0001 from __future__ import print_function
0002 from PhysicsTools.HeppyCore.framework.analyzer import Analyzer
0003 from PhysicsTools.Heppy.analyzers.AutoHandle import AutoHandle
0004 from PhysicsTools.HeppyCore.statistics.counter import Counter
0005 from PhysicsTools.HeppyCore.utils.TriggerList import TriggerList
0006 from PhysicsTools.HeppyCore.utils.TriggerMatching import selTriggerObjects
0007 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import TriggerObject
0008
0009
0010
0011 class TriggerAnalyzer( Analyzer ):
0012 '''Access to trigger information, and trigger selection'''
0013
0014 def declareHandles(self):
0015 super(TriggerAnalyzer, self).declareHandles()
0016
0017 self.handles['cmgTriggerObjectSel'] = AutoHandle(
0018 'cmgTriggerObjectSel',
0019 'std::vector<cmg::TriggerObject>'
0020 )
0021
0022 self.handles['cmgTriggerObjectListSel'] = AutoHandle(
0023 'cmgTriggerObjectListSel',
0024 'std::vector<cmg::TriggerObject>'
0025 )
0026
0027 def beginLoop(self, setup):
0028 super(TriggerAnalyzer,self).beginLoop(setup)
0029 self.triggerList = TriggerList( self.cfg_comp.triggers )
0030 if hasattr(self.cfg_comp,'vetoTriggers'):
0031 self.vetoTriggerList = TriggerList( self.cfg_comp.vetoTriggers )
0032 else:
0033 self.vetoTriggerList = None
0034
0035 self.counters.addCounter('Trigger')
0036 self.counters.counter('Trigger').register('All events')
0037 self.counters.counter('Trigger').register('HLT')
0038
0039
0040 def process(self, iEvent, event):
0041 self.readCollections( iEvent )
0042
0043 event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]
0044 run = iEvent.eventAuxiliary().id().run()
0045 lumi = iEvent.eventAuxiliary().id().luminosityBlock()
0046 eventId = iEvent.eventAuxiliary().id().event()
0047
0048 event.run = run
0049 event.lumi = lumi
0050 event.eventId = eventId
0051
0052
0053
0054
0055 self.counters.counter('Trigger').inc('All events')
0056
0057 usePrescaled = False
0058 if hasattr( self.cfg_ana, 'usePrescaled'):
0059 usePrescaled = self.cfg_ana.usePrescaled
0060
0061
0062 passed, hltPath = self.triggerList.triggerPassed(event.triggerObject,
0063 run, lumi, self.cfg_comp.isData,
0064 usePrescaled = usePrescaled)
0065
0066
0067
0068
0069 veto=False
0070 if self.vetoTriggerList is not None:
0071 veto,hltVetoPath = self.vetoTriggerList.triggerPassed(event.triggerObject,
0072 run,lumi,self.cfg_comp.isData,
0073 usePrescaled = usePrescaled)
0074
0075
0076 keepFailingEvents = False
0077 if hasattr( self.cfg_ana, 'keepFailingEvents'):
0078 keepFailingEvents = self.cfg_ana.keepFailingEvents
0079 if not passed or (passed and veto):
0080 event.passedTriggerAnalyzer = False
0081 if not keepFailingEvents:
0082 return False
0083 else:
0084 event.passedTriggerAnalyzer = True
0085
0086 event.hltPath = hltPath
0087
0088 if hltPath is not None:
0089 trigObjs = map( TriggerObject,
0090 self.handles['cmgTriggerObjectListSel'].product())
0091
0092 event.triggerObjects = selTriggerObjects( trigObjs, hltPath )
0093
0094 self.counters.counter('Trigger').inc('HLT')
0095 event.TriggerFired = 1
0096 return True
0097
0098 def write(self, setup):
0099 print('writing TriggerAnalyzer')
0100 super(TriggerAnalyzer, self).write(setup)
0101 self.triggerList.write( self.dirName )
0102
0103 def __str__(self):
0104 tmp = super(TriggerAnalyzer,self).__str__()
0105 triglist = str( self.triggerList )
0106 return '\n'.join( [tmp, triglist ] )
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117