Pol1 Fitting problem

Hi experts.
I have a problem when i use the pol1 fitter.
I want to fit the three coordinates I entered.
This is the code i used.

double pol1(Double_t *x, Double_t *p);

void fixcal()
{
TCanvas *c = new TCanvas(“c”,“c”,1200,900);
c->SetGrid();
c->GetFrame()->SetFillColor(21);
c->GetFrame()->SetBorderSize(12);

const Int_t n = 3;

Double_t x[n] = {
1.30217e+05,
1.81170e+05,
1.90896e+05
};
Double_t y[n] = {
59.5,
81,
88
};

Double_t ex[n] = {
2.63060e+01,
7.45597e+01,
1.49197e+02
} ;
Double_t ey[n] = {
0,
0,
0
};

TGraphErrors* g = new TGraphErrors(n,x,y,ex,ey);
g->SetMarkerColor(8);
g->SetMarkerStyle(21);
g->Draw(“ALP”);
g->Draw(“same”);

g->GetXaxis()->SetRangeUser(0,2.0e+05);
g->GetYaxis()->SetRangeUser(0,90);

g->GetXaxis()->CenterTitle();
g->GetXaxis()->SetTitle(“ADC”);
g->GetYaxis()->CenterTitle();
g->GetYaxis()->SetTitle(“Energy(keV)”);

TF1 *fit = new TF1(“fit”, pol1, 0, 1.91e+05, 2);
g->Fit(fit,“r”);
fit->SetLineColor(4);
fit->Draw(“same”);

TF1 *cal_am = new TF1(“cal_am”, pol1, 0, 1.91e+05, 2);
cal_am->SetParameters(0, y[0]/x[0]);
cal_am->SetLineColor(2);
cal_am->Draw(“same”);
}

double pol1(Double_t *x, Double_t *p)
{
return p[0]+p[1]*x[0];
}

And the result show’s like this.
Warning in : Abnormal termination of minimization.
FCN=0 FROM MIGRAD STATUS=FAILED 100 CALLS 101 TOTAL
EDM=1.28169e+08 STRATEGY= 1 ERROR MATRIX UNCERTAINTY 100.0 per cent
EXT PARAMETER APPROXIMATE STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 0.00000e+00 1.41421e+00 -0.00000e+00 0.00000e+00
2 p1 0.00000e+00 3.49162e-28 0.00000e+00 -3.24238e+31

How can i solve this problem?


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


In ROOT, before you try to fit your graph or histogram, you MUST set “reasonable” initial values for ALL parameters of your function (except for some “built-in” formulas, like “gaus”, for which the standard fit procedure can automatically “guess” them), otherwise the fitting procedure may easily misbehave.

Setting ey to non-zero values removes the issue

@Eddy_Offermann Modifying “experimental data” is known to work (at least in the short run) in the finance / banking domain but is prohibited in science / engineering.

But even in physics “money supply” is finite and therefore the accompanying data weights too :sunglasses:

In the case here, one will achieve significantly better long-term profits if one invests in learning how to use TF1::SetParameters than when fiddling with the data.

yes missing in action is the line:

fit->SetParameters(0, y[0]/x[0]);

But it would have been better to switch x and y in his code so that it
becomes a true linear fit. Currently the function is linear but projecting
the x error to y makes it non-linear.
And then no initial values are needed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.