I wanted to make an example script to demonstrate how Sumw2 affects error bars for weighted histograms. I was expecting that sqrt(bin content) would be drawn if I did not call Sumw2(). However, I cannot seem to avoid the Sumw2 errors, even if I call SetDefaultSumw2(kFALSE). Here is an example:
Hi @yus, OK, that is interesting – to turn off Sumw2, that call to Sumw2(kFALSE) needs to be done after filling the histogram. That is sort of counterintuitive, but OK.
However, as a suggestion to the developers, I would suggest that the behavior of SetDefaultSumw2(kFALSE) be changed. If a user calls that, and then goes on to fill a histogram with weights, then Sumw2 gets silently activated. This should either be changed, or a console message should alert the user that Sumw2 was activated.
The documentation of Sumw2-related things is a bit confusing too – here are some parts of the documentation which seem to give a reader the wrong impression.
under the documentation of Sumw2:
This function is automatically called when the histogram is created if the static function TH1::SetDefaultSumw2 has been called before. If flag = false the structure containing the sum of the square of weights is rest and it will be empty, but it is not deleted (i.e. GetSumw2()->fN = 0)
This seems to indicate that Sumw2 should not have happened for hn in my above example, but in fact it does happen.
in the “Filling Histograms” section:
If TH1::Sumw2 has been called before filling, the sum of squares of weights is also stored.
This seems to indicate that Sumw2 should be called beforehand if you want Sumw2 errors – but in fact Sumw2 happens by default and if you want it not to happen, the Sumw2(kFALSE) call needs to be called afterword, as in @yus above example.