Example #1
0
def bestFitContents(label=""):
    hVal = oneHisto(label=label,   hName="T2cc_poiVal")
    hErr = oneHisto(label=label,   hName="T2cc_poiErr")
    hSigma0 = oneHisto(label=label, hName="T2cc_nSigma_s0_sHat")
    if mode == "bestFit_binaryExcl":
        hSigma1 = oneHisto(label=label, hName="T2cc_nSigma_sNom_sHat")
    else:
        hSigma1 = None

    out = []
    if not all([hVal, hErr, hSigma0]):
        return out

    for (iBinX, x, iBinY, y, iBinZ, z) in utils.bins(hVal, interBin="LowEdge"):
        if iBinZ != 1:
            continue

        t = (iBinX, iBinY, iBinZ)
        val = hVal.GetBinContent(*t)
        err = hErr.GetBinContent(*t)
        n0 = hSigma0.GetBinContent(*t)
        n1 = hSigma1.GetBinContent(*t) if hSigma1 else None
        if val == 0.0 and err == 0.0:
            continue
        label = "%3d %3d" % (x, y)
        out.append((x, label, val, err, n0, n1))
    return out
Example #2
0
def xsHistoAllOne(model=None, cutFunc=None):
    spec = configuration.signal.effHistoSpec(model=model, **model.exampleKargs)
    h = smsEffHisto(spec=spec, model=model)
    for iX, x, iY, y, iZ, z in utils.bins(h, interBin=model.interBin):
        content = 1.0
        if cutFunc and not cutFunc(iX, x, iY, y, iZ, z):
            content = 0.0
        h.SetBinContent(iX, iY, iZ, content)
    return h
Example #3
0
def xsHistoAllOne(model=None, cutFunc=None):
    spec = configuration.signal.effHistoSpec(model=model, **model.exampleKargs)
    h = smsEffHisto(spec=spec, model=model)
    for iX, x, iY, y, iZ, z in utils.bins(h, interBin=model.interBin):
        content = 1.0
        if cutFunc and not cutFunc(iX, x, iY, y, iZ, z):
            content = 0.0
        h.SetBinContent(iX, iY, iZ, content)
    return h
Example #4
0
def printHoles(h):
    for iBinX, x, iBinY, y, iBinZ, z in utils.bins(h, interBin="Center"):
        xNeighbors = h.GetBinContent(iBinX + 1, iBinY, iBinZ)
        xNeighbors *= h.GetBinContent(iBinX - 1, iBinY, iBinZ)
        yNeighbors = h.GetBinContent(iBinX, iBinY + 1, iBinZ)
        yNeighbors *= h.GetBinContent(iBinX, iBinY - 1, iBinZ)
        empty = h.GetBinContent(iBinX, iBinY, iBinZ) == 0.0
        if empty and (xNeighbors or yNeighbors):
            print "WARNING: found hole (%d, %d, %d) = (%g, %g, %g)" % (
                iBinX, iBinY, iBinZ, x, y, z)
    return
Example #5
0
def printHoles(h):
    for iBinX, x, iBinY, y, iBinZ, z in utils.bins(h, interBin="Center"):
        xNeighbors = h.GetBinContent(iBinX+1, iBinY,   iBinZ)
        xNeighbors *= h.GetBinContent(iBinX-1, iBinY,   iBinZ)
        yNeighbors = h.GetBinContent(iBinX,   iBinY+1, iBinZ)
        yNeighbors *= h.GetBinContent(iBinX,   iBinY-1, iBinZ)
        empty = h.GetBinContent(iBinX, iBinY, iBinZ) == 0.0
        if empty and (xNeighbors or yNeighbors):
            print "WARNING: found hole (%d, %d, %d) = (%g, %g, %g)" % (iBinX,
                                                                       iBinY,
                                                                       iBinZ,
                                                                       x, y, z)
    return
Example #6
0
def points(respectWhiteList=False):
    out = []
    multiples = configuration.limit.multiplesInGeV()

    for model in configuration.signal.models():
        name = model.name
        whiteList = configuration.signal.whiteListOfPoints(name, respect=respectWhiteList)
        h = sumWeightInHisto(model)
        bins = utils.bins(h, interBin=model.interBin)
        for iBinX, x, iBinY, y, iBinZ, z in bins:
            if whiteList and (x, y) not in whiteList:
                continue
            content = h.GetBinContent(iBinX, iBinY, iBinZ)
            if not model.sumWeightInRange(content):
                continue
            if multiples and ((x/multiples) % 1 != 0.0):
                continue
            if patches.cutFunc()[name](iBinX, x, iBinY, y, iBinZ, z):
                out.append((name, iBinX, iBinY, iBinZ))
    return out
Example #7
0
def points(respectWhiteList=False):
    out = []
    multiples = configuration.limit.multiplesInGeV()

    for model in configuration.signal.models():
        name = model.name
        whiteList = configuration.signal.whiteListOfPoints(
            name, respect=respectWhiteList)
        h = sumWeightInHisto(model)
        bins = utils.bins(h, interBin=model.interBin)
        for iBinX, x, iBinY, y, iBinZ, z in bins:
            if whiteList and (x, y) not in whiteList:
                continue
            content = h.GetBinContent(iBinX, iBinY, iBinZ)
            if not model.sumWeightInRange(content):
                continue
            if multiples and ((x / multiples) % 1 != 0.0):
                continue
            if patches.cutFunc()[name](iBinX, x, iBinY, y, iBinZ, z):
                out.append((name, iBinX, iBinY, iBinZ))
    return out
Example #8
0
def clbContents(label=""):
    hClb = oneHisto(label=label,   hName="T2cc_CLb")
    hCls = oneHisto(label=label,   hName="T2cc_CLs")
    hClsb = oneHisto(label=label,  hName="T2cc_CLs+b")

    out = []
    if not all([hClb, hCls]):
        return out

    for (iBinX, x, iBinY, y, iBinZ, z) in utils.bins(hClb, interBin="LowEdge"):
        if iBinZ != 1:
            continue

        t = (iBinX, iBinY, iBinZ)
        clb = hClb.GetBinContent(*t)
        cls = hCls.GetBinContent(*t)
        clsb = hClsb.GetBinContent(*t)
        if clb == 0.0:
            continue
        label = "%3d %3d" % (x, y)
        out.append((x, label, clb, cls, clsb))
    return out
Example #9
0
def xsHistoPhysical(model=None, cmssmProcess=""):
    #get example histo and reset
    dummyHisto = model.weightedHistName
    s = configuration.signal.effHistoSpec(model=model, box="had")
    out = ratio(s["file"],
                s["beforeDir"], dummyHisto,
                s["beforeDir"], dummyHisto)
    out.Reset()

    spec = configuration.signal.xsHistoSpec(model=model, cmssmProcess=cmssmProcess)

    h = oneHisto(spec["file"], "/", spec["histo"])
    assert h.ClassName()[:2] == "TH", h.ClassName()
    dim = int(h.ClassName()[2:3])
    assert dim in [1, 2], dim

    for iX, x, iY, y, iZ, z in utils.bins(out, interBin=model.interBin):
        iBin = h.FindBin(x) if dim == 1 else h.FindBin(x, y)
        out.SetBinContent(iX, iY, iZ, h.GetBinContent(iBin))

    assert len(model.xsFactors) == 1, model.xsFactors
    out.Scale(model.xsFactors[0])

    return out
Example #10
0
def xsHistoPhysical(model=None, cmssmProcess=""):
    #get example histo and reset
    dummyHisto = model.weightedHistName
    s = configuration.signal.effHistoSpec(model=model, box="had")
    out = ratio(s["file"], s["beforeDir"], dummyHisto, s["beforeDir"],
                dummyHisto)
    out.Reset()

    spec = configuration.signal.xsHistoSpec(model=model,
                                            cmssmProcess=cmssmProcess)

    h = oneHisto(spec["file"], "/", spec["histo"])
    assert h.ClassName()[:2] == "TH", h.ClassName()
    dim = int(h.ClassName()[2:3])
    assert dim in [1, 2], dim

    for iX, x, iY, y, iZ, z in utils.bins(out, interBin=model.interBin):
        iBin = h.FindBin(x) if dim == 1 else h.FindBin(x, y)
        out.SetBinContent(iX, iY, iZ, h.GetBinContent(iBin))

    assert len(model.xsFactors) == 1, model.xsFactors
    out.Scale(model.xsFactors[0])

    return out
Example #11
0
def nllsValidation(model=None, divide=(4, 3), stampTitle=True):
    def name(s=""):
        return "%s_%s" % (model.name, s)

    histos = allHistos(fileName=configuration.limit.mergedFile(model=model), collapse=True)
    xs = histos.get(name("xs"))
    assert xs, "xs not found.  Available keys: %s" % str(histos.keys())

    graphs = {}
    for (iBinX, x, iBinY, y, iBinZ, z) in utils.bins(xs, interBin="LowEdge"):
        if any([iBinZ != 1, not xs.GetBinContent(iBinX, iBinY)]):
            continue

        graphName = name("%d_%d" % (iBinX, iBinY))
        zTitle = "%d_%d: (%g, %g)" % (iBinX, iBinY, x, y)
        graph = r.TGraphErrors()
        graph.SetName(graphName)
        graph.SetTitle("%s;#sigma (pb);delta NLL" % (zTitle if stampTitle else ""))
        graph.SetMarkerStyle(20)
        graph.SetMarkerSize(0.5)
        graph.SetMinimum(0.0)
        #graph.SetMaximum(20.0)

        y0 = histos[name("nll_sHat")].GetBinContent(iBinX, iBinY)
        fHat = histos[name("poiVal")].GetBinContent(iBinX, iBinY)
        values = [(fHat, y0)]
        values.append((0.0, histos[name("nll_s0")].GetBinContent(iBinX, iBinY)))

        xsVal = xs.GetBinContent(iBinX, iBinY)
        if name("nll_sNom") in histos:
            fNom = histos[name("poiNom")].GetBinContent(iBinX, iBinY)
            values.append((fNom, histos[name("nll_sNom")].GetBinContent(iBinX, iBinY)))
            ys = [x[1]-y0 for x in values]
            xLine = fNom * xsVal
            line = r.TLine(xLine, min(ys), xLine, max(ys))
            line.SetLineColor(r.kCyan)
        else:
            line = None

        for key in filter(lambda x: x.startswith(name("nll_sHat_")), histos.keys()):
            x = float(key[-4:]) * fHat
            y = histos[key].GetBinContent(iBinX, iBinY)
            values.append((x, y))

        for iPoint, (x, y) in enumerate(sorted(values)):
            graph.SetPoint(iPoint, x * xsVal, y - y0)

        graphs[graphName] = [graph, line] if line else graph

    fileName = outFileName(model=model, tag="nllsValidation")["pdf"]

    canvas = utils.numberedCanvas()
    canvas.Print(fileName+"[")
    text1 = printTimeStamp()
    text2 = printLumis()
    canvas.Print(fileName)
    canvas.Clear()

    canvas.SetRightMargin(0.15)
    goptions = "ap"
    if line:
        goptions += "l"
    utils.cyclePlot(d=graphs, f=None, args={}, optStat=1110, canvas=canvas,
                    fileName=fileName, divide=divide, goptions=goptions)

    canvas.Print(fileName+"]")
    print "%s has been written." % fileName
Example #12
0
def clsValidation(model=None, cl=None, filterKey="CLb", plotKey="",
                  yMin=0.0, yMax=1.0, lineHeight=0.5,
                  divide=(4, 3), whiteList=[], stampTitle=True):

    def name(s=""):
        #return s
        return "%s_%s" % (model.name, s)

    assert plotKey
    assert filterKey
    filterKey = name(filterKey)
    assert cl
    if whiteList:
        assert len(whiteList) == divide[0]*divide[1], "%d != %d" % (len(whiteList), divide[0]*divide[1])

    histos = allHistos(fileName=configuration.limit.mergedFile(model=model), collapse=True)
    xs = histos.get(name("xs"))
    assert xs, "xs not found.  Available keys: %s" % str(histos.keys())

    graphs = {}
    for (iBinX, x, iBinY, y, iBinZ, z) in utils.bins(xs, interBin="LowEdge"):
        if any([iBinZ != 1,
                whiteList and (iBinX, iBinY) not in whiteList,
                not xs.GetBinContent(iBinX, iBinY),
                not histos.get(filterKey),
                ]) or not histos[filterKey].GetBinContent(iBinX, iBinY):
            continue

        graphName = name("%s_%d_%d" % (plotKey, iBinX, iBinY))
        zTitle = "%d_%d: (%g, %g)" % (iBinX, iBinY, x, y)
        graph = r.TGraphErrors()
        graph.SetName(graphName)
        graph.SetTitle("%s;#sigma (pb);%s" % (zTitle if stampTitle else "", plotKey))
        graph.SetMarkerStyle(20)
        graph.SetMarkerSize(0.5)
        graph.SetMinimum(yMin)
        graph.SetMaximum(yMax)
        iPoint = 0

        while True:
            s = "" if not iPoint else "_%d" % iPoint
            key = name("%s%s" % (plotKey, s))
            keyErr = key.replace(plotKey, plotKey+"Error")
            if key not in histos:
                break
            x = histos[name("PoiValue%s" % s)].GetBinContent(iBinX, iBinY)
            x *= xs.GetBinContent(iBinX, iBinY)
            if not iPoint:
                xMin = x
            xMax = x
            graph.SetPoint(iPoint, x, histos[key].GetBinContent(iBinX, iBinY))
            if keyErr in histos:
                graph.SetPointError(iPoint, 0.0, histos[keyErr].GetBinContent(iBinX, iBinY))
            iPoint += 1

        e = 0.1*(xMax-xMin)
        y = 1.0 - cl
        clLine = r.TLine(xMin-e, y, xMax+e, y)
        clLine.SetLineColor(r.kRed)
        graphs[graphName] = [graph, clLine]

        ulhisto = histos.get(name("UpperLimit"))
        if ulhisto:
            xLim = ulhisto.GetBinContent(iBinX, iBinY)
            limLine = r.TLine(xLim, yMin, xLim, yMax*lineHeight)
            limLine.SetLineColor(r.kBlue)
            graphs[graphName].append(limLine)

        plhisto = histos.get(name("PlUpperLimit"))
        if plhisto and not whiteList:
            xLimPl = plhisto.GetBinContent(iBinX, iBinY)
            plLimLine = r.TLine(xLimPl, yMin, xLimPl, yMax*lineHeight)
            plLimLine.SetLineColor(r.kGreen)
            graphs[graphName].append(plLimLine)

    tag = "%sValidation_%s" % (plotKey, str(cl).replace("0.", ""))
    fileName = outFileName(model=model, tag=tag)["pdf"]

    if whiteList:
        fileName = fileName.replace(".pdf", ".eps")
        canvas = r.TCanvas("canvas", "", 500*divide[0], 500*divide[1])
    else:
        canvas = utils.numberedCanvas()
        canvas.Print(fileName+"[")
        text1 = printTimeStamp()
        text2 = printLumis()
        canvas.Print(fileName)
        canvas.Clear()

    canvas.SetRightMargin(0.15)
    utils.cyclePlot(d=graphs, f=None, args={}, optStat=1110, canvas=canvas,
                    fileName=fileName, divide=divide, goptions="alp")

    if whiteList:
        utils.epsToPdf(fileName, sameDir=True)
        print "%s has been written." % fileName.replace(".eps", ".pdf")
    else:
        canvas.Print(fileName+"]")
        print "%s has been written." % fileName
Example #13
0
    for bkey in bulk_file.GetListOfKeys():
        hname = bkey.GetName()
        print "Processing", hname
        bobj = bulk_file.Get(hname)
        sobj = slice_file.Get(hname)

        if bobj.ClassName()[0:2] == "TH":

            bobj = utils.threeToTwo(bobj)
            sobj = utils.threeToTwo(sobj)

            combined.append(r.TH2D(hname,'',nbinsx,x_range[0],x_range[1],
                nbinsy, y_range[0], y_range[1]))

            # [ (iBinX, x, iBinY, Y, iBinZ, Z), ... ]
            cbins = utils.bins(combined[-1])
            for cbin in cbins:
                iX, x, iY, y, iZ, z = cbin
                if y >= 50:
                    hist_to_use = bobj
                else:
                    hist_to_use = sobj
                content = hist_to_use.GetBinContent(hist_to_use.FindBin(x,y))
                combined[-1].SetBinContent(iX,iY,content)
            combined[-1].Draw('colz')
            canvas.Print(out_dir+rfile.replace('root','pdf'))
            combined[-1].Write()

    canvas.Print(out_dir+rfile.replace('root','pdf]'))
    out_file.Close()
Example #14
0
def killPoints(h, cutFunc=None, interBin=""):
    for iBinX, x, iBinY, y, iBinZ, z in utils.bins(h, interBin=interBin):
        if cutFunc and not cutFunc(iBinX, x, iBinY, y, iBinZ, z):
            h.SetBinContent(iBinX, iBinY, iBinZ, 0.0)
    return h
Example #15
0
def killPoints(h, cutFunc=None, interBin=""):
    for iBinX, x, iBinY, y, iBinZ, z in utils.bins(h, interBin=interBin):
        if cutFunc and not cutFunc(iBinX, x, iBinY, y, iBinZ, z):
            h.SetBinContent(iBinX, iBinY, iBinZ, 0.0)
    return h