void plotCovMatrix(TString file, TString label1, TString label2) { ModTDRStyle(); gStyle->SetPaintTextFormat(".3g"); TFile f(file); TH2D *h_cov1 = (TH2D*)gDirectory->Get(label1+"_h_cov"); TH2D *h_cov2 = (TH2D*)gDirectory->Get(label2+"_h_cov"); TH2D *h_cor1 = (TH2D*)gDirectory->Get(label1+"_h_cor"); TH2D *h_cor2 = (TH2D*)gDirectory->Get(label2+"_h_cor"); // TH2D *h_cov3 = (TH2D*)h_cov1->Clone("syst_h_cov"); // h_cov3->Add(h_cov2, -1); // TH2D *h_cor3 = (TH2D*)h_cov3->Clone("syst_h_cor"); // for (int i = 1; i <= h_cov3->GetNbinsX(); ++i) { // for (int j = 1; j <= h_cov3->GetNbinsY(); ++j) { // int n = h_cov3->GetNbinsX(); // int bx = TranslateToX(i, j, n); // int by = TranslateToY(i, j, n); // h_cor3->SetBinContent(bx, by, h_cov3->GetBinContent(bx, by) / ( // TMath::Sqrt(h_cov3->GetBinContent(TranslateToX(i, i, n), TranslateToY(i, i, n))) // * TMath::Sqrt(h_cov3->GetBinContent(TranslateToX(j, j, n), TranslateToY(j, j, n))))); // } // } drawMatrix(h_cov1, label1+"_cov"); drawMatrix(h_cov2, label2+"_cov"); drawMatrix(h_cor1, label1+"_cor"); drawMatrix(h_cor2, label2+"_cor"); // drawMatrix(h_cov3, "syst_cov"); // drawMatrix(h_cor3, "syst_cor"); printErrors(h_cov1, h_cov2); }
int main() { TH1::AddDirectory(0); ModTDRStyle(); TCanvas* canv = new TCanvas("ma-tanb", "ma-tanb"); std::vector<TPad*> pads = OnePad(); contour2D("higgsCombinemhmax.MultiDimFit.mH120.root", "ma-tanb-contours.root", "mA", 70, 90, 1000, "tanb", 70, 1, 60); TLegend *legend = PositionedLegend(0.20, 0.12, 1, 0.03); drawContours(pads[0], "ma-tanb-contours.root", "m_{A} (GeV)", "tan#beta", legend); legend->Draw(); GetAxisHist(pads[0])->GetXaxis()->SetTitleOffset(1.); DrawCMSLogo(pads[0], "CMS", "Preliminary", 0, 0.045, 0.035, 1.2); DrawTitle(pads[0], "19.7 fb^{-1} (8 TeV) + 4.9 fb^{-1} (7 TeV)", 3); // drawTitle(pads[0], "H#rightarrow#tau#tau", 1); // pads[0]->SetLogx(1); // pads[0]->SetLogy(1); canv->Update(); pads[0]->RedrawAxis(); pads[0]->GetFrame()->Draw(); canv->Print(".pdf"); canv->Print(".png"); return 0; }
int main(int argc, char* argv[]) { Json::Value const js = ch::MergedJson(argc, argv); TH1::AddDirectory(0); ModTDRStyle(); TCanvas canv(js.get("output", "scan").asCString(), ""); std::vector<TPad*> pads = OnePad(); std::vector<TLine *> lines; std::vector<Scan> scans; for (auto it = js["env"].begin(); it != js["env"].end(); ++it) { std::cout << (*it).asString() << "\n"; } std::string xvar = js.get("xvar", "r").asString(); std::string yvar = js.get("yvar", "2. * deltaNLL").asString(); bool re_zero_graphs = js.get("rezero", true).asBool(); double cross = js.get("crossing", 1.0).asFloat(); int precision = js.get("precision", 2).asInt(); std::set<std::string> draw; for (unsigned i = 0; i < js["draw"].size(); ++i) { draw.insert(js["draw"][i].asString()); } for (unsigned i = 0; i < js["scans"].size(); ++i) { Json::Value const sc_js = js["scans"][i]; if (!draw.count(sc_js["label"].asString())) continue; Scan scan; scan.file = sc_js["file"].asString(); scan.tree = sc_js["tree"].asString(); scan.color = sc_js["color"].asInt(); scan.label = sc_js["legend"].asString(); scans.push_back(scan); } if (scans.size() == 0) return 1; TLegend *leg = PositionedLegend(0.4, 0.15 * float(scans.size()) / 1.7, 2, 0.03); leg->SetTextSize(0.035); for (unsigned i = 0; i < scans.size(); ++i) { Scan & sc = scans[i]; TFile f(sc.file.c_str()); TTree *t = static_cast<TTree*>(f.Get(sc.tree.c_str())); sc.gr = new TGraph(TGraphFromTree(t, xvar, yvar)); sc.gr->Sort(); for (int j = 0; j < sc.gr->GetN(); ++j) { if (std::fabs(sc.gr->GetY()[j] - 0.) < 1E-5) sc.bestfit = sc.gr->GetX()[j]; } if (re_zero_graphs) ReZeroTGraph(sc.gr); auto x1 = GetCrossings(*(sc.gr), 1.0); TString res; if (x1.size() == 2) { sc.uncert = (x1[1]-x1[0])/2.0; std::cout << "Best fit is: " << sc.bestfit << " +/- " << sc.uncert << "\n"; lines.push_back(new TLine(x1[0], 0, x1[0], 1.0)); lines.back()->SetLineColor(sc.color); lines.back()->SetLineWidth(2); lines.push_back(new TLine(x1[1], 0, x1[1], 1.0)); lines.back()->SetLineColor(sc.color); lines.back()->SetLineWidth(2); res = TString::Format( TString::Format("%%.%if#pm%%.%if", precision, precision), sc.bestfit, sc.uncert); TString leg_text = "#splitline{"+sc.label+"}{"+res+"}"; sc.gr->SetLineColor(sc.color); sc.gr->SetLineWidth(3); leg->AddEntry(sc.gr, leg_text, "L"); } } TH1 *axis = CreateAxisHist(scans[0].gr, true); axis->GetXaxis()->SetTitle(js["x_axis_title"].asCString()); axis->GetYaxis()->SetTitle(js["y_axis_title"].asCString()); axis->Draw(); for (unsigned i = 0; i < scans.size(); ++i) { Scan & sc = scans[i]; sc.gr->Draw("LSAME"); } leg->Draw(); double xmin = axis->GetXaxis()->GetXmin(); double xmax = axis->GetXaxis()->GetXmax(); lines.push_back(new TLine(xmin, cross, xmax, cross)); lines.back()->SetLineColor(2); for (auto l : lines) l->Draw(); DrawCMSLogo(pads[0], "CMS", js["cms_label"].asString(), 0); DrawTitle(pads[0], js["title_right"].asString(), 3); canv.Update(); canv.SaveAs(".pdf"); canv.SaveAs(".png"); return 0; }
int main() { ModTDRStyle(); std::vector<Scan> scans; //scans.push_back({"higgsCombinefullScan.MultiDimFit.mH125.root", "with syst.", 1, nullptr}); //scans.push_back({"higgsCombinefastScan.MultiDimFit.mH125.root", "no syst.", 32, nullptr}); //scans.push_back({"higgsCombinenoBBBScan.MultiDimFit.mH125.root", "no bbb syst.", 38, nullptr}); // scans.push_back({"thesis/higgsCombineFullScan.MultiDimFit.mH125.root", "Stat+Syst+Theory", 1, nullptr}); scans.push_back({"higgsCombineFullScan.MultiDimFit.mH125.root", "Mass Scan", kAzure-4, nullptr}); // scans.push_back({"higgsCombineStatOnly.MultiDimFit.mH125.root", "Stat Only", kBlue+1, nullptr}); //scans.push_back({"thesis/higgsCombineStatAndTh.MultiDimFit.mH125.root", "Stat+Theory", 39, nullptr}); TCanvas c1("canvas","canvas"); std::vector<TLine *> lines; TLegend *leg = new TLegend(0.37,0.65,0.73,0.9,"","brNDC"); unsigned counter = 0; for (auto & sc : scans) { TFile f1(sc.file.c_str()); TTree *t1 = dynamic_cast<TTree*>(f1.Get("limit")); double best1 = 0.0; sc.gr = new TGraph(ExtractGraph(t1, best1)); auto x1 = GetCrossings(*(sc.gr), 1.0); TString res; if (x1.size() == 2) { double err = (x1[1]-x1[0])/2.0; std::cout << "Best fit is: " << best1 << " +/- " << err << std::endl; lines.push_back(new TLine(x1[0],0,x1[0],1.0)); lines.back()->SetLineColor(sc.color); lines.back()->SetLineWidth(2); lines.push_back(new TLine(x1[1],0,x1[1],1.0)); lines.back()->SetLineColor(sc.color); lines.back()->SetLineWidth(2); res = TString::Format("%.1f#pm%.1f",best1,err); } sc.gr->SetLineColor(sc.color); sc.gr->SetLineWidth(3); sc.gr->Draw(counter ? "LSAME" : "AL"); TString leg_text = "#splitline{"+sc.label+"}{"+res+"}"; leg->AddEntry(sc.gr, leg_text, "L"); counter++; } // c1.cd(); // // g1.Print(); // g1.SetLineColor(1); // g1.SetLineWidth(2); // // g1.SetMarkerColor(7); // g1.Draw("AC"); scans[0].gr->SetMaximum(4); scans[0].gr->GetXaxis()->SetRangeUser(110, 130); // scans[0].gr->GetXaxis()->SetTitle("Signal Strength, #mu"); scans[0].gr->GetXaxis()->SetTitle("m_{H} [GeV]"); scans[0].gr->GetYaxis()->SetTitle("-2 #Delta ln L"); scans[0].gr->GetXaxis()->SetTitleFont(62); scans[0].gr->GetYaxis()->SetTitleFont(62); leg->SetBorderSize(1); leg->SetTextFont(42); leg->SetTextSize(0.03); leg->SetLineColor(0); leg->SetLineStyle(1); leg->SetLineWidth(1); leg->SetFillColor(0); leg->SetFillStyle(1001); leg->Draw(); lines.push_back(new TLine(110,1,130,1)); lines.back()->SetLineColor(2); for (auto l : lines) l->Draw(); TLatex *title_latex = new TLatex(); title_latex->SetNDC(); title_latex->SetTextSize(0.035); title_latex->SetTextFont(62); title_latex->SetTextAlign(31); double height = 0.94; title_latex->DrawLatex(0.95,height,"19.7 fb^{-1} (8 TeV) + 4.9 fb^{-1} (7 TeV)"); title_latex->SetTextAlign(11); title_latex->DrawLatex(0.17,height,"H#rightarrow#tau#tau"); title_latex->SetTextSize(0.08); title_latex->DrawLatex(0.21, 0.25, "#mu#tau_{h}"); c1.Update(); c1.SaveAs("scan.pdf"); return 0; }
int main() { bool do_ratio = true; bool do_logy = true; TH1::AddDirectory(0); ModTDRStyle(); TString canvName = "FigExample"; TCanvas* canv = new TCanvas(canvName, canvName); canv->cd(); std::vector<TPad*> pads = do_ratio ? TwoPadSplit(0.29, 0.00, 0.00) : OnePad(); pads[0]->SetLogy(do_logy); // Source histograms TFile file_("histo.root", "READ"); TH1F* data = reinterpret_cast<TH1F*>(file_.Get("data")->Clone()); TH1F* MC = reinterpret_cast<TH1F*>(file_.Get("MC")->Clone()); file_.Close(); // Source binning MC->Rebin(2); data->Rebin(2); // Derived histograms TH1F* err = reinterpret_cast<TH1F*>(MC->Clone()); // Axis histogram std::vector<TH1*> h = CreateAxisHists(2, data, 70, 119.9); h[0]->Draw("axis"); if (do_ratio) { pads[1]->cd(); h[1]->Draw("axis"); SetupTwoPadSplitAsRatio(pads, "Obs/Exp", true, 0.65, 1.35); StandardAxes(h[1]->GetXaxis(), h[0]->GetYaxis(), "m_{e^{+}e^{-}}", "GeV"); } else { h[0]->GetXaxis()->SetTitleOffset(1.0); StandardAxes(h[0]->GetXaxis(), h[0]->GetYaxis(), "m_{e^{+}e^{-}}", "GeV"); } pads[0]->cd(); // Can draw main axis now int new_idx = CreateTransparentColor(12, 0.2); err->SetFillColor(new_idx); err->SetMarkerSize(0); MC->SetFillColor(kAzure + 1); MC->Draw("histsame"); err->Draw("e2same"); data->Draw("esamex0"); TH1F *ratio = reinterpret_cast<TH1F*>(MakeRatioHist(data, MC, true, false)); TH1F *ratio_err = reinterpret_cast<TH1F*>(MakeRatioHist(err, err, true, false)); if (pads[0]->GetLogy()) h[0]->SetMinimum(0.09); FixTopRange(pads[0], GetPadYMax(pads[0]), 0.15); DrawCMSLogo(pads[0], "CMS", "Preliminary", 11, 0.045, 0.035, 1.2); DrawTitle(pads[0], "19.7 fb^{-1} (8 TeV) + 4.9 fb^{-1} (7 TeV)", 3); DrawTitle(pads[0], "Z#rightarrowee", 1); if (do_ratio) { pads[1]->cd(); h[1]->Draw("axis"); ratio_err->Draw("e2same"); ratio->Draw("esamex0"); } pads[0]->cd(); // pos = 1, 2, 3 TLegend *legend = PositionedLegend(0.25, 0.18, 3, 0.03); legend->SetTextFont(42); FixBoxPadding(pads[0], legend, 0.05); legend->AddEntry(data, "Observed", "pe"); legend->AddEntry(MC, "Background", "f"); legend->AddEntry(err, "Uncertainty", "f"); legend->Draw(); canv->Update(); pads[0]->RedrawAxis(); pads[0]->GetFrame()->Draw(); if (do_ratio) { pads[1]->cd(); pads[1]->RedrawAxis(); pads[1]->GetFrame()->Draw(); } canv->Print(".pdf"); canv->Print(".png"); return 0; }
void plotCLs() { ModTDRStyle(2800, 2400, 0.06, 0.12, 0.14, 0.22); gStyle->SetPadTickX(1); gStyle->SetPadTickY(1); const unsigned Number = 2; Double_t Red[Number] = {1.00, 0.17}; Double_t Green[Number] = {1.00, 0.16}; Double_t Blue[Number] = {1.00, 0.47}; Double_t Length[Number] = {0.00, 1.00}; Int_t nb = 255; TColor::CreateGradientColorTable(Number, Length, Red, Green, Blue, nb); gStyle->SetNumberContours(nb); TFile f("combined_output.root"); TTree *t =(TTree*)gDirectory->Get("limit"); TGraph2D graph = TGraph2DFromTree(t, "mA", "tanb", "limit", //"quantileExpected > -1.1 && quantileExpected < -0.9"); "quantileExpected > 0.49 && quantileExpected < 0.51"); TGraph2D graph_exp = TGraph2DFromTree(t, "mA", "tanb", "limit", "quantileExpected > 0.49 && quantileExpected < 0.51"); TGraph2D graph_lo68 = TGraph2DFromTree(t, "mA", "tanb", "limit", "quantileExpected > 0.15 && quantileExpected < 0.16"); TGraph2D graph_hi68 = TGraph2DFromTree(t, "mA", "tanb", "limit", "quantileExpected > 0.83 && quantileExpected < 0.84"); TGraph2D graph_lo95 = TGraph2DFromTree(t, "mA", "tanb", "limit", "quantileExpected > 0.02 && quantileExpected < 0.03"); TGraph2D graph_hi95 = TGraph2DFromTree(t, "mA", "tanb", "limit", "quantileExpected > 0.97 && quantileExpected < 0.98"); TH2D hist("hist", "hist", 91, 90, 1000, 91, 1, 59); std::vector<TGraph *> cgraphs = SetupHist(&hist, &graph); TH2D h_exp("h_exp", "h_exp", 91, 90, 1000, 91, 1, 59); std::vector<TGraph *> g_exp = SetupHist(&h_exp, &graph_exp); TH2D h_lo68("h_lo68", "h_lo68", 91, 90, 1000, 91, 1, 59); std::vector<TGraph *> g_lo68 = SetupHist(&h_lo68, &graph_lo68); TH2D h_hi68("h_hi68", "h_hi68", 91, 90, 1000, 91, 1, 59); std::vector<TGraph *> g_hi68 = SetupHist(&h_hi68, &graph_hi68); TH2D h_lo95("h_lo95", "h_lo95", 91, 90, 1000, 91, 1, 59); std::vector<TGraph *> g_lo95 = SetupHist(&h_lo95, &graph_lo95); TH2D h_hi95("h_hi95", "h_hi95", 91, 90, 1000, 91, 1, 59); std::vector<TGraph *> g_hi95 = SetupHist(&h_hi95, &graph_hi95); TCanvas * canv = new TCanvas("cls", "cls"); canv->cd(); std::vector<TPad*> pads = OnePad(); hist.SetMinimum(0.); hist.SetMaximum(1.); hist.Draw("COLZ"); for (unsigned i = 0; i < g_exp.size(); ++i) { g_exp[i]->SetLineStyle(1); g_exp[i]->SetLineColor(kBlue); g_exp[i]->SetLineWidth(3); g_exp[i]->Draw("L SAME"); } for (unsigned i = 0; i < g_hi68.size(); ++i) { g_hi68[i]->SetLineStyle(7); g_hi68[i]->SetLineColor(kBlue); g_hi68[i]->SetLineWidth(3); g_hi68[i]->Draw("L SAME"); } for (unsigned i = 0; i < g_lo68.size(); ++i) { g_lo68[i]->SetLineStyle(7); g_lo68[i]->SetLineColor(kBlue); g_lo68[i]->SetLineWidth(3); g_lo68[i]->Draw("L SAME"); } for (unsigned i = 0; i < g_hi95.size(); ++i) { g_hi95[i]->SetLineStyle(2); g_hi95[i]->SetLineColor(kBlue); g_hi95[i]->SetLineWidth(3); g_hi95[i]->Draw("L SAME"); } for (unsigned i = 0; i < g_lo95.size(); ++i) { g_lo95[i]->SetLineStyle(2); g_lo95[i]->SetLineColor(kBlue); g_lo95[i]->SetLineWidth(3); g_lo95[i]->Draw("L SAME"); } for (unsigned i = 0; i < cgraphs.size(); ++i) { cgraphs[i]->SetLineStyle(1); cgraphs[i]->SetLineColor(kRed); cgraphs[i]->SetLineWidth(4); cgraphs[i]->Draw("L SAME"); } hist.GetXaxis()->SetTitle("m_{A} (GeV)"); hist.GetYaxis()->SetTitle("tan#beta"); hist.GetZaxis()->SetTitle("Observed CLs"); DrawTitle(pads[0], "CombineHarvester", 1); DrawTitle(pads[0], "MSSM h/H/A#rightarrow#tau#tau, #mu_{}#tau_{h} 8 TeV", 3); TLegend *leg = PositionedLegend(0.25, 0.20, 1, 0.025); leg->AddEntry(cgraphs[0], "95% CL Observed", "L"); leg->AddEntry(g_exp[0], "Expected", "L"); leg->AddEntry(g_lo68[0], " #pm1#sigma Expected", "L"); leg->AddEntry(g_lo95[0], " #pm2#sigma Expected", "L"); leg->Draw(); FixOverlay(); canv->Print("cls.png"); }