Simple test of using ROOT in a Python notebook

We need to import the ROOT package before we can use it:


In [1]:
import ROOT


Welcome to ROOTaaS 6.06/06

We can also explicitly import the classes we will need, so we don't have to type e.g. "ROOT.TH1F" each time.


In [2]:
from ROOT import TH1F, TCanvas

Then we can create a histogram, and use the FillRandom method to put some random numbers in it:


In [3]:
h1 = TH1F("Gaussian","Example histogram with Gaussian random data", 100, -5, 5)
h1.FillRandom("gaus")

To display the histogram, we need to create a "canvas" to put it in, and then draw the histogram:


In [4]:
c1 = TCanvas("TheCanvas","Canvas for plotting histograms",800,600)
h1.Draw()

Finally, we need to draw the canvas itself to the screen:


In [5]:
c1.Draw()


If we enable the "JSVis" option then the notebook will include some fancy Javascript functions for interacting with plots. Use the mouse buttons to zoom in and out, and select functions from the menus.


In [6]:
ROOT.enableJSVis()
c1.Draw()