# Problem with the convergence of TMinuit

Hello everybody!
I have a problem with TMinuit. The code should generate N angles following a certain function. The second step is to perform a Maximum Lilelihood minimization to find the three parameters of the function. Here I report only the section of the code in which I implement TMinuit.

``````double x[N], y[N]; // variables for MC events

void fcn(int &npar, double *deriv, double &f, double *par, int iflag){
double lnL = 0.;
for(int i = 0; i < N; i++){
lnL += log(0.2388 * (0.5*(1-par[0]) + 0.5*(3*par[0]-1)*pow(cos(x[i]),2) - par[1]*pow(sin(x[i]),2)*pow(cos(2*y[i]),2)
- sqrt(2)*par[2]*sin(2*y[i])*cos(y[i])));
}
f = -lnL;
}

int main(int argc, char** argv) {

/*MonteCarlo generator. This is not a problem since it works.
I report it just fot the sake of completeness. */

srand(time(NULL));
TNtuple cas ("cas", "cas", "x:y");
for(int i = 0; i < N; i++){
auto casuale = rand_TAC(0, 6.28, 0, 6.28, 0, 1);
cas.Fill(get<0>(casuale), get<1>(casuale));
x[i] = get<0>(casuale);
y[i]= get<1>(casuale);
}

//TMinuit

double arglist[10];
int ierflg = 0;

TMinuit minuit (3);
minuit.SetFCN(fcn);
arglist[0] = 0.5;
minuit.mnparm(0, "alpha", 0.40, 0.05, 0.0, 0.0, ierflg);
minuit.mnparm(1, "beta", 0.01, 0.01, 0.0, 0.0, ierflg);
minuit.mnparm(2, "gamma", -0.10, -0.01, 0.00, 0.0, ierflg);

return 0;
}
``````

My problem is about the output:

``````PARAMETER DEFINITIONS:
NO.   NAME         VALUE      STEP SIZE      LIMITS
1 alpha        4.00000e-01  5.00000e-02     no limits
2 beta         1.00000e-02  1.00000e-02     no limits
3 gamma       -1.00000e-01  constant
**********
**********
FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
START MIGRAD MINIMIZATION.  STRATEGY  1.  CONVERGENCE WHEN EDM .LT. 1.00e-04
FCN=119989 FROM MIGRAD    STATUS=INITIATE        8 CALLS           9 TOTAL
EDM= unknown      STRATEGY= 1      NO ERROR MATRIX
EXT PARAMETER               CURRENT GUESS       STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  alpha        4.00000e-01   5.00000e-02   5.00000e-02  -6.18671e+04
2  beta         1.00000e-02   1.00000e-02   1.00000e-02   2.38230e+04
3  gamma       -1.00000e-01   constant
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=92233.7 FROM HESSE     STATUS=OK             10 CALLS          49 TOTAL
EDM=18768.6    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  alpha        7.90493e-01   6.33068e-03   9.37632e-04  -2.92199e+04
2  beta        -6.60789e-01   1.53865e-02   2.27887e-03   1.25535e+04
3  gamma       -1.00000e-01   constant
FCN=92233.7 FROM MIGRAD    STATUS=FAILED         59 CALLS          60 TOTAL
EDM=18768.6    STRATEGY= 1      ERR MATRIX APPROXIMATE
EXT PARAMETER                APPROXIMATE        STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  alpha        7.90493e-01   6.33068e-03   0.00000e+00  -2.92199e+04
2  beta        -6.60789e-01   1.53865e-02  -0.00000e+00   1.25535e+04
3  gamma       -1.00000e-01   constant
EXTERNAL ERROR MATRIX.    NDIM=  25    NPAR=  2    ERR DEF=1
4.008e-05 -4.836e-06
-4.836e-06  2.367e-04
ERR MATRIX APPROXIMATE
PARAMETER  CORRELATION COEFFICIENTS
NO.  GLOBAL      1      2
1  0.04964   1.000 -0.050
2  0.04964  -0.050  1.000
ERR MATRIX APPROXIMATE

``````

Something does not work. I think the main problem is “MIGRAD FAILS TO FIND IMPROVEMENT”.
Is there someone who can help me, please?

_ROOT Version: 6.16/00
_Platform: Ubuntu 18
_Compiler: g++

Hi

This error is normally caused by limited precision or errors in your FCN function. I would check if the function implementation is correct and it is not having large discontinuities, especially in the derivatives

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.