# Fitting a histogram with convolved function

Hi,

I am having a problem on fitting. So f1(Func_1) is a step function and f2(Func_2) is a Gaussian. f_12 (Func_12) is the integrand of the convolution, and f_Conv (Conv_12) is convolution.

My objective is that I have some histogram and I want to fit it with f_Conv. With parameters: width of f1, mean of f1, sigma of f2, and normalization of f2.

Any suggestion will be greatly appreciated. Thank you.

Symptom is that f1,f2, and convolution seems fine, but the fitting part does not work.

Part of code:

``````double Func_1(double *x, double *par)
{
double result;
double dxmean = par;
double halfwidth = par;
if( x>dxmean-halfwidth && x<dxmean+halfwidth )
{
result = 1;
}

else result = 0;

f_12->SetParameter(0,par);
f_12->SetParameter(3,2*par);
f_12->FixParameter(1,par);

return result;
}

double Func_2(double *x, double *par)
{
double result;
double norm = par;
double sigma = par;

double x0 = (x)/sigma;

result = norm*exp(-0.5*x0*x0);

f_12->FixParameter(2,par);
f_12->SetParameter(1,par);
return result;
}

double Func_12( double *x, double *par )
{
f1->SetParameter(0,par);
f1->SetParameter(1,0.5*par);
f2->FixParameter(0,par);
f2->SetParameter(1,par);

return f1->Eval(x)*f2->Eval( par-x );

}

double Conv_12( double *x, double *par )
{
f_12->SetParameter(4, x);

double mean = par;
double sigma = par;
double normal = par;
double stepwidth = par;