Simple ROOTbook (Python)

This simple ROOTbook shows how to create a histogram, fill it and draw it.

Let's start importing the ROOT module, which gives us access to all ROOT classes.

In [2]:
import ROOT

Welcome to JupyROOT 6.07/07

In order to activate the interactive visualisation we can use the JSROOT magic:

In [3]:
%jsroot on

Now we will create a histogram specifying its title and axes titles:

In [5]:
h = ROOT.TH1F("myHisto","My Histo;X axis;Y axis",64, -4, 4)

Time to create a random generator and fill our histogram:

In [6]:
rndmGenerator = ROOT.TRandom3()
for i in xrange(1000):
    rndm = rndmGenerator.Gaus()

We can now draw the histogram. We will at first create a canvas, the entity which in ROOT holds graphics primitives. Note that thanks to JSROOT, this is not a static plot but an interactive visualisation. Try to play with it and save it as image when you are satisfied!

In [7]:
c = ROOT.TCanvas()

We'll try now to beautify the plot a bit, for example filling the histogram with a colour and setting a grid on the canvas.

In [9]:

Alright: we are done with our first step into the ROOTbooks world!