Hi all,
I’m trying to use root to calculate the ratio between two histograms (trying to find the acceptance of my experiment). I’ve been following the tutorial shown here, but when I try to apply the code to my histograms, it doesn’t work. As far as I can tell, the problem is with Clone() and/or Divide().
Here’s the code I wrote. I’m creating the canvas as a diagnostic more than anything else. The numerator and denominator histogram will display fine, but the ratio histogram won’t, both before and after I take the ratio. If anyone sees something I’m doing wrong, that would be so helpful.
void testratio() {
//Open ROOT files
TFile *fnum = TFile::Open("hist_pomegapi_30496.acc.root");
TFile *fden = TFile::Open("hist_thrown.root");
//Read the 3 Pion Mass histograms
TH1I *locHist_3PiMass_num = (TH1I*)fnum->Get("3PiMass_Measured");
TH1I *locHist_3PiMass_den = (TH1I*)fden->Get("3PiMass_thrown");
//Define a canvas
TCanvas *cc = new TCanvas("cc", "cc", 600, 600);
cc->Divide(2,2);
//Draw the 3 Pion Mass histograms
cc->cd(1);
locHist_3PiMass_num->Draw();
cc->cd(2);
locHist_3PiMass_den->Draw();
//Take their ratio and draw it
TH1I *locHist_ratio = (TH1I*)locHist_3PiMass_num->Clone();
cc->cd(3);
locHist_ratio->Draw();
locHist_ratio->Divide(locHist_3PiMass_den);
cc->cd(4);
locHist_ratio->Draw();
}