Esempio n. 1
0
def drawRatio(histRatio,stack,Region,BLINDEDLIST,nbins,xmin,xmax):
    #histRatio = datastack.sum.Clone()
    #histRatio.merge_bins([(0, 1), (-2, -1)])

    tempDataStack = histRatio.Clone()
    ratioMinimum=0
    ratioMaximum=2
    histRatio.SetMinimum(ratioMinimum)
    histRatio.SetMaximum(ratioMaximum)
    histRatio.yaxis.divisions = 5
    histRatio.Divide(stack.sum)

    if Region not in BLINDEDLIST: 
        histRatio.Draw("PE")
    
    line = Line(float(xmin)+1e-2*float(xmax),1.,float(xmax)-1e-2*float(xmax),1.);
    line.SetLineWidth(4);
    line.SetLineColor("red");
    line.Draw();
    

    if Region not in BLINDEDLIST:
        histRatio.Draw("SAME EP")

    MCerrorband = stack.sum.Clone()
    MCerrorband.SetLineWidth(10)
    MCerrorband.SetFillStyle(3244)
    MCerrorband.SetFillColor(922)


    for i in range(1,int(nbins)+1):
        if stack.sum.GetBinContent(i) != 0:
            if tempDataStack.GetBinContent(i)/stack.sum.GetBinContent(i) >= 2:
                xcoord = stack.sum.GetBinCenter(i)
                arrow = Arrow(xcoord,1.67,xcoord,1.87,0.015,"|>")
                arrow.SetAngle(50)
                arrow.SetLineWidth(6)
                arrow.SetLineColor(2)
                arrow.SetFillColor(2)
                arrow.Draw()
            if tempDataStack.GetBinContent(i)/stack.sum.GetBinContent(i) <= -2:
                xcoord = stack.sum.GetBinCenter(i)
                arrow = Arrow(xcoord,0.33,xcoord,0.13,0.015,"|>")
                arrow.SetAngle(50)
                arrow.SetLineWidth(6)
                arrow.SetLineColor(2)
                arrow.SetFillColor(2)
                arrow.Draw();
        
        mcerror = 0.0
        content = stack.sum.GetBinContent(i)
        error = stack.sum.GetBinError(i)
        if content != 0 :
            mcerror = (content+error)/content - 1.0 
        MCerrorband.SetBinContent(i,1)
        MCerrorband.SetBinError(i,mcerror)
        
    MCerrorband.Draw("E2PSAME")
Esempio n. 2
0
def plotratio(datastack, stack):
    histRatio = datastack.sum.Clone()
    #histRatio.merge_bins([(0, 1), (-2, -1)])
    ratioMinimum = 0
    ratioMaximum = 2
    histRatio.SetMinimum(ratioMinimum)
    histRatio.SetMaximum(ratioMaximum)

    histRatio.xaxis.SetTitle(xtitle)
    histRatio.yaxis.SetTitle("Data/SM")
    histRatio.yaxis.CenterTitle()
    histRatio.yaxis.divisions = 5
    histRatio.Divide(stack.sum)
    histRatio.xaxis.SetTitleOffset(3.4)
    histRatio.yaxis.SetTitleOffset(2)
    histRatio.xaxis.set_label_size(int(canvasheight * labelscale * 1.5))
    histRatio.yaxis.set_label_size(int(canvasheight * labelscale * 1.5))

    if plotData:
        histRatio.Draw("PE")

    line = Line(
        float(xmin) + 1e-2 * float(xmax), 1.,
        float(xmax) - 1e-2 * float(xmax), 1.)
    line.SetLineWidth(4)
    line.SetLineColor("red")

    if plotData:
        line.Draw("Same")
    else:
        line.Draw()

    if plotData:
        histRatio.Draw("SAME EP")

    MCerrorband = stack.sum.Clone()
    MCerrorband.SetLineWidth(10)
    MCerrorband.SetFillStyle(3244)
    MCerrorband.SetFillColor(922)

    for i in range(1, int(nbins) + 1):
        if stack.sum.GetBinContent(i) != 0:
            if datastack.sum.GetBinContent(i) / stack.sum.GetBinContent(
                    i) >= 2:
                xcoord = stack.sum.GetBinCenter(i)
                arrow = Arrow(xcoord, 1.67, xcoord, 1.87, 0.015, "|>")
                arrow.SetAngle(50)
                arrow.SetLineWidth(6)
                arrow.SetLineColor(2)
                arrow.SetFillColor(2)
                arrow.Draw()
            if datastack.sum.GetBinContent(i) / stack.sum.GetBinContent(
                    i) <= -2:
                xcoord = stack.sum.GetBinCenter(i)
                arrow = Arrow(xcoord, 0.33, xcoord, 0.13, 0.015, "|>")
                arrow.SetAngle(50)
                arrow.SetLineWidth(6)
                arrow.SetLineColor(2)
                arrow.SetFillColor(2)
                arrow.Draw()

        mcerror = 0.0
        content = stack.sum.GetBinContent(i)
        error = stack.sum.GetBinError(i)
        if content != 0:
            mcerror = (content + error) / content - 1.0
        MCerrorband.SetBinContent(i, 1)
        MCerrorband.SetBinError(i, mcerror)

    MCerrorband.Draw("E2PSAME")