TH1S and GetMean

Hi,

Using ROOT 4.02/00 or ROOT 5.10/00 on windows we see the following behavior:

root [0] h = new TH1S("","",100,0,100)
(class TH1S*)0xc4c2a00
root [1] h.SetBinContent(1,100)
root [2] h.SetBinContent(90,100)
root [3] h.GetMean()
(const Double_t)4.50000000000000000e+001
root [4] h.Fill(20)
(Int_t)21
root [5] h.GetMean()
(const Double_t)2.00000000000000000e+001

Why does the mean seem to ignore bins 1 and 90? Initially I thought perhaps the range was getting reset to something that excluded bins 1 and 90 - but I can’t find evidence that is the case.

I also check the results of GetStats:
root [11] h.GetStats(stats)
root [12] stats[0]
(Double_t)1.00000000000000000e+000
root [13] stats[1]
(Double_t)1.00000000000000000e+000
root [14] stats[2]
(Double_t)2.00000000000000000e+001
root [15] stats[3]
(Double_t)4.00000000000000000e+002

Which is consistent with the GetMean value of 20, but I’m still not sure why that is happening.

Is this a feature?

Take care,
Heather

Heather,

TH1::setBinContent does not change the statistics (mean,rms,etc),
only TH1::Fill does it.

TH1::GetMean knows how to compute mean/rms when the stats are not filled.
This explains why after your two first calls to SetBinContent, GetMean returns a correct value. As soon as you call Fill, GetMean will rely only on the stats from Fill.

Use setBinContent only if you want to set/replace a particular bin content.
Do not mix the two calls.

Rene