What is the error propagation formula of TH1 when using SetDefaultSumw2()?

Dear ROOT users,
I was using 2 TH1F histograms h_m and h_n to compute efficiency: h_\varepsilon = h_{m}/h_{n}:

TH1.SetDefaultSumw2()
# ... fill h_m and h_n
h_eff = TH1F(h_m)
h_eff.Divide(h_n)

According to the references it seems ROOT can handle errors properly by calling TH1::SetDefaultSumw2(). But when I checked the errors I found it is not equal to the value calculated by error propagation formula:

\begin{align} \varepsilon_i &= \frac{m_i}{n_i}\space (i=1,2,3,...,N_{bin}) \\ \sigma_{i} &= \sqrt{ \left(\frac{\partial\varepsilon_i}{\partial m_i}\right)^2 \sigma_{m_i}^2 + \left(\frac{\partial\varepsilon_i}{\partial n_i}\right)^2 \sigma_{n_i}^2 } \\ &=\sqrt{\varepsilon_i^2 \left( \frac{\sigma_{m_i}^2}{m_i^2} + \frac{\sigma_{n_i}^2}{n_i^2} \right)} \\ &=\sqrt{\varepsilon_i^2 \left( \frac{1}{m_i} + \frac{1}{n_i} \right)} \ \ \ \ \ \ \text{since} \ \sigma_{m(n)}^2=m(n) \\ &=\sqrt{\frac{m_i(m_i+n_i)}{n_i^3}} \end{align}

where m_i and n_i are obtained by GetBinContent(i), \sigma_{m_i} and \sigma_{n_i} are obtained by GetBinError(i) of h_m or h_n.

For example, for one bin, if m=10,n=34 (omit subscript i), GetBinError() will return their bin error: \sigma_m=\sqrt{10}=3.16,\sigma_n=\sqrt{34}=5.83

then h_eff.GetBinError() will return efficiency error: \sigma_{\mathrm{sumw2}}=0.25
while error propagation formula gives \sigma_\mathrm{propa}=0.11

I checked source codes of TH1::Divide, that formula seems the same as the error propagation formula I posted above.

Could anyone tell me how TH1 calculates errors under SetDefaultSumw2(kTrue) or what mistake I made?

Best wishes!

ROOT Version: 6.26/10
Platform: Linux


Hi @mrli,

welcome back to the forum. Maybe @moneta could take a look?

Cheers,
Marta

Hi,
TH1::Divide use this error propagation you have above. If you use the option 'B` assumes a binomial distribution.

in your case, I cannot reproduce your problem. This gives me the correct result (sigma = 0.105805)

   TH1::SetDefaultSumw2(true);
   TH1D h1("h1","h1",1,0,1);
   TH1D h2("h2","h2",1,0,1);
   h1.SetBinContent(1,10);
   h2.SetBinContent(1,34);
   // need to set the bin error if you have default sumw2
   h1.SetBinError(1,sqrt(10.));
   h2.SetBinError(1,sqrt(34.));
   TH1D h3 = h1;
   h3.Divide(&h2);
   std::cout << h3.GetBinError(1) << std::endl;

please share the full code, so I can see the error

Lorenzo

1 Like

I know how the problem occures!

I am using JupyROOT, the division cell is like:

h3 = ROOT.TH1F(h1)
h3.Divide(h2)

When the first time I ran that notebook, I forgot to call ROOT.RH1.SetDefaultSumw2(True), so I created and ran a new cell with ROOT.RH1.SetDefaultSumw2(True). After that I ran the division cell again, thinking the ROOT.TH1F may create a new instance of h1 with correct error which actually did not.

Sorry for my carelessness and thanks for help!

Best wishes