Given a collection of root files myrootfile_1.root, myrootfile_2.root,…, I plot muon_pt, stored in the tree mytree, as follows:
TChain ch(“mytree”);
ch.Add(“myrootfile_*”);
TCanvas *C = new TCanvas();
TH1F *h = new TH1F(“h”, “”, nbins, x1, x2);
ch.Draw(“muon_pt>>h”);
C->SaveAs(“muon_pt.pdf”);
Starting from this plot, I would like to plot now the percentage of muons (on the y axis) as a function of muon_pt. In other words, I would like to plot I(muon_pt>=x), where I is the integral of the previous plot between x and +∞.
The y axis of my original histogram is the number of entries for bin. For example, for the 0 GeV < muon_pt < 0.1 GeV bin, there are 170 entries, for the 1.0 GeV < muon_pt < 1.1 GeV bin there are 48 entries, and so on.
Exactly, I would like to plot the number of muons with muon_pt larger then in the current in bin divided by the total number of muons. For example, the number of muons with muon_pt higher than 0 GeV, the number of muons with muon_pt higher than 0.1 GeV and so on.
Ah, okay, then try something like that in ROOT6 (won’t work in ROOT5):
TH1* h_cumulative = h->GetCumulative(false);//false because this is cumulative in a backward direction
h_cumulative->GetYaxis()->SetTitle("Percentage of muons with higher p_{T} [%]");
h_cumulative->Scale(100./h_cumulative->GetBinContent(1));//scale so that the first bin is at 100% no matter what