<TH1::SetBinContent>: this method must be overridden!

Hi,

I have a histogram with (that includes errors) and I would like to copy the contents of this histogram to a new one. The new histogram is different to the old only in the bin length, I want my new histogram to have the same bin number, bin content and bin errors, but bin length=1.
So I did the following

   for (int kk=1; kk<pt2->GetBinsX(); kk++) {

    TH1 *constbinning = new TH1("constbinning","",size_xbins,0,5);
                    constbinning->SetBinContent(kk,pt2->GetBinContent(kk);
                    constbinning->SetBinError(kk,pt2->GetBinError(kk);

}

So I have two questions:

  1. When I run I get the warning “Warning in TH1::SetBinContent: this method must be overridden!” which I saw that has to do with Sumw2(), (but I haven’t called this method) , where does this warning come from?

  2. Is it right to copy the histogram errors like this, or I have to use constbinning->Sumw2() after the declaration of the histo?

Thanks!

Hi,

You should not construct the base class, TH1, but the derived one TH1D or TH1F (for single precision). This is the reason for the warning message.

Lorenzo

1 Like

Thanks a lot Lorenzo!

One more thing, is it ok to copy the content with setbincontent and setbinerror to get the errors right or I need to also call sumw2()?

Des

Hi Des,

If you copy the errors with SetBinError() there is no need to call Sumw2(). It is done automatically. Instead if you just use SetBinContent() the histogram by default does not store the summon weights square and compute its error using the square root of the bin content.

Lorenzo

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.