CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Static Public Attributes
objects.VertexAnalyzer.VertexAnalyzer Class Reference
Inheritance diagram for objects.VertexAnalyzer.VertexAnalyzer:

Public Member Functions

def __init__ (self, cfg_ana, cfg_comp, looperName)
 
def beginLoop (self, setup)
 
def declareHandles (self)
 
def mindist (self, vertices)
 
def process (self, event)
 
def testGoodVertex (self, vertex)
 
def write (self, setup)
 

Public Attributes

 allVertices
 
 count
 
 doHists
 
 pileup
 

Static Public Attributes

 class_object
 
 fixedWeight
 
 verbose
 
 vertexWeight
 

Detailed Description

selects a list of good primary vertices,
and optionally add a pile-up weight to MC events.

The list of good primary vertices is put in event.goodVertices.
if no good vertex is found, the process function returns False.

The weight is put in event.vertexWeight, and is multiplied to
the global event weight, event.eventWeight. 

Example:

vertexAna = cfg.Analyzer(
  'VertexAnalyzer',
  goodVertices = 'goodPVFilter',
  vertexWeight = 'vertexWeightFall112011AB',
  # uncomment the following line if you want a vertex weight = 1 (no weighting)
  # fixedWeight = 1, 
  verbose = False
  )

If fixedWeight is set to None, the vertex weight is read from the EDM collection with module name
'vertexWeightFall112011AB'.
Otherwise, the weight is set to fixedWeight.

The vertex weight collection was at some point produced in the PAT+CMG step,
and could directly be accessed from the PAT or CMG tuple. 
In the most recent versions of the PAT+CMG tuple, this collection is not present anymore,
and an additional full framework process must be ran to produce this collection,
so that this analyzer can read it. An example cfg to do that can be found here:
http://cmssw.cvs.cern.ch/cgi-bin/cmssw.cgi/UserCode/CMG/CMGTools/H2TauTau/prod/vertexWeight2011_cfg.py?view=markup

Definition at line 10 of file VertexAnalyzer.py.

Constructor & Destructor Documentation

def objects.VertexAnalyzer.VertexAnalyzer.__init__ (   self,
  cfg_ana,
  cfg_comp,
  looperName 
)

Definition at line 45 of file VertexAnalyzer.py.

45  def __init__(self, cfg_ana, cfg_comp, looperName):
46  super(VertexAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)
47 
48  self.doHists=True
49  if (hasattr(self.cfg_ana,'makeHists')) and (not self.cfg_ana.makeHists):
50  self.doHists=False
51  if self.doHists:
52  self.pileup = VertexHistograms('/'.join([self.dirName,
53  'pileup.root']))
54 
55  self.allVertices = self.cfg_ana.allVertices if (hasattr(self.cfg_ana,'allVertices')) else "_AUTO_"
56 
def __init__(self, cfg_ana, cfg_comp, looperName)
static std::string join(char **cmd)
Definition: RemoteFile.cc:18

Member Function Documentation

def objects.VertexAnalyzer.VertexAnalyzer.beginLoop (   self,
  setup 
)

Definition at line 91 of file VertexAnalyzer.py.

References Average.

91  def beginLoop(self, setup):
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')
98 
99 
def objects.VertexAnalyzer.VertexAnalyzer.declareHandles (   self)

Definition at line 57 of file VertexAnalyzer.py.

References core.PileUpAnalyzer.PileUpAnalyzer.allVertices, objects.VertexAnalyzer.VertexAnalyzer.allVertices, analyzer.Analyzer.cfg_ana, objects.VertexAnalyzer.VertexAnalyzer.fixedWeight, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, and core.Analyzer.Analyzer.mchandles.

57  def declareHandles(self):
58  super(VertexAnalyzer, self).declareHandles()
59  if self.allVertices == '_AUTO_':
60  self.handles['vertices'] = AutoHandle( "offlineSlimmedPrimaryVertices", 'std::vector<reco::Vertex>', fallbackLabel="offlinePrimaryVertices" )
61  else:
62  self.handles['vertices'] = AutoHandle( self.allVertices, 'std::vector<reco::Vertex>' )
63  self.fixedWeight = None
64  if self.cfg_comp.isMC:
65  if hasattr( self.cfg_ana, 'fixedWeight'):
66  self.fixedWeight = self.cfg_ana.fixedWeight
67  else:
68  self.mchandles['vertexWeight'] = AutoHandle( self.cfg_ana.vertexWeight,
69  'double' )
70 
71  self.mchandles['pusi'] = AutoHandle(
72  'slimmedAddPileupInfo',
73  'std::vector<PileupSummaryInfo>',
74  fallbackLabel='addPileupInfo',
75  )
76 
77  self.handles['rho'] = AutoHandle(
78  ('fixedGridRhoFastjetAll',''),
79  'double'
80  )
81  self.handles['rhoCN'] = AutoHandle(
82  ('fixedGridRhoFastjetCentralNeutral',''),
83  'double'
84  )
85  self.handles['sigma'] = AutoHandle(
86  ('fixedGridSigmaFastjetAll',''),
87  'double',
88  mayFail=True
89  )
90 
def objects.VertexAnalyzer.VertexAnalyzer.mindist (   self,
  vertices 
)

Definition at line 159 of file VertexAnalyzer.py.

References funct.abs().

159  def mindist(self, vertices):
160  mindist = 999999
161  for comb in itertools.combinations(vertices, 2):
162  dist = abs(comb[0].z() - comb[1].z())
163  if dist<mindist:
164  mindist = dist
165  return mindist
166 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.VertexAnalyzer.VertexAnalyzer.process (   self,
  event 
)

Definition at line 100 of file VertexAnalyzer.py.

References PVValHelper.add(), analyzer.Analyzer.averages, analyzer.Analyzer.cfg_ana, core.PileUpAnalyzer.PileUpAnalyzer.doHists, objects.VertexAnalyzer.VertexAnalyzer.doHists, ALCARECOTkAlBeamHalo_cff.filter, objects.VertexAnalyzer.VertexAnalyzer.fixedWeight, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, genParticles_cff.map, core.Analyzer.Analyzer.mchandles, core.Analyzer.Analyzer.readCollections(), objects.VertexAnalyzer.VertexAnalyzer.testGoodVertex(), core.SkimAnalyzerCount.SkimAnalyzerCount.verbose, VisualizationOptions.verbose, CSCTFanalyzer.verbose, L1TdeStage2EMTF.verbose, heppy::Davismt2.verbose, L1TStage2uGMTMuon.verbose, DQMGenericTnPClient.verbose, L1TStage2EMTF.verbose, dqmTnP::AbstractFitter.verbose, L1TStage2uGMT.verbose, L1TStage2MuonComp.verbose, L1TStage2RegionalMuonCandComp.verbose, confdbOfflineConverter.OfflineConverter.verbose, ElectronStudy.verbose, L1TStage2OMTF.verbose, MuonMillepedeAlgorithm.verbose, DeviationsFromFileSensor2D.verbose, L1TStage2BMTF.verbose, core.TriggerMatchAnalyzer.TriggerMatchAnalyzer.verbose, L1TCaloLayer1.verbose, L1TCaloLayer1RawToDigi.verbose, HIPAlignmentAlgorithm.verbose, L1TCaloLayer1Validator.verbose, FFTJetLookupTableESProducer< CT >.verbose, FFTJetCorrectionESProducer< CT >.verbose, o2olib.O2OJobMgr.verbose, objects.VertexAnalyzer.VertexAnalyzer.verbose, L1TStage2uGTCaloLayer2Comp.verbose, OpticalObject.verbose, L1TdeStage2CaloLayer2.verbose, objects.LeptonAnalyzer.LeptonAnalyzer.verbose, and HltDiff.verbose.

Referenced by ConfigBuilder.ConfigBuilder.addExtraStream(), ConfigBuilder.ConfigBuilder.completeInputCommand(), ConfigBuilder.ConfigBuilder.doNotInlineEventContent(), ConfigBuilder.ConfigBuilder.PrintAllModules.leave(), ConfigBuilder.ConfigBuilder.prepare(), ConfigBuilder.ConfigBuilder.prepare_ALCA(), ConfigBuilder.ConfigBuilder.prepare_DQM(), ConfigBuilder.ConfigBuilder.prepare_HLT(), ConfigBuilder.ConfigBuilder.prepare_LHE(), ConfigBuilder.ConfigBuilder.prepare_PATFILTER(), ConfigBuilder.ConfigBuilder.prepare_VALIDATION(), ConfigBuilder.ConfigBuilder.renameHLTprocessInSequence(), ConfigBuilder.ConfigBuilder.renameInputTagsInSequence(), and ConfigBuilder.ConfigBuilder.scheduleSequence().

100  def process(self, event):
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()
106  event.goodVertices = filter(self.testGoodVertex,event.vertices)
107 
108 
109  self.count.inc('All Events')
110 
111 
112  event.vertexWeight = 1
113  if self.cfg_comp.isMC:
114  event.pileUpInfo = map( PileUpSummaryInfo,
115  self.mchandles['pusi'].product() )
116  if self.fixedWeight is None:
117  event.vertexWeight = self.mchandles['vertexWeight'].product()[0]
118  else:
119  event.vertexWeight = self.fixedWeight
120  event.eventWeight *= event.vertexWeight
121 
122  self.averages['vertexWeight'].add( event.vertexWeight )
123  if self.verbose:
124  print 'VertexAnalyzer: #vert = ', len(event.vertices), \
125  ', weight = ', event.vertexWeight
126 
127  # Check if events needs to be skipped if no good vertex is found (useful for generator level studies)
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:
134  return False
135  else:
136  event.passedVertexAnalyzer=True
137 
138  if self.doHists:
139  self.pileup.hist.Fill( len(event.goodVertices) )
140 #A.R. mindist is one of the slowest functions, default commented
141 # self.pileup.mindist.Fill( self.mindist(event.goodVertices) )
142 
143  self.count.inc('Events With Good Vertex')
144  return True
145 
146 
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
def objects.VertexAnalyzer.VertexAnalyzer.testGoodVertex (   self,
  vertex 
)

Definition at line 147 of file VertexAnalyzer.py.

References funct.abs().

Referenced by objects.VertexAnalyzer.VertexAnalyzer.process().

147  def testGoodVertex(self,vertex):
148  if vertex.isFake():
149  return False
150  if vertex.ndof()<=4:
151  return False
152  if abs(vertex.z())>24:
153  return False
154  if vertex.position().Rho()>2:
155  return False
156 
157  return True
158 
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.VertexAnalyzer.VertexAnalyzer.write (   self,
  setup 
)

Definition at line 167 of file VertexAnalyzer.py.

References core.PileUpAnalyzer.PileUpAnalyzer.doHists, and objects.VertexAnalyzer.VertexAnalyzer.doHists.

167  def write(self, setup):
168  super(VertexAnalyzer, self).write(setup)
169  if self.doHists:
170  self.pileup.write()
171 
172 setattr(VertexAnalyzer,"defaultConfig",cfg.Analyzer(

Member Data Documentation

objects.VertexAnalyzer.VertexAnalyzer.allVertices
objects.VertexAnalyzer.VertexAnalyzer.class_object
static

Definition at line 173 of file VertexAnalyzer.py.

objects.VertexAnalyzer.VertexAnalyzer.count

Definition at line 95 of file VertexAnalyzer.py.

objects.VertexAnalyzer.VertexAnalyzer.doHists
objects.VertexAnalyzer.VertexAnalyzer.fixedWeight
static
objects.VertexAnalyzer.VertexAnalyzer.pileup

Definition at line 52 of file VertexAnalyzer.py.

objects.VertexAnalyzer.VertexAnalyzer.verbose
static
objects.VertexAnalyzer.VertexAnalyzer.vertexWeight
static

Definition at line 174 of file VertexAnalyzer.py.