def plotTurnOnData(datasets,
                   name,
                   pathAll,
                   pathPassed1,
                   pathPassed2,
                   dataText1,
                   dataText2,
                   rebin=1,
                   ratio=False):
    dataLabel1 = "Data: " + dataText1
    dataLabel2 = "Data: " + dataText2

    dataset = datasets.getDataset("Data")
    all = dataset.getDatasetRootHisto(pathAll).getHistogram()
    passed1 = dataset.getDatasetRootHisto(pathPassed1).getHistogram()
    passed2 = dataset.getDatasetRootHisto(pathPassed2).getHistogram()

    data_eff_gr1 = ROOT.TGraphAsymmErrors(passed1, all,
                                          "cp")  # 0.683 cl is default
    data_eff_gr2 = ROOT.TGraphAsymmErrors(passed2, all,
                                          "cp")  # 0.683 cl is default

    p = plots.ComparisonPlot(
        histograms.HistoGraph(data_eff_gr1, "Data1", "p", "P"),
        histograms.HistoGraph(data_eff_gr2, "Data2", "p", "P"))
    p.histoMgr.forEachHisto(
        styles.generator2(styles.StyleMarker(markerSizes=[1.0, 2.0]),
                          [styles.dataStyle, styles.mcStyle2]))
    p.histoMgr.setHistoLegendLabelMany({
        "Data1": dataLabel1,
        "Data2": dataLabel2,
    })
    p.setLuminosity(dataset.getLuminosity())

    opts = {"ymin": 0.0, "ymax": 1.1}
    #opts2 = {"ymin": 0.5, "ymax": 1.5}
    opts2 = {"ymin": 0.8, "ymax": 1.2}

    name = "calomet_turnon_" + runs + "_data_" + name
    p.createFrame(name,
                  createRatio=ratio,
                  invertRatio=True,
                  opts=opts,
                  opts2=opts2)
    if ratio:
        p.getFrame2().GetYaxis().SetTitle("Ratio")

    p.setLegend(
        histograms.moveLegend(
            histograms.createLegend(y1=0.95, y2=0.85),
            #dx=-0.55, dy=-0.05
            dx=-0.44,
            dy=-0.58))

    common(p, "Uncorrected PF E_{T}^{miss} (GeV)", "Efficiency")
Esempio n. 2
0
    def addCurve(self, name, label):
        def getHisto(dataset):
            tmp = self.datasets.getDataset(dataset).getDatasetRootHisto(name)
            #tmp.normalizeToLuminosity(46)
            tmp.normalizeByCrossSection()
            return tmp.getHistogram()

        signalRootHisto = getHisto("Signal")
        signalEff = muonAnalysis.dist2eff(signalRootHisto)
        signalEffValues = dataset.histoToList(signalEff)

        tmpHistoManager = histograms.HistoManager(self.datasets, name)
        tmpHistoManager.normalizeMCByCrossSection()
        #tmpHistoManager.normalizeMCByLuminosity()
        mcSum = histograms.sumRootHistos([
            muonAnalysis.getSumOrRootHisto(histo) for histo in filter(
                lambda h: h.isMC(), tmpHistoManager.getHistos())
        ])
        mcSum = muonAnalysis.dist2pass(mcSum)

        bkgHisto = tmpHistoManager.getHisto("Background")
        bkg = muonAnalysis.getSumOrRootHisto(bkgHisto).Clone(name +
                                                             "_bkgfraction")
        bkg = muonAnalysis.dist2pass(bkg)
        bkg.Divide(mcSum)
        bkgValues = dataset.histoToList(bkg)

        curve = ROOT.TGraph(len(signalEffValues),
                            array.array("d", signalEffValues),
                            array.array("d", bkgValues))
        self.histoMgr.appendHisto(histograms.HistoGraph(curve, label))
 def addEmbStatSyst(p):
     rhwu = p.histoMgr.getHisto("Embedded").getRootHistoWithUncertainties()
     embStatSyst = rhwu.getSystematicUncertaintyGraph(addStatistical=True)
     for i in xrange(0, embStatSyst.GetN()):
         embStatSyst.SetPointEXhigh(i, 0)
         embStatSyst.SetPointEXlow(i, 0)
     aux.copyStyle(rhwu.getRootHisto(), embStatSyst)
     p.appendPlotObject(
         histograms.HistoGraph(embStatSyst,
                               "EmbStatSyst",
                               legendStyle=None,
                               drawStyle="[]"))
Esempio n. 4
0
 def createPlot(graph_, **kwargs):
     if isinstance(graph_, ROOT.TH1):
         defaults = {"legendStyle": "l"}
         defaults.update(kwargs)
         graph_.GetZaxis().SetTitle("")
         ####            return plots.PlotBase([histograms.HistoBase(graph_, "efficiency", **defaults)])
         return plots.PlotBase(
             [histograms.Histo(graph_, "efficiency", **defaults)])
     else:
         defaults = {"drawStyle": "EP"}
         defaults.update(kwargs)
         return plots.PlotBase(
             [histograms.HistoGraph(graph_, "efficiency", **defaults)])
Esempio n. 5
0
    def addCurve(self, name, label):
        def getHisto(dataset):
            tmp = self.datasets.getDataset(dataset).getDatasetRootHisto(name)
            tmp.normalizeByCrossSection()
            return tmp.getHistogram()

        signalRootHisto = getHisto("Signal")
        bkgRootHisto = getHisto("Background")

        signalEff = muonAnalysis.dist2eff(signalRootHisto)
        bkgRej = muonAnalysis.dist2rej(bkgRootHisto)
        #        bkgRej = muonAnalysis.dist2eff(bkgRootHisto)

        signalEffValues = dataset.histoToList(signalEff)
        bkgRejValues = dataset.histoToList(bkgRej)

        roc = ROOT.TGraph(len(signalEffValues),
                          array.array("d", signalEffValues),
                          array.array("d", bkgRejValues))
        self.histoMgr.appendHisto(histograms.HistoGraph(roc, label))
Esempio n. 6
0
def plotEfficiency(datasets,
                   datasetNames,
                   allPath,
                   passedPath,
                   name,
                   xlabel,
                   rebinBins=None,
                   **kwargs):
    if mcOnly:
        return

    def rebin(h):
        return h.Rebin(
            len(rebinBins) - 1, h.GetName(), array.array("d", rebinBins))

    for dname in datasetNames:
        dset = datasets.getDataset(dname)
        allHisto = dset.getDatasetRootHisto(allPath).getHistogram()
        passedHisto = dset.getDatasetRootHisto(passedPath).getHistogram()

        if allHisto.Integral() < 1:
            continue

        if rebinBins != None:
            allHisto = rebin(allHisto)
            passedHisto = rebin(passedHisto)

        eff = ROOT.TGraphAsymmErrors(passedHisto, allHisto,
                                     "cp")  # 0.683 cl is default
        p = plots.PlotBase([histograms.HistoGraph(eff, dname, "p", "P")])
        if dset.isData():
            p.setLuminosity(dset.getLuminosity())
        opts = {"ymin": 0.0, "ymax": 1.1}

        plots.drawPlot(p,
                       name + "_" + dname,
                       xlabel,
                       addLuminosityText=dset.isData(),
                       opts=opts,
                       **kwargs)
Esempio n. 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()
Esempio n. 8
0
 def addDataStatSyst(p):
     dataStatSyst = p.histoMgr.getHisto("Data").getRootHistoWithUncertainties().getSystematicUncertaintyGraph(addStatistical=True)
     for i in xrange(0, dataStatSyst.GetN()):
         dataStatSyst.SetPointEXhigh(i, 0)
         dataStatSyst.SetPointEXlow(i, 0)
     p.appendPlotObject(histograms.HistoGraph(dataStatSyst, "DataStatSyst", legendStyle=None, drawStyle="[]"))
Esempio n. 9
0
 def addPoint(self, sigeff, bkgfrac, label):
     gr = ROOT.TGraph(1, array.array("d", [sigeff]),
                      array.array("d", [bkgfrac]))
     self.histoMgr.appendHisto(histograms.HistoGraph(gr, label))
     self.pointLabels.append(label)
Esempio n. 10
0
def plotTurnOn(datasets,
               pathAll,
               pathPassed,
               commonText,
               dataText=None,
               mcText=None,
               rebin=1,
               ratio=False):
    dataLabel = "Data"
    mcLabel = "Simulation"
    if dataText != None and mcText == None:
        raise Exception("mcText must not be None when dataText is not")
    if dataText == None and mcText != None:
        raise Exception("dataText must not be None when mcText is not")


#    if dataText != None:
#        dataLabel += ": "+dataText
#        mcLabel += ": "+mcText

    mc_effs = []
    data_eff_gr = None
    binWidth = None
    luminosity = 0
    for dataset in datasets.getAllDatasets():
        all = dataset.getDatasetRootHisto(pathAll).getHistogram()
        passed = dataset.getDatasetRootHisto(pathPassed).getHistogram()

        if rebin > 1:
            all.Rebin(rebin)
            passed.Rebin(rebin)
        binWidth = all.GetBinWidth(1)

        if dataset.isMC() and not "TTTo" in dataset.getName():
            #if dataset.isMC() and not "TTTo" in dataset.getName() and not "QCD" in dataset.getName():
            #if dataset.isMC() and "QCD" in dataset.getName():
            mc_effs.append(HistoEff(all, passed, dataset))

        elif dataset.isData():
            data_eff_gr = ROOT.TGraphAsymmErrors(passed, all,
                                                 "cp")  # 0.683 cl is default
            luminosity += dataset.getLuminosity()

    mc_eff_gr = combineHistoEffs(mc_effs)

    p = plots.ComparisonPlot(
        histograms.HistoGraph(data_eff_gr, "Data", "p", "P"),
        histograms.HistoGraph(mc_eff_gr, "Simulation", "p", "P"))
    p.histoMgr.forEachHisto(
        styles.generator2(styles.StyleMarker(markerSizes=[1.0, 1.5]),
                          plotStyles))
    p.histoMgr.setHistoLegendLabelMany({
        "Data": dataLabel,
        "Simulation": mcLabel,
    })
    p.setLuminosity(luminosity)
    #p.addGraph(data_eff_gr, "Data")
    #p.addGraph(mc_eff_gr, "Simulation")
    #p.finalize()

    opts = {"ymin": 0.0, "ymax": 1.1}
    #opts2 = {"ymin": 0.5, "ymax": 1.5}
    opts2 = {"ymin": 0.7, "ymax": 1.3}

    name = "calomet_turnon_" + runs
    if not mcDataDefinition:
        name += "_McSummer11"
    if caloMetNoHF:
        name += "_caloMetNoHF"

    p.createFrame(name, createRatio=ratio, opts=opts, opts2=opts2)
    if ratio:
        p.getFrame2().GetYaxis().SetTitle("Ratio")
        p.cf.canvas.cd(2)
        p.line1 = plots._createRatioLine(p.cf.frame.getXmin(),
                                         p.cf.frame.getXmax(), 0.9)
        p.line2 = plots._createRatioLine(p.cf.frame.getXmin(),
                                         p.cf.frame.getXmax(), 1.1)
        p.line1.SetLineColor(ROOT.kBlue)
        p.line2.SetLineColor(ROOT.kBlue)
        p.line1.Draw("L")
        p.line2.Draw("L")
        p.cf.canvas.cd(1)

    p.setLegend(
        histograms.moveLegend(
            histograms.createLegend(y1=0.95, y2=0.85),
            #dx=-0.55, dy=-0.05
            #dx=-0.44, dy=-0.58
            dx=-0.3,
            dy=-0.4))

    x = 0.25
    y = 0.3
    dy = 0.035
    mcColor = mc_eff_gr.GetMarkerColor()
    size = 17
    p.appendPlotObject(
        histograms.PlotText(x, y, "Data (runs %s):" % runs, size=size))
    y -= dy
    p.appendPlotObject(histograms.PlotText(x, y, dataText, size=size))
    y -= dy

    y -= 0.01
    p.appendPlotObject(
        histograms.PlotText(x, y, "Simulation:", size=size, color=mcColor))
    y -= dy
    p.appendPlotObject(
        histograms.PlotText(x, y, mcText, size=size, color=mcColor))
    y -= dy

    def text():
        l = ROOT.TLatex()
        l.SetNDC()
        #        l.SetTextFont(l.GetTextFont()-20) # bold -> normal
        l.SetTextSize(l.GetTextSize() * 0.65)
        #l.DrawLatex(0.35, 0.4, commonText)
        l.DrawLatex(0.48, 0.32, commonText)

    textFunction = text
    if dataText != None:
        textFunction = None
    #common(p, "PF E_{T}^{miss} (GeV)", "Efficiency / %.0f GeV"%binWidth, afterDraw=textFunction)
    common(p,
           "Uncorrected PF E_{T}^{miss} (GeV)",
           "Efficiency",
           afterDraw=textFunction)
def doCounters(datasets):
    eventCounter = counter.EventCounter(datasets)

    eventCounter.normalizeMCByLuminosity()
    #    eventCounter.normalizeMCToLuminosity(73)
    print "============================================================"
    print "Main counter (MC normalized by collision data luminosity)"
    print eventCounter.getMainCounterTable().format()

    # Set the signal cross sections to a value from MSSM
    #    xsect.setHplusCrossSectionsToMSSM(datasets, tanbeta=20, mu=200)

    ###    plots.mergeWHandHH(datasets) # merging of WH and HH signals must be done after setting the cross section

    style = tdrstyle.TDRStyle()

    eventCounter = counter.EventCounter(datasets)
    eventCounter.normalizeMCByCrossSection()
    mainTable = eventCounter.getMainCounterTable()

    signalDatasets = [
        "TTToHplusBWB_M80",
        "TTToHplusBWB_M90",
        "TTToHplusBWB_M100",
        "TTToHplusBWB_M120",
        "TTToHplusBWB_M140",
        "TTToHplusBWB_M150",
        "TTToHplusBWB_M155",
        "TTToHplusBWB_M160",
        #        "TTToHplusBHminusB_M80",
        #        "TTToHplusBHminusB_M90",
        #        "TTToHplusBHminusB_M100",
        #        "TTToHplusBHminusB_M120",
        #        "TTToHplusBHminusB_M140",
        #        "TTToHplusBHminusB_M150",
        #        "TTToHplusBHminusB_M155",
        #        "TTToHplusBHminusB_M160",
    ]
    allName = "All events"

    cuts = [
        "Trigger and HLT_MET cut", "primary vertex", "taus == 1",
        "trigger scale factor", "electron veto", "muon veto", "njets", "MET",
        "btagging", "btagging scale factor", "DeltaPhi(Tau,MET) upper limit"
    ]

    xvalues = [80, 90, 100, 120, 140, 150, 155, 160]
    #    xvalues = [80, 90, 120, 140, 150, 155, 160]
    xerrs = [0] * len(xvalues)
    yvalues = {}
    yerrs = {}
    for cut in cuts:
        yvalues[cut] = []
        yerrs[cut] = []
    for name in signalDatasets:
        column = mainTable.getColumn(name=name)

        # Get the counts (returned objects are of type dataset.Count,
        # and have both value and uncertainty
        #        allCount = column.getCount(column.getRowNames().index("All events"))

        for cut in cuts:
            cutCount = column.getCount(column.getRowNames().index(cut))
            if column.getRowNames().index(cut) == 1:  ## trigger
                allCount = column.getCount(
                    column.getRowNames().index("Offline selection begins"))

            if column.getRowNames().index(cut) == 4:  ## tau id
                allCount = column.getCount(
                    column.getRowNames().index("Trigger and HLT_MET cut"))

            if column.getRowNames().index(cut) == 9:  ## electron veto
                allCount = column.getCount(
                    column.getRowNames().index("taus == 1"))

            if column.getRowNames().index(cut) == 10:  ## muon veto
                ## muon veto for lepton veto
                allCount = column.getCount(
                    column.getRowNames().index("trigger scale factor"))
#                allCount = column.getCount(column.getRowNames().index("electron veto"))

            if column.getRowNames().index(cut) == 12:  ## njets
                allCount = column.getCount(
                    column.getRowNames().index("muon veto"))

            if column.getRowNames().index(cut) == 13:  ## MET
                allCount = column.getCount(column.getRowNames().index("njets"))

            if column.getRowNames().index(cut) == 15:  ## btagging
                allCount = column.getCount(column.getRowNames().index("MET"))

            if column.getRowNames().index(
                    cut) == 16:  ## DeltaPhi(Tau,MET) upper limit
                allCount = column.getCount(
                    column.getRowNames().index("btagging scale factor"))

            eff = cutCount.clone()
            eff.divide(allCount)  # N(cut) / N(all)
            #            print "cutCount ",cutCount.value(),"allCount  ",allCount.value()

            yvalues[cut].append(eff.value())
            yerrs[cut].append(eff.uncertainty())
            if column.getRowNames().index(
                    cut) == 9:  ## DeltaPhi(Tau,MET) upper
                print cut, eff.value()

    def createErrors(cutname):
        gr = ROOT.TGraphErrors(len(xvalues), array.array("d", xvalues),
                               array.array("d", yvalues[cutname]),
                               array.array("d", xerrs),
                               array.array("d", yerrs[cutname]))
        gr.SetMarkerStyle(24)
        gr.SetMarkerColor(2)
        gr.SetMarkerSize(0.9)
        gr.SetLineStyle(1)
        gr.SetLineWidth(2)
        return gr

    gtrig = createErrors("Trigger and HLT_MET cut")
    gtrig.SetLineColor(38)
    gtrig.SetMarkerColor(38)
    gtrig.SetMarkerStyle(20)
    gtrig.SetMarkerSize(2)
    gtrig.SetLineStyle(1)  ## 8
    gtrig.SetLineWidth(4)

    gtau = createErrors("taus == 1")
    gtau.SetLineColor(2)
    gtau.SetMarkerColor(2)
    gtau.SetMarkerStyle(21)
    gtau.SetMarkerSize(2)
    gtau.SetLineStyle(1)  ##3
    gtau.SetLineWidth(4)
    #gtau = createErrors("trigger scale factor")
    gveto = createErrors("muon veto")
    gveto.SetLineColor(6)
    gveto.SetMarkerColor(6)
    gveto.SetMarkerStyle(22)
    gveto.SetMarkerSize(2)
    gveto.SetLineStyle(1)  ## 5
    gveto.SetLineWidth(4)
    gjets = createErrors("njets")
    gjets.SetLineColor(4)
    gjets.SetMarkerColor(4)
    gjets.SetMarkerStyle(23)
    gjets.SetMarkerSize(2)
    gjets.SetLineStyle(1)  ## 1
    gjets.SetLineWidth(4)
    gmet = createErrors("MET")
    gmet.SetLineColor(ROOT.kGreen + 2)
    gmet.SetMarkerColor(ROOT.kGreen + 2)
    gmet.SetMarkerStyle(24)
    gmet.SetMarkerSize(2)
    gmet.SetLineStyle(1)  ##2
    gmet.SetLineWidth(4)
    gbtag = createErrors("btagging")
    gbtag.SetLineColor(1)
    gbtag.SetMarkerColor(1)
    gbtag.SetMarkerStyle(25)
    gbtag.SetMarkerSize(2)
    gbtag.SetLineStyle(1)  ## 6
    gbtag.SetLineWidth(4)
    gdphi = createErrors("DeltaPhi(Tau,MET) upper limit")
    gdphi.SetLineColor(93)
    gdphi.SetMarkerColor(93)
    gdphi.SetMarkerStyle(26)
    gdphi.SetMarkerSize(2)
    gdphi.SetLineStyle(1)  ## 6
    gdphi.SetLineWidth(4)
    #gtau = createErrors("trigger scale factor")

    glist = [gtrig, gtau, gveto, gjets, gmet, gbtag, gdphi]

    opts = {"xmin": 75, "xmax": 165, "ymin": 0.06}
    canvasFrame = histograms.CanvasFrame(
        [histograms.HistoGraph(g, "", "") for g in glist],
        "SignalEfficiencyConseq", **opts)
    canvasFrame.frame.GetYaxis().SetTitle("Selection efficiency")
    canvasFrame.frame.GetXaxis().SetTitle("m_{H^{#pm}} (GeV/c^{2})")
    canvasFrame.canvas.SetLogy(True)
    canvasFrame.frame.Draw()

    for gr in glist:
        gr.Draw("PC same")

    histograms.addStandardTexts()

    #    tex5 = ROOT.TLatex(120,0.11,"t#bar{t} -> bH^{#pm}bH^{#pm}")
    tex5 = ROOT.TLatex(120, 0.3, "t#bar{t} -> bH^{#pm}bW")

    #    tex5.SetNDC()
    tex5.SetTextSize(25)
    tex5.Draw()

    legend = histograms.createLegend(x1=0.2, y1=0.36, x2=0.5, y2=0.65)

    legend.AddEntry(gtrig, "Trigger", "lp")
    legend.AddEntry(gtau, "#tau identification", "lp")
    legend.AddEntry(gveto, "lepton vetoes", "lp")
    legend.AddEntry(gjets, "3 jets", "lp")
    legend.AddEntry(gmet, "MET ", "lp")
    legend.AddEntry(gbtag, "b tagging ", "lp")
    legend.AddEntry(gdphi, "DeltaPhi(Tau,MET)", "lp")
    legend.Draw()

    canvasFrame.canvas.SaveAs(".png")
    canvasFrame.canvas.SaveAs(".C")
    canvasFrame.canvas.SaveAs(".eps")
Esempio n. 12
0
def main():
    # Read the datasets
    #datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)
    datasets = dataset.getDatasetsFromMulticrabCfg(analysisName=analysis,
                                                   searchMode=searchMode,
                                                   dataEra=dataEra,
                                                   optimizationMode=optMode)
    datasets.updateNAllEventsToPUWeighted()
    datasets.loadLuminosities()

    plots.mergeRenameReorderForDataMC(datasets)

    # Remove signals other than M120
    ###    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))
    #datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))
    datasets.remove(
        filter(lambda name: "TTToHplusBHminusB" in name,
               datasets.getAllDatasetNames()))
    datasets.remove(
        filter(lambda name: "TTToHplus" in name,
               datasets.getAllDatasetNames()))
    # Set the signal cross sections to a given BR(t->H), BR(h->taunu)
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Set the signal cross sections to a value from MSSM
    #    xsect.setHplusCrossSectionsToMSSM(datasets, tanbeta=20, mu=200)

    ###    plots.mergeWHandHH(datasets) # merging of WH and HH signals must be done after setting the cross section

    style = tdrstyle.TDRStyle()
    eventCounter = counter.EventCounter(datasets)
    #eventCounter = counter.EventCounter(datasets, counters=counters)
    eventCounter.normalizeMCByCrossSection()
    mainTable = eventCounter.getMainCounterTable()
    cellFormat = counter.TableFormatText(cellFormat=counter.CellFormatText(
        valueOnly=True))
    print mainTable.format(cellFormat)

    #eventCounterUnweighted = counter.EventCounter(datasets, mainCounterOnly=True, counters="counters")
    #eventCounterUnweighted.normalizeMCByCrossSection()
    #mainTableUnweighted = eventCounterUnweighted.getMainCounterTable()
    #print mainTableUnweighted.format(cellFormat)

    signalDatasets = [
        "HplusTB_M180",
        "HplusTB_M190",
        "HplusTB_M200",
        "HplusTB_M220",
        "HplusTB_M250",
        "HplusTB_M300",
        #"HplusTB_M400",
        #"HplusTB_M500",
        #"HplusTB_M600",
        #"TTToHplusBWB_M80",
        #"TTToHplusBWB_M90",
        #"TTToHplusBWB_M100",
        #"TTToHplusBWB_M120",
        #"TTToHplusBWB_M140",
        #"TTToHplusBWB_M150",
        #"TTToHplusBWB_M155",
        #"TTToHplusBWB_M160",
    ]
    allName = "Trigger and HLT_MET cut"

    cuts = [
        #"Offline selection begins",
        "Trigger and HLT_MET cut",
        "primary vertex",
        "taus == 1",
        "tau trigger scale factor",
        "electron veto",
        "muon veto",
        "njets",
        "QCD tail killer collinear",
        "MET",
        "btagging",
        "btagging scale factor",
        "QCD tail killer back-to-back"
    ]

    xvalues = [180, 190, 200, 220, 250, 300]
    #xvalues = [80, 90, 100, 120, 140, 150, 155, 160]
    xerrs = [0] * len(xvalues)
    yvalues = {}
    yerrs = {}
    for cut in cuts:
        yvalues[cut] = []
        yerrs[cut] = []
    for name in signalDatasets:
        column = mainTable.getColumn(name=name)
        #columnUnweighted = mainTableUnweighted.getColumn(name=name)

        # Get the counts (returned objects are of type dataset.Count,
        # and have both value and uncertainty
        #allCount = column.getCount(column.getRowNames().index("Trigger and HLT_MET cut"))
        # Somewhat weird way to get total cross section via unweighted counters
        #rowNames = column.getRowNames()
        #if "allEvents" in rowNames:
        #    allCount = columnUnweighted.getCount(rowNames.index("allEvents"))
        #else:
        #    # Hack needed because non-triggered signal pattuples do not have allEvents counter!
        #    allCount = columnUnweighted.getCount(rowNames.index("primaryVertexAllEvents"))
        #dset = datasets.getDataset(name)
        #allCount.multiply(dataset.Count(dset.getNAllEvents()/dset.getNAllEventsUnweighted()))
        allCount = dataset.Count(
            datasets.getDataset(name).getCrossSection(), 0)

        for cut in cuts:
            cutCount = column.getCount(column.getRowNames().index(cut))
            eff = cutCount.clone()
            eff.divide(allCount)  # N(cut) / N(all)
            if column.getRowNames().index(cut) == 9:  ## btagging
                print cut, eff.value()
            yvalues[cut].append(eff.value())
            yerrs[cut].append(eff.uncertainty())

    def createErrors(cutname):
        gr = ROOT.TGraphErrors(len(xvalues), array.array("d", xvalues),
                               array.array("d", yvalues[cutname]),
                               array.array("d", xerrs),
                               array.array("d", yerrs[cutname]))
        gr.SetMarkerStyle(24)
        gr.SetMarkerColor(2)
        gr.SetMarkerSize(0.9)
        gr.SetLineStyle(1)
        gr.SetLineWidth(2)
        return gr

    #gtrig = createErrors("primary vertex")
    gtrig = createErrors("Trigger and HLT_MET cut")
    print gtrig
    gtrig.SetLineColor(38)
    gtrig.SetMarkerColor(38)
    gtrig.SetMarkerStyle(20)
    gtrig.SetLineStyle(2)
    gtrig.SetMarkerSize(2)

    gtau = createErrors("taus == 1")
    gtau.SetLineColor(2)
    gtau.SetMarkerColor(2)
    gtau.SetMarkerStyle(20)
    gtau.SetMarkerSize(2)
    gtau.SetLineStyle(3)
    #gtau = createErrors("trigger scale factor")

    gveto = createErrors("muon veto")
    gveto.SetLineColor(1)
    gveto.SetMarkerColor(1)
    gveto.SetMarkerStyle(21)
    gveto.SetMarkerSize(2)
    gveto.SetLineStyle(4)
    gjets = createErrors("njets")
    gjets.SetLineColor(4)
    gjets.SetMarkerColor(4)
    gjets.SetMarkerStyle(22)
    gjets.SetMarkerSize(2)
    gjets.SetLineStyle(1)
    gcoll = createErrors("QCD tail killer collinear")
    gcoll.SetLineColor(6)
    gcoll.SetMarkerColor(6)
    gcoll.SetMarkerStyle(26)
    gcoll.SetMarkerSize(2)
    gcoll.SetLineStyle(2)
    gmet = createErrors("MET")
    gmet.SetLineColor(1)
    gmet.SetMarkerColor(1)
    gmet.SetMarkerStyle(24)
    gmet.SetMarkerSize(2)
    gmet.SetLineStyle(5)
    gbtag = createErrors("btagging")
    gbtag.SetLineColor(2)
    gbtag.SetMarkerColor(2)
    gbtag.SetMarkerStyle(25)
    gbtag.SetMarkerSize(2)
    gbtag.SetLineStyle(6)
    print gbtag
    gback = createErrors("QCD tail killer back-to-back")
    gback.SetLineColor(7)
    gback.SetMarkerColor(7)
    gback.SetMarkerStyle(23)
    gback.SetMarkerSize(2)
    gback.SetLineStyle(1)
    #gtau = createErrors("trigger scale factor")

    glist = [gtrig, gtau, gveto, gjets, gcoll, gmet, gbtag, gback]

    opts = {"xmin": 175, "xmax": 310, "ymin": 0.001}
    canvasFrame = histograms.CanvasFrame(
        [histograms.HistoGraph(g, "", "") for g in glist], "SignalEfficiency",
        **opts)
    canvasFrame.frame.GetYaxis().SetTitle("Selection efficiency")
    canvasFrame.frame.GetXaxis().SetTitle("m_{H^{#pm}} (GeV/c^{2})")
    canvasFrame.canvas.SetLogy(True)
    canvasFrame.frame.Draw()

    for gr in glist:
        gr.Draw("PC same")

    histograms.addStandardTexts()

    legend2 = histograms.createLegend(x1=0.5, y1=0.7, x2=0.9, y2=0.85)

    legend2.AddEntry(gtrig, "Trigger", "lp")
    legend2.AddEntry(gtau, "Loose #tau identification", "lp")
    legend2.AddEntry(gveto, "lepton vetoes", "lp")
    legend2.AddEntry(gjets, "3 jets", "lp")
    legend2.Draw()

    legend = histograms.createLegend(x1=0.35, y1=0.15, x2=0.7, y2=0.3)
    legend.AddEntry(gcoll, "QCD tail killer collinear", "lp")
    legend.AddEntry(gmet, "MET > 60 GeV", "lp")
    legend.AddEntry(gbtag, "b tagging ", "lp")
    legend.AddEntry(gback, "QCD tail killer back-to-back: Tight", "lp")
    legend.Draw()
    canvasFrame.canvas.SaveAs(".png")
    canvasFrame.canvas.SaveAs(".C")
    canvasFrame.canvas.SaveAs(".eps")
Esempio n. 13
0
def main():
    # Read the datasets
    datasets = dataset.getDatasetsFromMulticrabCfg(counters=counters)
    datasets.loadLuminosities()

    plots.mergeRenameReorderForDataMC(datasets)

    # Remove signals other than M120
    ###    datasets.remove(filter(lambda name: "TTToHplus" in name and not "M120" in name, datasets.getAllDatasetNames()))
    ###    datasets.remove(filter(lambda name: "HplusTB" in name, datasets.getAllDatasetNames()))

    # Set the signal cross sections to a given BR(t->H), BR(h->taunu)
    xsect.setHplusCrossSectionsToBR(datasets, br_tH=0.05, br_Htaunu=1)

    # Set the signal cross sections to a value from MSSM
    #    xsect.setHplusCrossSectionsToMSSM(datasets, tanbeta=20, mu=200)

    ###    plots.mergeWHandHH(datasets) # merging of WH and HH signals must be done after setting the cross section

    style = tdrstyle.TDRStyle()

    eventCounter = counter.EventCounter(datasets, counters=counters)
    eventCounter.normalizeMCByCrossSection()
    mainTable = eventCounter.getMainCounterTable()

    signalDatasets = [
        "TTToHplusBWB_M80",
        "TTToHplusBWB_M90",
        "TTToHplusBWB_M100",
        "TTToHplusBWB_M120",
        "TTToHplusBWB_M140",
        "TTToHplusBWB_M150",
        "TTToHplusBWB_M155",
        "TTToHplusBWB_M160",
    ]
    allName = "All events"

    cuts = [
        "Trigger and HLT_MET cut", "primary vertex", "taus == 1",
        "trigger scale factor", "electron veto", "muon veto", "njets", "MET",
        "btagging", "btagging scale factor"
    ]

    xvalues = [80, 90, 100, 120, 140, 150, 155, 160]
    xerrs = [0] * len(xvalues)
    yvalues = {}
    yerrs = {}
    for cut in cuts:
        yvalues[cut] = []
        yerrs[cut] = []
    for name in signalDatasets:
        column = mainTable.getColumn(name=name)

        # Get the counts (returned objects are of type dataset.Count,
        # and have both value and uncertainty
        allCount = column.getCount(column.getRowNames().index("All events"))

        for cut in cuts:
            cutCount = column.getCount(column.getRowNames().index(cut))
            eff = cutCount.clone()
            eff.divide(allCount)  # N(cut) / N(all)

            yvalues[cut].append(eff.value())
            yerrs[cut].append(eff.uncertainty())

    def createErrors(cutname):
        gr = ROOT.TGraphErrors(len(xvalues), array.array("d", xvalues),
                               array.array("d", yvalues[cutname]),
                               array.array("d", xerrs),
                               array.array("d", yerrs[cutname]))
        gr.SetMarkerStyle(24)
        gr.SetMarkerColor(2)
        gr.SetMarkerSize(0.9)
        gr.SetLineStyle(1)
        gr.SetLineWidth(2)
        return gr

    gtrig = createErrors("Trigger and HLT_MET cut")
    gtrig.SetLineColor(38)
    gtrig.SetMarkerColor(38)
    gtrig.SetLineStyle(2)
    gtau = createErrors("taus == 1")
    gtau.SetLineColor(2)
    gtau.SetMarkerColor(2)
    gtau.SetLineStyle(3)
    #gtau = createErrors("trigger scale factor")
    gveto = createErrors("muon veto")
    gveto.SetLineColor(1)
    gveto.SetMarkerColor(1)
    gveto.SetLineStyle(4)
    gjets = createErrors("njets")
    gjets.SetLineColor(4)
    gjets.SetMarkerColor(4)
    gjets.SetLineStyle(1)
    gmet = createErrors("MET")
    gmet.SetLineColor(2)
    gmet.SetMarkerColor(2)
    gmet.SetLineStyle(5)
    gbtag = createErrors("btagging")
    gbtag.SetLineColor(1)
    gbtag.SetMarkerColor(1)
    gbtag.SetLineStyle(6)
    #gtau = createErrors("trigger scale factor")

    glist = [gtrig, gtau, gveto, gjets, gmet, gbtag]

    opts = {"xmin": 75, "xmax": 165, "ymin": 0.001}
    canvasFrame = histograms.CanvasFrame(
        [histograms.HistoGraph(g, "", "") for g in glist], "SignalEfficiency",
        **opts)
    canvasFrame.frame.GetYaxis().SetTitle("Selection efficiency")
    canvasFrame.frame.GetXaxis().SetTitle("m_{H^{#pm}} (GeV/c^{2})")
    canvasFrame.canvas.SetLogy(True)
    canvasFrame.frame.Draw()

    for gr in glist:
        gr.Draw("PC same")

    histograms.addEnergyText()
    histograms.addCmsPreliminaryText()

    legend = histograms.createLegend(x1=0.5, y1=0.53, x2=0.85, y2=0.75)

    legend.AddEntry(gtrig, "Trigger", "l")
    legend.AddEntry(gtau, "#tau identification", "l")
    legend.AddEntry(gveto, "lepton vetoes", "l")
    legend.AddEntry(gjets, "3 jets", "l")
    legend.AddEntry(gmet, "MET ", "l")
    legend.AddEntry(gbtag, "b tagging ", "l")
    legend.Draw()

    canvasFrame.canvas.SaveAs(".png")
    canvasFrame.canvas.SaveAs(".C")
    canvasFrame.canvas.SaveAs(".eps")