You are here

Histogramming in a Selector

Preparation

As previously, we provide a ready-made TSelector derived class in a simple source file. So please download also the following source file and save it where you can find it: EventDataSelector.C (or wget http://root-mirror.github.io/training/intro/EventDataSelector.C). This selector contains all the necessary steps to read the data from the tree branches, like the number of particles, the X position of each particle PosX[nparticles], and the absolute momentum of each particle Momentum[nparticles].

Now quit and restart ROOT (to make sure everybody starts from the same point). Then open the file again:

root[0] TFile::Open("http://root.cern/files/introtutorials/eventdata.root");

Adding a Data Member

Just like for the sum of event sizes, you need to add a data member to the class. As in Histogramming, we want to histogram the particles' fPosX; the type of the data member should thus be TH1F*. Don't forget to initialize the histogram pointer to 0 in the constructor, again just like for the event size sum.

Creating the Histogram

You then create the object with new TH1F("hPosX", "Position in X", 20, -5, 5);; check the documentation of TSelector to learn in which of your selector's functions to create the histogram object.

Associate error bars with this histogram (see TH1F::Sumw2())

Filling the Histogram

Like in the Histogramming chapter, fill the histogram with the value of fPosX from the tree for all particles with a momentum > 40. Just like before, the per-event analysis happens in Process(). Here again, you need to get the tree entry before you can access the corresponding data members of your selector.

Fitting and Drawing the Histogram

Here again, once the histogram is filled, fit it with a pol2 using TH1::Fit("pol2"). See the documentation of TSelector on where to do the fitting, i.e. which function of your selector gets called after the whole tree has been processed. You should first fit and then draw, to see the fit together with the histogram.

At the end, you should get the same result than the figure 6 in Histogramming

If, for any reason, you don't manage to get it working, you can download the working selector file here: FullEventDataSelector.C (or wget http://root-mirror.github.io/training/intro/FullEventDataSelector.C)

Note: You will have to use it that way:

EventTree->Process("FullEventDataSelector.C")