Walkthrough: Making Histograms

(10 minutes)

This tutorial is all about making histograms, so let’s use RDataFrame to make a histogram. Here’s an example of making a histogram of chi2 from the dataframe:

Listing 6: RDataFrame - create a histogram (C++)
histchi2 = dataframe.Histo1D("chi2");
Listing 7: RDataFrame - create a histogram (Python)
histchi2 = dataframe.Histo1D("chi2")

We’ve made the histogram. Now let’s draw it:

Listing 8: RDataFrame - draw a histogram (C++)
histchi2->Draw();
Listing 9: RDataframe - draw a histogram (Python)
histchi2.Draw()

Give it a try!

What’s that? It didn’t work? It didn’t if you’re using a notebook.

I’m being sneaky: I counted on you to forget the bit about needing a canvas (either in C++ or Python). Here’s a more complete example:

Listing 10: RDataFrame - drawing a histogram with a canvas (C++)
TCanvas canvas;
histchi2->Draw();
canvas.Draw();
Listing 11: RDataFrame - drawing a histogram with a canvas (Python)
canvas = ROOT.TCanvas()
histchi2.Draw()
canvas.Draw()

Tip

While we have to explicitly Draw a canvas, we can re-use a previously-defined canvas (the same way command-line ROOT keeps re-using c1).

Follow the above examples to make histograms of the other variables in the n-tuple.

Hint

I will permit you to use copy-and-paste (in a notebook) or the up-arrow key (if you’re using the command line) to speed up this task. The fact that I have no way to stop you has nothing to do with it.

xkcd flawed_data

Figure 34: https://xkcd.com/2494/ by Randall Munroe