From HandWiki
Jump to: navigation, search
Limitted access. First login to DataMelt if you are a full DataMelt member. Then login to HandWiki as a user.

Reading and viewing ROOT files

One can natively reads ROOT files including files created using ROOT files. Versions 3, 4, 5 and 6 are supported). The original library is RootIO FreeHep (, but it was modernized for new versions of ROOT.

Here is a Jython/Python example showing how to read a ROOT tree using <javadoc> import RootFileReader</javdoc>:

from import TTree
from import RootFileReader
reader = RootFileReader("ntuple_tree.root")
tree = reader.get("tree");
leaves = tree.getLeaves()
print "Nr of events=",maxevents
print "Nr of leaves=",nrleaves
print "Leaves:"
for l in xrange( nrleaves ):
   print "Leaf=",(leaves.get(l)).getName()
print "Run over events"
for i in xrange(tree.getEntries()):
      print f0.getValue(i), f1.getValue(i), f2.getValue(i)

The example directory also shows how to read histograms. Similar examples can be made using Java or Groovy scripting.

One can browser histogram (or ROOT objects) using this using the <javadoc>rootio</javdoc> class:

import rootio
rootio.HBrowser("histograms_root5.root") # browser and plot ROOT histograms 
rootio.Browser("histograms_root5.root")  # browser for ROOT objects

The script that call these browsers can be put into Jython or Groovy files and executed as binary programs.