SetBinError problem

I have a histogram that the content of each bin can be positive or negative. When setting the error bar for each bin with “SetBinError(i, errorbar)”, it always give me a error message

Warning in TCanvas::ResizePad: Inf/NaN propagated to the pad. Check drawn objects.
Warning in TCanvas::ResizePad: c1 height changed from 0 to 10

And once I change the content of each bin to be positive, it works fine. I got really confused, anyone can explain what is wrong?

It looks like your histogram contains NaN or Inf numbers. Can you check that the weights you are using to fill you histogram are valid numbers ?

hi Couet,
I am sure the content of histogram is fine. And the plot of this histogram looks normal (range (-0.5,0.5)). The content of each channel is also good. The question is when I set the error bar, It crashes.
Any idea?

Can you post the faulty histogram, or a small macro reproducing this problem so we can have a look at it ?

I had a similar problem (which I described uncorrectly as a bug, see bug report #46536).

Are you sure that you set all of the bin errors?

If you didn’t set all the bin errors (especially for the bins with negative value) and then draw the histogram or explicitly call GetBinError for a bin with negative contents, the following will happen:

  • the first call to SetBinError calls Sumw2 which initializes fSumw2 (the structure holding the square of the bin errors) and copies all bin contens (also negative!) to fSumw2.fArray
  • if not all of the bin errors are set to reasonable (positive!) values afterwards, there remain negative values as “squares of errors”
  • a subsequent call to GetBinError (this happens also when histogram is drawn) for such bins computes the square root of those negative “squares of errors” values resulting in “nan”.

So the solution in this scenario is to explicitly set all bin errors to reasonable (positive) values before drawing the histogram.