Create a Histogram - C++ version

Create a histogram, fill it with random numbers, set its colour to blue, draw it. Can you:

  • Can you use the native Python random number generator for this?
  • Can you make your plot interactive using JSROOT?
  • Can you document what you did in markdown?

We now create our histogram


In [1]:
TH1F h("h", "My Notebook Histo;x;#", 64, -4, 4)


(TH1F &) Name: h Title: My Notebook Histo NbinsX: 64

It is not easy nor efficient to use the Python random number generator in this context. We go for TRandom3


In [2]:
TRandom3 r(1);
for (auto i : ROOT::TSeqI(1000)) h.Fill(r.Gaus());

Time for styling the histogram and use jsroot


In [3]:
%jsroot on
h.SetLineColor(kBlue);
h.SetFillColor(kBlue);
TCanvas c;
h.Draw();
c.Draw();