Add and kIsAverage ignore error value 0.0


I have the following use-case: I need to make an average of histograms, that are defined in a range such that some bins never get filled for a sub-set of histograms that are to be averaged. The bins in this sub-set of histograms have the bin value as well as the bin error set to 0.0 . When I Add two histograms with the kIsAverage bit set, the errors of the bins for which both histograms I have added have the errors set to 0.0 are not equal to 0.0. This has an effect of putting non-zero error bars on the final averaged histogram where the error-bars should (imo) rather correspond to 0.O error values.

I note that when I add the same histograms without setting the kIsAverage bit, the errors of bins for which the errors values are 0.0 for both of the histograms I am adding do have the value of 0.0.

Please find/run an example macro to reproduce the reported above attached. I am using ROOT 5.30 on Unix system.

Can you please comment whether you agree with my opinion that the 0.0 errors are not treated correctly in case of adding the histograms with the kIsAverage bit set?

Thanks and Best,

add_av.C (1.49 KB)


I agree the errors are not correct in this case. The computation is done using a weighted average and
if one or both histogram have zero errors it uses an arbitrary error of 1. This could be fine in case of non-weighted histograms (i.e. when the histogram represent Poisson counts) and you can have zero errors only for zero content, but not in the general case of weighted histograms. In that case a zero error with a non-zero content has a clear meaning (one should use an infinite weight in the average). A problem remain how to treat
bins with zero errors and zero content in the case of a weighted histogram. Maybe use an error of 1 scaled by a
factor obtained from the total weight and weight square of the histogram.

I will fix now this in the ROOT trunk. Thank you for your report



This should be fixed now in the ROOT trunk (revision 40658)


Hi Lorenzo,

I agree with your suggestion how to treat the errors and the implemantation in the revision you point us to also looks/works fine for me.

Thank you for the feedback and for the fix.

Best, Liza