1 from __future__
import print_function
4 from PhysicsTools.Heppy.analyzers.core.VertexHistograms
import VertexHistograms
5 from PhysicsTools.Heppy.analyzers.core.Analyzer
import Analyzer
6 from PhysicsTools.Heppy.analyzers.core.AutoHandle
import AutoHandle
7 from PhysicsTools.HeppyCore.statistics.average
import Average
8 from PhysicsTools.Heppy.physicsutils.PileUpSummaryInfo
import PileUpSummaryInfo
9 import PhysicsTools.HeppyCore.framework.config
as cfg
12 """selects a list of good primary vertices, 13 and optionally add a pile-up weight to MC events. 15 The list of good primary vertices is put in event.goodVertices. 16 if no good vertex is found, the process function returns False. 18 The weight is put in event.vertexWeight, and is multiplied to 19 the global event weight, event.eventWeight. 23 vertexAna = cfg.Analyzer( 25 goodVertices = 'goodPVFilter', 26 vertexWeight = 'vertexWeightFall112011AB', 27 # uncomment the following line if you want a vertex weight = 1 (no weighting) 32 If fixedWeight is set to None, the vertex weight is read from the EDM collection with module name 33 'vertexWeightFall112011AB'. 34 Otherwise, the weight is set to fixedWeight. 36 The vertex weight collection was at some point produced in the PAT+CMG step, 37 and could directly be accessed from the PAT or CMG tuple. 38 In the most recent versions of the PAT+CMG tuple, this collection is not present anymore, 39 and an additional full framework process must be ran to produce this collection, 40 so that this analyzer can read it. An example cfg to do that can be found here: 41 http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/CMG/CMGTools/H2TauTau/prod/vertexWeight2011_cfg.py?view=markup 46 def __init__(self, cfg_ana, cfg_comp, looperName):
47 super(VertexAnalyzer, self).
__init__(cfg_ana, cfg_comp, looperName)
50 if (hasattr(self.cfg_ana,
'makeHists'))
and (
not self.cfg_ana.makeHists):
56 self.
allVertices = self.cfg_ana.allVertices
if (hasattr(self.cfg_ana,
'allVertices'))
else "_AUTO_" 61 self.handles[
'vertices'] = AutoHandle(
"offlineSlimmedPrimaryVertices",
'std::vector<reco::Vertex>', fallbackLabel=
"offlinePrimaryVertices" )
63 self.handles[
'vertices'] = AutoHandle( self.
allVertices,
'std::vector<reco::Vertex>' )
65 if self.cfg_comp.isMC:
66 if hasattr( self.cfg_ana,
'fixedWeight'):
69 self.mchandles[
'vertexWeight'] = AutoHandle( self.cfg_ana.vertexWeight,
72 self.mchandles[
'pusi'] = AutoHandle(
73 'slimmedAddPileupInfo',
74 'std::vector<PileupSummaryInfo>',
75 fallbackLabel=
'addPileupInfo',
78 self.handles[
'rho'] = AutoHandle(
79 (
'fixedGridRhoFastjetAll',
''),
82 self.handles[
'rhoCN'] = AutoHandle(
83 (
'fixedGridRhoFastjetCentralNeutral',
''),
86 self.handles[
'sigma'] = AutoHandle(
87 (
'fixedGridSigmaFastjetAll',
''),
93 super(VertexAnalyzer,self).
beginLoop(setup)
94 self.averages.add(
'vertexWeight',
Average(
'vertexWeight') )
95 self.counters.addCounter(
'GoodVertex')
96 self.
count = self.counters.counter(
'GoodVertex')
97 self.count.register(
'All Events')
98 self.count.register(
'Events With Good Vertex')
102 self.readCollections(event.input )
103 event.rho = self.handles[
'rho'].product()[0]
104 event.rhoCN = self.handles[
'rhoCN'].product()[0]
105 event.sigma = self.handles[
'sigma'].product()[0]
if self.handles[
'sigma'].isValid()
else -999
106 event.vertices = self.handles[
'vertices'].product()
110 self.count.inc(
'All Events')
113 event.vertexWeight = 1
114 if self.cfg_comp.isMC:
115 event.pileUpInfo =
map( PileUpSummaryInfo,
116 self.mchandles[
'pusi'].product() )
118 event.vertexWeight = self.mchandles[
'vertexWeight'].product()[0]
121 event.eventWeight *= event.vertexWeight
123 self.averages[
'vertexWeight'].
add( event.vertexWeight )
125 print(
'VertexAnalyzer: #vert = ', len(event.vertices), \
126 ', weight = ', event.vertexWeight)
129 keepFailingEvents =
False 130 if hasattr( self.cfg_ana,
'keepFailingEvents'):
131 keepFailingEvents = self.cfg_ana.keepFailingEvents
132 if len(event.goodVertices)==0:
133 event.passedVertexAnalyzer=
False 134 if not keepFailingEvents:
137 event.passedVertexAnalyzer=
True 140 self.pileup.hist.Fill( len(event.goodVertices) )
144 self.count.inc(
'Events With Good Vertex')
153 if abs(vertex.z())>24:
155 if vertex.position().Rho()>2:
162 for comb
in itertools.combinations(vertices, 2):
163 dist =
abs(comb[0].z() - comb[1].z())
169 super(VertexAnalyzer, self).
write(setup)
173 setattr(VertexAnalyzer,
"defaultConfig",cfg.Analyzer(
174 class_object=VertexAnalyzer,
def testGoodVertex(self, vertex)
S & print(S &os, JobReport::InputFile const &f)
def __init__(self, cfg_ana, cfg_comp, looperName)
Abs< T >::type abs(const T &t)
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
static std::string join(char **cmd)
def beginLoop(self, setup)
def mindist(self, vertices)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run