Statistical error on Integral of a fit function in ROOT

Hi,

I’m fitting a histogram in Root with a gaussian and a polynomial. I was able to deduce the number of events (using integral) for both signal and background. I would like now to get the statistical error on these number of events.
I tried (see full code below) :

Function->IntegralError(a,b);

However the IntegralError is giving me 0. Can anyone let me know what I’m doing wrong ?

Double_t background3(Double_t *x, Double_t *par)  {
return par[0] + par[1]*x[0] + par[2]*x[0]*x[0] ;
}


Double_t GAUSS(Double_t *x, Double_t *par){
return par[0]*exp(-0.5*(((x[0]-par[1])/par[2])*((x[0]-par[1])/par[2])));

}

Double_t fitFunction(Double_t *x, Double_t *par) {
  return background3(x,par) + GAUSS(x,&par[3]);
}

TF1 *fitFcn = new TF1("fitFcn",fitFunction,3.04,3.17,6);
fitFcn->SetParameters(1,1,1,1,3.095,0.004);

hist4230->GetXaxis()->SetTitle("MM_{(#pi^{+}#pi^{-})} GeV/c^{2}");
hist4230->SetTitle("@4.23 GeV");
hist4230->GetYaxis()->SetTitle("Entries/1.3 MeV/c^{2}");
hist4230->GetYaxis()->SetTitleOffset(1.4);

fitFcn->SetParLimits(5,0.003,0.007);

hist4230->Fit("fitFcn","V+","ep");
hist4230->SetMarkerStyle(20);

TF1 *backFcn = new TF1("backFcn",background3,3.04,3.17,3);
//fitFcn->SetLineColor(kGreen);
backFcn->SetLineColor(kRed);
TF1 *signalFcn = new TF1("signalFcn",GAUSS,3.04,3.17,3);
signalFcn->SetLineColor(kBlue);
signalFcn->SetNpx(500);
Double_t par[6];
fitFcn->GetParameters(par);
backFcn->SetParameters(par);
backFcn->Draw("same");
signalFcn->SetParameters(&par[3]);
signalFcn->Draw("same");

double w=hist4230->GetBinWidth(1);
int integral = backFcn->Integral(3.04,3.17)/w;
int integral2 =signalFcn->Integral(3.04,3.17)/w;

double error_integral2 =signalFcn->IntegralError(3.04,3.17);

cout<<"Integral 1::::::"<<integral<<endl;
cout<<"Integral 2::::::"<<integral2<<endl;
cout<<"Error Integral ::::::"<<error_integral2<<endl;


You fit with “fitFcn” so it only makes sense to ask for fitFcn->IntegralError(3.04, 3.17) (the partial functions “backFcn” and “signalFcn” do NOT have errors as they do NOT have the required covariance matrices passed, see the TF1::IntegralError method description for details).

Thank you for your reply.
So is there a way to go around this problem if I follow what was written in “IMPORTANT NOTE2” ?

From the existing covariance matrix of your "fitFcn”, you need to create / build appropriate covariance matrices for “backFcn” and “signalFcn”.

1 Like

I understood this part but I don’t know exactly how to do that. I start with getting the fit result and extracting fitFcn’s Covariance matrix

 TFitResultPtr r = hist4260->Fit("fitFcn", "S"); 
fitFcn->IntegralError(3.04,3.17,r->GetParams(), r->GetCovarianceMatrix()->GetMatrixArray() );

But how can I extract now SignalFcn’s covariance Matrix ?

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