fgDefaultSumw2=kTRUE and histogramm with variable bin width

Somewhere in the programm I called TH1::SetDefaultSumw2().

Then I create common TH1D histogramms with fixed width bins.
Eveything is OK.
But when I create TH1D histogramm with variable bin width, I have Warning in TH1::GetBinContent: this method must be overridden! many times. It happens, when Sumw2() function is automatically called. If I call TH1::SetDefaultSumw2(kFALSE) just before creation of that histogramm and hist->Sumw2() after the creation, I don’t have any warnings.
I create histogramm in the following way:
TH1D* hist = new TH1D(“hist”, “Some count”, someArrayD->GetSize(), someOtherArrayD->GetArray());
where
someOtherArrayD->GetSize() = someArrayD->GetSize() + 1;

What am I doing wrong?

Hi!

I stumbled upon the same problem. When I create histograms with variable bin size after calling TH1::SetDefaultSumw2() the warning
Warning in TH1::GetBinContent: this method must be overridden!
is produced very often.

The program works as intended, but this is nevertheless a little bit annoying.

The reason seems to be similar to warning reported here: http://root.cern.ch/root/roottalk/roottalk08/0278.html
The call to TH1::Sumw2 is included in the TH1 constructors for variable bin size, where the bins are not existent when it is called. Therefore the warnings are produced. In most of the derived class’s constructors the Sumw2 call is included (the only one were I could not see it, was the Double_t* xbins expecting constructor of TH1I). So maybe the calls can be removed from the base class constructors?

Kind Regards,
Arne.

Hello,

this is has been already fixed since few weeks in the ROOT svn trunk

Best Regards

Lorenzo

Thank you, Lorenzo.

But I can’t see the change. I checked TH1.cxx in the SVN trunk and there are still see the calls to Sumw2() in the constructors for variable bin size in lines 654 and 680. I think these lines can be deleted completely but it has to be entered into extended class’s constructors at line 8182 (TH1I). However, I haven’t checked the TH2 and TH3 constructors.

Kind Regards,
Arne.

Hello Arne,

the problem is not the call to Sumw2(). This has to be in the constructor if you have set the static TH1::SetDefaultSumw2().
The problem comes from calling the method GetBinContent from the constructor of the base class TH1, since the derived TH1D or TH1F is not yet constructed. The fix has been applied in Sumw2. When the entries are zero, GetBinContent is not call.
You should not get anymore of those messages now, if you still do please let me know

Best Regards

Lorenzo

Hi Lorenzo,

your solution should remove the error messages for each bin. It seems to me that this has already been accounted for in the TH2 constructors some time ago. But there I still get the following warning:

Warning in TH2F::Sumw2: Sum of squares of weights structure already created

because the Sumw2() is called twice: once in the constructor of TH2F and once in the constructor of TH2. However, the latter is protected and will hence not be called directly.

Therefore, with TH1 I went the way proposed earlier, namely removed the call to Sumw2() in the base class constructors and it works perfectly without any warnings. In the fixed bin size constructor of TH1 the call to Sumw2() was missing already, so there the problem did not occur.

Kind Regards,
Arne.

Hi Arne,

you are right that Sumw2() is called twice for the variable bin histograms and the call could be skipped. I will have to check that it is called for all the derived TH1 classes.
However you should not get that warning message with the current trunk version.

Best Regards

Lorenzo

Thank you Lorenzo,

I have not yet been able to check with the recent trunk, because I have to build another large framework against Root, but I will hopefully try it soon.

Kind Regards,
Arne.

Hi Lorenzo,

just another note here: Today I finally managed to try my program with the (recent) SVN trunk version. Indeed all “Warning in TH1::GetBinContent: this method must be overridden!” are now gone (which largely speeds up the initialisation of the program :smiley: ), but I still get “Warning in TH1F::Sumw2: Sum of squares of weights structure already created” for each TH1F with variable bin size.

Kind Regards,
Arne.

Hi Arne,

I cannot reproduce this problem with the trunk. It is true that Sumw2() is called two times, but the warning message should not be produced when
TH1::SetDefaultSumw2 is set.
Can you please send me the simpler script reproducing this problem,
Thank you
Lorenzo

Hi Lorenzo,

maybe this is not a problem of Root itself. I use Root-Histograms (and other stuff) inside the Go4 framework (go4.gsi.de). Therefore I can hardly produce a simple script where this error occurs. I have tried to reproduce it using the Root console but failed…

While running the program in Go4 there are actually two processes: the Go4 framework GUI itself and the analysis thread, where I have defined the histograms. The warnings for GetBinContent() where produce in the analysis thread’s terminal while the remaining warnings are displayed in the GUI’s. So maybe the problem is over there. Anyhow, it doesn’t seem to course any serious problems so this is not so critical.

Kind Regards,
Arne.

Hi,

I’m using root 5.22/00d (thinking that the fix would be implemented in the latest patch) but I’m still getting the same problem as described in the posts above.
So I’m getting an error message for each bin of each histogram with variable bins.
Which version do I need to use to get this fixed?
Thanks,

Vinzenz

Hi,

you will need to use 5.24. This fix has not been put in the 5.22 patches

Lorenzo