Something else… to tell you how the thing started…
Take a look at the following script:
for(int i = 1; i != 11; ++i)
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;
This one gives me the output:
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.