#!/usr/bin/env python
# coding: utf-8
# # Simple ROOTbook (Python)
#
# This simple ROOTbook shows how to create a [histogram](https://root.cern.ch/doc/master/classTH1F.html), [fill it](https://root.cern.ch/doc/master/classTH1.html#a77e71290a82517d317ea8d05e96b6c4a) and [draw it](https://root.cern.ch/doc/master/classTH1.html#aa53a024a9e94d5ec91e3ef49e49563da).
#
# Let's start importing the [ROOT](https://root.cern.ch) module, which gives us access to all [ROOT](https://root.cern.ch) classes.
# In[2]:
import ROOT
# In order to activate the interactive visualisation we can use the [JSROOT](https://root.cern.ch/js/) magic:
# In[3]:
get_ipython().run_line_magic('jsroot', 'on')
# Now we will create a [histogram](https://root.cern.ch/doc/master/classTH1F.html) 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()
h.Fill(rndm)
# We can now draw the histogram. We will at first create a [canvas](https://root.cern.ch/doc/master/classTCanvas.html), the entity which in ROOT holds graphics primitives. Note that thanks to [JSROOT](https://root.cern.ch/js/), 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()
h.Draw()
c.Draw()
# 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]:
h.SetFillColor(ROOT.kBlue-10)
c.SetGrid()
h.Draw()
c.Draw()
# Alright: we are done with our first step into the ROOTbooks world!