# TH::Sumw2()

Hi,

I observe that when I fill into a histogram’s underflow or overflow bin, the number of entries is updated as expected but the sum of weights is not:

``````root [0] TH1D h("h", "h", 10, -0.5, 9.5)
root [1] h.Sumw2()
root [2] h.GetEntries()
(const Double_t)0.00000000000000000e+00
root [3] h.GetSumOfWeights()
(const Double_t)0.00000000000000000e+00
root [4] h.Fill(15, 2)
(Int_t)(-1)
root [5] h.GetEntries()
(const Double_t)1.00000000000000000e+00
root [6] h.GetSumOfWeights()
(const Double_t)0.00000000000000000e+00``````

To my understanding, I believe this is incorrect behavior because the normalization will be wrong.

In general, I believe each event should be normalized by w/(sum of w) where w = event weight. The sum of weights should include weights from all events filled regardless of whether it went into under/overflow. This can be seen in the extreme case where e.g. events only enter the overflow, where otherwise the supposed normalization factor has a 0 in the denominator i.e. is infinite.

Am I missing something obvious?

Thanks,
Eric

Hi,
the histogram normalization is computed normally using only the entries in the histogram range (i.e. excluding underflow and overflow).
TH1::GetSumOfWeights does not consider the underflow and overflows.
This is documented in root.cern.ch/root/htmldoc/TH1.ht … mOfWeights

Best Regards
Lorenzo

[quote=“moneta”]Hi,
the histogram normalization is computed normally using only the entries in the histogram range (i.e. excluding underflow and overflow).
TH1::GetSumOfWeights does not consider the underflow and overflows.
This is documented in root.cern.ch/root/htmldoc/TH1.ht … mOfWeights

Best Regards
Lorenzo[/quote]

Hi Lorenzo,

Thanks, I see that now in the documentation. But why is that the case? I believe the argument I gave about that the sum of weights should include underflow and overflow bins was correct.

Eric

Hi,

your argument does not make much sense to me, because if the are are no events in the histograms, there is nothing to normalize.
I remind you that also all the histogram statistics, sum of weights, sum of weights square, mean , standard deviation, etc… it is computed using only the events in the histogram range.
See root.cern.ch/root/htmldoc/TH1.html#TH1:GetStats

Lorenzo