Area under curve problem

Hello, I’m trying to calculate the area under curve of a TH1F. I wrote
Double_t integral= htempkinensp->Integral(0,45);
but I noticed that I get different values of the area depending of the bin number that I set. For exampl, you can see in the stat box, here I setted

ts->Draw(Form("SecondaryParticleKinEn >> htemp(45000, 0., 45000.)"));

here I setted
ts->Draw(Form("SecondaryParticleKinEn >> htemp(1000, 0., 45000.)"));

you see in the stat box I get different Integral values…

I think the right value should be 34725

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Read how to use Integral:

Thank you @dastudillo, then, should I write

Double_t integral= htempkinensp->Integral(0,45, option="width");


From that page:
“TH1::Integral() returns the integral of bin contents in a given bin range
(not “x-axis value range”)

1 Like

To elaborate: given a 1-D histogram with 10 equidistant bins in the range 0-5, the full bin range (without the overflow/underflow bins) is 1-10 while the axis range is 0-5.

You can find the bin number corresponding to a value on the x axis with FindBin, e.g. histo.FindBin(4.9) would return 10 (bin number 10) for my example above.


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