ROOT Version: 6.24/06
Platform: CentOS Linux release 7.9.2009
Compiler: c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Hello everyone,
I am trying to perform a convolution of two functions (a Gaussian and a difference of two exponentials) in order to fit a signal pulse, using the fitConvolution.C macro provided on the ROOT website. I have checked in advance that the resulting function should roughly correspond to the shape of the pulse (it is similar to a Landau function). However, when I try to perform the fit, it does not work properly, the parameters are not in the expected region and very sensitive to the initial parameters that I provide with f->SetParameters()
. Please find a working code and its output below. Any help would be appreciated. Thanks a lot in advance.
void doubleExpWithGauss() {
std::vector<double> xvals = {4490.0, 4510.0, 4530.0, 4550.0, 4570.0, 4590.0, 4610.0, 4630.0, 4650.0, 4670.0, 4690.0, 4710.0, 4730.0, 4750.0, 4770.0, 4790.0, 4810.0};
std::vector<double> yvals = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 22.0, 140.0, 114.0, 88.0, 45.0, 30.0, 19.0, 10.0, 2.0, 2.0, 1.0};
int nbins = xvals.size();
double minval = *min_element(xvals.begin(), xvals.end());
double maxval = *max_element(xvals.begin(), xvals.end());
TH1F* h_testpulse = new TH1F("h_testpulse", "h_testpulse", nbins, minval-4630., maxval-4630);
for(int i = 1; i<=nbins; i++){
h_testpulse->SetBinContent(i, yvals[i]);
}
TF1Convolution *f_conv = new TF1Convolution("[0]*exp(-x/[1])-[2]*exp(-x/[3])", "[0]*exp(-(x)^2/[1]^2)", -50, 150, true);
f_conv->SetRange(-50., 150.);
f_conv->SetNofPointsFFT(1000);
TF1 *f = new TF1("f", *f_conv, -50., 150., f_conv->GetNpar());
f->SetParameters(62., 33., -0.7, 587369., 4., 12.8);
// Fit.
TCanvas * c = new TCanvas("c", "c", 800, 1000);
c->cd();
h_testpulse->Fit("f");
h_testpulse->Draw();
c->SaveAs("test.png");
}
Terminal output and fit parameters:
Warning in <Fit>: Abnormal termination of minimization.
FCN=47.6168 FROM MIGRAD STATUS=CALL LIMIT 1786 CALLS 1787 TOTAL
EDM=0.57082 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 8.2 per cent
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 5.82308e+01 7.21549e+00 3.51843e+00 4.20810e+00
2 p1 1.79265e+01 1.20824e+00 5.84075e-01 -3.47100e+01
3 p2 1.82196e+02 1.79801e+01 -5.62074e+00 -1.27555e+00
4 p3 3.53917e+01 2.12068e+00 -3.41671e-01 7.90901e+00
5 p4 -2.67664e-02 5.38028e-03 -2.64889e-03 -4.72243e+02
6 p5 -1.80632e+01 1.27075e+00 -1.46511e-01 2.04649e+00
Plot: