How to get chi² and probability from a fit

Hi,

I want to get fit results and print them in a more ‘latex’ way for easier formating/copying into my documents. Getting the fit parameter results, errors and covariances is not a problem but I have not really managed to get the simple(?) chi²/ndof and fit probability values.

The number of parameters is already printed:

 cout<<"\n \\bf{free, total parameters} \& "<<TVirtualFitter::GetFitter()->GetNumberFreeParameters()<<","<<TVirtualFitter::GetFitter()->GetNumberTotalParameters()<<" \\\\";

But I have not managed to get the fit results. Looking into TVirtualFitter I suppose that chisquared is returned by ‘Chisquare’ :wink: which needs to be fed by two parameters. But the way I have tried does not work:

 Double_t par[15];
 fitFcn->GetParameters(par);
 cout<<"\n \\bf{\$\\chi^{2}/ndof\$} \& "<<TVirtualFitter::GetFitter()->Chisquare(TVirtualFitter::GetFitter()->GetNumberFreeParameters(), &par))<<" \\\\";

What would be the right/easiest way be to get a fit’s chi², ndof & probability?

Cheers & many thanks for ideas and hints,
Thomas

Hi,
You may want to try an example here:

root [13] TH1F * h1f = new TH1F("h1f", "h", 100, 10, -10)
root [14] h1f->FillRandom("gaus")
root [15] h1f->Draw()
root [16] h1f->Fit("gaus")
root [17] TF1 * f = h1f->GetFunction("gaus")
root [18] f->GetNDF()
root [19] f->GetChisquare()    
root [20] f->GetProb()

Good luck.

Zhiyi.

1 Like