Mean with different bin size

Hi all

I have a histo with differents bin bize. When I use the method GetMean() and a second method:

[code]void MeanPt(Int_t nbins_pt, TH1 *htmp)
Double_t numerator = 0.0;
Double_t denominator = 0.0;

for(Int_t i=1;i<=nbins_pt;i++)

	Double_t binContent = htmp->GetBinContent(i);
	Double_t pTValue = htmp->GetBinCenter(i);

	numerator += binContent*pTValue

	denominator += binContent

cout << "<Pt> :" << numerator/denominator << endl;


I find 2 different values. The value given by GetMean() is lower than the value given by my function.
There is a special way to extract the mean value of a histo with different bin size ? Or what is wrong in my method ?


The TH1::GetMean is the correct version. It uses the values from TH1::Fill.
Your algorithm is an approximation using the center of bins.
GetMean reverts to your algorithm when you request a sub-range of the histogram.