Trying to duplicate tutorials/fit/fit2dHist.C

Hi All,

As part of a larger project I’m trying to learn how to fit using my own minimization function. As a starting point I’m simply trying to duplicate the chi2 fitting results of fitting a simple gaussian to a histogram, by using the method described in tutorials/fit/fit2dHist.C which seemed simple enough.

However, try as I might, I can not get the method to work. Migrad reports that the minimization has converged, but the parameters resulting from the minimization are exactly my seed parameters and the errors are all nan.

Please find my simple script attached. It can be run interactively via .x simpleSimFit.C+
I believe that I have duplicated the relevant parts of tutorials/fit/fit2dHist.C faithfully…

Thanks for any help.
simpleSimFit.C (2.67 KB)

Oooops! Solved my own problem…I needed to protect the chi2 function from empty bins which have bin errors of zero and make the chi2 value inf.

Having done that I now get exactly the same results as fitting a gaussian with the fit panel.

Corrected code is attached.

simpleSimFit.C (2.61 KB)