If status=converged break

Note that the above is valid only when using TMinuit and not Minuit2.
A more general solution is to use the return valued of FitResult::Status() or better what is returned by FitResult::IsValid(). The above lines should be then:

for (int i=0; i<100; i++) {
    auto result = hh->Fit(&ball,"SL","");
    if (result->IsValid() ) break;
 }

Note that In case of TMinuit when gMinuit->fCstatu="CONVERGED" , the return status is always zero and the FitResult is flagged as valid.
If the fit failed instead the status is equal to 4 when using TMinuit.
In case of Minuit2 you have different status values depending on the reason of fit failures.
See Minuit2Minimizer::Minimize().
In this case when the return status is 0 or 1, the fit can be considered a valid fit, while for status>1 the fit is invalid.

Lorenzo

1 Like