CMS 3D CMS Logo

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