# Fit model rewriting to improve stability or constraints... good idea? How to get errors?

Hi all,

I am fitting a detector signal shape like this:

with a 8-parameter function (note that the “baseline noise” has been assigned as error to each bin and a chi2 minimization has been requested) as:

f(t | A, B, b_r, \delta_1, \sigma, s_m, t_0, \tau) = \frac{ A ( e^{-\frac{t-t_0}{\tau}} - B e^{-\frac{t-t_0}{\tau \cdot b_r}} ) } {(1 + e^{-\frac{t-t_0}{\sigma}}) (1 + e^{-\frac{t-t_0-\delta t_1}{\sigma \cdot s_m}} ) }

I noticed that the fit is much more stable over all waveforms by rewriting the model in various ways, e.g. as:

f(t | A, B, b_r, \delta_1, \sigma, s_m, t_0, \tau) = \frac{ A ( e^{-(t-t_0)\cdot\alpha} - e^{-(t-t_0) \cdot \beta - b} ) } {(1 + e^{-(t-t_0) \cdot \omega}) (1 + e^{\delta_1 -\frac{ (t-t_0) \cdot \omega}{ 1+ \exp{\gamma}} } ) }

Basically:

• multiplications in the exponents work better than ratios (kind of expected)
• the initial idea of highlighting the ratios between the various “\tau”, i.e. always writing “\tau \cdot F” to refer one to another does not seem so decisive (cannot really draw conclusions here, too many different trials, but in general correlations seem to increase).
• I could force (and sometimes helps) a parameter to be positive by writing it as \exp{P}, or to be larger than 1 by writing it as 1+\exp{P} and I am using this especially in the denominator where the two sigmoid functions can easily exchange role.

My questions are the following:

1. Clearly I have apply at least the strategy in the first bullet point to have a high success rate. How do I recover the errors in the original parametrization with TMinuit2? E.g. I have found the best \alpha with its errors and I know that \tau = 1/\alpha, can I ask TH1::Fit() with TMinuit2 to not change any parameter value but just to calculate “Hesse” errors with the initial values that I have set up?

2. Is the third bullet point a good idea? I know that Minuit can also bound parameters but with the exponential I can have a one side limit only. Is this discouraged and if so for which reason?

Matteo

P.S. I used this category because it seems more related to fitting even if I am not using RooFit for this but just the bare TH1::Fit(). Please correct me if this is wrong

Hi @malfonsi79,
sorry for the long response times, I think we need @moneta to help here.

Cheers,
Enrico

Hi,

• Reparametrizing the parameter is certainly good because it can increase the stability, but if you are interested in the error it can become complicated. What you suggest will not work all the time, when computing errors you need to compute second derivatives and then inverting the matrix. This could cause a larger numerical error. You can call just the Hessian with the initial values, but you need to use the lower Fitter interface instead of TH1::Fit.
• If using Minuit2 you can use one side limits only. It is used sort for the transformation. Again this is possible using the Fitter interface.

Here is an example of using the Fitter interface:
https://root.cern.ch/doc/master/combinedFit_8C.html

In general to improve stability is better to redefine the fit parameters to have their value and errors at around 1, so the covariance matrix is well defined and the numerical computations of Minuit for derivatives are more robust. If you can rescale the parameters this will be in general better that appling non-linear transformations.

Lorenzo

Dear Lorenzo,

thanks a lot.
Is the method CalculateHessErrors () that is only calculating the errors without taking further minimization steps?
So the steps would be:

1. Make the fit with the more robust parametrization
2. Arrange a new fit with the Fitter interface and the other parametrization, but do not call Fit()
3. Set the parameters according to the results of the previous fit, e.g. using the relation \tau = 1/\alpha . I do not need to fix these parameters neither to set initial errors.
4. Call CalculateHessErrors() and get the results via the method Result()

BTW The Hessian should be nothing else (or maybe the inverse, always confused) than the matrix of errors that I should get with the errors propagation from the statistics lectures, isn’t it?

and for simple 1 to 1 relation between parameters of the two parametrizations maybe the error calculation is as simple as this… or am I missing something?

Hi,

The problem is that CalculateHessErrors will probably need to have a minimum before. What I would do is

1. Make the fit with a robust parametrisation
2. Change the parametrizatioon starting from the found minimum and fit again, maybe with an higher tolerance
3. .CalculateHessErrors()

If you apply error propagation you will get something different than using the Hessian with the new parametrization.

Lorenzo

Thanks a lot for the clarifications!

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