Chi square problems of fit when using ROOT

Hi everyone,
I am a Ph.D student. Now, I am trying to use ROOT to get some fit results,
but meet some problems. Please see the following two script at first:

//1. fitWithError.C
Double_t fitf(Double_t *x, Double_t *par)
{
Double_t fitval = par[0]*log( par[1] + par[2]*x[0] );
return fitval;
}
fitWithError(){
//
gROOT->Reset();
gStyle->SetCanvasColor(10);
gStyle->SetFillColor(10);
gStyle->SetOptFit(1);

c1 = new TCanvas(“c1”,"",0,0,600,600);

TH1 *hframe = new TH1F(“hframe”,"",1000,1.0,13);
hframe->SetMinimum(1.9);
hframe->SetMaximum(8.5);
hframe->SetDirectory(0);
hframe->SetStats(0);
hframe->GetXaxis()->SetTitle(“x”);
hframe->GetXaxis()->SetLabelFont(42);
hframe->GetXaxis()->SetTitleFont(42);
hframe->GetYaxis()->SetTitle(“y”);
hframe->GetYaxis()->SetLabelFont(42);
hframe->GetYaxis()->SetTitleFont(42);
hframe->GetYaxis()->CenterTitle(true);
hframe->Draw(“a”);

gPad->SetTicks(1,1);

const int nn = 6;

float x[nn] = {2,4,6,8,10,12};
float ex[nn]; for(int i=0;i<nn;i++) ex[i]=0.;

float y_N1[nn] = {2.71741,4.85521,6.068,6.71725,7.13693,
7.40361};
float ey_N1[nn]= {3.42184E-02 ,1.81865E-02 ,1.33356E-02 ,1.64314E-02 ,
2.30712E-02 ,3.68906E-02};

gr = new TGraphErrors(nn,x,y_N1,ex,ey_N1);
gr->SetMarkerStyle(20);
gr->SetMarkerSize(1.5);
gr->Draw(“P”);

//fit

TF1 *func = new TF1(“fitf”,fitf,2,12,3);
double vall[3]={1.99208,-4.41899,4.12568};
func->SetParameters(vall[0],vall[1],vall[2]);
gr->Fit(“fitf”,“R”);

c1->Update();
}

// 2. fitWithoutError.C
Double_t fitf(Double_t *x, Double_t *par)
{
Double_t fitval = par[0]*log( par[1] + par[2]*x[0] );
return fitval;
}
fitWithoutError(){
//
gROOT->Reset();
gStyle->SetCanvasColor(10);
gStyle->SetFillColor(10);
gStyle->SetOptFit(1);

c1 = new TCanvas(“c1”,"",0,0,600,600);

TH1 *hframe = new TH1F(“hframe”,"",1000,1.0,13);
hframe->SetMinimum(1.9);
hframe->SetMaximum(8.5);
hframe->SetDirectory(0);
hframe->SetStats(0);
hframe->GetXaxis()->SetTitle(“x”);
hframe->GetXaxis()->SetLabelFont(42);
hframe->GetXaxis()->SetTitleFont(42);
hframe->GetYaxis()->SetTitle(“y”);
hframe->GetYaxis()->SetLabelFont(42);
hframe->GetYaxis()->SetTitleFont(42);
hframe->GetYaxis()->CenterTitle(true);
hframe->Draw(“a”);

gPad->SetTicks(1,1);

const int nn = 6;

float x[nn] = {2,4,6,8,10,12};
float ex[nn]; for(int i=0;i<nn;i++) ex[i]=0.;

float y_N1[nn] = {2.71741,4.85521,6.068,6.71725,7.13693,
7.40361};
float ey_N1[nn]= {3.42184E-02 ,1.81865E-02 ,1.33356E-02 ,1.64314E-02 ,
2.30712E-02 ,3.68906E-02};

gr = new TGraph(nn,x,y_N1);
gr->SetMarkerStyle(20);
gr->SetMarkerSize(1.5);
gr->Draw(“P”);

//fit

TF1 *func = new TF1(“fitf”,fitf,2,12,3);
double vall[3]={1.99208,-4.41899,4.12568};
func->SetParameters(vall[0],vall[1],vall[2]);
gr->Fit(“fitf”,“R”);

c1->Update();
}

If you run the above two script, the two method will give two different fit
results: fitWithError will give large chi square but small errors of the 3
parameters; while fitWithoutError will give small chi square but large errors of the parameters.
From my knowledge, I know the large chi square of fitWithError come from the small errors of the dots. But it seems that fitWithoutError will assign the errors of every dots to 1 when calculating the chi squres.

Then, which one is correct and should I choose?

Thanks very much for your helps!

Best regards,
Zhiming

You definetely have to use TGraphWithErrors()
which is in first script.

I think your errors are not estimated properly. From spread of points and therefore quite high Chisq it is obvious that errors must be larger than what you have in right now. Perhaps you have forgotten to include some other errors from measurement of those points.

You probably know that ideally you should get chisq = 1.

High chisq means bad choice of fitting function or wrong estimate of errors.

If you know that the function is the one you have to use then look for uncovered errors.

Thanks very much for your advices!
I think I may take some time to check the errors!