CMS 3D CMS Logo

TriggerAnalyzer.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from PhysicsTools.HeppyCore.framework.analyzer import Analyzer
3 from PhysicsTools.Heppy.analyzers.AutoHandle import AutoHandle
4 from PhysicsTools.HeppyCore.statistics.counter import Counter
5 from PhysicsTools.HeppyCore.utils.TriggerList import TriggerList
6 from PhysicsTools.HeppyCore.utils.TriggerMatching import selTriggerObjects
7 from PhysicsTools.Heppy.physicsobjects.PhysicsObjects import TriggerObject
8 
9 
10 
11 class TriggerAnalyzer( Analyzer ):
12  '''Access to trigger information, and trigger selection'''
13 
14  def declareHandles(self):
15  super(TriggerAnalyzer, self).declareHandles()
16 
17  self.handles['cmgTriggerObjectSel'] = AutoHandle(
18  'cmgTriggerObjectSel',
19  'std::vector<cmg::TriggerObject>'
20  )
21 
22  self.handles['cmgTriggerObjectListSel'] = AutoHandle(
23  'cmgTriggerObjectListSel',
24  'std::vector<cmg::TriggerObject>'
25  )
26 
27  def beginLoop(self, setup):
28  super(TriggerAnalyzer,self).beginLoop(setup)
29  self.triggerList = TriggerList( self.cfg_comp.triggers )
30  if hasattr(self.cfg_comp,'vetoTriggers'):
31  self.vetoTriggerList = TriggerList( self.cfg_comp.vetoTriggers )
32  else:
33  self.vetoTriggerList = None
34 
35  self.counters.addCounter('Trigger')
36  self.counters.counter('Trigger').register('All events')
37  self.counters.counter('Trigger').register('HLT')
38 
39 
40  def process(self, iEvent, event):
41  self.readCollections( iEvent )
42 
43  event.triggerObject = self.handles['cmgTriggerObjectSel'].product()[0]
44  run = iEvent.eventAuxiliary().id().run()
45  lumi = iEvent.eventAuxiliary().id().luminosityBlock()
46  eventId = iEvent.eventAuxiliary().id().event()
47 
48  event.run = run
49  event.lumi = lumi
50  event.eventId = eventId
51 
52 ## if self.cfg_ana.verbose:
53 ## self.printTriggerObject( event.triggerObject )
54 
55  self.counters.counter('Trigger').inc('All events')
56  # import pdb; pdb.set_trace()
57  usePrescaled = False
58  if hasattr( self.cfg_ana, 'usePrescaled'):
59  usePrescaled = self.cfg_ana.usePrescaled
60 
61  # import pdb; pdb.set_trace()
62  passed, hltPath = self.triggerList.triggerPassed(event.triggerObject,
63  run, lumi, self.cfg_comp.isData,
64  usePrescaled = usePrescaled)
65 
66 
67 
68  #Check the veto!
69  veto=False
70  if self.vetoTriggerList is not None:
71  veto,hltVetoPath = self.vetoTriggerList.triggerPassed(event.triggerObject,
72  run,lumi,self.cfg_comp.isData,
73  usePrescaled = usePrescaled)
74 
75  # Check if events needs to be skipped if no trigger is found (useful for generator level studies)
76  keepFailingEvents = False
77  if hasattr( self.cfg_ana, 'keepFailingEvents'):
78  keepFailingEvents = self.cfg_ana.keepFailingEvents
79  if not passed or (passed and veto):
80  event.passedTriggerAnalyzer = False
81  if not keepFailingEvents:
82  return False
83  else:
84  event.passedTriggerAnalyzer = True
85 
86  event.hltPath = hltPath
87 
88  if hltPath is not None:
89  trigObjs = map( TriggerObject,
90  self.handles['cmgTriggerObjectListSel'].product())
91  # selecting the trigger objects used in this path
92  event.triggerObjects = selTriggerObjects( trigObjs, hltPath )
93 
94  self.counters.counter('Trigger').inc('HLT')
95  event.TriggerFired = 1
96  return True
97 
98  def write(self, setup):
99  print('writing TriggerAnalyzer')
100  super(TriggerAnalyzer, self).write(setup)
101  self.triggerList.write( self.dirName )
102 
103  def __str__(self):
104  tmp = super(TriggerAnalyzer,self).__str__()
105  triglist = str( self.triggerList )
106  return '\n'.join( [tmp, triglist ] )
107 
108 
109 ## def printTriggerObject(self, object):
110 ## '''FIXME : we need a trigger object class in physicsobjects.'''
111 ## print 'trig obj', object.pdgId(), object.pt(), object.charge(), object.eta(), object.phi()
112 ## for name in object.getSelectionNames():
113 ## hasSel = object.getSelection( name )
114 ## if self.cfg_ana.verbose==1 and hasSel:
115 ## print name, hasSel
116 ## elif self.cfg_ana.verbose==2:
117 ## print name, hasSel
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def process(self, iEvent, event)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def write(self, setup)
#define str(s)
Definition: event.py:1