CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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__
 
def beginLoop
 
def declareHandles
 
def mindist
 
def process
 
def testGoodVertex
 
def write
 

Public Attributes

 allVertices
 
 count
 
 doHists
 
 fixedWeight
 
 pileup
 

Static Public Attributes

int fixedWeight = 1
 
 verbose = False
 
 vertexWeight = None,
 

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

Member Function Documentation

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

Definition at line 81 of file VertexAnalyzer.py.

References Average.

81 
82  def beginLoop(self, setup):
83  super(VertexAnalyzer,self).beginLoop(setup)
84  self.averages.add('vertexWeight', Average('vertexWeight') )
85  self.counters.addCounter('GoodVertex')
86  self.count = self.counters.counter('GoodVertex')
87  self.count.register('All Events')
88  self.count.register('Events With Good Vertex')
89 
def objects.VertexAnalyzer.VertexAnalyzer.declareHandles (   self)

Definition at line 57 of file VertexAnalyzer.py.

References core.PileUpAnalyzer.PileUpAnalyzer.allVertices, objects.VertexAnalyzer.VertexAnalyzer.allVertices, core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, and HTTP.RequestManager.handles.

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

Definition at line 147 of file VertexAnalyzer.py.

References funct.abs().

148  def mindist(self, vertices):
149  mindist = 999999
150  for comb in itertools.combinations(vertices, 2):
151  dist = abs(comb[0].z() - comb[1].z())
152  if dist<mindist:
153  mindist = dist
154  return mindist
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.VertexAnalyzer.VertexAnalyzer.process (   self,
  event 
)

Definition at line 90 of file VertexAnalyzer.py.

References Clusterizer1DCommons.add(), analyzer.Analyzer.averages, analyzer.Analyzer.cfg_ana, core.PileUpAnalyzer.PileUpAnalyzer.doHists, objects.VertexAnalyzer.VertexAnalyzer.doHists, alcazmumu_cfi.filter, objects.VertexAnalyzer.VertexAnalyzer.fixedWeight, core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, python.multivaluedict.map(), core.Analyzer.Analyzer.mchandles, core.Analyzer.Analyzer.readCollections(), objects.VertexAnalyzer.VertexAnalyzer.testGoodVertex(), CSCTFanalyzer.verbose, heppy::Davismt2.verbose, CalibratedPatElectronProducer.verbose, DQMGenericTnPClient.verbose, dqmTnP::AbstractFitter.verbose, CalibratedElectronProducer.verbose, confdbOfflineConverter.OfflineConverter.verbose, ElectronStudy.verbose, MuonMillepedeAlgorithm.verbose, DeviationsFromFileSensor2D.verbose, HIPAlignmentAlgorithm.verbose, FFTJetLookupTableESProducer< CT >.verbose, FFTJetCorrectionESProducer< CT >.verbose, objects.VertexAnalyzer.VertexAnalyzer.verbose, and OpticalObject.verbose.

Referenced by ConfigBuilder.ConfigBuilder.addExtraStream(), ConfigBuilder.ConfigBuilder.completeInputCommand(), ConfigBuilder.ConfigBuilder.doNotInlineEventContent(), ConfigBuilder.ConfigBuilder.PrintAllModules.leave(), 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().

90 
91  def process(self, event):
92  self.readCollections(event.input )
93  event.rho = self.handles['rho'].product()[0]
94  event.vertices = self.handles['vertices'].product()
95  event.goodVertices = filter(self.testGoodVertex,event.vertices)
96 
97 
98  self.count.inc('All Events')
99 
100 
101  event.vertexWeight = 1
102  if self.cfg_comp.isMC:
103  event.pileUpInfo = map( PileUpSummaryInfo,
104  self.mchandles['pusi'].product() )
105  if self.fixedWeight is None:
106  event.vertexWeight = self.mchandles['vertexWeight'].product()[0]
107  else:
108  event.vertexWeight = self.fixedWeight
109  event.eventWeight *= event.vertexWeight
110 
111  self.averages['vertexWeight'].add( event.vertexWeight )
112  if self.verbose:
113  print 'VertexAnalyzer: #vert = ', len(event.vertices), \
114  ', weight = ', event.vertexWeight
115 
116  # Check if events needs to be skipped if no good vertex is found (useful for generator level studies)
117  keepFailingEvents = False
118  if hasattr( self.cfg_ana, 'keepFailingEvents'):
119  keepFailingEvents = self.cfg_ana.keepFailingEvents
120  if len(event.goodVertices)==0:
121  event.passedVertexAnalyzer=False
122  if not keepFailingEvents:
123  return False
124  else:
125  event.passedVertexAnalyzer=True
126 
127  if self.doHists:
128  self.pileup.hist.Fill( len(event.goodVertices) )
129 #A.R. mindist is one of the slowest functions, default commented
130 # self.pileup.mindist.Fill( self.mindist(event.goodVertices) )
131 
132  self.count.inc('Events With Good Vertex')
133  return True
134 
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
def objects.VertexAnalyzer.VertexAnalyzer.testGoodVertex (   self,
  vertex 
)

Definition at line 135 of file VertexAnalyzer.py.

References funct.abs().

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

136  def testGoodVertex(self,vertex):
137  if vertex.isFake():
138  return False
139  if vertex.ndof()<=4:
140  return False
141  if abs(vertex.z())>24:
142  return False
143  if vertex.position().Rho()>2:
144  return False
145 
146  return True
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def objects.VertexAnalyzer.VertexAnalyzer.write (   self,
  setup 
)

Definition at line 155 of file VertexAnalyzer.py.

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

156  def write(self, setup):
157  super(VertexAnalyzer, self).write(setup)
158  if self.doHists:
159  self.pileup.write()
160 
setattr(VertexAnalyzer,"defaultConfig",cfg.Analyzer(

Member Data Documentation

objects.VertexAnalyzer.VertexAnalyzer.allVertices

Definition at line 55 of file VertexAnalyzer.py.

Referenced by objects.VertexAnalyzer.VertexAnalyzer.declareHandles().

objects.VertexAnalyzer.VertexAnalyzer.count

Definition at line 85 of file VertexAnalyzer.py.

objects.VertexAnalyzer.VertexAnalyzer.doHists

Definition at line 48 of file VertexAnalyzer.py.

Referenced by objects.VertexAnalyzer.VertexAnalyzer.process(), and objects.VertexAnalyzer.VertexAnalyzer.write().

objects.VertexAnalyzer.VertexAnalyzer.fixedWeight

Definition at line 63 of file VertexAnalyzer.py.

int objects.VertexAnalyzer.VertexAnalyzer.fixedWeight = 1
static

Definition at line 163 of file VertexAnalyzer.py.

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

objects.VertexAnalyzer.VertexAnalyzer.pileup

Definition at line 52 of file VertexAnalyzer.py.

objects.VertexAnalyzer.VertexAnalyzer.verbose = False
static

Definition at line 164 of file VertexAnalyzer.py.

Referenced by python.diff_provenance.difference.list_diff(), python.diffProv.difference.list_diff(), python.diff_provenance.difference.module_diff(), python.diffProv.difference.module_diff(), python.diff_provenance.difference.onefilemodules(), python.diffProv.difference.onefilemodules(), and objects.VertexAnalyzer.VertexAnalyzer.process().

objects.VertexAnalyzer.VertexAnalyzer.vertexWeight = None,
static

Definition at line 162 of file VertexAnalyzer.py.