I have a question about: I have an histogram that gives the energy distribution in a detector. So, on the X axis I have the energy range and on the Y axis the total number of times each bin is filled.

Now, I want to get the total energy… so I thought that the Integral() method should help me. But, if I understood correctly, the method simply returns the sum of the bin contents…

So is there a quicker way or I have to do something like:

for(i=1;iGetNbinsX(); i++)
{
energy += h->GetBinContent(i)*h->GetBinCenter(i)
}

The loop you suggest seems fine assuming in each bin all the counts are comming from the same value equal to the bin center. May be @moneta has a better sugestion.

I was thinking that things could be easier than expected… since my bins have all the same width, let’s say 0.1 MeV, I could simply take for each bin the total number of entries and multiply by 0.1MeV to get the total energy deposit in that bin. Then, I sum all contributes.

if they are the same width you can do what you suggest assuming the x-axis starts at 0 MeV. And as the integral is the sum of the contents of the bins may be it is enough to do 0.1*integral ?