void chi2_fit() { TH1* h = new TH1F( "h", "#chi^{2}-Anpassung", 5, 0, 5 ); h->SetStats( kFALSE ); gStyle->SetOptFit(1111); h->SetMaximum( 3 ); h->Draw(); const UInt_t N = 3; double x[N] = { 1, 3, 4 }; double y[N] = { 0.8, 1.8, 2.2 }; //double e[N] = { 0.1, 0.2, 0.1 }; // double e[N] = { 0.04, 0.06, 0.02 }; //double e[N] = { 0.0, 0.0, 0.0 }; double e[N] = { 1.0, 1.0, 1.0 }; TGraphErrors* g = new TGraphErrors( N, x, y, 0, e ); g->SetMarkerStyle( 20 ); g->SetMarkerSize( 1 ); g->Draw( "p" ); TF1* f1 = new TF1( "f1", "pol1", 0, 5 ); TF1* f2 = new TF1( "f2", "[0]+[1]*x", 0, 5 ); TF1* f3 = new TF1( "f3", straightline, 0, 5, 2 ); g->Fit( "pol1" ); g->Fit( "f1" ); g->Fit( "f2" ); g->Fit( "f3" ); } double straightline( double* x, double* par ) { return par[0] + par[1]*x[0]; }