# ROOT::Math::Minimizer not Minimizing

I am trying to minimize my own 2D functor object and it is not working properly. I am instead now trying to minimize a simple 2D function to test the functionality and make sure I am doing everything right. Basically it looks like the minimizer is not actually doing any minimizing! Here is my code:

``````{
gROOT->ProcessLine("#include <Math/Minimizer.h>");
gROOT->ProcessLine("#include <Math/Factory.h>");
gROOT->ProcessLine("#include <Math/Functor.h>");
Double_t pars = {-0.5,0.2};
Double_t steps = {0.0001,0.0001};

TF2 ftest("ftest","*x*x+*y*y",-1,1,-1,1);
ftest.SetParameters(1,1);
ftest.Draw("surf");
ROOT::Math::Functor ftest_tor(&ftest,2);

ROOT::Math::Minimizer * min = ROOT::Math::Factory::CreateMinimizer("Minuit2","Simplex");
min->SetMaxFunctionCalls(100000000);
min->SetMaxIterations(10000000);
min->SetTolerance(0.000001);

min->SetFunction(ftest_tor);

min->SetVariable(0,"x",pars,steps);
min->SetVariable(1,"y",pars,steps);

min->SetPrintLevel(99);

min->Minimize();

cout << "Minimum at " << min->X() << ", " << min->X() << " : " << ftest_tor(min->X()) << endl;
}``````

The output is:

``````Minuit2Minimizer: Minimize with max-calls 100000000 convergence for edm < 1e-06 strategy 1
Simplex: Final iteration - FCN =                0 Edm =            0 NCalls =      7
Number of iterations 1
----------> Iteration 0
FVAL = 0 Edm = 0 Nfcn = 7
Error matrix change = 1
Parameters :  p0 = -0.5 p1 = 0.2
Minuit2Minimizer : Valid minimum - status = 0
FVAL  = 0
Edm   = 0
Nfcn  = 7
x	  = -0.5	 +/-  inf
y	  = 0.2	 +/-  inf
Minimum at -0.5, 0.2 : 0``````

I have tried with different minimizers and the result is the same (and the same with my homemade functor object that implements operator(const double *) which I feed to ROOT::Math::Functor). I am using ROOT v5.34/09 from MacPorts, root-config --features gives me:

```root-config --features asimage astiff builtin_afterimage builtin_ftgl builtin_glew cintex explicitlink fink fftw3 gviz genvector gsl_shared mathmore memstat minuit2 opengl python reflex roofit shared soversion ssl table tmva unuran x11 xft xml thread```
, so I have the right /configure flags for this to work.

What am I doing wrong here?

Apparently you cannot feed a TF2 to a ROOT::Math::Functor and expect it to survive, or expect a useful error message if you try.

I have been able to make it work using a self-coded class that implements the right operator() signature to feed to a ROOT::Math::Functor. I can still make a TF2 out of this class for plotting, but I can’t use the TF2 for minimizing.

Jean-François