Fitting two kind of function

Hi experts.
I fit two types of function(pol2+gaus, gaus) and integrate the gaus function.

void MultiFitIntegral()
  double initparms[] = {68.37, 2.9, 0.51, 24.1, -8.2, 0.74};
  TF1 *f1 = new TF1("f1","gaus(0)+pol2(3)");
  double initparms2[] = {68.37, 2.9, 0.51};
  TF1 *f2 = new TF1("f1","gaus");
auto fitresult = hdet_y->Fit(f2,"S","",0,6);

double integral = f2->Integral(0,6);

auto covMatrix = fitresult->GetCovarianceMatrix();
std::cout << "Covariance matrix from the fit";

double sigma_integral = f2->IntegralError(0,6,fitresult->GetParams(),covMatrix.GetMatrixArray());
std::cout << "Integral = " << integral << " +/- " << sigma_integral << std::endl;

But as shown in under picture, only gaus function is shown.
What should i do?
Screenshot from 2021-06-01 20-43-47

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided

Processing MultiFitIntegral.C...
In file included from input_line_9:1:
/Users/couet/Downloads/MultiFitIntegral.C:6:3: error: use of undeclared identifier 'hdet_y'
/Users/couet/Downloads/MultiFitIntegral.C:11:3: error: use of undeclared identifier 'hdet_y'
/Users/couet/Downloads/MultiFitIntegral.C:12:18: error: use of undeclared identifier 'hdet_y'
auto fitresult = hdet_y->Fit(f2,"S","",0,6);

I can’t understand what you talking about.

When I execute your macro it produces error because hdet_y does not exist.

That macro was created for just fitting after the histogram was created. hdet_y was defined before.

Yes but to run it we need the data.

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