Exemple #1
0
def make_threebody_plots(plt, reg, sig) :

    # get the canvases
    rcan = plt.ratioCanvas
    rcan.canvas.cd()
    rcan.upper_pad.cd()

    if plt.isLog() : rcan.upper_pad.SetLogy(True)

    # draw the frame
    hax = r.TH1F("axes","", int(plt.nbins), plt.x_range_min, plt.x_range_max)
    hax.SetMinimum(plt.y_range_min)
    hax.SetMaximum(plt.y_range_max)
    hax.GetXaxis().SetTitle(plt.x_label)
    hax.GetXaxis().SetTitleFont(42)
    hax.GetXaxis().SetLabelFont(42)
    hax.GetXaxis().SetLabelSize(0.035)
    hax.GetXaxis().SetTitleSize(0.048*0.85)
    hax.GetXaxis().SetTitleOffset(-999)
    hax.GetXaxis().SetLabelOffset(-999)

    hax.GetYaxis().SetTitle(plt.y_label)
    hax.GetYaxis().SetTitleFont(42)
    hax.GetYaxis().SetLabelFont(42)
    hax.GetYaxis().SetTitleOffset(1.4)
    hax.GetYaxis().SetLabelOffset(0.013)
    hax.GetYaxis().SetLabelSize(1.2*0.035)
    hax.GetYaxis().SetTitleSize(0.055*0.85)
    hax.Draw("axis")
    rcan.upper_pad.Update()

    # legend
    leg = pu.default_legend(xl=0.6, yl=0.65, xh=0.97, yh=0.90)
    leg.SetHeader("%s"%sig.displayname)
    leg.SetNColumns(1)
    
    #############################################################
    # get histogram for nom, 3-body (Right, Left, Mass-only)
    ############################################################
    h_nom = get_histogram(plt, sig, reg, "nom")
    h_r = get_histogram(plt, sig, reg, "right")
    h_l = get_histogram(plt, sig, reg, "left")
    h_m = get_histogram(plt, sig, reg, "mass") 

    #filetest = r.TFile.Open("/data/uclhc/uci/user/dantrim/ntuples/n0222/may23/mc/Raw/CENTRAL_387947.root")
    #treetest = filetest.Get("superNt")
    #c = r.TCanvas("c", "", 768, 768)
    #c.cd()
    #htest = r.TH1F("h","", 32, 0, 250)
    #cut = "(" + reg.tcut + ") * " + "eventweightNOPUPW" 
    #cut = r.TCut(cut)
    #sel = r.TCut("1")
    #cmd = "%s>>%s"%("MDR", htest.GetName()) 
    #treetest.Draw(cmd, cut*sel)
    #c.SaveAs("testing.eps")
    


    ############
    # hergiw
    #hf = r.TFile.Open("/data/uclhc/uci/user/dantrim/ntuples/n0222/apr17/mc/Raw/CENTRAL_406010.root")
    hf = r.TFile.Open("/data/uclhc/uci/user/dantrim/ntuples/n0222/may23/mc/Raw/CENTRAL_406010.root")
    herwig_250_160_tree = hf.Get("superNt")
    
    print "blah ", reg.tcut
    cut = "(" + reg.tcut + ") * " + "eventweightNOPUPW" 
    cut = r.TCut(cut)
    sel = r.TCut("1")
    hh = pu.th1f("h_herwig_" + "_" + sig.name + "_herwig", "", int(plt.nbins), plt.x_range_min, plt.x_range_max, plt.x_label, plt.y_label)
    hh.SetMinimum(plt.y_range_min)
    hh.SetMaximum(plt.y_range_max)
    hh.GetXaxis().SetTitleOffset(-999)
    hh.GetXaxis().SetLabelOffset(-999)
    hh.SetLineColor(r.kBlack)
    hh.SetLineWidth(2)
    hh.SetLineStyle(2)
    hh.SetFillStyle(0)
    cmd = "%s>>%s"%(plt.variable, hh.GetName()) 
    herwig_250_160_tree.Draw(cmd, cut * sel, "goff")


    histos = [h_nom, h_r, h_l, h_m]

    # overflows
    for h in histos:
        pu.add_overflow_to_lastbin(h)

    # colors
    for h in histos :
        color, name = get_color_from_name(h)
        h.SetLineColor(color)
        h.SetLineWidth(2)
        h.SetFillStyle(0)
        leg.AddEntry(h, name, "l") 

    # draw
    histos.append(hh)
    is_first = True
    for h in histos :
        if is_first :
            is_first = False
            rcan.upper_pad.cd()
            
            h.Draw("hist e")
            rcan.upper_pad.Update()
        else :
            rcan.upper_pad.cd()
            h.Draw("hist e same")
            rcan.upper_pad.Update()

    #hwerwig
    hh.SetLineColor(r.kRed)
    hh.SetFillStyle(0)
    hh.Draw("hist same")
    leg.AddEntry(hh, "Herwig++", "l")

    rcan.upper_pad.SetGridx(True)
    rcan.upper_pad.SetGridy(True)

    # draw the legend
    leg.Draw()


    ################################################
    ## ratio
    ################################################
    rcan.lower_pad.cd()

    h_den = h_nom.Clone("h_den")
    # y-axis
    yax = h_den.GetYaxis()
    yax.SetRangeUser(0,2)
    yax.SetTitle("Variation/Nominal")
    yax.SetTitleSize(0.14 * 0.75)
    yax.SetLabelSize(0.13)
    yax.SetLabelOffset(0.98 * 0.013)
    yax.SetTitleOffset(0.48)
    yax.SetLabelFont(42)
    yax.SetTitleFont(42)
    yax.SetNdivisions(5)
    # x-axis
    xax = h_den.GetXaxis()
    xax.SetTitleSize(1.0 * 0.14)
    xax.SetLabelSize(0.13)
    xax.SetLabelOffset(1.15*0.02)
    xax.SetTitleOffset(1.1)#0.2*2)
    #xax.SetTitleOffset(0.1 * xax.GetTitleOffset())
    xax.SetLabelFont(42)
    xax.SetTitleFont(42) 

    h_den.SetTickLength(0.06)
    h_den.Draw("AXIS")
    h_den.SetTitle(plt.x_label)

    # unity line
    pu.draw_line(plt.x_range_min, 1.0, plt.x_range_max, 1.0, color=r.kRed, style=2, width=1)

    # right
    h_rl = h_r.Clone("h_rl")
    h_rl.Divide(h_den)
    h_rl.Draw("hist e same")
    rcan.lower_pad.Update()

    # left
    h_ll = h_l.Clone("h_ll")
    h_ll.Divide(h_den)
    h_ll.Draw("hist e same")
    rcan.lower_pad.Update()

    # mass
    h_ml = h_m.Clone("h_ml")
    h_ml.Divide(h_den)
    h_ml.Draw("hist e same")
    rcan.lower_pad.Update()


    rcan.canvas.SaveAs("test_%s.eps"%plt.variable)
Exemple #2
0
def make_plot(samples, plot, region):

    c = plot.canvas
    c.cd()
    c.SetFrameFillColor(0)
    c.SetFillColor(0)
    c.SetLeftMargin(0.14)
    c.SetRightMargin(0.05)
    c.SetBottomMargin(1.3 * c.GetBottomMargin())
    c.Update()

    r.gPad.SetGrid()

    # prepare legend
    leg = pu.default_legend(xl=0.6, yl=0.69, xh=0.97, yh=0.88)

    histos = []
    for sample in samples:
        print "\t> %s" % sample.name
        hist_name = ""
        if "abs" in plot.variable:
            replace_var = plot.variable.replace("abs(", "")
            replace_var = replace_var.replace(")", "")
            hist_name = replace_var
        else:
            hist_name = plot.variable

        h = pu.th1f(
            "h_" + sample.name + "_" + hist_name,
            "",
            int(plot.nbins),
            plot.x_range_min,
            plot.x_range_max,
            plot.x_label,
            plot.y_label,
        )
        h.SetLineColor(sample.color)
        if "allIchep" in sample.name or "allRuns" in sample.name:
            h.SetLineStyle(1)
        else:
            h.SetLineStyle(2)
        h.SetFillStyle(0)
        h.SetLineWidth(3)
        h.GetYaxis().SetTitleOffset(1.17 * h.GetYaxis().GetTitleOffset())
        h.Sumw2

        sel = r.TCut("1")
        cut = region.tcut
        cut = r.TCut(cut)
        cmd = "%s>>%s" % (plot.variable, h.GetName())
        sample.tree.Draw(cmd, cut * sel, "goff")

        # normalize
        h.Scale(1 / h.Integral())

        # add overflow
        pu.add_overflow_to_lastbin(h)

        leg.AddEntry(h, sample.displayname, "l")
        histos.append(h)
        c.Update()

    is_first = True
    for h in histos:
        if is_first:
            h.Draw("hist")
            is_first = False
        else:
            h.Draw("hist same")

    leg.Draw()

    c.Update()

    outname = plot.name + ".eps"
    c.SaveAs(outname)
    out = "./plots/"
    utils.mv_file_to_dir(outname, out, True)
    fullname = out + "/" + outname
    print "%s saved to : %s" % (outname, os.path.abspath(fullname))
Exemple #3
0
def make_wp_comparison_plot(variable, sample, reg) :

    print 50*"-"
    print "Plotting WP comparison : %s"%variable


    nice_names = {}
    nice_names["bjets_n"] = "b-jet Multiplicity"
    nice_names["sjets_n"] = "Non b-tagged jet Multiplicity"
    nice_names["bjets_pt0"] = "Lead b-jet p_{T} [GeV]"
    nice_names["bjets_pt1"] = "2nd b-jet p_{T} [GeV]"
    nice_names["bjets_pt2"] = "3rd b-jet p_{T} [GeV]"
    nice_names["bjets_pt3"] = "4th b-jet p_{T} [GeV]"
    nice_names["bjets_nTrk0"] = "Lead b-jet # tracks"
    nice_names["bjets_nTrk1"] = "2nd b-jet # tracks"
    nice_names["bjets_nTrk2"] = "3rd b-jet # tracks"
    nice_names["bjets_nTrk3"] = "4th b-jet # Ttracks"
    nice_names["bjets_jvt0"] = "Lead b-jet JVT"
    nice_names["bjets_jvt1"] = "2nd b-jet JVT"
    nice_names["bjets_jvt2"] = "3rd b-jet JVT"
    nice_names["bjets_jvt3"] = "4th b-jet JVT"
    nice_names["bjets_eta0"] = "Lead b-jet #eta"
    nice_names["bjets_eta1"] = "2nd b-jet #eta"
    nice_names["bjets_eta2"] = "3rd b-jet #eta"
    nice_names["bjets_eta3"] = "4th b-jet #eta"
    nice_names["mt2"] = "m_{t2} [GeV]"
    nice_names["MDR"] = "M_{#Delta}^{R} [GeV]"
    nice_names["DPB_vSS"] = "#Delta#phi_{#beta}^{R}"

    bounds = {}
    bounds["bjets_n"] = [1,0,10,1e9]
    bounds["sjets_n"] = [1,0,10,1e9]
    bounds["bjets_pt0"] = [10, 0, 350,1e9]
    bounds["bjets_pt1"] = [10, 0, 350,1e9]
    bounds["bjets_pt2"] = [10, 0, 200,1e9]
    bounds["bjets_pt3"] = [10, 0, 200,1e9]
    bounds["bjets_nTrk0"] = [1, 0, 30, 1e9]
    bounds["bjets_nTrk1"] = [1, 0, 30, 1e9]
    bounds["bjets_nTrk2"] = [1, 0, 30, 1e9]
    bounds["bjets_nTrk3"] = [1, 0, 30, 1e9]
    bounds["bjets_jvt0"] = [0.02, 0, 1, 1e9]
    bounds["bjets_jvt1"] = [0.02, 0, 1, 1e9]
    bounds["bjets_jvt2"] = [0.02, 0, 1, 1e9]
    bounds["bjets_jvt3"] = [0.02, 0, 1, 1e9]
    bounds["bjets_eta0"] = [0.2, -3, 3, 1e9]
    bounds["bjets_eta1"] = [0.2, -3, 3, 1e9]
    bounds["bjets_eta2"] = [0.2, -3, 3, 1e9]
    bounds["bjets_eta3"] = [0.2, -3, 3, 1e9]
    bounds["mt2"] = [10, 0, 300, 1e9]
    bounds["MDR"] = [10, 0, 300, 1e9]
    bounds["DPB_vSS"] = [0.1, 0, 3.2, 1e9]

    variables = {}
    variables["bjets_n"] =     { 70 : "nBJets70", 77 : "nBJets", 85 : "nBJets85" , 0 : "nBJetsMatched"}
    variables["sjets_n"] =     { 70 : "nSJets70", 77 : "nSJets", 85 : "nSJets85" , 0 : "nSJetsMatched"}
    variables["bjets_pt0"] =   { 70 : "bj70_pt[0]", 77 : "bj_pt[0]", 85 : "bj85_pt[0]", 0 : "bjMatched_pt[0]"}
    variables["bjets_pt1"] =   { 70 : "bj70_pt[1]", 77 : "bj_pt[1]", 85 : "bj85_pt[1]", 0 : "bjMatched_pt[1]" }
    variables["bjets_pt2"] =   { 70 : "bj70_pt[2]", 77 : "bj_pt[2]", 85 : "bj85_pt[2]", 0 : "bjMatched_pt[2]" }
    variables["bjets_pt3"] =   { 70 : "bj70_pt[3]", 77 : "bj_pt[3]", 85 : "bj85_pt[3]", 0 : "bjMatched_pt[3]" }
    variables["bjets_nTrk0"] = { 70 : "bj70_nTrk[0]", 77 : "bj_nTrk[0]", 85 : "bj85_nTrk[0]", 0 : "bjMatched_nTrk[0]" }
    variables["bjets_nTrk1"] = { 70 : "bj70_nTrk[1]", 77 : "bj_nTrk[1]", 85 : "bj85_nTrk[1]", 0 : "bjMatched_nTrk[1]" }
    variables["bjets_nTrk2"] = { 70 : "bj70_nTrk[2]", 77 : "bj_nTrk[2]", 85 : "bj85_nTrk[2]", 0 : "bjMatched_nTrk[2]" }
    variables["bjets_nTrk3"] = { 70 : "bj70_nTrk[3]", 77 : "bj_nTrk[3]", 85 : "bj85_nTrk[3]", 0 : "bjMatched_nTrk[3]" }
    variables["bjets_jvt0"] =  { 70 : "bj70_jvt[0]", 77 : "bj_jvt[0]", 85 : "bj85_jvt[0]" , 0 : "bjMatched_jvt[0]"}
    variables["bjets_jvt1"] =  { 70 : "bj70_jvt[1]", 77 : "bj_jvt[1]", 85 : "bj85_jvt[1]" , 0 : "bjMatched_jvt[1]"}
    variables["bjets_jvt2"] =  { 70 : "bj70_jvt[2]", 77 : "bj_jvt[2]", 85 : "bj85_jvt[2]" , 0 : "bjMatched_jvt[2]"}
    variables["bjets_jvt3"] =  { 70 : "bj70_jvt[3]", 77 : "bj_jvt[3]", 85 : "bj85_jvt[3]" , 0 : "bjMatched_jvt[3]"}
    variables["bjets_eta0"] =  { 70 : "bj70_eta[0]", 77 : "bj_eta[0]", 85 : "bj85_eta[0]", 0 : "bjMatched_eta[0]" }
    variables["bjets_eta1"] =  { 70 : "bj70_eta[1]", 77 : "bj_eta[1]", 85 : "bj85_eta[1]", 0 : "bjMatched_eta[1]" }
    variables["bjets_eta2"] =  { 70 : "bj70_eta[2]", 77 : "bj_eta[2]", 85 : "bj85_eta[2]", 0 : "bjMatched_eta[2]" }
    variables["bjets_eta3"] =  { 70 : "bj70_eta[3]", 77 : "bj_eta[3]", 85 : "bj85_eta[3]", 0 : "bjMatched_eta[3]" }
    variables["mt2"] = { 70 : "mt2", 77 : "mt2", 85 : "mt2", 0 : "mt2" }
    variables["MDR"] = { 70 : "MDR", 77 : "MDR", 85 : "MDR", 0 : "MDR" }
    variables["DPB_vSS"] = { 70 : "DPB_vSS", 77 : "DPB_vSS", 85 : "DPB_vSS", 0 : "DPB_vSS" }

    colors = {}
    colors[70] = 30
    colors[77] = 38
    colors[85] = 46
    colors[0] = r.kBlack

    
    p = plot.Plot1D()
    p.initialize("%s"%str(reg.name), variable, "wp_comp_%s_%s"%(reg.name, variable))
    p.labels(x=nice_names[variable], y = "Events")
    p.xax(bounds[variable][0], bounds[variable][1], bounds[variable][2])
    p.yax(0.1, bounds[variable][3])
    p.doLogY = True
    p.setRatioCanvas(p.name)

    # canvas
    rcan = p.ratioCanvas
    rcan.canvas.cd()
    rcan.upper_pad.cd()

    if p.isLog() : rcan.upper_pad.SetLogy(True)
    rcan.upper_pad.Update()

    # axes
    hax = r.TH1F("axis", "", int(p.nbins), p.x_range_min, p.x_range_max)
    hax.SetMinimum(p.y_range_min)
    hax.SetMaximum(1e9)
    hax.GetXaxis().SetTitle(p.x_label)
    hax.GetXaxis().SetTitleFont(42)
    hax.GetXaxis().SetLabelFont(42)
    hax.GetXaxis().SetLabelSize(0.035)
    hax.GetXaxis().SetTitleOffset(-999)

    hax.GetYaxis().SetTitle(p.y_label)
    hax.GetYaxis().SetTitleFont(42)
    hax.GetYaxis().SetLabelFont(42)
    hax.GetYaxis().SetTitleOffset(1.4)
    hax.GetYaxis().SetLabelOffset(0.013)
    hax.GetYaxis().SetLabelSize(1.2 * 0.035)
    hax.GetYaxis().SetTitleSize(0.055 * 0.85)
    hax.Draw()
    rcan.upper_pad.Update()

    # legend
    leg = pu.default_legend(xl=0.55, yl=0.71, xh=0.93, yh=0.90)

    # hists for different WP
    histos = {}

    working_points = [70, 77, 85, 0]
    for wp in working_points :
        if ("data" in sample.name or "run" in sample.name) and wp==0 : continue
        h = pu.th1f("h_" + variable + "_" + str(wp), "", int(p.nbins), p.x_range_min, p.x_range_max, p.x_label, p.y_label)
        h.SetLineColor(colors[wp])
        if wp == 0 :
            h.SetLineStyle(2)
        h.SetFillStyle(0)
        h.SetLineWidth(2)
        h.GetXaxis().SetLabelOffset(-999)
        h.SetMaximum(1e9)
        h.Sumw2

        weight_str = "eventweight"
        cut = ""

        if wp == 70 :
            reg.tcut += " && nBJets70>0"
        elif wp == 77 :
            reg.tcut += " && nBJets>0"
        elif wp == 85 :
            reg.tcut += " && nBJets85>0"
        elif wp == 0 :
            reg.tcut += " && nBJetsMatched>0"

        if "data" not in sample.name or "run" not in sample.name :
            cut = "(" + reg.tcut + ") * %s * %s"%(weight_str, str(8.42))
        else :
            cut = "(" + reg.tcut + ")"
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>+%s"%(variables[variable][wp], h.GetName()) 
        sample.tree.Draw(cmd, cut * sel, "goff")

        # print the yield +/- stat error

        stat_err = r.Double(0.0)
        integral = h.IntegralAndError(0,-1, stat_err)
        print "%s : %.2f +/- %.2f"%(str(wp), integral, stat_err)

        # add overflow
        pu.add_overflow_to_lastbin(h)

        if wp != 0 :
            leg.AddEntry(h, "%s %s%% MV2c10 WP"%(sample.displayname, str(wp)), "l")
        elif wp==0 and ("data" not in sample.name or "run" not in sample.name) :
            leg.AddEntry(h, "%s 77%% MV2c10 + Truth Match"%sample.displayname, "l")

        histos[wp] = h
        rcan.upper_pad.Update()

     
    r.gPad.SetGrid()
    histos[70].Draw("hist")
    histos[77].Draw("hist same")
    histos[85].Draw("hist same")
    if len(histos)==4 :
        histos[0].Draw("hist same")
    rcan.upper_pad.Update()

    #draw the legend
    leg.Draw()

    # text
    pu.draw_text(text="ATLAS", x=0.18, y =0.85, size=0.06, font=72) 
    pu.draw_text(text="Internal", x=0.325, y =0.85, size =0.06, font=42)
    if not ("run" in sample.name.lower() or "data" in sample.name.lower()) :
        pu.draw_text(text="L = ~27 fb^{-1}, #sqrt{s} = 13 TeV", x=0.18, y=0.79, size=0.04)
    else :
        pu.draw_text(text="L = ~200 pb^{-1}, #sqrt{s} = 13 TeV", x=0.18, y =0.79, size=0.04)
    pu.draw_text(text=reg.displayname, x=0.18, y=0.74, size=0.04)


    r.gPad.SetTickx()
    r.gPad.SetTicky()


    ######## Lower Pad
    rcan.lower_pad.cd()

    #h_den = histos[77].Clone("h_den")

    ## y-axis
    #yax = h_den.GetYaxis()
    #yax.SetRangeUser(0,2)
    #yax.SetTitle("WP X / WP 77%")
    #yax.SetTitleSize(0.1 * 0.83)
    #yax.SetLabelSize(0.1 * 0.81)
    #yax.SetLabelOffset(0.98 * 0.013 * 1.08)
    #yax.SetTitleOffset(0.45*1.2)
    #yax.SetLabelFont(42)
    #yax.SetTitleFont(42)
    #yax.SetNdivisions(5)

    ## x-axis
    #xax = h_den.GetXaxis()
    #xax.SetTitleSize(1.1 * 0.14)
    #xax.SetLabelSize(yax.GetLabelSize())
    #xax.SetLabelOffset(1.15*0.02)
    #xax.SetTitleOffset(0.85*xax.GetTitleOffset())
    #xax.SetLabelFont(42)
    #xax.SetTitleFont(42)

    #h_den.SetTickLength(0.06)
    #h_den.Draw("axis")
    #rcan.lower_pad.Update()


    # 70
    h_70 = histos[70].Clone("h70")
    # y-axis
    yax = h_70.GetYaxis()
    #yax.SetRangeUser(0,2)
    yax.SetTitle("WP X / WP 77%")
    yax.SetTitleSize(0.1 * 0.83)
    yax.SetLabelSize(0.1 * 0.81)
    yax.SetLabelOffset(0.98 * 0.013 * 1.08)
    yax.SetTitleOffset(0.45*1.2)
    yax.SetLabelFont(42)
    yax.SetTitleFont(42)
    yax.SetNdivisions(5)

    # x-axis
    xax = h_70.GetXaxis()
    xax.SetTitleSize(1.0 * 0.14)
    xax.SetLabelSize(yax.GetLabelSize())
    xax.SetLabelOffset(1.15*0.02)
    xax.SetTitleOffset(0.85*xax.GetTitleOffset())
    xax.SetLabelFont(42)
    xax.SetTitleFont(42)


    h_77 = histos[77].Clone("h77")
    h_85 = histos[85].Clone("h85")

    h_70.GetYaxis().SetRangeUser(0,5)
    h_77.GetYaxis().SetRangeUser(0,5)
    h_85.GetYaxis().SetRangeUser(0,5)
    h_70.SetNdivisions(5)
    h_77.SetNdivisions(5)
    h_85.SetNdivisions(5)

    h_70.Divide(h_77)
    h_85.Divide(h_77)

    h_70.Draw("hist")
    h_85.Draw("hist same")

    if len(histos) == 4 :
        h_0 = histos[0].Clone("h0")
        h_0.GetYaxis().SetRangeUser(0,5)
        h_0.SetNdivisions(5)
        h_0.Divide(h_77)
        h_0.Draw("hist same")
    rcan.lower_pad.Update()

    # lines
    pu.draw_line(p.x_range_min, 1.0, p.x_range_max, 1.0, color=r.kRed, style=2, width=1)

    # save
    outname = p.name + "_" + sample.name + ".eps"
    rcan.canvas.SaveAs(outname)
    out = "./bjet_check_plots/"
    utils.mv_file_to_dir(outname, out, True)
    fullname = out + "/" + outname
    print "%s saved to : %s"%(outname, os.path.abspath(fullname))
def make_MDR_nm1_plot(reg, backgrounds, data) :

    print "make_MDR_nm1_plot    %s"%reg.name

    #mdr_nice = "E_{V}^{P} [GeV]"
    mdr_nice = "M_{#Delta}^{R} [GeV]"

    p = plot.Plot1D()
    p.initialize(reg.name, "MDR", "%s_MDR"%(reg.name))
    p.labels(x=mdr_nice, y = "Entries")
    if reg.name == "srwNM1" :
        p.yax(0.1, 10000)
    elif reg.name == "srwNM1SF" :
        p.yax(0.1, 20000)
    elif reg.name == "srtNM1" :
        p.yax(0.1, 50000)
    elif reg.name == "srtNM1SF" :
        p.yax(0.1, 50000)
    p.doLogY = True
    p.setRatioCanvas(p.name)

    ### canvas get
    rcan = p.ratioCanvas
    rcan.canvas.cd()
    rcan.upper_pad.cd()

    if p.isLog() : rcan.upper_pad.SetLogy(True)
    rcan.upper_pad.Update()

    binlow = []
    if reg.name == "srwNM1":
        binlow = [80,95,110,130,150,180]#100,140]#,130]#,130]#75,90,110,130,160]
    elif reg.name == "srwNM1SF" :
        binlow = [80,95,110,130,150,180]
        #binlow = [80,95,110,130,150,180,200]
    elif reg.name == "srtNM1" :
        binlow = [70,80,95,110,130,150,180]#100,140]#,130]#,130]#75,90,110,130,160]
    elif reg.name == "srtNM1SF" :
        binlow = [70,80,95,110,130,150,180]
        #binlow = [70,80,95,110,130,150,180,200]
        #binlow = [70,80,90,100,110,120,130,140,150,160,170,180,200]

    hax = r.TH1F("axes", "", len(binlow)-1, array('d',binlow))
    hax.SetMinimum(p.y_range_min)
    hax.SetMaximum(p.y_range_max)
    hax.GetXaxis().SetTitle(p.x_label)
    hax.GetXaxis().SetTitleFont(42)
    hax.GetXaxis().SetLabelFont(42)
    hax.GetXaxis().SetLabelSize(0.035)
    hax.GetXaxis().SetTitleSize(0.048 * 0.85)
    hax.GetXaxis().SetTitleOffset(-999)
    hax.GetXaxis().SetLabelOffset(-999)

    hax.GetYaxis().SetTitle(p.y_label)
    hax.GetYaxis().SetTitleFont(42)
    hax.GetYaxis().SetLabelFont(42)
    hax.GetYaxis().SetTitleOffset(1.4)
    hax.GetYaxis().SetLabelOffset(0.013)
    hax.GetYaxis().SetLabelSize(1.2 * 0.035)
    hax.GetYaxis().SetTitleSize(0.055 * 0.85)
    hax.Draw()
    rcan.upper_pad.Update()

    stack = r.THStack("stack_"+p.name,"")

    # legend
    leg = pu.default_legend(xl=0.55,yl=0.71,xh=0.93,yh=0.90)
    #leg = pu.default_legend(xl=0.55,yl=0.65,xh=0.93,yh=0.90)
    leg.SetNColumns(2)

    # histos
    histos = []
    h_nom_fake = None

    n_total_sm_yield = 0.
    for b in backgrounds :
        if b.isSignal() : continue
        if "data" in b.name.lower() : continue
        hist_name = "MDR"
        h = r.TH1F("h_" + b.treename+"_"+hist_name, "", len(binlow)-1, array('d',binlow))
        font = 42
        h.SetTitleFont(font)

        #x-axis
        xx = h.GetXaxis()
        xx.SetTitle(p.x_label)
        xx.SetTitleOffset(1.2*xx.GetTitleOffset())
        xx.SetTitleFont(font)
        xx.SetLabelFont(font)

        #y-axis
        yy = h.GetYaxis()
        yy.SetTitle(p.y_label)
        yy.SetTitleOffset(1.2*yy.GetTitleOffset())
        yy.SetTitleFont(font)
        yy.SetLabelFont(font)

        h.Sumw2()

        h.SetLineColor(b.color) # stop2L people have no sense
        #h.SetLineColor(r.kBlack)
        h.GetXaxis().SetLabelOffset(-999)
        h.SetFillColor(b.color)
        h.SetFillStyle(1001)

        # cuts
        weight_str = ""
        if "fakes" in b.name :
            weight_str = "FakeWeight"
        else :
            weight_str = "eventweight"

        norm_factor = "1"
        if "ttbar" in b.name :
            norm_factor = "0.99"
        elif "vv" in b.name  and "SF" in reg.name :
            norm_factor = "1.23"
        elif "vv" in b.name and "SF" not in reg.name :
            norm_factor = "1.27"
        cut = "(" + reg.tcut + ") * %s * %s * %s"%(weight_str, str(b.scale_factor), norm_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>+%s"%(p.variable, h.GetName())
        blah = b.tree.Draw(cmd, cut * sel, "goff")

        # print yields
        stat_err = r.Double(0.0)
        integral = h.IntegralAndError(0,-1,stat_err)
        n_total_sm_yield += float(integral)
        print "%s: %.2f +/- %.2f"%(b.name, integral, stat_err)

        # get variation histos
        if doSys and 'fakes' not in b.name and (integral>0)  : getSystHists(p, reg, b, integral, h)
        #if doSys and 'fakes' not in b.name and (integral>0) and "zjets" not in b.name : getSystHists(p, reg, b, integral, h)

        # add overflow
        pu.add_overflow_to_lastbin(h)

        # set negative bin yields to 0
        for ibin in xrange(h.GetXaxis().GetNbins()) :
            if h.GetBinContent(ibin+1) < 0. :
                print "Setting bin %d for %s to 0"%(ibin, b.name)
                h.SetBinContent(ibin+1, 0)
                h.SetBinError(ibin+1,0)

        if "fakes" in b.name :
            h_nom_fake = h.Clone("fakes_nominal_histo")

        leg.AddEntry(h, b.displayname, "f")
        if integral > 0 :
            histos.append(h)
        rcan.upper_pad.Update()


    # order the histos
    histos = sorted(histos, key=lambda h: h.Integral(), reverse=False)
    for h in histos :
        stack.Add(h)
    rcan.upper_pad.Update()
    #hist_sm = stack.GetStack().Last().Clone("hist_sm")
        

    # now get the data points
    hd = r.TH1F("h_data_"+reg.name,"", len(binlow)-1, array('d',binlow))
    hd.Sumw2()
    cut = "(" + reg.tcut + ")"
    cut = r.TCut(cut)
    sel = r.TCut("1")
    cmd = "%s>>+%s"%(p.variable, hd.GetName()) 
    data.tree.Draw(cmd, cut * sel, "goff")
    hd.GetXaxis().SetLabelOffset(-999)

    print "Total SM: %.2f"%(n_total_sm_yield)

    # print yeild +/- stat err
    stat_err = r.Double(0.0)
    integral = hd.IntegralAndError(0,-1,stat_err)
    print "Data: %.2f +/- %.2f"%(integral, stat_err)
    pu.add_overflow_to_lastbin(hd)

    gdata = pu.convert_errors_to_poisson(hd)
    gdata.SetLineWidth(2)
    gdata.SetMarkerStyle(20)
    gdata.SetMarkerSize(1.5)
    #gdata.SetMarkerSize(1.1)
    gdata.SetLineColor(1)
    leg.AddEntry(gdata, "Data", "p")
    rcan.upper_pad.Update()
    
    #############################
    # systematics loop
    r.gStyle.SetHatchesSpacing(0.9)

    # dummy histo for legend
    mcError = r.TH1F("mcError", "mcError", 2,0,2)
    mcError.SetFillStyle(3354)
    mcError.SetFillColor(r.kBlack)
    mcError.SetLineColor(r.TColor.GetColor("#FC0F1D"))
    mcError.SetLineWidth(3)
    leg.AddEntry(mcError, "Total SM", "fl")

    # histogram for total stack
    totalSM = stack.GetStack().Last().Clone("totalSM")
    nominalAsymErrors = pu.th1_to_tgraph(totalSM)
    nominalAsymErrors.SetMarkerSize(0)
    nominalAsymErrors.SetLineWidth(0)
    nominalAsymErrors.SetFillStyle(3354)
    nominalAsymErrors.SetFillColor(r.kGray + 3)
   # leg.AddEntry(nominalAsymErrors, "Bkg. Uncert.", "f")


    tmp = []
    backgrounds_original = backgrounds
    for b in backgrounds :
        if "bwn" in b.name : continue
        if "fakes" in b.name : continue
        #if "zjets" in b.name : continue
        tmp.append(b)
    backgrounds = tmp
    if doSys :
        # totalSystHisto will hold each samples'
        # variation
        totalSysHisto = totalSM.Clone()
        totalSysHisto.Reset("ICE")
        transient = r.TGraphAsymmErrors()

        # add to the error band the contribution from the up-variations 
        systematics_up = [s.up_name for s in backgrounds[0].systList]
        for up_sys in systematics_up :

            new_name = ""
            if "syst_" in up_sys :
                new_name = "syst_" + up_sys.replace("syst_","")
            else :
                new_name = up_sys
            up_sys = new_name

            transient = r.TGraphAsymmErrors()
            transient.Clear()
            for b in backgrounds :
                #if b.name in avoid_bkg : continue
                #if "zjets" in b.name : continue
                if "bwn" in b.name : continue
                if b.isSignal() : continue
                if 'fakes' in b.name : continue
                for syst in b.systList :
                    if "EG_SCALE_ALL" in syst.up_name  and "zjets" in b.name : continue

                    new_name = ""
                    if "syst_" in syst.up_name :
                        new_name = "syst_" + syst.up_name.replace("syst_","")
                    else :
                        new_name = syst.up_name
                    syst.up_name = new_name

                    if syst.up_name != up_sys : continue
                    #print "[%s] adding %s to up histo : %.2f (%.2f)"%(up_sys, b.name, syst.up_histo.Integral(), totalSM.Integral())
                    totalSysHisto.Add(syst.up_histo)
            if h_nom_fake :
                totalSysHisto.Add(h_nom_fake)
            transient = pu.th1_to_tgraph(totalSysHisto)
            #print " > %s: %s"%(b.name, up_sys)
            pu.add_to_band(transient, nominalAsymErrors)#, up_sys)
            totalSysHisto.Reset()

        # add to the error band the contribution from the down-variations
        systematics_down = [s.down_name for s in backgrounds[0].systList]
        for dn_sys in systematics_down :

            new_name = ""
            if "syst_" in dn_sys :
                new_name = "syst_" + dn_sys.replace("syst_","")
            else :
                new_name = dn_sys
            dn_sys = new_name

            transient = r.TGraphAsymmErrors()
            transient.Clear()
            for b in backgrounds :
                #if "zjets" in b.name : continue
                if "bwn" in b.name : continue
                #if b.name in avoid_bkg : continue
                if b.isSignal() : continue
                if 'fakes' in b.name : continue
                for syst in b.systList :
                    if "EG_SCALE_ALL" in syst.down_name  and "zjets" in b.name : continue

                    new_name = ""
                    if "syst_" in syst.down_name :
                        new_name = "syst_" + syst.down_name.replace("syst_","")
                    else :
                        new_name = syst.down_name
                    syst.down_name = new_name

                    if syst.down_name != dn_sys : continue
                    #print "[%s] adding %s to down histo : %.2f"%(dn_sys, b.name, syst.down_histo.Integral())
                   # if syst.isOneSided() : continue

                   # if "JER" in syst.name : continue
                   # if "ResoPerp" in syst.name or "ResoPara" in syst.name : continue
                    totalSysHisto.Add(syst.down_histo)
            if h_nom_fake :
                totalSysHisto.Add(h_nom_fake)
            transient = pu.th1_to_tgraph(totalSysHisto)
            #print " > %s: %s"%(b.name, dn_sys)
            pu.add_to_band(transient, nominalAsymErrors)#, dn_sys)
            totalSysHisto.Reset()

    # draw mc stack
    stack.Draw("HIST SAME")
    stack.SetMinimum(p.y_range_min)
    stack.SetMaximum(p.y_range_max)
    rcan.upper_pad.Update()

    # draw the error band
    nominalAsymErrors.Draw("same && E2")
    
    # draw the total bkg line
    hist_sm = stack.GetStack().Last().Clone("hist_sm")
    hist_sm.SetLineColor(r.TColor.GetColor("#FC0F1D"))
    hist_sm.SetLineWidth(mcError.GetLineWidth())
    hist_sm.SetLineStyle(1)
    hist_sm.SetFillStyle(0)
    hist_sm.Draw("hist same")


    ####################################
    # plot signal
    leg_sig = pu.default_legend(xl=0.55,yl=0.56,xh=0.91,yh=0.71)
    #leg_sig = pu.default_legend(xl=0.55,yl=0.35,xh=0.93,yh=0.60)
    leg_sig.SetNColumns(1)
    sig_histos = []
    for s in backgrounds_original :
        if not s.isSignal() : continue
        hist_name = "MDR"
        h = r.TH1F("h_" + b.treename+"_"+hist_name, "", len(binlow)-1, array('d',binlow))
        h.SetLineWidth(2)
        h.SetLineStyle(2)
        h.SetLineColor(s.color)
        h.GetXaxis().SetLabelOffset(-999)
        h.SetFillStyle(0)
        h.Sumw2()

        # cut and make the sample weighted, applying the scale_factor
        cut = "(" + reg.tcut + ") * eventweightNOPUPW * susy3BodyRightPol *" + str(s.scale_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>+%s"%(p.variable, h.GetName())
        s.tree.Draw(cmd, cut * sel, "goff")

        # print the yield +/- stat error
        stat_err = r.Double(0.0)
        integral = h.IntegralAndError(0,-1,stat_err)
        print "%s: %.2f +/- %.2f"%(s.name, integral, stat_err)
        
        # add overflow
        pu.add_overflow_to_lastbin(h)

        #h_dummy = r.TH1F("dummy","",2,0,2)
        #h_dummy.SetFillStyle(1001)
        #h_dummy.SetFillColor(r.kWhite)
        #h_dummy.SetLineColor(r.kWhite)

        leg_sig.AddEntry(h, s.displayname, "l")
        #leg_sig.AddEntry(h_dummy, "", "fl")
        sig_histos.append(h)
        rcan.upper_pad.Update()

    # draw the signals
    for hsig in sig_histos :
        hsig.Draw("hist same")

    # draw the dta graph
    gdata.Draw("option same pz 0")
    leg.Draw()
    leg_sig.Draw()
    r.gPad.RedrawAxis()

    # add some text/labels
    #pu.draw_text(text="#it{ATLAS} Preliminary",x=0.18,y=0.85, size=0.06)
    pu.draw_text(text="ATLAS",x=0.18,y=0.85,size=0.06,font=72)
    pu.draw_text(text="Preliminary",x=0.325,y=0.85,size=0.06,font=42)
    pu.draw_text(text="L = 13.3 fb^{-1}, #sqrt{s} = 13 TeV",x=0.18,y=0.79, size=0.04)
    pu.draw_text(text=reg.displayname,      x=0.18,y=0.74, size=0.04)

    r.gPad.SetTickx()
    r.gPad.SetTicky()

    rcan.canvas.Update()

    ########################################
    # lower pad
    ########################################
    rcan.lower_pad.cd()

    # get the total SM histo
    h_sm = stack.GetStack().Last().Clone("h_sm")

    # yaxis
    yax = h_sm.GetYaxis()
    yax.SetRangeUser(0,2)
    yax.SetTitle("Data/SM")
    
    yax.SetTitleSize(0.14 * 0.83)
    yax.SetLabelSize(0.13 * 0.81)
    yax.SetLabelOffset(0.98 * 0.013 * 1.08)
    yax.SetTitleOffset(0.45 * 1.2)
    yax.SetLabelFont(42)
    yax.SetTitleFont(42)
    yax.SetNdivisions(5) 

#    print "title size: ", yax.GetTitleSize()
#    print "label size : ", yax.GetLabelSize()
#    print "lab off      : ", yax.GetLabelOffset()
#    print "title off        : ", yax.GetTitleOffset()
    
    # xaxis
    xax = h_sm.GetXaxis()
    xax.SetTitleSize(1.1 * 0.14)
    xax.SetLabelSize(yax.GetLabelSize())
    #xax.SetLabelSize(0.13)
    xax.SetLabelOffset(1.15*0.02)
    xax.SetTitleOffset(0.85 * xax.GetTitleOffset())
    xax.SetLabelFont(42)
    xax.SetTitleFont(42)
   
    h_sm.SetTickLength(0.06)
    h_sm.Draw("AXIS")
    
    rcan.lower_pad.Update()

    # get the ratio-error band
    ratioBand = r.TGraphAsymmErrors(nominalAsymErrors)
    pu.buildRatioErrorBand(nominalAsymErrors, ratioBand)

    # draw lines
    pu.draw_line(binlow[0], 1.0, binlow[-1], 1.0,color=r.kRed,style=2,width=1)
    pu.draw_line(binlow[0], 0.5, binlow[-1], 0.5,style=3,width=1)
    pu.draw_line(binlow[0], 1.5, binlow[-1], 1.5,style=3,width=1)

    # convert to tgraphs to get the ratio
    #g_data = pu.th1_to_tgraph(hd)
    g_data = pu.convert_errors_to_poisson(hd)
    #g_data = gdata
    g_sm = pu.th1_to_tgraph(h_sm)
    g_ratio = pu.tgraphAsymmErrors_divide(g_data, g_sm)

    # For Data/MC only use the statistical error for data
    # since we explicity draw the MC error band
    nominalAsymErrorsNoSys = r.TGraphAsymmErrors(nominalAsymErrors)
    for i in xrange(nominalAsymErrorsNoSys.GetN()) :
        nominalAsymErrorsNoSys.SetPointError(i,0,0,0,0)
        #nominalAsymErrorsNoSys.SetPointError(i-1,0,0,0,0)
    ratio_raw = pu.tgraphAsymmErrors_divide(g_data, nominalAsymErrorsNoSys)
    ratio = r.TGraphAsymmErrors() 

    x1, y1 = r.Double(0.0), r.Double(0.0)
    index = 0
    for i in xrange(ratio_raw.GetN()) :
        ratio_raw.GetPoint(i, x1, y1)
       # print "raw: (i, x, y) = (%d, %f, %f)"%(int(i),float(x1),float(y1))
       # xx, yy = r.Double(0.0), r.Double(0.0)
       # xn, yn = r.Double(0.0), r.Double(0.0)
       # xg, yg = r.Double(0.0), r.Double(0.0)
       # g_data.GetPoint(i, xx, yy)
       # nominalAsymErrorsNoSys.GetPoint(i, xn, yn)
       # g_sm.GetPoint(i, xg, yg)
       # print "gdata: (i, x, y) = (%d, %f, %f)"%(int(i),float(xx),float(yy))
       # print "nomAs: (i, x, y) = (%d, %f, %f)"%(int(i),float(xn),float(yn))
       # print "g_sm : (i, x, y) = (%d, %f, %f)"%(int(i),float(xg),float(yg))
        x_, y_ = r.Double(0.0), r.Double(0.0)
        xx, yy = r.Double(0.0), r.Double(0.0)
        xr, yr = r.Double(0.0), r.Double(0.0)
        g_data.GetPoint(i, x_, y_)
        gdata.GetPoint(i, xx, yy)
        g_ratio.GetPoint(i, xr, yr)
        print "gdata   (%f,%f) EYH : %f    EYL: %f"%(xx, yy, gdata.GetErrorYhigh(i), gdata.GetErrorYlow(i))
        print "g_data  (%f,%f) EYH : %f    EYL: %f"%(x_, y_, g_data.GetErrorYhigh(i), g_data.GetErrorYlow(i)) 
        print "g_ratio (%f,%f) EYH: %f    EYL: %f"%(xr, yr, g_ratio.GetErrorYhigh(i), g_ratio.GetErrorYlow(i))
        print 50*"-"
        if y1 > 0. :
            ratio.SetPoint(index, x1, y1)
            ratio.SetPointError(index, ratio_raw.GetErrorXlow(i), ratio_raw.GetErrorXhigh(i), ratio_raw.GetErrorYlow(i), ratio_raw.GetErrorYhigh(i))
            index+=1
    #print "SETTING RATIO_RAW TO RATIO"
    #ratio = ratio_raw
    ratio.SetLineWidth(2)
    ratio.SetMarkerStyle(20)
    ratio.SetMarkerSize(1.5)
    #ratio.SetMarkerSize(1.1)
    ratio.SetLineColor(1)
    ratio.SetMarkerSize(1.5)
    ratio.Draw("option pz 0")
    rcan.lower_pad.Update()

    ratioBand.Draw("same && E2")
    rcan.lower_pad.Update()
    



    #########################################
    # save
    #########################################
    outname = p.name + "_prelim.eps"
    rcan.canvas.SaveAs(outname)
    out = indir + "/plots/" + outdir
    utils.mv_file_to_dir(outname, out, True)
    fullname = out + "/" + outname
    print "%s saved to : %s"%(outname, os.path.abspath(fullname))
Exemple #5
0
def make_ttbar_comp_plots(var, region, samples) :
    print 50*"-"
    print "Making ttbar comparison plots, variable: %s"%var.name


    p = plot.Plot1D()
    p.initialize("%s"%str(region.name), var.name, "ttbar_comp_%s_%s"%(region.name, var.name))
    p.labels(x=var.nice_name, y = "Arb. Units")
    p.xax(var.bounds[reg.name][0], var.bounds[reg.name][1], var.bounds[reg.name][2])
    p.yax(0.1, var.bounds[reg.name][3])
    p.doLogY = True
    p.setRatioCanvas(p.name)

    # canvas
    rcan = p.ratioCanvas
    rcan.canvas.cd()
    rcan.upper_pad.cd()

    if p.isLog() : rcan.upper_pad.SetLogy(True)
    rcan.upper_pad.Update()

    # axes
    hax = r.TH1F("axis", "", int(p.nbins), p.x_range_min, p.x_range_max)
    hax.SetMinimum(p.y_range_min)
    hax.SetMaximum(10000)
    hax.GetXaxis().SetTitle(var.nice_name)
    hax.GetXaxis().SetTitleFont(42)
    hax.GetXaxis().SetLabelFont(42)
    hax.GetXaxis().SetLabelSize(0.035)
    hax.GetXaxis().SetTitleOffset(-999)

    hax.GetYaxis().SetTitle(p.y_label)
    hax.GetYaxis().SetTitleFont(42)
    hax.GetYaxis().SetLabelFont(42)
    hax.GetYaxis().SetTitleOffset(1.4)
    hax.GetYaxis().SetLabelOffset(0.013)
    hax.GetYaxis().SetLabelSize(1.2 * 0.035)
    hax.GetYaxis().SetTitleSize(0.055 * 0.85)
    hax.Draw()
    rcan.upper_pad.Update()

    # legend
    leg = pu.default_legend(xl=0.55, yl=0.71, xh=0.93, yh=0.90)

    # histos
    histos_tmp = {}
    display_names = {}
    samples_for_order = ["nominal", "sherpa", "mgp"]
    colors = {}
    for s in samples :
        h = pu.th1f("h_" + var.name + "_" + str(s.name), "", int(p.nbins), p.x_range_min, p.x_range_max, p.x_label, p.y_label)
        h.SetLineColor(s.color)
        h.SetFillStyle(0)
        h.SetLineWidth(2)
        h.GetXaxis().SetLabelOffset(-999)
        h.SetMaximum(10000)
        h.Sumw2

        display_names[s.name] = s.displayname
        colors[s.name] = s.color

        lumi_scale = 8.42 # not neeed for normalized distributions
        weight_str = "eventweight * %s"%lumi_scale

        cut = "(" + region.tcut + ") * %s"%weight_str
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>+%s"%(var.name, h.GetName())
        s.tree.Draw(cmd, cut * sel, "goff") 

        #print yield stuffs
        stat_err = r.Double(0.0)
        integral = h.IntegralAndError(0,-1,stat_err)
        print "%s : %.2f +/- %.2f"%(s.name, integral, stat_err) 


        # add overflow
        pu.add_overflow_to_lastbin(h)

        # norm to unity
        h.Scale(1/h.Integral())

        histos_tmp[s.name] = h
        rcan.upper_pad.Update()

    r.gPad.SetGrid()

    histos = {}
    for sname in samples_for_order :
        for sn, hist in histos_tmp.iteritems() :
            if sn == sname :
                histos[sname] = hist 
                leg.AddEntry(hist, display_names[sname], "l")

    histos["nominal"].Draw("hist")
    histos["sherpa"].Draw("hist same")
    histos["mgp"].Draw("hist same")

    # draw the legend
    leg.Draw()


    ############### lower pad
    rcan.lower_pad.cd()

    # nom
    h_nom = histos["nominal"].Clone("nominal")
    # sherpa
    h_sherpa = histos["sherpa"].Clone("sherpa")
    # mgpythia
    h_mgp = histos["mgp"].Clone("mgp")

    # y-axis
    yax = h_sherpa.GetYaxis()
    yax.SetTitle("Other/Nominal")
    yax.SetTitleSize(0.1 * 0.83)
    yax.SetLabelSize(0.1 * 0.81)
    yax.SetLabelOffset(0.98 * 0.013 * 1.08)
    yax.SetTitleOffset(0.45 * 1.2)
    yax.SetLabelFont(42)
    yax.SetTitleFont(42)
    yax.SetNdivisions(5)

    # x-axis
    xax = h_sherpa.GetXaxis()
    xax.SetTitleSize(1.0 * 0.14)
    xax.SetLabelSize(yax.GetLabelSize())
    xax.SetLabelOffset(1.15 * 0.02)
    xax.SetTitleOffset(0.85 * xax.GetTitleOffset())
    xax.SetLabelFont(42)
    xax.SetTitleFont(42)

    h_nom.GetYaxis().SetRangeUser(0,5)
    h_sherpa.GetYaxis().SetRangeUser(0,5)
    h_mgp.GetYaxis().SetRangeUser(0,5)
    h_nom.SetNdivisions(5)
    h_sherpa.SetNdivisions(5)
    h_mgp.SetNdivisions(5)

    h_sherpa.Divide(h_nom)
    h_mgp.Divide(h_nom)

    maxy_ = 5
    if "bj_pt[0]" in var.name or "bj_pt[1]" in var.name:
        maxy_ = 2
    elif "bj_pt[2]" in var.name :
        maxy_ = 3
    elif "nBJets" in var.name :
        maxy_ = 2
    elif "nSJets" in var.name :
        maxy_ = 3
    elif "eta" in var.name :
        maxy_ = 2
    elif "dphi_ll" in var.name or "pTll" in var.name :
        maxy_ = 2
    elif "l_pt" in var.name :
        maxy_ = 2
    elif "meff" in var.name or "met" in var.name :
        maxy_ = 2
    elif "sj_pt" in var.name :
        maxy_ = 2

    h_sherpa.GetYaxis().SetRangeUser(0,maxy_)
    h_mgp.GetYaxis().SetRangeUser(0,maxy_)

    h_sherpa.SetMarkerStyle(20)
    h_sherpa.SetMarkerColor(colors["sherpa"])
    h_mgp.SetMarkerStyle(20)
    h_mgp.SetMarkerColor(colors["mgp"])

    h_sherpa.Draw("pe")
    h_mgp.Draw("pe same")

    rcan.lower_pad.Update()

    # lines
    pu.draw_line(p.x_range_min, 1.0, p.x_range_max, 1.0, color=r.kRed, style=2, width=1)


    # save
    outname = p.name + ".eps"
    rcan.canvas.SaveAs(outname)
    out = "./ttbar_comp_plots/"
    utils.mv_file_to_dir(outname, out, True)
    fullname = out + "/" + outname
    print "%s saved to : %s"%(outname, os.path.abspath(fullname))
Exemple #6
0
def make_nVtxEffPlot(plt, reg, data, bkgs):

    print "make_nVtxEffPlot..."

    if plt.variable != "nVtx":
        print "make_nVtxEffPlot ERROR    You may only provide plots setup to plot nVtx!"
        print "make_nVtxEffPlot ERROR    This plot is configured to plot %s" % plt.variable
        sys.exit()

    r.gStyle.SetOptStat(0000)
    r.gStyle.SetOptFit(0111)

    # get the canvas
    c = plt.canvas
    c.cd()
    c.SetFrameFillColor(0)
    c.SetFillColor(0)
    c.SetLeftMargin(0.14)
    c.SetRightMargin(0.05)
    c.SetBottomMargin(1.3 * c.GetBottomMargin())

    c.Update()

    ## stack for MC with selection
    stack = r.THStack("stack_" + plt.name, "")

    ## get MC histos with region selection applied
    histos = []

    print "make_nVtxEffPlot    Getting histograms with selection applied (%s)" % reg.name
    for b in bkgs:
        print "    > %s" % b.name
        hist_name = plt.variable

        h = pu.th1f(
            "h_" + b.treename + "_" + hist_name,
            "",
            int(plt.nbins),
            plt.x_range_min,
            plt.x_range_max,
            plt.x_label,
            plt.y_label,
        )
        h.SetLineColor(b.color)
        h.SetLineColor(r.kBlack)
        h.SetMarkerSize(1.2 * h.GetMarkerSize())
        h.SetMarkerStyle(20)
        h.SetLineWidth(2)
        h.SetLineStyle(b.line_style)
        h.SetFillColor(0)
        h.Sumw2

        weight_str = ""
        if b.isSignal():
            weight_str = "eventweightNOPUPW * susy3BodyRightPol"
        else:
            print " **** NOT APPLYING PRW TO MC ***** "
            weight_str = "eventweightNOPUPW"
        cut = "(" + reg.tcut + ") * %s *" % weight_str + str(b.scale_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>+%s" % (plt.variable, h.GetName())
        b.tree.Draw(cmd, cut * sel)

        pu.add_overflow_to_lastbin(h)

        histos.append(h)
        c.Update()

    histos = sorted(histos, key=lambda h: h.Integral(), reverse=False)
    for h in histos:
        stack.Add(h)

    ## stack for MC withi NO selection
    stack_nosel = r.THStack("stack_" + plt.name + "_nosel", "")

    ## get the MC histos with no selection applied
    histos_nosel = []

    print "make_nVtxEffPlot    Getting histograms with NO selection applied (%s)" % reg.name
    for b in bkgs:
        print "    > %s" % b.name
        hist_name = plt.variable

        h = pu.th1f(
            "h_" + b.treename + "_" + hist_name + "_nosel",
            "",
            int(plt.nbins),
            plt.x_range_min,
            plt.x_range_max,
            plt.x_label,
            plt.y_label,
        )
        h.SetLineColor(b.color)
        h.SetMarkerStyle(20)
        h.SetMarkerSize(1.2 * h.GetMarkerSize())
        h.SetLineColor(r.kBlack)
        h.SetLineWidth(2)
        h.SetLineStyle(b.line_style)
        h.SetFillColor(0)
        h.Sumw2

        weight_str = ""
        if b.isSignal():
            weight_str = "eventweightNOPUPW * susy3BodyRightPol"
        else:
            print " **** NOT APPLYING PRW TO MC ***** "
            weight_str = "eventweightNOPUPW"
        # cut = "(" + reg.tcut + ") * %s *"%weight_str + str(b.scale_factor)
        cut = "1"
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>+%s" % (plt.variable, h.GetName())
        b.tree.Draw(cmd, cut * sel)

        pu.add_overflow_to_lastbin(h)

        histos_nosel.append(h)
        c.Update()

    histos_nosel = sorted(histos_nosel, key=lambda h: h.Integral(), reverse=False)
    for h in histos_nosel:
        stack_nosel.Add(h)

    ### total MC with selection
    totalSM = stack.GetStack().Last().Clone("totalSM")
    ### total MC with no selection
    totalSM_nosel = stack_nosel.GetStack().Last().Clone("totalSM_nosel")

    # c.SetMaximum(5)
    # c.SetMinimum(0)
    # c.Update()

    h_den = totalSM_nosel.Clone("h_den")
    h_num = totalSM.Clone("h_num")

    h_num.Divide(h_den)

    # axes
    hax = r.TH1F("axes", "", int(plt.nbins), plt.x_range_min, plt.x_range_max)
    hax.SetMinimum(0)
    hax.SetMaximum(1.2 * h_num.GetMaximum())
    hax.GetXaxis().SetTitle("Number of Primary Vertices")
    hax.GetXaxis().SetTitleFont(42)
    hax.GetXaxis().SetLabelFont(42)
    hax.GetXaxis().SetLabelSize(0.035)
    hax.GetXaxis().SetTitleSize(0.048 * 0.85)

    hax.GetYaxis().SetTitle("%s Selection Efficiency" % reg.displayname)
    hax.GetYaxis().SetTitleFont(42)
    hax.GetYaxis().SetLabelFont(42)
    hax.GetYaxis().SetTitleOffset(1.4)
    hax.GetYaxis().SetLabelOffset(0.013)
    hax.GetYaxis().SetLabelSize(1.2 * 0.035)
    hax.GetYaxis().SetTitleSize(0.055 * 0.85)
    hax.Draw("axis")

    c.Update()

    h_num.Draw("p0 e same")
    h_num.GetXaxis().SetTitle("Number of Primary Vertices")
    h_num.GetXaxis().SetTitleFont(42)
    h_num.GetXaxis().SetLabelFont(42)
    h_num.GetXaxis().SetLabelSize(0.035)
    h_num.GetXaxis().SetTitleSize(0.048 * 0.85)
    h_num.GetYaxis().SetTitle("%s Selection Efficiency" % reg.displayname)
    h_num.GetYaxis().SetTitleFont(42)
    h_num.GetYaxis().SetLabelFont(42)
    h_num.GetYaxis().SetTitleOffset(1.35)
    h_num.GetYaxis().SetLabelOffset(0.013)
    h_num.GetYaxis().SetLabelSize(1.2 * 0.035)
    h_num.GetYaxis().SetTitleSize(0.055 * 0.85)
    c.Update()
    h_num.Fit("pol1")
    r.gStyle.SetOptFit(0111)
    c.Update()
    h_num.Draw()
    # ps = r.gStyle.GetListOfFunctions().FindObject("stats");
    # ps.SetX1NDC(0.15);
    # ps.SetX2NDC(0.6);
    # c.Modified();
    # c.Update();
    r.gStyle.SetStatX(0.58)
    r.gStyle.SetStatY(0.85)
    c.Update()

    c.SaveAs("eff_nVtx_%s.eps" % reg.name)
def getSystHists(plot, reg, b, nom_yield, nom_hist) :
    for s in b.systList :
        hist_name = "MDR"
        h_up = nom_hist.Clone("h_"+b.treename+"_"+hist_name+"_"+s.name+"_up")
        h_dn = nom_hist.Clone("h_"+b.treename+"_"+hist_name+"_"+s.name+"_dn")

        h_up.SetMinimum(plot.y_range_min)
        h_up.SetMaximum(plot.y_range_max)
        h_up.GetXaxis().SetLabelOffset(-999)
        h_up.GetXaxis().SetTitleOffset(-999)
        h_dn.SetMinimum(plot.y_range_min)
        h_dn.SetMaximum(plot.y_range_max)
        h_dn.GetXaxis().SetLabelOffset(-999)
        h_dn.GetXaxis().SetTitleOffset(-999)

        for hsys in [h_up, h_dn] :
            yax = hsys.GetYaxis()
            xax = hsys.GetXaxis()

            yax.SetTitleSize(0.05)
            yax.SetLabelSize(0.045)
            yax.SetLabelOffset(0.008)
            yax.SetTitleOffset(1.2)
            yax.SetLabelFont(42)
            yax.SetTitleFont(42)
            yax.SetNdivisions(5) 
        
        if s.isWeightSys() :
            name_up = s.up_name
            name_up = "syst_" + name_up.replace('syst_', "")
            name_dn = s.down_name
            name_dn = "syst_" + name_dn.replace('syst_', "")
            weight_up = ""
            weight_dn = ""
            if "PILEUPUP" in name_up :
                weight_up = " eventweightNOPUPW * pupw_up "
            else :
                weight_up = " eventweight * %s"%(str(name_up))
            if "PILEUPDOWN" in name_dn :
                weight_dn = " eventweightNOPUPW * pupw_down "
            else :
                weight_dn = " eventweight * %s"%(str(name_dn))

            norm_factor = "1"
            if "ttbar" in b.name :
                norm_factor = "0.99"
            elif "vv" in b.name  and "SF" in reg.name :
                norm_factor = "1.27"
            elif "vv" in b.name and "SF" not in reg.name :
                norm_factor = "1.23"

            cut_up = "(" + reg.tcut + ") * %s * %s *%s"%(weight_up, str(b.scale_factor), norm_factor)
            cut_dn = "(" + reg.tcut + ") * %s * %s *%s"%(weight_dn, str(b.scale_factor), norm_factor)
            #cut_up = "(" + reg.tcut + ") * eventweight * " + str(name_up) + " * " + str(b.scale_factor)
            #cut_dn = "(" + reg.tcut + ") * eventweight * " + str(name_dn) + " * " + str(b.scale_factor)

            cut_up = r.TCut(cut_up)
            cut_dn = r.TCut(cut_dn)
            sel = r.TCut("1")

            cmd_up = "%s>>%s"%(plot.variable, h_up.GetName())
            cmd_dn = "%s>>%s"%(plot.variable, h_dn.GetName()) 

            s.tree.Draw(cmd_up, cut_up * sel)
            s.tree.Draw(cmd_dn, cut_dn * sel)

            # add overflow to these guys' last bins
            pu.add_overflow_to_lastbin(h_up)
            pu.add_overflow_to_lastbin(h_dn)


            print "    %s   (+%.2f, -%.2f)"%(s.name, h_up.Integral(0,-1)-nom_yield, nom_yield-h_dn.Integral(0,-1))

            s.up_histo = h_up
            s.down_histo = h_dn

        elif s.isKinSys() :

            norm_factor = "1"
            if "ttbar" in b.name :
                norm_factor = "0.99"
            elif "vv" in b.name  and "SF" in reg.name :
                norm_factor = "1.27"
            elif "vv" in b.name and "SF" not in reg.name :
                norm_factor = "1.23"

            cut = "(" + reg.tcut + ") * eventweight * %s * %s"%(str(b.scale_factor), norm_factor)
            cut = r.TCut(cut)
            sel = r.TCut("1")
            cmd_up = "%s>>%s"%(plot.variable, h_up.GetName())
            cmd_dn = "%s>>%s"%(plot.variable, h_dn.GetName())

            s.tree_up.Draw(cmd_up, cut * sel)
            pu.add_overflow_to_lastbin(h_up)
            s.up_histo = h_up

            is_one_side = False
            if "JER" in syst.name : is_one_side = True
            if "ResoPerp" in syst.name or "ResoPara" in syst.name : is_one_side = True
            if not s.isOneSided() :
            #if not is_one_side :
                s.tree_down.Draw(cmd_dn, cut * sel)
                pu.add_overflow_to_lastbin(h_dn)
                s.down_histo = h_dn
            else :
                s.down_histo = nom_hist.Clone("%s_down_hist"%s.name)
                h_dn = s.down_histo

            if s.isOneSided() :
                print "    %s (+%.2f, -%.2f)"%(s.name, h_up.Integral(0,-1)-nom_yield, nom_yield-h_dn.Integral(0,-1))
            else :
                print "    %s  (+%.2f, -%.2f)"%(s.name, h_up.Integral(0,-1)-nom_yield, nom_yield-h_dn.Integral(0,-1))
Exemple #8
0
def getSystHistos(plot_, reg, bkg, syst, histname) :

    var_yields = []

    h_up = pu.th1f("h_"+bkg.treename+"_"+histname+"_"+syst.name+"_up","", int(plot_.nbins), plot_.x_range_min, plot_.x_range_max, plot_.x_label, plot_.y_label)
    h_up.SetFillStyle(0)
    h_up.SetLineColor(46)
    h_dn = pu.th1f("h_"+bkg.treename+"_"+histname+"_"+syst.name+"_dn","", int(plot_.nbins), plot_.x_range_min, plot_.x_range_max, plot_.x_label, plot_.y_label)
    h_dn.SetFillStyle(0)
    h_dn.SetLineColor(38)


    if syst.isWeightSys() :
        #weight_up = "eventweight * pupw_up"
        #weight_dn = "eventweight * pupw_down"
        #weight_up = "eventweight * pupw * syst_PILEUPUP"
        #weight_dn = "eventweight * pupw * syst_PILEUPDOWN"
        #cut_up = "(" + reg.tcut + ") * " + weight_up + " * " + str(bkg.scale_factor)
        #cut_dn = "(" + reg.tcut + ") * " + weight_dn + " * " + str(bkg.scale_factor)

        tmp_up = str(syst.up_name)
        tmp_dn = str(syst.down_name)
        tmp_up = tmp_up.replace("syst_","")
        tmp_up = "syst_" + tmp_up
        tmp_dn = tmp_dn.replace("syst_","")
        tmp_dn = "syst_" + tmp_dn

        syst.up_name = tmp_up
        syst.down_name = tmp_dn

        weight_str = ""
        if "PILEUP" not in syst.name :
            weight_str = "eventweight"
        elif "PILEUP" in syst.name :
            weight_str = "eventweightNOPUPW"
            syst.up_name = "pupw_up"
            syst.down_name = "pupw_down"

        cut_up = "(" + reg.tcut + ") * " + weight_str + " * " + str(syst.up_name) + " * " + str(bkg.scale_factor)
        cut_dn = "(" + reg.tcut + ") * " + weight_str + " * " + str(syst.down_name) + " * " + str(bkg.scale_factor)
        cut_up = r.TCut(cut_up)
        cut_dn = r.TCut(cut_dn)
        sel = r.TCut("1")

        cmd_up = "%s>>%s"%(plot_.variable, h_up.GetName())
        cmd_dn = "%s>>%s"%(plot_.variable, h_dn.GetName())

        syst.tree.Draw(cmd_up, cut_up * sel)
        syst.tree.Draw(cmd_dn, cut_dn * sel)

        ## overflow
        pu.add_overflow_to_lastbin(h_up)
        pu.add_overflow_to_lastbin(h_dn)


        var_yields.append(h_up.Integral(0,-1))
        var_yields.append(h_dn.Integral(0,-1))

        print "up: ",var_yields[0]
        print "dn: ",var_yields[1]

        syst.up_histo = h_up
        syst.down_histo = h_dn

    elif syst.isKinSys() :
        cut = "(" + reg.tcut + ") * eventweight * " + str(bkg.scale_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd_up = "%s>>%s"%(plot_.variable, h_up.GetName())
        cmd_dn = "%s>>%s"%(plot_.variable, h_dn.GetName())

        syst.tree_up.Draw(cmd_up, cut*sel)
        pu.add_overflow_to_lastbin(h_up)
        syst.up_histo = h_up
        var_yields.append(h_up.Integral(0,-1))
        if "JER" not in syst.name :
       # if not syst.isOneSided() or "JER" in syst.name :
            syst.tree_down.Draw(cmd_dn, cut*sel)
            pu.add_overflow_to_lastbin(h_dn)
            syst.down_histo = h_dn
            var_yields.append(h_dn.Integral(0,-1))

        print "up: ", var_yields[0]

    return var_yields
Exemple #9
0
def make_sys_plot(plot_, region, bkg_list, sys_list) :

    # canvases
    rcan = plot_.ratioCanvas
    rcan.canvas.cd()
    rcan.upper_pad.cd()

    if plot_.isLog() : rcan.upper_pad.SetLogy(True)
    rcan.upper_pad.Update()

    # stack for MC
    hax = r.TH1F("axes", "", int(plot_.nbins), plot_.x_range_min, plot_.x_range_max)
    hax.SetMinimum(plot_.y_range_min)
    hax.SetMaximum(plot_.y_range_max)
    hax.GetXaxis().SetTitle(plot_.x_label)
    hax.GetXaxis().SetTitleFont(42)
    hax.GetXaxis().SetLabelFont(42)
    hax.GetXaxis().SetLabelSize(0.035)
    hax.GetXaxis().SetTitleSize(0.048 * 0.85)
    hax.GetXaxis().SetTitleOffset(-999)
    hax.GetXaxis().SetLabelOffset(-999)

    hax.GetYaxis().SetTitle(plot_.y_label)
    hax.GetYaxis().SetTitleFont(42)
    hax.GetYaxis().SetLabelFont(42)
    hax.GetYaxis().SetTitleOffset(1.4)
    hax.GetYaxis().SetLabelOffset(0.013)
    hax.GetYaxis().SetLabelSize(1.2 * 0.035)
    hax.GetYaxis().SetTitleSize(0.055 * 0.85)
    hax.Draw()
    rcan.upper_pad.Update()

    nom_stack = r.THStack("stack_" + plot_.name + "_nom", "")
    up_stack  = r.THStack("stack_" + plot_.name + "_up", "")
    down_stack = r.THStack("stack_" + plot_.name + "_down", "")

    # legend
    leg = pu.default_legend(xl=0.62, yl=0.68, xh=0.93, yh=0.90)

    if len(sys_list) > 1 :
        print "ERROR you should only provide this method one systematic"
        sys.exit()

    # loop through background MC and add to stack
    nom_histos = []
    up_histos = []
    down_histos = []

    syst = sys_list[0]

    for b in bkg_list :

        #######################################
        ## nominal
        hist_name = ""
        if "abs" in plot_.variable :
            replace_var = plot_.variable.replace("abs(","")
            replace_var = replace_var.replace(")","")
            hist_name = replace_var
        else :
            hist_name = plot_.variable

        h = pu.th1f("h_" + b.treename + "_" + hist_name + "_nom", "",
                    int(plot_.nbins), plot_.x_range_min, plot_.x_range_max,
                    plot_.x_label, plot_.y_label)
        h.SetLineColor(r.kBlack)
        h.SetLineWidth(2*h.GetLineWidth())
        h.SetFillStyle(0)
        h.GetXaxis().SetLabelOffset(-999)

        # cut and make the sample wait
        cut = "(" + region.tcut + ") * eventweight * " + str(b.scale_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>+%s"%(plot_.variable, h.GetName())
        b.tree.Draw(cmd, cut * sel, "goff")

        stat_err = r.Double(0.0)
        nom_integral = h.IntegralAndError(0,-1,stat_err)
        print "nom: ",nom_integral

        # add overflow
        pu.add_overflow_to_lastbin(h)
        nom_histos.append(h)
        rcan.upper_pad.Update()
        
        ##############################
        # fill variation histos
        for x in b.systList :
            if x.name == syst.name :
                syst = x
        sys_yields = getSystHistos(plot_, region, b, syst, hist_name)

        syst.up_histo.SetLineColor(46)
        syst.up_histo.SetFillStyle(0)
        up_histos.append(syst.up_histo)

        if "JER" not in syst.name :
        #if not syst.isOneSided() :
            syst.down_histo.SetFillStyle(0)
            syst.down_histo.SetLineColor(38)
            down_histos.append(syst.down_histo)

    ## order the histos (not really necessary for this)
    nom_histos = sorted(nom_histos, key=lambda h: h.Integral(), reverse=False)
    up_histos = sorted(up_histos, key=lambda h: h.Integral(), reverse=False)
    if not syst.isOneSided() :
        down_histos = sorted(down_histos, key=lambda h: h.Integral(), reverse=False)
    for h in nom_histos :
        nom_stack.Add(h)
    for h in up_histos :
        up_stack.Add(h)
    #if not syst.isOneSided() :
    if "JER" not in syst.name :
        for h in down_histos :
            down_stack.Add(h)


    ############################ get the envelopes
    nom_total = nom_stack.GetStack().Last().Clone("nom_total")
    nom_total.SetMaximum(plot_.y_range_max)
    nom_total.SetMinimum(plot_.y_range_min)
    nom_total.SetLineColor(r.kBlack)
    nom_total.SetLineWidth(1*nom_total.GetLineWidth())
    nom_total.SetFillStyle(0)
    leg.AddEntry(nom_total, "Nominal", "l")

    up_total = up_stack.GetStack().Last().Clone("up_total")
    up_total.SetMaximum(plot_.y_range_max)
    up_total.SetMinimum(plot_.y_range_min)
    up_total.SetLineColor(46)
    up_total.SetLineWidth(1*up_total.GetLineWidth())
    up_total.SetFillStyle(0)
    var_up = ""
    if "JER" in syst.name :
        var_up = "Variation"
    else :
        var_up = "Up-Variation"
    leg.AddEntry(up_total, var_up, "l")

    if "JER" not in syst.name :
        down_total = down_stack.GetStack().Last().Clone("down_total")
        down_total.SetMaximum(plot_.y_range_max)
        down_total.SetMinimum(plot_.y_range_min)
        down_total.SetLineColor(38)
        down_total.SetLineWidth(1*down_total.GetLineWidth())
        down_total.SetFillStyle(0)
        leg.AddEntry(down_total, "Down-Variation", "l")

    ############################# draw!
    nom_total.Draw("hist")
    up_total.Draw("hist same")
    if "JER" not in syst.name :
        down_total.Draw("hist same")
    rcan.upper_pad.Update()

    r.gPad.SetTickx()
    r.gPad.SetTicky()
    rcan.upper_pad.Update()

    ############################ words
    pu.draw_text(text="#it{ATLAS} Preliminary", x= 0.18, y = 0.85)
    pu.draw_text(text="13 TeV, 3.2/fb", x=0.18,y=0.8)
    pu.draw_text(text=region.displayname, x=0.18,y=0.75)
    pu.draw_text(text=syst.name,x=0.18,y=0.7)
    rcan.upper_pad.Update()


    ############################# ratios
    rcan.lower_pad.cd()

    up_ratio = up_total.Clone("up_ratio")
    up_ratio.Divide(nom_total)

    down_ratio = None
    if "JER" not in syst.name :
        down_ratio = down_total.Clone("down_ratio")
        down_ratio.Divide(nom_total)

    ## axis for lower pad
    yax = up_ratio.GetYaxis()
    yax.SetRangeUser(0,2)
    yax.SetTitle("Variation/Nominal")
    yax.SetTitleSize(nom_total.GetYaxis().GetTitleSize())
 #   yax.SetTitleSize(0.14 * 0.5)
    yax.SetLabelSize(nom_total.GetYaxis().GetLabelSize())
 #   yax.SetLabelSize(0.13)
    yax.SetLabelOffset(1.2 * nom_total.GetYaxis().GetLabelOffset())
 #   yax.SetLabelOffset(0.98 * 0.013)
#    yax.SetTitleOffset(0.45)
    yax.SetTitleOffset(nom_total.GetYaxis().GetTitleOffset())
    yax.SetLabelFont(42)
    yax.SetTitleFont(42)
    yax.SetNdivisions(5)

    xax = up_ratio.GetXaxis()
    xax.SetTitleSize(1.2 * 0.14)
    xax.SetLabelSize(0.13)
    xax.SetLabelOffset(1.15*0.02)
    xax.SetTitleOffset(0.85 * xax.GetTitleOffset())
    xax.SetLabelFont(42)
    xax.SetTitleFont(42)


    up_ratio.Draw("hist")
    if down_ratio :
        down_ratio.Draw("hist same")
    rcan.lower_pad.Update()
    

    


    ########################### save
    outname = plot_.name + "_" + syst.name + ".eps"
    rcan.canvas.SaveAs(outname)
    out = indir + "/plots/" + outdir
    utils.mv_file_to_dir(outname, out, True)
    fullname = out + "/" + outname
    print "%s saved to : %s"%(outname, os.path.abspath(fullname))

    nom_total.Delete()
    up_total.Delete()
    if "JER" not in syst.name :
        down_total.Delete()
    hax.Delete()
Exemple #10
0
def make_fjvt_plots(higgs, zjets) :

    # pre-selection regions
    reg_pre_fjvt, reg_pre_nfjvt = get_pre_regions()
    regions = [reg_pre_fjvt, reg_pre_nfjvt]

    # variables
    nice_names = {}
    nice_names["mjj"] = "m_{jj} [GeV]"
    nice_names["deta"] = "|#Delta#eta|"
    nice_names["centrality"] = "Lepton centrality"
    nice_names["recoil"] = "f_{recoil}"
    nice_names["nsjets"] = "Number of jets"
    nice_names["jpt0"] = "Lead jet p_{T} [GeV]"
    nice_names["jpt1"] = "Sub-lead jet p_{T} [GeV]"

    bounds = {}
    bounds["mjj"] = [100, 0, 3000,1e10]
    bounds["deta"] = [0.4,0,8,1e10]
    bounds["centrality"] = [0.4, -2,5,1e10]
    bounds["recoil"] = [0.1, 0, 5,1e10]
    bounds["nsjets"] = [1,2,6,1e10]
    bounds["jpt0"] = [20, 0, 300,1e10]
    bounds["jpt1"] = [20, 0, 300,1e10] 

    variables = {}
    variables["mjj"] = { "fjvt" : "mjj_sj", "nfjvt" : "mjj_snpj" }
    variables["deta"] = { "fjvt" : "deta_sj", "nfjvt" : "deta_snpj" }
    variables["centrality"] = { "fjvt" : "lep_centrality_sjet", "nfjvt" : "lep_centrality_snpjet" }
    variables["recoil"] = { "fjvt" : "f_recoil_sjet", "nfjvt" : "f_recoil_snpjet" }
    variables["nsjets"] = { "fjvt" : "nSJets", "nfjvt" : "nSNPJets" }
    variables["jpt0"] = { "fjvt" : "sj_pt[0]", "nfjvt" : "snpj_pt[0]" }
    variables["jpt1"] = { "fjvt" : "sj_pt[1]", "nfjvt" : "snpj_pt[1]" }

    line_styles = {}
    line_styles["fjvt"] = 1
    line_styles["nfjvt"] = 2

    for var in variables.keys() :
        print "Plotting %s"%var

        p = plot.Plot1D()
        p.initialize("fjvt_check_%s"%str(var), str(var), "fjvt_check_%s"%str(var))
        p.labels(x=nice_names[var], y = "Arb. Units")
        p.xax(bounds[var][0], bounds[var][1], bounds[var][2])
        p.setRatioCanvas(p.name)

        # canvas
        rcan = p.ratioCanvas
        rcan.upper_pad.cd()

        # axis
        hax = r.TH1F("axis", "", int(p.nbins), p.x_range_min, p.x_range_max)
        hax.SetMinimum(10)
        hax.GetXaxis().SetTitle(nice_names[var])
        hax.Draw()
        rcan.upper_pad.Update()

        histos = []
        maxy_ = -1
        for reg in regions :
            print " > Region %s"%reg.name
            if "nfjvt" in reg.name :
                key = "nfjvt"
            else :
                key = "fjvt"
            for proc in [higgs, zjets] :
                print " >> %s"%proc.name
                h = pu.th1f("h_" + var + "_" + str(key) + "_" + proc.name, "", int(p.nbins),
                                        p.x_range_min, p.x_range_max, p.x_label, p.y_label)
                h.SetLineColor(proc.color)
                h.SetLineStyle(line_styles[key])
                h.SetFillStyle(0)
                h.SetLineWidth(2)
                h.GetXaxis().SetLabelOffset(-999)
                h.Sumw2

                weight_str = "eventweight"
                if "higgs" in proc.name :
                    weight_str += " * 1e5"
                cut = "(" + reg.tcut + ") * " + weight_str
                cut = r.TCut(cut)
                sel = r.TCut("1")
                cmd = "%s>>%s"%(variables[var][key], h.GetName())
                proc.tree.Draw(cmd, cut * sel, "goff")

                pu.add_overflow_to_lastbin(h) 


                stat_err = r.Double(0.0)
                integral = h.IntegralAndError(0,-1,stat_err)
                print "%s (%s) : %.2f +/- %.2f"%(str(proc.name), key, integral, stat_err)


                # normalize
                #h.Scale(1/h.Integral())
                if h.GetMaximum() > maxy_ :
                    maxy_ = 1.2 * h.GetMaximum()

                histos.append(h)
                rcan.upper_pad.Update()

        r.gPad.SetGrid()

        for h in histos :
            h.SetMaximum(maxy_)

        # legend
        leg = pu.default_legend(xl=0.55, yl=0.71, xh=0.93, yh=0.90)
        h_higgs_fjvt = None
        h_higgs_nfjvt = None
        h_zjets_fjvt = None
        h_zjets_nfjvt = None
        for h in histos :
            if "nfjvt" in h.GetName() :
                if "higgs" in h.GetName() :
                    h_higgs_nfjvt = h
                else :
                    h_zjets_nfjvt = h
            else :
                if "higgs" in h.GetName() :
                    h_higgs_fjvt = h
                else :
                    h_zjets_fjvt = h
        #h_higgs_nfjvt.Scale(h_zjets_nfjvt.Integral())
        #h_higgs_fjvt.Scale(h_zjets_fjvt.Integral())
        #h_higgs_nfjvt.Scale(h_zjets_nfjvt.Integral()/h_higgs_nfjvt.Integral())
        #h_higgs_fjvt.Scale(h_zjets_fjvt.Integral()/h_zjets_fjvt.Integral())

        leg.AddEntry(h_higgs_fjvt, "VBF Higgs x1e5 (w/ fJVT)", "l")
        leg.AddEntry(h_higgs_nfjvt, "VBF Higgs x1e5 (w/out fJVT)", "l")
        leg.AddEntry(h_zjets_fjvt, "Z+jets (w/ fJVT)", "l")
        leg.AddEntry(h_zjets_nfjvt, "Z+jets (w/out fJVT)", "l")

        ## draw
        h_higgs_fjvt.Draw("hist")
        h_higgs_nfjvt.Draw("hist same")
        h_zjets_fjvt.Draw("hist same")
        h_zjets_nfjvt.Draw("hist same")

        ## draw legend
        leg.Draw()

        r.gPad.SetTickx()
        r.gPad.SetTicky()


        ######################## LOWER PAD
        rcan.lower_pad.cd()

        # higgses
        h_h_nfjvt  = h_higgs_nfjvt.Clone("higgs_nofjvt")
        h_h_ratio  = h_higgs_fjvt.Clone("higgs_fjvt")
        h_h_ratio.Divide(h_h_nfjvt)
        h_h_ratio.GetYaxis().SetRangeUser(0,5)

        # zjetses
        h_z_nfjvt = h_zjets_nfjvt.Clone("zjets_nofjvt")
        h_z_ratio = h_zjets_fjvt.Clone("zjets_fjvt")
        h_z_ratio.Divide(h_z_nfjvt)
        h_z_ratio.GetYaxis().SetRangeUser(0,5)

        # axes
        haxis = [h_h_ratio, h_z_ratio]
        for hax in haxis :
            yax = hax.GetYaxis()
            yax.SetTitle("fJVT / no fJVT")
            yax.SetTitleSize(0.1 * 0.83)
            yax.SetLabelSize(0.1 * 0.81)
            yax.SetLabelOffset(0.98 * 0.013 * 1.08)
            yax.SetTitleOffset(0.45 * 1.2)
            yax.SetLabelFont(42)
            yax.SetTitleFont(42)
            yax.SetNdivisions(5)

            xax = hax.GetXaxis()
            xax.SetTitleSize(1.0 * 0.14)
            xax.SetLabelSize(yax.GetLabelSize())
            xax.SetLabelOffset(1.15 * 0.02)
            xax.SetTitleOffset(0.85 * xax.GetTitleOffset())
            xax.SetLabelFont(42)
            xax.SetTitleFont(42)


        h_h_ratio.Draw("hist")
        h_z_ratio.Draw("hist same")



        # save
        outname = p.name + ".eps"
        rcan.canvas.SaveAs(outname)
        out = "./fjvtcheck/"
        utils.mv_file_to_dir(outname, out, True)
        fullname = out + outname
        print "%s saved to : %s"%(outname, os.path.abspath(fullname))
Exemple #11
0
def make_plotsRatio(plot, region, backgrounds) :

    print "make_plotsRatio    Plotting %s"%plot.name

    # get the canvases
    rcan = plot.ratioCanvas
    rcan.canvas.cd()
    rcan.upper_pad.cd()

    if plot.isLog() : rcan.upper_pad.SetLogy(True)
    rcan.upper_pad.Update()

    # set up the frame
    hax = r.TH1F("axes", "", int(plot.nbins), plot.x_range_min, plot.x_range_max)
    hax.SetMinimum(plot.y_range_min)
    hax.SetMaximum(plot.y_range_max)
    xax = hax.GetXaxis()
    xax.SetTitle(plot.x_label)
    xax.SetTitleFont(42)
    xax.SetLabelFont(42)
    xax.SetLabelSize(0.035)
    xax.SetTitleSize(0.048 * 0.85)
    xax.SetTitleOffset(-999)
    xax.SetLabelOffset(-999)

    yax = hax.GetYaxis()
    yax.SetTitle(plot.y_label)
    yax.SetTitleFont(42)
    yax.SetLabelFont(42)
    yax.SetTitleOffset(1.4)
    yax.SetLabelOffset(0.013)
    yax.SetLabelSize(1.2 * 0.035)
    yax.SetTitleSize(0.055 * 0.85)

    hax.Draw()
    rcan.upper_pad.Update()

    # legend
    leg = pu.default_legend(xl=0.65, yl=0.72, xh=0.93, yh=0.90)

    histos = [] 
    n_drawn = 0
    for b in backgrounds :
        hist_name = ""
        if "abs" in plot.variable :
            replace_var = plot.variable.replace("abs(", "")
            replace_var = replace_var.replace(")", "")
            hist_name = replace_var
        else : hist_name = plot.variable
        h = None
        h = pu.th1f("h_"+b.treename+"_"+b.name+"_"+hist_name, "", int(plot.nbins), plot.x_range_min, plot.x_range_max, plot.x_label, plot.y_label)
        h.SetMinimum(0.1)
        h.SetLineColor(b.color)
        h.GetXaxis().SetLabelOffset(-999)
        h.SetLineWidth(2)
        h.SetFillStyle(0)
        h.Sumw2()

        idx = ""
        if "WW" in b.name or "ww" in b.name :
            idx = "WW"
        elif "WZ" in b.name or "wz" in b.name :
            idx = "WZ"

        sumw = get_sumw(idx)
        xsec = get_xsec(idx)
        lumi = 3300.0 # 3.3/fb

        weight_str = "eventweight * %s * %s / %s"%(str(xsec), str(lumi), str(sumw))
        print "weight = %s"%weight_str

        cut = "(" + reg.tcut + ") * %s "%weight_str
        #cut = "(" + reg.tcut + ") * eventweight * " + str(b.scale_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>%s"%(plot.variable, h.GetName())
        b.tree.Draw(cmd, cut * sel, "goff")

        # yield
        stat_err = r.Double(0.0)
        integral = h.IntegralAndError(0,-1,stat_err)
        print "%s: %.2f +/- %.2f"%(b.name, integral, stat_err)

        # add overflow
        pu.add_overflow_to_lastbin(h)
        leg.AddEntry(h, b.displayname, "l")
        histos.append(h)
        #rcan.upper_pad.Update()
        #rcan.canvas.Update()

    h_WW = None
    h_WZ = None
    for h in histos :
        if "WW" in h.GetName() or "ww" in h.GetName() :
            h_WW = h
            rcan.upper_pad.Update()
        elif "WZ" in h.GetName() or "wz" in h.GetName() :
            h_WZ = h
            rcan.upper_pad.Update()
        else :
            print "Expecting a  histogram with name that has 'WZ/wz' or 'WW/ww' in it"
            sys.exit()
    h_WW.Draw()
    h_WZ.Draw("same")
Exemple #12
0
def make_znRatioPlots(backgrounds, signals, region, plot) :
    print "make_znRatioPlots    Plottings %s"%plot.name

    # get canvases
    ratiocan = plot.getCanvas()
    ratiocan.canvas.cd()

    # go to the upper-pad
    ratiocan.upper_pad.cd()
    ratiocan.upper_pad.Draw()
    ratiocan.middle_pad.cd()
    ratiocan.middle_pad.Draw()
    ratiocan.lower_pad.cd()
    ratiocan.lower_pad.Draw()

    ratiocan.canvas.cd()
    ratiocan.upper_pad.cd()

    if plot.isLog() : ratiocan.upper_pad.SetLogy(True)
    ratiocan.upper_pad.Update()

    # stack for MC backgrounds

    ratiocan.upper_pad.cd()
    hax = r.TH1F("axes", "", int(plot.nbins), plot.x_range_min, plot.x_range_max)
    hax.SetMinimum(plot.y_range_min)
    hax.SetMaximum(plot.y_range_max)
    hax.GetXaxis().SetTitle(plot.x_label)
    hax.GetXaxis().SetTitleFont(42)
    hax.GetXaxis().SetLabelFont(42)
    hax.GetXaxis().SetLabelSize(0.035)
    hax.GetXaxis().SetTitleSize(0.048 * 0.85)
    hax.GetXaxis().SetTitleOffset(-999)
    hax.GetXaxis().SetLabelOffset(-999)

    hax.GetYaxis().SetTitle(plot.y_label)
    hax.GetYaxis().SetTitleFont(42)
    hax.GetYaxis().SetLabelFont(42)
    hax.GetYaxis().SetTitleOffset(1.4)
    hax.GetYaxis().SetLabelOffset(0.013)
    hax.GetYaxis().SetLabelSize(1.2 * 0.035)
    hax.GetYaxis().SetTitleSize(0.055 * 0.85)
    hax.Draw()
    ratiocan.upper_pad.Update()
    
    stack = r.THStack("stack_"+plot.name, "")

    # legend
    leg = pu.default_legend(xl=0.5, yl=0.6, xh=0.93, yh=0.90)
    #leg = pu.default_legend(xl=0.65, yl=0.72, xh=0.93, yh=0.90)
    leg.SetNColumns(2)

    ### loop through the background MC and add to stack
    histos = []
    hist_dict = {} # associate the background with its histogram name

    hist_name = ""
    if "abs" in plot.variable :
        replace_var = plot.variable.replace("abs(","")
        replace_var = replace_var.replace(")","")
        hist_name = replace_var
    elif "MDR_v1_t1_0 - MDR_i1_t1_0" in plot.variable :
        hist_name = "RATIO"
    elif "RPT_0/RPZ_0" in plot.variable :
        hist_name = "RPTZratio"
    elif "H_11_SS/H_21_SS" in plot.variable :
        hist_name = "RH11SSH21SS"
    elif "H_11_SS/H_11_S1" in plot.variable :
        hist_name = "RH11SSH11S1"
    elif "xH_11_S1/xH_42_SS" in plot.variable :
        hist_name = "xH_11_S1_over_xH_42_SS"
    elif "xH_42_SS_T/xH_42_SS" in plot.variable :
        hist_name = "xH_42_SS_T_over_xH_42_SS"
    elif "xH_11_SS/xH_42_SS_T" in plot.variable :
        hist_name = "xH_11_SS_over_xH_42_SS_T"
    elif "(xNV[0]-xNV[1])/(xNV[0]+xNV[1])" in plot.variable :
        hist_name = "n_obs_asy"
    elif "xH_11_SS/xH_42_SS_T" in plot.variable :
        hist_name = "xH_11_SSoverxH_42_SS_T"
    elif "xH_42_SS_T/xH_11_SS" in plot.variable :
        hist_name = "xH_42_SS_ToverxH_11_SS"
    else : hist_name = plot.variable

    for b in backgrounds :
        h = pu.th1f("h_"+b.treename+"_"+hist_name, "", int(plot.nbins), plot.x_range_min, plot.x_range_max, plot.x_label, plot.y_label)
        h.SetLineColor(r.kBlack)
        h.SetFillColor(b.color)
        h.SetFillStyle(1001)
        h.Sumw2

        # cut and make the sample weighted, applying the scale_factor
        cut = "(" + reg.tcut + ") * eventweight * " + str(b.scale_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>%s"%(plot.variable, h.GetName())
        b.tree.Draw(cmd, cut * sel, "goff")
        
        # print the yield +/- stat error
        stat_error = r.Double(0.0)
        integral = h.IntegralAndError(0, -1, stat_error)
        print "%s: %.2f +/- %.2f"%(b.name, integral, stat_error)

        # add overflow
        pu.add_overflow_to_lastbin(h)

        # add to group
        histos.append(h)
        hist_dict[h.GetName()] = b.displayname
     #   ratiocan.upper_pad.Update()

    # order the histograms and add to legend
    histos = sorted(histos, key = lambda h: h.Integral(), reverse = False)
    for his in histos :
        stack.Add(his)
    
    histos_leg = sorted(histos, key = lambda h: h.Integral(), reverse = True)
    for hl in histos_leg :
        leg.AddEntry(hl, hist_dict[hl.GetName()], "f")
        #leg.AddEntry(hl, hist_dict[hl.GetName()], "fl")
    ### total SM histo
    totalSM = stack.GetStack().Last().Clone("totalSM")

    ### container for zn pads
    sig_values = {}

    ### now plot the signal points

    sig_histos = []
    for s in signals :

        sig_values[s.name] = {} # { up : [], down : [] }

        hs = pu.th1f("h_"+s.treename+"_"+hist_name, "", int(plot.nbins), plot.x_range_min, plot.x_range_max, plot.x_label, plot.y_label)
        hs.SetLineColor(s.color)
        hs.SetLineStyle(2)
        hs.SetLineWidth(2) 
        hs.SetFillStyle(0)
        hs.Sumw2

        # cut and make sample weighted, applying the scale_factor
        cut = "(" + reg.tcut + ") * eventweight *" + str(s.scale_factor)
        cut = r.TCut(cut)
        sel = r.TCut("1")
        cmd = "%s>>%s"%(plot.variable, hs.GetName())
        s.tree.Draw(cmd, cut * sel, "goff")

        # print the yield +/- stat error
        stat_error = r.Double(0.0)
        integral = hs.IntegralAndError(0, -1, stat_error)
        print "%s: %.2f +/- %.2f"%(s.name, integral, stat_error)

        # add overflow
        pu.add_overflow_to_lastbin(hs)

        # add to legend
        leg.AddEntry(hs, s.displayname, "l")

        hs.SetMaximum(plot.y_range_max)
        hs.SetMinimum(plot.y_range_min)

        sig_histos.append(hs)
      #  ratiocan.upper_pad.Update()

        # get the zn-per-bin values
        # "up" : Zn values for lower-cuts (i.e. SR includes everything to the right of the cut)
        # "down" : Zn values for upper-cuts (i.e. SR includes everything to the left of the cut)
        if 'zn' in method :
            sig_values[s.name]['up'], sig_values[s.name]['down'] = get_zn_per_bin(hs, totalSM)

        # get the total zn for this selection
        # and attach the the signal point
        significance, nbkg, nsig, rel_bkgerr = 0, 0, 0, 0 
        if 'zn' in method :
            significance, nbkg, nsig, rel_bkgerr = get_zn_for_selection(hs, totalSM)
            s.sig_val = significance
            s.n_bkg = nbkg
            s.n_sig = nsig
            s.n_bkgerr = rel_bkgerr

    signame = ''
    if 'zn' in method : signame = "Zn"
    print " ++ --------------------------------------- ++ "
    print "     Significance (%s) for selection %s"%(signame, reg.displayname)
    print ""
    print "   # bkg : %.2f +/- %.2f             "%(nbkg, nbkg * rel_bkgerr)
    for sigpoint in signals :
        print "   # %s: %.2f                  "%(sigpoint.displayname, sigpoint.n_sig)
        print "       Z --> %.2f"%sigpoint.sig_val
    print " ++ --------------------------------------- ++ "

#    if method == "zn" : sys.exit()
    if method == "zn" or method == "fasimov" : return


    ### draw MC backgrounds
    ratiocan.upper_pad.Update()
    
    # now draw the stack without the axis
    stack.Draw("HIST same")

    ### draw signals
    for h_sig in sig_histos :
        h_sig.Draw("same")
    ratiocan.canvas.Update()

    leg.Draw()
    ratiocan.canvas.Update()
    r.gPad.RedrawAxis()

    #pu.draw_text_on_top(text=reg.tcut, size = 0.02)
    pu.draw_text(text="#it{ATLAS} Internal",x=0.18,y=0.83, size = 0.06)
    pu.draw_text(text="13 TeV, 10/fb", x=0.18,y=0.73, size = 0.06)
    #pu.draw_text(text="13 TeV, 10 fb^{-1}", x=0.18,y=0.8)

    #########################
    ## now draw zn

    ### up
    sig_up_histos = []
    sig_down_histos = []
    for sig in signals :
        updown = ['up', 'down']
        for dir in updown :
            zns = sig_values[sig.name][dir]
            hz = pu.th1f("h_sig_"+dir+"_" + sig.name, "", int(plot.nbins), plot.x_range_min, plot.x_range_max, "","")
            hz.SetMarkerStyle(20)
            hz.SetMarkerColor(sig.color)
            hz.SetMarkerSize(0.3 * hz.GetMarkerSize())
            max_y = 2.5
            for ibin, zn in enumerate(zns) :
                if zn > 2.5 :
                    max_y = 4
                elif zn > 4 :
                    max_y = 5
            hz.SetMaximum(max_y)
            hz.SetMinimum(0.0)
            for ibin, zn in enumerate(zns) :
                hz.SetBinContent(ibin, r.Double(zn))
            if 'up' in dir : sig_up_histos.append(hz)
            elif 'down' in dir : sig_down_histos.append(hz)

    ratiocan.middle_pad.cd()
    is_first = True
    for hzn in sig_up_histos :
        if is_first : 
            hzn.Draw("p")
            set_ratio_style(hzn, "mid", "")
            is_first = False
        else :
            hzn.Draw("same p")
    ratiocan.middle_pad.Update()

    ratiocan.lower_pad.cd()
    is_first = True
    for hzn in sig_down_histos :
        if is_first : 
            hzn.Draw("p")
            is_first = False
            set_ratio_style(hzn, "low", plot.x_label)
        else :
            hzn.Draw("same p")
    ratiocan.lower_pad.Update()

    #### save
    outname = plot.name + ".eps"
    ratiocan.canvas.SaveAs(outname)
    out = indir + "/plots/" + outdir
    utils.mv_file_to_dir(outname, out, True)
    fullname = out + "/" + outname
    print "%s saved to : %s"%(outname, os.path.abspath(fullname))