Sum and ratio of histos with different binning

Hello, in this macro I plot:

  1. I get a Th1f from a root file (hExp0)

TH1F *hExp0 = (TH1F *)g->Get("GePD");

2) I plot also other Th1f (hSim0 and hSim097) getting values from a TTree. And I bin hSim0 and hSim097 using the binning of hExp0, i.e.

  TH1F *hSim0 = (TH1F*)hExp0->Clone("htemp0");
		TString hString0 = TString::Format("Edep[0] >> htemp0"); 
	TH1F *hSim097 = (TH1F*)hExp0->Clone("htemp097");
		TString hString097 = TString::Format("Edep[0] >> htemp097"); 

  1. I get other Th1f from other root file (hBib0) and I plot it.

TH1F *hBib0 = (TH1F *)l->Get("GePD");

  1. I need to plot the sum hSim0+hSim097+hBib0 (i.e. hSimBib0sum)
TH1F *hSim0sum = (TH1F *)hSim0->Clone("hSim0sum");
    		if (!(hSim0sum->GetSumw2N() > 0))hSim0sum->Sumw2(kTRUE);
	TH1F *hSimBib0sum = (TH1F *)hSim0sum->Clone("hSimBib0sum");
    		if (!(hSimBib0sum->GetSumw2N() > 0))hSimBib0sum->Sumw2(kTRUE);
  1. I need to plot the ratio between hExp0 and hSimBib0sum (i.e. ratio0).
 TH1F *ratio0 = (TH1F *)hExp0->Clone("ratio0");
    if (!(ratio0->GetSumw2N() > 0))ratio0->Sumw2(kTRUE);

The problem is that hBib0 has a different binning than hExp0 (therefore also different binning than hSim0 and hSim097, because I binned hSim0 and hSim097 using the same binning of hExp0), then I can’t get sum hSim0+hSim097+hBib0 and I can’t have the ratio hExp0/hSimBib0sum.

Is it possible to assign to hBib0 the same binning of hExp0 (as I did for data from the Tree)? Or what should I do to correctly sum and divide histos with different binning?

detsumbibratio.cpp (7.9 KB)

Create all histograms with the same binning as the old one, which you cannot “recreate”.

If your GePD histograms in different files have different binnings, there is not much you can do other than to recreate all your files (or ask someone to do it for you) with histograms using the same binning.

Hello @Wile_E_Coyote and @yus

The hExp0 is the histogram of data and hBib is a histogram of BIB. I changed research group since a few time then I didn’t take part of that data acquisition (it has been done before that I started tge new work).
A collegue gave me the two histograms (hExp0 and hBib0) to compare them with my MC simulation (hSim0 and hSim097).

1.Is it possible to rebin one of the two histograms or should I ask raw data to fill a new histogram?
2. How knowing the number of bins of hExp0 histogram?


1 - Get the raw data
2 - histo->GetNbinsX()

Thank you @dastudillo, then I’ve to ask for the raw data…I don’t have them…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.