Halfanalytical fit

Since I am not really into how fitting algorithm used in ROOT work, I have a general question about an approach.

I want to fit a 2D function, to simplify, let’s say it’s centre position (x,y) and scale. Scale can be calculated analytically for every given centre position (x,y), while the position needs to be fitted numerically. The thing that I’m doing now and which seems to work is that I define TF2 with (x,y,scale) parameters and fix the scale. Inside the function called by TF2, let’s say, calc_func(), I calculate the scale for centre position requested by fitter and return the function value scaled by the calculated scale. Than I change the scale parameter of the TF2.

Is this a proper approach? I mean do minuit, fumili and levenberg-marquadt implementations in ROOT work properly with such changing TF2 parameter from inside the TF2, etc.? I hope my question is clear without minimal sample working code :slight_smile:


all the fitting algorithms in ROOT work by minimizing a sum (least square or negative log likelihood).
This sum should be a smooth function of the parameters and the derivatives must exist in the considered parameter region. The minimization program should be able to compute the derivatives. If this is not the case these algorithms will not work.
You can still use an algorithm not requiring the derivatives like Simplex, Simulated annealing or a genetic algorithm


Thanks for an answer. I am struggling with fitting centre of a 2D function, where the scale is, as mentioned, calculated analyticaly. Although the fit seems to be a very easy one, with just 2 free parameters, it is really unstable, especially liking to stay near the initial values, no matter if I use GSL or minuit or, as just tested… simplex.

However, I found out that it is fairly easy to generate a 2D gaussian example that does not converge or converge badly with all parameters but position in x and y free (tried with minuit), so I guess it is not as easy fit as it seems.