def do_final_cosmetics(self): self.decoratee.do_final_cosmetics() titlebox = TPaveText(0.18, 0.94, 0.9, 0.97, "brNDC") titlebox.AddText(self.make_title()) titlebox.SetTextSize(0.045) titlebox.SetFillStyle(0) titlebox.SetBorderSize(0) titlebox.SetTextAlign(13) titlebox.SetMargin(0.0) titlebox.SetFillColor(0) titlebox.Draw("SAME") self.titlebox = titlebox
def plot_all(report_lumi=True): # prepare all plots plots = {} for chan in ('el', 'mu', 'both'): fn_full, fn_notau, fn_stat = the_files[chan] file_full = TFile(fn_full) file_notau = TFile(fn_notau) file_stat = TFile(fn_stat) ttree_full = file_full.Get("limit") n = ttree_full.Draw(draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") g_full = TGraph(n, ttree_full.GetV2(), ttree_full.GetV1()) ttree_notau = file_notau.Get("limit") n = ttree_notau.Draw(draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") g_notau = TGraph(n, ttree_notau.GetV2(), ttree_notau.GetV1()) ttree_stat = file_stat.Get("limit") n = ttree_stat.Draw(draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") g_stat = TGraph(n, ttree_stat.GetV2(), ttree_stat.GetV1()) if chan == 'both': g_full.SetLineWidth(4) else: g_full.SetLineWidth(2) g_notau.SetLineWidth(2) g_stat.SetLineWidth(2) g_stat.SetLineStyle(7) # removing the title #g_full .SetTitle(";\\text{fitted } #hat{r};") # ROOT latex cannot put a hat on a letter #g_full .SetTitle(";\\text{fitted } r;-2\\Delta log L") #g_full .SetTitle(";\\text{fitted signal strength};-2\\Delta log L") g_full.SetTitle(";%s;-2#Delta log (L)" % args.title_x) g_notau.SetTitle(";;") g_stat.SetTitle(";;") #g_full .GetXaxis().SetRange(0.75, 1.35) #g_notau.GetXaxis().SetRange(0.75, 1.35) #g_stat .GetXaxis().SetRange(0.75, 1.35) g_full.GetXaxis().SetRangeUser(0.75, 1.35) g_notau.GetXaxis().SetRangeUser(0.75, 1.35) g_stat.GetXaxis().SetRangeUser(0.75, 1.35) plots[chan] = g_full, g_notau, g_stat print "set up observed plots" plots_expected = {} # prepare expected plots for chan in ('el', 'mu', 'both'): fn_full, fn_notau, fn_stat = the_files_expected[chan] exp_file_full = TFile(fn_full) exp_file_notau = TFile(fn_notau) exp_file_stat = TFile(fn_stat) print fn_full, fn_notau, fn_stat exp_ttree_full = exp_file_full.Get("limit") n = exp_ttree_full.Draw( draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") exp_g_full = TGraph(n, exp_ttree_full.GetV2(), exp_ttree_full.GetV1()) exp_ttree_notau = exp_file_notau.Get("limit") n = exp_ttree_notau.Draw( draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") exp_g_notau = TGraph(n, exp_ttree_notau.GetV2(), exp_ttree_notau.GetV1()) exp_ttree_stat = exp_file_stat.Get("limit") n = exp_ttree_stat.Draw( draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") exp_g_stat = TGraph(n, exp_ttree_stat.GetV2(), exp_ttree_stat.GetV1()) if chan == 'both': exp_g_full.SetLineWidth(4) else: exp_g_full.SetLineWidth(2) exp_g_notau.SetLineWidth(2) exp_g_stat.SetLineWidth(2) exp_g_stat.SetLineStyle(7) # removing the title #g_full .SetTitle(";\\text{fitted } #hat{r};") # ROOT latex cannot put a hat on a letter #exp_g_full .SetTitle(";\\text{fitted } r;-2\\Delta log L") #exp_g_full .SetTitle(";\\text{fitted signal strength};-2\\Delta log L") exp_g_full.SetTitle(";%s;-2#Delta log (L)" % args.title_x) exp_g_notau.SetTitle(";;") exp_g_stat.SetTitle(";;") #exp_g_full .GetXaxis().SetRange(0.75, 1.35) #exp_g_notau.GetXaxis().SetRange(0.75, 1.35) #exp_g_stat .GetXaxis().SetRange(0.75, 1.35) exp_g_full.GetXaxis().SetRangeUser(0.75, 1.35) exp_g_notau.GetXaxis().SetRangeUser(0.75, 1.35) exp_g_stat.GetXaxis().SetRangeUser(0.75, 1.35) plots_expected[chan] = exp_g_full, exp_g_notau, exp_g_stat print "set up expectation plots" leg = TLegend(0.6, 0.7, 0.89, 0.89) # plotting # first plots to set up the canvas # draw horizontal lines first drawn = False if args.horizontal_lines: for y in [float(s) for s in args.horizontal_lines.split(',')]: l = TLine(0.1, y, 0.9, y) l.SetLineColor(kGray) if not drawn: # root is awesome, isn't it? drawn = True l.Draw() else: l.Draw('same') chan = 'el' print 'plotting %s' % chan exp_g_full = plots_expected[chan][0] g_full = plots[chan][0] exp_g_full.SetLineColor(colors[chan]) g_full.SetLineColor(colors[chan]) if not drawn: g_full.Draw("ap") # this cast makes the following work g_full.Draw("L") else: g_full.Draw("same ap") g_full.Draw("same L") #g_notau.Draw("L same") #g_stat .Draw("L same") name = names[chan] leg.AddEntry(g_full, "%s" % name, "L") #leg.AddEntry(g_full, "%s observed" % name, "L") #leg.AddEntry(g_full, "fitted full unc.", "L") #leg.AddEntry(g_stat, "fitted stat unc.", "L") #exp_g_full.SetLineStyle(7) ##exp_g_full .Draw("ap") #exp_g_full .Draw("L same") ##exp_g_notau.Draw("L same") ##exp_g_stat .Draw("L same") #leg.AddEntry(exp_g_full, "%s expected" % chan, "L") ##leg.AddEntry(exp_g_full, "exp. full unc.", "L") ##leg.AddEntry(exp_g_stat, "exp. stat unc.", "L") # add el and mu for chan in ('mu', 'both'): exp_g_full = plots_expected[chan][0] g_full = plots[chan][0] exp_g_full.SetLineColor(colors[chan]) g_full.SetLineColor(colors[chan]) name = names[chan] g_full.Draw("L same") #leg.AddEntry(g_full, "%s observed" % name, "L") leg.AddEntry(g_full, "%s" % name, "L") #exp_g_full.SetLineStyle(7) ##exp_g_full .Draw("same ap") # this cast makes the following work #exp_g_full .Draw("same L") #leg.AddEntry(exp_g_full, "%s expected" % name, "L") #left_title = TPaveText(0.15, 0.82, 0.3, 0.88, "brNDC") #left_title.AddText(args.left_title) #left_title.SetTextFont(1) #left_title.SetFillColor(0) if args.left_title_below: left_title = TPaveText(0.12, 0.82, 0.72, 0.89, "brNDC") else: left_title = TPaveText(0.1, 0.92, 0.7, 0.99, "brNDC") #left_title = TPaveText(0.1, 0.92, 0.7, 0.99, "brNDC") left_title.SetTextAlign(13) left_title.SetMargin(0) left_title.AddText(args.left_title) left_title.SetFillColor(0) left_title.Draw("same") right_title = TPaveText(0.7, 0.9, 0.9, 0.99, "brNDC") both = True if report_lumi: right_title.AddText("%s fb^{-1} (13 TeV)" % (35.8 if chan == 'el' else 35.8)) elif both: right_title.AddText("%s fb^{-1} (13 TeV)" % '35.8') else: right_title.AddText("(13 TeV)") right_title.SetTextFont(132) right_title.SetFillColor(0) right_title.Draw("same") leg.SetBorderSize(0) leg.Draw("same") plotted = '' plotted += '_exp' plotted += '_obs' c1.SaveAs("uncertainty_scans_%s_%s%s.%s" % (args.fit_release, 'all', plotted, args.output_type))
#left_title = TPaveText(0.1, 0.9, 0.4, 0.94, "brNDC") #left_title.AddText("CMS preliminary at 13 TeV") #left_title.SetTextFont(1) #left_title = TPaveText(0.15, 0.82, 0.25, 0.88, "brNDC") #left_title.AddText("CMS") #left_title.SetTextFont(1) #left_title.SetFillColor(0) ##left_title.Draw("same") #left_title = TPaveText(0.1, 0.92, 0.5, 0.99, "brNDC") left_title = TPaveText(0.1, 0.92, 0.5, 1., "brNDC") left_title.AddText("CMS") left_title.SetTextAlign( 13) # this adjust to left (+ margin inside the box and top) left_title.SetMargin(0) left_title.SetFillColor(0) #right_title = TPaveText(0.75, 0.9, 0.9, 0.94, "brNDC") #right_title.AddText("L = %s fb^{-1}" % args.lumi) #right_title.SetTextFont(132) #right_title.SetFillColor(0) #right_title = TPaveText(0.7, 0.9, 0.9, 0.98, "brNDC") ##if report_lumi: ## right_title.AddText("%s fb^{-1} (13 TeV)" % (31.3 if chan == 'el' else 35.8)) ##else: ## right_title.AddText("(13 TeV)") #right_title.AddText("%s fb^{-1} (13 TeV)" % args.lumi) #right_title.SetTextFont(132) #right_title.SetFillColor(0)
def plot(chan, plot_expected, plot_data, report_lumi=True): #c1.SetGrid(); #c1 = TCanvas("c1","Expected Bias Band Graph",200,10,800,800); c1 = TCanvas("c1", "Expected Bias Band Graph", 200, 10, args.canvas_size, args.canvas_size) c1.DrawFrame(0.85, 0.75, 1.15, 1.25) gStyle.SetTitleW(0.7) # //per cent of the pad width gStyle.SetTitleH(0.5) # //per cent of the pad height # none of these work # prepare data files if plot_data: fn_full, fn_notau, fn_stat = the_files[chan] file_full = TFile(fn_full) file_notau = TFile(fn_notau) file_stat = TFile(fn_stat) ttree_full = file_full.Get("limit") n = ttree_full.Draw(draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") g_full = TGraph(n, ttree_full.GetV2(), ttree_full.GetV1()) ttree_notau = file_notau.Get("limit") n = ttree_notau.Draw(draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") g_notau = TGraph(n, ttree_notau.GetV2(), ttree_notau.GetV1()) ttree_stat = file_stat.Get("limit") n = ttree_stat.Draw(draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") g_stat = TGraph(n, ttree_stat.GetV2(), ttree_stat.GetV1()) g_full.SetLineWidth(4) g_notau.SetLineWidth(2) g_stat.SetLineWidth(2) g_stat.SetLineStyle(7) # removing the title #g_full .SetTitle(";\\text{fitted } #hat{r};") # ROOT latex cannot put a hat on a letter #g_full .SetTitle(";\\text{fitted } r;-2\\Delta log L") #g_full .SetTitle(";\\text{fitted signal strength};-2\\Delta log L") #g_full .SetTitle(";%s;-2#Delta log (L)" % args.title_x) g_full.SetTitle(";;") g_notau.SetTitle(";;") g_stat.SetTitle(";;") #g_full .GetXaxis().SetRange(0.75, 1.35) #g_notau.GetXaxis().SetRange(0.75, 1.35) #g_stat .GetXaxis().SetRange(0.75, 1.35) g_full.GetXaxis().SetRangeUser(0.75, 1.35) g_notau.GetXaxis().SetRangeUser(0.75, 1.35) g_stat.GetXaxis().SetRangeUser(0.75, 1.35) # font #set_trace() g_full.GetXaxis().SetTitleFont(133) g_notau.GetXaxis().SetTitleFont(133) g_stat.GetXaxis().SetTitleFont(133) g_full.GetXaxis().SetTitleSize(args.font_size) g_notau.GetXaxis().SetTitleSize(args.font_size) g_stat.GetXaxis().SetTitleSize(args.font_size) g_full.GetYaxis().SetTitleFont(133) g_notau.GetYaxis().SetTitleFont(133) g_stat.GetYaxis().SetTitleFont(133) g_full.GetYaxis().SetTitleSize(args.font_size) g_notau.GetYaxis().SetTitleSize(args.font_size) g_stat.GetYaxis().SetTitleSize(args.font_size) print "set up data plots", g_full # prepare expected files if plot_expected: fn_full, fn_notau, fn_stat = the_files_expected[chan] exp_file_full = TFile(fn_full) exp_file_notau = TFile(fn_notau) exp_file_stat = TFile(fn_stat) print fn_full, fn_notau, fn_stat exp_ttree_full = exp_file_full.Get("limit") n = exp_ttree_full.Draw( draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") exp_g_full = TGraph(n, exp_ttree_full.GetV2(), exp_ttree_full.GetV1()) exp_ttree_notau = exp_file_notau.Get("limit") n = exp_ttree_notau.Draw( draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") exp_g_notau = TGraph(n, exp_ttree_notau.GetV2(), exp_ttree_notau.GetV1()) exp_ttree_stat = exp_file_stat.Get("limit") n = exp_ttree_stat.Draw( draw_command, "2*deltaNLL>0 && 2*deltaNLL< %f" % args.nll_limit, "L") exp_g_stat = TGraph(n, exp_ttree_stat.GetV2(), exp_ttree_stat.GetV1()) exp_g_full.SetLineWidth(2) exp_g_notau.SetLineWidth(2) exp_g_stat.SetLineWidth(2) exp_g_stat.SetLineStyle(7) # removing the title #g_full .SetTitle(";\\text{fitted } #hat{r};") # ROOT latex cannot put a hat on a letter #exp_g_full .SetTitle(";\\text{fitted } r;-2\\Delta log L") #exp_g_full .SetTitle(";\\text{fitted signal strength};-2\\Delta log L") exp_g_full.SetTitle(";%s;-2 #Delta log (L)" % args.title_x) exp_g_notau.SetTitle(";;") exp_g_stat.SetTitle(";;") #exp_g_full .GetXaxis().SetRange(0.75, 1.35) #exp_g_notau.GetXaxis().SetRange(0.75, 1.35) #exp_g_stat .GetXaxis().SetRange(0.75, 1.35) exp_g_full.GetXaxis().SetRangeUser(0.75, 1.35) exp_g_notau.GetXaxis().SetRangeUser(0.75, 1.35) exp_g_stat.GetXaxis().SetRangeUser(0.75, 1.35) # fonts exp_g_full.GetXaxis().SetTitleFont(133) exp_g_notau.GetXaxis().SetTitleFont(133) exp_g_stat.GetXaxis().SetTitleFont(133) exp_g_full.GetXaxis().SetTitleSize(args.font_size) exp_g_notau.GetXaxis().SetTitleSize(args.font_size) exp_g_stat.GetXaxis().SetTitleSize(args.font_size) exp_g_full.GetYaxis().SetTitleFont(133) exp_g_notau.GetYaxis().SetTitleFont(133) exp_g_stat.GetYaxis().SetTitleFont(133) exp_g_full.GetYaxis().SetTitleSize(args.font_size) exp_g_notau.GetYaxis().SetTitleSize(args.font_size) exp_g_stat.GetYaxis().SetTitleSize(args.font_size) exp_g_full.GetXaxis().SetTitleOffset(args.offset_x) exp_g_notau.GetXaxis().SetTitleOffset(args.offset_x) exp_g_stat.GetXaxis().SetTitleOffset(args.offset_x) exp_g_full.GetYaxis().SetTitleOffset(args.offset_y) exp_g_notau.GetYaxis().SetTitleOffset(args.offset_y) exp_g_stat.GetYaxis().SetTitleOffset(args.offset_y) print "set up expectation plots", exp_g_full ## add X axis title #g_full .SetXTitle("fitted \\mu") #g_notau.SetXTitle("fitted \\mu") #g_stat .SetXTitle("fitted \\mu") leg = TLegend(0.6, 0.7, 0.89, 0.89) leg.SetTextFont(133) leg.SetTextSize(args.font_size) # draw horizontal lines first drawn = False if args.horizontal_lines: for y in [float(s) for s in args.horizontal_lines.split(',')]: l = TLine(100, y, 1000, y) l.SetLineColor(kGray) if not drawn: # root is awesome, isn't it? drawn = True l.Draw() else: l.Draw('same') print "drew line", y if plot_expected and plot_data: print "plotting both" exp_g_full.SetLineStyle(7) if not drawn: exp_g_full.Draw("ap") # this cast makes the following work exp_g_full.Draw("L") else: exp_g_full.Draw("same ap") exp_g_full.Draw("same L") if args.horizontal_lines: for y in [float(s) for s in args.horizontal_lines.split(',')]: l = TLine(0, y, 1000, y) l.SetLineColor(kGray) l.Draw('same L') print "drew line", y exp_g_full.Draw("same ap") exp_g_full.Draw("same L") #exp_g_full .Draw("ap") # this cast makes the following work #exp_g_full .Draw("L") #exp_g_notau.Draw("L same") #exp_g_stat .Draw("L same") leg.AddEntry(exp_g_full, "expected", "L") #leg.AddEntry(exp_g_full, "exp. full unc.", "L") #leg.AddEntry(exp_g_stat, "exp. stat unc.", "L") g_full.Draw("L same") #g_notau.Draw("L same") #g_stat .Draw("L same") leg.AddEntry(g_full, "observed", "L") #leg.AddEntry(g_full, "fitted full unc.", "L") #leg.AddEntry(g_stat, "fitted stat unc.", "L") elif plot_data: print "plotting data" g_full.Draw("ap") # this cast makes the following work g_full.Draw("L") g_notau.Draw("L same") g_stat.Draw("L same") leg.AddEntry(g_full, "fitted full unc.", "L") leg.AddEntry(g_notau, "#splitline{fitted unc.}{w.o. tau ID}", "L") leg.AddEntry(g_stat, "fitted stat unc.", "L") elif plot_expected: print "plotting expected" exp_g_full.SetLineColor(43) exp_g_notau.SetLineColor(43) exp_g_stat.SetLineColor(43) exp_g_full.Draw("ap") exp_g_full.Draw("L") exp_g_notau.Draw("L same") exp_g_stat.Draw("L same") leg.AddEntry(exp_g_full, "exp. full unc.", "L") leg.AddEntry(exp_g_notau, "#splitline{exp. unc.}{w.o. tau ID}", "L") leg.AddEntry(exp_g_stat, "exp. stat unc.", "L") #left_title = TPaveText(0.1, 0.9, 0.4, 0.94, "brNDC") #left_title.AddText("CMS preliminary at 13 TeV") #left_title.SetTextFont(1) #left_title = TPaveText(0.15, 0.82, 0.3, 0.88, "brNDC") #left_title.AddText("CMS") #left_title.SetTextFont(1) #left_title.SetFillColor(0) if args.left_title_below: left_title = TPaveText(0.12, 0.82, 0.72, 0.89, "brNDC") else: left_title = TPaveText(0.1, 0.92, 0.7, 0.99, "brNDC") left_title.SetTextAlign(13) left_title.SetMargin(0) left_title.AddText(args.left_title) left_title.SetFillColor(0) left_title.Draw("same") #right_title = TPaveText(0.75, 0.9, 0.9, 0.94, "brNDC") #right_title.AddText("L = %s fb^{-1}" % (31.3 if chan == 'el' else 35.8)) #right_title.SetTextFont(132) #right_title.SetFillColor(0) #right_title = TPaveText(0.5, 0.9, 0.9, 0.95, "brNDC") right_title = TPaveText(0.5, 0.92, 0.9, 0.99, "brNDC") both = True if report_lumi: right_title.AddText("%s fb^{-1} (13 TeV)" % 35.8) elif both: right_title.AddText("%s fb^{-1} (13 TeV)" % '35.8') else: right_title.AddText("(13 TeV)") right_title.SetMargin(0) right_title.SetTextAlign(33) right_title.SetTextFont(132) right_title.SetFillColor(0) right_title.Draw("same") leg.SetBorderSize(0) leg.Draw("same") plotted = '' plotted += '_exp' if plot_expected else '' plotted += '_obs' if plot_data else '' c1.SaveAs("uncertainty_scans_%s_%s%s.%s" % (args.fit_release, chan, plotted, args.output_type))