Fixed parameters in fit


I would like to know the number of free parameters of a TF1 fit function. So, the number of parameters minus the number of parameter that I fixed with TF1::FixParameter. Is it possible to obtain that number from somewhere?

I can’t find a method anywhere - it even appears as if the chi2 that you get after fitting to a histogram doesn’t take into account that some parameters may be fixed!

(I’m using root 3.05/04 on Red Hat 7.3)



root [0] TF1 *f1 = new TF1(“f1”,"[0]xsin([1]*x)",-3,3);
root [1] f1->GetNpar()
(const Int_t)2
root [2] f1->SetParameters(1,2)
root [3] f1->Draw()
TCanvas::MakeDefCanvas: created default TCanvas with name c1
root [4] f1->GetNpar()
(const Int_t)2
root [6] f1->FixParameter(0,1)
root [7] f1->GetNpar()
(const Int_t)2

Hi Paul,

Following your legitimate request, I have implemented
Int_t TF1::GetFreeParameters() const
The source is in CVS.

In your case, you can emulate this function with your version of ROOT, eg

Int_t GetNumberFreeParameters(TF1 *f1)
// return the number of free parameters

Int_t npar = f1->GetNpar();
Int_t nfree = npar;
Double_t al,bl;
for (Int_t i=0;i<npar;i++) {
if (al*bl != 0 && al >= bl) nfree–;
return nfree;