Something else… to tell you how the thing started…
Take a look at the following script:
{
TH1D histo("histo","histo",10,0,10);
for(int i = 1; i != 11; ++i)
{
histo.Fill(i,i**2);
}
cout << "number 1.9 is in bin " << histo.GetBin(1.9) << endl;
cout << "number 2 is in bin " << histo.GetBin(2) << endl;
cout << "number 2.1 is in bin " << histo.GetBin(2.1) << endl;
cout << "content of bin 2 is " << histo.GetBinContent(2) << endl;
cout << "content of bin 3 is " << histo.GetBinContent(3) << endl;
histo.Draw();
}
This one gives me the output:
root [0]
Processing testHisto.C...
number 1.9 is in bin 1
number 2 is in bin 2
number 2.1 is in bin 2
content of bin 2 is 1
content of bin 3 is 4
<TCanvas>: created default TCanvas with name c1
As you can see, I am checking for values right in the boundary between bins (that is why I tried the half integer bin boundaries in the previous post). As expected, 1.9 is in the bin below 2.1 and 2 falls in the bin corresponding to the integer part. That is fine. Bins seem to be numbered starting from 0.
Then, when I query for the bin content, I get the content of the bin below. It seems that GetBinContent indexes bins starting from 1!
So, this can create a big mess! Maybe that is documented somewhere, but it is clearly a problem. You should either index stuff in the C++ way or the natural way, whatever you prefer, but be consistent. Of course, there are tons of code written using this convention, and maybe we are stuck with it. I don’t know.
If this is not a bug, but a “feature” of ROOT, or if I am completely wrong, making some programming mistake, then please accept my apologies.