Fit problem

Hello everybody,

I have a big problem with the fit function for a TF1D:
I want to fit an exponential but the result looks really bad (see attachement).
here is what I do:

TF1 Fit(“Fit”,"[0]10*([1]*x)",10,14.5);
Fit.SetParameters(0.1,0.5);//can remove it, still bad

Changing the options in Fit does not seem to have any effect.
I don t get why the result seems so wrong (it is easy to get a better fit …).

Thanks for your help, I have tried everything I could …

Please send me your script together with your mygraph object (in a root file).
It looks like the classical problem where errors are uncorrectly defined or not defined at all.


Here is the root file with the canvas.

The piece of code that does the fit:

TF1 MyFit(“Fit”,"[0]10*([1]*x)",10,14.5);

Even when using the Fit panel, the fit doesn t work properly …

Thanks for your help.
NmSigCanvas.root (12.3 KB)

The fit is perfectly correct.
However your fit model is wrong in the range where you fit.
Your fit function model seems OK if you fit
in the range [10,14], but not [10,14.5]
where your graph turns into a different behaviour.


well ok … It’s in fact much better if I cut at 14, I just found it weird that it seems only to fit the upper part when cutting at 14.5… may be because of the log scale.

Anyway thanks for your help

The reason your fit looks bad is because you are plotting the Y-axis on a log scale - if you turn this off you will find it looks a lot better !

If what you really wanted to fit was the log of your variable you should plot the log then fit a straight line to that.

(A good book on fitting might help :wink: ).


Sorrowly, I do not know TMinuit well enough, but I am afraid that it does
not have the possibility to do robust fitting.

You could try to use the following robust fitting functions from R, a public
domain statistics package: … l/rlm.html … Index.html

I am sure these functions will fit your data correctly.

P.S.: It would be great if TMinuit would also have this possibility.

Best regards

Hi Christian,

I feel obliged to disagree with you (and even strongly disagree).
There is likely far more experience with fitting with Minuit (I mean serious fitting) than packages like the ones in R.
In the case reported above, the problem is not in the fitting procedure,
but on the user assumption with the fitting function that cannot represent
the data in this range.


Dear Rene

As I said, I do not know Minuit well enough although I have made
a copy of the manual. As far as I understand, Minuit is a robust
but already old package written originally in Fortran for the
special purposes of the HEP community, but I might be wrong?

Meanwhile the field of statistics has made much progress in
developing novel algorithms, among them also novel algorithms
for robust fitting, as e.g. described in:
P. J. Rousseeuw and A. M. Leroy (1987)
Robust Regression and Outlier Detection. Wiley.

One of these algorithms is called Least Trimmed Squares (LTS),
and it is implemented in every serious commercial statistics
package such as S-Plus, SPSS and SAS. For the SAS implementation
SAS is the world leading professional statistics package, and
probably nobody can say that SAS does not have much experience.

The statistics packages give you a choice of algorithms to
choose from, and it is up to the user to select the suitable
algorithm for his/her dataset.

You may be right that in the special case the user assumption
was wrong, so let me give you a different example, namely your
tutorial macro quantiles.C:
The figure “final quantiles” is a quantile-quantile plot (qq-plot),
and you HAVE to fit a line because the qq-plot compares two
gaussian distributions.
When I use the LTS algorithm then the line is fitted correctly,
however, the following code example does not fit it correctly,
when using the range [0,1]:
f1 = new TF1(“f1”, “pol1”, 0, 1);
gr = new TGraph(n, x, y);
gr->Fit(“f1”, “RQ”);
par0 = f1->GetParameter(0);
par1 = f1->GetParameter(1);

Only limiting the range to e.g. [0.3,0.7] results in a
correct fit, i.e. f1 = new TF1(“f1”, “pol1”, 0.3, 0.7);

Maybe, I did something wrong, and then I would be interested
how to fit this case correctly.
I did not use the methods of TMinuit directly, because I find
them pretty hard to understand.

Best regards


Could you send a running script showing the problem with the fit of a staraght line. In your example, the points in the graph are not defined.


Dear Rene

I have modified the macro quantiles.C in the attachment.
When you do robust fitting, the parameters in both cases would
be almost identical.

Best regards
quantiles.C (2.08 KB)

Dear all,

Interesting discussion, but I have some observations :

  1. Sancho, you are fitting this non-linear power function to data with
    equal weight ? Probably you want the sqrt(1/weight) to be a fraction
    of your data point value .

  2. elc, we all love to enrich our libraries . Any suggestions ??

  3. Christian, the function minimizer Minuit has no clue what a
    least squares, robust estimation etc… is ! It just wants/can
    minimize an objective function that you have to specify . One
    usually calculates the mean of the square of deviations but feel
    free to replace that mean with median and you have one of the
    many possible flavors of robust fitting .

    Correct me if I am wrong but all your links are to robust linear(!)

    I think that the minimzer Minuit runs circles around most other
    minimizers . Even better, the “darth vader” of robust fitting
    Peter Rousseeuw uses currently minuit .

  4. Christian, a misunderstanding of Rene’s quantiles.C .
    This produces not a qqplot , see for instance … plot.shtml

    Even if it did, there is no reason to expect that a straight line will fit
    it . Only in case both distributions are similar .

  5. Anybody willing/interested/already busy to supply some robust


Dear Eddy

ad 3) You are correct, all links are robust linear fitters. There are also
nonlinear fitters, but since I am not a statistician I have no idea whether
these fitters can be considered to be robust.
One popular robust method is called M-estimators, as described in: … ode24.html
The most primitive M-estimator is the trimmed mean, which would already
be sufficient in the case of the modified quantiles.C macro.

ad 4) You are right, I did not read the code carefully. Nevertheless, it
is probably a good example that using trimmed mean before fitting a line
would result in a more accurate fit.

Best regards