Пример #1
0
def closure():
    
    # genmatch for e->e and e->g, without Ht100To200 bin
    filename = "/user/rmeyer/Dropbox/data_uni/root_selectorFiles/myTestSelector_closureWJetsToLNu__1466503598.root"
    
    # no genmatch for e->e, only leading em object
    filename = "/user/rmeyer/Dropbox/data_uni/root_selectorFiles/myTestSelector_closureWJetsToLNu__1466514536.root"
    # nur barrell
    filename = "/user/rmeyer/Dropbox/data_uni/root_selectorFiles/myTestSelector_closureWJetsToLNu__1466514983.root"
    
    # drell yan
    #filename = "/user/rmeyer/Dropbox/data_uni/root_selectorFiles/myTestSelector_closureDY__1466515252.root"
    
    
    data = rt.TFile(filename)
    
    g = data.Get("clos_gen_g")
    e = data.Get("clos_gen_e")
    
    
    f = 0.0107
    f = 0.0077
    
    edges = [50., 60., 70., 70., 80., 90., 100., 120., 140., 160., 250.]
    #edges = [40., 250.]
    
    g = aux.rebin(g, edges)
    e = aux.rebin(e, edges)
    
    #g.Rebin(10)
    #e.Rebin(10)
    
    print "predicted: ", e.Integral()*f/(1-f)
    print "matched:   ", g.Integral()
    
    e.Scale(f/(1-f))
    
    e.SetMarkerColor(rt.kRed)
    g.SetMarkerColor(rt.kBlack)
    
    e.SetMarkerStyle(rt.kFullCircle)
    g.SetMarkerStyle(rt.kFullSquare)
    
    
    
    
    
    # empty histogram
    #h = rt.TH1F("h", "h", len(edges)-1, array( 'd', edges ))
    
    
    
    ### create ratio
    #def ratio_hishis(h1, h2):
    ##returns h1/h2
    ratio = aux.ratio_hishis(g, e)
    
    ratio.GetYaxis().SetLabelSize(0.065)
    ratio.GetYaxis().SetTitle("gen./pred.")
    ratio.GetYaxis().SetTitleSize(0.08)
    ratio.GetYaxis().SetTitleOffset(0.5)
    
    ratio.GetXaxis().SetLabelSize(0.)
    ratio.GetXaxis().SetTitleSize(0.)
    
    
    l = rt.TLegend(0.5,0.7,0.9,0.9);
    l.AddEntry(g, "N_{e#rightarrow#gamma}", "ep")
    l.AddEntry(e, "N_{e#rightarrowe} * f/(1-f)", "ep")
    
    
    c = rt.TCanvas("c", "c", 700, 700)
    c.cd()
    
    p1 = rt.TPad("p1", "p1", 0., 0.3, 1., 1.)
    p1.SetLeftMargin(0.12)
    p1.Draw()
    p1.cd()
    
    g.Draw("ep")
    e.Draw("ep same")
    l.Draw()
    
    c.cd()
    p2 = rt.TPad("p2", "p2", 0., 0.01, 1., 0.3)
    p2.SetLeftMargin(0.12)
    p2.SetGridy()
    p2.Draw()
    p2.cd()
    
    ratio.Draw("ep")
    
    
    
    raw_input()
    
    return 0
Пример #2
0
def histoCanvas(fs, name, target, prediction, clabel, logy=True, yrng=[], *opt):
    # CLOSURE PLOTS
    
    
    
    cwidth = 800
    cheight = 800
    rat = 0.35
    
    rt.gStyle.SetLegendBorderSize(0)
    

    

    c = rt.TCanvas(name, name, cwidth, cheight)
    rt.gStyle.SetTitleFontSize(0.07)
    
    c.cd()
    
    #c.SetGridx()
    #c.SetGrid()
    
    target.GetXaxis().SetTitleSize(0.05)
    target.GetXaxis().SetLabelSize(0.0)
    target.GetYaxis().SetTitleSize(0.06)
    target.GetYaxis().SetLabelSize(0.05)
    target.GetYaxis().SetTitleOffset(1.3)
    target.GetYaxis().SetTitle("Events / bin")
    target.SetFillColor(rt.kGray+2)
    target.SetLineColor(rt.kGray+2)
    target.SetTitle(clabel)
    
    prediction.SetMarkerStyle(rt.kFullCircle)
    prediction.SetMarkerColor(rt.kRed)
    
    if not yrng:
        pass
    else:
        target.SetMinimum(yrng[0])
        target.SetMaximum(yrng[1])
        prediction.SetMinimum(yrng[0])
        prediction.SetMaximum(yrng[1])
    
    
    #l = rt.TLegend()
    ratio = aux.ratio_hishis(target, prediction)
    
    
    ratio.SetTitle("")
    ratio.GetXaxis().SetTitleSize(0.15)
    ratio.GetXaxis().SetLabelSize(0.1)
    
    ratio.GetYaxis().SetTitle("exp. / pred.")
    ratio.GetYaxis().SetTitleSize(0.12)
    ratio.GetYaxis().SetLabelSize(0.09)
    ratio.GetYaxis().SetTitleOffset(0.6)
    #ratio.GetYaxis().SetNdivisions(7)
    ratio.SetMinimum(0.85)
    ratio.SetMaximum(1.15)
    
    pad1 = rt.TPad("pad1","pad1",0,rat,1,1)
    
    pad1.SetGridx()
    pad1.SetGridy()
    
    if logy:
        pad1.SetLogy()
    pad1.SetBottomMargin(0)
    pad1.SetLeftMargin(0.16)
    
    pad1.Draw()
    pad1.cd()
    #pad1.SetLogy()
    pad1.Update()
    
    
    
    
    offset = -0.1
    leg = rt.TLegend(.6+offset,.75+offset,.97+offset,.97+offset)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.AddEntry(target, "N_{e#rightarrow#gamma}", "f")
    leg.AddEntry(prediction, "Tag n probe", "ep")
    #'''
    
    #egraph.GetYaxis().SetTitle("Fakerate")
    #egraph.GetYaxis().SetTitleOffset(1.3)
    #egraph.GetYaxis().SetTitleSize(0.05)
    
    #egraph.GetXaxis().SetLabelSize(0.0)
    #egraph.GetXaxis().SetTitleSize(0.05)
    #.SetMaximum(0.015)
    
    #eff.GetXaxis().SetRangeUser(0.,210.)
    #egraph.SetMinimum(0.)
    
    #eff.Draw("ap")
    #print leg
    
    prediction.DrawClone("ep")
    target.Draw("E2")
    prediction.Draw("ep same")
    
    
    if logy:
        pad1.SetLogy()
    
    #leg = rt.TLegend(0.1,0.7,0.48,0.9);
    #leg.AddEntry(target, "N_{e#rightarrow#gamma}", "f")
    leg.Draw()
    
    #leg = pad1.BuildLegend()
    #rt.gPad.ls()
    
    #leg.Draw()
    
    #if leg is not None:
    #leg.Draw()
    
    c.cd()
    
    pad2 = rt.TPad("pad2","pad2",0,0,1,rat)
    pad2.SetGridy()
    pad2.SetGridx()
    pad2.SetTopMargin(0)
    pad2.SetBottomMargin(0.35)
    pad2.SetLeftMargin(0.16)
    pad2.Draw()
    pad2.cd()
    
    oneline = rt.TF1("oneline", "1",    target.GetXaxis().GetXmin(),
                                        target.GetXaxis().GetXmax())
    oneline.SetLineWidth(1)
    oneline.SetLineColor(rt.kBlack)
    
    ratio.Draw("ep")
    oneline.Draw("same")
    pad2.Update()
    
    c.Update()
    
    #drawCMS(c)
    #c.Update()
    fs.savePdf(c, name)
    
    c.Close()
    
    #raw_input()
    #ch[names[num]] = c.Clone(names[num])
    #ch[names[num]].SetDirectory(0)
    #ch[names[num]].Update()
    
    return 0