def doPlot(datasetsEmb, analyses, path, name, text):
    histos = []
    legends = {"Plus": "#tau-jet energy scale variated by +3 %",
               "Minus": "#tau-jet energy scale variated by -3 %"}

    for aname, analysis in analyses:
        (rootHisto, tmp) = datasetsEmb.getHistogram("Data", analysis+"/"+path)
        h = histograms.Histo(rootHisto, aname)
        h.setLegendLabel(legends.get(aname, aname))
        h.setDrawStyle("EP")
        h.setLegendStyle("p")
        histos.append(h)

    p = plots.ComparisonManyPlot(histos[0], histos[1:])
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))

    styles.dataStyle(p.histoMgr.getHisto("Baseline"))
    styles.mcStyle(p.histoMgr.getHisto("Plus"))
    styles.mcStyle2(p.histoMgr.getHisto("Minus"))
    p.histoMgr.getHisto("Minus").getRootHisto().SetMarkerSize(2)
    p.setLuminosity(datasetsEmb.getLuminosity())
    p.createFrame(name, createRatio=True, opts2={"ymax": 2}, opts={"ymax": 35})
    yaxis = p.getFrame2().GetYaxis()
    yaxis.SetTitle("Ratio")
    #yaxis.SetTitleSize(yaxis.GetTitleSize()*0.8)
    p.setLegend(histograms.moveLegend(histograms.createLegend()))

    p.appendPlotObject(histograms.PlotText(0.5, 0.55, text, size=20))
    
    p.frame.GetXaxis().SetTitle("m_{T}(#tau jet, E_{T}^{miss}) (GeV/c^{2})")
    p.frame.GetYaxis().SetTitle("Events / 20 GeV/c^{2}")
    p.draw()
    p.addStandardTexts()
    p.save()
def doPlot(datasets, analyses, path, name, rootFile=None, rootHistoName=None):
    histos = []
    legends = {
        "Plus": "#tau-jet energy scale variated by +3 %",
        "Minus": "#tau-jet energy scale variated by -3 %"
    }

    for aname, analysis in analyses:
        p = None
        if isinstance(path, basestring):
            p = plots.DataMCPlot(datasets, analysis + "/" + path)
        else:
            p = plots.DataMCPlot(datasets, path.clone(tree=analysis + "/tree"))

        if normalize:
            tauEmbedding.scaleNormalization(p)

        h = p.histoMgr.getHisto("Data")
        h.setName(aname)
        h.setLegendLabel(legends.get(aname, aname))
        histos.append(h)

    p = plots.ComparisonManyPlot(histos[0], histos[1:])
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
    if rootFile:
        baseline = histos[0].getRootHisto().Clone("EWKtau_" + rootHistoName)
        baseline.SetDirectory(rootFile)
        baseline.Write()

        plus = histos[1].getRootHisto().Clone("EWKtau_JESUp_" + rootHistoName)
        plus.SetDirectory(rootFile)
        plus.Write()

        minus = histos[2].getRootHisto().Clone("EWKtau_JESDown_" +
                                               rootHistoName)
        minus.SetDirectory(rootFile)
        minus.Write()

    styles.mcStyle(p.histoMgr.getHisto("Plus"))
    styles.mcStyle2(p.histoMgr.getHisto("Minus"))
    p.histoMgr.getHisto("Minus").getRootHisto().SetMarkerSize(2)
    p.setLuminosity(datasets.getDataset("Data").getLuminosity())
    p.createFrame(name, createRatio=True, opts2={"ymax": 2}, opts={"ymax": 40})
    yaxis = p.getFrame2().GetYaxis()
    yaxis.SetTitle("Ratio")
    #yaxis.SetTitleSize(yaxis.GetTitleSize()*0.8)
    p.setLegend(histograms.moveLegend(histograms.createLegend()))

    p.frame.GetXaxis().SetTitle("m_{T}(#tau jet, E_{T}^{miss}) (GeV/c^{2})")
    p.frame.GetYaxis().SetTitle("Events / 20 GeV/c^{2}")
    p.draw()
    p.addStandardTexts()
    p.save()
def doPlot(datasets, analyses, path, name, rootFile=None, rootHistoName=None):
    histos = []
    legends = {"Plus": "#tau-jet energy scale variated by +3 %",
               "Minus": "#tau-jet energy scale variated by -3 %"}

    for aname, analysis in analyses:
        p = None
        if isinstance(path, basestring):
            p = plots.DataMCPlot(datasets, analysis+"/"+path)
        else:
            p = plots.DataMCPlot(datasets, path.clone(tree=analysis+"/tree"))

        if normalize:
            tauEmbedding.scaleNormalization(p)
        
        h = p.histoMgr.getHisto("Data")
        h.setName(aname)
        h.setLegendLabel(legends.get(aname, aname))
        histos.append(h)

    p = plots.ComparisonManyPlot(histos[0], histos[1:])
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))
    if rootFile:
        baseline = histos[0].getRootHisto().Clone("EWKtau_"+rootHistoName)
        baseline.SetDirectory(rootFile)
        baseline.Write()

        plus = histos[1].getRootHisto().Clone("EWKtau_JESUp_"+rootHistoName)
        plus.SetDirectory(rootFile)
        plus.Write()

        minus = histos[2].getRootHisto().Clone("EWKtau_JESDown_"+rootHistoName)
        minus.SetDirectory(rootFile)
        minus.Write()

    styles.mcStyle(p.histoMgr.getHisto("Plus"))
    styles.mcStyle2(p.histoMgr.getHisto("Minus"))
    p.histoMgr.getHisto("Minus").getRootHisto().SetMarkerSize(2)
    p.setLuminosity(datasets.getDataset("Data").getLuminosity())
    p.createFrame(name, createRatio=True, opts2={"ymax": 2}, opts={"ymax": 40})
    yaxis = p.getFrame2().GetYaxis()
    yaxis.SetTitle("Ratio")
    #yaxis.SetTitleSize(yaxis.GetTitleSize()*0.8)
    p.setLegend(histograms.moveLegend(histograms.createLegend()))
    
    p.frame.GetXaxis().SetTitle("m_{T}(#tau jet, E_{T}^{miss}) (GeV/c^{2})")
    p.frame.GetYaxis().SetTitle("Events / 20 GeV/c^{2}")
    p.draw()
    histograms.addCmsPreliminaryText()
    histograms.addEnergyText()
    p.addLuminosityText()
    p.save()
def doPlot(datasetsEmb, analyses, path, name, text):
    histos = []
    legends = {
        "Plus": "#tau-jet energy scale variated by +3 %",
        "Minus": "#tau-jet energy scale variated by -3 %"
    }

    for aname, analysis in analyses:
        (rootHisto, tmp) = datasetsEmb.getHistogram("Data",
                                                    analysis + "/" + path)
        h = histograms.Histo(rootHisto, aname)
        h.setLegendLabel(legends.get(aname, aname))
        h.setDrawStyle("EP")
        h.setLegendStyle("p")
        histos.append(h)

    p = plots.ComparisonManyPlot(histos[0], histos[1:])
    p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20))

    styles.dataStyle(p.histoMgr.getHisto("Baseline"))
    styles.mcStyle(p.histoMgr.getHisto("Plus"))
    styles.mcStyle2(p.histoMgr.getHisto("Minus"))
    p.histoMgr.getHisto("Minus").getRootHisto().SetMarkerSize(2)
    p.setLuminosity(datasetsEmb.getLuminosity())
    p.createFrame(name, createRatio=True, opts2={"ymax": 2}, opts={"ymax": 35})
    yaxis = p.getFrame2().GetYaxis()
    yaxis.SetTitle("Ratio")
    #yaxis.SetTitleSize(yaxis.GetTitleSize()*0.8)
    p.setLegend(histograms.moveLegend(histograms.createLegend()))

    p.appendPlotObject(histograms.PlotText(0.5, 0.55, text, size=20))

    p.frame.GetXaxis().SetTitle("m_{T}(#tau jet, E_{T}^{miss}) (GeV/c^{2})")
    p.frame.GetYaxis().SetTitle("Events / 20 GeV/c^{2}")
    p.draw()
    histograms.addCmsPreliminaryText()
    histograms.addEnergyText()
    p.addLuminosityText()
    p.save()
def doPlot(datasetsEmb, analyses, path, name, text):
    histos = []
    legends = {"Plus": taujetH+" energy scale varied by +3 %",
               "Minus": taujetH+" energy scale varied by -3 %"}

    for aname, analysis in analyses:
        (rootHisto, tmp) = datasetsEmb.getHistogram("Data", analysis+"/"+path)
        h = histograms.Histo(rootHisto, aname)
        h.setLegendLabel(legends.get(aname, aname))
        h.setDrawStyle("EP")
        h.setLegendStyle("p")
        histos.append(h)

    p = plots.ComparisonManyPlot(histos[0], histos[1:])

    styles.dataStyle(p.histoMgr.getHisto("Nominal"))
    styles.mcStyle(p.histoMgr.getHisto("Plus"))
    styles.mcStyle2(p.histoMgr.getHisto("Minus"))
    p.histoMgr.getHisto("Minus").getRootHisto().SetMarkerSize(2)
    p.setLuminosity(datasetsEmb.getLuminosity())
    p.appendPlotObject(histograms.PlotText(0.45, 0.55, text, size=20))

    plots.drawPlot(p, name, "m_{T}(^{}%s, ^{}E_{T}^{miss}) (GeV/^{}c^{2})"%taujet, ylabel="Events / %d GeV/^{}c^{2}",
                   rebin=20, ratio=True, opts={"ymax": 35, "xmax": 300}, opts2={"ymax": 2}, addLuminosityText=True)
Beispiel #6
0
def doQCDfactorisedResultPlots(opts, dsetMgr, moduleInfoString, myDir, luminosity):
    # Set here the names of the histograms you want to access
    myBasicName = "QCDfactorised/MtAfterStandardSelections"
    myLeg1Name = "QCDfactorised/MtAfterLeg1"
    myLeg2Name = "QCDfactorised/MtAfterLeg2"

    # Obtain QCD shapes
    myBasicShape = DataDrivenQCDShape(dsetMgr, "Data", "EWK", myBasicName, luminosity)
    myLeg1Shape = DataDrivenQCDShape(dsetMgr, "Data", "EWK", myLeg1Name, luminosity)
    myLeg2Shape = DataDrivenQCDShape(dsetMgr, "Data", "EWK", myLeg2Name, luminosity)

    # Calculate final shape in signal region (leg1 * leg2 / basic)
    myResult = QCDFactorisedResult(myBasicShape, myLeg1Shape, myLeg2Shape, myHistoSpecs, moduleInfoString)
    hTotalQCD = myResult.getResultShape().Clone()

    # Do plotting - this needs to be edited to use tdr style ...
    c1 = ROOT.TCanvas()
    c1.Draw()
    hTotalQCD.Draw()
    c1.Print("%s/QCDShape_total_%s.png"%(myDir, moduleInfoString))
    for i in range(0,len(myResult.getNQCDHistograms())):
        c = ROOT.TCanvas()
        c.Draw()
        myResult.getNQCDHistograms()[i].Draw()
        myBinTitle = myBasicShape.getPhaseSpaceBinFileFriendlyTitle(i)
        c.Print("%s/QCDShape_%s_%s.png"%(myDir, myBinTitle, moduleInfoString))

    # Do systematics coming from met shape difference
    # Set here the names of the histograms you want to access
    myCtrlRegionName = "QCDfactorised/MtAfterStandardSelections"
    mySignalRegionName = "QCDfactorised/MtAfterLeg2"
    # Obtain QCD shapes
    myCtrlRegion = DataDrivenQCDShape(dsetMgr, "Data", "EWK", myCtrlRegionName, luminosity)
    mySignalRegion = DataDrivenQCDShape(dsetMgr, "Data", "EWK", mySignalRegionName, luminosity)
    # Calculate
    mySyst = SystematicsForMetShapeDifference(mySignalRegion, myCtrlRegion, myResult.getResultShape(), myHistoSpecs, moduleInfoString)
    print "Evaluated MET shape systematics"
    # Do plotting
    #mySyst
    hNominal = myResult.getResultShape().Clone()
    hUp = mySyst.getUpHistogram().Clone()
    hDown = mySyst.getDownHistogram().Clone()
    hNominal.SetLineColor(ROOT.kBlack)
    hUp.SetLineColor(ROOT.kBlue)
    hDown.SetLineColor(ROOT.kRed)
    hNominal.Draw()
    myYmax = 15
    if "2012" in moduleInfoString:
        myYmax = 70
    plot = plots.ComparisonManyPlot(histograms.Histo(hNominal, "Nominal"),
        [histograms.Histo(hUp, "Up"), histograms.Histo(hDown, "Down")])
    plot.createFrame("%s/QCDShapeWithMetSyst_%s_%s"%(myDir, myBinTitle, moduleInfoString), createRatio=True, opts2={"ymin": -2.5, "ymax": 2.5}, opts={"addMCUncertainty": True, "ymin": -5, "ymax": myYmax, "xmin": 0, "xmax": 500})
    plot.frame.GetXaxis().SetTitle("Transverse mass, GeV/c^{2}")
    plot.frame.GetYaxis().SetTitle("N_{events}")
    plot.setLegend(histograms.createLegend(0.59, 0.70, 0.87, 0.90))
    plot.legend.SetFillColor(0)
    plot.legend.SetFillStyle(1001)
    styles.mcStyle(plot.histoMgr.getHisto("Up"))
    plot.histoMgr.getHisto("Up").getRootHisto().SetMarkerSize(0)
    styles.mcStyle2(plot.histoMgr.getHisto("Down"))
    #hRatioDown = hDown.Clone()
    #hRatioUp = hUp.Clone()
    #hRatioDown.Divide(hNominal)
    #hRatioUp.Divide(hNominal)
    #plot.setRatios([hRatioUp,hRatioDown])
    plot.setLuminosity(luminosity)
    if "2012" in moduleInfoString:
        plot.setEnergy("8")
    else:
        plot.setEnergy("7")
    plot.addStandardTexts()
    #plot.setDrawOptions({addMCUncertainty: True})
    plot.draw()
    plot.save()

    if False:
        c2 = ROOT.TCanvas()
        c2.Draw()
        hNominal = myResult.getResultShape().Clone()
        hUp = mySyst.getUpHistogram().Clone()
        hDown = mySyst.getDownHistogram().Clone()
        hNominal.SetLineColor(ROOT.kBlack)
        hUp.SetLineColor(ROOT.kBlue)
        hDown.SetLineColor(ROOT.kRed)
        hNominal.Draw()
        hUp.Draw("same")
        hDown.Draw("same")
        c2.Print("%s/QCDShapeWithMetSyst_%s_%s.png"%(myDir, myBinTitle, moduleInfoString))

    print HighlightStyle()+"doQCDfactorisedResultPlots is ready"+NormalStyle()