Exemplo n.º 1
0
def plot(values, suffix=None):
    canvas = ROOT.TCanvas("canvas", "canvas", 800, 600)
    axes = canvas.DrawFrame(-1.55, -0.6, 1.15, 2.6)
    axes.GetXaxis().SetTitle("#eta#alpha")
    axes.GetYaxis().SetTitle("response")
    axes.GetYaxis().SetTitleOffset(1.2)

    PyROOTUtils.DrawText(0.2,
                         0.87,
                         "InterpCode = " + str(options.interpcode),
                         textSize=0.03)
    leg = PyROOTUtils.Legend(0.2, 0.83, textSize=0.03)

    for etaData in values:
        eta = etaData['eta']
        data = etaData['data']

        g = PyROOTUtils.Graph(data)
        container.append(g)

        gDerivative = PyROOTUtils.Graph(g.derivativeData(),
                                        lineStyle=ROOT.kDashed)
        container.append(gDerivative)

        gDerivative2 = PyROOTUtils.Graph(g.derivative2Data(),
                                         lineStyle=ROOT.kDotted)
        if 'secondDerivative' in etaData:
            gDerivative2 = PyROOTUtils.Graph(etaData['secondDerivative'],
                                             lineStyle=ROOT.kDotted)
        gDerivative2.transformY(lambda y: y / 10.0)
        container.append(gDerivative2)

        infoStr = "#eta = " + str(eta) + "  "
        if 'slopeAtZero' in etaData:
            infoStr += "\nslope(0) = %.2f  " % (etaData['slopeAtZero'])
        t = PyROOTUtils.DrawText(data[0][0],
                                 data[0][1],
                                 infoStr,
                                 textSize=0.025,
                                 halign="right",
                                 valign="center",
                                 NDC=False)
        container.append(t)

        g.Draw("L")
        gDerivative.Draw("L")
        gDerivative2.Draw("L")

    leg.AddEntry(g, "f(#eta#alpha)", "L")
    leg.AddEntry(gDerivative, "f'(#eta#alpha)", "L")
    leg.AddEntry(gDerivative2, "1/10 f''(#eta#alpha)", "L")
    leg.Draw()

    outFileName = options.output
    if suffix: outFileName = outFileName.replace(".eps", suffix + ".eps")
    canvas.SaveAs(outFileName)
Exemplo n.º 2
0
def profiledContourOverlay(opts={}):
    if 'box' not in opts:
        fullFile = "output/twoBin/" + opts['type'] + "/muTmuW.root"
    else:
        fullFile = "output/twoBin/" + opts['type'] + "_box/muTmuW.root"
    effFile = "output/twoBin/" + opts['type'] + "/muTmuW_eff.root"
    learningSuffix = ''
    if 'learningFull' in opts: learningSuffix = 'Full'

    profiledFiles = [
        ('aligned', "output/twoBin/" + opts['type'] +
         "/muTmuW_profiledContour_template0.root", ROOT.kRed, ROOT.kSolid),
        ('learning', "output/twoBin/" + opts['type'] +
         "/muTmuW_profiledContour_template20_etasgeneric20_learning" +
         learningSuffix + ".root", ROOT.kBlue, 5),
    ]
    if 'byHand' in opts:
        profiledFiles.insert(
            1, ('by hand', "output/twoBin/" + opts['type'] +
                "/muTmuW_profiledContour_template10_etasgeneric_M5.root",
                ROOT.kGreen + 2, ROOT.kDashed))
    if 'box' in opts:
        profiledFiles = [(n, f.replace('.root', '_box1.0.root'), c, s)
                         for n, f, c, s in profiledFiles]

    PyROOTUtils.DrawText(0.22, 0.88, "Recoupled contours", textSize=0.03)
    leg2 = PyROOTUtils.Legend(0.22, 0.86, textSize=0.03)

    for label, fileName, color, lineStyle in profiledFiles:
        c68_p = drawContours(fileName,
                             "muTmuW",
                             color=color,
                             lineStyle=lineStyle)
        if c68_p: leg2.AddEntry(c68_p[0], label, "L")
    leg2.Draw()

    PyROOTUtils.DrawText(0.66, 0.88, "68% CL contours", textSize=0.03)
    leg = PyROOTUtils.Legend(0.65, 0.86, textSize=0.03)
    leg.AddEntry(SMMarker, "Standard Model", "P")

    c68 = drawContours(fullFile,
                       "profiledNLL",
                       scale=2.0,
                       color=ROOT.kBlack,
                       lineStyle=ROOT.kDashed,
                       lineWidth=3)
    c68_f = drawContours(effFile,
                         "profiledNLL",
                         scale=2.0,
                         color=ROOT.kBlack,
                         lineStyle=ROOT.kDotted)

    if c68: leg.AddEntry(c68[0], "full model", "L")
    if c68_f: leg.AddEntry(c68_f[0], "fixed effective", "L")
    leg.Draw()
Exemplo n.º 3
0
def countingMuTMuWArrowsAtMuHat(opts):
    modelSuffix = ''
    if 'interpCode0' in opts: modelSuffix = '_interpCode0'

    arrows = []
    for c in ['2ph', '4l', 'lvlv']:
        try:
            with open(
                    "output/atlas_counting/" + c + modelSuffix +
                    "/table_etas.pickle", "rb") as f:
                etasAll = pickle.load(f)
                muHat = {
                    'muT':
                    etasAll['generic20_learning'].values()[0]['muT__hat'],
                    'muW':
                    etasAll['generic20_learning'].values()[0]['muW__hat'],
                }
                arrows = etas.drawArrows('fisherInfo',
                                         etasAll['fisherInfo'],
                                         muHat,
                                         lineWidth=2.0)
                container.append(arrows)
                label = PyROOTUtils.DrawText(
                    muHat['muT'],
                    muHat['muW'],
                    {
                        '2ph': 'H#rightarrow#gamma#gamma  ',
                        '4l': 'H#rightarrowZZ*#rightarrow4l  ',
                        'lvlv': 'H#rightarrowWW*#rightarrowl#nul#nu  ',
                    }[c],
                    textSize=0.03,
                    halign="right",
                    valign="top",
                    NDC=False)
                container.append(label)
        except IOError:
            print("WARNING: Could not open:")
            print("output/atlas_counting/" + c + modelSuffix +
                  "/table_etas.pickle")
        except:
            print("ERROR!!!!!!!!!!!!")

    leg = PyROOTUtils.Legend(0.2, 0.9, textSize=0.03)
    for a, p in arrows:
        leg.AddEntry(a, p.replace("alpha_", ""), "L")
    leg.Draw()
Exemplo n.º 4
0
def content(mHBestFit=130.0, height1SigmaLabel=10.0, color=ROOT.kBlue):
    # make mock curve
    linSpace = [100 + i * 60.0 / 300.0 for i in range(300)]
    likelihood = [(x, (x - mHBestFit) * (x - mHBestFit) / 25.0)
                  for x in linSpace]
    likelihood_statOnly = [(x, (x - mHBestFit) * (x - mHBestFit) / 20.0)
                           for x in linSpace]
    # draw curve
    g = PyROOTUtils.Graph(likelihood, lineColor=color, lineWidth=2)
    g.Draw()
    g_statOnly = PyROOTUtils.Graph(likelihood_statOnly,
                                   lineColor=color,
                                   lineWidth=2,
                                   lineStyle=ROOT.kDashed)
    g_statOnly.Draw()

    # find 68% CL interval from likelihood
    low, high = g.getFirstIntersectionsWithValue(1.0)
    vLineM1Sigma = PyROOTUtils.DrawVLine(low,
                                         lineStyle=ROOT.kDashed,
                                         lineWidth=1,
                                         lineColor=color)
    vLineP1Sigma = PyROOTUtils.DrawVLine(high,
                                         lineStyle=ROOT.kDashed,
                                         lineWidth=1,
                                         lineColor=color)
    hLine1Sigma = PyROOTUtils.DrawLine(low,
                                       height1SigmaLabel,
                                       high,
                                       height1SigmaLabel,
                                       lineWidth=5,
                                       lineColor=color)
    label1Sigma = PyROOTUtils.DrawText(
        mHBestFit,
        height1SigmaLabel, ("#lower[-0.5]{%.1f^{%+.1f}_{%+.1f} GeV}" %
                            (mHBestFit, high - mHBestFit, low - mHBestFit)),
        NDC=False,
        textSize=0.025,
        halign="center",
        valign="bottom",
        textColor=color)

    container.append(
        (g, g_statOnly, vLineM1Sigma, vLineP1Sigma, hLine1Sigma, label1Sigma))

    return (g, g_statOnly)
Exemplo n.º 5
0
def profiledContour(opts={}):
    if opts["type"] == "oneAlpha_catUniversal":
        modelType = "oneAlpha_catUniversal"
        color = ROOT.kRed - 3
    elif opts["type"] == "oneAlpha_catNonUniversal":
        modelType = "oneAlpha_catNonUniversal"
        color = ROOT.kGreen - 2
    elif opts["type"] == "twoAlpha_catUniversal":
        modelType = "twoAlpha_catUniversal"
        color = ROOT.kOrange - 3
    elif opts["type"] == "twoAlpha_catNonUniversal":
        modelType = "twoAlpha_catNonUniversal"
        color = ROOT.kBlue

    elif opts["type"] == "oneAlpha_catUniversal_interpCode0":
        modelType = "oneAlpha_catUniversal_interpCode0"
        color = ROOT.kRed - 3
    elif opts["type"] == "oneAlpha_catNonUniversal_interpCode0":
        modelType = "oneAlpha_catNonUniversal_interpCode0"
        color = ROOT.kGreen - 2
    elif opts["type"] == "twoAlpha_catUniversal_interpCode0":
        modelType = "twoAlpha_catUniversal_interpCode0"
        color = ROOT.kOrange - 3
    elif opts["type"] == "twoAlpha_catNonUniversal_interpCode0":
        modelType = "twoAlpha_catNonUniversal_interpCode0"
        color = ROOT.kBlue

    elif opts["type"] == "scenarioA":
        modelType = "scenarioA"
        color = ROOT.kRed - 3
    elif opts["type"] == "scenarioA2":
        modelType = "scenarioA2"
        color = ROOT.kRed - 3
    elif opts["type"] == "scenarioB":
        modelType = "scenarioB"
        color = ROOT.kGreen - 2
    elif opts["type"] == "scenarioC":
        modelType = "scenarioC"
        color = ROOT.kBlue
    elif opts["type"] == "scenarioC2":
        modelType = "scenarioC2"
        color = ROOT.kBlue
    elif opts["type"] == "scenarioD":
        modelType = "scenarioD"
        color = ROOT.kGreen

    elif opts["type"] == "scenarioA_interpCode0":
        modelType = "scenarioA_interpCode0"
        color = ROOT.kRed - 3
    elif opts["type"] == "scenarioA2_interpCode0":
        modelType = "scenarioA2_interpCode0"
        color = ROOT.kRed - 3
    elif opts["type"] == "scenarioB_interpCode0":
        modelType = "scenarioB_interpCode0"
        color = ROOT.kGreen - 2
    elif opts["type"] == "scenarioC_interpCode0":
        modelType = "scenarioC_interpCode0"
        color = ROOT.kBlue
    elif opts["type"] == "scenarioC2_interpCode0":
        modelType = "scenarioC2_interpCode0"
        color = ROOT.kBlue
    elif opts["type"] == "scenarioD_interpCode0":
        modelType = "scenarioD_interpCode0"
        color = ROOT.kGreen

    effFile = "output/twoBin/" + modelType + "/muTmuW_eff.root"
    if "template0" in opts:
        inFile = "output/twoBin/" + modelType + "_interpCode0/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template0.root"
    elif "templateM1" in opts:
        inFile = "output/twoBin/" + modelType + "_additiveMu_interpCode0/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_templateM1.root"
    elif "template14_etasgeneric_M4" in opts:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric_M4.root"
    elif "template14_etasgeneric_M5" in opts:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric_M5.root"
    elif "template14_etasgeneric_fisherInfo" in opts:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric_fisherInfo.root"

    elif "template10_etasgeneric10_learning" in opts:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template10_etasgeneric10_learning.root"
    elif "template14_etasgeneric14_learning" in opts:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template14_etasgeneric14_learning.root"
    elif "template20_etasgeneric20_learning" in opts:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template20_etasgeneric20_learning.root"
    elif "template24_etasgeneric24_learning" in opts:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template24_etasgeneric24_learning.root"

    elif "template20_etasgeneric20_learning_box1.0" in opts:
        inFile = "output/twoBin/" + modelType + "_box/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour_template20_etasgeneric20_learning_box1.0.root"

    else:
        inFile = "output/twoBin/" + modelType + "/muTmuW.root"
        profiledFile = "output/twoBin/" + modelType + "/muTmuW_profiledContour.root"

    c68 = drawContours(inFile, "profiledNLL", scale=2.0, color=color)
    c68_f = drawContours(effFile,
                         "profiledNLL",
                         scale=2.0,
                         color=color,
                         lineStyle=ROOT.kDashed)
    c68_p = drawContours(profiledFile,
                         "muTmuW",
                         color=ROOT.kGray + 2,
                         lineStyle=ROOT.kDotted)
    container.append((c68, c68_f, c68_p))

    PyROOTUtils.DrawText(0.66, 0.88, "68% CL contours", textSize=0.03)
    leg2 = PyROOTUtils.Legend(0.65, 0.85, textSize=0.03)
    leg2.AddEntry(SMMarker, "Standard Model", "P")
    if c68: leg2.AddEntry(c68[0], "full model", "L")
    if c68_f: leg2.AddEntry(c68_f[0], "fixed effective", "L")
    if c68_p: leg2.AddEntry(c68_p[0], "profiled effective", "L")
    leg2.Draw()
Exemplo n.º 6
0
def drawAllArrows(allEtas, cut=0.03, detailed=False):
    for etasName, etas in allEtas.iteritems():
        canvas = ROOT.TCanvas("c1", "c1", 600, 600)

        if detailed: axes = canvas.DrawFrame(0.48, 0.48, 1.62, 1.82)
        else: axes = canvas.DrawFrame(0.58, 0.58, 1.42, 1.42)
        axes.GetXaxis().SetTitle("#mu^{f}_{ggF+ttH}")
        axes.GetYaxis().SetTitle("#mu^{f}_{VBF+VH}")
        #axes.GetYaxis().SetTitleOffset( 1.2 )

        template = 0
        if 'generic' in etasName: template = 10
        if 'generic10' in etasName: template = 10
        if 'generic14' in etasName: template = 14
        if 'generic20' in etasName: template = 20
        if 'generic24' in etasName: template = 24
        print("For " + etasName + " chose template " + str(template) + ".")

        scanPoints = [{'muT': 1.0, 'muW': 1.0}]
        npVals = [(1.0, 3.0)]  # nuis par values and line widths
        if detailed:
            scanPoints = [{
                'muT': 1.0,
                'muW': 1.0
            }, {
                'muT': 1.3,
                'muW': 1.0
            }, {
                'muT': 1.0,
                'muW': 1.3
            }]
            npVals = [(-1.0, 1.5), (1.0, 2.5)]
        for muIn in scanPoints:
            for npVal, lineWidth in npVals:
                arrows = drawArrows(etas,
                                    muIn,
                                    npVal,
                                    lineWidth,
                                    cut,
                                    template=template)
                container.append(arrows)

        leg = PyROOTUtils.Legend(0.2, 0.85, textSize=0.035)
        for a, p in arrows:
            leg.AddEntry(a, parameterNames[p.replace("alpha_", "")], "L")
        leg.Draw()

        if cut > 0.0:
            PyROOTUtils.DrawText(0.2,
                                 0.88,
                                 "showing only |#eta| > %.0f%%" %
                                 (cut * 100.0),
                                 textSize=0.035)
        if detailed:
            PyROOTUtils.DrawText(
                0.2,
                0.25,
                "positive variation thick\nnegative variation thin",
                textSize=0.035)

        if detailed: canvas.SaveAs(options.output + etasName + "_detailed.eps")
        else: canvas.SaveAs(options.output + etasName + ".eps")