TCanvas *myc = new TCanvas("myc", "Confidence intervals on the fitted function",1000, 500); myc->Divide(3,1); int ngr = 100; TGraph *gr = new TGraph(ngr); gr->SetName("GraphNoError"); double x, y; int i; for (i=0; iUniform(-1, 1); y = -1 + 2*x + gRandom->Gaus(0, 1); gr->SetPoint(i, x, y); } TF1 *fpol = new TF1("fpol", "pol1", -1, 1); fpol->SetLineWidth(2); gr->Fit(fpol, "Q"); /*Create a TGraphErrors to hold the confidence intervals*/ TGraphErrors *grint = new TGraphErrors(ngr); grint->SetTitle("Fitted line with .95 conf. band"); for (i=0; iSetPoint(i, gr->GetX()[i], 0); /*Compute the confidence intervals at the x points of the created graph*/ (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint); myc->cd(1); grint->SetLineColor(kRed); grint->Draw("ap"); gr->SetMarkerStyle(5); gr->SetMarkerSize(0.7); gr->Draw("psame"); myc->cd(2); int nh=5000; TH1D *h = new TH1D("h", "Fitted Gaussian with .95 conf.band", 100, -3, 3); h->FillRandom("gaus", nh); TF1 *f = new TF1("fgaus", "gaus", -3, 3); f->SetLineWidth(2); h->Fit(f, "Q"); h->Draw(); /*Create a histogram to hold the confidence intervals*/ TH1D *hint = new TH1D("hint", "Fitted Gaussian with .95 conf.band", 100, -3, 3); (TVirtualFitter::GetFitter())->GetConfidenceIntervals(hint); hint->SetStats(false); hint->SetFillColor(2); hint->Draw("e3 same"); int ngr2 = 100; double z, rnd, e=0.3; TGraph2D *gr2 = new TGraph2D(ngr2); gr2->SetName("Graph2DNoError"); TF2 *f2 = new TF2("f2", "1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+250",-6,6,-6,6); f2->SetParameters(1,1); for (i=0; iGetRandom2(x,y); // Generate a random number in [-e,e] rnd = 2*gRandom->Rndm()*e-e; z = f2->Eval(x,y)*(1+rnd); gr2->SetPoint(i,x,y,z); } TGraph2DErrors *grint2 = new TGraph2DErrors(ngr2); for (i=0; iSetPoint(i, gr2->GetX()[i], gr2->GetY()[i], 0); f2->SetParameters(0.5,1.5); gr2->Fit(f2, "Q"); /*Compute the confidence intervals*/ (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint2); myc->cd(3); f2->SetNpx(30); f2->SetNpy(30); f2->SetFillColor(kBlue); f2->Draw("surf4"); grint2->SetNpx(20); grint2->SetNpy(20); grint2->SetMarkerStyle(24); grint2->SetMarkerSize(0.7); grint2->SetMarkerColor(kRed); grint2->SetLineColor(kRed); grint2->Draw("E0 same"); grint2->SetTitle("Fitted 2d function with .95 error bars"); myc->cd(); gROOT->GetListOfCanvases()->Draw()