From 5be700a78fe7b582b1b91f42bc16f7f6ba81aee5 Mon Sep 17 00:00:00 2001 From: Andrea Date: Fri, 19 Dec 2014 11:36:39 +0100 Subject: [PATCH] Add default configs and option to store individual bits for trigger studies --- .../analyzers/core/TriggerBitAnalyzer.py | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py b/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py index 7cf022904f42a..5e9195fc5bdc3 100644 --- a/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py +++ b/PhysicsTools/Heppy/python/analyzers/core/TriggerBitAnalyzer.py @@ -3,12 +3,15 @@ from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer from PhysicsTools.Heppy.analyzers.core.AutoHandle import AutoHandle from PhysicsTools.Heppy.analyzers.core.AutoFillTreeProducer import NTupleVariable +import PhysicsTools.HeppyCore.framework.config as cfg class TriggerBitAnalyzer( Analyzer ): def __init__(self, cfg_ana, cfg_comp, looperName ): super(TriggerBitAnalyzer,self).__init__(cfg_ana,cfg_comp,looperName) self.processName = getattr(self.cfg_ana,"processName","HLT") self.outprefix = getattr(self.cfg_ana,"outprefix", self.processName) + self.unrollbits = ( hasattr(self.cfg_ana,"unrollbits") and self.cfg_ana.unrollbits ) + def declareHandles(self): super(TriggerBitAnalyzer, self).declareHandles() @@ -17,15 +20,31 @@ def declareHandles(self): def beginLoop(self, setup): super(TriggerBitAnalyzer,self).beginLoop(setup) self.triggerBitCheckers = [] + if self.unrollbits : + self.allPaths = set() + self.triggerBitCheckersSingleBits = [] + for T, TL in self.cfg_ana.triggerBits.iteritems(): trigVec = ROOT.vector(ROOT.string)() for TP in TL: trigVec.push_back(TP) - outname="%s_%s"%(self.outprefix,T) + if self.unrollbits : + if TP not in self.allPaths : + self.allPaths.update(TP) + trigVecBit = ROOT.vector(ROOT.string)() + trigVecBit.push_back(TP) + outname="%s_BIT_%s"%(self.outprefix,TP) + if not hasattr(setup ,"globalVariables") : + setup.globalVariables = [] + setup.globalVariables.append( NTupleVariable(outname, eval("lambda ev: ev.%s" % outname), help="Trigger bit %s"%TP) ) + self.triggerBitCheckersSingleBits.append( (TP, ROOT.heppy.TriggerBitChecker(trigVecBit)) ) + + outname="%s_%s"%(self.outprefix,T) if not hasattr(setup ,"globalVariables") : setup.globalVariables = [] setup.globalVariables.append( NTupleVariable(outname, eval("lambda ev: ev.%s" % outname), help="OR of %s"%TL) ) self.triggerBitCheckers.append( (T, ROOT.heppy.TriggerBitChecker(trigVec)) ) + def process(self, event): self.readCollections( event.input ) @@ -33,6 +52,40 @@ def process(self, event): for T,TC in self.triggerBitCheckers: outname="%s_%s"%(self.outprefix,T) setattr(event,outname, TC.check(event.input.object(), triggerResults)) + if self.unrollbits : + for TP,TC in self.triggerBitCheckersSingleBits: + outname="%s_BIT_%s"%(self.outprefix,TP) + setattr(event,outname, TC.check(event.input.object(), triggerResults)) + return True + +setattr(TriggerBitAnalyzer,"defaultConfig",cfg.Analyzer( + TriggerBitAnalyzer, name="TriggerFlags", + processName = 'HLT', + triggerBits = { + # "" : [ 'HLT__v*', 'HLT__v*' ] +} +) +) +setattr(TriggerBitAnalyzer,"defaultEventFlagsConfig",cfg.Analyzer( + TriggerBitAnalyzer, name="EventFlags", + processName = 'PAT', + outprefix = 'Flag', + triggerBits = { + "HBHENoiseFilter" : [ "Flag_HBHENoiseFilter" ], + "CSCTightHaloFilter" : [ "Flag_CSCTightHaloFilter" ], + "hcalLaserEventFilter" : [ "Flag_hcalLaserEventFilter" ], + "EcalDeadCellTriggerPrimitiveFilter" : [ "Flag_EcalDeadCellTriggerPrimitiveFilter" ], + "goodVertices" : [ "Flag_goodVertices" ], + "trackingFailureFilter" : [ "Flag_trackingFailureFilter" ], + "eeBadScFilter" : [ "Flag_eeBadScFilter" ], + "ecalLaserCorrFilter" : [ "Flag_ecalLaserCorrFilter" ], + "trkPOGFilters" : [ "Flag_trkPOGFilters" ], + "trkPOG_manystripclus53X" : [ "Flag_trkPOG_manystripclus53X" ], + "trkPOG_toomanystripclus53X" : [ "Flag_trkPOG_toomanystripclus53X" ], + "trkPOG_logErrorTooManyClusters" : [ "Flag_trkPOG_logErrorTooManyClusters" ], + } +) +)