# TF1 does not take fitted parameters

Hi forum,

I have a histogram with a plateau region. For considering the uncertainties of this plateau, I fit a horizontal line and a linear line with some slope to the plateau and look for some differences.

The problem I have is, that the linear fit function called fslope does not take the values from the fit (which I see in the output), but the parameters are still the original values.

fLine = new TF1("fLine","[0]",0,1000);
fSlope = new TF1("fSlope","[0] + [1]*x",0,1000);

fLine->SetParameter(0, someinitalvalue);
histogram->Fit("fLine","","",binstart, binend)

float plateauHeight  = fLine->GetParameter(0)
cout << "Plateau Height is " << fLine->GetParameter(0) << endl;

fSlope->SetParameters(plateauHeight, 0.);
//The Slope is initially set to be the same as fLine
histogram->Fit("fSlope","","",binstart, binend);

Now, I get the ouput from the Fit, which tells me that both fits (fLine & fSlope) converge and the parameter values differ as expected. However I now try to get these values with the following command, the actual parameters of fSlope are still plateauHeight and zero and not the newly fitted values.

cout << "Parameters of fSlope: p0 = " << fSlope->GetParameter(0) << " p1 = " << fSlope->GetParameter(1) << endl;

Here is an example output from the log of the fit:

fLine:
FCN=10.7144 FROM MIGRAD    STATUS=CONVERGED      12 CALLS          13 TOTAL
EDM=2.29974e-15    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  p0           2.54368e+01   3.49470e-02   5.84037e-05  -1.94064e-06

fSlope:
FCN=8.50783 FROM MIGRAD    STATUS=CONVERGED      37 CALLS          38 TOTAL
EDM=2.2915e-19    STRATEGY= 1      ERROR MATRIX ACCURATE
EXT PARAMETER                                   STEP         FIRST
NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  p0           2.58210e+01   2.61019e-01   5.26164e-05   1.93279e-08
2  p1          -1.00532e-02   6.76774e-03   1.36424e-06   7.45442e-07

As you can see, the p0 parameters should differ after the two fits, but for fslope the parameters are never updated from the fLine p0 adn zero to the new fSlope p0 and p1.

Does anybody know, why the parameters are not updated? I use ROOT v6

If I understood correctly, you want to get the results of the fit, right? I think you have to create a separate function that is updated with the fit parameters. After the fitting, maybe try something like this:

TF1 *fittedfunc = histogram->GetFunction(“fLine”);
cout << "parameter p0: " << fittedfunc->GetParameter(0) << endl;

@ilam: Thank your for your response. I try to implement an auxiliary function as you suggested. However, the fLine Function also changes its parameter values according to the fit. Why doesn’t the fSlope?

Additionally, I have seen that in some cases the fSlope takes the new parameter values and in some cases it doesn’t - with no obvious difference in the Histograms (i.e. their Plateau Height)

Hi,
You only show the output of Minuit which looks fine
At least the following works as expected.

void fitp1()
{
auto f1 = new TF1("f1", "pol1", 0, 100);
f1->SetParameters(0, 0.1);
auto h1 = new TH1F("h1", "h1", 100, 0, 100);
h1->FillRandom("f1");
h1->Draw();
f1->SetParameters(1, 0.5);
h1->Fit("f1");
printf("p0 = %f p1 = %f\n",
f1->GetParameter(0), f1->GetParameter(1));
}

Otto