21 void ConfidenceIntervals()
23 TCanvas *myc =
new TCanvas(
"myc",
24 "Confidence intervals on the fitted function",1200, 500);
30 TGraph *gr =
new TGraph(ngr);
31 gr->SetName(
"GraphNoError");
34 for (i=0; i<ngr; i++){
35 x = gRandom->Uniform(-1, 1);
36 y = -1 + 2*x + gRandom->Gaus(0, 1);
37 gr->SetPoint(i, x, y);
40 TF1 *fpol =
new TF1(
"fpol",
"pol1", -1, 1);
41 fpol->SetLineWidth(2);
45 TGraphErrors *grint =
new TGraphErrors(ngr);
46 grint->SetTitle(
"Fitted line with .95 conf. band");
48 grint->SetPoint(i, gr->GetX()[i], 0);
50 (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint);
55 grint->SetLineColor(kRed);
57 gr->SetMarkerStyle(5);
58 gr->SetMarkerSize(0.7);
65 TH1D *h =
new TH1D(
"h",
66 "Fitted gaussian with .95 conf.band", 100, -3, 3);
67 h->FillRandom(
"gaus", nh);
68 TF1 *f =
new TF1(
"fgaus",
"gaus", -3, 3);
74 TH1D *hint =
new TH1D(
"hint",
75 "Fitted gaussian with .95 conf.band", 100, -3, 3);
76 (TVirtualFitter::GetFitter())->GetConfidenceIntervals(hint);
79 hint->SetStats(kFALSE);
80 hint->SetFillColor(2);
81 hint->Draw(
"e3 same");
86 Double_t z, rnd, e=0.3;
87 TGraph2D *gr2 =
new TGraph2D(ngr2);
88 gr2->SetName(
"Graph2DNoError");
89 TF2 *f2 =
new TF2(
"f2",
90 "1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+250",-6,6,-6,6);
91 f2->SetParameters(1,1);
92 for (i=0; i<ngr2; i++){
95 rnd = 2*gRandom->Rndm()*e-e;
96 z = f2->Eval(x,y)*(1+rnd);
97 gr2->SetPoint(i,x,y,z);
100 TGraph2DErrors *grint2 =
new TGraph2DErrors(ngr2);
101 for (i=0; i<ngr2; i++)
102 grint2->SetPoint(i, gr2->GetX()[i], gr2->GetY()[i], 0);
105 f2->SetParameters(0.5,1.5);
108 (TVirtualFitter::GetFitter())->GetConfidenceIntervals(grint2);
115 f2->SetFillColor(kBlue);
119 grint2->SetMarkerStyle(24);
120 grint2->SetMarkerSize(0.7);
121 grint2->SetMarkerColor(kRed);
122 grint2->SetLineColor(kRed);
123 grint2->Draw(
"E0 same");
124 grint2->SetTitle(
"Fitted 2d function with .95 error bars");