I have a TH1D which I have filled in my macro using a different weight in each call to TH1D::Fill(…). Now, when I tried to see the number of entries in the histogram I noticed it did not match with the value of a counter I use to check consistency. Everything matches if I add up the integral, the overflow and the underflow. I expected this value to be equal to the result of TH1D::GetEntries() but this is not the case. I might be missing something but it does not look very reasonable at first glance. Any idea?
TH1::Integral returns the integral of bins in the bin range (default(1,Nbins).
If you want to include the Under/Overflow, use
But my point is why is that value different from what GetEntries() returns? Shouldn’t they be exactly the same?
TH1::Integral return the sum of the weights in the bin range. TH1::GetEntries return the total number of entries. Use a TProfile if you need both the number of entries and the sum of weights per bin.
The histogram integral is the sum of the bin contents, while the number of entries is the given by the number of times the Fill method is called. So, if you fill the histogram with all weights=1 the two quantities (when underflow and overflow are included in the integral) are the same. If you filled with weights they are different, and GetEntries does not make much sense. In that case exists also the function GetEffectiveEntries() which returns the square of sum of the weights divided by the sum of the weights square.
Now that makes a lot of sense to me. Thanks for clarifying!