Hot to use TMinuit2

Dear experts

I want to use TMinuit2 to fit some straight tracks (I assume it’s better than TMinuit), but all legacy code I can get are using TMinuit instead of TMinuit2, so here I have two questions:

  1. Is TMinuit2 better than TMinuit? (even only in some cases)
  2. Is there any example for how to use TMinuit2 comparing with doing the same thing with TMinuit?

Hi,

Thanks for the post.
Minuit served us very well for a long time. However, ROOT is transitioning to the Minuit2 minimizer, that builds on the experience of Minuit and, only because of that, aims to be better than that.
I would perhps start by pointing you to ROOT: Minuit2

Cheers,
Danilo

Thank you for pointing this page, I have read the page and there are two calls:

minimum->SetMaxFunctionCalls(1000000); //for Minuit/Minuit2
minimum->SetMaxIterations(10000); //for GSL

What are the difference of them? And Do I need to set the second one when using TMinuit2?

And I have another question, in the Fitting function I need to use some extra information instead of fitting parameters, I made it a class and Fitting function is a member function so that it can access the member parameter in the class, but when write ROOT::Math::Functor functionRT(&FittingFunctionRT, 4); I got this:

error: must explicitly qualify name of member function when taking its address

then I added the namespace ROOT::Math::Functor functionRT(&TrackFitMinimizer::FittingFunctionRT, 4); I got this error:

Functor.h:121:14: error: called object type 'double (TrackFitMinimizer::*)(const double *)' is not a function or function pointer
      return fFunc(x);

What should I do?

Hi,

I think the error is not related to ROOT: perhaps one can have a look to pages like this one? c++ - Function Pointer (Within Class) - Stack Overflow

Cheers,
D

Thank you, I understood about the error, and can you please tell more details about the functions I mentioned before? What are the difference of them? And Do I need to set the second one when using TMinuit2?

Hi,

For creating the Functor class from a non-static member function, you need to pass a pointer to the class itself, in order to get its data, and the member function pointer. Here is an example of using the Functor class from Mathematical libraries - ROOT

#include "Math/Functor.h"

class MyFunction {
public:
    double operator()(const double *x) const
    {
        return x[0]+x[1];
    }
    double Eval(const double * x) const
    {
        return x[0]+x[1];
    }
};

double freeFunction(const double * x ) {
    return x[0]+x[1];
}

int main() {
    // Test directly calling the function object.
    MyFunction myf;

    // Test from a free function pointer.
    ROOT::Math::Functor f1(&freeFunction,2);

    // Test from function object.
    ROOT::Math::Functor f2(myf,2);

    // Test from a member function.
    ROOT::Math::Functor f3(&myf,&MyFunction::Eval,2);
    double x[] = {1,2};
    cout << f1(x) << endl;
    cout << f2(x) << endl;
    cout << f3(x) << endl;
    return 0;
}

Then for doing the minimization you should not use the TMinuit2 class. This is a legacy and deprecated class, that has a signature similar to TMinuit. For minimising a function, you should use the minimiser interface, as described in this tutorial: ROOT: tutorials/fit/NumericalMinimization.C File Reference.

Concerning your previous question:

minimum->SetMaxFunctionCalls(1000000); //for Minuit/Minuit2
minimum->SetMaxIterations(10000); //for GSL

Minuit and Minuit2 do not have a limit on the maximum number of iterations but on the number of function calls. Normally, if not computing the Hessian but computing numerical derivatives you have something like:

number_of_function_calls = number_of_iterations * (number_of_parameters * 2 + 2)

Teh GSL minimiser instead can control the number of iterations. In general you can always use the default values and change them only if needed.

Lorenzo