# Problems with Fit Options Statistics Panel

**URL:** <https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772>\
**Category:** Newbie\
**Created:** [March 2, 2021, 2:43pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772 "2021-03-02T14:43:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrramos](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rrramos](https://root-forum.cern.ch/u/rrramos)\
**Post date:** [March 2, 2021, 2:43pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/1 "2021-03-02T14:43:28Z")

</div>

Hello everyone,

I am having a problem with the statistics panel of my fit. I am trying to fit the same function in my spectrum with different ranges but even though I change the range, my fit parameters, chi-square / ndf and etc don’t change in the fit statistics panel but if I ask to print in the terminal, using for example:

```auto
  cout << "Chi Square = " << f4->GetChisquare() << endl;
  cout << "NDF = " << f4->GetNDF() << endl;

```

then I obtain a different chi-square that I have in the statistic panel.

Can anybody help me?

Sorry if this problem already appeared here, but I couldn’t find anything that can help me.

Best regards.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [March 2, 2021, 2:51pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/2 "2021-03-02T14:51:06Z")

</div>

Hi @rrramos; I am inviting @jonas as he may know the answer to this question.

Cheers.

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [March 2, 2021, 3:05pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/3 "2021-03-02T15:05:52Z")

</div>

Hi,  
Probably, since you are doing many fits with different ranges, the results refer to different fit results.  
The best, is for each fit, you keep the TFitResult object , return by TH1::Fit when using option S.  
You can then always add the desired values in the fit statistics panel.

Lorenzo

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 2, 2021, 4:07pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/4 "2021-03-02T16:07:16Z")

</div>

After each “Fit” statement, try to add:  
`if (gPad) { gPad->Modified(); gPad->Update(); }`

---

<div class="post-metadata">

**Author:** ![rrramos](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rrramos](https://root-forum.cern.ch/u/rrramos)\
**Post date:** [March 2, 2021, 4:49pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/5 "2021-03-02T16:49:53Z")

</div>

Hi Lorenzo,

when you say it, it’s for example, to me to do something like that:

```auto
h1->Fit("f4", "S");

```

?

and I am doing many fits but it’s not at the same time in my script. Actually, I run my script for each new range because of this I can’t understand why my fits in the statistics panel keep showing the same results, since they are independent.

thank you so much for helping me!!

---

<div class="post-metadata">

**Author:** ![rrramos](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rrramos](https://root-forum.cern.ch/u/rrramos)\
**Post date:** [March 2, 2021, 4:59pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/6 "2021-03-02T16:59:34Z")

</div>

Hi Wile!

I tried to do this but still doesn’t work =/ and also I am not doing each fit in the same time in my scrip, actually I run my script for each new range fit and save the results, because of this I cant understand why the results is the same even when I change the range, also, the Chi square and NDF make no sense for me, because I fiting 4 bins with a function that have 2 parameters (and the fit looks good for me) and I got a Chi square/NDF = 29.13/11. What do you think it can be?

Thank you so much for helping me!

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 2, 2021, 5:19pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/7 "2021-03-02T17:19:53Z")

</div>

Attach your macro for inspection.

---

<div class="post-metadata">

**Author:** ![rrramos](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rrramos](https://root-forum.cern.ch/u/rrramos)\
**Post date:** [March 2, 2021, 5:40pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/8 "2021-03-02T17:40:00Z")

</div>

now that I went to send you my code I ended up finding my error. I was doing this:

```auto
 initial->Fit("f1", "REM0");
  initial->Fit("f2", "REM0");
  initial->Fit("f3", "REM0");
  initial->Fit("f4", "REM0");
  initial->Fit("f5", "REM0");
  initial->Fit("f6", "REM0");
  initial->Fit("f7", "REM0");
  initial->Fit("f8", "REM0");
  initial->Fit("f9", "REM0");

```

I forgot to comment on all these lines that make the fit (how a said, I run only one fit per time, so I think I should let just the line that makes the fit that I want).

Doing this my Chi-square / ndf in the statistics panel is equal to that I print in the terminal using this

```auto
  cout << "Chi Square = " << f4->GetChisquare() << endl;
  cout << "NDF = " << f4->GetNDF() << endl;

```

With these, my problem is solved!!

Thank you!!!

---

<div class="post-metadata">

**Author:** ![rrramos](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rrramos](https://root-forum.cern.ch/u/rrramos)\
**Post date:** [March 2, 2021, 6:57pm UTC](https://root-forum.cern.ch/t/problems-with-fit-options-statistics-panel/43772/9 "2021-03-02T18:57:48Z")

</div>

Hi Lorenzo, I found my error in the code, now my problem is solved! Thank you for your help!!
