Error bars in TProfile from unweighted TH2

Hello ROOTers,

I have a TH2 histogram that I fill without weights. When I call ProfileX() on that histogram, the error bars that come out for each bin are not the standard error on the mean (sigma/sqrt(N)) that I expect. However, if I call h2->Sumw2() before I call h2->ProfileX(), the error bars are what I expect. I thought that I didn’t have to call Sumw2() to get the correct errors if my 2-d histogram is unweighted. Am I misunderstanding? This is in v6.03/03. I can provide a sample file if that would help.


According to … 23b01fa014
you should call TH1::SetDefaultSumw2 to have this behavior automatic.

Thanks, that’s very helpful and I will definitely use that. I’m still unclear about why I need to call this for the error bars to be correct when I am creating a profile out of an unweighted TH2. I thought the sum of weights structure would only be used to calculate the standard deviation in a bin when the bin has weighted entries. If that’s not the case, we should probably update the ProfileX() documentation in TH2 to tell users to call Sumw2() before calling ProfileX().


Your analysis is correct. In principle calling TH1::Sumw2() should not be needed. This is a current limitation and I’ll see if I can remove it. One needs to set correctly the number of bin entries in the obtained profile
If you could submit bug report in JIRA with a minimal example showing this problem, it would be helpful.

Thank you for reporting this problem

Best Regards