Trouble with TMinuit

I’ve been trying to use TMinuit to fit a function and I think I have everything set up correctly, but the code won’t compile. I’m using the compiler from MSVC 8 and I believe the error is in my implementation of TMinuit::SetFCN.

void MyClass::MyFunction(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t errflag)
{

//Function does stuff

}

void MyClass::OtherFunction(Int_t int1, Int_t int2)
{

//Function does stuff
TMinuit* fit = new TMinuit(5);
fit -> SetFCN(MyFunction);

}

This gives a compiler error ‘MyClass::MyFunction’: function call missing argument list. When I try fit -> SetFCN(&MyClass::MyFunction); I get the error ‘void TMinuit::SetFCN(void )’ : cannot convert parameter 1 from 'void (_thiscall MyFunction::)(Int_t &,Double_t *,Double_t &, Double_t *, Int_t)’ to ‘void *’. If anyone can point me in the right direction, I’d really appreciate it.

TMinuit::SetFCN can not take a member functions as argument. You need to use a free standing function.

Cheers,
Philippe

What is the reason for this (I guess there is one :smiley: ) ? It is quite annoying…

And I think it might be useful to write a warning about it on the TMinuit class description, wouldn’t it ?

Hi,

In your case, it seems that the function is not static, this means it can only be used in conjunction with an object. Passing (and then) both an object and a function is slightly more difficult and was not implemented when TMinuit was first developed.

We are now working to alleviate the situation by introduction support for functor objects.

Cheers,
Philippe.

Well it is not really my case, this is an old topic. Personnaly I have the error

error: no matching function for call to ‘TMinuit::SetFCN(<unknown type>)’ /cern/pro/root/include/TMinuit.h:269: note: candidates are: virtual void TMinuit::SetFCN(void*) /cern/pro/root/include/TMinuit.h:270: note: virtual void TMinuit::SetFCN(void (*)(Int_t&, Double_t*, Double_t&, Double_t*, Int_t))
or

error: no matching function for call to ‘TMinuit::SetFCN(void (myClass::*)(Int_t&, Double_t*, Double_t&, Double_t*, Int_t))’ [...]
if I give myClass::myFcn in argument to SetFCN.

But anyway I guess this is the same problem, and you are right about the conjunction since I use several TMinuit objects which FCN need a customed array in argument… I’ll try to get round the problem.

Thanks for the explanation.

You can use Minuit2, which supports passing objects, via the class, TFitterMinuit,

using instead of SetFCN , the function SetMinuitFCN, where you pass a pointer of a class implementing the ROOT::Minuit2::FCNBase interface.

See root.cern.ch/root/htmldoc/MINUIT2_Index.html

Best Regards

Lorenzo

Yes, I could, thank you for making me know this feature.

However, as far as I understand the Minuit2 package is independant from ROOT (at least for old versions), and since my code will (or might…) be used by other people than me, I don’t want to impose them to install a new package.

Furthermore, my code will be mainly used on CCALI servers (Lyon), which ROOT version is 4.02/00, I don’t know if Minuit2 is so far backward compatible ?

So, I will just try to find a trick for know, but I keep this in mind for my personal utilisation… :wink:

Minuit2 is part of ROOT for versions >= 5.08.
You could use with older versions, but it is more complicated (you need to install and use as an external package)

Lorenzo

I think that website actually is:
http://root.cern.ch/root/html524/TFitterMinuit.html

Elliott

Hello,
Thank you for posting the correct link for the TFitterMinuit class.

However, things have changed since 2007. The simplest way to use the Minuit2 minimizer in ROOT is via a common ROOT::Math::Minimizer interface

root.cern.ch/root/htmldoc/ROOT__ … mizer.html

which in the case of Minuit2 is implemented by the ROOT::Minuit2::Minuit2Minimizer

root.cern.ch/root/htmldoc/ROOT__ … mizer.html

See examples how to use this class in
root.cern.ch/drupal/content/nume … nimization

Lorenzo

I am trying to do something similar using ROOT::Math::Minimizer, following the examples given in the links provided in the post before this one. However, I keep hitting an error message whenever I try to compile:

/a/apps/local/root-05.24.00/include/Math/Functor.h:86: error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘((const ROOT::Math::FunctorHandler<ROOT::Math::Functor, Double_t (Functor_Test::*)(const Double_t*)>*)this)->ROOT::Math::FunctorHandler<ROOT::Math::Functor, Double_t (Functor_Test::*)(const Double_t*)>::fFunc (...)’, e.g. ‘(... ->* ((const ROOT::Math::FunctorHandler<ROOT::Math::Functor, Double_t (Functor_Test::*)(const Double_t*)>*)this)->ROOT::Math::FunctorHandler<ROOT::Math::Functor, Double_t (Functor_Test::*)(const Double_t*)>::fFunc) (...)’

I have no idea what to make of this. Has anybody else run into this before, and have suggestions for what to do? I have included code that should reproduce the error.

Thanks!
Functor_Test.h (367 Bytes)
Functor_Test.cxx (703 Bytes)

Hi,

the problem is that Shape() is a non static member function of a class. In this case you need to pass a pointer to the class object as follows:

 ROOT::Math::Functor fShape(this,&Functor_Test::Shape,2);

Or alternatively you can make the function Shape() a static function.

See “Wrapping Multi Dimensional Functions” in
root.cern.ch/drupal/content/how- … -framework

Best Regards

Lorenzo