def __init__(self, cfg_ana, cfg_comp, looperName): super(TreeAnalyzerNumpy,self).__init__(cfg_ana, cfg_comp, looperName) fileName = '/'.join([self.dirName, 'tree.root']) isCompressed = self.cfg_ana.isCompressed if hasattr(cfg_ana,'isCompressed') else 1 print 'Compression', isCompressed self.file = TFile( fileName, 'recreate', '', isCompressed ) self.tree = Tree('tree', self.name)
def create_tree(filename="test_tree.root"): outfile = TFile(filename, 'recreate') tree = Tree('test_tree', 'A test tree') tree.var('var1') for i in range(100): tree.fill('var1', i) tree.tree.Fill() print('creating a tree', tree.tree.GetName(),\ tree.tree.GetEntries(), 'entries in',\ outfile.GetName()) outfile.Write()
def test_fill(self): fi = TFile('tree.root', 'RECREATE') tr = Tree('test_tree', 'A test tree') tr.var('a') tr.var('b') tr.fill('a', 3) tr.fill('a', 4) tr.fill('b', 5) tr.tree.Fill() fi.Write() fi.Close()
def write(self, dirName, fileName='RLTInfo.root'): f = TFile('/'.join([dirName, fileName]), 'RECREATE') t = Tree('RLTInfo', 'HLT/Run/Lumi information') t.var('run', int) t.var('lumi', int) t.var('counts', int) t.var('trigger', int) for rlt, count in six.iteritems(self.dict): t.fill('run', rlt[1]) t.fill('lumi', rlt[2]) t.fill('counts', count.integer) t.tree.Fill() f.Write() f.Close()
def beginLoop(self, setup) : super(TreeAnalyzerNumpy, self).beginLoop(setup) if self.outservicename in setup.services: print("Using outputfile given in", self.outservicename) self.file = setup.services[self.outservicename].file else : fileName = '/'.join([self.dirName, 'tree.root']) isCompressed = self.cfg_ana.isCompressed if hasattr(self.cfg_ana,'isCompressed') else 1 print('Compression', isCompressed) self.file = TFile( fileName, 'recreate', '', isCompressed ) self.file.cd() if self.file.Get(self.treename) : raise RuntimeError("You are booking two Trees with the same name in the same file") self.tree = Tree(self.treename, self.name) self.tree.setDefaultFloatType(getattr(self.cfg_ana, 'defaultFloatType','D')); # or 'F' self.declareVariables(setup)
def beginLoop(self, setup): super(TreeAnalyzerNumpy, self).beginLoop(setup) print setup.services if self.outservicename in setup.services: print "Using outputfile given in", self.outservicename self.file = setup.services[self.outservicename].file else: fileName = '/'.join([self.dirName, 'tree.root']) isCompressed = self.cfg_ana.isCompressed if hasattr( self.cfg_ana, 'isCompressed') else 1 print 'Compression', isCompressed self.file = TFile(fileName, 'recreate', '', isCompressed) self.tree = Tree('tree', self.name) self.tree.setDefaultFloatType( getattr(self.cfg_ana, 'defaultFloatType', 'D')) # or 'F' self.declareVariables(setup)
def beginLoop(self): super(SimpleTreeProducer, self).beginLoop() self.rootfile = TFile('/'.join([self.dirName, 'simple_tree.root']), 'recreate') self.tree = Tree(self.cfg_ana.tree_name, self.cfg_ana.tree_title) self.tree.var('test_variable')
from ROOT import TFile from PhysicsTools.HeppyCore.statistics.tree import Tree outfile = TFile('test_tree.root', 'recreate') tree = Tree('test_tree', 'A test tree') tree.var('var1') for i in range(100): tree.fill('var1', i) tree.tree.Fill() print 'creating a tree', tree.tree.GetName(),\ tree.tree.GetEntries(), 'entries in',\ outfile.GetName() outfile.Write()