Simple ROOTbook (C++)¶
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). The language chosen is C++.
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)
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();
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!