gMinuit.fCstatu

In C++ I sometimes inspect gMinuit.fCstatu to check for convergence. In the python interpreter, I can access gMinuit, too:

import ROOT as R
R.TMinuit()
print(R.gMinuit.fCstatu)

However, the same code snippet results in a null reference to R.gMinuit when executed from a file, e.g., saving the snippet in test_gMinuit.py and executing execfile(‘test_gMinuit.py’).

What is the correct way to access the convergence status from within a Python program?

Hi,

the problem is in this line:R.TMinuit()which creates a TMinuit object (that underneath assigns itself to gMinuit, which is why that is non-NULL), but doesn’t keep it alive. In the interpreter, the result of the last statement is assigned the the implicit variable ‘_’, so it takes two statements before the TMinuit object goes out of scope. In a file, without such an implicit variable, it’s immediate.

So, assign the freshly created TMinuit to something and keep that reference alive for the needed duration, or release Python from maintaining the created instance.

Cheers,
Wim

Wim,

Many, many thanks for the explanation and solution.

-Evan