def finalize(self):
        def setLabel(histo):
            name = histo.getName()
            scic_re = re.compile("Sc(?P<sig>\d+)(Ic(?P<iso>\d+))?")
            ic_re = re.compile("Ic(?P<iso>\d+)")
            for tauIso in ["VLoose", "Loose", "Medium", "Tight"]:
                if "IsoTau"+tauIso in name:
                    histo.setLegendLabel('Counting iso "'+tauIso+'"')
                    break
                if "IsoTauLike"+tauIso in name:
                    m = scic_re.search(name)
                    sc = "0.1"
                    ic = "0.5"
                    if m:
                        sc = m.group("sig").replace("0", "0.")
                        if m.group("iso"):
                            ic = m.group("iso").replace("0", "0.")
                    else:
                        m = ic_re.search(name)
                        if m:
                            ic = m.group("iso").replace("0", "0.")
                    label = 'Counting iso "'+tauIso + '" %s < DR < %s' % (sc, ic)
                    print label
                    histo.setLegendLabel(label)

        self.histoMgr.setHistoLegendLabelMany({
                "sumIsoRel": "Rel iso",
                "pfSumIsoRel": "PF rel iso",
                "sumIsoRelFull": "Rel iso",
                "pfSumIsoRelFull": "PF rel iso",
                })
        self.histoMgr.forEachHisto(setLabel)

        self.histoMgr.forEachHisto(styles.generator2(styles.StyleMarker(markerSize=1.5), plotStyles))
        self.defaultStyle()
예제 #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")
    def __init__(self, datasets, dname, names, labels):
        plots.PlotBase.__init__(self, [])

        self.name = dname
        self.ylabel = "Efficiency"

        for hname, label in zip(names, labels):
            dh = datasets.getDataset(dname).getDatasetRootHisto(hname)
            dh.normalizeByCrossSection()
            dh = dataset.DatasetRootHisto(muonAnalysis.dist2eff(dh.getHistogram()), dh.getDataset())
            dh.setName(label)
            self.histoMgr.append(dh)

        self.histoMgr.forEachHisto(styles.generator2(styles.StyleMarker(markerSize=1.5), plotStyles))
        self.histoMgr.setHistoLegendStyleAll("l")
예제 #4
0
    def __init__(self, datasets, dname, names, labels):
        plots.PlotBase.__init__(self, [])

        self.name = dname
        self.ylabel = "Efficiency"

        for hname, label in zip(names, labels):
            dh = datasets.getDataset(dname).getDatasetRootHisto(hname)
            dh.normalizeByCrossSection()
            dh = dataset.DatasetRootHisto(
                muonAnalysis.dist2eff(dh.getHistogram()), dh.getDataset())
            dh.setName(label)
            self.histoMgr.append(dh)

        self.histoMgr.forEachHisto(
            styles.generator2(styles.StyleMarker(markerSize=1.5), plotStyles))
        self.histoMgr.setHistoLegendStyleAll("l")
예제 #5
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")
예제 #6
0
    def finalize(self):
        def setLabel(histo):
            name = histo.getName()
            scic_re = re.compile("Sc(?P<sig>\d+)(Ic(?P<iso>\d+))?")
            ic_re = re.compile("Ic(?P<iso>\d+)")
            for tauIso in ["VLoose", "Loose", "Medium", "Tight"]:
                if "IsoTau" + tauIso in name:
                    histo.setLegendLabel('Counting iso "' + tauIso + '"')
                    break
                if "IsoTauLike" + tauIso in name:
                    m = scic_re.search(name)
                    sc = "0.1"
                    ic = "0.5"
                    if m:
                        sc = m.group("sig").replace("0", "0.")
                        if m.group("iso"):
                            ic = m.group("iso").replace("0", "0.")
                    else:
                        m = ic_re.search(name)
                        if m:
                            ic = m.group("iso").replace("0", "0.")
                    label = 'Counting iso "' + tauIso + '" %s < DR < %s' % (sc,
                                                                            ic)
                    print label
                    histo.setLegendLabel(label)

        self.histoMgr.setHistoLegendLabelMany({
            "sumIsoRel": "Rel iso",
            "pfSumIsoRel": "PF rel iso",
            "sumIsoRelFull": "Rel iso",
            "pfSumIsoRelFull": "PF rel iso",
        })
        self.histoMgr.forEachHisto(setLabel)

        self.histoMgr.forEachHisto(
            styles.generator2(styles.StyleMarker(markerSize=1.5), plotStyles))
        self.defaultStyle()
예제 #7
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)
예제 #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("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)