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[0];
  double halfwidth = par[1];
  if( x[0]>dxmean-halfwidth && x[0]<dxmean+halfwidth )
    {
      result = 1;
    }

  else result = 0;

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

  return result;
}

double Func_2(double *x, double *par)
{
  double result;
  double norm = par[0];
  double sigma = par[1];

  double x0 = (x[0])/sigma;


      result = norm*exp(-0.5*x0*x0);
 
  f_12->FixParameter(2,par[0]);
  f_12->SetParameter(1,par[1]);
  return result;
}

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

  return f1->Eval(x[0])*f2->Eval( par[4]-x[0] );

}

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

   double mean = par[0];
   double sigma = par[1];
   double normal = par[2];
   double stepwidth = par[3];



   ROOT::Math::IntegratorOneDim ig(ROOT::Math::IntegrationOneDim::kADAPTIVE);

  ig.SetFunction(*f_12);

  return ig.Integral(-5000,5000);
}

HI,

For the convolution we have a class in ROOT doing it, Tf1Convolution. You can see the tutorial,
tutorials/fit/fitConvolution.C

See root.cern.ch/doc/master/fitConvolution_8C.html

Lorenzo