CMS 3D CMS Logo

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