How to get the convolution of self-defined function and gaus

I defined a function and it works when I fit it to the waveforms I got.

Double_t wave_func(Double_t* x, Double_t* par)
{// 4 parameters
	if (x[0] < par[0]) return 0;
	Double_t result = 0;
	Double_t x1 = x[0] - par[0];
	result = TMath::Exp(-x1 / par[2]) - TMath::Exp(-x1 / par[3]);
	result *= par[1];
	return result;
}

Then I want to get the convolution of it and gaus but it doesn’t work.

TF1* myfit = new TF1("myfit", wave_func, 0, 1000, 4);
myfit->SetParameters(300, 3500, 15, 15);
myfit->SetNpx(1000);
TF1Convolution myfit_gaus{"myfit", "gaus", 0, 1000, true};
myfit_gaus.SetRange(0, 1000);
myfit_gaus.SetNofPointsFFT(4000);
TF1* fit = new TF1("myfit_gaus", myfit_gaus, 0, 1000, myfit_gaus.GetNpar());
fit->SetParameters(300, 3500, 15, 15, 0, 5);

I have two questions:

  1. The convolution has 7 parameters instead of 6. I have used the convolution of landau (3 parameters) and gaus and it has 5 parameters. Why it is not 4+2 parameters this time?
  2. I tried to draw it to find out what the 6th parameter is. But something is wrong. I cannot even draw the origin function. What is wrong in my code?
Double_t myfunc(Double_t* x, Double_t* par)
{
	if (x[0] < par[0]) return 0;
	Double_t result = 0;
	Double_t x1 = x[0] - par[0];
	result = TMath::Exp(-x1 / par[2]) - TMath::Exp(-x1 / par[3]);
	result *= par[1];
	return result;
}
void test()
{
	auto myfit = new TF1("myfit", myfunc, 0, 1000, 4);
	myfit->SetParameters(300, 3500, 15, 15);
	myfit->SetNpx(10000);
	myfit->Draw();
}

I think @moneta can give the proper answers to your questions

My mistake. myfit->SetParameters(300, 3500, 15, 15);works well as initial parameters for fit.
But it equals 0 when par[2]==par[3]

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