# Fitting gaussian with polynomial

Greeting Root’rs

I am attempting to fit a spectrum with a gaussian and polynomial.

``````TF1 *fitter = new TF1("fitter","gaus + [3] + [4]*x + [5]*x*x + [6]*x*x*x", 0.98, 1.02);
fitter->SetParName(0, "Norm");
fitter->SetParName(1, "Factor");
fitter->SetParName(2, "#sigma");
fitter->SetParName(3, "const term");
fitter->SetParName(4, "linear term");
fitter->SetParName(6, "cube term");
fitter->SetParameters(24000, 1., 0.01, -1.5, 0, 100, 100);

fitter->SetParLimits(0,10000,80000);
fitter->SetParLimits(1,0.98,1.02);
fitter->SetParLimits(2,0.1,0.001);
h1->Fit("fitter","R")[/code]

As you can see from the code above, I give the sigma value a limit to fit to, however when I look at the output of the fit, the value of sigma is fixed (see below)
[code] NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Norm         6.36342e+04   3.34150e+02   1.23749e-05  -4.93590e-02
2  Factor       1.00673e+00   3.35716e-05   8.37694e-06   4.28272e-01
3  #sigma       1.00000e-02     fixed
4  const term   1.45214e+05   3.10270e+03   5.25546e+00   2.60649e-07
5  linear term   4.90880e+04   1.04364e+03   1.80099e+00  -3.57208e-06
6  quad term   -4.92793e+04   1.06804e+03  -1.74130e+00  -3.53123e-06
7  cube term   -1.49985e+05   3.22557e+03  -5.36773e+00   2.07391e-07``````

So to debug this, I fit just just the gaussian part

``````TF1 *fitter = new TF1("fitter","gaus", 0.985, 1.02);
fitter->SetParName(0, "Norm");
fitter->SetParName(1, "Factor");
fitter->SetParName(2, "#sigma");

fitter->SetParameters(24000, 1., 0.01);
fitter->SetParLimits(0,10000,80000);
fitter->SetParLimits(1,0.98,1.02);
fitter->SetParLimits(2,0.1,0.001);
h1->Fit("fitter","R")[/code]

As you can see from above, its the same code without the polynomial term and I get an "unfixed" sigma

[code] NO.   NAME      VALUE            ERROR          SIZE      DERIVATIVE
1  Norm         5.44251e+04   1.34820e+02   5.95872e-05  -2.17868e-02
2  Factor       1.00509e+00   2.11097e-05   2.15343e-05  -4.61512e-01
3  #sigma       9.56520e-03   2.28368e-05   1.27431e-05   6.64344e-01``````

So how can I let the sigma vary with a gaussian and polynomial?

Thanks

Michael

You have put wrong limits to sigma. The minimum value is greater than the max, for this reason is considered fixed

Best Regards

Lorenzo

Thanks