1 from __future__
import print_function
4 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
5 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
6 from PhysicsTools.HeppyCore.framework.event
import Event
7 from PhysicsTools.HeppyCore.statistics.counter
import Counter, Counters
9 from DataFormats.FWLite
import Events, Handle,Lumis
16 def __init__(self, cfg_ana, cfg_comp, looperName):
17 super(SkimAnalyzerCount, self).
__init__(cfg_ana, cfg_comp, looperName)
18 self.
useLumiBlocks = self.cfg_ana.useLumiBlocks
if (hasattr(self.cfg_ana,
'useLumiBlocks'))
else False
19 self.
verbose = getattr(self.cfg_ana,
'verbose',
False)
24 self.mchandles[
'GenInfo'] = AutoHandle( (
'generator',
'',
''),
'GenEventInfoProduct' )
27 super(SkimAnalyzerCount,self).
beginLoop(setup)
29 self.counters.addCounter(
'SkimReport')
31 self.
count.register(
'All Events')
32 if self.cfg_comp.isMC:
33 self.
count.register(
'Sum Weights')
39 print(
'Counting the total events before the skim by accessing luminosity blocks')
40 lumis = Lumis(self.cfg_comp.files)
52 self.
count.inc(
'All Events',totalEvents)
53 if self.cfg_comp.isMC:
54 self.
count.inc(
'Sum Weights',totalEvents)
55 print(
'Done -> proceeding with the analysis')
57 print(
'Failed -> will have to actually count events (this can happen if the input dataset is not a CMG one)')
63 print(
"\nProcessing run:lumi:event %d:%d:%d" % (
64 event.input.eventAuxiliary().
id().
run(),
65 event.input.eventAuxiliary().
id().luminosityBlock(),
66 event.input.eventAuxiliary().
id().
event()))
68 self.readCollections( event.input )
69 self.
count.inc(
'All Events')
70 if self.cfg_comp.isMC:
71 self.
count.inc(
'Sum Weights', self.mchandles[
'GenInfo'].product().
weight())