The integral option in TH1::Add

In TH1 class, there is such a function.

virtual Bool_t 	Add (TF1 *h1, Double_t c1=1, Option_t *option="")

It add a TF1 function to TH1.

The behaviour of this function with option “I” is very weird to me. I would thought this function should integrate the function h1 over the bin and then divided by the bin width. However, in really, the function multiply by the bin width instead.
In the line 816 of the source code

cu += c1*f1->Integral(fXaxis.GetBinLowEdge(binx), fXaxis.GetBinUpEdge(binx)) * fXaxis.GetBinWidth(binx);

I also don’t understand what is the point of 815 line

cu = c1*f1->EvalPar(xx);

Is there any reason for this? Or is it a bug?

Thanks.

Hi,

I agree this function is weird and certainly not correct the way it is implemented.
One should just compute the integral and dived by the bin width.

I see the code has been like this for more than 10 years. This means nobody has used this functionality. For curiosity what is your use case to use TH1::Add with a function and for using it with the integral option ?

Best Regards

Lorenzo

Hi Lorenzo,

Thank you for the response.
I want to smooth a function to a certain resolution which corresponding to the bin width of the histogram created. I believe the integral option will automatically do this for me, if it works appropriately.

Chenliang

Hi,

The bug us fixed now in the ROOT master and 6.08 version

Lorenzo