Skip to content

Commit

Permalink
Merge pull request cms-sw#187 from gpetruc/CMGTools-from-CMSSW_7_2_3
Browse files Browse the repository at this point in the history
TimeReport functionality, and heppy bugfixes.
  • Loading branch information
gpetruc committed Dec 19, 2014
2 parents 2440eb3 + 086d7be commit 48a06eb
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 16 deletions.
20 changes: 17 additions & 3 deletions CMGTools/TTHAnalysis/cfg/run_susyMultilepton_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#ttHLepSkim.ptCuts = []


# switch off slow photon MC matching
photonAna.do_mc_match = False

# Event Analyzer for susy multi-lepton (at the moment, it's the TTH one)
from CMGTools.TTHAnalysis.analyzers.ttHLepEventAnalyzer import ttHLepEventAnalyzer
ttHEventAna = cfg.Analyzer(
Expand Down Expand Up @@ -57,9 +60,9 @@
#-------- SAMPLES AND TRIGGERS -----------

#-------- SEQUENCE
from CMGTools.TTHAnalysis.samples.samples_13TeV_PHYS14 import TTH_PU40bx25, SMS_T1tttt_2J_mGl1500_mLSP100
from CMGTools.TTHAnalysis.samples.samples_13TeV_PHYS14 import *

selectedComponents = [ TTH_PU40bx25 ]
selectedComponents = [ SMS_T1tttt_2J_mGl1200_mLSP800 ]

sequence = cfg.Sequence(susyCoreSequence+[
ttHEventAna,
Expand All @@ -68,11 +71,22 @@

test = 1
if test == 1:
comp = TTH_PU40bx25; comp.name = "TTH"
comp = TTH; comp.name = "TTH"
#comp = SMS_T1tttt_2J_mGl1500_mLSP100
comp.files = comp.files[:1]
comp.splitFactor = 1
comp.fineSplitFactor = 4
selectedComponents = [ comp ]
elif test == 2:
for comp in selectedComponents:
comp.files = comp.files[:1]
comp.splitFactor = 1
elif test == 3:
comp = TTJets
comp.files = comp.files[:1]
comp.splitFactor = 1
selectedComponents = [ comp ]


# the following is declared in case this cfg is used in input to the heppy.py script
from PhysicsTools.HeppyCore.framework.eventsfwlite import Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@
photons='slimmedPhotons',
ptMin = 20,
etaMax = 2.5,
gammaID = "PhotonCutBasedIDLoose_CSA14"
gammaID = "PhotonCutBasedIDLoose_CSA14",
do_mc_match = True,
)


Expand Down
4 changes: 2 additions & 2 deletions CMGTools/TTHAnalysis/python/plotter/bins/validation_plots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ lep1sip3d: LepGood1_sip3d: 15,0,5; Legend='TR'
lep2sip3d: LepGood2_sip3d: 15,0,5; Legend='TR'
lep1tightId: LepGood1_tightId: [-0.5,0.5,1.5]; Legend='TL'
lep2tightId: LepGood2_tightId: [-0.5,0.5,1.5]; Legend='TL'
lep1mvaTTH: LepGood1_mvaTTH: 20,-1,1; Legend='TL'
lep2mvaTTH: LepGood2_mvaTTH: 20,-1,1; Legend='TL'
lep1mvaSusy: LepGood1_mvaSusy: 20,-1,1; Legend='TL'
lep2mvaSusy: LepGood2_mvaSusy: 20,-1,1; Legend='TL'
lep1mcMatchId: abs(LepGood1_mcMatchId): 28,-1.5,26.5; Legend='TR'
lep2mcMatchId: abs(LepGood2_mcMatchId): 28,-1.5,26.5; Legend='TR'
lep1mcMatchAny: LepGood1_mcMatchAny: [-1.5,-0.5,0.5,1.5,2.5,3.5]; Legend='TR'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def declareCoreVariables(self, tr, isMC):
tr.var('lumi', int, storageType="i")
tr.var('evt', int, storageType="i")
tr.var('isData', int)
tr.var('xsec', float)

# self.triggerBitCheckers = []
# if hasattr(self.cfg_ana, 'triggerBits'):
Expand All @@ -62,6 +61,8 @@ def declareCoreVariables(self, tr, isMC):
# self.triggerBitCheckers.append( (T, TriggerBitChecker(trigVec)) )

if isMC:
## cross section
tr.var('xsec', float)
## PU weights
tr.var("puWeight")
## number of true interactions
Expand Down Expand Up @@ -109,13 +110,14 @@ def fillCoreVariables(self, tr, event, isMC):
tr.fill('lumi',event.input.eventAuxiliary().id().luminosityBlock())
tr.fill('evt', event.input.eventAuxiliary().id().event())
tr.fill('isData', 0 if isMC else 1)
tr.fill('xsec',self.cfg_comp.xSection)

# triggerResults = self.handles['TriggerResults'].product()
# for T,TC in self.triggerBitCheckers:
# tr.fill("HLT_"+T, TC.check(event.object(), triggerResults))

if isMC:
## xsection, if available
tr.fill('xsec', getattr(self.cfg_comp,'xSection',1.0))
## PU weights, check if a PU analyzer actually filled it
if hasattr(event,"nPU"):
tr.fill("nTrueInt", event.nPU)
Expand Down
3 changes: 2 additions & 1 deletion PhysicsTools/Heppy/python/physicsobjects/GenParticle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ def printGenParticle(self):
return theStr
setattr(ROOT.reco.GenParticle,"__str__",printGenParticle)

from ROOT.reco import GenParticle
#from ROOT.reco import GenParticle # sometimes doesn't work
GenParticle = ROOT.reco.GenParticle # this instead does
9 changes: 8 additions & 1 deletion PhysicsTools/HeppyCore/python/framework/heppy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def runLoop( comp, outDir, config, options):
loop = Looper( fullName,
config,
options.nevents, 0,
nPrint = options.nprint)
nPrint = options.nprint,
timeReport = options.timeReport)
print loop
if options.iEvent is None:
loop.loop()
Expand Down Expand Up @@ -202,6 +203,12 @@ def main( options, args ):
action='store_true',
help="stay in the command line prompt instead of exiting",
default=False)
parser.add_option("-t", "--timereport",
dest="timeReport",
action='store_true',
help="Make a report of the time used by each analyzer",
default=False)



(options,args) = parser.parse_args()
Expand Down
28 changes: 22 additions & 6 deletions PhysicsTools/HeppyCore/python/framework/looper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from platform import platform
from math import ceil
from event import Event
import time
import timeit

class Setup(object):
'''The Looper creates a Setup object to hold information relevant during
Expand Down Expand Up @@ -52,7 +52,7 @@ class Looper(object):
def __init__( self, name,
config,
nEvents=None,
firstEvent=0, nPrint=0 ):
firstEvent=0, nPrint=0, timeReport=False ):
"""Handles the processing of an event sample.
An Analyzer is built for each Config.Analyzer present
in sequence. The Looper can then be used to process an event,
Expand All @@ -79,6 +79,7 @@ def __init__( self, name,
self.nEvents = nEvents
self.firstEvent = firstEvent
self.nPrint = int(nPrint)
self.timeReport = [ {'time':0.0,'events':0} for a in self.analyzers ] if timeReport else False
tree_name = None
if( hasattr(self.cfg_comp, 'tree_name') ):
tree_name = self.cfg_comp.tree_name
Expand Down Expand Up @@ -158,10 +159,10 @@ def loop(self):
# print 'event', iEv
if not hasattr(self,'start_time'):
print 'event', iEv
self.start_time = time.time()
self.start_time = timeit.default_timer()
self.start_time_event = iEv
else:
print 'event %d (%.1f ev/s)' % (iEv, (iEv-self.start_time_event)/float(time.time() - self.start_time))
print 'event %d (%.1f ev/s)' % (iEv, (iEv-self.start_time_event)/float(timeit.default_timer() - self.start_time))

self.process( iEv )
if iEv<self.nPrint:
Expand All @@ -186,10 +187,16 @@ def process(self, iEv ):
"""
self.event = Event(iEv, self.events[iEv], self.setup)
self.iEvent = iEv
for analyzer in self.analyzers:
for i,analyzer in enumerate(self.analyzers):
if not analyzer.beginLoopCalled:
analyzer.beginLoop()
if analyzer.process( self.event ) == False:
start = timeit.default_timer()
ret = analyzer.process( self.event )
if self.timeReport:
self.timeReport[i]['events'] += 1
if self.timeReport[i]['events'] > 0:
self.timeReport[i]['time'] += timeit.default_timer() - start
if ret == False:
return (False, analyzer.name)
return (True, analyzer.name)

Expand All @@ -201,6 +208,15 @@ def write(self):
for analyzer in self.analyzers:
analyzer.write(self.setup)
self.setup.close()

if self.timeReport:
allev = max([x['events'] for x in self.timeReport])
print "\n ---- TimeReport (all times in ms; first evt is skipped) ---- "
print "%9s %9s %9s %9s %s" % ("processed","all evts","time/proc", " time/all", "analyer")
print "%9s %9s %9s %9s %s" % ("---------","--------","---------", "---------", "-------------")
for ana,rep in zip(self.analyzers,self.timeReport):
print "%9d %9d %10.2f %10.2f %s" % ( rep['events'], allev, 1000*rep['time']/(rep['events']-1) if rep['events']>1 else 0, 1000*rep['time']/(allev-1) if allev > 1 else 0, ana.name)
print ""
pass


Expand Down

0 comments on commit 48a06eb

Please sign in to comment.