h_pionplus_long_trans.SetTitle("#pi^{+}") h_pionplus_long_trans.GetXaxis().SetTitle("p_{Z} [GeV/c]") # h_pionplus_long_trans.GetXaxis().SetTitleFont(12) h_pionplus_long_trans.GetYaxis().SetTitle("p_{T} [GeV/c]") # h_pionplus_long_trans.GetYaxis().SetTitleFont(12) h_pionplus_long_trans.GetXaxis().SetRangeUser(0, 130) h_pionplus_long_trans.GetYaxis().SetRangeUser(0, 5) h_pionplus_long_trans.GetXaxis().SetLabelSize(0.05) h_pionplus_long_trans.GetXaxis().SetTitleSize(0.05) h_pionplus_long_trans.GetYaxis().SetLabelSize(0.05) h_pionplus_long_trans.GetYaxis().SetTitleSize(0.05) cpionplus_long_trans.SetLeftMargin(0.15) cpionplus_long_trans.SetBottomMargin(0.12) cpionplus_long_trans.SetRightMargin(0.14) gStyle.SetTitleH(0.07) h_pionplus_long_trans.Draw("colz") # Seun's K/pi measurements (MIPP, thick target, so with tptype particle) [FERMILAB-THESIS-2007-61] line1 = TLine(20, 0, 20, 1) line2 = TLine(20, 1, 24, 1) line3 = TLine(24, 1, 24, 1.2) line4 = TLine(24, 1.2, 31, 1.2) line5 = TLine(31, 1.2, 31, 1.55) line6 = TLine(31, 1.55, 42, 1.55) line7 = TLine(42, 1.55, 42, 2) line8 = TLine(42, 2, 60, 2) line9 = TLine(60, 2, 90, 2) line10 = TLine(90, 2, 90, 0) line11 = TLine(90, 0, 20, 0)
def setStyle(): TColor.InitializeColors() stops = array('d', [ 0.0000, 0.1250, 0.2500, 0.3750, 0.5000, 0.6250, 0.7500, 0.8750, 1.0000 ]) red = array('d', [ 0.9764, 0.9956, 0.8186, 0.5301, 0.1802, 0.0232, 0.0780, 0.0592, 0.2082 ]) green = array('d', [ 0.9832, 0.7862, 0.7328, 0.7492, 0.7178, 0.6419, 0.5041, 0.3599, 0.1664 ]) blue = array('d', [ 0.0539, 0.1968, 0.3499, 0.4662, 0.6425, 0.7914, 0.8385, 0.8684, 0.5293 ]) TColor.CreateGradientColorTable(9, stops, red, green, blue, 255, 1.0) gStyle.SetHatchesLineWidth(1) gStyle.SetNumberContours(255) gStyle.SetNdivisions(505, "xyz") gStyle.SetTitleBorderSize(0) gStyle.SetTitleColor(1) gStyle.SetTitleStyle(3013) gStyle.SetTitleFillColor(0) gStyle.SetTitleX(0.05) gStyle.SetTitleW(0.4) gStyle.SetTitleY(0.965) gStyle.SetTitleH(0.065) gStyle.SetCanvasBorderMode(0) gStyle.SetCanvasBorderSize(3) gStyle.SetCanvasColor(0) gStyle.SetPadColor(0) gStyle.SetPadBorderMode(0) gStyle.SetFuncWidth(3) gStyle.SetPadGridY(False) gStyle.SetPadGridX(False) gStyle.SetFrameLineWidth(1) gStyle.SetMarkerSize(5) gStyle.SetPadTickX(True) gStyle.SetPadTickY(True) #gStyle.SetPalette(1) gStyle.SetHistLineWidth(3) gStyle.SetHistLineColor(1) gStyle.SetOptStat(0) gStyle.SetOptFit(0) gStyle.SetStatW(0.25) gStyle.SetStatH(0.25) gStyle.SetStatX(0.9) gStyle.SetStatY(0.9) gStyle.SetStatColor(0) gStyle.SetStatFormat("6.4g") gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) gStyle.SetPadBottomMargin(0.16) gStyle.SetPadLeftMargin(0.12) font = 42 gStyle.SetTextSize(.055) gStyle.SetTextFont(font) gStyle.SetLabelFont(font, "x") gStyle.SetTitleFont(font, "x") gStyle.SetLabelFont(font, "y") gStyle.SetTitleFont(font, "y") gStyle.SetLabelFont(font, "z") gStyle.SetTitleFont(font, "z") gStyle.SetTitleSize(.055, "x") gStyle.SetTitleSize(.055, "y") gStyle.SetTitleSize(.05, "z") gStyle.SetLabelSize(.05, "x") gStyle.SetLabelSize(.05, "y") gStyle.SetLabelSize(.05, "z") gStyle.SetLabelOffset(0.014, "x") gStyle.SetLabelOffset(0.006, "y") gStyle.SetLabelOffset(0.008, "z") gStyle.SetTitleOffset(1, "y") gStyle.SetTitleXOffset(1.2) # use bold lines and markers gStyle.SetMarkerStyle(20) gStyle.SetMarkerColor(1) gStyle.SetMarkerSize(1.2) gStyle.SetLineStyleString(2, "[12 12]") # postscript dashes gStyle.SetPadTickX(1) gStyle.SetPadTickY(1)
def set_root_env(): #//TStyle* genieStyle = new TStyle("genieStyle", "GENIE Style") #//set the background color to white gStyle.SetFillColor(10) gStyle.SetFrameFillColor(10) gStyle.SetCanvasColor(10) gStyle.SetPadColor(10) gStyle.SetTitleFillColor(0) gStyle.SetStatColor(10) #dont put a colored frame around the plots gStyle.SetFrameBorderMode(0) gStyle.SetCanvasBorderMode(0) gStyle.SetPadBorderMode(0) gStyle.SetLegendBorderSize(3) #use the primary color palette #gStyle.SetPalette(1,0) #set the default line color for a histogram to be black gStyle.SetHistLineColor(ROOT.kBlack) #set the default line color for a fit function to be red gStyle.SetFuncColor(ROOT.kRed) #make the axis labels black gStyle.SetLabelColor(ROOT.kBlack, "xyz") #set the default title color to be black gStyle.SetTitleColor(ROOT.kBlack) #set the margins gStyle.SetPadBottomMargin(0.18) gStyle.SetPadTopMargin(0.08) gStyle.SetPadRightMargin(0.08) gStyle.SetPadLeftMargin(0.17) #set axis label and title text sizes gStyle.SetLabelFont(42, "xyz") gStyle.SetLabelSize(0.04, "xyz") gStyle.SetLabelOffset(0.015, "xyz") gStyle.SetTitleFont(42, "xyz") gStyle.SetTitleSize(0.04, "xyz") gStyle.SetTitleOffset(1.4, "y") gStyle.SetTitleOffset(1.3, "x") gStyle.SetStatFont(42) gStyle.SetStatFontSize(0.07) gStyle.SetTitleBorderSize(1) gStyle.SetStatBorderSize(0) gStyle.SetTextFont(42) gStyle.SetTitleW(0.5) gStyle.SetTitleH(0.1) #set line widths gStyle.SetFrameLineWidth(2) gStyle.SetFuncWidth(2) gStyle.SetHistLineWidth(2) #set the number of divisions to show gStyle.SetNdivisions(506, "xy") #gStyle.SetPadTickX(-50202) #turn off xy grids gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) #set the tick mark style gStyle.SetPadTickX(1) gStyle.SetPadTickY(1) #turn off stats gStyle.SetOptStat(0) gStyle.SetOptFit(0) #marker/line settings #gStyle.SetMarkerStyle(20) gStyle.SetMarkerSize(.95) #0.7 gStyle.SetLineWidth(2) gStyle.SetErrorX(0) gStyle.SetHistLineStyle(0) #It was 3 for a dotted line #done gStyle.cd() gROOT.ForceStyle()
def initialization(batch=True, font=default_font): '''-- ROOT initialization --''' print "Initializing ROOT ..." # general gROOT.Reset() gROOT.SetBatch(batch) gROOT.SetStyle("Plain") # gStyle gStyle.SetFillColor(0) gStyle.SetCanvasColor(10) gStyle.SetLineWidth(1) gStyle.SetPalette(8) gStyle.SetTextFont(font) #gStyle.SetTextSize(30) # Frame gStyle.SetFrameBorderMode(0) gStyle.SetFrameFillColor(0) # Pad gStyle.SetPadBorderMode(0) gStyle.SetPadColor(0) gStyle.SetPadBottomMargin(0.1) gStyle.SetPadTopMargin(0.01) gStyle.SetPadLeftMargin(0.1) gStyle.SetPadRightMargin(0.01) gStyle.SetPadTickX(1) # make ticks be on all 4 sides. gStyle.SetPadTickY(1) gStyle.SetPadGridX(0) gStyle.SetPadGridY(0) # histogram gStyle.SetHistFillStyle(0) gStyle.SetOptTitle(0) gStyle.SetTitleSize(0.22) gStyle.SetTitleFontSize(10) gStyle.SetTitleFont(font) gStyle.SetTitleFont(font, "xyz") gStyle.SetTitleYOffset(1.0) gStyle.SetTitleXOffset(1.0) gStyle.SetTitleXSize(0.04) gStyle.SetTitleYSize(0.04) gStyle.SetTitleX(.15) gStyle.SetTitleY(.98) gStyle.SetTitleW(.70) gStyle.SetTitleH(.05) # statistics box gStyle.SetOptStat(0) gStyle.SetStatFont(font) gStyle.SetStatFontSize(10) gStyle.SetStatX(.91) gStyle.SetStatY(.90) gStyle.SetStatW(.15) gStyle.SetStatH(.15) # axis labels gStyle.SetLabelFont(font) gStyle.SetLabelFont(font, "xyz") gStyle.SetLabelSize(10, "xyz") # gStyle.SetGridColor(1) gStyle.SetLegendBorderSize(1)
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))
else: logging.basicConfig(level=logging.INFO) logging.info("importing ROOT") import ROOT from ROOT import TCanvas, TGraph, TLine, gStyle, gROOT, gPad, TFile, TTree, TPaveText, TLegend, kBlack, TColor, kGray #include "TGraph.h" #include "TAxis.h" #include "TH1.h" logging.info("done") gStyle.SetTitleFontSize(args.font_size) gROOT.ForceStyle() gStyle.SetTitleW(0.7) # //per cent of the pad width gStyle.SetTitleH(0.5) # //per cent of the pad height # none of these work def rgb(r, g, b): '''rgb(r, g, b): from: http://webhome.phy.duke.edu/~dmb60/the-guide/ TColor* color = gROOT->GetColor(TColor::GetColor(red,green,blue));//Use ints from 0 to 255 color->SetAlpha(0.5);//0 is fully transparent, 1 fully opaque hist->SetFillColor(color->GetNumber()); ''' return TColor.GetColor(r, g, b)