Automatic binning in TH1

Hi experts,

when creating a histogram with identical xmin and xmax, ROOT creates the binning for you automatically. This usually works fine as long as you fill some non-crazy values.

Now I discovered a strange behavior - it seems ROOT doesn’t like x=0 if you also fill at x<0.

Example:

root [0] auto h1 = new TH1F("","",50,0,0);
root [1] h1->Fill(0); h1->Fill(-10);
root [2] h1->GetMean()
(double) -10.000000
root [3] cout << '[' << h1->GetXaxis()->GetXmin() << " .. " << h1->GetXaxis()->GetXmax() << ")\n";
[-11 .. 0)

As you can see, 0 is in the overflow bin and the binning is -11 to 0 (exclusive). If you fill any value != 0 then everything is fine, for example 0.1 or 1:

root [4] auto h2 = new TH1F("","",50,0,0);
root [5] h2->Fill(1); h2->Fill(-10);
root [6] h2->GetMean()
(double) -4.500000
root [7] cout << '[' << h2->GetXaxis()->GetXmin() << " .. " << h2->GetXaxis()->GetXmax() << ")\n";
[-11 .. 2)

Here the upper limit is 2, i.e. 1 is inside the range.

The problem seems to happen only if the maximum x is exactly 0.

Is this intended behavior?

Yes it seems 0 is a special case.
I think @moneta can help you.

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