Пример #1
0
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 createPlot(name):
        drhAve = dsetAve.getDatasetRootHisto(name)
        drhAve.setName("Average")
        if drhAve.isMC():
            drhAve.normalizeToLuminosity(lumi)
        drhSeeds = []
        for i, d in enumerate(dsetSeeds):
            drh = d.getDatasetRootHisto(name)
            drh.setName("Seed %d" % i)
            if drh.isMC():
                drh.normalizeToLuminosity(lumi)
            drhSeeds.append(drh)

        if name == "shapeTransverseMass":
            tha = drhAve.getHistogram()
            for i, di in enumerate(drhSeeds):
                thi = di.getHistogram()
                chi2 = tha.Chi2Test(thi, "WW")
                kolmo = tha.KolmogorovTest(thi)
                compatTestsAve.append(("a+%d" % i, chi2, kolmo))

                for j in xrange(i + 1, len(drhSeeds)):
                    thj = drhSeeds[j].getHistogram()
                    chi2 = thi.Chi2Test(thj, "WW")
                    kolmo = thi.KolmogorovTest(thj)
                    compatTests.append(("%d+%d" % (i, j), chi2, kolmo))

        p = plots.ComparisonManyPlot(drhAve, drhSeeds)
        p.setLuminosity(lumi)
        legLabel = plots._legendLabels.get(datasetName, datasetName)
        leg = "Average " + legLabel
        if addEventCounts:
            leg += " (" + tauEmbedding.strIntegral(drhAve.getHistogram()) + ")"
        p.histoMgr.setHistoLegendLabelMany({"Average": leg})
        for i, drh in enumerate(drhSeeds):
            leg = ("Seed %d " % i) + legLabel
            if addEventCounts:
                leg += " (" + tauEmbedding.strIntegral(
                    drh.getHistogram()) + ")"
            p.histoMgr.setHistoLegendLabelMany({"Seed %d" % i: leg})
        p.histoMgr.forEachHisto(styles.Generator(styles=myStyles))

        p.setDrawOptions(ratioYlabel="Seed/Average")
        return p
Пример #3
0
    def compare(step):
        path = "CommonPlots/AtEveryStep/%s/MET_Calo" % step
        drhNormal = dsetNormal.getDatasetRootHisto(path)
        drhEmb = dsetEmb.getDatasetRootHisto(path)

        drhNormal.setName("Normal ttbar")
        drhEmb.setName("Embedded ttbar")

        p = plots.ComparisonManyPlot(drhNormal, [drhEmb])
        p.histoMgr.normalizeMCToLuminosity(lumi)

        p.histoMgr.forHisto("Normal ttbar", lambda h: doStyle(h, ROOT.kBlack))
        p.histoMgr.forHisto("Embedded ttbar", lambda h: doStyle(h, ROOT.kRed))
        p.histoMgr.forHisto(
            "Embedded ttbar",
            lambda h: tauEmbedding.scaleTauBRNormalization(h.getRootHisto()))

        p.prependPlotObjectToRatio(doLineStyle(ROOT.TLine(0, 1.1, 500, 1.1)))
        p.prependPlotObjectToRatio(doLineStyle(ROOT.TLine(0, 0.9, 500, 0.9)))

        global ind
        ind += 1
        bins = range(0, 200, 20) + [200, 250, 300, 500]
        plots.drawPlot(
            p,
            "calometComparison/%02d_calomet_%s" % (ind, step),
            xlabel="Calo MET (GeV)",
            ylabel="Events / #DeltaMET / %.0f-%.0f GeV",
            #rebinToWidthX=20,
            rebin=bins,
            divideByBinWidth=True,
            ratio=True,
            ratioYlabel="Emb./Norm.",
            ratioType="errorScale",
            ratioCreteLegend=True,
            opts2={
                "ymin": 0.5,
                "ymax": 1.5
            },
            addLuminosityText=True,
            moveLegend={"dx": -0.2})
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 createPlot(name):
        name2Emb = name

        if isinstance(name, basestring):
            name2Emb = analysisEmb + "/" + name
        else:
            name2Emb = name.clone(tree=analysisEmb + "/tree")

        (embData, embDataVar) = datasetsEmb.getHistogram("Data", name2Emb)
        embHistos = datasetsEmb.getHistograms("Data", name2Emb)

        p = plots.ComparisonManyPlot(embData, embHistos)
        p.setLuminosity(datasetsEmb.getLuminosity())

        p.histoMgr.forEachHisto(
            styles.Generator([styles.dataStyle] + styles.styles))
        #p.histoMgr.setHistoDrawStyleAll("P")
        #p.histoMgr.setHistoLegendStyleAll("P")
        p.histoMgr.setHistoDrawStyle("Average", "PE")
        p.histoMgr.setHistoLegendStyle("Average", "P")

        return p
    def createPlot(name):
        drhSeeds = []
        for i, d in enumerate(dsetSeeds):
            drh = d.getDatasetRootHisto(name)
            drh.setName("Seed %d" % i)
            if drh.isMC():
                drh.normalizeToLuminosity(lumi)
            drhSeeds.append(drh)

        p = plots.ComparisonManyPlot(drhSeeds[0], drhSeeds[1:])
        p.setLuminosity(lumi)
        legLabel = plots._legendLabels.get(datasetName, datasetName)
        for i, drh in enumerate(drhSeeds):
            leg = labels[i] + " " + legLabel
            if addEventCounts:
                leg += " (" + tauEmbedding.strIntegral(
                    drh.getHistogram()) + ")"
            p.histoMgr.setHistoLegendLabelMany({"Seed %d" % i: leg})
        p.histoMgr.forEachHisto(styles.Generator(styles=myStyles))

        p.setDrawOptions(ratioYlabel="Others/" + labels[0])
        return p
Пример #7
0
    def Save(self, name):

        hObserved = self.CreateGraph("Observed")
        hExpected = self.CreateGraph("Expected")
        hExpected1s = self.CreateGraph("Expected1")
        hExpected1s.SetFillColor(ROOT.kYellow)
        hExpected2s = self.CreateGraph("Expected2")
        hExpected2s.SetFillColor(ROOT.kOrange)

        style = tdrstyle.TDRStyle()

        plot = plots.ComparisonManyPlot(
            histograms.HistoGraph(hObserved, "Observed"), [
                histograms.HistoGraph(hExpected, "Expected"),
                histograms.HistoGraph(hExpected1s, "Expected1"),
                histograms.HistoGraph(hExpected2s, "Expected2")
            ])

        obsStyle = styles.getDataStyle().clone()
        plot.histoMgr.forHisto("Observed", styles.getDataStyle().clone())
        plot.histoMgr.setHistoDrawStyle("Observed", "PL")

        expStyle = styles.getDataStyle().clone()
        expStyle.append(styles.StyleLine(lineStyle=2))
        expStyle.append(styles.StyleLine(lineColor=ROOT.kRed))
        expStyle.append(styles.StyleMarker(markerStyle=ROOT.kFullSquare))
        expStyle.append(styles.StyleMarker(markerColor=ROOT.kRed))
        plot.histoMgr.forHisto("Expected", expStyle)
        plot.histoMgr.setHistoDrawStyle("Expected", "PL")
        plot.histoMgr.setHistoDrawStyle("Expected1", "PL3")
        plot.histoMgr.setHistoDrawStyle("Expected2", "PL3")

        plot.createFrame(name,
                         opts={
                             "xmin": 70.1,
                             "xmax": 169.9,
                             "ymin": 0,
                             "ymax": 0.2
                         })
        plot.frame.GetXaxis().SetTitle(self.xtitle)
        plot.frame.GetYaxis().SetTitle(self.ytitle)

        plot.histoMgr.setHistoLegendStyle("Observed", "PL")
        plot.histoMgr.setHistoLegendStyle("Expected", "PL")
        plot.histoMgr.setHistoLegendStyle("Expected1", "F")
        plot.histoMgr.setHistoLegendStyle("Expected2", "F")

        plot.histoMgr.setHistoLegendLabelMany({
            "Expected":
            "Expected median",
            "Expected1":
            "Expected median #pm1#sigma",
            "Expected2":
            "Expected median #pm2#sigma"
        })
        plot.setLegend(histograms.createLegend(0.55, 0.68, 0.9, 0.93))

        histograms.addCmsPreliminaryText()
        histograms.addEnergyText()
        histograms.addLuminosityText(x=None, y=None, lumi=self.lumi)

        textSize = 16
        textX = 0.19
        textY = 0.8
        textDY = 0.038
        histograms.addText(textX, textY + 2 * textDY,
                           "t#rightarrowbH^{#pm}, H^{#pm}#rightarrow#tau#nu",
                           textSize)
        histograms.addText(textX, textY + textDY, "Fully hadronic final state",
                           textSize)
        histograms.addText(textX, textY,
                           "BR(H^{#pm}#rightarrow#tau^{#pm} #nu) = 1",
                           textSize)

        plot.draw()
        plot.save()
    def createPlot(name):
        if mtOnly and "shapeTransverseMass" not in name:
            return None

        drhEmb = getDRH(dsetEmb, name, systematicsEmbMC)
        drhSig = getDRH(dsetSig, name, systematicsSigMC)
        drhEmb.normalizeToLuminosity(lumi)
        drhSig.normalizeToLuminosity(lumi)
        drhEmb.setName("Embedded")
        drhSig.setName("Normal")
        if addData:
            drhEmbData = getDRH(dsetEmbData, name, None)
            drhEmbData.setName("Embedded data")

        if "shapeTransverseMass" in name and "TTJets" in datasetName:
            doScaleFactors(drhSig.getHistogramWithUncertainties(),
                           drhEmb.getHistogramWithUncertainties(), outputDir,
                           opts)

        if addData:
            p = plots.ComparisonManyPlot(drhSig, [drhEmb, drhEmbData])
        else:
            p = plots.ComparisonManyPlot(drhSig, [drhEmb])
        p.setLuminosity(lumi)
        legLabel = plots._legendLabels.get(datasetName, datasetName)
        legEmb = "Embedded " + legLabel
        #legSig = "Normal "+legLabel
        #legSig = legLabel
        legSig = "Non-emb. %s with ^{}#tau_{h}" % legLabel
        if addEventCounts:
            legEmb += " (" + strIntegral(drhEmb.getHistogram()) + ")"
            legSig += " (" + strIntegral(drhSig.getHistogram()) + ")"
        p.histoMgr.setHistoLegendLabelMany({
            "Embedded": legEmb,
            "Normal": legSig,
        })
        #p.histoMgr.forEachHisto(styles.generator())
        hemb = p.histoMgr.getHisto("Embedded")
        hemb.setDrawStyle("HIST E")
        hemb.setLegendStyle("L")
        themb = hemb.getRootHisto()
        #styles.ttStyle.apply(themb)
        themb.SetLineColor(ROOT.kBlue)
        themb.SetLineWidth(2)
        themb.SetMarkerColor(themb.GetLineColor())
        themb.SetMarkerSize(0)
        hsig = p.histoMgr.getHisto("Normal")
        hsig.setLegendStyle("F")
        thsig = hsig.getRootHisto()
        thsig.SetFillColor(ROOT.kGray)
        thsig.SetLineColor(thsig.GetFillColor())
        histoOrder = ["Embedded", "Normal"]
        if addData:
            legData = "Embedded data"
            histoOrder.append("Embedded data")
            if addEventCounts:
                legData += " (" + strIntegral(drhEmbData.getHistogram()) + ")"
            p.histoMgr.setHistoLegendLabelMany({"Embedded data": legData})
            p.histoMgr.forHisto("Embedded data", styles.dataStyle)
            p.histoMgr.setHistoDrawStyle("Embedded data", "EP")
            p.histoMgr.setHistoLegendStyle("Embedded data", "P")
            p.histoMgr.reorderDraw(["Embedded data", "Embedded", "Normal"])
        if opts.dofit:
            p.setDrawOptions(ratioYlabel="Norm./Emb.",
                             ratioInvert=True,
                             ratioType="errorPropagation")
            if "shapeTransverseMass" in name and "TTJets" in datasetName:
                binning = systematics.getBinningForPlot("shapeTransverseMass")
                p.setDrawOptions(
                    customizeBeforeSave=lambda p: doScaleFactorFit(
                        p, outputDir),
                    rebin=range(0, 160, 20) + binning[binning.index(160):])
        else:
            #            p.setDrawOptions(ratioYlabel="Emb./Norm.")
            p.setDrawOptions(ratioYlabel="Emb./Non-emb.")
        p.histoMgr.reorder(histoOrder)
        return p
Пример #9
0
    def Save(self, name):

        if len(self.histogramsNotFound) > 0:
            for name in self.histogramsNotFound:
                print "Histo", name, "not found"
            self.histogramsNotFound = []
            return

        hObserved = self.histograms[self.FindHistoIndex(
            self.dataHistos[0].name)].Clone("Data")
        hObserved.Reset()
        for histo in self.dataHistos:
            hObserved.Add(self.histograms[self.FindHistoIndex(histo.label)])
        print "    Data:    ", hObserved.Integral(
            0, hObserved.GetNbinsX()), "events"
        hEstimatedEWKfake = self.histograms[self.FindHistoIndex(
            "EWKfake")].Clone("hEstimatedEWKfake")
        print "    EWKfake: ", hEstimatedEWKfake.Integral(
            0, hEstimatedEWKfake.GetNbinsX()), "events"
        hEstimatedEWK = self.histograms[self.FindHistoIndex("EWK")].Clone(
            "hEstimatedEWK")
        print "    EWK:     ", hEstimatedEWK.Integral(
            0, hEstimatedEWK.GetNbinsX()), "events"
        hEstimatedEWK.Add(hEstimatedEWKfake)
        hEstimatedQCD = self.histograms[self.FindHistoIndex("QCD")].Clone(
            "hEstimatedQCD")
        print "    QCD:     ", hEstimatedQCD.Integral(
            0, hEstimatedQCD.GetNbinsX()), "events"
        hEstimatedQCD.Add(hEstimatedEWK)
        hUncertainty = hEstimatedQCD.Clone("BackgrUncertainty")
        hUncertainty.SetFillColor(1)
        hUncertainty.SetFillStyle(3354)
        hUncertainty.SetLineColor(0)
        hUncertainty.SetLineStyle(0)
        hUncertainty.SetLineWidth(0)
        hUncertainty.SetMarkerColor(0)
        hUncertainty.SetMarkerSize(0)
        hSignal = self.histograms[self.FindHistoIndex("Signal")].Clone(
            "hSignal")
        print "    Signal:  ", hSignal.Integral(0,
                                                hSignal.GetNbinsX()), "events"
        hSignal.Add(hEstimatedQCD)

        style = tdrstyle.TDRStyle()

        plot = plots.ComparisonManyPlot(histograms.Histo(hObserved, "Data"), [
            histograms.Histo(hUncertainty, "Backgr.Uncertainty"),
            histograms.Histo(hEstimatedEWKfake, "EWKfake"),
            histograms.Histo(hEstimatedEWK, "EWK"),
            histograms.Histo(hEstimatedQCD, "QCD"),
            histograms.Histo(hSignal, "Signal")
        ])

        plot.histoMgr.forHisto("Data", styles.getDataStyle())

        plot.histoMgr.forHisto("EWK", styles.getEWKStyle())
        plot.histoMgr.forHisto("EWKfake", styles.getEWKFakeStyle())
        plot.histoMgr.forHisto("QCD", styles.getQCDStyle())
        plot.histoMgr.forHisto("Signal", styles.getSignalStyle())
        plot.histoMgr.forHisto("Backgr.Uncertainty", styles.getErrorStyle())

        plot.histoMgr.setHistoDrawStyleAll("HIST")
        plot.histoMgr.setHistoDrawStyle("Data", "EP")
        plot.histoMgr.setHistoDrawStyle("Backgr.Uncertainty", "E2")

        plot.histoMgr.setHistoLegendStyleAll("F")
        plot.histoMgr.setHistoLegendStyle("Data", "P")
        plot.histoMgr.setHistoLegendStyle("Signal", "L")

        plot.createFrame(name, opts={"ymin": 0, "ymaxfactor": 1.2})
        plot.frame.GetXaxis().SetTitle(self.xtitle)
        plot.frame.GetYaxis().SetTitle(self.ytitle)

        plot.histoMgr.reorderLegend(
            ["Data", "Signal", "QCD", "EWK", "EWKfake", "Backgr.Uncertainty"])
        self.setLegendLabels(plot)
        plot.setLegend(histograms.createLegend(0.55, 0.68, 0.9, 0.93))

        histograms.addCmsPreliminaryText()
        histograms.addEnergyText()
        histograms.addLuminosityText(x=None, y=None, lumi=self.lumi)

        plot.draw()
        plot.save()
    def createPlot(name, rebin=1, addVariation=False):
        name2Emb = name
        name2Sig = name
        if isinstance(name, basestring):
            name2Emb = analysisEmb + "/" + name
            name2Sig = analysisSig + "/" + name
        else:
            name2Emb = name.clone(tree=analysisEmb + "/tree")
            name2Sig = name.clone(tree=analysisSig + "/tree")

        (emb, embVar) = datasetsEmb.getHistogram(datasetName, name2Emb, rebin)
        sig = datasetsSig.getDataset(datasetName).getDatasetRootHisto(name2Sig)
        sig.normalizeToLuminosity(lumi)
        sig = sig.getHistogram()
        if rebin > 1:
            sig.Rebin(rebin)

        emb.SetName("Embedded")
        sig.SetName("Normal")

        p = None
        sty = plotStyles
        if addData:
            (embData, embDataVar) = datasetsEmb.getHistogram("Data",
                                                             name2Emb,
                                                             rebin=rebin)
            embData.SetName("EmbeddedData")
            #p = plots.ComparisonManyPlot(embData, [emb, sig])
            #p = plots.ComparisonPlot(embData, sig)
            p = plots.ComparisonManyPlot(sig, [embData, emb])
            p.histoMgr.reorderDraw(["EmbeddedData", "Embedded", "Normal"])
            p.histoMgr.reorderLegend(["EmbeddedData", "Embedded", "Normal"])
            p.histoMgr.setHistoDrawStyle("EmbeddedData", "EP")
            p.histoMgr.setHistoLegendStyle("EmbeddedData", "P")
            p.histoMgr.setHistoLegendStyle("Embedded", "PL")
            p.setLuminosity(lumi)
            #            sty = [styles.dataStyle, styles.styles[1]]
            #sty = [sty[0], styles.dataStyle, sty[1]]
            sty = [styles.dataStyle] + sty
        else:
            p = plots.ComparisonPlot(emb, sig)
            sty = styles.styles

        embedded = "Embedded "
        legLabel = plots._legendLabels.get(datasetName, datasetName)
        legLabelEmb = legLabel
        if legLabel != "Data":
            legLabel += " MC"
        residual = ""
        if isCorrected:
            embedded = "Emb. "
            residual = " + res. MC"
        else:
            lebLabelEmb += " MC"
        p.histoMgr.setHistoLegendLabelMany({
            "Embedded":
            embedded + legLabelEmb + residual,
            "Normal":
            "Normal " + legLabel,
            #"EmbeddedData": "Embedded data"+residual,
            "EmbeddedData":
            embedded + "data" + residual,
        })
        p.histoMgr.forEachHisto(styles.Generator(sty))
        if addVariation:
            if addData:
                if embDataVar != None:
                    plots.copyStyle(
                        p.histoMgr.getHisto("EmbeddedData").getRootHisto(),
                        embDataVar)
                    embDataVar.SetMarkerStyle(2)
                    p.embeddingDataVariation = embDataVar
            if embVar != None:
                plots.copyStyle(
                    p.histoMgr.getHisto("Embedded").getRootHisto(), embVar)
                embVar.SetMarkerStyle(2)
                p.embeddingVariation = embVar

        return p
Пример #11
0
    def compare(step):
        if step is None:
            path = "shapeTransverseMass"
        else:
            path = "CommonPlots/AtEveryStep/%s/MET_MET" % step

        #bins = range(0, 200, 20) + [200, 250, 300, 500]
        bins = systematics.getBinningForPlot("shapeTransverseMass")

        def getTH1(ds):
            drh = ds.getDatasetRootHisto(path)
            drh.normalizeToLuminosity(lumi)
            th1 = drh.getHistogram()
            #th1.Rebin(2)
            #return th1
            return th1.Rebin(
                len(bins) - 1, th1.GetName(), array.array("d", bins))

        th1NormalNum = getTH1(dsetNormalNum)
        th1NormalDenom = getTH1(dsetNormalDenom)

        #print th1NormalNum.Integral(0, th1NormalNum.GetNbinsX()+1), th1NormalDenom.Integral(0, th1NormalDenom.GetNbinsX()+1)

        th1EmbNum = getTH1(dsetEmbNum)
        th1EmbDenom = getTH1(dsetEmbDenom)

        #print th1EmbNum.Integral(0, th1EmbNum.GetNbinsX()+1), th1EmbDenom.Integral(0, th1EmbDenom.GetNbinsX()+1)

        effNormal = ROOT.TGraphAsymmErrors(th1NormalNum, th1NormalDenom, "n")
        effEmb = ROOT.TGraphAsymmErrors(th1EmbNum, th1EmbDenom, "n")

        effNormal.SetName("Normal ttbar")
        effEmb.SetName("Embedded ttbar")

        p = plots.ComparisonManyPlot(effNormal, [effEmb])
        p.setLuminosity(lumi)
        p.histoMgr.forEachHisto(styles.generator())
        #p.histoMgr.forHisto("Normal ttbar", lambda h: doStyle(h, ROOT.kBlack, ROOT.kFullCircle))
        #p.histoMgr.forHisto("Embedded ttbar", lambda h: doStyle(h, ROOT.kRed, ROOT.kFullSquare))
        p.histoMgr.setHistoDrawStyleAll("EP")
        p.histoMgr.setHistoLegendStyleAll("EPL")

        unc1 = 1.12
        unc2 = 0.88
        p.prependPlotObjectToRatio(
            doLineStyle(ROOT.TLine(0, unc1, bins[-1], unc1)))
        p.prependPlotObjectToRatio(
            doLineStyle(ROOT.TLine(0, unc2, bins[-1], unc2)))
        p.appendPlotObject(
            histograms.PlotText(x=0.6, y=0.6, text="CaloMET > 70 GeV",
                                size=20))

        global ind
        ind += 1
        # plots.drawPlot(p, "calometComparison/eff_%02d_calomet_%s"%(ind, step), xlabel="Type I PF MET (GeV)", ylabel="CaloMET cut efficiency",
        #                ratio=True, ratioYlabel="Norm./emb.", ratioType="errorScale",
        #                opts={"xmin": 0, "xmax": 500},
        #                opts2={"ymin": 0.8, "ymax": 1.2},
        #                addLuminosityText=True, moveLegend={"dx": -0.2, "dy": -0.5})

        plots.drawPlot(p,
                       "calometComparison/eff_%d_calomet_shapeTransverseMass" %
                       ind,
                       xlabel="Transverse mass (GeV)",
                       ylabel="CaloMET cut efficiency",
                       ratio=True,
                       ratioYlabel="Emb./Norm.",
                       ratioCreateLegend=True,
                       ratioType="errorScale",
                       opts={"ymax": 1.2},
                       opts2={
                           "ymin": 0.8,
                           "ymax": 1.2
                       },
                       addLuminosityText=True,
                       moveLegend={
                           "dx": -0.2,
                           "dy": -0.5
                       })
Пример #12
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()