Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:27

0001 import ROOT
0002 
0003 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
0004 from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle
0005         
0006 class TriggerBitFilter( Analyzer ):
0007     def __init__(self, cfg_ana, cfg_comp, looperName ):
0008         super(TriggerBitFilter,self).__init__(cfg_ana,cfg_comp,looperName)
0009         self.processName = getattr(self.cfg_ana,"processName","HLT")
0010         triggers = cfg_comp.triggers
0011         self.autoAccept = True if len(triggers) == 0 else False
0012         vetoTriggers = cfg_comp.vetoTriggers if hasattr(cfg_comp, 'vetoTriggers') else []
0013         trigVec = ROOT.vector(ROOT.string)()
0014         for t in triggers: trigVec.push_back(t)
0015         self.mainFilter = ROOT.heppy.TriggerBitChecker(trigVec)
0016         if len(vetoTriggers):
0017             vetoVec = ROOT.vector(ROOT.string)()
0018             for t in vetoTriggers: vetoVec.push_back(t)
0019             self.vetoFilter = ROOT.heppy.TriggerBitChecker(vetoVec)
0020         else:
0021             self.vetoFilter = None 
0022         
0023     def declareHandles(self):
0024         super(TriggerBitFilter, self).declareHandles()
0025         self.handles['TriggerResults'] = AutoHandle( ('TriggerResults','',self.processName), 'edm::TriggerResults' )
0026 
0027     def beginLoop(self, setup):
0028         super(TriggerBitFilter,self).beginLoop(setup)
0029         self.counters.addCounter('events')
0030         self.count = self.counters.counter('events')
0031         self.count.register('all events')
0032         self.count.register('pass trigger')
0033         self.count.register('pass veto')
0034 
0035     def process(self, event):
0036         if self.autoAccept: return True
0037         self.readCollections( event.input )
0038         self.count.inc('all events')
0039         if not self.mainFilter.check(event.input.object(), self.handles['TriggerResults'].product()):
0040             return False
0041         self.count.inc('pass trigger')
0042         if self.vetoFilter != None and self.vetoFilter.check(event.input.object(), self.handles['TriggerResults'].product()):
0043             return False
0044         self.count.inc('pass veto')
0045         return True
0046