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