"Translating" testMinimize.cxx to Python


when running my Python/PyROOT version of
(from the source tree of ROOT-5.20) - see attached file - I get the following message:

python: math/minuit2/src/TFitterMinuit.cxx:181: virtual ROOT::Minuit2::FunctionMinimum TFitterMinuit::DoMinimization(int, double): Assertion `GetMinuitFCN() != 0’ failed.

The actual function to be minimized is not even called by the minimizer (at least there was no output when I inserted a print statement into the call method of the MyFCN class).

So I assume I made a mistake regarding the definition of MyFCN.

But what’s wrong?


PyROOTtestMinimize.py (3.77 KB)


this isn’t going to work: the C++ vtable, as used to call derived class functions does not know anything about python dictionary look-ups, which that language uses for overriding functions in derived classes.

For TMinuit, there is a replacement of SetFCN() that makes it possible to forward calls from C++ into the python class. I wasn’t aware of the existence of TFitterMinuit (in fact, it doesn’t appear to be built by default on my system), and so there’s no corresponding function for it, since I never wrote one.

What would be needed, is a derived class written in C++ that would forward to the python class that subsequently derives from that class (see pyroot/src/TPySelector.h/.cxx for an example).

I put it on my TODO list, but I’m not going to be able to do any work on it until at least late September. Feel free to file a savannah feature request also.


Hello Wim and Tom,

I would suggest you to to the python wrapper for the ROOT::Math::OOT::Math::IBaseFunctionMultiDim which is used by the ROOT::Math::Minimizer class. This is now the recommended entry point for using all the minimization algorithm in ROOT, including TMinuit.
root.cern.ch/drupal/content/how- … -framework


root.cern.ch/drupal/content/nume … nimization

The class TFitterMinuit of minuit2 is maintained just for backward compatibility