Hello,
I cannot find any tutorials with custom (provided by user) gradient calculation procedure for Minuit or Minuit2. When I try to make very simple test procedure like
void FCN(Int_t&npar, Double_t*gin, Double_t&f, Double_t*par, Int_t flag)
{// select case using flag
switch(flag)
{
case 1:
// Initialization
cout<<"case1\n";
break;
case 2:
cout<<"case2\n";
gin[0]=2*par[0]-8;
// Compute derivatives
// store them in gin
break;
case 3:
cout<<"case3\n";
break;
default:
cout<<"flag:"<<flag<<"\n";
f=pow(par[0],2)-8*par[0]+4;
cout<<f<<"\n";
break;
}
}
void test()
{
TVirtualFitter::SetDefaultFitter("Minuit");
TVirtualFitter * minuit = TVirtualFitter::Fitter(0,1);
minuit->SetParameter(0,"x",0,0.01,0,0);
minuit->SetFCN(FCN);
double arglist[100];
arglist[0] = 0;
// set print level
minuit->ExecuteCommand("SET PRINT",arglist,2);
// minimize
arglist[0] = 5000; // number of function calls
arglist[1] = 0.01; // tolerance
minuit->ExecuteCommand("MIGRAD",arglist,2);
}
Minuit always sets flag=4, so custom derivative procedure never used.
_ROOT Version:_6.20/04
Platform: x86-x64
_Compiler:_g++