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() { 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"); }