コード例 #1
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
コード例 #2
0
ファイル: plot1DScan.py プロジェクト: senka/HTT_20162017
def ProcessEnvelopeNew(main, others, relax_safety=0):
    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
    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
コード例 #3
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
コード例 #4
0
ファイル: plot1DScan.py プロジェクト: senka/HTT_20162017
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 > -1.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
コード例 #5
0
def BuildScan(scan,
              param,
              files,
              color,
              yvals,
              chop,
              remove_near_min=None,
              rezero=False,
              envelope=False,
              pregraph=None,
              remove_delta=None,
              improve=False):
    print files
    if pregraph is None:
        remove_dups = not envelope
        graph = read(scan, param, files, chop, remove_near_min, rezero,
                     remove_delta, improve, remove_dups)
        plot.RemoveGraphYAbove(graph, chop)

    else:
        graph = pregraph
    bestfit = None
    for i in xrange(graph.GetN()):
        if graph.GetY()[i] == 0.:
            bestfit = graph.GetX()[i]
    if envelope:
        plot.RemoveGraphYAll(graph, 0.)
    graph.SetMarkerColor(color)
    spline = ROOT.TSpline3("spline3", graph)
    global NAMECOUNTER
    func = ROOT.TF1('splinefn' + str(NAMECOUNTER), partial(Eval, spline),
                    graph.GetX()[0],
                    graph.GetX()[graph.GetN() - 1], 1)
    func.SetNpx(NPX)
    NAMECOUNTER += 1
    func.SetLineColor(color)
    func.SetLineWidth(3)
    assert (bestfit is not None)
    if not envelope:
        plot.ImproveMinimum(graph, func)
    crossings = {}
    cross_1sig = None
    cross_2sig = None
    other_1sig = []
    other_2sig = []
    val = None
    val_2sig = None
    for yval in yvals:
        crossings[yval] = plot.FindCrossingsWithSpline(graph, func, yval)
        for cr in crossings[yval]:
            cr["contains_bf"] = cr["lo"] <= bestfit and cr["hi"] >= bestfit
    for cr in crossings[yvals[0]]:
        if cr['contains_bf']:
            val = (bestfit, cr['hi'] - bestfit, cr['lo'] - bestfit)
            cross_1sig = cr
        else:
            other_1sig.append(cr)
    if len(yvals) > 1:
        for cr in crossings[yvals[1]]:
            if cr['contains_bf']:
                val_2sig = (bestfit, cr['hi'] - bestfit, cr['lo'] - bestfit)
                cross_2sig = cr
            else:
                other_2sig.append(cr)
    else:
        val_2sig = (0., 0., 0.)
        cross_2sig = cross_1sig
    return {
        "graph": graph,
        "spline": spline,
        "func": func,
        "crossings": crossings,
        "val": val,
        "val_2sig": val_2sig,
        "cross_1sig": cross_1sig,
        "cross_2sig": cross_2sig,
        "other_1sig": other_1sig,
        "other_2sig": other_2sig
    }
コード例 #6
0
        legend.AddEntry(new_others[i]['func'], other_scans_opts[i][1], 'L')
else:
    for i, other in enumerate(other_scans):
        legend.AddEntry(other['func'], other_scans_opts[i][1], 'L')
# if len(args) >= 4: legend.AddEntry(syst_scan['func'], 'Stat. Only', 'L')
# legend.Draw()

save_graph = main_scan['graph'].Clone()
save_graph.GetXaxis().SetTitle(
    '%s = %.3f %+.3f/%+.3f' % (fixed_name, val_nom[0], val_nom[2], val_nom[1]))
outfile = ROOT.TFile(args.output + '.root', 'RECREATE')
outfile.WriteTObject(save_graph, 'main')
for i, other in enumerate(other_scans):
    save_graph = other['graph'].Clone()
    if args.envelope:
        min_val = plot.ImproveMinimum(save_graph, other['func'])
        save_graph.Set(save_graph.GetN() + 1)
        save_graph.SetPoint(save_graph.GetN() - 1, min_val[0], min_val[1])
        save_graph.Sort()
    save_graph.SetTitle(other_scans_opts[i][1])
    outfile.WriteTObject(
        save_graph, other_scans_opts[i][0].replace('.root', '').split('/')[-1])

outfile.Close()
canv.Print('.pdf')
canv.Print('.png')

meta = {}

if args.meta != '':
    meta_list = args.meta.split(',')