TH1 mean calculation - Bin value when zoom or not

I had an issue with histogram mean calculation, which is probably already known, but couldn’t find proper documentation for it.

When drawing the histogram, I guess the mean shown is the real one.
When zooming (or changing range) the mean is recalculated and shown properly, but it is different. Makes sense since it’s derived from the binned data.

However, I found that when working with integers (e.g. TH1I) the mean is calculated using the middle of the bin as bin value, which gives a very wrong value.

This can be seen even when zooming in the histogram, into a single bin, which goes from 2 to 3, then it gives the mean 2.5. But clearly it should be 2, since it is a histogram of integers

I assume there is a reason for keeping this same as other classes, but naively I would expect that when having TH1I, the mean calculation actually uses the start of the bin instead of the middle.

_ROOT Version: 6.10.08 and 5.34.36
_Platform: Linux Mint
Compiler: Not Provided

The “I” in the “TH1I” means “integer Y”. The “X” axis is always “double” so, make your histogram bins’ edges 0.5, 1.5, 2.5, … (i.e. nbinsx = “xmax - xmin + 1”, xlow = “xmin - 0.5”, xup = “xmax + 0.5”).

1 Like

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