How can I detect when parameters are at limit?

I’m trying to find a way to track when my fits have a variable reaching a limit. So naturally the Bool_t fLimset from TMinuit seemed like a great flag to use.

But, I have a weird problem. in a situation where I have some parameters reaching a limit (and minuit shows the at limit warning). If I fit once, then look at fLimset, it will have a value of 0.
But If I rerun the fit, and then look at the value of fLimset, it will have the correct value of 1.

Below, customGaus is a multiple gaussian TF1, with ParLimits placed on every parameter. There are 14 parameters.

histo->Fit(customGaus,"N");
cout << "#IS PAR Reaching Limit? = "<< gMinuit->fLimset << endl; 

histo->Fit(customGaus,"N");
cout << "#IS PAR Reaching Limit? = "<< gMinuit->fLimset << endl; 

This code results in an output to console of:

#IS PAR Reaching Limit? = 0
#IS PAR Reaching Limit? = 1

Can anyone tell me where I’m going wrong?

Update: I edited the title from “Using fLimset from TMinuit to detect pars hitting l” to “How to detect when parameters are at limit” in the hopes I’ll get an answer.

Thanks

I think I figured out a solution, or at least a workaround.
When I add fitting option:
“E” Perform better Errors estimation using Minos technique

Then it seems to detect parameters hitting a limit much better.

Yes, when you are close to the limits, it is also alway better to run Minos (option “E”), since the likelihood does not have anymore a parabolic shape. Minos also detects and also prints a message when the parameter is found to be at the limit

Lorenzo