Relative error of the ratio

Hello Rooters,

I have two histograms called h_simu and h_gen(2D hist). Applied SumW2 option before filling the histograms.Then I took the ratio of these two histograms.
h_ratio= h_simu/h_gen

I need to calculate the “relative error of this ratio histogram”.
Could you please check if my way is correct?

h_ratio_error=(TH2F *)h_ratio->Clone("h_ratio_error");
for(int i=0; i < h_ratio->GetSize();i++){
                h_ratio_error>GetArray()[i]= h_ratio_error->GetBinError(i)/(h_ratio_error->GetBinContent(i)+0.1);
                h_ratio_error->Sumw2(kFALSE);
                h_ratio_error->ResetStats();
                h_ratio_error->SetTitle("Relative Error of the ratio histogram CsHS vs mpipi");
                h_ratio_error->Draw("COLZ ");
                
   }

For 1-D histograms:
TRatioPlot
${ROOTSYS}/tutorials/hist/ratioplot*

I’m afraid there is no “ready-to-use” tool for 2-D cases.

Thank you.
What about my calculation?
The reason I was worring my calculation is, my errors are too big.
When I commented out h_ratio_error->Sumw2(kFALSE);
I got reasonable errors.
Need to know my calculation is okay without h_ratio_error->Sumw2(kFALSE);
I already applied sumw2 options for the h_simu and h_gen histograms.

Thanks
Dil

If histograms have errors defined (see TH1::Sumw2) and you used:
TH1::Divide(const TH1 *h1)
or:
TH1::Divide(const TH1 *h1, const TH1 *h2, Double_t c1, Double_t c2, Option_t *option)
then the errors should be “properly” taken into account.

Yes. I used that way.

//Applied sumw2 while filling the histogram
h_simu
h_gen

h_ratio=(TH2F *)h_simu->Clone();
 h_ratio->Divide(h_gen);
 h_ratio->Draw("COLZ TEXT45");

//relative error

h_ratio_error=(TH2F *)h_ratio->Clone("h_ratio_error");
for(int i=0; i < h_ratio->GetSize();i++){
                h_ratio_error>GetArray()[i]= h_ratio_error->GetBinError(i)/(h_ratio_error->GetBinContent(i)+0.1);
             //   h_ratio_error->Sumw2(kFALSE);
                h_ratio_error->ResetStats();
                h_ratio_error->SetTitle("Relative Error of the ratio histogram CsHS vs mpipi");
                h_ratio_error->Draw("COLZ ");
                
   }

My question is h_ratio_error->Sumw2(kFALSE);
Is it need or not?

With h_ratio_error->Sumw2(kFALSE);-Big errors
Without h_ratio_error->Sumw2(kFALSE);-small errors

which is correct?

Thanks
Dil

TH2F *h_ratio_error = (TH2F*)h_ratio->Clone("h_ratio_error");
for (int i = 0; i < h_ratio_error->GetSize(); i++)
  h_ratio_error->GetArray()[i] = (h_ratio_error->GetBinContent(i) ? h_ratio_error->GetBinError(i) / h_ratio_error->GetBinContent(i) : 0.);
h_ratio_error->Sumw2(kFALSE);
// h_ratio_error->ResetStats();

BTW. See also the older thread: “Error calculation of 2D histogram

Thank You,@Wile_E_Coyote.
This gave me nice errors but when I commented out h_ratio_error->Sumw2(kFALSE);.

Bin errors of the “h_ratio_error” histogram are meaningless (after the content of its bins has been modified).