You need:
// ...
TH1D *h = new TH1D("Energy", "Final Energy; Protons; Frequency", 50, 0., 2.);
for (Long64_t jentry = 0; jentry < nentries; jentry++) {
// ...
if (pdgf[pdgindex] == 2212) {
h->Fill(Your_Particle_Final_Energy_Value); // maybe (Ef[pdgindex])
}
// ...
}
h->Draw();
// ...
BTW. If this is the same tree as in the “InteractionsII.root” file, instead of:
for (Long64_t pdgindex=0; pdgindex<28;pdgindex++)
you need:
for (Int_t pdgindex = 0; pdgindex < nf; pdgindex++) // if you use the "pdgf[nf]/I " branch inside
or:
for (Int_t pdgindex = 0; pdgindex < ni; pdgindex++) // if you use the "pdgi[ni]/I " branch inside