Getting details of a gaussian fit

Hi,

Thank you , I understand it now.
You are doing a default fit of an histogram. Then the fit is a Least squares fit using as error for the data point the square root of the observed events.
The fit goodness (chi2 and ndf) you obtain from the fit result, as you are doing in the macro.
The problem with the least square fits are the bins with very small or zero entries. The fit method of ROOT exclude bins with zero entries, but this creates a small bias.
A more correct approach for fitting histogram with counts is to use the binned maximum likelihood method (option L). When doing this you can compute for goodness of fit a chi2 from 2 * maximum likelihood value at the minimum. Since the empty bins are used in the fit, the number of degree of freedom will include now also the empty bins. However, be aware that if you have a large number of empty bins the obtained chi2 value will deviate from following a chi2 distribution.
I attach an example on fitting with the two methods and on how to make a residual plot

Cheers

Lorenzo

exampleFitHistogram.C (1.1 KB)