# How To Correctly Use ROOT::Fit::Chi2FCN?

Dear all,

in order to perform a multi-parametric chi2 fit of my binned model function f(x_i,p) to a binned data y_i histogram I would like to apply the fit method “GSLMultiFit” (The reason is that using other standard minimizer, like Minuit, gives poor convergence in my case when starting slightly away from the expected minimum p_min). The GSLMultiFit method can be initialized, for example, via

I understand that this minimizing routine does not work by handing over a common user-derived fit function of type ROOT::Math::IBaseFunctionMultiDim but instead requires a function of class type ROOT::Fit::Chi2FCN. This class provides a public method named

which can be used to specify – to my understanding – the i-th term (residual) of the chi2 sum (or LogL function, when performing a LogL fit).

Now comes my problem: In my case, the model function f(x_i,p) is not given by any analytical expression. The histogram f(x_i), where x_i denotes the i-th model bin, is computed by a rather complex signal MC simulation (detector response function) and, of course, depends on the fit parameters p. Therefore, I cannot afford to have the model function f be called whenever a single residual i is computed (data and fit histograms have 50 bins, so there are 50 summands in the chi2 sum). Instead, what I would like to do in every minimization step, is compute the entire model histogram f(x_i,p) just once for given p and then sum over all 50 residuals to compute only once the obtained chi2 (afterwards repeat until a minimum chi2 is reached).

Is there anyone having experience with this kind of problem? Is there a way to have the entire model histogram f(x_i) be simulated first and afterwards accessed within “DataElement(…)” to provide the i-th residual (f(x_i)-y_i)^2/y_i ? How does the private member function “DoEval()” play a role in this class (when is it called during the actual minimzation process)? Can it be used to achieve what I need (mind that DoEval() const is a “const” function thus it cannot modify class members)? I know there is one example code provided [url=https://root-forum.cern.ch/t/locate-like-command/65/1 this post[/url] but I don’t see how it would help solving my particular problem.

Thanks for your support,
cheers

Marc