Here is a link you answered somebody else before: Integral Error in Signal - #6 by Wile_E_Coyote
Here is the adapted version of YOUR code below to get background:
As you know as soon as you say somewhere “fiz the parameter”, yo -u get ZERO error as normal.
{
60Codata.txt (17.3 KB)
const Bool_t use_partial_covariance = kFALSE; // kFALSE or kTRUE
const char *filename = “60Codata.txt”;
TGraph *g0 = new TGraph(filename, “%lg %lg %*lg”); // X axis = channels
g0->SetTitle(“g0;Channel number;Energy”); // energy calibration
TGraph *g1 = new TGraph(filename, “%lg %*lg %lg”); // X axis = channels
g1->SetTitle(“g1;Channel number;Counts”);
TGraph *g2 = new TGraph(filename, “%*lg %lg %lg”); // X axis = energies
g2->SetTitle(“g2;Energy;Counts”);
if ((g1->GetN() < 2) || (g2->GetN() < 2)) return; // just a precaution
TF1 *fg = new TF1(“fg”, “gaus”);
Double_t sb = 5.0; // sigma band for the fg integral (e.g. 3 or 5 or 7)
TF1 *bcg = new TF1(“bcg”, “pol1”);
Int_t ch_min = 360, ch_max = 460; // “channel numbers”
TF1 *f1 = new TF1(“f1”, “gaus(0) + pol1(3)”, ch_min, ch_max);
f1->SetParameters(30000., 430., 10., 5000., 0.);
f1->FixParameter(3, 5000); //for pol **************************************
f1->FixParameter(4, 0.); //for pol *******************************************
TFitResultPtr r1 = g1->Fit(f1, “WEMRS”);
TMatrixD c1 = r1->GetCovarianceMatrix();
TMatrixD c1g = c1.GetSub(0, 2, 0, 2);
TMatrixD c_bcg = c1.GetSub(3, 4, 3, 4);
Double_t s1, s1e;
fg->SetParameters(f1->GetParameters());
bcg->SetParameters(f1->GetParameters()+3);
// fg->SetParErrors(f1->GetParErrors());
s1 = bcg->Integral(fg->GetParameter(1) - sb * fg->GetParameter(2),
fg->GetParameter(1) + sb * fg->GetParameter(2));
s1e = bcg->IntegralError(fg->GetParameter(1) - sb * fg->GetParameter(2),
fg->GetParameter(1) + sb * fg->GetParameter(2),
bcg->GetParameters(),
c_bcg.GetMatrixArray());
std::cout << "gaus peak integral (mean +/- " << sb << " sigma) = "
<< s1 << " +/- " << s1e << std::endl;
}