Hi all,
I am new to ROOT and need help so please accept my apologies for asking this question. I have looked forum and documents some but do not understand what I am doing wrong.
I am trying to fit a linear function to a few points and the fit looks really strange. I need error bars on the fit parameters. I tried the TGraphError->LeastSquareFit but I don;t know how to access the errors on fit parameters. What is the best way to do it and what am I doing wrong? Here is a sample script:
{
// create a simple TGraphErrors and make a linear fit on a portion
// of the graph.
const Int_t n = 24;
Double_t x[n] = {1337227380.0000, 1337227650.0000, 1337227950.0000, 1337228190.0000, 1337228580.0000, 1337228850.0000, 1337229180.0000, 1337229510.0000, 1337229780.0000, 1337230050.0000, 1337230380.0000, 1337230710.0000, 1337230980.0000, 1337231250.0000, 1337231670.0000, 1337231940.0000, 1337232180.0000, 1337232510.0000, 1337232780.0000, 1337233080.0000, 1337233350.0000, 1337233650.0000, 1337233980.0000, 1337234280.0000};
Double_t y[n] = {0.000459, 0.000524, 0.000151, 0.000715, 0.000311, 0.000788, 0.00213, 0.00141, 0.00165, 0.00159, 0.00328, 0.0067, 0.00687, 0.0164, 0.0281, 0.00529, 0.00927, 0.0621, 0.043, 0.0784, 0.167, 0.214, 0.163, 0.191};
Double_t dy[n] = {0.000265, 0.000302, 0.000151, 0.000413, 0.00022, 0.000353, 0.000614, 0.000498, 0.000549, 0.000531, 0.000669, 0.00113, 0.00111, 0.00177, 0.00273, 0.00121, 0.00132, 0.00426, 0.00251, 0.00384, 0.00613, 0.00717, 0.00502, 0.00647};
Double_t dx[n] = {4.0000, 5.0000, 5.0000, 3.0000, 4.0000, 5.0000, 6.0000, 5.0000, 4.0000, 5.0000, 6.0000, 5.0000, 4.0000, 5.0000, 3.0000, 4.0000, 4.0000, 3.0000, 6.0000, 4.0000, 5.0000, 5.0000, 6.0000, 4.0000};
TGraphErrors * graphE = new TGraphErrors(n, x, y, dx, dy);
graphE->SetTitle("Two linear fits");
graphE->GetXaxis()->SetTitle("some x values");
graphE->GetYaxis()->SetTitle("some y values");
graphE->Draw("ALP");
//gPad->SetLogy();
// define a linear function and fit in a range
TF1* myF = new TF1("myF", "[0]+[1]*x", 1337231670.0000, 1337233650.0000);
Double_t myFPar[2];
Double_t myFParEr[2];
myF->SetLineColor(2);
graphE->Fit(myF, "R");
myF->GetParameters(&myFPar[0]);
myFParEr[0]=myF->GetParError(0);
myFParEr[1]=myF->GetParError(1);
}
Thank you.