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
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
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
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
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 }
def BuildScan(scan, param, files, color, yvals, chop, remove_near_min=None, rezero=False, envelope=False, pregraph=None, remove_delta=None, improve=False): print "Build scan files:", files if pregraph is None: print "pregraph is none" remove_dups = not envelope graph = read(scan, param, files, chop, remove_near_min, rezero, remove_delta, improve, remove_dups) print "Graph1:" print graph.Print() print chop plot.RemoveGraphYAbove(graph, chop) #plot.SetMinToZero(graph) print "Graph2:" print graph.Print() else: print "pregraph is NOT none" graph = pregraph bestfit = None #print "Graph:" #print graph.Print() min_i = -1 min_val = 999 for i in xrange(graph.GetN()): print i, graph.GetY()[i] #if i == 10 : graph.SetPoint(i, graph.GetX()[i], 0.) # FIXME if graph.GetY()[i] < min_val: min_val = graph.GetY()[i] min_i = i #if graph.GetY()[i] == 0.: # bestfit = graph.GetX()[i] bestfit = graph.GetX()[min_i] if envelope: plot.RemoveGraphYAll(graph, 0.) global NAMECOUNTER print "NAMECOUNTER:", NAMECOUNTER ## for 1 lines + obs #colorMap = { #0 : ROOT.kBlack, #1 : ROOT.kRed} # for 2 lines + obs #colorMap = { #0 : ROOT.kBlack, #1 : ROOT.kGreen+1, #2 : ROOT.kRed} ## for 3 lines + obs colorMap = { 0: ROOT.kBlack, 2: ROOT.kBlue, 3: ROOT.kRed, 1: ROOT.kGreen + 1 } #graph.SetMarkerColor(color) graph.SetMarkerColor(colorMap[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) #func.SetLineColor(color) func.SetLineColor(colorMap[NAMECOUNTER]) NAMECOUNTER += 1 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 }
scan.graph_settings.update(ParseDictArgs(splitargs[2])) if len(splitargs) > 3: scan.func_settings.update(ParseDictArgs(splitargs[3])) label = scan.label info[label] = {} scan_info = info[label] # THEN DO SOME PROCESSING OF THE GRAPH # STANDARD PROCESSING # 1. Remove (x, y) duplicates scanner.FilterDuplicates(scan.gr) # 2. Remove near the minimum (0.8) scanner.RemoveNearMin(scan.gr, 0.8) # 3. Remove y points above some cutoff (mostly cosmetic - should come later because envelope processing will change things) plotting.RemoveGraphYAbove(scan.gr, args.chop) # TOOD: what if there is a scan point with deltaNLL < 0.0 scan.gr.Print() bestfit = scanner.FindGlobalBestFit(scan.gr) scan_info['Val'] = bestfit[1] scan.BuildSpline() # scanner.ImproveMinimum(scan.gr, scan.fn) # PROCESS ENVELOPE # 1. Remove (x, y) duplicates (previously didn't remove duplicates, # but was only checking x duplicates before). Guess was worried about # removing a legit point with deltaNLL > 0 at the same x as the minimum # 2. Remove the minimum # 3. Run the enveloping procedure