Example #1
0
def diagnosticErrorPlot(effgr, ierror, nameout):
    errorNames = efficiency.getSystematicNames()
    c2D_Err = rt.TCanvas('canScaleFactor_%s' % errorNames[ierror],
                         'canScaleFactor: %s' % errorNames[ierror], 1000, 600)
    c2D_Err.Divide(2, 1)
    c2D_Err.GetPad(1).SetLogy()
    c2D_Err.GetPad(2).SetLogy()
    c2D_Err.GetPad(1).SetRightMargin(0.15)
    c2D_Err.GetPad(1).SetLeftMargin(0.15)
    c2D_Err.GetPad(1).SetTopMargin(0.10)
    c2D_Err.GetPad(2).SetRightMargin(0.15)
    c2D_Err.GetPad(2).SetLeftMargin(0.15)
    c2D_Err.GetPad(2).SetTopMargin(0.10)

    h2_sfErrorAbs = effgr.ptEtaScaleFactor_2DHisto(ierror + 1, False)
    h2_sfErrorRel = effgr.ptEtaScaleFactor_2DHisto(ierror + 1, True)
    h2_sfErrorAbs.SetMinimum(0)
    h2_sfErrorAbs.SetMaximum(min(h2_sfErrorAbs.GetMaximum(), 0.2))
    h2_sfErrorRel.SetMinimum(0)
    h2_sfErrorRel.SetMaximum(1)
    h2_sfErrorAbs.SetTitle('e/#gamma absolute SF syst: %s ' %
                           errorNames[ierror])
    h2_sfErrorRel.SetTitle('e/#gamma relative SF syst: %s ' %
                           errorNames[ierror])
    c2D_Err.cd(1)
    h2_sfErrorAbs.DrawCopy("colz TEXT45")
    c2D_Err.cd(2)
    h2_sfErrorRel.DrawCopy("colz TEXT45")

    c2D_Err.Print(nameout)
def diagnosticErrorPlot( effgr, ierror, nameout ):
    errorNames = efficiency.getSystematicNames()
    c2D_Err = rt.TCanvas('canScaleFactor_%s' % errorNames[ierror] ,'canScaleFactor: %s' % errorNames[ierror],1000,600)    
    c2D_Err.Divide(2,1)
    c2D_Err.GetPad(1).SetLogy()
    c2D_Err.GetPad(2).SetLogy()
    c2D_Err.GetPad(1).SetRightMargin(0.15)
    c2D_Err.GetPad(1).SetLeftMargin( 0.15)
    c2D_Err.GetPad(1).SetTopMargin(  0.10)
    c2D_Err.GetPad(2).SetRightMargin(0.15)
    c2D_Err.GetPad(2).SetLeftMargin( 0.15)
    c2D_Err.GetPad(2).SetTopMargin(  0.10)

    h2_sfErrorAbs = effgr.ptEtaScaleFactor_2DHisto(ierror+1, False )
    h2_sfErrorRel = effgr.ptEtaScaleFactor_2DHisto(ierror+1, True  )
    h2_sfErrorAbs.SetMinimum(0)
    h2_sfErrorAbs.SetMaximum(min(h2_sfErrorAbs.GetMaximum(),0.2))
    h2_sfErrorRel.SetMinimum(0)
    h2_sfErrorRel.SetMaximum(1)
    h2_sfErrorAbs.SetTitle('e/#gamma absolute SF syst: %s ' % errorNames[ierror])
    h2_sfErrorRel.SetTitle('e/#gamma relative SF syst: %s ' % errorNames[ierror])
    c2D_Err.cd(1)
    h2_sfErrorAbs.DrawCopy("colz TEXT45")
    c2D_Err.cd(2)
    h2_sfErrorRel.DrawCopy("colz TEXT45")
    
    c2D_Err.Print(nameout)
def diagnosticErrorPlot(effgr, ierror, nameout):
    errorNames = efficiency.getSystematicNames()
    c2D_Err = rt.TCanvas('canScaleFactor_%s' % errorNames[ierror],
                         'canScaleFactor: %s' % errorNames[ierror], 1000, 600)
    c2D_Err.Divide(2, 1)
    c2D_Err.GetPad(1).SetLogy()
    c2D_Err.GetPad(2).SetLogy()
    c2D_Err.GetPad(1).SetRightMargin(0.15)
    c2D_Err.GetPad(1).SetLeftMargin(0.15)
    c2D_Err.GetPad(1).SetTopMargin(0.10)
    c2D_Err.GetPad(2).SetRightMargin(0.15)
    c2D_Err.GetPad(2).SetLeftMargin(0.15)
    c2D_Err.GetPad(2).SetTopMargin(0.10)

    h2_sfErrorAbs = effgr.ptEtaScaleFactor_2DHisto(ierror + 1, False)
    h2_sfErrorRel = effgr.ptEtaScaleFactor_2DHisto(ierror + 1, True)
    h2_sfErrorAbs.SetMinimum(0)
    h2_sfErrorAbs.SetMaximum(min(h2_sfErrorAbs.GetMaximum(), 0.2))
    h2_sfErrorRel.SetMinimum(0)
    h2_sfErrorRel.SetMaximum(1)
    h2_sfErrorAbs.SetTitle('e/#gamma absolute SF syst: %s ' %
                           errorNames[ierror])
    h2_sfErrorRel.SetTitle('e/#gamma relative SF syst: %s ' %
                           errorNames[ierror])
    c2D_Err.cd(1)
    h2_sfErrorAbs.DrawCopy("colz TEXT45")
    c2D_Err.cd(2)
    h2_sfErrorRel.DrawCopy("colz TEXT45")

    c2D_Err.Print(nameout)

    listName = nameout.split('/')
    for iext in ["pdf", "C", "png"]:
        #c2D_Err.SaveAs(nameout.replace('egammaEffi.txt_egammaPlots',listName[-6].replace('tnp','')+'_SF2D'+'_'+errorNames[ierror]+listName[-3]).replace('pdf',iext))
        c2D_Err.SaveAs(
            nameout.replace(
                'egammaEffi.txt_egammaPlots',
                listName[-3].replace('tnp', '') + '_SF2D' + '_' +
                errorNames[ierror] + listName[-3]).replace('pdf', iext))  #bing

    return h2_sfErrorAbs
def doEGM_SFs(filein, lumi, axis=['pT', 'eta']):
    print " Opening file: %s (plot lumi: %3.1f)" % (filein, lumi)
    CMS_lumi.lumi_13TeV = "%+3.1f fb^{-1}" % lumi

    nameOutBase = filein
    if not os.path.exists(filein):
        print 'file %s does not exist' % filein
        sys.exit(1)

    fileWithEff = open(filein, 'r')
    effGraph = efficiencyList()

    for line in fileWithEff:
        modifiedLine = line.lstrip(' ').rstrip(' ').rstrip('\n')
        numbers = modifiedLine.split('\t')

        if len(numbers) > 0 and isFloat(numbers[0]):
            etaKey = (float(numbers[0]), float(numbers[1]))
            ptKey = (float(numbers[2]), min(500, float(numbers[3])))

            myeff = efficiency(ptKey, etaKey, float(numbers[4]),
                               float(numbers[5]), float(numbers[6]),
                               float(numbers[7]), float(numbers[8]),
                               float(numbers[9]), float(numbers[10]),
                               float(numbers[11]))
            #                           float(numbers[8]),float(numbers[9]),float(numbers[10]), -1 )

            effGraph.addEfficiency(myeff)

    fileWithEff.close()

    ### massage the numbers a bit
    effGraph.symmetrizeSystVsEta()
    effGraph.combineSyst()

    print " ------------------------------- "

    customEtaBining = []
    customEtaBining.append((0.000, 0.800))
    customEtaBining.append((0.800, 1.444))
    #    customEtaBining.append( (1.444,1.566))
    customEtaBining.append((1.566, 2.000))
    customEtaBining.append((2.000, 2.500))

    pdfout = nameOutBase + '_egammaPlots.pdf'
    cDummy = rt.TCanvas()
    cDummy.Print(pdfout + "[")

    EffiGraph1D(  #effGraph.pt_1DGraph_list_customEtaBining(customEtaBining, False, isData=True) , #eff Data
        #None,
        effGraph.pt_1DGraph_list_customEtaBining(
            customEtaBining, False, isData=True),  #eff Data   ###bing
        effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,
                                                 False,
                                                 isData=False),  #bing
        effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,
                                                 True,
                                                 isData=True),  #SF
        pdfout,
        xAxis=axis[0],
        yAxis=axis[1])
    #EffiGraph1D( effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,False) ,
    #             effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,True)   , False, pdfout )
    #    EffiGraph1D( effGraph.eta_1DGraph_list(False), effGraph.eta_1DGraph_list(True), True , pdfout )
    listOfSF1D = EffiGraph1D(
        effGraph.eta_1DGraph_list(typeGR=0),  # eff Data
        effGraph.eta_1DGraph_list(typeGR=-1),  # eff MC
        effGraph.eta_1DGraph_list(typeGR=+1),  # SF
        pdfout,
        xAxis=axis[1],
        yAxis=axis[0])

    h2EffData = effGraph.ptEtaScaleFactor_2DHisto(-3)
    h2EffMC = effGraph.ptEtaScaleFactor_2DHisto(-2)
    h2SF = effGraph.ptEtaScaleFactor_2DHisto(-1)
    h2Error = effGraph.ptEtaScaleFactor_2DHisto(0)  ## only error bars

    rt.gStyle.SetPalette(1)
    rt.gStyle.SetPaintTextFormat('1.3f')
    rt.gStyle.SetOptTitle(1)

    c2D = rt.TCanvas('canScaleFactor', 'canScaleFactor', 900, 600)
    c2D.Divide(2, 1)
    c2D.GetPad(1).SetRightMargin(0.15)
    c2D.GetPad(1).SetLeftMargin(0.15)
    c2D.GetPad(1).SetTopMargin(0.10)
    c2D.GetPad(2).SetRightMargin(0.15)
    c2D.GetPad(2).SetLeftMargin(0.15)
    c2D.GetPad(2).SetTopMargin(0.10)
    c2D.GetPad(1).SetLogy()
    c2D.GetPad(2).SetLogy()

    c2D.cd(1)
    dmin = 1.0 - h2SF.GetMinimum()
    dmax = h2SF.GetMaximum() - 1.0
    dall = max(dmin, dmax)
    h2SF.SetMinimum(1 - dall)
    h2SF.SetMaximum(1 + dall)
    h2SF.DrawCopy("colz TEXT45")

    c2D.cd(2)
    h2Error.SetMinimum(0)
    h2Error.SetMaximum(min(h2Error.GetMaximum(), 0.2))
    h2Error.DrawCopy("colz TEXT45")

    c2D.Print(pdfout)
    listName = pdfout.split('/')
    for iext in ["pdf", "C", "png"]:
        #c2D.SaveAs(pdfout.replace('egammaEffi.txt_egammaPlots',listName[-6].replace('tnp','')+'_SF2D'+'_'+listName[-3]).replace('pdf',iext))
        c2D.SaveAs(
            pdfout.replace(
                'egammaEffi.txt_egammaPlots', listName[-3].replace('tnp', '') +
                '_SF2D' + '_' + listName[-3]).replace('pdf', iext))  #bing

    rootout = rt.TFile(nameOutBase + '_EGM2D.root', 'recreate')
    rootout.cd()
    h2SF.Write('EGamma_SF2D', rt.TObject.kOverwrite)
    h2EffData.Write('EGamma_EffData2D', rt.TObject.kOverwrite)
    h2EffMC.Write('EGamma_EffMC2D', rt.TObject.kOverwrite)
    for igr in range(len(listOfSF1D)):
        listOfSF1D[igr].Write('grSF1D_%d' % igr, rt.TObject.kOverwrite)

    errorNames = efficiency.getSystematicNames()
    for isyst in range(len(errorNames)):
        h2_isyst = diagnosticErrorPlot(effGraph, isyst, pdfout)
        h2_isyst.Write(errorNames[isyst], rt.TObject.kOverwrite)
    cDummy.Print(pdfout + "]")
    rootout.Close()
def doEGM_SFs(filein, lumi):
    print " Opening file: %s (plot lumi: %3.1f)" % ( filein, lumi )
    CMS_lumi.lumi_13TeV = "%+3.1f fb^{-1}" % lumi 

    nameOutBase = filein 
    if not os.path.exists( filein ) :
        print 'file %s does not exist' % filein
        sys.exit(1)


    fileWithEff = open(filein, 'r')
    effGraph = efficiencyList()
    
    for line in fileWithEff :
        modifiedLine = line.lstrip(' ').rstrip(' ').rstrip('\n')
        numbers = modifiedLine.split('\t')

        if len(numbers) > 0 and isFloat(numbers[0]):
            etaKey = ( float(numbers[0]), float(numbers[1]) )
            ptKey  = ( float(numbers[2]), min(200,float(numbers[3])) )
        
            myeff = efficiency(ptKey,etaKey,
                               float(numbers[4]),float(numbers[5]),float(numbers[6] ),float(numbers[7] ),
                               float(numbers[8]),float(numbers[9]),float(numbers[10]),float(numbers[11]) )
#                           float(numbers[8]),float(numbers[9]),float(numbers[10]), -1 )

            effGraph.addEfficiency(myeff)

    fileWithEff.close()

### massage the numbers a bit
    effGraph.symmetrizeSystVsEta()
    effGraph.combineSyst()

    print " ------------------------------- "

    customEtaBining = []
    customEtaBining.append( (0.000,0.800))
    customEtaBining.append( (0.800,1.444))
    customEtaBining.append( (1.444,1.566))
    customEtaBining.append( (1.566,2.000))
    customEtaBining.append( (2.000,2.500))


    pdfout = nameOutBase + '_egammaPlots.pdf'
    cDummy = rt.TCanvas()
    cDummy.Print( pdfout + "[" )


    EffiGraph1D( effGraph.pt_1DGraph_list(False) , None, effGraph.pt_1DGraph_list(True) , False, pdfout )
#EffiGraph1D( effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,False) , 
#             effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,True)   , False, pdfout )
#    EffiGraph1D( effGraph.eta_1DGraph_list(False), effGraph.eta_1DGraph_list(True), True , pdfout )
    EffiGraph1D( effGraph.eta_1DGraph_list( typeGR =  0 ) , # Data
                 effGraph.eta_1DGraph_list( typeGR = -1 ) , # MC
                 effGraph.eta_1DGraph_list( typeGR = +1 ) , # SF
                 True , pdfout )
#cDummy.Print( pdfout + "]" )

    h2EffData = effGraph.ptEtaScaleFactor_2DHisto(-3)
    h2EffMC   = effGraph.ptEtaScaleFactor_2DHisto(-2)
    h2SF      = effGraph.ptEtaScaleFactor_2DHisto(-1)
    h2Error   = effGraph.ptEtaScaleFactor_2DHisto( 0)  ## only error bars

    rt.gStyle.SetPalette(1)
    rt.gStyle.SetPaintTextFormat('1.3f');
    rt.gStyle.SetOptTitle(1)

    c2D = rt.TCanvas('canScaleFactor','canScaleFactor',900,600)
    c2D.Divide(2,1)
    c2D.GetPad(1).SetRightMargin(0.15)
    c2D.GetPad(1).SetLeftMargin( 0.15)
    c2D.GetPad(1).SetTopMargin(  0.10)
    c2D.GetPad(2).SetRightMargin(0.15)
    c2D.GetPad(2).SetLeftMargin( 0.15)
    c2D.GetPad(2).SetTopMargin(  0.10)
    c2D.GetPad(1).SetLogy()
    c2D.GetPad(2).SetLogy()
    

    c2D.cd(1)
    dmin = 1.0 - h2SF.GetMinimum()
    dmax = h2SF.GetMaximum() - 1.0
    dall = max(dmin,dmax)
    h2SF.SetMinimum(1-dall)
    h2SF.SetMaximum(1+dall)
    h2SF.DrawCopy("colz TEXT45")
    
    c2D.cd(2)
    h2Error.SetMinimum(0)
    h2Error.SetMaximum(min(h2Error.GetMaximum(),0.2))    
    h2Error.DrawCopy("colz TEXT45")

    c2D.Print( pdfout )


    rootout = rt.TFile(nameOutBase + '_EGM2D.root','recreate')
    rootout.cd()
    h2SF.Write('EGamma_SF2D',rt.TObject.kOverwrite)
    h2EffData.Write('EGamma_EffData2D',rt.TObject.kOverwrite)
    h2EffMC  .Write('EGamma_EffMC2D'  ,rt.TObject.kOverwrite)
    rootout.Close()

    for isyst in range(len(efficiency.getSystematicNames())):
        diagnosticErrorPlot( effGraph, isyst, pdfout )

    cDummy.Print( pdfout + "]" )
Example #6
0
def doEGM_SFs(filein, lumi):
    print " Opening file: %s (plot lumi: %3.1f)" % ( filein, lumi )
    CMS_lumi.lumi_13TeV = "%+3.1f fb^{-1}" % lumi 

    nameOutBase = filein 
    if not os.path.exists( filein ) :
        print 'file %s does not exist' % filein
        sys.exit(1)


    fileWithEff = open(filein, 'r')
    effGraph = efficiencyList()
    
    for line in fileWithEff :
        modifiedLine = line.lstrip(' ').rstrip(' ').rstrip('\n')
        numbers = modifiedLine.split('\t')

        if len(numbers) > 0 and isFloat(numbers[0]):
            etaKey = ( float(numbers[0]), float(numbers[1]) )
            ptKey  = ( float(numbers[2]), min(200,float(numbers[3])) )
        
            myeff = efficiency(ptKey,etaKey,
                               float(numbers[4]),float(numbers[5]),float(numbers[6] ),float(numbers[7] ),
                               float(numbers[8]),float(numbers[9]),float(numbers[10]),float(numbers[11]) )
#                           float(numbers[8]),float(numbers[9]),float(numbers[10]), -1 )

            effGraph.addEfficiency(myeff)

    fileWithEff.close()

### massage the numbers a bit
    effGraph.symmetrizeSystVsEta()
    effGraph.combineSyst()

    print " ------------------------------- "

    customEtaBining = []
    customEtaBining.append( (0.000,0.800))
    customEtaBining.append( (0.800,1.444))
    customEtaBining.append( (1.444,1.566))
    customEtaBining.append( (1.566,2.000))
    customEtaBining.append( (2.000,2.500))


    pdfout = nameOutBase + '_egammaPlots.pdf'
    cDummy = rt.TCanvas()
    cDummy.Print( pdfout + "[" )


    EffiGraph1D( effGraph.pt_1DGraph_list(False) , effGraph.pt_1DGraph_list(True) , False, pdfout )
#EffiGraph1D( effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,False) , 
#             effGraph.pt_1DGraph_list_customEtaBining(customEtaBining,True)   , False, pdfout )
    EffiGraph1D( effGraph.eta_1DGraph_list(False), effGraph.eta_1DGraph_list(True), True , pdfout )

#cDummy.Print( pdfout + "]" )

    h2SF    = effGraph.ptEtaScaleFactor_2DHisto(-1)
    h2Error = effGraph.ptEtaScaleFactor_2DHisto( 0)  ## only error bars

    rt.gStyle.SetPalette(1)
    rt.gStyle.SetPaintTextFormat('1.3f');
    rt.gStyle.SetOptTitle(1)

    c2D = rt.TCanvas('canScaleFactor','canScaleFactor',900,600)
    c2D.Divide(2,1)
    c2D.GetPad(1).SetRightMargin(0.15)
    c2D.GetPad(1).SetLeftMargin( 0.15)
    c2D.GetPad(1).SetTopMargin(  0.10)
    c2D.GetPad(2).SetRightMargin(0.15)
    c2D.GetPad(2).SetLeftMargin( 0.15)
    c2D.GetPad(2).SetTopMargin(  0.10)
    c2D.GetPad(1).SetLogy()
    c2D.GetPad(2).SetLogy()
    

    c2D.cd(1)
    dmin = 1.0 - h2SF.GetMinimum()
    dmax = h2SF.GetMaximum() - 1.0
    dall = max(dmin,dmax)
    h2SF.SetMinimum(1-dall)
    h2SF.SetMaximum(1+dall)
    h2SF.DrawCopy("colz TEXT45")
    
    c2D.cd(2)
    h2Error.SetMinimum(0)
    h2Error.SetMaximum(min(h2Error.GetMaximum(),0.2))    
    h2Error.DrawCopy("colz TEXT45")

    c2D.Print( pdfout )


    rootout = rt.TFile(nameOutBase + '_SF2D.root','recreate')
    rootout.cd()
    h2SF.Write('EGamma_SF2D',rt.TObject.kOverwrite)
    rootout.Close()

    for isyst in range(len(efficiency.getSystematicNames())):
        diagnosticErrorPlot( effGraph, isyst, pdfout )

    cDummy.Print( pdfout + "]" )