Sure, here’s the example. I add also a few questions about my problem:
I have these 3 functions, the first, the second, and the third is the sum of the 1st and the 2nd. With the 3rd function I have to fit an histogram.
TF1* FunzNo = new TF1(“FunzNo”, FunzNo, 30, 110,
;
TF1* FunzFirst = new TF1(“FunzFirst”, FunzFirst, 110, 170,
;
TF1* FunzTot = new TF1(“FunzTot”, “FunzNo+FunzFirst”, 30, 170,
;
The 1st and the 2nd functions are created in a separate file.h, in particular:
double FunzFirst (double* x, double* params) {
unsigned n_pts1 = nc14_1st;
double q = x[0];
double de = (2c14_spectrum_endpoint - 2c14_spectrum_startpoint)/(2nc14 -1);
if (n_pts3 % 2 == 0) n_pts1–;
double result = 0;
for (unsigned i = 0; i < n_pts1; i++) {
double energy = dei;
int factor = ((i % 2) ? 4:2);
if (i == 0 || i + 1 == n_pts1) factor = 1;
result += factor*(c14_energy_spectrum_1st[i]*response_function(q, energy, params));
} result = de/3;
return resultparams[8]*params[5]/c14_spectrum_norm + params[6];
}
The same for the 1st function. So I have to pass to the functions some parameters, from 0 to 8, which are physics stuffs. So I have to set the parameters:
FunzFirst->SetParameter(0, 0);
FunzFirst->SetParameter(1, 0.463);
FunzFirst->SetParameter(2, 0.01);
FunzFirst->SetParLimits(3, 0, 1);
FunzFirst->SetParameter(4, 0.002);
FunzFirst->SetParameter(5, hist->Integral(30,110));
FunzFirst->FixParameter(6, hist->GetBinWidth(1));
FunzFirst->SetParameter(7, 0.1);
FunzFirst->SetParameter(8, hist->Integral(110,170));
for FunzNo, FunzFirst and FunzTot?
Then I fit with:
hist->Fit(FuncTot, “RV”);
But the result is no function on the histogram.