Likelihood scan with TFitterMinuit

Dear all,
I am fitting a rather complicated function using the TFitterMinuit interface. I know that it is deprecated, but currently it is deeply embedded into the framework I have to use, so that I would like to try to use it before rewriting large parts.
My goal is to scan the likelihood function and from the documentation and forum threads I found the following function at the end of the relevant code:

TFitterMinuit* minuit = new TFitterMinuit();
minuit->SetMinuitFCN(fcn);  // fcn is of class FCNBase
minuit->SetParameter(0, "theta0", the0  , 0.5*degree, 0, 0); //Setting paramaters
// more parameters
minuit->CreateMinimizer(TFitterMinuit::kCombined);
minuit->Minimize();
// Now the scan
minuit->ExecuteCommand("SCAN", 0, 0);

Everything runs smoothly, but I just can’t find a way to retrieve the scan. I’m sorry for my ignorance, but where and in which format is this saved?
If necessary I will try to update the code to use a ROOT::Math::Minimizer.

Thank you very much!

Hi,

The SCAN command finds just the best value of the function scanning the likelihood varying each parameter at a time.
The only result saved is the new function minimum value.

If you use the new Minimiser interface (i…e the Minuit2Minimizer class) there is a method call Minimiser::Scan. This method scan a parameter requested by the user and fills a vector of likelihood function values
See

root.cern.ch/doc/v606/classROOT … 435733a389

Cheers

Lorenzo

Hi Lorenzo,
thank you for your answer, I assumed something like that.

Regarding the transition to the new interface, I learned from the tutorials that ROOT::Math::Minimizer::SetFunction wants a ROOT::Math::IMultiGenFunction which I can get via the ROOT::Math::Functor method.
Currently I am stuck with a class derived from FCNBase

class MyFcn : public ROOT::Minuit2::FCNBase
{
...
double operator()( const std::vector<double>& par ) const;
...
};

I’d like to make sure that I don’t miss a handy function to help me out here. Do I have to rewrite this class to be a plain c++ function that takes a const double *xx array of variables in order to pass it to the minimizer?
Thank you again and cheers

HI,

In order to use with the ROOT::Minimiser interface, just add this simple method to your MyFCN class
(I assume you know the number of parameter and it is the represented by the integer NPAR)

double operator()( const double *  par ) const { 
    std::vector<double> p(par, par+NPAR); 
    return (*this)(p); 
}

and then you create a IGenFunction object using the Functor class:

MyFCN f(.....);
ROOT::Math::Functor func(f,NPAR); 
minimiser.SetFunction(func); 

Cheers

Lorenzo

Great, worked like a charm :slight_smile:
Didn’t have enough understanding of overloading operators to have this idea.
Thanks!

hi,
I have one more question.
MyFCN is a little bit more complicated.

class MyFCN: public ROOT::Minuit2::FCNBase {
         public:
          MyFCN(RecTimeLikeAlg *alg){m_alg =alg;}
          double operator() (const std::vector<double>& x)const{
          return m_alg->Calculate_Energy_Likelihood(x[0],x[1],x[2],x[3]);
          }
         ...};

it returns value of a member function of a class.
I try to rewrite to Minuit2Minimizer .

class MyFCN: public ROOT::Minuit2::FCNBase {
         public:
          MyFCN(RecTimeLikeAlg *alg){m_alg =alg;}
          double operator()(const double*  par)const{
           std::vector<double> p(par, par+4);
           return (m_alg->Calculate_Energy_Likelihood)(p);
          }
          ...};

However, I failed.

error: no matching function for call to ‘RecTimeLikeAlg::Calculate_Energy_Likelihood(std::vector<double, std::allocator<double> >&)’

What should I do? Thanks