Fitting with class member - virtual function called

I would like to fit function, lets say I have class like this:

class Func(){
static double MyFunc(const double *params)...}

I would like to minimize MyFunc with ROOT::Math::Minimizer
so I tried something like this:

ROOT::Math::Minimizer *min = ROOT::Math::Factory::CreateMinimizer("Minuit2", "Migrad");
ROOT::Math::Functor f(&Func::MyFunc,GetParametersNo());

However now I get error “pure virtual method called” when I call min->Mimimize.
Somebody can help me with this? I would prefer solution that avoid calling static function.

EDIT: after some investigation it seems to be ok, but I still don’t know what is source of this error. By dynamic cast I check class - the minimizer is ROOT::Minuit2::Minuit2Minimize but I don’t know why throws this error.

ROOT Version (e.g. 6.04):
Platform, compiler (e.g. Mint 17, gcc4.8.4):


The is very strange. You should have the Minuit2 library automatically loaded by the ROOT plugin manager. Are you maybe copying the minimiser object later on ?
If you post the full code I can understand this better

Best Regards


I think i found reason, my functor was set in if condition (so it was deleted outside this condition when Minimize was called).
But now I have different error:

Error in : Minuit2Minimizer::Minimize : FCN function has not been set
TempClass.h (9,2 KB)
TempClass.cxx (13,5 KB)
Class its quite big but everything interesing happen at NumericalMinimization.
EDIT: Sorry I’m so blind I didn’t called SetFunction.


Before calling min->Minimize(), you need to pass to the minimiser object the functor pointer.
You should do, just after having create the minimiser,


In your code it is commented (line 459) of TempClass.cxx


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.