def Plot(files, label, obs):

    radmasses = []
    for f in files:
#        radmasses.append(float(f.replace("CMS_jj_","").split("_")[0])/1000.)
        
        radmasses=[500, 550, 650, 700, 900, 1000, 1200, 1800, 2000]#,3.5,4.,4.5]
        for i in range(len(radmasses)):
            radmasses[i]=radmasses[i]/1000.
    print radmasses

    efficiencies={}
    for mass in radmasses:
        efficiencies[mass]=1000. # to convert from pb to fb
    from ROOT import limit_t
    limit_branch = limit_t()
    fChain = []
    for onefile in files:
        print onefile
        fileIN = rt.TFile.Open(onefile)
        fileIN.Print()
        fChain.append(copy.copy(fileIN.Get("limit;1"))) 
        

        for j in range(0,len(fChain)):
            chain = fChain[j]
            chain.SetBranchAddress("limit", rt.AddressOf(limit_branch,'limit'))

    rad = []
    for j in range(0,len(fChain)):
        chain = fChain[j]
        thisrad = []
        for  i in range(0,6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)


    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> ZZ")
    c1 = rt.TCanvas("c1","A Simple Graph Example",200,10,600,600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0,len(fChain)):
        y2up.append(rad[i][0]*efficiencies[radmasses[j]])
        y1up.append(rad[i][1]*efficiencies[radmasses[j]])
        ymean.append(rad[i][2]*efficiencies[radmasses[j]])
        y1down.append(rad[i][3]*efficiencies[radmasses[j]])
        y2down.append(rad[i][4]*efficiencies[radmasses[j]])
        yobs.append(rad[i][5]*efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kRed)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)
  
    for j in range(0,len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])    
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])
    
    mg.Add(gr2up)#.Draw("same")
    mg.Add(gr1up)#.Draw("same")
    mg.Add(grmean,"L")#.Draw("same,AC*")
    mg.Add(gr1down)#.Draw("same,AC*")
    mg.Add(gr2down)#.Draw("same,AC*")
    if obs: mg.Add(grobs,"L")#.Draw("AC*")
 
    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("Resonance mass (TeV)")
    resonance="G_{RS}"
        #resonance="G_{Bulk}"
    if withAcceptance:
        mg.GetYaxis().SetTitle("#sigma #times B("+resonance+" #rightarrow "+label.split("_")[0].replace("RS1","").replace("Bulk","")+") #times A (fb)")
    else:
        mg.GetYaxis().SetTitle("#sigma #times B("+resonance+" #rightarrow HH to b#bar{b}b#bar{b}) (fb)")
    mg.GetYaxis().SetLabelFont(42)	
    mg.GetXaxis().SetLabelFont(42)
    mg.GetYaxis().SetTitleFont(42)
    mg.GetXaxis().SetTitleFont(42)
    mg.GetYaxis().SetTitleSize(0.035)
    mg.GetXaxis().SetTitleSize(0.035)
    mg.GetXaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetRangeUser(1.,1000)
    mg.GetYaxis().SetTitleOffset(1.4)
    mg.GetYaxis().CenterTitle(True)
    mg.GetXaxis().SetTitleOffset(1.1)
    mg.GetXaxis().CenterTitle(True)
    mg.GetXaxis().SetNdivisions(508)

    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(0.5,2.4)
    else:
        mg.GetXaxis().SetLimits(0.5,2.4)

    # histo to shade
    n=len(fChain)

    grgreen = rt.TGraph(2*n)
    for i in range(0,n):
        grgreen.SetPoint(i,radmasses[i],y2up[i])
        grgreen.SetPoint(n+i,radmasses[n-i-1],y2down[n-i-1])

    grgreen.SetFillColor(rt.kGreen)
    grgreen.Draw("f") 


    gryellow = rt.TGraph(2*n)
    for i in range(0,n):
        gryellow.SetPoint(i,radmasses[i],y1up[i])
        gryellow.SetPoint(n+i,radmasses[n-i-1],y1down[n-i-1])

    gryellow.SetFillColor(rt.kYellow)
    gryellow.Draw("f,same") 

    grmean.Draw("L")
    if obs: grobs.Draw("L")

    gtheory = rt.TGraphErrors(1)
    gtheory.SetLineColor(rt.kBlue)
    gtheory.SetLineWidth(4)
    #ftheory=open("signal_cross_section_RS1Graviton.txt")
    ftheory=open("bulk_graviton_exo15002.txt")	
    ij=0
    glogtheory = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
     for line in lines.split("\r"):
        split=line.split(":")
	print(split[1][0:])
        gtheory.SetPoint(ij, float(split[0][-4:])/1000., float(split[1])*0.57*0.57*1000.)
        glogtheory.SetPoint(ij, float(split[0][-4:])/1000., log(float(split[1])*0.57*0.57*1000.))
	ij+=1
    mg.Add(gtheory,"L")
    gtheory.Draw("L")
    #ltheory="G_{RS1} #rightarrow HH (k/#bar{M}_{Pl}=0.1)"
    ltheory ="BulkGrav k=0.5"	
    
   # crossing=0
   # for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
   #     if exp(glogtheory.Eval(mass/1000.))>grmean.Eval(mass/1000.) and crossing>=0:
#	    print label,"exp crossing",mass
#	    crossing=-1
#        if exp(glogtheory.Eval(mass/1000.))<grmean.Eval(mass/1000.) and crossing<=0:
#	    print label,"exp crossing",mass
#	    crossing=1
#    crossing=0
#    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
#        if exp(glogtheory.Eval(mass/1000.))>grobs.Eval(mass/1000.) and crossing>=0:
#	    print label,"obs crossing",mass
#	    crossing=-1
#        if exp(glogtheory.Eval(mass/1000.))<grobs.Eval(mass/1000.) and crossing<=0:
	    #print label,"obs crossing",mass
	    #crossing=1
    
    if "WW" in label.split("_")[0] or "ZZ" in label.split("_")[0]:
       leg = rt.TLegend(0.53,0.65,0.95,0.89)
       leg2 = rt.TLegend(0.33,0.55,0.95,0.89)
    else:
       leg = rt.TLegend(0.59,0.65,0.95,0.89)
       leg2 = rt.TLegend(0.49,0.55,0.95,0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetTextFont(42) 	
    leg.SetBorderSize(0)
    leg2.SetFillColor(rt.kWhite)
    leg2.SetFillStyle(0)
    leg2.SetTextSize(0.04)
    leg2.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed", "L")
    leg.AddEntry(gryellow, "Expected (68%)", "f")
    leg.AddEntry(grgreen, "Expected (95%)", "f")
    leg.AddEntry(gtheory, ltheory, "L")

    if obs: leg2.AddEntry(grobs, " ", "")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(gtheory, " ", "")

    leg.Draw()
    #leg2.Draw("same")

    CMS_lumi.CMS_lumi(c1, iPeriod, iPos)
    c1.cd()
    c1.Update()


    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.root" %label)
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.pdf" %label)
    else:
        c1.SaveAs("brazilianFlag_%s_13TeV.root" %label)
        c1.SaveAs("brazilianFlag_%s_13TeV.pdf" %label)
Exemplo n.º 2
0
def Plot(files, label, obs):

    radmasses = []
    for f in files:
        radmasses.append(float(f.replace("CMS_jj_", "").split("_")[0]) / 1000.)
    #print radmasses

    efficiencies = {}
    for mass in radmasses:
        efficiencies[mass] = 0.01  # assume 10/fb signal cross section

    fChain = []
    for onefile in files:
        print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0, len(fChain)):
            chain = fChain[j]
            chain.SetBranchAddress("limit",
                                   rt.AddressOf(limit_branch, 'limit'))

    rad = []
    for j in range(0, len(fChain)):
        chain = fChain[j]
        thisrad = []
        for i in range(0, 6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)

    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> ZZ")
    c1 = rt.TCanvas("c1", "A Simple Graph Example", 200, 10, 600, 600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0, len(fChain)):
        y2up.append(rad[i][0] * efficiencies[radmasses[j]])
        y1up.append(rad[i][1] * efficiencies[radmasses[j]])
        ymean.append(rad[i][2] * efficiencies[radmasses[j]])
        y1down.append(rad[i][3] * efficiencies[radmasses[j]])
        y2down.append(rad[i][4] * efficiencies[radmasses[j]])
        yobs.append(rad[i][5] * efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kRed)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)

    for j in range(0, len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])

    mg.Add(gr2up)  #.Draw("same")
    mg.Add(gr1up)  #.Draw("same")
    mg.Add(grmean, "L")  #.Draw("same,AC*")
    mg.Add(gr1down)  #.Draw("same,AC*")
    mg.Add(gr2down)  #.Draw("same,AC*")
    if obs: mg.Add(grobs, "L")  #.Draw("AC*")

    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("Resonance mass (TeV)")
    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        resonance = "q*"
    if "RS1" in label.split("_")[0]:
        resonance = "G_{RS}"
    if "Bulk" in label.split("_")[0]:
        resonance = "G_{Bulk}"
    if "WZ" in label.split("_")[0]:
        resonance = "W'"
    if withAcceptance:
        mg.GetYaxis().SetTitle(
            "#sigma #times B(" + resonance + " #rightarrow " +
            label.split("_")[0].replace("RS1", "").replace("Bulk", "") +
            ") #times A (pb)")
    else:
        mg.GetYaxis().SetTitle(
            "#sigma #times B(" + resonance + " #rightarrow " +
            label.split("_")[0].replace("RS1", "").replace("Bulk", "") +
            ") (pb)")
    mg.GetYaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetRangeUser(0.0004, 4)
    mg.GetYaxis().SetTitleOffset(1.4)
    mg.GetYaxis().CenterTitle(True)
    mg.GetXaxis().SetTitleOffset(1.1)
    mg.GetXaxis().CenterTitle(True)
    mg.GetXaxis().SetNdivisions(508)

    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(0.9, 4.1)
    else:
        mg.GetXaxis().SetLimits(0.9, 3.1)

    # histo to shade
    n = len(fChain)

    grgreen = rt.TGraph(2 * n)
    for i in range(0, n):
        grgreen.SetPoint(i, radmasses[i], y2up[i])
        grgreen.SetPoint(n + i, radmasses[n - i - 1], y2down[n - i - 1])

    grgreen.SetFillColor(rt.kGreen)
    grgreen.Draw("f")

    gryellow = rt.TGraph(2 * n)
    for i in range(0, n):
        gryellow.SetPoint(i, radmasses[i], y1up[i])
        gryellow.SetPoint(n + i, radmasses[n - i - 1], y1down[n - i - 1])

    gryellow.SetFillColor(rt.kYellow)
    gryellow.Draw("f,same")

    grmean.Draw("L")
    if obs: grobs.Draw("L")

    gtheory = rt.TGraphErrors(1)
    gtheory.SetLineColor(rt.kBlue)
    gtheory.SetLineWidth(4)
    ftheory = open("signalcrosssections.txt")
    j = 0
    glogtheory = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
        for line in lines.split("\r"):
            if label.split("_")[0] in line and line.count(
                    "Bulk") == label.split("_")[0].count("Bulk"):
                split = line.split(":")
                gtheory.SetPoint(j,
                                 float(split[0][-4:]) / 1000., float(split[1]))
                glogtheory.SetPoint(j,
                                    float(split[0][-4:]) / 1000.,
                                    log(float(split[1])))
                j += 1
    mg.Add(gtheory, "L")
    gtheory.Draw("L")
    if "qW" in label.split("_")[0]:
        ltheory = "q* #rightarrow qW"
    elif "qZ" in label.split("_")[0]:
        ltheory = "q* #rightarrow qZ"
    elif "BulkWW" in label.split("_")[0]:
        ltheory = "G_{Bulk} #rightarrow WW (k/#bar{M}_{Pl}=0.2)"
    elif "RS1WW" in label.split("_")[0]:
        ltheory = "G_{RS} #rightarrow WW (k/#bar{M}_{Pl}=0.1)"
    elif "BulkZZ" in label.split("_")[0]:
        ltheory = "G_{Bulk} #rightarrow ZZ (k/#bar{M}_{Pl}=0.2)"
    elif "RS1ZZ" in label.split("_")[0]:
        ltheory = "G_{RS} #rightarrow ZZ (k/#bar{M}_{Pl}=0.1)"
    elif "WZ" in label.split("_")[0]:
        ltheory = "W' #rightarrow WZ"

    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheory.Eval(mass / 1000.)) > grmean.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "exp crossing", mass
            crossing = -1
        if exp(glogtheory.Eval(mass / 1000.)) < grmean.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "exp crossing", mass
            crossing = 1
    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheory.Eval(mass / 1000.)) > grobs.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "obs crossing", mass
            crossing = -1
        if exp(glogtheory.Eval(mass / 1000.)) < grobs.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "obs crossing", mass
            crossing = 1

    if "WW" in label.split("_")[0] or "ZZ" in label.split("_")[0]:
        leg = rt.TLegend(0.43, 0.65, 0.95, 0.89)
        leg2 = rt.TLegend(0.43, 0.65, 0.95, 0.89)
    else:
        leg = rt.TLegend(0.59, 0.65, 0.95, 0.89)
        leg2 = rt.TLegend(0.59, 0.65, 0.95, 0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetBorderSize(0)
    leg2.SetFillColor(rt.kWhite)
    leg2.SetFillStyle(0)
    leg2.SetTextSize(0.04)
    leg2.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed", "L")
    leg.AddEntry(gryellow, "Expected (68%)", "f")
    leg.AddEntry(grgreen, "Expected (95%)", "f")
    leg.AddEntry(gtheory, ltheory, "L")

    if obs: leg2.AddEntry(grobs, " ", "")
    leg2.AddEntry(grmean, " ", "L")
    leg2.AddEntry(grmean, " ", "L")
    leg2.AddEntry(gtheory, " ", "")

    leg.Draw()
    leg2.Draw("same")

    banner = TLatex(0.22, 0.93,
                    "CMS Preliminary, 19.7 fb^{-1}, #sqrt{s} = 8TeV")
    banner.SetNDC()
    banner.SetTextSize(0.045)
    banner.Draw()

    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s.root" % label)
        c1.SaveAs("brazilianFlag_acc_%s.pdf" % label)
    else:
        c1.SaveAs("brazilianFlag_%s.root" % label)
        c1.SaveAs("brazilianFlag_%s.pdf" % label)
Exemplo n.º 3
0
def Plot(files, label, obs):

    radmasses = []
    imass=650
    for f in files:
        radmasses.append(imass)
        imass=imass+10
    print radmasses

    efficiencies={}
    for mass in radmasses:
        efficiencies[mass]=1. # to convert from fb to fb

    fChain = []
    for onefile in files:
        print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))  

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0,len(fChain)):
            chain = fChain[j]
            chain.SetBranchAddress("limit", rt.AddressOf(limit_branch,'limit'))

    rad = []
    for j in range(0,len(fChain)):
        chain = fChain[j]
        thisrad = []
        for  i in range(0,6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)


    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> ZZ")
    c1 = rt.TCanvas("c1","A Simple Graph Example",200,10,600,600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0,len(fChain)):
        y2up.append(rad[i][0]*efficiencies[radmasses[j]])
        y1up.append(rad[i][1]*efficiencies[radmasses[j]])
        ymean.append(rad[i][2]*efficiencies[radmasses[j]])
        y1down.append(rad[i][3]*efficiencies[radmasses[j]])
        y2down.append(rad[i][4]*efficiencies[radmasses[j]])
        yobs.append(rad[i][5]*efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kBlack)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)
  
    for j in range(0,len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        print(radmasses[j], ymean[j], yobs[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])    
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])
    
    mg.Add(gr2up)#.Draw("same")
    mg.Add(gr1up)#.Draw("same")
    mg.Add(grmean,"L")#.Draw("same,AC*")
    mg.Add(gr1down)#.Draw("same,AC*")
    mg.Add(gr2down)#.Draw("same,AC*")
    if obs: mg.Add(grobs,"L")#.Draw("AC*")
 
    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("Resonance mass (GeV)")
    resonance="G"
        #resonance="G_{Bulk}"
    if withAcceptance:
        mg.GetYaxis().SetTitle("#sigma #times B("+resonance+" #rightarrow "+label.split("_")[0].replace("RS1","").replace("Bulk","")+") #times A (fb)")
    else:
        mg.GetYaxis().SetTitle("95% CL UL on #sigma #times B(X#rightarrowZ#gamma) (fb)")
    mg.GetYaxis().SetRangeUser(0.9,1000)
    mg.GetXaxis().SetNdivisions(508)

    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(500,3000)
    else:
        mg.GetXaxis().SetLimits(500,3150)

    # histo to shade
    n=len(fChain)

    grgreen = rt.TGraph(2*n)
    for i in range(0,n):
        grgreen.SetPoint(i,radmasses[i],y2up[i])
        grgreen.SetPoint(n+i,radmasses[n-i-1],y2down[n-i-1])

    grgreen.SetFillColor(rt.kYellow)
    grgreen.Draw("f") 


    gryellow = rt.TGraph(2*n)
    for i in range(0,n):
        gryellow.SetPoint(i,radmasses[i],y1up[i])
        gryellow.SetPoint(n+i,radmasses[n-i-1],y1down[n-i-1])

    gryellow.SetFillColor(rt.kGreen)
    gryellow.Draw("f,same") 

    grmean.Draw("L")
    if obs: grobs.Draw("L")

    gtheory = rt.TGraphErrors(1)
    gtheory.SetLineColor(rt.kBlack)
    gtheory.SetLineWidth(4)

    if "WW" in label.split("_")[0] or "ZZ" in label.split("_")[0]:
       leg = rt.TLegend(0.5,0.7,0.95,0.89)
       leg2 = rt.TLegend(0.33,0.55,0.95,0.89)
    else:
        leg = rt.TLegend(0.5,0.65,0.95,0.89,"Z(q#bar{q})#gamma: #frac{#Gamma}{m}=1.4#times10^{-4}, J=0")
        leg2 = rt.TLegend(0.49,0.55,0.95,0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetTextFont(42)
    leg.SetBorderSize(0)
    leg2.SetFillColor(rt.kWhite)
    leg2.SetFillStyle(0)
    leg2.SetTextSize(0.04)
    leg2.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed limit", "L")
    leg.AddEntry(grmean, "Expected limit", "L")
    leg.AddEntry(gryellow, "Expected limit #pm 1#sigma", "f")
    leg.AddEntry(grgreen, "Expected limit #pm 2#sigma", "f")
    #leg.AddEntry(gtheory, ltheory, "L")

    if obs: leg2.AddEntry(grobs, " ", "")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(gtheory, " ", "")

    leg.Draw()
    #leg2.Draw("same")

    CMS_lumi.CMS_lumi(c1, iPeriod, iPos)
    c1.cd()
    c1.Update()


    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.root" %label)
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.pdf" %label)
    else:
        c1.SaveAs("brazilianFlag_%s_13TeV.root" %label)
        c1.SaveAs("brazilianFlag_%s_13TeV.pdf" %label)
        grobs.SaveAs("brazilianFlag_observed_%s_13TeV.root" %label)
        grmean.SaveAs("brazilianFlag_expected_%s_13TeV.root" %label)
Exemplo n.º 4
0
def Plot(files, label, obs):

    radmasses = []
    for f in files:
        #        radmasses.append(float(f.replace("CMS_jj_","").split("_")[0])/1000.)
        radmasses = [1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.]  #,3.5,4.,4.5]
    print radmasses

    efficiencies = {}
    for mass in radmasses:
        efficiencies[mass] = 10.  # to convert from pb to fb

    fChain = []
    for onefile in files:
        print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0, len(fChain)):
            chain = fChain[j]
            chain.SetBranchAddress("limit",
                                   rt.AddressOf(limit_branch, 'limit'))

    rad = []
    for j in range(0, len(fChain)):
        chain = fChain[j]
        thisrad = []
        for i in range(0, 6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)

    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> ZZ")
    c1 = rt.TCanvas("c1", "A Simple Graph Example", 200, 10, 600, 600)
    c1.SetGridx(1)
    c1.SetGridy(1)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0, len(fChain)):
        y2up.append(rad[i][0] * efficiencies[radmasses[j]])
        y1up.append(rad[i][1] * efficiencies[radmasses[j]])
        ymean.append(rad[i][2] * efficiencies[radmasses[j]])
        y1down.append(rad[i][3] * efficiencies[radmasses[j]])
        y2down.append(rad[i][4] * efficiencies[radmasses[j]])
        yobs.append(rad[i][5] * efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kBlack)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)

    for j in range(0, len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        print "%f %f %f %f %f" % (radmasses[j], yobs[j], ymean[j], y1up[j],
                                  y1down[j])

    mg.Add(gr2up)  #.Draw("same")
    mg.Add(gr1up)  #.Draw("same")
    mg.Add(grmean, "L")  #.Draw("same,AC*")
    mg.Add(gr1down)  #.Draw("same,AC*")
    mg.Add(gr2down)  #.Draw("same,AC*")
    if obs: mg.Add(grobs, "L")  #.Draw("AC*")

    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("m_{X}^{spin-2} (TeV)")
    resonance = "G_{RS}"
    #resonance="G_{Bulk}"
    if withAcceptance:
        mg.GetYaxis().SetTitle(
            "#sigma #times B(" + resonance + " #rightarrow " +
            label.split("_")[0].replace("RS1", "").replace("Bulk", "") +
            ") #times A (fb)")
    else:
        mg.GetYaxis().SetTitle("#sigma #times B(" + resonance +
                               " #rightarrow HH to b#bar{b}b#bar{b}) (fb)")
    mg.GetYaxis().SetLabelFont(42)
    mg.GetXaxis().SetLabelFont(42)
    mg.GetYaxis().SetTitleFont(42)
    mg.GetXaxis().SetTitleFont(42)
    mg.GetYaxis().SetTitleSize(0.035)
    mg.GetXaxis().SetTitleSize(0.035)
    mg.GetXaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetRangeUser(0.7, 10000)
    mg.GetYaxis().SetTitleOffset(1.4)
    mg.GetYaxis().CenterTitle(True)
    mg.GetXaxis().SetTitleOffset(1.1)
    mg.GetXaxis().CenterTitle(True)
    mg.GetXaxis().SetNdivisions(508)

    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(1.2, 3.5)
    else:
        mg.GetXaxis().SetLimits(1.2, 3.5)

    # histo to shade
    n = len(fChain)

    grgreen = rt.TGraph(2 * n)
    for i in range(0, n):
        grgreen.SetPoint(i, radmasses[i], y2up[i])
        grgreen.SetPoint(n + i, radmasses[n - i - 1], y2down[n - i - 1])

    grgreen.SetFillColor(rt.kYellow)
    grgreen.Draw("f")

    gryellow = rt.TGraph(2 * n)
    for i in range(0, n):
        gryellow.SetPoint(i, radmasses[i], y1up[i])
        gryellow.SetPoint(n + i, radmasses[n - i - 1], y1down[n - i - 1])

    gryellow.SetFillColor(rt.kGreen)
    gryellow.Draw("f,same")

    grmean.Draw("L")
    if obs: grobs.Draw("L")

    gtheory = rt.TGraphErrors(1)
    gtheory.SetLineColor(rt.kBlue + 1)
    gtheory.SetLineWidth(4)
    #ftheory=open("signal_cross_section_RS1Graviton.txt")
    ftheory = open("bulk_graviton_exo15002.txt")
    #ftheory=open("subjet.txt")
    ij = 0
    glogtheory = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
        for line in lines.split("\r"):
            split = line.split(":")
            print(split[1][0:])
            #gtheory.SetPoint(ij, float(split[0][-4:])/1000., float(split[1])*0.57*0.57*1000.)
            #glogtheory.SetPoint(ij, float(split[0][-4:])/1000., log(float(split[1])*0.57*0.57*1000.))
            gtheory.SetPoint(ij, float(split[0][-4:]) / 1., float(split[1]))
            glogtheory.SetPoint(ij,
                                float(split[0][-4:]) / 1.,
                                log(float(split[1])))
            ij += 1
    mg.Add(gtheory, "L")
    gtheory.Draw("L")
    #ltheory="G_{RS1} #rightarrow HH (k/#bar{M}_{Pl}=0.1)"
    ltheory = "G_{Bulk} (k/M_{Pl} = 0.5)"
    #ltheory = "sub-jet b-tag"

    # crossing=0
    # for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
    #     if exp(glogtheory.Eval(mass/1000.))>grmean.Eval(mass/1000.) and crossing>=0:
    #	    print label,"exp crossing",mass
    #	    crossing=-1
    #        if exp(glogtheory.Eval(mass/1000.))<grmean.Eval(mass/1000.) and crossing<=0:
    #	    print label,"exp crossing",mass
    #	    crossing=1
    #    crossing=0
    #    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
    #        if exp(glogtheory.Eval(mass/1000.))>grobs.Eval(mass/1000.) and crossing>=0:
    #	    print label,"obs crossing",mass
    #	    crossing=-1
    #        if exp(glogtheory.Eval(mass/1000.))<grobs.Eval(mass/1000.) and crossing<=0:
    #print label,"obs crossing",mass
    #crossing=1

    if "WW" in label.split("_")[0] or "ZZ" in label.split("_")[0]:
        leg = rt.TLegend(0.53, 0.65, 0.95, 0.89)
        leg2 = rt.TLegend(0.33, 0.55, 0.95, 0.89)
    else:
        leg = rt.TLegend(0.59, 0.65, 0.95, 0.89)
        leg2 = rt.TLegend(0.49, 0.55, 0.95, 0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetTextFont(42)
    leg.SetBorderSize(0)
    leg2.SetFillColor(rt.kWhite)
    leg2.SetFillStyle(0)
    leg2.SetTextSize(0.04)
    leg2.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed", "L")
    leg.AddEntry(gryellow, "Expected (68%)", "f")
    leg.AddEntry(grgreen, "Expected (95%)", "f")
    leg.AddEntry(gtheory, ltheory, "L")

    if obs: leg2.AddEntry(grobs, " ", "")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(gtheory, " ", "")

    leg.Draw()
    #leg2.Draw("same")

    CMS_lumi.CMS_lumi(c1, iPeriod, iPos)
    c1.cd()
    c1.Update()

    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.root" % label)
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.pdf" % label)
    else:
        c1.SaveAs("brazilianFlag_%s_13TeV.root" % label)
        c1.SaveAs("brazilianFlag_%s_13TeV.pdf" % label)
def Plot(files, label, obs):

    radmasses = []
    for f in files:
        radmasses.append(float(f.replace("CMS_jj_","").split("_")[0])/1000.)
    #print radmasses

    efficiencies={}
    for mass in radmasses:
	efficiencies[mass]=0.01*1000. # assume 10/fb signal cross section

    fChain = []
    for onefile in files:
        print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))  
	print fileIN

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0,len(fChain)):
            chain = fChain[j]
            chain.SetBranchAddress("limit", rt.AddressOf(limit_branch,'limit'))

    rad = []
    for j in range(0,len(fChain)):
        chain = fChain[j]
        thisrad = []
        for  i in range(0,6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)


    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> ZZ")
    c1 = rt.TCanvas("c1","A Simple Graph Example",200,10,600,600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0,len(fChain)):
        y2up.append(rad[i][0]*efficiencies[radmasses[j]])
        y1up.append(rad[i][1]*efficiencies[radmasses[j]])
        ymean.append(rad[i][2]*efficiencies[radmasses[j]])
        y1down.append(rad[i][3]*efficiencies[radmasses[j]])
        y2down.append(rad[i][4]*efficiencies[radmasses[j]])
        yobs.append(rad[i][5]*efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kBlack)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)
  
    for j in range(0,len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])    
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])
    
    mg.Add(gr2up)#.Draw("same")
    mg.Add(gr1up)#.Draw("same")
    mg.Add(grmean,"L")#.Draw("same,AC*")
    mg.Add(gr1down)#.Draw("same,AC*")
    mg.Add(gr2down)#.Draw("same,AC*")
    if obs: mg.Add(grobs,"L")#.Draw("AC*")
 
    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("Resonance mass (TeV)")
    if "HH" in label.split("_")[0]:
        resonance="Radion"
    if withAcceptance:
        mg.GetYaxis().SetTitle("#sigma #times B("+resonance+" #rightarrow HH #rightarrow bbbb #times A (fb)")
    else:
        mg.GetYaxis().SetTitle("#sigma #times B("+resonance+" #rightarrow HH #rightarrow bbbb) (fb)")
    mg.GetYaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetRangeUser(0.1,1000)
    mg.GetYaxis().SetTitleOffset(1.4)
    mg.GetYaxis().CenterTitle(True)
    mg.GetXaxis().SetTitleOffset(1.1)
    mg.GetXaxis().CenterTitle(True)
    mg.GetXaxis().SetNdivisions(508)

    mg.GetXaxis().SetLimits(0.9,3.2)

    # histo to shade
    n=len(fChain)

    grgreen = rt.TGraph(2*n)
    for i in range(0,n):
        grgreen.SetPoint(i,radmasses[i],y2up[i])
        grgreen.SetPoint(n+i,radmasses[n-i-1],y2down[n-i-1])

    grgreen.SetFillColor(rt.kBlue)
    grgreen.Draw("f") 


    gryellow = rt.TGraph(2*n)
    for i in range(0,n):
        gryellow.SetPoint(i,radmasses[i],y1up[i])
        gryellow.SetPoint(n+i,radmasses[n-i-1],y1down[n-i-1])

    gryellow.SetFillColor(rt.kBlue-7)
    gryellow.Draw("f,same") 

    grmean.Draw("L")
    if obs: grobs.Draw("L")

    gtheory = rt.TGraphErrors(1)
    gtheory.SetLineColor(rt.kBlue)
    gtheory.SetLineWidth(4)
    ftheory=open("signalcrosssections.txt")
    j=0
    glogtheory = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
     for line in lines.split("\r"):
      if label.split("_")[0] in line and line.count("Bulk")==label.split("_")[0].count("Bulk"):
        split=line.split(":")
        gtheory.SetPoint(j, float(split[0][-4:])/1000., float(split[1]))
        glogtheory.SetPoint(j, float(split[0][-4:])/1000., log(float(split[1])))
	j+=1
    #mg.Add(gtheory,"L")
    #gtheory.Draw("L")
    #if "HH" in label.split("_")[0]:
    #    ltheory="Radion #rightarrow HH"
    
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheory.Eval(mass/1000.))>grmean.Eval(mass/1000.) and crossing>=0:
	    print label,"exp crossing",mass
	    crossing=-1
        if exp(glogtheory.Eval(mass/1000.))<grmean.Eval(mass/1000.) and crossing<=0:
	    print label,"exp crossing",mass
	    crossing=1
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheory.Eval(mass/1000.))>grobs.Eval(mass/1000.) and crossing>=0:
	    print label,"obs crossing",mass
	    crossing=-1
        if exp(glogtheory.Eval(mass/1000.))<grobs.Eval(mass/1000.) and crossing<=0:
	    print label,"obs crossing",mass
	    crossing=1
    
    leg = rt.TLegend(0.43,0.65,0.95,0.89)
    leg2 = rt.TLegend(0.43,0.65,0.95,0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetBorderSize(0)
    leg2.SetFillColor(rt.kWhite)
    leg2.SetFillStyle(0)
    leg2.SetTextSize(0.04)
    leg2.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed", "L")
    leg.AddEntry(gryellow, "Expected (68%)", "f")
    leg.AddEntry(grgreen, "Expected (95%)", "f")
    #leg.AddEntry(gtheory, ltheory, "L")

    if obs: leg2.AddEntry(grobs, " ", "")
    leg2.AddEntry(grmean, " ", "L")
    leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(gtheory, " ", "")

    leg.Draw()
    leg2.Draw("same")

    banner = TLatex(0.22,0.93,"CMS Preliminary, 19.7 fb^{-1}, #sqrt{s} = 8TeV");
    banner.SetNDC()
    banner.SetTextSize(0.045)
    banner.Draw();  

    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s.root" %label)
        c1.SaveAs("brazilianFlag_acc_%s.pdf" %label)
    else:
        c1.SaveAs("brazilianFlag_%s.root" %label)
        c1.SaveAs("brazilianFlag_%s.pdf" %label)
def Plot(files, label, obs):

    radmasses = []
    for f in files:
        radmasses.append(float(f.replace("Xvv.mX","").split("_")[0])/1000.)
    #print radmasses

    efficiencies={}
    for mass in radmasses:
	efficiencies[mass]=number_of_mc_events*0.005/19800.0
        # W-tagging scale factor
        if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
            efficiencies[mass]*=0.89
        else:
            efficiencies[mass]*=0.89*0.89

    fChain = []
    for onefile in files:
        #print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))  

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0,len(fChain)):
            chain = fChain[j]
            print j, chain
            chain.SetBranchAddress("limit", rt.AddressOf(limit_branch,'limit'))

    rad = []
    for j in range(0,len(fChain)):
        chain = fChain[j]
        thisrad = []
        for  i in range(0,6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)


    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> HH")
    c1 = rt.TCanvas("c1","A Simple Graph Example",200,10,600,600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0,len(fChain)):
        y2up.append(rad[i][0]*efficiencies[radmasses[j]])
        y1up.append(rad[i][1]*efficiencies[radmasses[j]])
        ymean.append(rad[i][2]*efficiencies[radmasses[j]])
        y1down.append(rad[i][3]*efficiencies[radmasses[j]])
        y2down.append(rad[i][4]*efficiencies[radmasses[j]])
        yobs.append(rad[i][5]*efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kRed)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)
  
    for j in range(0,len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])    
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])
    
    mg.Add(gr2up)#.Draw("same")
    mg.Add(gr1up)#.Draw("same")
    mg.Add(grmean,"L")#.Draw("same,AC*")
    mg.Add(gr1down)#.Draw("same,AC*")
    mg.Add(gr2down)#.Draw("same,AC*")
    if obs: mg.Add(grobs,"L,P")#.Draw("AC*")
 
    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("Resonance mass (TeV)")
    if withAcceptance:
        mg.GetYaxis().SetTitle("#sigma #times BR(X #rightarrow "+label.split("_")[0]+" #rightarrow 4b) #times A (pb)")
    else:
        mg.GetYaxis().SetTitle("#sigma #times BR(X #rightarrow "+label.split("_")[0]+" #rightarrow 4b) (pb)")
    mg.GetYaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetRangeUser(0.001,4)
    mg.GetYaxis().SetTitleOffset(1.4)
    mg.GetYaxis().CenterTitle(True)
    mg.GetXaxis().SetTitleOffset(1.1)
    mg.GetXaxis().CenterTitle(True)
    mg.GetXaxis().SetNdivisions(508)

    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(0.9,4.1)
    elif "WZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(0.9,2.1)
    else:
        mg.GetXaxis().SetLimits(0.9,3.1)

    # histo to shade
    n=len(fChain)

    grgreen = rt.TGraph(2*n)
    for i in range(0,n):
        grgreen.SetPoint(i,radmasses[i],y2up[i])
        grgreen.SetPoint(n+i,radmasses[n-i-1],y2down[n-i-1])

    grgreen.SetFillColor(rt.kGreen)
    grgreen.Draw("f") 


    gryellow = rt.TGraph(2*n)
    for i in range(0,n):
        gryellow.SetPoint(i,radmasses[i],y1up[i])
        gryellow.SetPoint(n+i,radmasses[n-i-1],y1down[n-i-1])

    gryellow.SetFillColor(rt.kYellow)
    gryellow.Draw("f,same") 

    grmean.Draw("L")
    if obs: grobs.Draw("L,P,E")



    gtheoryRadion = rt.TGraphErrors(1)
    gtheoryRadion.SetLineColor(rt.kBlue)
    gtheoryRadion.SetLineWidth(3)
    ftheory=open("HH_crosssections.txt")
    j=0
    glogtheoryRadion = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
     for line in lines.split("\r"):
      if "Radion" in line:
        split=line.split(":")
        print split[1]
        gtheoryRadion.SetPoint(j, float(split[0][-4:])/1000., float(split[1]))
        glogtheoryRadion.SetPoint(j, float(split[0][-4:])/1000., log(float(split[1])))
	j+=1
    mg.Add(gtheoryRadion,"L")
    gtheoryRadion.Draw("L")
    if "HH" in label.split("_")[0]:
        ltheoryRadion="Radion #rightarrow HH"
    
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheoryRadion.Eval(mass/1000.))>grmean.Eval(mass/1000.) and crossing>=0:
	    print label,"exp crossing",mass
	    crossing=-1
        if exp(glogtheoryRadion.Eval(mass/1000.))<grmean.Eval(mass/1000.) and crossing<=0:
	    print label,"exp crossing",mass
	    crossing=1
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheoryRadion.Eval(mass/1000.))>grobs.Eval(mass/1000.) and crossing>=0:
	    print label,"obs crossing",mass
	    crossing=-1
        if exp(glogtheoryRadion.Eval(mass/1000.))<grobs.Eval(mass/1000.) and crossing<=0:
	    print label,"obs crossing",mass
	    crossing=1


            

    gtheoryBrane = rt.TGraphErrors(1)
    gtheoryBrane.SetLineColor(28)
    gtheoryBrane.SetLineWidth(3)
    ftheory=open("HH_crosssections.txt")
    j=0
    glogtheoryBrane = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
     for line in lines.split("\r"):
      if "BraneGraviton" in line:
        split=line.split(":")
        print split[1]
        gtheoryBrane.SetPoint(j, float(split[0][-4:])/1000., float(split[1]))
        glogtheoryBrane.SetPoint(j, float(split[0][-4:])/1000., log(float(split[1])))
	j+=1
    mg.Add(gtheoryBrane,"L")
    gtheoryBrane.Draw("L")
    if "HH" in label.split("_")[0]:
        ltheoryBrane="Brane G #rightarrow HH"
    
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheoryBrane.Eval(mass/1000.))>grmean.Eval(mass/1000.) and crossing>=0:
	    print label,"exp crossing",mass
	    crossing=-1
        if exp(glogtheoryBrane.Eval(mass/1000.))<grmean.Eval(mass/1000.) and crossing<=0:
	    print label,"exp crossing",mass
	    crossing=1
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheoryBrane.Eval(mass/1000.))>grobs.Eval(mass/1000.) and crossing>=0:
	    print label,"obs crossing",mass
	    crossing=-1
        if exp(glogtheoryBrane.Eval(mass/1000.))<grobs.Eval(mass/1000.) and crossing<=0:
	    print label,"obs crossing",mass
	    crossing=1



    gtheoryBulk = rt.TGraphErrors(1)
    gtheoryBulk.SetLineColor(6)
    gtheoryBulk.SetLineWidth(3)
    ftheory=open("HH_crosssections.txt")
    j=0
    glogtheoryBulk = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
     for line in lines.split("\r"):
      if "BulkGraviton" in line:
        split=line.split(":")
        print split[1]
        gtheoryBulk.SetPoint(j, float(split[0][-4:])/1000., float(split[1]))
        glogtheoryBulk.SetPoint(j, float(split[0][-4:])/1000., log(float(split[1])))
	j+=1
    mg.Add(gtheoryBulk,"L")
    gtheoryBulk.Draw("L")
    if "HH" in label.split("_")[0]:
        ltheoryBulk="Bulk G #rightarrow HH"
    
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheoryBulk.Eval(mass/1000.))>grmean.Eval(mass/1000.) and crossing>=0:
	    print label,"exp crossing",mass
	    crossing=-1
        if exp(glogtheoryBulk.Eval(mass/1000.))<grmean.Eval(mass/1000.) and crossing<=0:
	    print label,"exp crossing",mass
	    crossing=1
    crossing=0
    for mass in range(int(radmasses[0]*1000.),int(radmasses[-1]*1000.)):
        if exp(glogtheoryBulk.Eval(mass/1000.))>grobs.Eval(mass/1000.) and crossing>=0:
	    print label,"obs crossing",mass
	    crossing=-1
        if exp(glogtheoryBulk.Eval(mass/1000.))<grobs.Eval(mass/1000.) and crossing<=0:
	    print label,"obs crossing",mass
	    crossing=1


            
    
    leg = rt.TLegend(0.60,0.65,0.95,0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed", "L,P")
    leg.AddEntry(grmean, "Expected", "L")
    leg.AddEntry(gryellow, "#pm 1 #sigma Expected", "f")
    leg.AddEntry(grgreen, "#pm 2 #sigma Expected", "f")
    leg.AddEntry(gtheoryRadion, ltheoryRadion, "L")
    leg.AddEntry(gtheoryBrane, ltheoryBrane, "L")
    leg.AddEntry(gtheoryBulk, ltheoryBulk, "L")
    #leg.SetHeader("X #rightarrow %s" %label.split("_")[0])

    leg.Draw()

    banner = TLatex(0.22,0.93,"CMS Preliminary, 19.8 fb^{-1}, #sqrt{s} = 8TeV");
    banner.SetNDC()
    banner.SetTextSize(0.045)
    banner.Draw();  

    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s.root" %label)
        c1.SaveAs("brazilianFlag_acc_%s.pdf" %label)
    else:
        c1.SaveAs("brazilianFlag_%s.root" %label)
        c1.SaveAs("brazilianFlag_%s.pdf" %label)
def Plot(files, label, obs):

    radmasses = []
    for f in files:
        radmasses.append(float(f.replace("Xvv.mX", "").split("_")[0]) / 1000.)
    #print radmasses

    efficiencies = {}
    for mass in radmasses:
        efficiencies[mass] = number_of_mc_events * 0.005 / 19800.0
        # W-tagging scale factor
        if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
            efficiencies[mass] *= 0.89
        else:
            efficiencies[mass] *= 0.89 * 0.89

    fChain = []
    for onefile in files:
        #print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0, len(fChain)):
            chain = fChain[j]
            print j, chain
            chain.SetBranchAddress("limit",
                                   rt.AddressOf(limit_branch, 'limit'))

    rad = []
    for j in range(0, len(fChain)):
        chain = fChain[j]
        thisrad = []
        for i in range(0, 6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)

    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> HH")
    c1 = rt.TCanvas("c1", "A Simple Graph Example", 200, 10, 600, 600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0, len(fChain)):
        y2up.append(rad[i][0] * efficiencies[radmasses[j]])
        y1up.append(rad[i][1] * efficiencies[radmasses[j]])
        ymean.append(rad[i][2] * efficiencies[radmasses[j]])
        y1down.append(rad[i][3] * efficiencies[radmasses[j]])
        y2down.append(rad[i][4] * efficiencies[radmasses[j]])
        yobs.append(rad[i][5] * efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kRed)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)

    for j in range(0, len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])

    mg.Add(gr2up)  #.Draw("same")
    mg.Add(gr1up)  #.Draw("same")
    mg.Add(grmean, "L")  #.Draw("same,AC*")
    mg.Add(gr1down)  #.Draw("same,AC*")
    mg.Add(gr2down)  #.Draw("same,AC*")
    if obs: mg.Add(grobs, "L,P")  #.Draw("AC*")

    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("Resonance mass (TeV)")
    if withAcceptance:
        mg.GetYaxis().SetTitle("#sigma #times BR(X #rightarrow " +
                               label.split("_")[0] +
                               " #rightarrow 4b) #times A (pb)")
    else:
        mg.GetYaxis().SetTitle("#sigma #times BR(X #rightarrow " +
                               label.split("_")[0] + " #rightarrow 4b) (pb)")
    mg.GetYaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetTitleSize(0.06)
    mg.GetXaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetLabelSize(0.045)
    mg.GetYaxis().SetRangeUser(0.001, 4)
    mg.GetYaxis().SetTitleOffset(1.4)
    mg.GetYaxis().CenterTitle(True)
    mg.GetXaxis().SetTitleOffset(1.1)
    mg.GetXaxis().CenterTitle(True)
    mg.GetXaxis().SetNdivisions(508)

    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(0.9, 4.1)
    elif "WZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(0.9, 2.1)
    else:
        mg.GetXaxis().SetLimits(0.9, 3.1)

    # histo to shade
    n = len(fChain)

    grgreen = rt.TGraph(2 * n)
    for i in range(0, n):
        grgreen.SetPoint(i, radmasses[i], y2up[i])
        grgreen.SetPoint(n + i, radmasses[n - i - 1], y2down[n - i - 1])

    grgreen.SetFillColor(rt.kGreen)
    grgreen.Draw("f")

    gryellow = rt.TGraph(2 * n)
    for i in range(0, n):
        gryellow.SetPoint(i, radmasses[i], y1up[i])
        gryellow.SetPoint(n + i, radmasses[n - i - 1], y1down[n - i - 1])

    gryellow.SetFillColor(rt.kYellow)
    gryellow.Draw("f,same")

    grmean.Draw("L")
    if obs: grobs.Draw("L,P,E")

    gtheoryRadion = rt.TGraphErrors(1)
    gtheoryRadion.SetLineColor(rt.kBlue)
    gtheoryRadion.SetLineWidth(3)
    ftheory = open("HH_crosssections.txt")
    j = 0
    glogtheoryRadion = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
        for line in lines.split("\r"):
            if "Radion" in line:
                split = line.split(":")
                print split[1]
                gtheoryRadion.SetPoint(j,
                                       float(split[0][-4:]) / 1000.,
                                       float(split[1]))
                glogtheoryRadion.SetPoint(j,
                                          float(split[0][-4:]) / 1000.,
                                          log(float(split[1])))
                j += 1
    mg.Add(gtheoryRadion, "L")
    gtheoryRadion.Draw("L")
    if "HH" in label.split("_")[0]:
        ltheoryRadion = "Radion #rightarrow HH"

    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheoryRadion.Eval(mass / 1000.)) > grmean.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "exp crossing", mass
            crossing = -1
        if exp(glogtheoryRadion.Eval(mass / 1000.)) < grmean.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "exp crossing", mass
            crossing = 1
    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheoryRadion.Eval(mass / 1000.)) > grobs.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "obs crossing", mass
            crossing = -1
        if exp(glogtheoryRadion.Eval(mass / 1000.)) < grobs.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "obs crossing", mass
            crossing = 1

    gtheoryBrane = rt.TGraphErrors(1)
    gtheoryBrane.SetLineColor(28)
    gtheoryBrane.SetLineWidth(3)
    ftheory = open("HH_crosssections.txt")
    j = 0
    glogtheoryBrane = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
        for line in lines.split("\r"):
            if "BraneGraviton" in line:
                split = line.split(":")
                print split[1]
                gtheoryBrane.SetPoint(j,
                                      float(split[0][-4:]) / 1000.,
                                      float(split[1]))
                glogtheoryBrane.SetPoint(j,
                                         float(split[0][-4:]) / 1000.,
                                         log(float(split[1])))
                j += 1
    mg.Add(gtheoryBrane, "L")
    gtheoryBrane.Draw("L")
    if "HH" in label.split("_")[0]:
        ltheoryBrane = "Brane G #rightarrow HH"

    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheoryBrane.Eval(mass / 1000.)) > grmean.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "exp crossing", mass
            crossing = -1
        if exp(glogtheoryBrane.Eval(mass / 1000.)) < grmean.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "exp crossing", mass
            crossing = 1
    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheoryBrane.Eval(mass / 1000.)) > grobs.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "obs crossing", mass
            crossing = -1
        if exp(glogtheoryBrane.Eval(mass / 1000.)) < grobs.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "obs crossing", mass
            crossing = 1

    gtheoryBulk = rt.TGraphErrors(1)
    gtheoryBulk.SetLineColor(6)
    gtheoryBulk.SetLineWidth(3)
    ftheory = open("HH_crosssections.txt")
    j = 0
    glogtheoryBulk = rt.TGraphErrors(1)
    for lines in ftheory.readlines():
        for line in lines.split("\r"):
            if "BulkGraviton" in line:
                split = line.split(":")
                print split[1]
                gtheoryBulk.SetPoint(j,
                                     float(split[0][-4:]) / 1000.,
                                     float(split[1]))
                glogtheoryBulk.SetPoint(j,
                                        float(split[0][-4:]) / 1000.,
                                        log(float(split[1])))
                j += 1
    mg.Add(gtheoryBulk, "L")
    gtheoryBulk.Draw("L")
    if "HH" in label.split("_")[0]:
        ltheoryBulk = "Bulk G #rightarrow HH"

    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheoryBulk.Eval(mass / 1000.)) > grmean.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "exp crossing", mass
            crossing = -1
        if exp(glogtheoryBulk.Eval(mass / 1000.)) < grmean.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "exp crossing", mass
            crossing = 1
    crossing = 0
    for mass in range(int(radmasses[0] * 1000.), int(radmasses[-1] * 1000.)):
        if exp(glogtheoryBulk.Eval(mass / 1000.)) > grobs.Eval(
                mass / 1000.) and crossing >= 0:
            print label, "obs crossing", mass
            crossing = -1
        if exp(glogtheoryBulk.Eval(mass / 1000.)) < grobs.Eval(
                mass / 1000.) and crossing <= 0:
            print label, "obs crossing", mass
            crossing = 1

    leg = rt.TLegend(0.60, 0.65, 0.95, 0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed", "L,P")
    leg.AddEntry(grmean, "Expected", "L")
    leg.AddEntry(gryellow, "#pm 1 #sigma Expected", "f")
    leg.AddEntry(grgreen, "#pm 2 #sigma Expected", "f")
    leg.AddEntry(gtheoryRadion, ltheoryRadion, "L")
    leg.AddEntry(gtheoryBrane, ltheoryBrane, "L")
    leg.AddEntry(gtheoryBulk, ltheoryBulk, "L")
    #leg.SetHeader("X #rightarrow %s" %label.split("_")[0])

    leg.Draw()

    banner = TLatex(0.22, 0.93,
                    "CMS Preliminary, 19.8 fb^{-1}, #sqrt{s} = 8TeV")
    banner.SetNDC()
    banner.SetTextSize(0.045)
    banner.Draw()

    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s.root" % label)
        c1.SaveAs("brazilianFlag_acc_%s.pdf" % label)
    else:
        c1.SaveAs("brazilianFlag_%s.root" % label)
        c1.SaveAs("brazilianFlag_%s.pdf" % label)
Exemplo n.º 8
0
def Plot(files, label, obs):

    radmasses = []
    imass = 650
    for f in files:
        radmasses.append(imass)
        imass = imass + 10
    print radmasses

    efficiencies = {}
    for mass in radmasses:
        efficiencies[mass] = 1.  # to convert from fb to fb

    fChain = []
    for onefile in files:
        print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0, len(fChain)):
            chain = fChain[j]
            chain.SetBranchAddress("limit",
                                   rt.AddressOf(limit_branch, 'limit'))

    rad = []
    for j in range(0, len(fChain)):
        chain = fChain[j]
        thisrad = []
        for i in range(0, 6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)

    # we do a plot r*MR
    mg = rt.TMultiGraph()
    mg.SetTitle("X -> ZZ")
    c1 = rt.TCanvas("c1", "A Simple Graph Example", 200, 10, 600, 600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0, len(fChain)):
        y2up.append(rad[i][0] * efficiencies[radmasses[j]])
        y1up.append(rad[i][1] * efficiencies[radmasses[j]])
        ymean.append(rad[i][2] * efficiencies[radmasses[j]])
        y1down.append(rad[i][3] * efficiencies[radmasses[j]])
        y2down.append(rad[i][4] * efficiencies[radmasses[j]])
        yobs.append(rad[i][5] * efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetLineColor(rt.kBlack)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)

    for j in range(0, len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        print(radmasses[j], ymean[j], yobs[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])

    mg.Add(gr2up)  #.Draw("same")
    mg.Add(gr1up)  #.Draw("same")
    mg.Add(grmean, "L")  #.Draw("same,AC*")
    mg.Add(gr1down)  #.Draw("same,AC*")
    mg.Add(gr2down)  #.Draw("same,AC*")
    if obs: mg.Add(grobs, "L")  #.Draw("AC*")

    c1.SetLogy(1)
    mg.SetTitle("")
    mg.Draw("AP")
    mg.GetXaxis().SetTitle("Resonance mass (GeV)")
    resonance = "G"
    #resonance="G_{Bulk}"
    if withAcceptance:
        mg.GetYaxis().SetTitle(
            "#sigma #times B(" + resonance + " #rightarrow " +
            label.split("_")[0].replace("RS1", "").replace("Bulk", "") +
            ") #times A (fb)")
    else:
        mg.GetYaxis().SetTitle(
            "95% CL UL on #sigma #times B(X#rightarrowZ#gamma) (fb)")
    mg.GetYaxis().SetRangeUser(0.9, 1000)
    mg.GetXaxis().SetNdivisions(508)

    if "qW" in label.split("_")[0] or "qZ" in label.split("_")[0]:
        mg.GetXaxis().SetLimits(500, 3000)
    else:
        mg.GetXaxis().SetLimits(500, 3150)

    # histo to shade
    n = len(fChain)

    grgreen = rt.TGraph(2 * n)
    for i in range(0, n):
        grgreen.SetPoint(i, radmasses[i], y2up[i])
        grgreen.SetPoint(n + i, radmasses[n - i - 1], y2down[n - i - 1])

    grgreen.SetFillColor(rt.kYellow)
    grgreen.Draw("f")

    gryellow = rt.TGraph(2 * n)
    for i in range(0, n):
        gryellow.SetPoint(i, radmasses[i], y1up[i])
        gryellow.SetPoint(n + i, radmasses[n - i - 1], y1down[n - i - 1])

    gryellow.SetFillColor(rt.kGreen)
    gryellow.Draw("f,same")

    grmean.Draw("L")
    if obs: grobs.Draw("L")

    gtheory = rt.TGraphErrors(1)
    gtheory.SetLineColor(rt.kBlack)
    gtheory.SetLineWidth(4)

    if "WW" in label.split("_")[0] or "ZZ" in label.split("_")[0]:
        leg = rt.TLegend(0.5, 0.7, 0.95, 0.89)
        leg2 = rt.TLegend(0.33, 0.55, 0.95, 0.89)
    else:
        leg = rt.TLegend(
            0.5, 0.65, 0.95, 0.89,
            "Z(q#bar{q})#gamma: #frac{#Gamma}{m}=1.4#times10^{-4}, J=0")
        leg2 = rt.TLegend(0.49, 0.55, 0.95, 0.89)
    leg.SetFillColor(rt.kWhite)
    leg.SetFillStyle(0)
    leg.SetTextSize(0.04)
    leg.SetTextFont(42)
    leg.SetBorderSize(0)
    leg2.SetFillColor(rt.kWhite)
    leg2.SetFillStyle(0)
    leg2.SetTextSize(0.04)
    leg2.SetBorderSize(0)

    if obs: leg.AddEntry(grobs, "Observed limit", "L")
    leg.AddEntry(grmean, "Expected limit", "L")
    leg.AddEntry(gryellow, "Expected limit #pm 1#sigma", "f")
    leg.AddEntry(grgreen, "Expected limit #pm 2#sigma", "f")
    #leg.AddEntry(gtheory, ltheory, "L")

    if obs: leg2.AddEntry(grobs, " ", "")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(grmean, " ", "L")
    #leg2.AddEntry(gtheory, " ", "")

    leg.Draw()
    #leg2.Draw("same")

    CMS_lumi.CMS_lumi(c1, iPeriod, iPos)
    c1.cd()
    c1.Update()

    if withAcceptance:
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.root" % label)
        c1.SaveAs("brazilianFlag_acc_%s_13TeV.pdf" % label)
    else:
        c1.SaveAs("brazilianFlag_%s_13TeV.root" % label)
        c1.SaveAs("brazilianFlag_%s_13TeV.pdf" % label)
        grobs.SaveAs("brazilianFlag_observed_%s_13TeV.root" % label)
        grmean.SaveAs("brazilianFlag_expected_%s_13TeV.root" % label)
def Plot(files, label, obs):

    radmasses = [ m*0.1 for m in range(10,26+1) ]
    #for f in files:
    #    radmasses.append(float(f.replace("CMS_jj_","").split("_")[0])/1000.)
    #print radmasses

    #all the limits already have Higgs decay branching ratio taken into account
    #so here we only have to correct the Z decay branching ratio
    efficiencies={}
    for mass in radmasses:
	if "Z" in label :
	    efficiencies[mass]=0.01/0.699 # assume 10/fb signal cross section, take Z decay branching ratio into account
	if "W" in label :
            efficiencies[mass]=0.01/0.676 # assume 10/fb signal cross section, take W decay branching ratio into account

    fChain = []
    for onefile in files:
        print onefile
        fileIN = rt.TFile.Open(onefile)
        fChain.append(fileIN.Get("limit;1"))  

        rt.gROOT.ProcessLine("struct limit_t {Double_t limit;};")
        from ROOT import limit_t
        limit_branch = limit_t()

        for j in range(0,len(fChain)):
            chain = fChain[j]
            chain.SetBranchAddress("limit", rt.AddressOf(limit_branch,'limit'))

    rad = []
    for j in range(0,len(fChain)):
        chain = fChain[j]
        thisrad = []
        for  i in range(0,6):
            chain.GetTree().GetEntry(i)
            thisrad.append(limit_branch.limit)
            #print "limit = %f" %limit_branch.limit
        #print thisrad
        rad.append(thisrad)


    # we do a plot r*MR
   # mg = rt.TMultiGraph()
   # mg.SetTitle("X -> ZZ")
   # c1 = rt.TCanvas("c1","A Simple Graph Example",200,10,600,600)
    x = []
    yobs = []
    y2up = []
    y1up = []
    y1down = []
    y2down = []
    ymean = []

    for i in range(0,len(fChain)):
        y2up.append(rad[i][0]*efficiencies[radmasses[j]])
        y1up.append(rad[i][1]*efficiencies[radmasses[j]])
        ymean.append(rad[i][2]*efficiencies[radmasses[j]])
        y1down.append(rad[i][3]*efficiencies[radmasses[j]])
        y2down.append(rad[i][4]*efficiencies[radmasses[j]])
        yobs.append(rad[i][5]*efficiencies[radmasses[j]])

    grobs = rt.TGraphErrors(1)
    #grobs.SetMarkerStyle(rt.kFullDotLarge)
    grobs.SetMarkerStyle(24)
    grobs.SetMarkerSize(1)
    grobs.SetLineColor(rt.kRed)
    grobs.SetLineWidth(3)
    gr2up = rt.TGraphErrors(1)
    gr2up.SetMarkerColor(0)
    gr1up = rt.TGraphErrors(1)
    gr1up.SetMarkerColor(0)
    grmean = rt.TGraphErrors(1)
    grmean.SetLineColor(1)
    grmean.SetLineWidth(2)
    grmean.SetLineStyle(3)
    gr1down = rt.TGraphErrors(1)
    gr1down.SetMarkerColor(0)
    gr2down = rt.TGraphErrors(1)
    gr2down.SetMarkerColor(0)
  
    for j in range(0,len(fChain)):
        grobs.SetPoint(j, radmasses[j], yobs[j])
        gr2up.SetPoint(j, radmasses[j], y2up[j])
        gr1up.SetPoint(j, radmasses[j], y1up[j])
        grmean.SetPoint(j, radmasses[j], ymean[j])
        gr1down.SetPoint(j, radmasses[j], y1down[j])    
        gr2down.SetPoint(j, radmasses[j], y2down[j])
        #print " observed %f %f" %(radmasses[j],yobs[j])
    return grobs, grmean, gr2up, gr2down, gr1up, gr1down