// Root macro to plot histogram of q0 and superimpose // the asymptotic half-chi-square pdf. // G. Cowan, RHUL Physics, 8 July 2014 // To execute, run root and type .x plot_q0.C at prompt { gROOT->Reset(); gROOT->LoadMacro("ScaledChi2.C"); TFile* file = new TFile("inv14.root"); TH1D* h = (TH1D*)(file->Get("h_q0")); TCanvas* c = new TCanvas("c", "c",10,10,500,500); c->SetFillColor(0); c->SetBorderMode(0); c->SetFrameBorderMode(0); // need this to turn off red hist frame! gROOT->SetStyle("Plain"); c->UseCurrentStyle(); gPad->SetLeftMargin(0.17); gPad->SetRightMargin(0.05); gPad->SetTopMargin(0.07); gPad->SetBottomMargin(0.17); gStyle->SetOptStat(0); gStyle->SetTitleBorderSize(0); gStyle->SetTitleSize(0.04); gStyle->SetTextFont(42); gStyle->SetTextSize(0.04); gStyle->SetTitleFont(42, "hxy"); // for histogram and axis title gStyle->SetLabelFont(42, "xyz"); // for axis labels (values) gStyle->SetTitleOffset(0.8, "h"); // what does this do? gStyle->SetTitleX(0.15); gStyle->SetTitleY(0.99); gROOT->ForceStyle(); double dx = h->GetBinWidth(1); double nExp = h->GetEntries(); // double rebinFactor=1; // h->Rebin(rebinFactor); // dx *= rebinFactor; double s = 1/(dx*nExp); h->Scale(s); // move content of underflow bin to bin 1 double underflow = h->GetBinContent(0); double bin1 = h->GetBinContent(1); h->SetBinContent(0, 0.); h->SetBinContent(1, bin1+underflow); h->SetTitle(""); h->SetXTitle("q_{0}"); h->SetYTitle("f(q_{0}|0)"); gPad->SetLogx(0); gPad->SetLogy(1); TAxis* xa = h->GetXaxis(); TAxis* ya = h->GetYaxis(); xa->SetTitleOffset(1.3); // factor multiplies default offset ya->SetTitleOffset(1.3); xa->SetLabelOffset(0.015); ya->SetLabelOffset(0.015); xa->SetTitleFont(42); ya->SetTitleFont(42); xa->SetLabelFont(42); ya->SetLabelFont(42); xa->SetTitleSize(0.05); ya->SetTitleSize(0.05); xa->SetLabelSize(0.05); ya->SetLabelSize(0.05); int binLo = h->FindBin(0.); int binHi = h->FindBin(30.); h->GetXaxis()->SetRange(binLo, binHi); h->SetMinimum(5.e-8); h->SetMaximum(5.); h->SetLineStyle(1); h->SetLineWidth(2); h->SetLineColor(kBlack); h->Draw(); // Superimpose half chi-square pdf double w = 0.5; // for half-chi-square TF1* func = new TF1("func", ScaledChi2, 0., 50., 2); func->SetParameter(0,1.0); // degrees of freedom func->SetParameter(1, w); // scale factor func->SetLineStyle(2); func->SetLineWidth(2); func->SetLineColor(kRed); func->Draw("same"); TLatex* tl = new TLatex(); tl->SetTextSize(0.04); tl->SetTextFont(42); tl->SetNDC(true); tl->DrawLatex(.46, .85, "n = 12, #tilde{b} = 6.0, #sigma_{#tilde{b}} = 1.0"); TLegend* leg = new TLegend(0.45, 0.67, .85, .82); // x1, y1, x2, y2 leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetBorderSize(0); leg->SetFillColor(0); leg->AddEntry(h, " toy MC", "l"); leg->AddEntry(func, " asymptotic formula", "l"); leg->Draw(); TPostScript psfile("q0.eps", 113); // 113 makes eps c->Draw(); psfile.Close(); c->Print("q0.gif", "gif"); }