3 """Example routines for creating and reading a ROOT tree.
5 Python is simply a superior way to write many ROOT scripts than
6 using normal CINT macros. It is more stable, and the simpler
7 syntax of Python compared to C++ is better suited to common
8 tree and histogramming operations.
9 This module contains simple routines outlining how to create
10 and access tree files with EIC events via Python.
11 Note you need a version of ROOT compiled against Python and
12 the necessary environment variables set (see the ROOT installation
17 """Import the PyROOT module and use ROOT.gSystem.Load
18 to import the eic-smear class library.
21 ROOT.gSystem.Load(
'libeicsmear')
24 def build(inputname, outputdir = '.', nevents = -1):
25 """Example of creating a tree.
27 Once the eic-smear library, you can just use the
28 BuildTree routine as usual.
31 ROOT.gSystem.Load(
'libeicsmear')
33 ROOT.BuildTree(inputname, outputdir, nevents)
37 """Example of creating a tree.
39 Creating and writing events manually without the use of BuildTree.
42 ROOT.gSystem.Load(
'libeicsmear')
44 file = ROOT.TFile(outputname,
'recreate')
45 tree = ROOT.TTree(
'events',
'A ROOT tree of EIC events')
48 event = ROOT.erhic.EventPythia()
49 tree.Branch(
'event', event)
51 for i
in xrange(0, nevents):
61 def read(inputname, treename):
62 """Example of reading back a tree.
65 ROOT.gSystem.Load(
'libeicsmear')
67 file = ROOT.TFile(inputname,
'read')
70 file.Get(treename).
Draw(
'GetN()')