Differences

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

Link to this comparison view

Both sides previous revision Previous revision
hepsim:jas4pp [2021/02/17 00:11]
hepsim17
hepsim:jas4pp [2021/02/17 16:15] (current)
hepsim17 [Reading ROOT files]
Line 318: Line 318:
 The script that call these browsers  can be put into Jython or Groovy files and executed as binary programs. 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 ======