Migrad edm values in a chi2 fit problem

Dear Rooters

We are trying to perform a simple 1D test fit of a chi2 function for some data. I have included the chi2 values for the range of X we are considering in the fit:


However, when I try to complete the minimization of this chi2 using migrad the values of the edm for this function appear out of control- see the output from the test run below. I also not that simplex appears to find the correct minimum and chi2 value but never returns a status other than “Progress” even though it has located an edm less than the tolerance.

My feeling is we must be missing something simple here and any advice on how to proceed would be really appreciated.
Best wishes
Darren

----------begin minuit output------

*********hit Doms ************
number of doms hit 57
past the nhit check
----------Start here event into minuit--------------------


** 1 **SET PRINT 1



** 2 **SET ERR 1



** 3 **SET NOWARNINGS 0



** 4 **SET STRATEGY 2


NOW USING STRATEGY 2: MAKE SURE MINIMUM TRUE, ERRORS CORRECT


** 5 **SET EPS 1e-10


FLOATING-POINT NUMBERS ASSUMED ACCURATE TO 1e-10
PARAMETER DEFINITIONS:
NO. NAME VALUE STEP SIZE LIMITS
1 theta 1.57080e+00 1.00000e-03 no limits
2 phi 0.00000e+00 1.00000e-03 no limits
3 x0 -7.50000e+02 1.00000e-01 -8.00000e+02 8.00000e+02
4 y0_given 0.00000e+00 1.00000e-01 no limits
5 z0_given -3.50000e+02 1.00000e-01 no limits
6 length 5.00000e+02 1.00000e-01 no limits
7 t0_given 0.00000e+00 5.00000e-01 no limits


** 6 **FIX 1



** 7 **FIX 2



** 8 **FIX 4



** 9 **FIX 5



** 10 **FIX 6



** 11 **FIX 7



** 12 **MINIMIZE 5e+05 0.001


FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.

START MIGRAD MINIMIZATION. STRATEGY 2. CONVERGENCE WHEN EDM .LT. 1.00e-06

COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1.63022e+07 FROM HESSE STATUS=OK 7 CALLS 8 TOTAL
EDM=7.57911e+13 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 -7.50000e+02 9.79027e+02 9.91746e-03 -1.23119e+07
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
MIGRAD FAILS TO FIND IMPROVEMENT

COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=13324.5 FROM HESSE STATUS=OK 7 CALLS 30 TOTAL
EDM=2.01082e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.70585e+02 2.32383e+02 4.92877e+02 -9.39466e+04
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
MIGRAD FAILS TO FIND IMPROVEMENT

COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=13324.5 FROM HESSE STATUS=OK 9 CALLS 45 TOTAL
EDM=2.01082e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.70585e+02 2.32383e+02 4.92877e+02 -9.39466e+04
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
MIGRAD FAILS TO FIND IMPROVEMENT
MIGRAD TERMINATED WITHOUT CONVERGENCE.
FCN=13324.5 FROM MIGRAD STATUS=FAILED 50 CALLS 51 TOTAL
EDM=2.01082e+08 STRATEGY= 2 ERR MATRIX APPROXIMATE
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.70585e+02 2.32383e+02 0.00000e+00 -9.39466e+04
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 1 ERR DEF=1
5.567e+04
ERR MATRIX APPROXIMATE
START SIMPLEX MINIMIZATION. CONVERGENCE WHEN EDM .LT. 0.001
FCN=13324.5 FROM SIMPLEX STATUS=PROGRESS 3 CALLS 54 TOTAL
EDM=6.65194e+06 STRATEGY= 2 ERR MATRIX APPROXIMATE
EXT PARAMETER APPROXIMATE INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.70585e+02 2.32383e+02 9.85753e+00 6.16096e+06
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
FCN=13324.5 FROM SIMPLEX STATUS=PROGRESS 8 CALLS 59 TOTAL
EDM=2.03831e+07 STRATEGY= 2 ERR MATRIX APPROXIMATE
EXT PARAMETER APPROXIMATE INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.70585e+02 2.32383e+02 1.57721e+00 6.16096e+06
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
SIMPLEX MINIMIZATION HAS CONVERGED.
FCN=1633.67 FROM SIMPLEX STATUS=PROGRESS 47 CALLS 98 TOTAL
EDM=0.000223964 STRATEGY= 2 ERR MATRIX APPROXIMATE
EXT PARAMETER APPROXIMATE INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.54298e+02 2.32383e+02 3.00817e-06 6.16096e+06
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
START MIGRAD MINIMIZATION. STRATEGY 2. CONVERGENCE WHEN EDM .LT. 1.00e-06
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1633.67 FROM HESSE STATUS=OK 9 CALLS 107 TOTAL
EDM=1.80737e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.54298e+02 2.41218e+02 4.92877e+02 -8.60829e+04
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
MIGRAD FAILS TO FIND IMPROVEMENT
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1633.67 FROM HESSE STATUS=OK 9 CALLS 121 TOTAL
EDM=1.80737e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.54298e+02 2.41218e+02 4.92877e+02 -8.60829e+04
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
MIGRAD FAILS TO FIND IMPROVEMENT
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=1633.67 FROM HESSE STATUS=OK 9 CALLS 135 TOTAL
EDM=1.80737e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.54298e+02 2.41218e+02 4.92877e+02 -8.60829e+04
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
MIGRAD FAILS TO FIND IMPROVEMENT
MIGRAD TERMINATED WITHOUT CONVERGENCE.
FCN=1633.67 FROM MIGRAD STATUS=FAILED 42 CALLS 140 TOTAL
EDM=1.80737e+08 STRATEGY= 2 ERR MATRIX APPROXIMATE
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 0.00000e+00 fixed
3 x0 1.54298e+02 2.41218e+02 0.00000e+00 -8.60829e+04
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 1 ERR DEF=1
6.012e+04
ERR MATRIX APPROXIMATE
Not Converged

---------begin minuit setup info part -----------------

TMinuit *mini = 0;

double params_min[7];
double angle_err[7]; //it seems that “GetParameter” requires this. Is a space to put
//associated minimization errors I believe. look into to be sure.
bool converged;

mini = new TMinuit(7);
mini->SetFCN(miniFCN); //think/hope this calls miniFCN :S … EP! This is generating ERRORS!

//Stuff specific to Minuit
// argument list for Minuit commands
double arglist[10];

// error flag from Minuit
int ierflg = 0;

//Turn off output of MINUIT
arglist[0] = 1;
mini->mnexcm(“SET PRint”, arglist, 1, ierflg);
arglist[0] = 1;
mini->mnexcm(“SET ERR”, arglist ,1,ierflg);
arglist[0] = 0;
mini->mnexcm(“SET NOWarnings”, arglist, 1, ierflg);
arglist[0] = 2;
mini->mnexcm(“SET STRategy”,arglist,1,ierflg);
arglist[0] = 1e-10;
mini->mnexcm(“SET EPS”,arglist,1,ierflg);

//Define step size and inital values of my parameters that need to be solved by migrad to form an min. chi2 value
double start_value[7] = {(3.14159625/2),0.0, -750.0, 0.0, -350.0, 500.0, 0.0 };
double step[7] = {0.001,0.001, 0.1, 0.1, 0.1, 0.1, 0.5};
//int hits.size = hits.size(); //this means other parts of hit map may
// also not be passing

//Getting an error here that says 'ierflg not declaired in the scope… why?
// Initialize the parameters
mini->mnparm(0, “theta”, start_value[0], step[0],0, 0,ierflg); //zenith
mini->mnparm(1, “phi”, start_value[1], step[1],0, 0,ierflg); //azimuth
//may have to put physical bounds of dector in eventually… or not
mini->mnparm(2, “x0”, start_value[2],step[2],-800.0,800.0,ierflg);
mini->mnparm(3, “y0_given”,start_value[3],step[3],0,0,ierflg);
mini->mnparm(4, “z0_given”,start_value[4],step[4],0,0,ierflg);
mini->mnparm(5, “length”,start_value[5],step[5],0,0,ierflg);
mini->mnparm(6, “t0_given”,start_value[6],step[6],0,0,ierflg);

mini->FixParameter(0);
mini->FixParameter(1);
mini->FixParameter(3);
mini->FixParameter(4);
mini->FixParameter(5);
mini->FixParameter(6);
double eps = 1e-3;
// mini->mncn(“SETPrecision”,eps);

// Set maximum number of iterations, example suggests 5000
arglist[0] = 500000;

// Set threshold for minimum --ASK Darren about the best value for this
// and how it will effect my fit exactly.
arglist[1] = 1E-2; //was formally 1E-3

// Execute MIGRAD minimization!
mini->mnexcm(“MINIMIZE”, arglist ,2,ierflg);
converged = true;

// Check for convergence - if no convergence, return NOT_CONVERGED
if (ierflg == 4) {

converged = false;

}

if (!converged){
cout << “Not Converged” << endl;
}

Hi,

I see that you are getting this error from Migrad:
MIGRAD FAILS TO FIND IMPROVEMENT

This is normally caused by a bug in the function definition, for example when f(x) evaluate at a certain time is different than f(x) evaluated at a later time.
I would check first carefully the function and for example printing them for every call by Minuit.

Best Regards

Lorenzo

1 Like

Hi Lorenzo

I am not sure that is the issue here. We have looked at the function carefully and I have below an example of the output for each pass in to the chi2 function for a corresponding test X location. What you see is that for the same values of X the chi2 calculated between various steps is the same. Is there something more subtle I am missing?

thanks!
Darren

COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=2958.32 FROM HESSE STATUS=OK 9 CALLS 122 TOTAL
EDM=1.09801e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 3.14159e+00 fixed
3 x0 1.54876e+02 1.00467e+03 1.12950e+04 -9.68469e+03
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
The number usable hits for this frame is 54
current chi2 2.05063e+07 for cuurent x0 698.043
The number usable hits for this frame is 54
current chi2 4.60817e+07 for cuurent x0 -736.369
The number usable hits for this frame is 54
current chi2 7.90135e+06 for cuurent x0 492.066
The number usable hits for this frame is 54
current chi2 1.05315e+06 for cuurent x0 -3.37275
MIGRAD FAILS TO FIND IMPROVEMENT
The number usable hits for this frame is 54
current chi2 2958.32 for cuurent x0 154.876
The number usable hits for this frame is 54
current chi2 2.85611e+07 for cuurent x0 795.886
The number usable hits for this frame is 54
current chi2 5.04388e+07 for cuurent x0 -767.007
The number usable hits for this frame is 54
current chi2 1.02408e+07 for cuurent x0 538.745
The number usable hits for this frame is 54
current chi2 4.42536e+07 for cuurent x0 -723.014
The number usable hits for this frame is 54
current chi2 2.63508e+07 for cuurent x0 770.587
The number usable hits for this frame is 54
current chi2 3.28509e+07 for cuurent x0 -631.18
The number usable hits for this frame is 54
current chi2 2.85611e+07 for cuurent x0 795.886
The number usable hits for this frame is 54
current chi2 5.04388e+07 for cuurent x0 -767.007
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=2958.32 FROM HESSE STATUS=OK 9 CALLS 135 TOTAL
EDM=1.09801e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 3.14159e+00 fixed
3 x0 1.54876e+02 1.00467e+03 1.12950e+04 -9.68469e+03
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
The number usable hits for this frame is 54
current chi2 2.05063e+07 for cuurent x0 698.043
The number usable hits for this frame is 54
current chi2 4.60817e+07 for cuurent x0 -736.369
The number usable hits for this frame is 54
current chi2 7.90135e+06 for cuurent x0 492.066
The number usable hits for this frame is 54
current chi2 1.05315e+06 for cuurent x0 -3.37275
MIGRAD FAILS TO FIND IMPROVEMENT
The number usable hits for this frame is 54
current chi2 2958.32 for cuurent x0 154.876
The number usable hits for this frame is 54
current chi2 2.85611e+07 for cuurent x0 795.886
The number usable hits for this frame is 54
current chi2 5.04388e+07 for cuurent x0 -767.007
The number usable hits for this frame is 54
current chi2 1.02408e+07 for cuurent x0 538.745
The number usable hits for this frame is 54
current chi2 4.42536e+07 for cuurent x0 -723.014
The number usable hits for this frame is 54
current chi2 2.63508e+07 for cuurent x0 770.587
The number usable hits for this frame is 54
current chi2 3.28509e+07 for cuurent x0 -631.18
The number usable hits for this frame is 54
current chi2 2.85611e+07 for cuurent x0 795.886
The number usable hits for this frame is 54
current chi2 5.04388e+07 for cuurent x0 -767.007
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=2958.32 FROM HESSE STATUS=OK 9 CALLS 148 TOTAL
EDM=1.09801e+08 STRATEGY= 2 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 3.14159e+00 fixed
3 x0 1.54876e+02 1.00467e+03 1.12950e+04 -9.68469e+03
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
The number usable hits for this frame is 54
current chi2 2.05063e+07 for cuurent x0 698.043
The number usable hits for this frame is 54
current chi2 4.60817e+07 for cuurent x0 -736.369
The number usable hits for this frame is 54
current chi2 7.90135e+06 for cuurent x0 492.066
The number usable hits for this frame is 54
current chi2 1.05315e+06 for cuurent x0 -3.37275
MIGRAD FAILS TO FIND IMPROVEMENT
MIGRAD TERMINATED WITHOUT CONVERGENCE.
FCN=2958.32 FROM MIGRAD STATUS=FAILED 39 CALLS 152 TOTAL
EDM=1.09801e+08 STRATEGY= 2 ERR MATRIX APPROXIMATE
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 theta 1.57080e+00 fixed
2 phi 3.14159e+00 fixed
3 x0 1.54876e+02 1.00467e+03 0.00000e+00 -9.68469e+03
4 y0_given 0.00000e+00 fixed
5 z0_given -3.50000e+02 fixed
6 length 5.00000e+02 fixed
7 t0_given 0.00000e+00 fixed
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 1 ERR DEF=1
2.885e+06
ERR MATRIX APPROXIMATE

Hi,

the problem could be caused by an error in the calculation of the function derivatives. I see the function is very steep around the minimum, and it is not having a typical parabola shape.
I see Minuit calculates very large step sizes and this could be caused by wrong derivatives or because the parabola approximation (Taylor expansion around the minimum) does not work in your case.
The best would be trying to re-parametrize your problem to reduce the non-linearity of your function. You can try also to put smaller step sizes and initial conditions closer to the minimum.
In order to help you more, I would need however your full chi2 function (i.e. your fitting function + the data).

Best Regards

Lorenzo

Hi Lorenzo

We had a look at the “zoomed” region near the minimum today for one of our test cases- please see the attached plot. The chi2 values look really well behaved in this region- about what I would have expected.


I do note that we tired to have MIGRAD do a pol2 fit to this region of the data and the output from the fit was:


I have to admit I do not understand this - I would have expected with the number of point in the plot the fit would be quite easy.

Is there some way to fix the step size for the determination of the first derivatives in minuit? As you pointed out earlier they are getting very large for some reason- my feeling is if we could keep them to a reasonable size- ie. no larger than the expected detector resolution - we may work around this? As always any advice would be hugely appreciated.

Best wishes
Darren

Hi,

in Minuit you cannot change externally the step size, but you can provide eventually the gradient, which is used (together with the Hessian) to compute the steps.

FOr the pol2 fitting, you should use option “F” to foce the usage of Migrad instead of the linear fitter

Lorenzo