How to make TH1 recalculate stats?

From: Benjamin Monreal <bmonreal_at_mit.edu>
Date: Sat, 2 Jun 2007 10:45:49 -0400

Hello ROOTers,

How do I force ROOT to recompute the mean, RMS, etc. of a histogram after a SetBinContent operation? I had thought that TH1::Rebuild() would do it but this seems not to be the case:

root [0] test = new TH1F("test","test",2,0,10)
(class TH1F*)0x7149a00

root [1] test->FillRandom("pol0",1000)
root [2] test->GetMean()
(const Double_t)5.01881719480501509e+00

root [3] test->SetBinContent(2,0) // the mean should now be 2.5 root [4] test->GetMean() // but it is not
(const Double_t)5.01881719480501509e+00

root [5] test->Rebuild() //nothing seems to trigger a recalc based on bin contents
root [6] test->GetMean()
(const Double_t)5.01881719480501509e+00

root [7] test->Add(test,1e-5)
root [8] test->GetMean()
(const Double_t)5.01881719480501509e+00

root [9] test->Fill(7,1e-5)
(Int_t)2

root [10] test->GetMean()
(const Double_t)5.01881721461664476e+00

root [11] test->Sumw2()
root [12] test->GetMean()
(const Double_t)5.01881721461664476e+00

root [13] test->Rebuild()
root [14] test->GetMean()
(const Double_t)5.01881721461664476e+00

Everything is fine if your *first* histogram operation is a SetBinContent, but not if you start with Fill and SetBinContent later.

(using 5.14/00b on OS X)

Cheers,

-Ben Monreal Received on Sat Jun 02 2007 - 16:47:15 CEST

This archive was generated by hypermail 2.2.0 : Tue Jun 05 2007 - 17:50:02 CEST