In order to activate the interactive visualsisation we can use the JSROOT magic:
%jsroot on
Now we will create a histogram specifying its title and axes titles:
TH1F h("myHisto","My Histo;X axis;Y axis",64, -4, 4)
(TH1F &) Name: myHisto Title: My Histo NbinsX: 64
If you are wondering what this output represents, it is what we call a "printed value". The ROOT interpreter can indeed be instructed to "print" according to certain rules instances of a particular class.
Time to create a random generator and fill our histogram:
TRandom3 rndmGenerator;
for (auto i : ROOT::TSeqI(1000)){
auto rndm = rndmGenerator.Gaus();
h.Fill(rndm);
}
We can now draw the histogram. We will at first create a canvas, the entity which in ROOT holds graphics primitives.
TCanvas c;
h.Draw();
c.Draw();
We'll try now to beutify the plot a bit, for example filling the histogram with a colour and setting a grid on the canvas.
h.SetFillColor(kBlue-10);
c.SetGrid();
h.Draw();
c.Dra();
input_line_57:5:3: error: no member named 'Dra' in 'TCanvas' c.Dra(); ~ ^
Oops! We mispelled a method. Luckily ROOT informed us about the typo. Let's draw the canvas properly:
c.Draw();
Alright: we are done with our first step into the ROOTbooks world!