Minuit2Minimizer converges but assertion fails in X()

Hello,
I have written a fitting routine using the Minuit2Minimizer that converges successfully and yet aborts due to a failed assertion when Miniut2Minimizer::X() is called. I know that it fails because the guts of the method gets the MnUserParameters vector and this seems to have a different size than the dimension of Minuit2Minimizer.

Fitting Results
Iteration :     0

Parameters initialized to:
 Index       name            value      val_err    
       0              a        5.00e-01  1.00e-01 
       1              b        1.63e-01  1.00e-01 
       2              c       -2.17e-01  1.00e-01 
       3              d        9.47e-01  1.00e-01 
 
Minuit2Minimizer: Minimize with max-calls 1000 convergence for edm < 0.1 strategy 1
MnSeedGenerator: for initial parameters FCN = 380.615
MnSeedGenerator: Initial state:   - FCN =   380.6151324595 Edm =      684.665 NCalls =     17
VariableMetric: start iterating until Edm is < 0.0002
VariableMetric: Initial state   - FCN =   380.6151324595 Edm =      684.665 NCalls =     17
VariableMetric: Iteration #   1 - FCN =   10.77669015462 Edm =      16.4275 NCalls =     29
VariableMetric: Iteration #   2 - FCN =     1.9575847631 Edm =     0.115871 NCalls =     39
VariableMetric: Iteration #   3 - FCN =   1.245981019195 Edm =   0.00703602 NCalls =     50
VariableMetric: Iteration #   4 - FCN =   1.119808716821 Edm =  3.33602e-18 NCalls =     62
VariableMetric: After Hessian   - FCN =   1.119808716821 Edm =  3.40971e-18 NCalls =     85
Number of iterations 6
----------> Iteration 0
            FVAL = 380.61513246 Edm = 684.665327635 Nfcn = 17
            Error matrix change = 1
            Parameters :  p0 = 0.499742 p1 = 0.16291 p2 = -0.217382 p3 = 0.947201
----------> Iteration 1
            FVAL = 10.7766901546 Edm = 16.4274627426 Nfcn = 29
            Error matrix change = 0.605944
            Parameters :  p0 = 9.73973 p1 = 14.9479 p2 = 1.25801 p3 = 3.67853
----------> Iteration 2
            FVAL = 1.9575847631 Edm = 0.115871474975 Nfcn = 39
            Error matrix change = 0.407127
            Parameters :  p0 = 9.8348 p1 = 15.2214 p2 = 2.26586 p3 = 0.554465
----------> Iteration 3
            FVAL = 1.2459810192 Edm = 0.00703601772242 Nfcn = 50
            Error matrix change = 0.538188
            Parameters :  p0 = 8.44776 p1 = 17.4563 p2 = 2.3808 p3 = 0.596536
----------> Iteration 4
            FVAL = 1.11980871682 Edm = 3.3360179237e-18 Nfcn = 62
            Error matrix change = 0.649003
            Parameters :  p0 = 8.08661 p1 = 17.4538 p2 = 3.02516 p3 = 2.89839
----------> Iteration 5
            FVAL = 1.11980871682 Edm = 3.40971036027e-18 Nfcn = 85
            Error matrix change = 0
            Parameters :  p0 = 8.08661 p1 = 17.4538 p2 = 3.02516 p3 = 2.89839
Minuit2Minimizer : Valid minimum - status = 0
FVAL  = 1.11980871682085215
Edm   = 3.40971036027127066e-18
Nfcn  = 85
a	  = 8.08661	 +/-  1.99228
b	  = 17.4538	 +/-  2.76025
c	  = 3.02516	 +/-  1.85211
d	  = 2.89839	 +/-  6.56687
RandomFitter: /usr/local/root/math/minuit2/src/Minuit2Minimizer.cxx:469: virtual const double* ROOT::Minuit2::Minuit2Minimizer::X() const: Assertion `fDim == paramsObj.size()' failed.
Aborted

I also know that I set 4 variables, as the output of PrintResults() shows, but Minuit2Minimizer::NDim() returns 2. Somehow two of my variables are either “forgotten” by MnUserParameters or never get added.
Any ideas?

Thanks in advance.

I have just discovered that this was due to the fact that the function I was trying to minimize incorrectly was set to 2 dimensions. Minuit2Minimizer::NDim() returns the result of function.NDim() and that is what was happening.