Fit with unsymmetrical gauss function

Hallo!
I have to fit some peaks with a gauss function on quadratic background, so I’ve defined:

Double_t gaus_lau (Double_t *x, Double_t *par)

{

  Double_t pi = 3.1415926535;

  Double_t xx =x[0];

  return par[2]*exp(-(pow(((xx-par[0])/par[1]),2))/2) + par[3] + par[4]*xx + par[5] * xx * xx;

}

The problem now is that these peaks have a tail on one side, so I would like to use an unsymmetrical function…something like a gauss function with 2 different FWHM…but I don’t know how to do this :blush:
can you help me? Thank you!

Hi Laly86,

Try something along the following lines:

Double_t gaus_lau (Double_t *x, Double_t *par) 
{ 
  static Double_t pi = 3.1415926535; 

  const Double_t xx =x[0]; 

  const Double_t width = (xx > par[0]) ? par[1] : par[2];
  const Double_t arg    = pow(((xx-par[0])/width),2);
  const Double_t ampl  = par[3];

  return ampl*exp(-arg/2) + par[4] + xx*(par[5] + xx * par[6]); 
}

Hi,

Actually FWHM is proportional to sigma ( par[1] in your function ).
It is needed to add another parameter, since you have two sigmas.
In the following there is an example how to that,.
Maybe there are simpler ways also, but I don’t know…

#include <TF1.h>

double Gaus_2sigma( double *, double* );

void Gaus_2sigmas()
{
  
  TF1 *f_Gaus_2sigma = new TF1("f_Gaus_2sigma", Gaus_2sigma, -5, 5, 7 );
  f_Gaus_2sigma->SetParameters(100, 0, 0.5, 1.5, 0, 0, 0);
  f_Gaus_2sigma->Draw();

}

double Gaus_2sigma( double *x, double*par )
{
  double xx = x[0];
  double height = par[0];
  double mean = par[1];
  double sigma_1 = par[2];
  double sigma_2 = par[3];
  
  double Pol = par[4] + xx*(par[5] + xx*par[6] );
  
  if( xx < mean ) 
    {
      return Pol + height*exp( -(xx - mean)*(xx - mean)/(2*sigma_1*sigma_1) );
    }
  else
    {
      return Pol + height*exp( -(xx - mean)*(xx - mean)/(2*sigma_2*sigma_2) );
    }
}

I’ve tried your functions, they’re both perfect for my fit! 8)
Thank you very much! :smiley: