I have a histogram in a ROOT file whose x-axis is channel number and y-axis is number of hits. I am trying to divide number of hits by total entries of a histogram and plot this hitrate in new histogram where x-axis is channel number and y-axis in hitrate.
11 void code() {
12 TFile *file = new TFile("onmon_r1169_s1-92.root", "READ");
13 TH1F *hist = (TH1F*)file->Get("SSDProfile_14");
14 int entries = hist->GetEntries();
15 // cout << entries << endl; //Output: 503071
16
17 TH1F* new_hist = new TH1F("hitrate", "hitrate per channel", 100, 0, 700);
18
19 for (int i = 0; i <= entries; i++) {
20 //hist->GetBinContent(i);
21 double bin_content = hist->GetBinContent(i);
22 double hitrate = bin_content/entries;
23 new_hist->SetBinContent(i, hitrate);
24 }
25
26 new_hist->Draw();
27
28 }
However, the histogram I produced is not as expected. I think I am messing up on GetBinContent part. Please let me know how I can fix the issue. Thank you.