CMS 3D CMS Logo

TreeAnalyzerNumpy.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from PhysicsTools.Heppy.analyzers.core.Analyzer import Analyzer
3 from PhysicsTools.HeppyCore.statistics.tree import Tree as Tree
4 from ROOT import TFile
5 
7  """Base TreeAnalyzerNumpy, to create flat TTrees.
8 
9  Check out TestTreeAnalyzer for a concrete example.
10  IMPORTANT: FOR NOW, CANNOT RUN SEVERAL TreeAnalyzers AT THE SAME TIME!
11  Anyway, you want only one TTree, don't you?"""
12 
13  def __init__(self, cfg_ana, cfg_comp, looperName):
14  super(TreeAnalyzerNumpy,self).__init__(cfg_ana, cfg_comp, looperName)
15  self.outservicename = getattr(cfg_ana,"outservicename","outputfile")
16  self.treename = getattr(cfg_ana,"treename","tree")
17 
18 
19  def beginLoop(self, setup) :
20  super(TreeAnalyzerNumpy, self).beginLoop(setup)
21  if self.outservicename in setup.services:
22  print("Using outputfile given in", self.outservicename)
23  self.file = setup.services[self.outservicename].file
24  else :
25  fileName = '/'.join([self.dirName,
26  'tree.root'])
27  isCompressed = self.cfg_ana.isCompressed if hasattr(self.cfg_ana,'isCompressed') else 1
28  print('Compression', isCompressed)
29  self.file = TFile( fileName, 'recreate', '', isCompressed )
30  self.file.cd()
31  if self.file.Get(self.treename) :
32  raise RuntimeError("You are booking two Trees with the same name in the same file")
33  self.tree = Tree(self.treename, self.name)
34  self.tree.setDefaultFloatType(getattr(self.cfg_ana, 'defaultFloatType','D')); # or 'F'
35  self.declareVariables(setup)
36 
37  def declareVariables(self,setup):
38  print('TreeAnalyzerNumpy.declareVariables : overload this function.')
39  pass
40 
41  def write(self, setup):
42  super(TreeAnalyzerNumpy, self).write(setup)
43  if self.outservicename not in setup.services:
44  self.file.Write()
45 
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.file
file
Definition: TreeAnalyzerNumpy.py:23
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.tree
tree
Definition: TreeAnalyzerNumpy.py:33
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.declareVariables
def declareVariables(self, setup)
Definition: TreeAnalyzerNumpy.py:37
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.outservicename
outservicename
Definition: TreeAnalyzerNumpy.py:15
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.__init__
def __init__(self, cfg_ana, cfg_comp, looperName)
Definition: TreeAnalyzerNumpy.py:13
remoteMonitoring_LED_IterMethod_cfg.Analyzer
Analyzer
Definition: remoteMonitoring_LED_IterMethod_cfg.py:32
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.treename
treename
Definition: TreeAnalyzerNumpy.py:16
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
hippyaddtobaddatafiles.cd
def cd(newdir)
Definition: hippyaddtobaddatafiles.py:40
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.write
def write(self, setup)
Definition: TreeAnalyzerNumpy.py:41
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy.beginLoop
def beginLoop(self, setup)
Definition: TreeAnalyzerNumpy.py:19
core.TreeAnalyzerNumpy.TreeAnalyzerNumpy
Definition: TreeAnalyzerNumpy.py:6