CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
tree.Tree Class Reference
Inheritance diagram for tree.Tree:

Public Member Functions

def __init__ (self, name, title, defaultFloatType="D", defaultIntType="I")
 
def branch_ (self, selfmap, varName, type, len, postfix="", storageType="default", title=None)
 
def copyStructure (self, tree)
 
def fill (self, varName, value)
 
def reset (self)
 
def setDefaultFloatType (self, defaultFloatType)
 
def setDefaultIntType (self, defaultIntType)
 
def var (self, varName, type=float, default=-99, title=None, storageType="default", filler=None)
 
def vector (self, varName, lenvar, maxlen=None, type=float, default=-99, title=None, storageType="default", filler=None)
 
def vfill (self, varName, values)
 

Public Attributes

 defaultFloatType
 
 defaultIntType
 
 defaults
 
 fillers
 
 tree
 
 vars
 
 vecdefaults
 
 vecvars
 

Detailed Description

Definition at line 5 of file tree.py.

Constructor & Destructor Documentation

◆ __init__()

def tree.Tree.__init__ (   self,
  name,
  title,
  defaultFloatType = "D",
  defaultIntType = "I" 
)

Definition at line 7 of file tree.py.

7  def __init__(self, name, title, defaultFloatType="D", defaultIntType="I"):
8  self.vars = {}
9  self.vecvars = {}
10  self.tree = TTree(name, title)
11  self.defaults = {}
12  self.vecdefaults = {}
13  self.defaultFloatType = defaultFloatType
14  self.defaultIntType = defaultIntType
15  self.fillers = {}
16 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ branch_()

def tree.Tree.branch_ (   self,
  selfmap,
  varName,
  type,
  len,
  postfix = "",
  storageType = "default",
  title = None 
)
Backend function used to create scalar and vector branches. 
   Users should call "var" and "vector", not this function directly.

Definition at line 32 of file tree.py.

References tree.Tree.defaultFloatType, tree.Tree.defaultIntType, tree.Tree.tree, HIPMonitorVariables.tree, SimpleTreeProducer.SimpleTreeProducer.tree, eventstfile.Events.tree, CSCTFAnalyzer.tree, CSCTFanalyzer.tree, core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.tree, TreeWriterForEcalCorrection.tree, AlignmentIORootBase.tree, TkOfflineVariables.tree, HIPTwoBodyDecayAnalyzer.tree, EcalPerEvtMatacqAnalyzer.tree, HcalIsoTrackAnalyzer.tree, SiStripHitEfficiencyHarvester.tree, EcalMatacqAnalyzer.tree, BPHHistoSpecificDecay.tree, IsoTrackCalibration.tree, IsoTrackCalib.tree, TkAlMap.TkAlMap.tree, HcalIsoTrkSimAnalyzer.tree, and HcalIsoTrkAnalyzer.tree.

Referenced by tree.Tree.var(), and tree.Tree.vector().

32  def branch_(self, selfmap, varName, type, len, postfix="", storageType="default", title=None):
33  """Backend function used to create scalar and vector branches.
34  Users should call "var" and "vector", not this function directly."""
35  if storageType == "default":
36  storageType = self.defaultIntType if type is int else self.defaultFloatType
37  if type is float :
38  if storageType == "F":
39  selfmap[varName]=numpy.zeros(len,numpy.float32)
40  self.tree.Branch(varName,selfmap[varName],varName+postfix+'/F')
41  elif storageType == "D":
42  selfmap[varName]=numpy.zeros(len,numpy.float64)
43  self.tree.Branch(varName,selfmap[varName],varName+postfix+'/D')
44  else:
45  raise RuntimeError('Unknown storage type %s for branch %s' % (storageType, varName))
46  elif type is int:
47  dtypes = {
48  "i" : numpy.uint32,
49  "s" : numpy.uint16,
50  "b" : numpy.uint8,
51  "l" : numpy.uint64,
52  "I" : numpy.int32,
53  "S" : numpy.int16,
54  "B" : numpy.int8,
55  "L" : numpy.int64,
56  }
57  if storageType not in dtypes:
58  raise RuntimeError('Unknown storage type %s for branch %s' % (storageType, varName))
59  selfmap[varName]=numpy.zeros(len,dtypes[storageType])
60  self.tree.Branch(varName,selfmap[varName],varName+postfix+'/'+storageType)
61  else:
62  raise RuntimeError('Unknown type %s for branch %s' % (type, varName))
63  if title:
64  self.tree.GetBranch(varName).SetTitle(title)
65 

◆ copyStructure()

def tree.Tree.copyStructure (   self,
  tree 
)

Definition at line 23 of file tree.py.

References CentralityTable::BinValues.var, trigger::EgammaObject.var(), TaggingVariablePlotter::VariableConfig.var, tree.Tree.var(), reco::parser::Grammar::definition< ScannerT >.var, PhysicsTools::MVAComputer::InputVar.var, and TkAlMap.TkAlMap.var.

23  def copyStructure(self, tree):
24  for branch in tree.GetListOfBranches():
25  name = branch.GetName()
26  typeName = branch.GetListOfLeaves()[0].GetTypeName()
27  type = float
28  if typeName == 'Int_t':
29  type = int
30  self.var(name, type)
31 

◆ fill()

def tree.Tree.fill (   self,
  varName,
  value 
)

Definition at line 116 of file tree.py.

References tree.Tree.fillers, tree.Tree.vars, PlotAlignmentValidation::DMRPlotInfo.vars, and JsonOutputProducer.vars.

116  def fill(self, varName, value ):
117  if isinstance(self.vars[varName], numpy.ndarray):
118  self.vars[varName][0]=value
119  else:
120  self.fillers[varName](self.vars[varName],value)
121 

◆ reset()

def tree.Tree.reset (   self)

Definition at line 103 of file tree.py.

References tree.Tree.defaults, geometryComparison.GeometryComparison.defaults, primaryVertexResolution.PrimaryVertexResolution.defaults, primaryVertexValidation.PrimaryVertexValidation.defaults, offlineValidation.OfflineValidation.defaults, zMuMuValidation.ZMuMuValidation.defaults, trackSplittingValidation.TrackSplittingValidation.defaults, preexistingValidation.PreexistingValidation.defaults, plottingOptions.BasePlottingOptions.defaults, genericValidation.GenericValidation.defaults, preexistingValidation.PreexistingOfflineValidation.defaults, plottingOptions.PlottingOptionsTrackSplitting.defaults, plottingOptions.PlottingOptionsZMuMu.defaults, plottingOptions.PlottingOptionsOffline.defaults, plottingOptions.PlottingOptionsPrimaryVertex.defaults, plottingOptions.PlottingOptionsPVResolution.defaults, genericValidation.GenericValidationData.defaults, genericValidation.GenericValidationData_CTSR.defaults, svgfig.Path.defaults, svgfig.Curve.defaults, svgfig.Poly.defaults, svgfig.Text.defaults, svgfig.TextGlobal.defaults, svgfig.Dots.defaults, svgfig.Line.defaults, svgfig.LineGlobal.defaults, svgfig.VLine.defaults, svgfig.HLine.defaults, svgfig.Rect.defaults, svgfig.Ellipse.defaults, svgfig.Ticks.defaults, svgfig.CurveAxis.defaults, svgfig.LineAxis.defaults, svgfig.XAxis.defaults, svgfig.YAxis.defaults, svgfig.Axes.defaults, svgfig.HGrid.defaults, svgfig.VGrid.defaults, svgfig.Grid.defaults, svgfig.XErrorBars.defaults, svgfig.YErrorBars.defaults, tree.Tree.fillers, mps_monitormerge.items, tree.Tree.vars, PlotAlignmentValidation::DMRPlotInfo.vars, JsonOutputProducer.vars, tree.Tree.vecdefaults, and tree.Tree.vecvars.

103  def reset(self):
104  for name,value in self.vars.items():
105  if name in self.fillers:
106  self.fillers[name](value, self.defaults[name])
107  else:
108  value[0]=self.defaults[name]
109  for name,value in self.vecvars.items():
110  if isinstance(value, numpy.ndarray):
111  value.fill(self.vecdefaults[name])
112  else:
113  if isinstance(value, ROOT.TObject) and value.ClassName() == "TClonesArray":
114  value.ExpandCreateFast(0)
115 
void reset(double vett[256])
Definition: TPedValues.cc:11

◆ setDefaultFloatType()

def tree.Tree.setDefaultFloatType (   self,
  defaultFloatType 
)

Definition at line 17 of file tree.py.

References tree.Tree.defaultFloatType.

17  def setDefaultFloatType(self, defaultFloatType):
18  self.defaultFloatType = defaultFloatType
19 

◆ setDefaultIntType()

def tree.Tree.setDefaultIntType (   self,
  defaultIntType 
)

Definition at line 20 of file tree.py.

References tree.Tree.defaultIntType.

20  def setDefaultIntType(self, defaultIntType):
21  self.defaultIntType = defaultIntType
22 

◆ var()

def tree.Tree.var (   self,
  varName,
  type = float,
  default = -99,
  title = None,
  storageType = "default",
  filler = None 
)

Definition at line 66 of file tree.py.

References tree.Tree.branch_(), fwlite::RecordWriter::DataBuffer.branch_, fwlite::internal::Data.branch_, BareRootProductGetter::Buffer.branch_, edm::PoolOutputModule::SpecialSplitLevelForBranch.branch_, tree.Tree.defaults, geometryComparison.GeometryComparison.defaults, primaryVertexResolution.PrimaryVertexResolution.defaults, primaryVertexValidation.PrimaryVertexValidation.defaults, offlineValidation.OfflineValidation.defaults, trackSplittingValidation.TrackSplittingValidation.defaults, zMuMuValidation.ZMuMuValidation.defaults, preexistingValidation.PreexistingValidation.defaults, plottingOptions.BasePlottingOptions.defaults, genericValidation.GenericValidation.defaults, preexistingValidation.PreexistingOfflineValidation.defaults, plottingOptions.PlottingOptionsTrackSplitting.defaults, plottingOptions.PlottingOptionsZMuMu.defaults, plottingOptions.PlottingOptionsOffline.defaults, plottingOptions.PlottingOptionsPrimaryVertex.defaults, plottingOptions.PlottingOptionsPVResolution.defaults, genericValidation.GenericValidationData.defaults, genericValidation.GenericValidationData_CTSR.defaults, svgfig.Path.defaults, svgfig.Curve.defaults, svgfig.Poly.defaults, svgfig.Text.defaults, svgfig.TextGlobal.defaults, svgfig.Dots.defaults, svgfig.Line.defaults, svgfig.LineGlobal.defaults, svgfig.VLine.defaults, svgfig.HLine.defaults, svgfig.Rect.defaults, svgfig.Ellipse.defaults, svgfig.Ticks.defaults, svgfig.CurveAxis.defaults, svgfig.LineAxis.defaults, svgfig.XAxis.defaults, svgfig.YAxis.defaults, svgfig.Axes.defaults, svgfig.HGrid.defaults, svgfig.VGrid.defaults, svgfig.Grid.defaults, svgfig.XErrorBars.defaults, svgfig.YErrorBars.defaults, tree.Tree.fillers, tree.Tree.tree, HIPMonitorVariables.tree, SimpleTreeProducer.SimpleTreeProducer.tree, eventstfile.Events.tree, CSCTFAnalyzer.tree, CSCTFanalyzer.tree, core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.tree, TreeWriterForEcalCorrection.tree, AlignmentIORootBase.tree, TkOfflineVariables.tree, HIPTwoBodyDecayAnalyzer.tree, EcalPerEvtMatacqAnalyzer.tree, HcalIsoTrackAnalyzer.tree, SiStripHitEfficiencyHarvester.tree, EcalMatacqAnalyzer.tree, BPHHistoSpecificDecay.tree, IsoTrackCalibration.tree, IsoTrackCalib.tree, TkAlMap.TkAlMap.tree, HcalIsoTrkSimAnalyzer.tree, HcalIsoTrkAnalyzer.tree, tree.Tree.vars, PlotAlignmentValidation::DMRPlotInfo.vars, and JsonOutputProducer.vars.

Referenced by tree.Tree.copyStructure().

66  def var(self, varName,type=float, default=-99, title=None, storageType="default", filler=None ):
67  if type in [int, float]:
68  self.branch_(self.vars, varName, type, 1, title=title, storageType=storageType)
69  self.defaults[varName] = default
70  elif __builtins__['type'](type) == str:
71  # create a value, looking up the type from ROOT and calling the default constructor
72  self.vars[varName] = getattr(ROOT,type)()
73  if type in [ "TLorentzVector" ]: # custom streamer classes
74  self.tree.Branch(varName+".", type, self.vars[varName], 8000,-1)
75  else:
76  self.tree.Branch(varName+".", type, self.vars[varName])
77  if filler is None:
78  raise RuntimeError("Error: when brancing with an object, filler should be set to a function that takes as argument an object instance and a value, and set the instance to the value (as otherwise python assignment of objects changes the address as well)")
79  self.fillers[varName] = filler
80  else:
81  raise RuntimeError('Unknown type %s for branch %s: it is not int, float or a string' % (type, varName))
82  self.defaults[varName] = default
83 

◆ vector()

def tree.Tree.vector (   self,
  varName,
  lenvar,
  maxlen = None,
  type = float,
  default = -99,
  title = None,
  storageType = "default",
  filler = None 
)
either lenvar is a string, and maxlen an int (variable size array), or lenvar is an int and maxlen is not specified (fixed array)

Definition at line 84 of file tree.py.

References tree.Tree.branch_(), fwlite::RecordWriter::DataBuffer.branch_, fwlite::internal::Data.branch_, BareRootProductGetter::Buffer.branch_, edm::PoolOutputModule::SpecialSplitLevelForBranch.branch_, tree.Tree.fillers, tree.Tree.tree, HIPMonitorVariables.tree, SimpleTreeProducer.SimpleTreeProducer.tree, eventstfile.Events.tree, CSCTFAnalyzer.tree, CSCTFanalyzer.tree, core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.tree, TreeWriterForEcalCorrection.tree, AlignmentIORootBase.tree, TkOfflineVariables.tree, HIPTwoBodyDecayAnalyzer.tree, EcalPerEvtMatacqAnalyzer.tree, HcalIsoTrackAnalyzer.tree, SiStripHitEfficiencyHarvester.tree, EcalMatacqAnalyzer.tree, BPHHistoSpecificDecay.tree, IsoTrackCalibration.tree, IsoTrackCalib.tree, TkAlMap.TkAlMap.tree, HcalIsoTrkSimAnalyzer.tree, HcalIsoTrkAnalyzer.tree, tree.Tree.vecdefaults, and tree.Tree.vecvars.

84  def vector(self, varName, lenvar, maxlen=None, type=float, default=-99, title=None, storageType="default", filler=None ):
85  """either lenvar is a string, and maxlen an int (variable size array), or lenvar is an int and maxlen is not specified (fixed array)"""
86  if type in [int, float]:
87  if __builtins__['type'](lenvar) == int: # need the __builtins__ since 'type' is a variable here :-/
88  self.branch_(self.vecvars, varName, type, lenvar, postfix="[%d]" % lenvar, title=title, storageType=storageType)
89  else:
90  if maxlen == None: RuntimeError, 'You must specify a maxlen if making a dynamic array';
91  self.branch_(self.vecvars, varName, type, maxlen, postfix="[%s]" % lenvar, title=title, storageType=storageType)
92  elif __builtins__['type'](type) == str:
93  self.vecvars[varName] = ROOT.TClonesArray(type,(lenvar if __builtins__['type'](lenvar) == int else maxlen))
94  if type in [ "TLorentzVector" ]: # custom streamer classes
95  self.tree.Branch(varName+".", self.vecvars[varName], 32000, -1)
96  else:
97  self.tree.Branch(varName+".", self.vecvars[varName])
98  if filler is None:
99  raise RuntimeError("Error: when brancing with an object, filler should be set to a function that takes as argument an object instance and a value, and set the instance to the value (as otherwise python assignment of objects changes the address as well)")
100  self.fillers[varName] = filler
101  self.vecdefaults[varName] = default
102 

◆ vfill()

def tree.Tree.vfill (   self,
  varName,
  values 
)

Definition at line 122 of file tree.py.

References tree.Tree.fillers, and tree.Tree.vecvars.

122  def vfill(self, varName, values ):
123  a = self.vecvars[varName]
124  if isinstance(a, numpy.ndarray):
125  for (i,v) in enumerate(values):
126  a[i]=v
127  else:
128  if isinstance(a, ROOT.TObject) and a.ClassName() == "TClonesArray":
129  a.ExpandCreateFast(len(values))
130  fillit = self.fillers[varName]
131  for (i,v) in enumerate(values):
132  fillit(a[i],v)
133 

Member Data Documentation

◆ defaultFloatType

tree.Tree.defaultFloatType

Definition at line 13 of file tree.py.

Referenced by tree.Tree.branch_(), and tree.Tree.setDefaultFloatType().

◆ defaultIntType

tree.Tree.defaultIntType

Definition at line 14 of file tree.py.

Referenced by tree.Tree.branch_(), and tree.Tree.setDefaultIntType().

◆ defaults

tree.Tree.defaults

Definition at line 11 of file tree.py.

Referenced by tree.Tree.reset(), and tree.Tree.var().

◆ fillers

tree.Tree.fillers

◆ tree

◆ vars

tree.Tree.vars

Definition at line 8 of file tree.py.

Referenced by tree.Tree.fill(), tree.Tree.reset(), and tree.Tree.var().

◆ vecdefaults

tree.Tree.vecdefaults

Definition at line 12 of file tree.py.

Referenced by tree.Tree.reset(), and tree.Tree.vector().

◆ vecvars

tree.Tree.vecvars

Definition at line 9 of file tree.py.

Referenced by tree.Tree.reset(), tree.Tree.vector(), and tree.Tree.vfill().