Problem with float to int conversion in plotting poisson errors from TH1F

ROOT Version: 6.06


I have a TH1F filled with integer numbers. With this two options I enforce Poisson errors in plotting:


Everything works fine except for one bin.
For one bin I set the bin content to 2.
If I call GetBinContent for that bin I get: 2
If I call GetBinErrorUp for that bin I get: 1.29953
If I call GetBinErrorLow for that bin I get: 1.82725
But it should be 2.63786 and 1.29181 respectively.
For a bin content of 1 it would be 2.29953 and 0.827246 respectively.

So, what causes the problem is the double to int conversion in the GetBinErrorLow/high function:
In my case the 2 is internally a 1.9999999 and it gets rounded to 1.
If I fill the histogramm with 2.00001 everything is fine.

Is it a option to change the line 8413 and 8443 from

Int_t n = int(c);


Int_t n = int(c+0.5);
if (c<-0.5) n = int(c-0.5);

or would this cause other problems?

As temporary workaround I add 0.00001 to each bin before plotting. Is there a better solution to avoid this?


Have you tried to use TH1D instead of TH1F ?

I just tried. It does not solve the problem. But I figured out, that I set the bin content not exactly to 2. It is already internally a 1.9999999. If I round the number before setting the bin content then everything works fine. This is what I will do now.

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