def BuildScan(scan, param, files, color, yvals, chop, remove_near_min = None, rezero = False, envelope = False, pregraph = None, remove_delta = None, improve = False): if pregraph is None: graph = read(scan, param, files, chop, remove_near_min, rezero, remove_delta, improve) 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) 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 }