#include "TFile.h" #include "TGraphErrors.h" #include "TF1.h" #include "TVirtualFitter.h" #include "TCanvas.h" #include "TStyle.h" void test_confidenceIntervals(){ gROOT->SetStyle("Plain"); gStyle->SetOptFit(111111); TCanvas *can = new TCanvas("can", "can", 800, 600); //data to build a TGraphErros double x[21], y[21], ex[21], ey[21]; x[0]=8; y[0]=1.67506; ex[0]=0; ey[0]=0.145915; x[1]=10; y[1]=1.29694; ex[1]=0; ey[1]=0.0440371; x[2]=12; y[2]=1.22618; ex[2]=0; ey[2]=0.0500436; x[3]=14; y[3]=1.11704; ex[3]=0; ey[3]=0.0318592; x[4]=16; y[4]=1.08951; ex[4]=0; ey[4]=0.0316879; x[5]=18; y[5]=1.13821; ex[5]=0; ey[5]=0.0339264; x[6]=20; y[6]=1.08974; ex[6]=0; ey[6]=0.0254162; x[7]=22; y[7]=1.10829; ex[7]=0; ey[7]=0.027147; x[8]=24; y[8]=1.01716; ex[8]=0; ey[8]=0.00351731; x[9]=26; y[9]=1.02074; ex[9]=0; ey[9]=0.00265809; x[10]=28; y[10]=1.02534; ex[10]=0; ey[10]=0.00296933; x[11]=30; y[11]=1.0209; ex[11]=0; ey[11]=0.00334639; x[12]=32; y[12]=1.00721; ex[12]=0; ey[12]=0.00353621; x[13]=34; y[13]=1.01081; ex[13]=0; ey[13]=0.00371931; x[14]=36; y[14]=1.00884; ex[14]=0; ey[14]=0.00399801; x[15]=38; y[15]=1.02371; ex[15]=0; ey[15]=0.00522067; x[16]=40; y[16]=1.00065; ex[16]=0; ey[16]=0.00482257; x[17]=42; y[17]=1.00661; ex[17]=0; ey[17]=0.005707; x[18]=44; y[18]=1.02457; ex[18]=0; ey[18]=0.00665586; x[19]=46; y[19]=0.990207; ex[19]=0; ey[19]=0.00762263; x[20]=48; y[20]=1.02183; ex[20]=0; ey[20]=0.00953737; //create a TGraphErros TGraphErrors *g = new TGraphErrors(21, x, y, ex, ey); g->SetMarkerStyle(22); g->SetMarkerColor(kRed); g->SetLineColor(kRed); //fitting function used. TF1 * fRbiasETj = new TF1("fRbiasETj", "[0]+exp([1]+[2]*x)", 6, 35); fRbiasETj->SetNpx(10000); /*************************/ //Question: //If commenting the following 1 lines (e.g. don't fit one parameters), //confidence intervals will be plotted. //If fixing one parameters, no confidence intervals plotted. //Why? fRbiasETj->FixParameter(0, 1.); /**************************/ g->Fit("fRbiasETj", "", "", 5, 50); fRbiasETj->SetNpx(10000); TGraphErrors *gint2 = new TGraphErrors(*g); gint2->SetFillColor(5); (TVirtualFitter::GetFitter())->GetConfidenceIntervals(gint2); g->Draw("AP"); gint2->Draw("e3 same"); g->Draw("P same"); }