Problems with fitting

I have a problem with the fitting of histograms. I’m trying to fit a function with four peaks. I’m first fitting each peak on its own (from the biggest peak to the smallest peak), which works just fine. Then I’m fitting all peaks together, but for some reason the positions of the peaks seem to be fixed. The code I’m using is:
//fit all
for(i = 0; i < npar; i++)
fitfun->ReleaseParameter(i);
fitfun->SetParLimits(0, 0.3, 1.);
fitfun->SetParLimits(1, 0, 0.3);
fitfun->SetParLimits(2, 0.1, 2);
fitfun->SetParLimits(3, 0., 1.);
fitfun->SetParLimits(4, min_area1, MAX_HEIGHT);
fitfun->SetParLimits(5, par[5]-par[0], par[5]-par[0]);
fitfun->SetParLimits(6, min_area2, MAX_HEIGHT);
fitfun->SetParLimits(7, par[7]-par[0], par[7]-par[0]);
fitfun->SetParLimits(8, min_area3, MAX_HEIGHT);
fitfun->SetParLimits(9, par[9]-par[0], par[9]-par[0]);
fitfun->SetParLimits(10, min_area4, MAX_HEIGHT);
fitfun->SetParLimits(11, par[11]-par[12], par[11]+par[12]);
fitfun->SetParLimits(12, 0.3, 2.);
if(noBG == 0)
{
fitfun->SetParLimits(13, -1, 1);
fitfun->SetParLimits(14, -10, 10);
}
else
{
fitfun->FixParameter(13, 0);
fitfun->FixParameter(14, 0);
}

cout << "fitrange: " << fit_low << " to " << fit_high << endl;

strncat(fit_option, “EM+”, 3);
spec->Fit(“fitfun”, fit_option);

cout << "Reduced chisquare: " << fitfun->GetChisquare()/fitfun->GetNDF() << endl;

But the output I get from that fit is:
fitrange: 15 to 36
FUNCTION MUST BE MINIMIZED BEFORE CALLING MINOs
FCN=9610.2 FROM MINOS STATUS=SUCCESSFUL 811 CALLS 3236 TOTAL
EDM=9.3054e-11 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 0.0 per cent
EXT PARAMETER PARABOLIC MINOS ERRORS
NO. NAME VALUE ERROR NEGATIVE POSITIVE
1 sigma 4.95233e-01 5.47521e-04 -5.47397e-04 5.47415e-04
2 tail_p 1.10286e-01 6.97767e-04 -6.95647e-04 7.00299e-04
3 lambda 5.86322e-01 1.75460e-03 -1.74958e-03 1.75759e-03
4 eta 9.15934e-15 8.03051e-04 at limit 7.91812e-04
WARNING - - ABOVE PARAMETER IS AT LIMIT.
5 area1 1.54257e+05 2.37005e+02 -2.37126e+02 2.37012e+02
6 pos1 2.51090e+01 fixed
7 area2 2.64175e+04 7.00969e+01 -7.01057e+01 7.01381e+01
8 pos2 2.83014e+01 fixed
9 area3 9.08989e+03 9.68000e+01 -9.69685e+01 9.66195e+01
10 pos3 3.06232e+01 fixed
11 p10 9.38471e+04 1.63894e+02 -1.63810e+02 1.63964e+02
12 p11 3.27401e+01 2.68210e-03 -2.68502e-03 2.67574e-03
13 p12 1.10088e+00 1.89021e-03 -1.88651e-03 1.89204e-03
14 p13 0.00000e+00 fixed
15 p14 0.00000e+00 fixed
Reduced chisquare: 101.16

The last two parameters are supposed to be fixed (noBG is 1), but the positions of the peaks were released, so why do they appear to be fixed??

could you send the shortest possible running script showing your problem?

Rene

The files fitfunction.cc and .hh provide the fitfunction, which is used by test_fitfunction.cc.
test_fitfunction.c (625 Bytes)
fitfunction.h (946 Bytes)
fitfunction.c (24.9 KB)

In your code you are fixing 3 parameters with your statements:

fitfun->SetParLimits(5, par[5]-par[0], par[5]-par[0]); fitfun->SetParLimits(7, par[7]-par[0], par[7]-par[0]); fitfun->SetParLimits(9, par[9]-par[0], par[9]-par[0]);

Rene

Thanks for catching that error, sometimes one can’t see the most obvious things. I’ve never looked for an error like that because I didn’t know that root is so intelligent that it knows that a parameter who’s upper and lower limit are the same is actually fixed.