# How to supress TMinuit warnings and retrieve FitStatus

**URL:** <https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703>\
**Category:** ROOT\
**Created:** [June 19, 2019, 4:45pm UTC](https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703 "2019-06-19T16:45:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [June 19, 2019, 4:45pm UTC](https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703/1 "2019-06-19T16:45:14Z")

</div>

Hi ROOT expert,  
I’m fitting a lot (~100) of histograms in a single macro. I have two different problems:

- I Get a lot (thousand) of the following errors

```auto
FUNCTION VALUE DOES NOT SEEM TO DEPEND ON ANY OF THE 4 VARIABLE PARAMETERS.
          VERIFY THAT STEP SIZES ARE BIG ENOUGH AND CHECK FCN LOGIC.

```

this floods my output and it’s very annoying. How can I suppress them?

- I cannot printout the detailedfit results of every fit, but I’d like to know if some of them has aSTATUS = FAILED, CALL LIMIT or NOT POS DEF. How can I retrieve it? I’m not finding too useful this printout

```auto
TFitResultPtr r = hist->Fit("func","MRLSQ");
cout<<"Fit Status: "<<r->Status()<<endl;

```

Bonus (hard) question:

- sometimes I get a call limits, to avoid this I have increased the default number to

```auto
ROOT::Math::MinimizerOptions::SetDefaultMaxFunctionCalls( 5000 );

```

this however increase a lot the annoying above-mentioned warnings. Is there a way to know if call limits was it -\> increase max function calls -\> re fit -\> reset max function calls?

Thanks a lot,  
Alberto

* * *

_ROOT Version:_ 6.12/07

* * *

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [June 19, 2019, 7:11pm UTC](https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703/2 "2019-06-19T19:11:46Z")

</div>

This is only a partial answer to your questions, but perhaps it will be sufficient until an expert gets back to you:

> [@a.bragagnolo](#):
>
> How can I suppress them?

You can suppress output by doing:

```python
ROOT.RooMsgService.instance().setGlobalKillBelow(ROOT.RooFit.FATAL)

```

where FATAL can be replaced by ERROR, WARNING, INFO, etc., depending on what output you want to see.

> [@a.bragagnolo](#):
>
> I’m not finding too useful this printout

The status codes are detailed [in this post](https://root-forum.cern.ch/t/meaning-of-values-returned-by-roofitresult-status/16355/2):

> [@Meaning of values returned by RooFitResult::status(..)?](https://root-forum.cern.ch/t/meaning-of-values-returned-by-roofitresult-status/16355/2):
>
> This values depends on the Minimizer used for fitting. For example if you are using Minuit2, you will have:
> 
> ```auto
> status = 0 : OK
> status = 1 : Covariance was mad epos defined
> status = 2 : Hesse is invalid
> status = 3 : Edm is above max
> status = 4 : Reached call limit
> status = 5 : Any other failure
> 
> ```

You can, of course, check the value of the code instead of printing it.

> [@a.bragagnolo](#):
>
> Bonus (hard) question:
> 
> - sometimes I get a call limits, to avoid this I have increased the default number to
> 
> ```auto
> ROOT::Math::MinimizerOptions::SetDefaultMaxFunctionCalls( 5000 );
> 
> ```
> 
> this however increase a lot the annoying above-mentioned warnings. Is there a way to know if call limits was it -\> increase max function calls -\> re fit -\> reset max function calls?

I don’t really understand this part of your question. If you’re not worried about seeing WARNINGs, you can use the `setGlobalKillBelow` function mentioned above.

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [June 19, 2019, 10:06pm UTC](https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703/3 "2019-06-19T22:06:06Z")

</div>

Hi,  
this maybe is a silly advice but are you setting reasonable starting parameters for your function?  
Since the fitter struggle to find a minimum of the Likelihood.

Cheers,  
Stefano

---

<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:** [June 20, 2019, 8:17am UTC](https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703/4 "2019-06-20T08:17:29Z")

</div>

Hi,

Concerning your questions:

1. Normally you switch off all printing in TMinuit, when using from TH1::Fit by doing  
`ROOT::Math::MinimizerOptions::SetDefaultPrintLevel(-1)`

however those messages cannot be switched off. They can be serious and maybe it is worth understand their origin.  
Otherwise they are coming from using as minimiser engine Improve or Simplex. These methods are found not too be very effective, so I would eventually avoid using them. If you find that you really need them, please let me know and it would be great if you can post an example where you show these are useful

1. For getting the status you can both check `FitResult::Status()` but also `FitResult::CovMatrixStatus()`  
which has the meaning:

```auto
 /// using Minuit convention : =0 not calculated, =1 approximated, =2 made pos def , =3 accurate

```

Lorenzo

---

<div class="post-metadata">

**Author:** ![a.bragagnolo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@a.bragagnolo](https://root-forum.cern.ch/u/a.bragagnolo)\
**Post date:** [June 20, 2019, 8:50am UTC](https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703/5 "2019-06-20T08:50:09Z")

</div>

@Dilicus,  
I’m already doing this, but my fit model runs over histograms with number of entries spanning order of magnitudes. So the starting parameters need to work both for 20k entries and 50.

@moneta  
I will try not using Improve. I simply read “improved version” in the root guide and assumed it was strictly better.

Alberto

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [July 4, 2019, 8:50am UTC](https://root-forum.cern.ch/t/how-to-supress-tminuit-warnings-and-retrieve-fitstatus/34703/6 "2019-07-04T08:50:11Z")

</div>

Closed on July 4, 2019, 8:50am UTC

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