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
core.AutoFillTreeProducer.AutoFillTreeProducer Class Reference
Inheritance diagram for core.AutoFillTreeProducer.AutoFillTreeProducer:

Public Member Functions

def __init__
 
def beginLoop
 
def declareCoreVariables
 
def declareHandles
 
def declareVariables
 cross section More...
 
def fillCoreVariables
 
def fillTree
 
def getPythonWrapper
 
def process
 

Public Attributes

 collections
 Read whether we want 4-vectors. More...
 
 globalObjects
 
 globalVariables
 
 scalar
 Read whether we want vectors or flat trees. More...
 

Detailed Description

Definition at line 8 of file AutoFillTreeProducer.py.

Constructor & Destructor Documentation

def core.AutoFillTreeProducer.AutoFillTreeProducer.__init__ (   self,
  cfg_ana,
  cfg_comp,
  looperName 
)

Definition at line 13 of file AutoFillTreeProducer.py.

13 
14  def __init__(self, cfg_ana, cfg_comp, looperName):
15  super(AutoFillTreeProducer,self).__init__(cfg_ana, cfg_comp, looperName)
16 
17  ## Read whether we want vectors or flat trees
18  self.scalar = not self.cfg_ana.vectorTree
19 
20  ## Read whether we want 4-vectors
21  if not getattr(self.cfg_ana, 'saveTLorentzVectors', False):
22  fourVectorType.removeVariable("p4")
23 
24 
25  self.collections = {}
26  self.globalObjects = {}
27  self.globalVariables = []
28  if hasattr(cfg_ana,"collections"):
29  self.collections.update(cfg_ana.collections)
30  if hasattr(cfg_ana,"globalObjects"):
31  self.globalObjects.update(cfg_ana.globalObjects)
32  if hasattr(cfg_ana,"globalVariables"):
33  self.globalVariables=cfg_ana.globalVariables[:]
scalar
Read whether we want vectors or flat trees.

Member Function Documentation

def core.AutoFillTreeProducer.AutoFillTreeProducer.beginLoop (   self,
  setup 
)

Definition at line 34 of file AutoFillTreeProducer.py.

34 
35  def beginLoop(self, setup) :
36  super(AutoFillTreeProducer, self).beginLoop(setup)
def core.AutoFillTreeProducer.AutoFillTreeProducer.declareCoreVariables (   self,
  tr,
  isMC 
)
Here we declare the variables that we always want and that are hard-coded

Definition at line 45 of file AutoFillTreeProducer.py.

References analyzer.Analyzer.cfg_ana, core.AutoFillTreeProducer.AutoFillTreeProducer.scalar, and DQMNet::Object.scalar.

Referenced by core.AutoFillTreeProducer.AutoFillTreeProducer.declareVariables().

45 
46  def declareCoreVariables(self, tr, isMC):
47  """Here we declare the variables that we always want and that are hard-coded"""
48  tr.var('run', int, storageType="i")
49  tr.var('lumi', int, storageType="i")
50  tr.var('evt', int, storageType="l")
51  tr.var('isData', int)
def core.AutoFillTreeProducer.AutoFillTreeProducer.declareHandles (   self)

Definition at line 37 of file AutoFillTreeProducer.py.

References core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, and core.Analyzer.Analyzer.mchandles.

37 
38  def declareHandles(self):
39  super(AutoFillTreeProducer, self).declareHandles()
40 # self.handles['TriggerResults'] = AutoHandle( ('TriggerResults','','HLT'), 'edm::TriggerResults' )
41  self.mchandles['GenInfo'] = AutoHandle( ('generator','',''), 'GenEventInfoProduct' )
42  for k,v in self.collections.iteritems():
43  if type(v) == tuple and isinstance(v[0], AutoHandle):
44  self.handles[k] = v[0]
def core.AutoFillTreeProducer.AutoFillTreeProducer.declareVariables (   self,
  setup 
)

cross section

PU weights number of true interactions generator weight PDF weights

Definition at line 83 of file AutoFillTreeProducer.py.

References analyzer.Analyzer.cfg_ana, core.AutoFillTreeProducer.AutoFillTreeProducer.declareCoreVariables(), core.AutoFillTreeProducer.AutoFillTreeProducer.globalVariables, core.AutoFillTreeProducer.AutoFillTreeProducer.scalar, DQMNet::Object.scalar, tree.Tree.tree, SimpleTreeProducer.SimpleTreeProducer.tree, eventstfile.Events.tree, CSCTFanalyzer.tree, RootChamberWriter.tree(), CSCTFAnalyzer.tree, core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.tree, HcalTestHistoManager.tree, TreeWriterForEcalCorrection.tree, TkOfflineVariables.tree, AlignmentIORootBase.tree, edm::DuplicateTreeSentry.tree(), IsolatedParticlesGeneratedJets.tree, KVFTest.tree, EcalPerEvtMatacqAnalyzer.tree, CheckSecondary.tree, ShallowTree.tree, FWFileEntry.tree(), EcalDeadChannelRecoveryNN< DetIdT >::MultiLayerPerceptronContext.tree, edm::RootOutputTree.tree(), TreeSaver.tree, EcalMatacqAnalyzer.tree, PhysicsTools::TreeReader.tree, edm::FileBlock.tree(), HcalIsoTrkAnalyzer.tree, python.cmstools.EventTree.tree(), KinematicVertex.tree, IsoTrackCalibration.tree, IsoTrackCalib.tree, KinematicParticle.tree, edm::RootTree.tree(), IsolatedGenParticles.tree, IsolatedTracksHcalScale.tree, IsolatedTracksNxN.tree, and svgfig.SVG.tree().

83 
84  def declareVariables(self,setup):
85  isMC = self.cfg_comp.isMC
86  tree = self.tree
87  self.declareCoreVariables(tree, isMC)
88 
89  if not hasattr(self.cfg_ana,"ignoreAnalyzerBookings") or not self.cfg_ana.ignoreAnalyzerBookings :
90  #import variables declared by the analyzers
91  if hasattr(setup,"globalVariables"):
92  self.globalVariables+=setup.globalVariables
93  if hasattr(setup,"globalObjects"):
94  self.globalObjects.update(setup.globalObjects)
95  if hasattr(setup,"collections"):
96  self.collections.update(setup.collections)
97 
98  for v in self.globalVariables:
99  v.makeBranch(tree, isMC)
100  for o in self.globalObjects.itervalues():
101  o.makeBranches(tree, isMC)
102  for c in self.collections.itervalues():
103  if type(c) == tuple: c = c[-1]
104  if self.scalar:
105  c.makeBranchesScalar(tree, isMC)
106  else:
107  c.makeBranchesVector(tree, isMC)
scalar
Read whether we want vectors or flat trees.
def core.AutoFillTreeProducer.AutoFillTreeProducer.fillCoreVariables (   self,
  tr,
  event,
  isMC 
)
Here we fill the variables that we always want and that are hard-coded

Definition at line 108 of file AutoFillTreeProducer.py.

References analyzer.Analyzer.cfg_comp, looper.Looper.cfg_comp, core.Analyzer.Analyzer.mchandles, DTTTrigCorrFirst.run, core.AutoFillTreeProducer.AutoFillTreeProducer.scalar, and DQMNet::Object.scalar.

Referenced by core.AutoFillTreeProducer.AutoFillTreeProducer.fillTree().

109  def fillCoreVariables(self, tr, event, isMC):
110  """Here we fill the variables that we always want and that are hard-coded"""
111  tr.fill('run', event.input.eventAuxiliary().id().run())
112  tr.fill('lumi',event.input.eventAuxiliary().id().luminosityBlock())
113  tr.fill('evt', event.input.eventAuxiliary().id().event())
114  tr.fill('isData', 0 if isMC else 1)
115 
116 # triggerResults = self.handles['TriggerResults'].product()
117 # for T,TC in self.triggerBitCheckers:
118 # tr.fill("HLT_"+T, TC.check(event.object(), triggerResults))
119 
120  if not isMC:
121  tr.fill('intLumi', getattr(self.cfg_comp,'intLumi',1.0))
122 
123  if isMC:
124  ## xsection, if available
125  tr.fill('xsec', getattr(self.cfg_comp,'xSection',1.0))
126  ## PU weights, check if a PU analyzer actually filled it
127  if hasattr(event,"nPU"):
128  tr.fill("nTrueInt", event.nPU)
129  tr.fill("puWeight", event.puWeight)
130  else :
131  tr.fill("nTrueInt", -1)
132  tr.fill("puWeight", 1.0)
133 
134  tr.fill("genWeight", self.mchandles['GenInfo'].product().weight())
135  ## PDF weights
136  if hasattr(event,"pdfWeights") :
137  for (pdf,nvals) in self.pdfWeights:
138  if len(event.pdfWeights[pdf]) != nvals:
139  raise RuntimeError, "PDF lenght mismatch for %s, declared %d but the event has %d" % (pdf,nvals,event.pdfWeights[pdf])
140  if self.scalar:
141  for i,w in enumerate(event.pdfWeights[pdf]):
142  tr.fill('pdfWeight_%s_%d' % (pdf,i), w)
143  else:
144  tr.vfill('pdfWeight_%s' % pdf, event.pdfWeights[pdf])
scalar
Read whether we want vectors or flat trees.
Definition: weight.py:1
Definition: event.py:1
def core.AutoFillTreeProducer.AutoFillTreeProducer.fillTree (   self,
  event,
  resetFirst = True 
)

Definition at line 152 of file AutoFillTreeProducer.py.

References core.AutoFillTreeProducer.AutoFillTreeProducer.fillCoreVariables(), core.AutoFillTreeProducer.AutoFillTreeProducer.globalVariables, core.AutoHandle.AutoHandle.handles, core.Analyzer.Analyzer.handles, HTTP.RequestManager.handles, core.AutoFillTreeProducer.AutoFillTreeProducer.scalar, DQMNet::Object.scalar, tree.Tree.tree, SimpleTreeProducer.SimpleTreeProducer.tree, eventstfile.Events.tree, CSCTFanalyzer.tree, RootChamberWriter.tree(), CSCTFAnalyzer.tree, core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.tree, HcalTestHistoManager.tree, TreeWriterForEcalCorrection.tree, TkOfflineVariables.tree, AlignmentIORootBase.tree, edm::DuplicateTreeSentry.tree(), IsolatedParticlesGeneratedJets.tree, KVFTest.tree, EcalPerEvtMatacqAnalyzer.tree, CheckSecondary.tree, ShallowTree.tree, FWFileEntry.tree(), EcalDeadChannelRecoveryNN< DetIdT >::MultiLayerPerceptronContext.tree, edm::RootOutputTree.tree(), TreeSaver.tree, EcalMatacqAnalyzer.tree, PhysicsTools::TreeReader.tree, edm::FileBlock.tree(), HcalIsoTrkAnalyzer.tree, python.cmstools.EventTree.tree(), KinematicVertex.tree, IsoTrackCalibration.tree, IsoTrackCalib.tree, KinematicParticle.tree, edm::RootTree.tree(), IsolatedGenParticles.tree, IsolatedTracksHcalScale.tree, IsolatedTracksNxN.tree, and svgfig.SVG.tree().

Referenced by core.AutoFillTreeProducer.AutoFillTreeProducer.process().

153  def fillTree(self, event, resetFirst=True):
154  isMC = self.cfg_comp.isMC
155  if resetFirst: self.tree.reset()
156 
157  self.fillCoreVariables(self.tree, event, isMC)
158 
159  for v in self.globalVariables:
160  if not isMC and v.mcOnly: continue
161  v.fillBranch(self.tree, event, isMC)
162 
163  for on, o in self.globalObjects.iteritems():
164  if not isMC and o.mcOnly: continue
165  o.fillBranches(self.tree, getattr(event, on), isMC)
166 
167  for cn, c in self.collections.iteritems():
168  if type(c) == tuple and isinstance(c[0], AutoHandle):
169  if not isMC and c[-1].mcOnly: continue
170  objects = self.handles[cn].product()
171  setattr(event, cn, [objects[i] for i in xrange(objects.size())])
172  c = c[-1]
173  if not isMC and c.mcOnly: continue
174  if self.scalar:
175  c.fillBranchesScalar(self.tree, getattr(event, cn), isMC)
176  else:
177  c.fillBranchesVector(self.tree, getattr(event, cn), isMC)
178 
179  self.tree.tree.Fill()
scalar
Read whether we want vectors or flat trees.
def core.AutoFillTreeProducer.AutoFillTreeProducer.getPythonWrapper (   self)
This function produces a string that contains a Python wrapper for the event.
The wrapper is automatically generated based on the collections and allows the full
event contents to be accessed from subsequent Analyzers using e.g.

leps = event.selLeptons #is of type selLeptons
pt0 = leps[0].pt

One just needs to add the EventAnalyzer to the sequence.

Definition at line 180 of file AutoFillTreeProducer.py.

181  def getPythonWrapper(self):
182  """
183  This function produces a string that contains a Python wrapper for the event.
184  The wrapper is automatically generated based on the collections and allows the full
185  event contents to be accessed from subsequent Analyzers using e.g.
186 
187  leps = event.selLeptons #is of type selLeptons
188  pt0 = leps[0].pt
189 
190  One just needs to add the EventAnalyzer to the sequence.
191  """
192 
193  isMC = self.cfg_comp.isMC
194 
195  classes = ""
196  anclass = ""
197  anclass += "from PhysicsTools.HeppyCore.framework.analyzer import Analyzer\n"
198  anclass += "class EventAnalyzer(Analyzer):\n"
199  anclass += " def __init__(self, cfg_ana, cfg_comp, looperName):\n"
200  anclass += " super(EventAnalyzer, self).__init__(cfg_ana, cfg_comp, looperName)\n"
201 
202  anclass += " def process(self, event):\n"
203 
204  for cname, coll in self.collections.items():
205  classes += coll.get_py_wrapper_class(isMC)
206  anclass += " event.{0} = {0}.make_array(event)\n".format(coll.name)
207 
208  return classes + "\n" + anclass
209 
def core.AutoFillTreeProducer.AutoFillTreeProducer.process (   self,
  event 
)

Definition at line 145 of file AutoFillTreeProducer.py.

References analyzer.Analyzer.cfg_ana, MuonGeometryArrange.fillTree(), edm::RootOutputTree.fillTree(), TrackerGeometryCompare.fillTree(), TrackerOfflineValidationSummary.fillTree(), core.AutoFillTreeProducer.AutoFillTreeProducer.fillTree(), TrackerOfflineValidation.fillTree(), and core.Analyzer.Analyzer.readCollections().

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().

def process(self, event):

Member Data Documentation

core.AutoFillTreeProducer.AutoFillTreeProducer.collections

Read whether we want 4-vectors.

Definition at line 24 of file AutoFillTreeProducer.py.

core.AutoFillTreeProducer.AutoFillTreeProducer.globalObjects

Definition at line 25 of file AutoFillTreeProducer.py.

core.AutoFillTreeProducer.AutoFillTreeProducer.globalVariables

Definition at line 26 of file AutoFillTreeProducer.py.

Referenced by core.AutoFillTreeProducer.AutoFillTreeProducer.declareVariables(), and core.AutoFillTreeProducer.AutoFillTreeProducer.fillTree().

core.AutoFillTreeProducer.AutoFillTreeProducer.scalar

Read whether we want vectors or flat trees.

Definition at line 17 of file AutoFillTreeProducer.py.

Referenced by core.AutoFillTreeProducer.AutoFillTreeProducer.declareCoreVariables(), core.AutoFillTreeProducer.AutoFillTreeProducer.declareVariables(), core.AutoFillTreeProducer.AutoFillTreeProducer.fillCoreVariables(), and core.AutoFillTreeProducer.AutoFillTreeProducer.fillTree().