CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 = "outputfile"
15  if hasattr(cfg_ana,"outservicename") :
16  self.outservicename = cfg_ana.outservicename
17 
18 
19  def beginLoop(self, setup) :
20  super(TreeAnalyzerNumpy, self).beginLoop(setup)
21  print setup.services
22  if self.outservicename in setup.services:
23  print "Using outputfile given in", self.outservicename
24  self.file = setup.services[self.outservicename].file
25  else :
26  fileName = '/'.join([self.dirName,
27  'tree.root'])
28  isCompressed = self.cfg_ana.isCompressed if hasattr(self.cfg_ana,'isCompressed') else 1
29  print 'Compression', isCompressed
30  self.file = TFile( fileName, 'recreate', '', isCompressed )
31  self.tree = Tree('tree', self.name)
32  self.tree.setDefaultFloatType(getattr(self.cfg_ana, 'defaultFloatType','D')); # or 'F'
33  self.declareVariables(setup)
34 
35  def declareVariables(self,setup):
36  print 'TreeAnalyzerNumpy.declareVariables : overload this function.'
37  pass
38 
39  def write(self, setup):
40  super(TreeAnalyzerNumpy, self).write(setup)
41  if self.outservicename not in setup.services:
42  self.file.Write()
43 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18