Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision Both sides next revision
hepsim:jas4pp [2020/11/05 14:21]
hepsim17
hepsim:jas4pp [2021/02/13 23:12]
hepsim17 [Reading LCIO files]
Line 195: Line 195:
 Also, look at concrete example of how to analyze single particles in [[:fcs:eic:intro|this section]]. Also, look at concrete example of how to analyze single particles in [[:fcs:eic:intro|this section]].
  
 +
 +======  Reading ROOT files ======
 +
 +Jas4pp natively reads ROOT files including files created using ROOT 6 (ROOT3, 4 and 5 are also supported). For example, one can read ROOT trees/ntuples.
 +One can find some examples in the directory "examples/root". Here is a Jython/Python example showing how to read a ROOT tree:
 + 
 +<hidden Show example of a Python code here>
 +<code python>
 +from  hep.io.root.interfaces import TTree
 +from  hep.io.root import RootFileReader
 +
 +reader = RootFileReader("ntuple_tree.root")
 +
 +tree = reader.get("tree");
 +maxevents=tree.getEntries()
 +
 +leaves = tree.getLeaves()
 +nrleaves=leaves.size()
 +
 +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"
 +f0=leaves.get(0);
 +f1=leaves.get(1);
 +f2=leaves.get(2);
 +for i in xrange(tree.getEntries()):
 +      print f0.getValue(i), f1.getValue(i), f2.getValue(i)
 +
 +</code>
 +</hidden>
 +
 +The example directory also shows how to read histograms.
 +Similar examples can be made using Java or Groovy scripting.
 +
 +The supported ROOT interfaces are:
 +
 +<hidden show more details on ROOT interfaces here>
 +TArrayC
 +TArrayD
 +TArrayF
 +TArrayI
 +TArray
 +TArrayL
 +TAttAxis
 +TAttFill
 +TAttLine
 +TAttMarker
 +TAxis
 +TBasket
 +TBranchClones
 +TBranchElement
 +TBranch
 +TBranchObject
 +TClonesArray
 +TCollection
 +TDatime
 +TDirectory
 +TFile
 +TGraph
 +TH1D
 +TH1F
 +TH1
 +TH2D
 +TH2F
 +TH2
 +TKey
 +TLeafB
 +TLeafC
 +TLeafD
 +TLeafElement
 +TLeafF
 +TLeafI
 +TLeaf
 +TLeafL
 +TLeafObject
 +TLeafO
 +TLeafS
 +TList
 +TMap
 +TNamed
 +TObjArray
 +TObject
 +TProfile
 +TSeqCollection
 +TStreamerBase
 +TStreamerBasicPointer
 +TStreamerBasicType
 +TStreamerElement
 +TStreamerInfo
 +TStreamerLoop
 +TStreamerObjectAny
 +TStreamerObject
 +TStreamerObjectPointer
 +TStreamerString
 +TString
 +TTree
 +</hidden>
 +
 +One can browser histogram (or ROOT objects) using this:
 +
 +<code python>
 +import rootio
 +rootio.HBrowser("histograms_root5.root") # browser and plot ROOT histograms 
 +rootio.Browser("histograms_root5.root" # browser for ROOT objects
 +</code>
 +
 +You will see the browsers:
 +
 +{{:asc:browser_histograms.png?300|Histogram browser}}
 +
 +{{:asc:root_browser.png?300|Object browser}}
 +
 +The script that call these browsers  can be put into Jython or Groovy files and executed as binary programs.
 +
 +Jas4pp does not support ROOT files with complex objects created using ROOT 6, i.e. TH1D, TH2D and TGraph.  Under investigation.
  
 ====== Using GUI mode ====== ====== Using GUI mode ======