// -------- ROOT Macro chi2PDF ------------------- // Description: plot chi2 distribution // Author: G. Quast, Dec. 2013 // last modified: // // dependencies: ROOT //------------------------------------------------ #ifndef __CINT__ #include #include #endif Double_t chi2(Double_t *x, Double_t *par) // chi2 pdf { return ROOT::Math::chisquared_pdf(x[0],par[0],par[1]); } Double_t chi2F(Double_t *x, Double_t *par) //chi2 cumulative distribution function { return ROOT::Math::chisquared_cdf(x[0],par[0],par[1]); } Double_t chi2P(Double_t *x, Double_t *par) //chi2 probability { return 1.-ROOT::Math::chisquared_cdf(x[0],par[0],par[1]); } Double_t chi2n(Double_t *x, Double_t *par) // normalized chi2 pdf (chi2/ndf) { return ROOT::Math::chisquared_pdf(x[0]*par[0],par[0],par[1])*par[0]; } Double_t chi2Fn(Double_t *x, Double_t *par) //normalized chi2 cumulative distribution function { return ROOT::Math::chisquared_cdf(x[0]*par[0],par[0],par[1]); } Double_t chi2Pn(Double_t *x, Double_t *par) //normalized chi2, probability { return 1.-ROOT::Math::chisquared_cdf(x[0]*par[0],par[0],par[1]); } void chi2Prob() { TF1 *Fchi2 = new TF1("chi2",chi2, 0.,12.,200); TF1 *Fchi2F = new TF1("chi2F",chi2F, 0.,25.,200); TF1 *Fchi2P = new TF1("chi2P",chi2P, 0.,25.,200); TF1 *Fchi2n = new TF1("chi2n",chi2n, 0.,4.,200); TF1 *Fchi2Fn = new TF1("chi2Fn",chi2Fn, 0.,5.,200); TF1 *Fchi2Pn = new TF1("chi2Pn",chi2Pn, 0.,5.,200); // make a white canvas without borders TCanvas *c1 = new TCanvas("c1", "c1", 0, 0, 700, 500); c1->SetFillColor(0); c1->SetBorderMode(0); c1->SetBorderSize(0); c1->SetGridx(); c1->SetGridy(); c1->SetFrameBorderMode(0); c1->cd(); gStyle->SetOptTitle(0); // plot one of these functions for different n_f //TF1 *Func = Fchi2; TF1 *Func = Fchi2P; Func->SetParameter(1,0); Func->SetParameter(0,2); Func->SetLineColor(kWhite); Func->SetTitle("#chi^{2} Verteilung;#chi^{2}; P-value"); Func->DrawCopy(); TLegend* legend = new TLegend(0.79, 0.28, 0.87, 0.88); char title[20]; TObject* copied; int ndf=1; for (int ils=1; ils<4; ils++) { for (int ilc=1; ilc<8; ilc++) { Func->SetLineStyle(ils); Func->SetLineColor(ilc); ndf=ndf+1; Func->SetParameter(0,ndf); Func->DrawCopy("same"); sprintf(title, "n_{f} = %2i", ndf); copied = Func->DrawCopy("same"); legend->AddEntry(copied, title); } } legend->Draw(); }