3 from PhysicsTools.Heppy.analyzers.core.VertexHistograms
import VertexHistograms
4 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
5 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
6 from PhysicsTools.HeppyCore.statistics.average
import Average
7 from PhysicsTools.Heppy.physicsutils.PileUpSummaryInfo
import PileUpSummaryInfo
8 import PhysicsTools.HeppyCore.framework.config
as cfg
11 """selects a list of good primary vertices, 12 and optionally add a pile-up weight to MC events. 14 The list of good primary vertices is put in event.goodVertices. 15 if no good vertex is found, the process function returns False. 17 The weight is put in event.vertexWeight, and is multiplied to 18 the global event weight, event.eventWeight. 22 vertexAna = cfg.Analyzer( 24 goodVertices = 'goodPVFilter', 25 vertexWeight = 'vertexWeightFall112011AB', 26 # uncomment the following line if you want a vertex weight = 1 (no weighting) 31 If fixedWeight is set to None, the vertex weight is read from the EDM collection with module name 32 'vertexWeightFall112011AB'. 33 Otherwise, the weight is set to fixedWeight. 35 The vertex weight collection was at some point produced in the PAT+CMG step, 36 and could directly be accessed from the PAT or CMG tuple. 37 In the most recent versions of the PAT+CMG tuple, this collection is not present anymore, 38 and an additional full framework process must be ran to produce this collection, 39 so that this analyzer can read it. An example cfg to do that can be found here: 40 http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/CMG/CMGTools/H2TauTau/prod/vertexWeight2011_cfg.py?view=markup 45 def __init__(self, cfg_ana, cfg_comp, looperName):
46 super(VertexAnalyzer, self).
__init__(cfg_ana, cfg_comp, looperName)
49 if (hasattr(self.cfg_ana,
'makeHists'))
and (
not self.cfg_ana.makeHists):
55 self.
allVertices = self.cfg_ana.allVertices
if (hasattr(self.cfg_ana,
'allVertices'))
else "_AUTO_" 60 self.handles[
'vertices'] = AutoHandle(
"offlineSlimmedPrimaryVertices",
'std::vector<reco::Vertex>', fallbackLabel=
"offlinePrimaryVertices" )
62 self.handles[
'vertices'] = AutoHandle( self.
allVertices,
'std::vector<reco::Vertex>' )
64 if self.cfg_comp.isMC:
65 if hasattr( self.cfg_ana,
'fixedWeight'):
68 self.mchandles[
'vertexWeight'] = AutoHandle( self.cfg_ana.vertexWeight,
71 self.mchandles[
'pusi'] = AutoHandle(
72 'slimmedAddPileupInfo',
73 'std::vector<PileupSummaryInfo>',
74 fallbackLabel=
'addPileupInfo',
77 self.handles[
'rho'] = AutoHandle(
78 (
'fixedGridRhoFastjetAll',
''),
81 self.handles[
'rhoCN'] = AutoHandle(
82 (
'fixedGridRhoFastjetCentralNeutral',
''),
85 self.handles[
'sigma'] = AutoHandle(
86 (
'fixedGridSigmaFastjetAll',
''),
92 super(VertexAnalyzer,self).
beginLoop(setup)
93 self.averages.add(
'vertexWeight',
Average(
'vertexWeight') )
94 self.counters.addCounter(
'GoodVertex')
95 self.
count = self.counters.counter(
'GoodVertex')
96 self.count.register(
'All Events')
97 self.count.register(
'Events With Good Vertex')
101 self.readCollections(event.input )
102 event.rho = self.handles[
'rho'].product()[0]
103 event.rhoCN = self.handles[
'rhoCN'].product()[0]
104 event.sigma = self.handles[
'sigma'].product()[0]
if self.handles[
'sigma'].isValid()
else -999
105 event.vertices = self.handles[
'vertices'].product()
109 self.count.inc(
'All Events')
112 event.vertexWeight = 1
113 if self.cfg_comp.isMC:
114 event.pileUpInfo =
map( PileUpSummaryInfo,
115 self.mchandles[
'pusi'].product() )
117 event.vertexWeight = self.mchandles[
'vertexWeight'].product()[0]
120 event.eventWeight *= event.vertexWeight
122 self.averages[
'vertexWeight'].
add( event.vertexWeight )
124 print 'VertexAnalyzer: #vert = ', len(event.vertices), \
125 ', weight = ', event.vertexWeight
128 keepFailingEvents =
False 129 if hasattr( self.cfg_ana,
'keepFailingEvents'):
130 keepFailingEvents = self.cfg_ana.keepFailingEvents
131 if len(event.goodVertices)==0:
132 event.passedVertexAnalyzer=
False 133 if not keepFailingEvents:
136 event.passedVertexAnalyzer=
True 139 self.pileup.hist.Fill( len(event.goodVertices) )
143 self.count.inc(
'Events With Good Vertex')
152 if abs(vertex.z())>24:
154 if vertex.position().Rho()>2:
161 for comb
in itertools.combinations(vertices, 2):
162 dist =
abs(comb[0].z() - comb[1].z())
168 super(VertexAnalyzer, self).
write(setup)
172 setattr(VertexAnalyzer,
"defaultConfig",cfg.Analyzer(
173 class_object=VertexAnalyzer,
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
def testGoodVertex(self, vertex)
def __init__(self, cfg_ana, cfg_comp, looperName)
Abs< T >::type abs(const T &t)
static std::string join(char **cmd)
def beginLoop(self, setup)
def mindist(self, vertices)