Preparation
Start from the previously used macro (AnalyzeTree.C).
Adding a Variable
Just like for the sum of event sizes, you need to add a variable in your macro. We want to histogram the particles' fPosX; the type of the data member should thus be TH1F *. TH1F is a 1 dimensional histogram storing floats for each bin, see the documentation. Don't forget to initialize the histogram pointer to 0, 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);
Associate error bars with this histogram (see TH1F::Sumw2())
Filling the Histogram
The goal is to fill the histogram with the value of fPosX from the tree for all particles with a momentum > 40. You will need access to the particles' total momentum and their X position. Each TTree entry has several particles; it's thus easiest to use one TTreeReaderArray each for these Double_t values, for instance TTreeReaderArray
The analysis happens in loops. The outer loop is iterating through the TTree entries, using the TTreeReader::Next() loop - just as before. For each TTree entry, loop over all particles of the TTree entry with a simple for loop. For each particle, check that its momentum is > 40; if it is, fill the histogram (see TH1F::Fill()) with the fPosX value of that particle.
This step involves writing some code (similar to the code you have for the event size). If you get lost (SPOILER ALERT!): the solution is at the end of this page.
Fitting and Drawing the Histogram
Once the histogram is filled, fit it with a pol2 using TH1::Fit("pol2"). Here "pol2" is ROOT's short name for "polynomial of 2nd degree", i.e. [0] + [1]x + [2]x*x, aka "parabola".
"Fitting" means using a function (in this case the pol2) with one or more free parameters ([0]..[2] in this case) and looking for those values of the parameters that result in the function passing as closely as possible through the data points, where "close" takes the points' uncertainties into account. You should first fit and then draw, to see the fit together with the histogram.
At the end, you should get something like this:

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