Show ROOT histograms using different styles
Code: "hep_root.py"
Programming language: Python
DMelt Version 1.4. Last modified: 03/10/1970. License: Free
http://jwork.org/dmelt/code/cache/hep_root_4515.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


# This example shows how to read ROOT file with histograms
from java.awt import Color
from jhplot  import *
from jhplot.io  import *

file="Example.root"
Web.get("http://jwork.org/dmelt/examples/data/"+file)

# location of ROOT file
rfr = FileRoot( file )
print "number of histograms=",rfr.getNKeys()
print "ROOT version=",rfr.getVersion()
print "ROOT version=",rfr.getTitle()
print "No of histograms=",rfr.toString()

# get ROOT histograms 
h1 = rfr.getH1D("mainHistogram")
h2 = rfr.getH1D("totalHistogram")
# create canvas 1x1
c1 = HPlot("Canvas",600,400,1, 1)
c1.setGTitle("Show ROOT histograms")
c1.visible(1)
c1.setMarginLeft(90)
c1.setRange(0, -4, 4)
c1.setAutoRange(1,1)

h1.setColor(Color.blue)
h1.setFill(True)
h1.setFillColor(Color.blue)
c1.draw(h1)

p2=P1D(h2) # show as dots
h2.setColor(Color.red)
c1.draw(p2)

c1.setNameX("Xaxis")
c1.setNameY("Yaxis")
c1.setName("Canvas title")
c1.update()