Problems with Fit Options Statistics Panel

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:

  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.

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


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.


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

Hi Lorenzo,

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

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!!

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!

Attach your macro for inspection.

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

 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

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

With these, my problem is solved!!

Thank you!!!

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