Пример #1
0
def getFromPF(dataset, pathAll, pathPassed, bin):
    hall = histograms.dist2pass(dataset.getDatasetRootHisto(pathAll).getHistogram(), greaterThan=True)
    hpassed= histograms.dist2pass(dataset.getDatasetRootHisto(pathPassed).getHistogram(), greaterThan=True)
    all = hall.GetBinContent(bin)
    passed = hpassed.GetBinContent(bin)
    cutvalue = hpassed.GetBinCenter(bin)
    if abs(cutvalue-hall.GetBinCenter(bin)) > 1e-4:
        raise Exception("Internal error, cutvalue %f, hall.GetBinCenter(bin) %f" % (cutvalue, hall.GetBinCenter(bin)))
    return (all, passed, cutvalue)
Пример #2
0
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")
Пример #3
0
def getFromPF(dataset, pathAll, pathPassed, bin):
    hall = histograms.dist2pass(
        dataset.getDatasetRootHisto(pathAll).getHistogram(), greaterThan=True)
    hpassed = histograms.dist2pass(
        dataset.getDatasetRootHisto(pathPassed).getHistogram(),
        greaterThan=True)
    all = hall.GetBinContent(bin)
    passed = hpassed.GetBinContent(bin)
    cutvalue = hpassed.GetBinCenter(bin)
    if abs(cutvalue - hall.GetBinCenter(bin)) > 1e-4:
        raise Exception(
            "Internal error, cutvalue %f, hall.GetBinCenter(bin) %f" %
            (cutvalue, hall.GetBinCenter(bin)))
    return (all, passed, cutvalue)
Пример #4
0
def getHistogram(dataset, histoname, isRef):
    roothisto = dataset.getDatasetRootHisto(histoname[0])
    roothisto.normalizeToOne()
    h = roothisto.getHistogram()
    # Rebin
    a = (h.GetXaxis().GetXmax() - h.GetXaxis().GetXmin()) / h.GetNbinsX()
    if histoname[1] > a:
        h.Rebin(int(histoname[1] / a))
    # Set attributes
    h.SetStats(1)
    if isRef:
        h.SetName("Reference")
        h.SetFillStyle(1001)
        h.SetFillColor(ROOT.kBlue-6)
        h.SetLineColor(ROOT.kBlue-6)
        #statbox.SetTextColor(ROOT.kBlue-6)
    else:
        h.SetName("New")
        h.SetMarkerColor(ROOT.kBlack)
        h.SetLineColor(ROOT.kBlack)
        h.SetMarkerStyle(20)
        h.SetMarkerSize(1.0)
        #statbox.SetTextColor(ROOT.kBlack)

#p1->SetX1NDC(xmin);
#p1->SetX2NDC(xmax);
#p1->SetY1NDC(ymin);
#p1->SetY2NDC(ymax);
    return h
Пример #5
0
def getFromCalo(dataset, path, bin):
    hpass = histograms.dist2pass(
        dataset.getDatasetRootHisto(path).getHistogram(), greaterThan=True)
    all = hpass.GetBinContent(1)
    passed = hpass.GetBinContent(bin)
    cutvalue = hpass.GetBinCenter(bin)
    return (all, passed, cutvalue)
Пример #6
0
def getHistogram(dataset, histoname, isRef):
    roothisto = dataset.getDatasetRootHisto(histoname[0])
    roothisto.normalizeToOne()
    h = roothisto.getHistogram()
    # Rebin
    a = (h.GetXaxis().GetXmax() - h.GetXaxis().GetXmin()) / h.GetNbinsX()
    if histoname[1] > a:
        h.Rebin(int(histoname[1] / a))
    # Set attributes
    h.SetStats(1)
    if isRef:
        h.SetName("Reference")
        h.SetFillStyle(1001)
        h.SetFillColor(ROOT.kBlue - 6)
        h.SetLineColor(ROOT.kBlue - 6)
        #statbox.SetTextColor(ROOT.kBlue-6)
    else:
        h.SetName("New")
        h.SetMarkerColor(ROOT.kBlack)
        h.SetLineColor(ROOT.kBlack)
        h.SetMarkerStyle(20)
        h.SetMarkerSize(1.0)
        #statbox.SetTextColor(ROOT.kBlack)


#p1->SetX1NDC(xmin);
#p1->SetX2NDC(xmax);
#p1->SetY1NDC(ymin);
#p1->SetY2NDC(ymax);
    return h
Пример #7
0
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")
Пример #8
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)
Пример #9
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("Data / MC")
        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)
Пример #10
0
def getFromCalo(dataset, path, bin):
    hpass = histograms.dist2pass(dataset.getDatasetRootHisto(path).getHistogram(), greaterThan=True)
    all = hpass.GetBinContent(1)
    passed = hpass.GetBinContent(bin)
    cutvalue = hpass.GetBinCenter(bin)
    return (all, passed, cutvalue)