dear rooters,
using root 5.18 i obseve a very strange problem: i created my own function (see attached MyFitFunction.C):
Double_t MyFitFunction(Double_t* x, Double_t* parameter) {
Double_t funtionValue;
if (x[0] <= 24.77) {
functionValue = parameter[0] +
parameter[1] * x[0] ;
} else {
functionValue = parameter[2] +
parameter[3] * x[0] +
parameter[4] * x[0] * x[0] +
parameter[5] * x[0] * x[0] * x[0] +
parameter[6] * x[0] * x[0] * x[0] * x[0];
}
return functionValue;
}
to fit a histogram (stored in attached test.root) with a root macro (attached fitTest.C):
{
TFile* _file0 = TFile::Open("test.root");
TH1D* ElecERatio = (TH1D*) _file0->Get("ScatElecEnergy");
gInterpreter->Load("MyFitFunction.C");
TF1 FitFunction("myFitFunction",MyFitFunction,10.,30.,7);
FitFunction.SetParameters(1.9223668, -0.04884, 3.998807e+04, -6.356760e+03, 3.790429e+02, -1.004786e+01, 9.991058e-02);
ElecERatio->SetYTitle("data/mc");
ElecERatio->Fit(&myFitFunction);
FitFunction.Draw("same");
}
the fit works fine, but if i run a second script (attached plotTest.C) in which i set the parameters resulting from the fit by hand:
{
gInterpreter->Load("MyFitFunctionForElecERatio.C");
TF1 FitFunction("myFitFunction",MyFitFunction,10.,30.,7);
FitFunction.SetParameters(2.042, -0.05528, 3.998e+04, -6357., 379.1, -10.05, 0.09989);
FitFunction.Draw();
}
the curve looks very, very different from the one resulting from the fit.
does anyone have an idea why this happens?
thanks in advance for help!
cheers,
axel.
test.root (4.33 KB)
plotTest.C (231 Bytes)
fitTest.C (427 Bytes)
MyFitFunction.C (420 Bytes)