TH1::GetMean() feature or a bug

Hi everybody, I posted the next lines into roottalk@cern.ch already, Pere told me I should rather use the forum for question of that kind:

Dear ROOTers,

Today I recognized something in root and I am not sure if it is a
feature or a bug! Please see the attached example. Both charts look
identical by the means are different

I always thought that the mean-value which is written in the stat box
above a histogram (or reachable by GetMean()) relies on the discrete
values of the histogram bins. I checked the source code and indeed the
mean and also the RMS is calculated by using the individual values used
in the Fill-command (which have usually a much finer resolution than the
bin-width).

This is interesting, because I always thought, one could use a histogram
to calculate a performance record (german: Notenspiegel or
Klassenspiegel) - like 6 people have a grade between 1 and 2, 10 between
2 and 3, and so on. It seems this is not possible. By calculating the
performance record you have to use the BinCenter-Value of each bin and
its content, but not the full resolution of every value.

I’m 99% sure that this is a feature, not a bug (can’t believe that this
was not discovered since 10 years :-p). But from the doc it does not
come clear that GetMean() is not calculated from the content of the
bins, bot from the value entered in the Fill-method.

Is there an easy way to calculate the mean based on the BinCenter
values? (without looping over all bincontents from outside the TH1-class)

Georg
getMean.C (633 Bytes)

h1->ResetStats(); // after all h1->Fill(…) and before h1->GetMean()

From Lorenzo answer in roottalk mailing list:
Dear George,

The statistics for a ROOT histogram (mean and StandardDeviations) are computed by default using the filled values and not the bin center. This has alsways been like this and it is a feature and not a bug. It is maybe not clearly documented, I will add a sentence in the TH1::GetMean and TH1::GetStdDev.
Note that when a range is set in the histogram the statistics are computed using the bin center values.

The calculation of the statistics using the bin center can also be forced by calling before TH1::ResetStats() before TH1::GetMean.

Best Regards

Lorenzo