Speeding up fitting to a Landau distribution

I’m trying to fit a lot of sets of data to a Landau distribution as quickly as possible. Using the TF1.FIT() method does give good results but it is quite slow and I would like to speed things up.

I’ve had two ideas on how to do this. Firstly, I notice that fitting to the function of a Gaussian ([0] exp(-(X - [1])^2 / (2 * [2] ^2) ) is faster than using TMath::Gaus, so I wondered if there is a numerical approximation to a Landau that might be faster.

Secondly, I considered altering the fitting algorithm used to give less precision but more speed, for instance using simplex or reducing the maximum number of iterations.

Unfortunately, when I googled for how to do both of these, I couldn’t find an answer. I’m aware that the TMinuit object can be told to use simplex and so on, but the only tutorials I can find for it were for minimising functions. Is there a way I can use it to fit functions to data instead?


I am surprised that ([0] exp(-(X - [1])^2 / (2 * [2] ^2) ) is faster than TMath::Gaus. This can happen only if you are using ROOT 5.34 (i.e. CINT) and define the function using a string (i.e. using TFormula).

In 5.34 you would need to write the function in C++ code in order to be fast.
This on the other hand is not needed anymore in ROOT 6.
If you are using the master we are putting speedup in fitting by using multi-threads and also vectorisation in the function evaluation. We don;t have yet a vectorised version for Math::Landau, but we will have it soon.

You should not use Simplex, it is much slower than Migrad. You might need to use Migrad with strategy 0 to be a bit faster if you are not interest in the error evaluation. You might try also to increase slightly the tolerance.
Just do for example before calling TH1.Fit


Best Regards


Thanks for the help Lorenzo, it works much faster after switching to a newer version of root and fiddling with the tolerances.

1 Like

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