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
hepsim:jas4pp [2020/05/22 02:38]
hepsim17
hepsim:jas4pp [2021/02/17 16:15] (current)
hepsim17 [Reading ROOT files]
Line 41: Line 41:
   * Downloading and searching HepSim data   * Downloading and searching HepSim data
   * Processing ProMC files from HepSim   * Processing ProMC files from HepSim
 +  * Processing ROOT files created by the Delphes program for fast simulation
   * Running over SLCIO files with Geant4 simulated / reconstructed events.   * Running over SLCIO files with Geant4 simulated / reconstructed events.
   * Data analysis (jets, physics vectors, histogram packages)   * Data analysis (jets, physics vectors, histogram packages)
-  * Visualisation of reconstructed events using Wired4 display+  * Visualization of reconstructed events using Wired4 display
  
-You can find more details in [[https://atlaswww.hep.anl.gov/hepsim/description.php|HepSim manual]].+You can find more details in [[https://atlaswww.hep.anl.gov/hepsim/doc/doku.php|HepSim manual]].
  
  
Line 195: Line 196:
 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.
 +
 +
 +To read ROOT files from Delphes simulations, use 
 +[[https://atlaswww.hep.anl.gov/asc/jas4pp/api/rootio/Delphes.html|Delphes class]] and its "get" methods,
 +getFloat, getDouble, getInt, and getBool. But first, explore the Delphes ROOT file using the browser shown above.
 +
 +Here is an example that uses high-level classes to read transverse momentum (PT) and pseudorapidity (ETA) of Monte Carlo particles:
 +
 + 
 +<hidden Click here to show  a Python code to read Delphes files>
 +<code python>
 +from  hep.io.root import RootFileReader
 +from rootio import *
 +
 +reader = RootFileReader("mg5_ttbar_Njet_001.root" )
 +tree = reader.get("Delphes");
 +maxevents=tree.getEntries()
 +branches=tree.getBranches()
 +print "Nr of events=",tree.getEntries()
 +print "Nr of branches=",branches.size()
 +print "Branches:"
 +for l in xrange( branches.size()  ):
 +   print "Branch=",l," name=",(branches.get(l)).getName()
 +
 +particles=tree.getBranch("Particle") # get  generator particles
 +
 +ptEvents=Delphes.getFloat(particles,"PT"  # get PT array
 +etaEvents=Delphes.getFloat(particles,"Eta") # get ETA array
 +
 +from jhplot import *
 +h1 = H1D("PT of particles",100, 0, 100)
 +h2 = H1D("Eta of particles",100, -4, 4)
 +for i in xrange(tree.getEntries()):
 +       pt,eta=ptEvents[i],etaEvents[i]
 +       for j in xrange(len(pt)):
 +           h1.fill(pt[j])
 +           h2.fill(eta[j])
 +c=HPlot("pT",600,300,2,1)
 +c.visible()
 +c.setAutoRange()
 +c.draw(h1)
 +
 +c.cd(2,1)
 +c.setAutoRange()
 +c.draw(h2)
 +</code>
 +</hidden>
 +
 +{{:hepsim:pt_eta_delphes.png?300|}}
 +
 +<note warning>Reading Delphes trees is an experimental feature. Under study </note>
  
 ====== Using GUI mode ====== ====== Using GUI mode ======
Line 339: Line 512:
   * S.Chekanov (ANL, main developer)   * S.Chekanov (ANL, main developer)
   * E.May (ANL, debugging, Wired4)   * E.May (ANL, debugging, Wired4)
 +  * Gagik Gavalian (JLab)