TH1::SetBinContent does not change the statistics (at the difference of
TH1::Fill or TH1::AddBinContent).
In general this is OK because one does not mix calls to TH1::Fill and
TH1::SetBinContent.
In the CVS head, I have modified the SetBinContent functions such that
calling later GetMean, GetRMS, GetStats will force the re computation of
the statistics.
As a workaround when mixing Fill and SetBinContent, you can reset the
statistics by doing:
double stats[4] = {0,0,0,0};
myhist.PutStats(stats);
Rene Brun
Benjamin Monreal wrote:
>
> 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 Tue Jun 05 2007 - 12:51:18 CEST
This archive was generated by hypermail 2.2.0 : Tue Jun 05 2007 - 17:50:02 CEST