# TF1 does not take fitted parameters

**URL:** <https://root-forum.cern.ch/t/tf1-does-not-take-fitted-parameters/36665>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [November 4, 2019, 1:34pm UTC](https://root-forum.cern.ch/t/tf1-does-not-take-fitted-parameters/36665 "2019-11-04T13:34:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AndreasLdt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@AndreasLdt](https://root-forum.cern.ch/u/AndreasLdt)\
**Post date:** [November 4, 2019, 1:34pm UTC](https://root-forum.cern.ch/t/tf1-does-not-take-fitted-parameters/36665/1 "2019-11-04T13:34:48Z")

</div>

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.

```auto
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.

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

```

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

```auto
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

---

<div class="post-metadata">

**Author:** ![ilam](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ilam/32/19180_2.png) [@ilam](https://root-forum.cern.ch/u/ilam)\
**Post date:** [November 4, 2019, 6:11pm UTC](https://root-forum.cern.ch/t/tf1-does-not-take-fitted-parameters/36665/2 "2019-11-04T18:11:24Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![AndreasLdt](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/edb3f5/32.png) [@AndreasLdt](https://root-forum.cern.ch/u/AndreasLdt)\
**Post date:** [November 6, 2019, 10:45am UTC](https://root-forum.cern.ch/t/tf1-does-not-take-fitted-parameters/36665/3 "2019-11-06T10:45:04Z")

</div>

@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)

---

<div class="post-metadata">

**Author:** ![OSchaile](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/e495f1/32.png) [@OSchaile](https://root-forum.cern.ch/u/OSchaile)\
**Post date:** [November 6, 2019, 12:01pm UTC](https://root-forum.cern.ch/t/tf1-does-not-take-fitted-parameters/36665/4 "2019-11-06T12:01:53Z")

</div>

Hi,  
to help you we need your complete macro+ histo  
and your complete log.  
You only show the output of Minuit which looks fine  
At least the following works as expected.

```auto
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
