示例#1
0
def read(scan, param, files, chop, remove_near_min, rezero,
         remove_delta=None, improve=False, remove_dups=True):
    # print files
    goodfiles = [f for f in files if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    graph = plot.TGraphFromTree(
        limit, param, '2*%s' % DELTANLL, 'quantileExpected > -1.5')
    # print 'INPUT'
    # graph.Print()
    graph.SetName(scan)
    graph.Sort()
    if remove_dups:
        plot.RemoveGraphXDuplicates(graph)
    if remove_delta is not None:
        plot.RemoveSmallDelta(graph, remove_delta)
    plot.RemoveGraphYAbove(graph, chop)
    plot.ReZeroTGraph(graph, rezero)
    if remove_near_min is not None:
        plot.RemoveNearMin(graph, remove_near_min)
    if improve:
        global NAMECOUNTER
        spline = ROOT.TSpline3("spline3", graph)
        func = ROOT.TF1('splinefn' + str(NAMECOUNTER), partial(Eval, spline),
                        graph.GetX()[0], graph.GetX()[graph.GetN() - 1], 1)
        func.SetNpx(NPX)
        NAMECOUNTER += 1
        plot.ImproveMinimum(graph, func, True)
    # graph.Print()
    if FILTER is not None:
        plot.FilterGraph(graph, FILTER)
    if REMOVE_X_RANGES is not None:
        for remove_x in REMOVE_X_RANGES:
            plot.RemoveInXRange(graph, remove_x[0], remove_x[1])
    return graph
示例#2
0
def read(scan,
         param,
         files,
         chop,
         remove_near_min,
         rezero,
         remove_delta=None,
         improve=False):
    # print files
    goodfiles = [f for f in files if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    # require quantileExpected > -0.5 to avoid the final point which is always committed twice
    # (even if the fit fails)
    graph = plot.TGraphFromTree(limit, param, '2*deltaNLL',
                                'quantileExpected > -0.5')
    graph.SetName(scan)
    graph.Sort()
    plot.RemoveGraphXDuplicates(graph)
    if remove_delta is not None: plot.RemoveSmallDelta(graph, remove_delta)
    plot.RemoveGraphYAbove(graph, chop)
    plot.ReZeroTGraph(graph, rezero)
    if remove_near_min is not None: plot.RemoveNearMin(graph, remove_near_min)
    if improve:
        global NAMECOUNTER
        spline = ROOT.TSpline3("spline3", graph)
        func = ROOT.TF1('splinefn' + str(NAMECOUNTER), partial(Eval, spline),
                        graph.GetX()[0],
                        graph.GetX()[graph.GetN() - 1], 1)
        NAMECOUNTER += 1
        plot.ImproveMinimum(graph, func, True)
    # graph.Print()
    return graph
示例#3
0
def main(args):
    # Get tree with scan values from all input files
    limit = plot.MakeTChain(args.files, 'limit')

    # Write Tree entries in TGraph to get structure for likelihood database
    graph = plot.TGraph2DFromTree(
        limit, args.x_var, args.y_var, 'deltaNLL',
        'quantileExpected > -0.5 && deltaNLL < 1000')
    # 'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')

    # rezero the TGraph to have sensible values in the output file
    min_delta_nll = rezero_tgraph2d(graph)
    df = convert_graph_to_dataframe(graph)
    df.to_csv(args.output,
              sep=" ",
              float_format="%.6f",
              header=False,
              index=False,
              na_rep="NaN",
              columns=[args.x_var, args.y_var, "deltaNLL"])
    best = plot.TGraphFromTree(limit, args.x_var, args.y_var, 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best)
    # Write back a root TTree with the modified contents.
    outfile = ROOT.TFile(args.output.replace(".txt", ".root"), "recreate")
    tree = convert_dataframe_to_tree(df, best, offset=min_delta_nll)
    # Add the best fit values from the limit trees
    outfile.Write()
    return
示例#4
0
def ProcessEnvelopeNew(main, others, relax_safety=0, chop=-1.):
    print '[ProcessEnvelope] Will create envelope from %i other scans' % len(
        others)
    min_x = min([oth['graph'].GetX()[0] for oth in others])
    max_x = max(
        [oth['graph'].GetX()[oth['graph'].GetN() - 1] for oth in others])
    # print '(min_x,max_x) = (%f, %f)' % (min_x, max_x)
    npoints = 200
    step = (max_x - min_x) / float(npoints - 1)
    x = min_x
    xvals = []
    yvals = []
    for i in xrange(npoints):
        yset = []
        for oth in others:
            gr = oth['graph']
            if x >= gr.GetX()[0] and x <= (gr.GetX()[gr.GetN() - 1] + 1E-6):
                yset.append(oth['func'].Eval(x))
        # print 'At x=%f, possible y vals are %s' % (x, yset)
        if len(yset) > 0:
            xvals.append(x)
            yvals.append(min(yset))
        x = x + step

    gr = ROOT.TGraph()
    gr.Set(len(xvals))  # will not contain the best fit
    for i in xrange(gr.GetN()):
        gr.SetPoint(i, xvals[i], yvals[i])

    # print 'Envelope'
    # gr.Print()

    spline = ROOT.TSpline3("spline3", gr)
    global NAMECOUNTER
    func = ROOT.TF1('splinefn' + str(NAMECOUNTER), partial(Eval, spline),
                    gr.GetX()[0],
                    gr.GetX()[gr.GetN() - 1], 1)
    func.SetNpx(NPX)
    min_x, min_y = plot.ImproveMinimum(gr, func)
    gr.Set(len(xvals) + 1)
    gr.SetPoint(len(xvals), min_x, min_y)
    gr.Sort()

    for i in xrange(gr.GetN()):
        gr.GetY()[i] -= min_y
    if chop > 0:
        plot.RemoveGraphYAbove(gr, chop)

    for oth in others:
        for i in xrange(oth['graph'].GetN()):
            oth['graph'].GetY()[i] -= min_y
        if chop > 0:
            plot.RemoveGraphYAbove(oth['graph'], chop)
        # print 'OTHER'
        # oth['graph'].Print()

    plot.RemoveGraphXDuplicates(gr)
    return gr
示例#5
0
def read(scan, param, files, ycut):
    goodfiles = [f for f in files if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    graph = plot.TGraphFromTree(limit, param, '2*deltaNLL', 'quantileExpected > -1.5')
    graph.SetName(scan)
    graph.Sort()
    plot.RemoveGraphXDuplicates(graph)
    plot.RemoveGraphYAbove(graph, ycut)
    # graph.Print()
    return graph
示例#6
0
def ProcessEnvelope(main, others, relax_safety=0):
    '[ProcessEnvelope] Will create envelope from %i other scans' % len(others)
    vals = {}
    for oth in others:
        gr = oth['graph']
        # gr.Print()
        for i in xrange(gr.GetN()):
            x = gr.GetX()[i]
            y = gr.GetY()[i]
            if x not in vals:
                vals[x] = []
            vals[x].append(y)
    lengths = []
    for key in sorted(vals):
        # print '%f %i' % (key,len(vals[key]))
        lengths.append(len(vals[key]))
    mode = max(set(lengths), key=lengths.count)
    to_del = []
    for key in sorted(vals):
        if len(vals[key]) < (mode - relax_safety):
            to_del.append(key)
    for x in to_del:
        del vals[x]

    gr = ROOT.TGraph()
    gr.Set(len(vals))  # will not contain the best fit
    for i, key in enumerate(sorted(vals)):
        gr.SetPoint(i, key, min(vals[key]))

    # print 'Envelope'
    # gr.Print()

    spline = ROOT.TSpline3("spline3", gr)
    global NAMECOUNTER
    func = ROOT.TF1('splinefn' + str(NAMECOUNTER), partial(Eval, spline),
                    gr.GetX()[0],
                    gr.GetX()[gr.GetN() - 1], 1)
    func.SetNpx(NPX)
    min_x, min_y = plot.ImproveMinimum(gr, func)
    gr.Set(len(vals) + 1)
    gr.SetPoint(len(vals), min_x, min_y)
    gr.Sort()

    for i in xrange(gr.GetN()):
        gr.GetY()[i] -= min_y
    for oth in others:
        for i in xrange(oth['graph'].GetN()):
            oth['graph'].GetY()[i] -= min_y
        # print 'OTHER'
        # oth['graph'].Print()

    plot.RemoveGraphXDuplicates(gr)
    return gr
示例#7
0
def read(scan, param_x, param_y, file):
    # print files
    goodfiles = [f for f in [file] if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    graph = plot.TGraph2DFromTree(limit, param_x, param_y, '2*deltaNLL', 'quantileExpected > -0.5 && deltaNLL > 0')
    best = plot.TGraphFromTree(limit, param_x, param_y, 'quantileExpected > -0.5 && deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best)
    assert(best.GetN() == 1)
    graph.SetName(scan)
    best.SetName(scan+'_best')
    # graph.Print()
    return (graph, best)
示例#8
0
def read(scan, param, other_param, files, remove_dups=True):
    # print files
    goodfiles = [f for f in files if plot.TFileIsGood(f)]
    limit = plot.MakeTChain(goodfiles, 'limit')
    graph = plot.TGraphFromTree(limit, param, other_param,
                                'quantileExpected > -0.5')
    # print 'INPUT'
    # graph.Print()
    graph.SetName(scan)
    graph.Sort()
    if remove_dups:
        plot.RemoveGraphXDuplicates(graph)
    # graph.Print()
    return graph
示例#9
0
###plot.RemoveGraphXDuplicates(best2)
####hists2 = plot.TH2FromTGraph2D(graph2, method='BinCenterAligned')
###hists.append( plot.TH2FromTGraph2D(graph2, method='BinCenterAligned') )
####plot.fastFillTH2(hists2, graph,interpolateMissing=True)
###if args.bg_exp:
###    limit_bg = plot.MakeTChain(args.bg_exp, 'limit')
###    best_bg = plot.TGraphFromTree(
###        limit_bg, "CV", "CF", 'deltaNLL == 0')
###    plot.RemoveGraphXDuplicates(best_bg)
limit = plot.MakeTChain(args.files, 'limit')
print limit
graph = plot.TGraph2DFromTree(
    limit, "CV", "CF", '2*deltaNLL',
    'quantileExpected > -0.5 && deltaNLL > 0 && deltaNLL < 1000')
best = plot.TGraphFromTree(limit, "CV", "CF", 'deltaNLL == 0')
plot.RemoveGraphXDuplicates(best)
hists = plot.TH2FromTGraph2D(graph, method='BinCenterAligned')
plot.fastFillTH2(hists, graph, interpolateMissing=True)
if args.bg_exp:
    limit_bg = plot.MakeTChain(args.bg_exp, 'limit')
    best_bg = plot.TGraphFromTree(limit_bg, "CV", "CF", 'deltaNLL == 0')
    plot.RemoveGraphXDuplicates(best_bg)

# If included just plot SM exp at 1,1
if args.sm_exp:
    limit_sm = plot.MakeTChain(args.sm_exp, 'limit')
    best_sm = ROOT.TGraph(1, array('d', [
        1,
    ]), array('d', [
        1,
    ]))