# If status=converged break

**URL:** <https://root-forum.cern.ch/t/if-status-converged-break/41782>\
**Category:** Newbie\
**Created:** [October 9, 2020, 1:47am UTC](https://root-forum.cern.ch/t/if-status-converged-break/41782 "2020-10-09T01:47:33Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [January 27, 2021, 11:33am UTC](https://root-forum.cern.ch/t/if-status-converged-break/41782/6 "2021-01-27T11:33:29Z")

</div>

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:

```auto
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()`](https://root.cern/doc/master/classROOT_1_1Minuit2_1_1Minuit2Minimizer.html#a8f72504b2afaabf666601a44e50a79d6).  
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

---

_[View the full topic](https://root-forum.cern.ch/t/if-status-converged-break/41782)._
