void tfit() { TFitResultPtr frp(0); int b1 = 1, b2 = 10; auto f1 = new TF1("myfunc", "[0]+[1]*x +[2]*x*x",0, 10); // the following should be equivalent but doesnt work here // auto f1 = new TF1("myfunc", "pol2",0, 10); // f1->SetParameters(1,1,0.1); auto h1 = new TH1F("hh", "hh", 10, 0,10); h1->SetBinContent(b1, 3); // h1->SetBinError(b1, 1); // h1->SetBinContent(b2, 5); // h1->SetBinError(b2, 2); h1->Draw(); // f1->Draw("same"); frp = h1->Fit(f1, "S"); if ( frp >= 0 ) { // TFitResultPtr frp = h1->Fit("myfunc", "S"); frp->Print(); cout << "Fit ok frp = " << (int)frp << endl; } else { cout << "Fit failed frp= " << frp << endl; } }