I wanna see if my fitting results are good or not

Hi experts.

Q1.I wanna see if my fitting results are good or not.
So i wanna get Chi square from my fit result.

Below is what i used the code when i was fitting.

 Double_t par1[13];

 TF1 *fe = new TF1("fe","expo",0,20);
 N_37->Fit(fe,"R");

 TF1 *fp = new TF1("fp","pol0",1,20);
 N_37->Fit(fp,"R");

 TF1 *fg = new TF1("fg","gaus",2,4);
 fg->FixParameter(1, 3.2);
 fg->FixParameter(2, 6.76268e-1);
 N_37->Fit(fg,"B","R+");


 TF1 *f1 = new TF1("f1","expo(0)+pol0(2)+gaus(3)",0,20);
 f1->Draw("same");
 f1->SetLineColor(kRed);
 fe->GetParameters(&par1[0]);
 fp->GetParameters(&par1[2]);
 fg->GetParameters(&par1[3]);
 f1->SetParameters(par1);
 f1->FixParameter(4, f1->GetParameter(4));
 f1->FixParameter(5, f1->GetParameter(5));
 f1->SetLineColor(kRed);
 N_37->Fit(f1,"B","R+",1,20);

 TF1 *f2 = new TF1("f2","expo(0)+pol0(2)",0,20);
 f2->Draw("same");
 f2->SetParameters(f1->GetParameter(0),f1->GetParameter(1),f1->GetParameter(2));
 f2->SetLineColor(kBlue);
 f2->SetLineStyle(3);
 N_37->Fit(f2,"B","R+",1,20);

 auto fitresult1 = N_37->Fit(f1,"S","",0,20);
 auto fitresult2 = N_37->Fit(f2,"S+","",0,20);

 double integral1 = f1->Integral(1,6);
 double integral2 = f2->Integral(1,6);

 auto covMatrix1 = fitresult1->GetCovarianceMatrix();
 auto covMatrix2 = fitresult2->GetCovarianceMatrix();

 double sigma_integral1 = f1->IntegralError(1,6,fitresult1->GetParams(),covMatrix1.GetMatrixArray());
 double sigma_integral2 = fp->IntegralError(1,6,fitresult2->GetParams(),covMatrix2.GetMatrixArray());

 std::cout << "Number of signal event = " << 2*integral1-2*integral2 << "+/-" << 2*sigma_integral1-2*sigma_integral2 << std::endl;

and result show like below.

Q2. I have a question here. What is the “Minimizer is Linear” mean"?

Hi @HyungJoe_Kwon,
to get the Chi2 you just need to use

fitresult1->GetFCN();

Regarding the second question, a minimizer is linear when the function you minimize (e.g. Chi2) depends in a linear way from all the parameters you are fitting, as example think of the polynomial coefficients.

Stefano

Thanks for reply!
I use that code but it shows like below.
/home/a9mon/NaI037/Fit_expolgaus.C:62:15: error: no member named ‘GetFCN’ in ‘TFitResult’
fitresult1->GetFCN();
How can i fix it??

TFitResult

I saw it already but there’s no information about GetFCN().

Sorry @HyungJoe_Kwon, the method name is MinFcnValue()

Thanks for reply @Dilicus .
But when i use that command, It didn’t show any value.
What should i do?

How do you use it ? can you post the line of code ?

I just type this code.

fitresult1 → MinFcnValue();

I would say:

double result = itresult1-> MinFcnValue();
printf("result = %g\n",result);

Thanks for reply!
And i have another question.
How can i get ndf?

On the same documentation page it seems la the Ndf function does the job ? right ?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.