Using TMinuit/TFitter in a class

Hello,

while trying to use the TFitter-function within a class I obtained the following error:

src/LKFMinuit.cpp:13: error: no matching function for call to ‘TFitter::SetFCN(<unresolved overloaded function type>)’ /cernroot/5_18_00/deb4.0-gcc4.1.2/include/TFitter.h:69: note: candidates are: virtual void TFitter::SetFCN(void*) /cernroot/5_18_00/deb4.0-gcc4.1.2/include/TFitter.h:70: note: virtual void TFitter::SetFCN(void (*)(Int_t&, Double_t*, Double_t&, Double_t*, Int_t))
The attachment delivers a minimal example which reproduces the error. Does anybody know how to solve this? Or is impossible to use TMinuit within a class?

Thx alot
Philipp
minimalbeispiel.tar.gz (2.34 KB)

Hi,

the function passed in TFitter::SetFCN, must be a global function or a static member function of a class, cannot be a member function.
You can fix this by making a static instance of your class (LKFMinuit)

If you are using the latest ROOT version, the alternative is to use the new fitter class, ROOT::Fit::Fitter. In this case you can use a member function of a class, as following:

LKFMinuit * myClass = new LKFMinuit();
ROOT::Math::Functor fcn(ndim, myClass, &LKFMinuit::minuitFunction);
ROOT::Fit::Fitter fitter; 
double params[ndim] = {  .........}; // initial parameters
fitter.FitFCN( fcn, params);
fitter.Result().Print();

But the signature of LKFMinuit::minuitFunction must be :

double  LKFMinuit::minuitFunction( const double * x);

If you are interested, I could send a complete running example,
Regards

Lorenzo

Hi,

I am having exactly the same problem. I want to use TFitter, could you please upload the modified code that is running?

Thanks.

Hi,

I solved the problem myself, thanks anyway.

Hello, how did you solve your problem? A brief explanation may be useful for the next users who may encounter the same problem. Thanks you in advance.

Hi,

It is recommended to use the new class ROOT::Math::Fitter or ROOT::Math::Minimizer if you just want to minimise a function.
See the example tutorials:

root.cern.ch/root/html534/tutori … ion.C.html

root.cern.ch/root/html534/tutori … t3D.C.html

Best Regards

Lorenzo

Hi,

Sorry dude, I should have put the code. I attached a simpler version of the code this time, no make file. You compile with

.L LKFMinuit.cpp+ //compile fitting class
.L lkf.cpp+ //compile main program

lkf() //run the fit

I just made the minuit function static and I call the member functions using the pointer to this (the object) that I declared as a global variable and initialize in the constructor.
Code.tar.gz (880 Bytes)