CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 11 of file VertexAnalyzer.py.

Constructor & Destructor Documentation

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

Definition at line 46 of file VertexAnalyzer.py.

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

Member Function Documentation

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

Definition at line 92 of file VertexAnalyzer.py.

References Average.

92 
93  def beginLoop(self, setup):
94  super(VertexAnalyzer,self).beginLoop(setup)
95  self.averages.add('vertexWeight', Average('vertexWeight') )
96  self.counters.addCounter('GoodVertex')
97  self.count = self.counters.counter('GoodVertex')
98  self.count.register('All Events')
99  self.count.register('Events With Good Vertex')
100 
def objects.VertexAnalyzer.VertexAnalyzer.declareHandles (   self)

Definition at line 58 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.

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

Definition at line 160 of file VertexAnalyzer.py.

References funct.abs().

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

Definition at line 101 of file VertexAnalyzer.py.

References PVValHelper.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, sistrip::SpyUtilities.isValid(), core.Analyzer.Analyzer.mchandles, print(), core.Analyzer.Analyzer.readCollections(), objects.VertexAnalyzer.VertexAnalyzer.testGoodVertex(), core.SkimAnalyzerCount.SkimAnalyzerCount.verbose, VisualizationOptions.verbose, CSCTFanalyzer.verbose, L1TdeStage2EMTF.verbose, L1TStage2uGMTMuon.verbose, L1TStage2EMTF.verbose, L1TStage2RegionalShower.verbose, heppy::Davismt2.verbose, DQMGenericTnPClient.verbose, dqmTnP::AbstractFitter.verbose, L1TStage2OMTF.verbose, TritonService::FallbackOpts.verbose, DeviationsFromFileSensor2D.verbose, L1TStage2BMTF.verbose, confdbOfflineConverter.OfflineConverter.verbose, L1TStage2MuonComp.verbose, core.TriggerMatchAnalyzer.TriggerMatchAnalyzer.verbose, L1TStage2RegionalMuonCandComp.verbose, L1TCaloLayer1.verbose, L1TCaloLayer1RawToDigi.verbose, L1TCaloSummary.verbose, L1TCaloLayer1Validator.verbose, HIPAlignmentAlgorithm.verbose, FFTJetLookupTableESProducer< CT >.verbose, FFTJetCorrectionESProducer< CT >.verbose, BeamSpotDipServer.verbose, o2olib.O2OJobMgr.verbose, objects.VertexAnalyzer.VertexAnalyzer.verbose, L1TStage2uGTCaloLayer2Comp.verbose, OpticalObject.verbose, L1TdeStage2CaloLayer2.verbose, and HltDiff.verbose.

102  def process(self, event):
103  self.readCollections(event.input )
104  event.rho = self.handles['rho'].product()[0]
105  event.rhoCN = self.handles['rhoCN'].product()[0]
106  event.sigma = self.handles['sigma'].product()[0] if self.handles['sigma'].isValid() else -999
107  event.vertices = self.handles['vertices'].product()
108  event.goodVertices = list(filter(self.testGoodVertex,event.vertices))
109 
110 
111  self.count.inc('All Events')
112 
113 
114  event.vertexWeight = 1
115  if self.cfg_comp.isMC:
116  event.pileUpInfo = map( PileUpSummaryInfo,
117  self.mchandles['pusi'].product() )
118  if self.fixedWeight is None:
119  event.vertexWeight = self.mchandles['vertexWeight'].product()[0]
120  else:
121  event.vertexWeight = self.fixedWeight
122  event.eventWeight *= event.vertexWeight
123 
124  self.averages['vertexWeight'].add( event.vertexWeight )
125  if self.verbose:
126  print('VertexAnalyzer: #vert = ', len(event.vertices), \
127  ', weight = ', event.vertexWeight)
128 
129  # Check if events needs to be skipped if no good vertex is found (useful for generator level studies)
130  keepFailingEvents = False
131  if hasattr( self.cfg_ana, 'keepFailingEvents'):
132  keepFailingEvents = self.cfg_ana.keepFailingEvents
133  if len(event.goodVertices)==0:
134  event.passedVertexAnalyzer=False
135  if not keepFailingEvents:
136  return False
137  else:
138  event.passedVertexAnalyzer=True
139 
140  if self.doHists:
141  self.pileup.hist.Fill( len(event.goodVertices) )
142 #A.R. mindist is one of the slowest functions, default commented
143 # self.pileup.mindist.Fill( self.mindist(event.goodVertices) )
144 
145  self.count.inc('Events With Good Vertex')
146  return True
147 
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
def objects.VertexAnalyzer.VertexAnalyzer.testGoodVertex (   self,
  vertex 
)

Definition at line 148 of file VertexAnalyzer.py.

References funct.abs().

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

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

Definition at line 168 of file VertexAnalyzer.py.

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

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

Member Data Documentation

objects.VertexAnalyzer.VertexAnalyzer.allVertices

Definition at line 56 of file VertexAnalyzer.py.

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

objects.VertexAnalyzer.VertexAnalyzer.count

Definition at line 96 of file VertexAnalyzer.py.

objects.VertexAnalyzer.VertexAnalyzer.doHists

Definition at line 49 of file VertexAnalyzer.py.

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

objects.VertexAnalyzer.VertexAnalyzer.fixedWeight

Definition at line 64 of file VertexAnalyzer.py.

int objects.VertexAnalyzer.VertexAnalyzer.fixedWeight = 1
static

Definition at line 176 of file VertexAnalyzer.py.

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

objects.VertexAnalyzer.VertexAnalyzer.pileup

Definition at line 53 of file VertexAnalyzer.py.

objects.VertexAnalyzer.VertexAnalyzer.verbose = False
static

Definition at line 177 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 175 of file VertexAnalyzer.py.