TH2::TH2 and SetDefaultSumw2

From: Philip Rodrigues <p.rodrigues1_at_physics.ox.ac.uk>
Date: Mon, 31 Mar 2008 17:44:51 +0100


Hi Roottalk,
I noticed a little annoying misfeature in TH2F::TH2F, shown by the following snippet:

TH1::SetDefaultSumw2()
TH2F* h2=new TH2F("foo", "bar", 100, 0, 10, 100, 0, 10)

This results in the following warning being printed many times (once per bin I think):
Warning in <TH2::GetBinContent>: this method must be overridden!

The reason is that the TH2F constructor calls the TH2 constructor, which has:

if (fgDefaultSumw2) Sumw2();

This results in TH1::Sumw2() being called, before the TH2F is constructed, so the call in TH1::Sumw2() to GetBinContent() gets resolved to TH2::GetBinContent instead of TH2F::GetBinContent.

A possible solution is to move the Sumw2() call into the TH2F constructor. This fixes it for me.

The same problem affects TH3 too.

Regards,
Philip Received on Mon Mar 31 2008 - 18:45:01 CEST

This archive was generated by hypermail 2.2.0 : Mon Mar 31 2008 - 23:50:02 CEST