def EffiGraph1D(effDataList, effMCList, sfList ,etaPlot,nameout):
            
    W = 800
    H = 800
    yUp = 0.45
    canName = 'totoPt'
    if etaPlot:
        canName = 'totoEta'
    c = rt.TCanvas(canName,canName,50,50,H,W)
    c.SetTopMargin(0.055)
    c.SetBottomMargin(0.10)
    c.SetLeftMargin(0.12)
    
    
    p1 = rt.TPad( canName + '_up', canName + '_up', 0, yUp, 1,   1, 0,0,0)
    p2 = rt.TPad( canName + '_do', canName + '_do', 0,   0, 1, yUp, 0,0,0)
    p1.SetBottomMargin(0.0075)
    p1.SetTopMargin(   c.GetTopMargin()*1/(1-yUp))
    p2.SetTopMargin(   0.0075)
    p2.SetBottomMargin( c.GetBottomMargin()*1/yUp)
    p1.SetLeftMargin( c.GetLeftMargin() )
    p2.SetLeftMargin( c.GetLeftMargin() )
    firstGraph = True
    leg = rt.TLegend(0.5,0.80,0.95 ,0.92)
    leg.SetFillColor(0)
    leg.SetBorderSize(0)
    if not etaPlot:
        p1.SetLogx()
        p2.SetLogx()

    igr = 0
    listOfTGraph1 = []
    listOfTGraph2 = []
    listOfMC      = []
    xMin = 10
    xMax = 200
    if etaPlot:
        xMin = 0.0
#        xMin = -2.60
        xMax = +2.60
    

    minmax =  findMinMax( effDataList )
    effiMin = minmax[0]
    effiMax = minmax[1]
    
    for key in sorted(effDataList.keys()):
        grBinsEffData = effUtil.makeTGraphFromList(effDataList[key], 'min', 'max')
        grBinsSF      = effUtil.makeTGraphFromList(sfList[key]     , 'min', 'max')
        grBinsEffMC = None
        if not effMCList is None:
            grBinsEffMC = effUtil.makeTGraphFromList(effMCList[key], 'min', 'max')
            grBinsEffMC.SetLineStyle( rt.kDashed )
            grBinsEffMC.SetLineColor( graphColors[igr] )
            grBinsEffMC.SetMarkerSize( 0 )
            grBinsEffMC.SetLineWidth( 2 )

        grBinsSF     .SetMarkerColor( graphColors[igr] )
        grBinsSF     .SetLineColor(   graphColors[igr] )
        grBinsSF     .SetLineWidth(2)
        grBinsEffData.SetMarkerColor( graphColors[igr] )
        grBinsEffData.SetLineColor(   graphColors[igr] )
        grBinsEffData.SetLineWidth(2) 
                
        grBinsEffData.GetHistogram().SetMinimum(effiMin)
        grBinsEffData.GetHistogram().SetMaximum(effiMax)



#        if not etaPlot:
            ### for pT 1D plot, use the actual TGraph range
#            xMin = grBinsEffData.GetHistogram().GetXaxis().GetXmin()
#            xMax = grBinsEffData.GetHistogram().GetXaxis().GetXmax()
            
            #            if grBinsEffData.GetHistogram().GetXaxis().GetXmin() < xMin:
            #    xMin = grBinsEffData.GetHistogram().GetXaxis().GetXmin()
            #if grBinsEffData.GetHistogram().GetXaxis().GetXmax() > xMax:
            #    xMax = grBinsEffData.GetHistogram().GetXaxis().GetXmax()
        
        grBinsEffData.GetHistogram().GetXaxis().SetLimits(xMin,xMax)
        grBinsSF.GetHistogram()     .GetXaxis().SetLimits(xMin,xMax)
        grBinsSF.GetHistogram().SetMinimum(sfMin)
        grBinsSF.GetHistogram().SetMaximum(sfMax)


        
        grBinsSF.GetHistogram().GetXaxis().SetTitleOffset(1)
        if etaPlot:
            grBinsSF.GetHistogram().GetXaxis().SetTitle("SuperCluster #eta")
        else:
            grBinsSF.GetHistogram().GetXaxis().SetTitle("p_{T}  [GeV]")  
            
        grBinsSF.GetHistogram().GetYaxis().SetTitle("Data / MC " )
        grBinsSF.GetHistogram().GetYaxis().SetTitleOffset(1)
            
        grBinsEffData.GetHistogram().GetYaxis().SetTitleOffset(1)
        grBinsEffData.GetHistogram().GetYaxis().SetTitle("Data efficiency" )
        grBinsEffData.GetHistogram().GetYaxis().SetRangeUser( effiMin, effiMax )

            
        ### to avoid loosing the TGraph keep it in memory by adding it to a list
        listOfTGraph1.append( grBinsEffData )
        listOfTGraph2.append( grBinsSF ) 
        listOfMC.append( grBinsEffMC   )
        if etaPlot:
            leg.AddEntry( grBinsEffData, '%3.0f #leq p_{T} #leq  %3.0f GeV'   % (float(key[0]),float(key[1])), "PL")        
        else:
            leg.AddEntry( grBinsEffData, '%1.3f #leq | #eta | #leq  %1.3f' % (float(key[0]),float(key[1])), "PL")        

        
    for igr in range(len(listOfTGraph1)+1):

        option = "P"
        if igr == 1:
            option = "AP"

        use_igr = igr
        if use_igr == len(listOfTGraph1):
            use_igr = 0
            
        listOfTGraph1[use_igr].SetLineColor(graphColors[use_igr])
        listOfTGraph1[use_igr].SetMarkerColor(graphColors[use_igr])
        if not listOfMC[use_igr] is None:
            listOfMC[use_igr].SetLineColor(graphColors[use_igr])

        listOfTGraph1[use_igr].GetHistogram().SetMinimum(effiMin)
        listOfTGraph1[use_igr].GetHistogram().SetMaximum(effiMax)
        p1.cd()
        listOfTGraph1[use_igr].Draw(option)
        if not listOfMC[use_igr] is None:
            listOfMC[use_igr].Draw("ez")

        p2.cd()            
        listOfTGraph2[use_igr].SetLineColor(graphColors[use_igr])
        listOfTGraph2[use_igr].SetMarkerColor(graphColors[use_igr])
        listOfTGraph2[use_igr].GetHistogram().SetMinimum(sfMin)
        listOfTGraph2[use_igr].GetHistogram().SetMaximum(sfMax)
        if not etaPlot:
            listOfTGraph2[use_igr].GetHistogram().GetXaxis().SetMoreLogLabels()
        listOfTGraph2[use_igr].GetHistogram().GetXaxis().SetNoExponent()
        listOfTGraph2[use_igr].Draw(option)
        

    lineAtOne = rt.TLine(xMin,1,xMax,1)
    lineAtOne.SetLineStyle(rt.kDashed)
    lineAtOne.SetLineWidth(2)
    
    p2.cd()
    lineAtOne.Draw()

    c.cd()
    p2.Draw()
    p1.Draw()

    leg.Draw()    
    CMS_lumi.CMS_lumi(c, 4, 10)

    c.Print(nameout)
def EffiGraph1D(effDataList,
                effMCList,
                sfList,
                nameout,
                xAxis='pT',
                yAxis='eta'):

    W = 800
    H = 800
    yUp = 0.45
    canName = 'toto' + xAxis

    c = rt.TCanvas(canName, canName, 50, 50, H, W)
    c.SetTopMargin(0.055)
    c.SetBottomMargin(0.10)
    c.SetLeftMargin(0.12)

    p1 = rt.TPad(canName + '_up', canName + '_up', 0, yUp, 1, 1, 0, 0, 0)
    p2 = rt.TPad(canName + '_do', canName + '_do', 0, 0, 1, yUp, 0, 0, 0)
    p1.SetBottomMargin(0.0075)
    p1.SetTopMargin(c.GetTopMargin() * 1 / (1 - yUp))
    p2.SetTopMargin(0.0075)
    p2.SetBottomMargin(c.GetBottomMargin() * 1 / yUp)
    p1.SetLeftMargin(c.GetLeftMargin())
    p2.SetLeftMargin(c.GetLeftMargin())
    firstGraph = True
    leg = rt.TLegend(0.5, 0.80, 0.95, 0.92)
    leg.SetFillColor(0)
    leg.SetBorderSize(0)

    igr = 0
    listOfTGraph1 = []
    listOfTGraph2 = []
    listOfMC = []

    xMin = 10
    xMax = 200
    if 'pT' in xAxis or 'pt' in xAxis:
        p1.SetLogx()
        p2.SetLogx()
        xMin = 10
        #xMax = 500
        xMax = 50  #bing
    elif 'vtx' in xAxis or 'Vtx' in xAxis or 'PV' in xAxis:
        xMin = 3
        xMax = 42
    elif 'eta' in xAxis or 'Eta' in xAxis:
        xMin = -2.60
        xMax = +2.60

    if 'abs' in xAxis or 'Abs' in xAxis:
        xMin = 0.0

    effminmax = findMinMax(effDataList)
    effiMin = effminmax[0]
    effiMax = effminmax[1]
    effiMin = 0.18
    effiMax = 1.35

    sfminmax = findMinMax(sfList)
    sfMin = sfminmax[0]
    sfMin = 0.78
    #sfMax = 1.52
    sfMax = 1.31
    #sfMin = sfminmax[0]#bing
    #sfMax = 2.1#bing

    for key in sorted(effDataList.keys()):
        grBinsEffData = effUtil.makeTGraphFromList(effDataList[key], 'min',
                                                   'max')
        grBinsSF = effUtil.makeTGraphFromList(sfList[key], 'min', 'max')
        grBinsEffMC = None
        if not effMCList is None:
            grBinsEffMC = effUtil.makeTGraphFromList(effMCList[key], 'min',
                                                     'max')
            grBinsEffMC.SetLineStyle(rt.kDashed)
            grBinsEffMC.SetLineColor(graphColors[igr])
            grBinsEffMC.SetMarkerSize(0)
            grBinsEffMC.SetLineWidth(2)

        grBinsSF.SetMarkerColor(graphColors[igr])
        grBinsSF.SetLineColor(graphColors[igr])
        grBinsSF.SetLineWidth(2)
        grBinsEffData.SetMarkerColor(graphColors[igr])
        grBinsEffData.SetLineColor(graphColors[igr])
        grBinsEffData.SetLineWidth(2)

        grBinsEffData.GetHistogram().SetMinimum(effiMin)
        grBinsEffData.GetHistogram().SetMaximum(effiMax)

        grBinsEffData.GetHistogram().GetXaxis().SetLimits(xMin, xMax)
        grBinsSF.GetHistogram().GetXaxis().SetLimits(xMin, xMax)
        grBinsSF.GetHistogram().SetMinimum(sfMin)
        grBinsSF.GetHistogram().SetMaximum(sfMax)

        grBinsSF.GetHistogram().GetXaxis().SetTitleOffset(1)
        if 'eta' in xAxis or 'Eta' in xAxis:
            grBinsSF.GetHistogram().GetXaxis().SetTitle("SuperCluster #eta")
        elif 'pt' in xAxis or 'pT' in xAxis:
            grBinsSF.GetHistogram().GetXaxis().SetTitle("p_{T}  [GeV]")
        elif 'vtx' in xAxis or 'Vtx' in xAxis or 'PV' in xAxis:
            grBinsSF.GetHistogram().GetXaxis().SetTitle("N_{vtx}")

        grBinsSF.GetHistogram().GetYaxis().SetTitle("Data / MC ")
        grBinsSF.GetHistogram().GetYaxis().SetTitleOffset(1)

        grBinsEffData.GetHistogram().GetYaxis().SetTitleOffset(1)
        grBinsEffData.GetHistogram().GetYaxis().SetTitle("Data efficiency")
        grBinsEffData.GetHistogram().GetYaxis().SetRangeUser(effiMin, effiMax)

        ### to avoid loosing the TGraph keep it in memory by adding it to a list
        listOfTGraph1.append(grBinsEffData)
        listOfTGraph2.append(grBinsSF)
        listOfMC.append(grBinsEffMC)
        if 'eta' in yAxis or 'Eta' in yAxis:
            leg.AddEntry(
                grBinsEffData, '%1.3f #leq | #eta | #leq  %1.3f' %
                (float(key[0]), float(key[1])), "PL")
        elif 'pt' in yAxis or 'pT' in yAxis:
            leg.AddEntry(
                grBinsEffData, '%3.0f #leq p_{T} #leq  %3.0f GeV' %
                (float(key[0]), float(key[1])), "PL")
        elif 'vtx' in yAxis or 'Vtx' in yAxis or 'PV' in yAxis:
            leg.AddEntry(
                grBinsEffData,
                '%3.0f #leq nVtx #leq  %3.0f' % (float(key[0]), float(key[1])),
                "PL")

    for igr in range(len(listOfTGraph1) + 1):

        option = "P"
        if igr == 1:
            option = "AP"

        use_igr = igr
        if use_igr == len(listOfTGraph1):
            use_igr = 0

        listOfTGraph1[use_igr].SetLineColor(graphColors[use_igr])
        listOfTGraph1[use_igr].SetMarkerColor(graphColors[use_igr])
        if not listOfMC[use_igr] is None:
            listOfMC[use_igr].SetLineColor(graphColors[use_igr])

        listOfTGraph1[use_igr].GetHistogram().SetMinimum(effiMin)
        listOfTGraph1[use_igr].GetHistogram().SetMaximum(effiMax)
        p1.cd()
        listOfTGraph1[use_igr].Draw(option)
        if not listOfMC[use_igr] is None:
            listOfMC[use_igr].Draw("ez")

        p2.cd()
        listOfTGraph2[use_igr].SetLineColor(graphColors[use_igr])
        listOfTGraph2[use_igr].SetMarkerColor(graphColors[use_igr])
        listOfTGraph2[use_igr].GetHistogram().SetMinimum(sfMin)
        listOfTGraph2[use_igr].GetHistogram().SetMaximum(sfMax)
        if 'pT' in xAxis or 'pt' in xAxis:
            listOfTGraph2[use_igr].GetHistogram().GetXaxis().SetMoreLogLabels()
        listOfTGraph2[use_igr].GetHistogram().GetXaxis().SetNoExponent()
        listOfTGraph2[use_igr].Draw(option)

    lineAtOne = rt.TLine(xMin, 1, xMax, 1)
    lineAtOne.SetLineStyle(rt.kDashed)
    lineAtOne.SetLineWidth(2)

    p2.cd()
    lineAtOne.Draw()

    c.cd()
    p2.Draw()
    p1.Draw()

    leg.Draw()
    CMS_lumi.CMS_lumi(c, 4, 10)

    c.Print(nameout)
    listName = nameout.split('/')
    print "[[ INFO ]]nameout: " + nameout
    print listName
    print listName[-3].replace('tnp',
                               '') + '_SFvs' + xAxis + '_' + listName[-3]
    for iext in ["pdf", "C", "png"]:
        #c.SaveAs(nameout.replace('egammaEffi.txt_egammaPlots',listName[-6].replace('tnp','')+'_SFvs'+xAxis+'_'+listName[-3]).replace('pdf',iext))
        c.SaveAs(
            nameout.replace(
                'egammaEffi.txt_egammaPlots', listName[-3].replace('tnp', '') +
                '_SFvs' + xAxis + '_' + listName[-3]).replace('pdf',
                                                              iext))  #bing

    return listOfTGraph2
Beispiel #3
0
def EffiGraph1D(effDataList, sfList, etaPlot, nameout):

    W = 800
    H = 800
    yUp = 0.45
    canName = 'totoPt'
    if etaPlot:
        canName = 'totoEta'
    c = rt.TCanvas(canName, canName, 50, 50, H, W)
    c.SetTopMargin(0.055)
    c.SetBottomMargin(0.10)
    c.SetLeftMargin(0.12)

    p1 = rt.TPad(canName + '_up', canName + '_up', 0, yUp, 1, 1, 0, 0, 0)
    p2 = rt.TPad(canName + '_do', canName + '_do', 0, 0, 1, yUp, 0, 0, 0)
    p1.SetBottomMargin(0.0075)
    p1.SetTopMargin(c.GetTopMargin() * 1 / (1 - yUp))
    p2.SetTopMargin(0.0075)
    p2.SetBottomMargin(c.GetBottomMargin() * 1 / yUp)
    p1.SetLeftMargin(c.GetLeftMargin())
    p2.SetLeftMargin(c.GetLeftMargin())
    firstGraph = True
    leg = rt.TLegend(0.5, 0.80, 0.95, 0.92)
    leg.SetFillColor(0)
    leg.SetBorderSize(0)
    if not etaPlot:
        p1.SetLogx()
        p2.SetLogx()

    igr = 0
    listOfTGraph1 = []
    listOfTGraph2 = []
    xMin = 5
    xMax = 200
    if etaPlot:
        xMin = -2.60
        xMax = +2.60

    minmax = findMinMax(effDataList)
    effiMin = minmax[0]
    effiMax = minmax[1]

    for key in sorted(effDataList.keys()):
        grBinsEffData = effUtil.makeTGraphFromList(effDataList[key], 'min',
                                                   'max')
        grBinsSF = effUtil.makeTGraphFromList(sfList[key], 'min', 'max')

        if not etaPlot:
            print key
            grBinsEffData.Print()

        grBinsSF.SetMarkerColor(graphColors[igr])
        grBinsSF.SetLineColor(graphColors[igr])
        grBinsSF.SetLineWidth(2)
        grBinsEffData.SetMarkerColor(graphColors[igr])
        grBinsEffData.SetLineColor(graphColors[igr])
        grBinsEffData.SetLineWidth(2)

        grBinsEffData.GetHistogram().SetMinimum(effiMin)
        grBinsEffData.GetHistogram().SetMaximum(effiMax)

        if not etaPlot:
            ### for pT 1D plot, use the actual TGraph range
            xMin = grBinsEffData.GetHistogram().GetXaxis().GetXmin()
            xMax = grBinsEffData.GetHistogram().GetXaxis().GetXmax()

            #            if grBinsEffData.GetHistogram().GetXaxis().GetXmin() < xMin:
            #    xMin = grBinsEffData.GetHistogram().GetXaxis().GetXmin()
            #if grBinsEffData.GetHistogram().GetXaxis().GetXmax() > xMax:
            #    xMax = grBinsEffData.GetHistogram().GetXaxis().GetXmax()

        grBinsEffData.GetHistogram().GetXaxis().SetLimits(xMin, xMax)
        grBinsSF.GetHistogram().GetXaxis().SetLimits(xMin, xMax)
        grBinsSF.GetHistogram().SetMinimum(sfMin)
        grBinsSF.GetHistogram().SetMaximum(sfMax)

        grBinsSF.GetHistogram().GetXaxis().SetTitleOffset(1)
        if etaPlot:
            grBinsSF.GetHistogram().GetXaxis().SetTitle("SuperCluster #eta")
        else:
            grBinsSF.GetHistogram().GetXaxis().SetTitle("p_{T}  [GeV]")

        grBinsSF.GetHistogram().GetYaxis().SetTitle("Data / MC ")
        grBinsSF.GetHistogram().GetYaxis().SetTitleOffset(1)

        grBinsEffData.GetHistogram().GetYaxis().SetTitleOffset(1)
        grBinsEffData.GetHistogram().GetYaxis().SetTitle("Data efficiency")
        grBinsEffData.GetHistogram().GetYaxis().SetRangeUser(effiMin, effiMax)

        ### to avoid loosing the TGraph keep it in memory by adding it to a list
        listOfTGraph1.append(grBinsEffData)
        listOfTGraph2.append(grBinsSF)

        if etaPlot:
            leg.AddEntry(
                grBinsEffData, '%3.0f #leq p_{T} #leq  %3.0f GeV' %
                (float(key[0]), float(key[1])), "PL")
        else:
            leg.AddEntry(
                grBinsEffData, '%1.3f #leq | #eta | #leq  %1.3f' %
                (float(key[0]), float(key[1])), "PL")

    for igr in range(len(listOfTGraph1) + 1):

        option = "P"
        if igr == 1:
            option = "AP"

        use_igr = igr
        if use_igr == len(listOfTGraph1):
            use_igr = 0

        listOfTGraph1[use_igr].SetLineColor(graphColors[use_igr])
        listOfTGraph1[use_igr].SetMarkerColor(graphColors[use_igr])

        listOfTGraph1[use_igr].GetHistogram().SetMinimum(effiMin)
        listOfTGraph1[use_igr].GetHistogram().SetMaximum(effiMax)
        p1.cd()
        listOfTGraph1[use_igr].Draw(option)

        listOfTGraph2[use_igr].SetLineColor(graphColors[use_igr])
        listOfTGraph2[use_igr].SetMarkerColor(graphColors[use_igr])
        listOfTGraph2[use_igr].GetHistogram().SetMinimum(sfMin)
        listOfTGraph2[use_igr].GetHistogram().SetMaximum(sfMax)
        if not etaPlot:
            listOfTGraph2[use_igr].GetHistogram().GetXaxis().SetMoreLogLabels()
        listOfTGraph2[use_igr].GetHistogram().GetXaxis().SetNoExponent()
        p2.cd()
        listOfTGraph2[use_igr].Draw(option)

    lineAtOne = rt.TLine(xMin, 1, xMax, 1)
    lineAtOne.SetLineStyle(rt.kDashed)
    lineAtOne.SetLineWidth(2)

    p2.cd()
    lineAtOne.Draw()

    c.cd()
    p2.Draw()
    p1.Draw()

    leg.Draw()
    CMS_lumi.CMS_lumi(c, 4, 10)

    c.Print(nameout)