Fitting, Integral

Hi experts.
I now want to fit pol1+gaus and pol1 respectively to the histogram. So I used the code below.

double initparms_f1[] = {1,1,5, 3.2, 6.76268e-1};
TF1 *f1 = new TF1("f1","pol1(0)+gaus(2)");
f1->SetParameters(initparms_f1);
f1->FixParameter(3, 3.2);
f1->FixParameter(4, 6.76268e-1);
f1->SetLineColor(kRed);
N_37->Fit(f1,"B","R",1,20);

double initparms_f2[] = {5.59856, -1.42512e-1};
TF1 *f2 = new TF1("f2","pol1");
f2->SetParameters(initparms_f2);
f2->FixParameter(0, 5.59856);
f2->FixParameter(1, -1.42512e-1);
f2->SetLineColor(kBlue);
f2->SetLineStyle(3);
N_37->Fit(f2,"B","R+",1,20);

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

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

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

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

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

However, I want to apply the parameters of pol1 obtained from f1(pol1+gaus) as initial parameters to pol1 of f2(pol1).

And also can i get integral error different way?

Thanks for reply! But I can’t find about parameter information.

This example shows how to get the fit parameters. May be that’s what you need.

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