CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TriggerBitAnalyzer.py
Go to the documentation of this file.
1 import ROOT
2 
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
7 
8 class TriggerBitAnalyzer( Analyzer ):
9  def __init__(self, cfg_ana, cfg_comp, looperName ):
10  super(TriggerBitAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName)
11  self.processName = getattr(self.cfg_ana,"processName","HLT")
12  self.outprefix = getattr(self.cfg_ana,"outprefix", self.processName)
13  self.unrollbits = ( hasattr(self.cfg_ana,"unrollbits") and self.cfg_ana.unrollbits )
14 
15 
16  def declareHandles(self):
17  super(TriggerBitAnalyzer, self).declareHandles()
18  self.handles['TriggerResults'] = AutoHandle( ('TriggerResults','',self.processName), 'edm::TriggerResults' )
19 
20  def beginLoop(self, setup):
21  super(TriggerBitAnalyzer,self).beginLoop(setup)
23  if self.unrollbits :
24  self.allPaths = set()
26 
27  for T, TL in self.cfg_ana.triggerBits.iteritems():
28  trigVec = ROOT.vector(ROOT.string)()
29  for TP in TL:
30  trigVec.push_back(TP)
31  if self.unrollbits :
32  if TP not in self.allPaths :
33  self.allPaths.update(TP)
34  trigVecBit = ROOT.vector(ROOT.string)()
35  trigVecBit.push_back(TP)
36  outname="%s_BIT_%s"%(self.outprefix,TP)
37  if not hasattr(setup ,"globalVariables") :
38  setup.globalVariables = []
39  if outname[-1] == '*' :
40  outname=outname[0:-1]
41  setup.globalVariables.append( NTupleVariable(outname, eval("lambda ev: ev.%s" % outname), help="Trigger bit %s"%TP) )
42  self.triggerBitCheckersSingleBits.append( (TP, ROOT.heppy.TriggerBitChecker(trigVecBit)) )
43 
44  outname="%s_%s"%(self.outprefix,T)
45  if not hasattr(setup ,"globalVariables") :
46  setup.globalVariables = []
47  setup.globalVariables.append( NTupleVariable(outname, eval("lambda ev: ev.%s" % outname), help="OR of %s"%TL) )
48  self.triggerBitCheckers.append( (T, ROOT.heppy.TriggerBitChecker(trigVec)) )
49 
50 
51  def process(self, event):
52  self.readCollections( event.input )
53  triggerResults = self.handles['TriggerResults'].product()
54  for T,TC in self.triggerBitCheckers:
55  outname="%s_%s"%(self.outprefix,T)
56  setattr(event,outname, TC.check(event.input.object(), triggerResults))
57  if self.unrollbits :
58  for TP,TC in self.triggerBitCheckersSingleBits:
59  outname="%s_BIT_%s"%(self.outprefix,TP)
60  if outname[-1] == '*' :
61  outname=outname[0:-1]
62  setattr(event,outname, TC.check(event.input.object(), triggerResults))
63 
64 
65  return True
66 
67 
68 setattr(TriggerBitAnalyzer,"defaultConfig",cfg.Analyzer(
69  TriggerBitAnalyzer, name="TriggerFlags",
70  processName = 'HLT',
71  triggerBits = {
72  # "<name>" : [ 'HLT_<Something>_v*', 'HLT_<SomethingElse>_v*' ]
73 }
74 )
75 )
76 setattr(TriggerBitAnalyzer,"defaultEventFlagsConfig",cfg.Analyzer(
77  TriggerBitAnalyzer, name="EventFlags",
78  processName = 'PAT',
79  outprefix = 'Flag',
80  triggerBits = {
81  "HBHENoiseFilter" : [ "Flag_HBHENoiseFilter" ],
82  "CSCTightHaloFilter" : [ "Flag_CSCTightHaloFilter" ],
83  "hcalLaserEventFilter" : [ "Flag_hcalLaserEventFilter" ],
84  "EcalDeadCellTriggerPrimitiveFilter" : [ "Flag_EcalDeadCellTriggerPrimitiveFilter" ],
85  "goodVertices" : [ "Flag_goodVertices" ],
86  "trackingFailureFilter" : [ "Flag_trackingFailureFilter" ],
87  "eeBadScFilter" : [ "Flag_eeBadScFilter" ],
88  "ecalLaserCorrFilter" : [ "Flag_ecalLaserCorrFilter" ],
89  "trkPOGFilters" : [ "Flag_trkPOGFilters" ],
90  "trkPOG_manystripclus53X" : [ "Flag_trkPOG_manystripclus53X" ],
91  "trkPOG_toomanystripclus53X" : [ "Flag_trkPOG_toomanystripclus53X" ],
92  "trkPOG_logErrorTooManyClusters" : [ "Flag_trkPOG_logErrorTooManyClusters" ],
93  "METFilters" : [ "Flag_METFilters" ],
94  }
95 )
96 )