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
Previous revision
Next revision Both sides next revision
hepsim:jas4pp [2020/05/22 02:38]
hepsim17
hepsim:jas4pp [2021/02/15 02:03]
hepsim17 [Reading ROOT files]
Line 194: Line 194:
  
 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 commonly used objects and data structures from [[https://root.cern/ | ROOT files]]  (versions 3, 4, 5 and 6). 
 +ROOT files can be loaded using the Jas4pp menu [File]-[Open data source]-[Root file] (*.root).
 +
 +In addition, one can work with ROOT files using Python/Jython or Groovy scripts. 
 +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:
 +
 +{{:hepsim:browser_histograms.png?300|Histogram browser}}
 +
 +{{:hepsim: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.
  
  
Line 339: Line 461:
   * S.Chekanov (ANL, main developer)   * S.Chekanov (ANL, main developer)
   * E.May (ANL, debugging, Wired4)   * E.May (ANL, debugging, Wired4)
 +  * Gagik Gavalian (JLab)