Example #1
0
def common_make_root_histogram_test():
  x_list = list(range(0,10000))
  w_list = []
  for i in range( len(x_list) ): 
    x_list[i] = float(x_list[i])/10000.
    w_list.append(x_list[i])
  y_list = __sine_list(2., 2.*math.pi, x_list)
  hist1 = common.make_root_histogram('hist sin(x)', y_list, 'hist of x', 100)
  hist2 = common.make_root_histogram('hist sin(x)', y_list, 'hist of x', 50, x_list, 'hist of y', 50)
  hist3 = common.make_root_histogram('hist sin(x)', y_list, 'hist of x', 10, x_list, 'hist of y', 10, w_list)
  testpass = __test_root_hist(hist3,'hist sin(x)','hist of x','hist of y',common.min_max(y_list, w_list, rg.histo_margin)[0], common.min_max(y_list, w_list, rg.histo_margin)[1], 
                                                                          common.min_max(x_list, w_list, rg.histo_margin)[0], common.min_max(x_list, w_list, rg.histo_margin)[1], 
                              rg.line_color, rg.line_style, rg.line_width, rg.fill_color, '')
  hist4 = common.make_root_histogram('hist sin(x)', y_list, 'hist of x', 10, x_list, 'hist of y', 10, w_list, xmin=y_list[7500],xmax=y_list[2500],ymin=x_list[2500],ymax=x_list[7500],
                                     line_color=1, line_style=2, line_width=3, fill_color=4, hist_title_string='title_string')
  testpass = __test_root_hist(hist4,'hist sin(x)', 'hist of x', 'hist of y', y_list[7500], y_list[2500], x_list[2500], x_list[7500], 1, 2, 3, 4, 'title_string')
  canvas1 = common.make_root_canvas('hist_test1')
  hist1.Draw()
  canvas2 = common.make_root_canvas('hist_test2')
  hist2.Draw('cont1z')
  canvas3 = common.make_root_canvas('hist_test3')
  hist3.Draw('lego')
  canvas4 = common.make_root_canvas('hist_test4')
  hist4.Draw('lego')
  if not testpass: return 'fail'
  return 'pass'
def plot_trajectory(item, line_color, canvas = None):
    z_list = [hit["z"] for hit in item["seed"]]
    x_list = [hit["x"] for hit in item["seed"]]
    y_list = [hit["y"] for hit in item["seed"]]
    r_list = [hit["r"] for hit in item["seed"]]

    x_min, x_max = common.min_max(x_list+r_list+y_list)
    title = "x: "+str(item["seed"][0]["x"])+" mm "+\
            "p_{x}: "+str(item["seed"][0]["px"])+" MeV/c"
    hist_r, graph_r = common.make_root_graph(title, z_list, "z [mm]", r_list, "Radius [mm]", ymin=0.0, ymax=250.)
    hist_x, graph_x = common.make_root_graph("x", z_list, "z [mm]", x_list, "Position [mm]")
    hist_y, graph_y = common.make_root_graph("y", z_list, "z [mm]", y_list, "Position [mm]")
    graph_r.SetLineColor(line_color)
    graph_x.SetLineColor(line_color)
    graph_x.SetLineStyle(3)
    graph_y.SetLineColor(line_color)
    graph_y.SetLineStyle(4)
    if canvas == None:
        canvas = common.make_root_canvas("trajectory")
        #hist_r.SetTitle("x = "+str(x_list[0])+" px = "+str(item["seed"][0]["px"]))
        hist_r.Draw()
    canvas.cd()
    graph_r.Draw("SAMEPL")
    #graph_x.Draw("SAMEPL")
    #graph_y.Draw("SAMEPL")
    canvas.Update()

    return canvas, graph_r
def graph_peak_magnitude(pos_peak_with_errors, neg_peak_with_errors, title):
    peak_time_list, peak_voltage_list, peak_err_list = [], [], []
    for i, v_pos in enumerate(pos_peak_with_errors):
        di = 0
        if i >= len(neg_peak_with_errors):
            break
        while neg_peak_with_errors[i+di]["x"] < pos_peak_with_errors[i]["x"]:
            if i+di+1 >= len(neg_peak_with_errors):
                break
            di += 1
        v_neg = neg_peak_with_errors[i+di]
        v_0 = (v_pos["y"]+v_neg["y"])/2.
        v_err = abs(v_0)*(v_pos["cov(x,y)"][1][1]/v_pos["y"]**2+v_neg["cov(x,y)"][1][1]/v_neg["y"]**2)**0.5
        peak_voltage_list.append(v_0)
        peak_err_list.append(v_err*1e3)
        peak_time_list.append(v_pos["x"]*DT)
    print "    Peak voltage mean:", numpy.mean(peak_voltage_list[-20:-10]),
    print "sigma:", numpy.std(peak_voltage_list[-20:-10])
    canvas = common.make_root_canvas(title+" rf voltage")
    canvas.Draw()
    canvas.cd()
    y_range = common.min_max(peak_voltage_list+peak_err_list)
    hist, graph = common.make_root_graph("Peaks", peak_time_list, "Time of peak [ns]", peak_voltage_list, "Peak voltage [kV]", ymin = y_range[0], ymax = y_range[1])
    hist.Draw()
    graph.SetMarkerStyle(6)
    graph.Draw("p")
    hist, graph = common.make_root_graph("Errors", peak_time_list, "Time of peak [ns]", peak_err_list, "Error [V]", ymin = y_range[0], ymax = y_range[1])
    graph.SetMarkerColor(2)
    graph.SetMarkerStyle(6)
    graph.Draw("p")
    canvas.Update()    
    return canvas, hist, graph
Example #4
0
def common_make_root_graph_test():
  testpass = True
  canvas = common.make_root_canvas('graph_test')
  x_list = list(range(0,100))
  for i in range( len(x_list) ): x_list[i] = float(x_list[i])/100.
  y_list = __sine_list(2., 2.*math.pi, x_list)
  mm = common.min_max(x_list) + common.min_max(y_list)
  (hist,graph) = common.make_root_graph('test', x_list, 'x [2#pi rad]', y_list, 'a*sin(b*x)')
  if not __test_root_hist(hist, '', 'x [2#pi rad]', 'a*sin(b*x)', mm[0], mm[1], mm[2], mm[3], rg.line_color, rg.line_style, rg.line_width, rg.fill_color, ''): return 'fail'
  (hist,graph) = common.make_root_graph('test', x_list, 'x [2#pi rad]', y_list, 'a*sin(b*x)', xmin=-1001., xmax=+1001, ymin=-1002., ymax=+1002.,line_color=201, line_style=202, line_width=203, fill_color=204, hist_title_string='mr title')
  testpass &= __test_root_hist(hist, 'namey', 'x [2#pi rad]', 'a*sin(b*x)', -1001., +1001., -1002., +1002., rg.line_color, rg.line_style, rg.line_width, rg.fill_color, 'mr title') 
  testpass &= __test_root_graph(graph, 'namey', x_list, y_list, 201, 202, 203, 204)
  (x_list, y_list) = ([3,2,1], [3,2,1]) #check that x_list and y_list are not changed by sort
  (hist,graph) = common.make_root_graph('test', x_list, 'x', y_list, 'y')
  testpass &=   (x_list, y_list) == ([3,2,1], [3,2,1])
  hist.Draw()
  graph.Draw()
  common.clear_root()
  if testpass: return 'pass'
  else:        return 'fail'
Example #5
0
def plot_trajectory(item, line_color, canvas=None):
    z_list = [hit["z"] for hit in item["seed"]]
    x_list = [hit["x"] for hit in item["seed"]]
    y_list = [hit["y"] for hit in item["seed"]]
    r_list = [hit["r"] for hit in item["seed"]]

    x_min, x_max = common.min_max(x_list + r_list + y_list)
    title = "x: "+str(item["seed"][0]["x"])+" mm "+\
            "p_{x}: "+str(item["seed"][0]["px"])+" MeV/c"
    hist_r, graph_r = common.make_root_graph(title,
                                             z_list,
                                             "z [mm]",
                                             r_list,
                                             "Radius [mm]",
                                             ymin=0.0,
                                             ymax=250.)
    hist_x, graph_x = common.make_root_graph("x", z_list, "z [mm]", x_list,
                                             "Position [mm]")
    hist_y, graph_y = common.make_root_graph("y", z_list, "z [mm]", y_list,
                                             "Position [mm]")
    graph_r.SetLineColor(line_color)
    graph_x.SetLineColor(line_color)
    graph_x.SetLineStyle(3)
    graph_y.SetLineColor(line_color)
    graph_y.SetLineStyle(4)
    if canvas == None:
        canvas = common.make_root_canvas("trajectory")
        #hist_r.SetTitle("x = "+str(x_list[0])+" px = "+str(item["seed"][0]["px"]))
        hist_r.Draw()
    canvas.cd()
    graph_r.Draw("SAMEPL")
    #graph_x.Draw("SAMEPL")
    #graph_y.Draw("SAMEPL")
    canvas.Update()

    return canvas, graph_r
Example #6
0
def common_min_max_test():
  test_pass = True
  out = common.min_max([-0.1,-0.5,-0.9,0.0])
  test_pass = test_pass and abs(out[0]--0.99) < __float_tol
  test_pass = test_pass and abs(out[1]-+0.09) < __float_tol
  out = common.min_max(x_float_list=[-0.1,-0.5,-0.9,0.0], weight_list=[1,1,0,1])
  test_pass = test_pass and abs(out[0]--0.55) < __float_tol
  test_pass = test_pass and abs(out[1]-+0.05) < __float_tol
  out = common.min_max(x_float_list=[-0.1,-0.5,-0.9,0.0], weight_list=[1,1,0,1], margin=0.0)
  test_pass = test_pass and abs(out[0]--0.5) < __float_tol
  test_pass = test_pass and abs(out[1]-+0.0) < __float_tol
  out = common.min_max(x_float_list=[-0.1,-0.5,-0.9,0.0], weight_list=[1,1,0,1], margin=0.0, xmin=+100.)
  test_pass = test_pass and abs(out[0]-100.) < __float_tol
  test_pass = test_pass and abs(out[1]-+0.0) < __float_tol
  out = common.min_max(x_float_list=[-0.1,-0.5,-0.9,0.0], weight_list=[1,1,0,1], margin=0.0, xmax=-100.)
  test_pass = test_pass and abs(out[0]--0.5) < __float_tol
  test_pass = test_pass and abs(out[1]+100.) < __float_tol
  out = common.min_max([-10., 10.], [0.,0.])
  test_pass = test_pass and abs(out[0]+1.) < __float_tol
  test_pass = test_pass and abs(out[1]-1.) < __float_tol
  if   test_pass: return 'pass'
  else:           return 'fail'
Example #7
0
def plot_2d(data, foil_probe, foil_var1, foil_var2, z_lambda, plot_title,
            canvas):
    name = plot_title.replace("__", "")
    name = name.replace("_", " ")
    x_data, y_data, z_data = [], [], []
    for bump in data:
        for hit in bump["tracking"]:
            if hit[0] == foil_probe:
                x_data.append(hit[foil_var1])
                y_data.append(hit[foil_var2])
                break
        if len(x_data) != len(z_data):  # meaning we found foil probe
            z_data.append(z_lambda(bump))
    if abs(max(z_data) - min(z_data)) < 1e-5:
        print("Not plotting", name)
        print("    ", "z_data", z_data)
        return False

    print("Plotting ", name)
    print("   ", "x_data", x_data)
    print("   ", "y_data", y_data)
    print("   ", "z_data", z_data)

    n_points = len(x_data)
    if canvas == None:
        canvas = common.make_root_canvas(name)
        canvas.Draw()
    canvas.cd()
    x_min_max = common.min_max(x_data)
    y_min_max = common.min_max(y_data)
    z_min_max = common.min_max(z_data)
    hist = ROOT.TH3D(
        "",
        "",
        10,
        x_min_max[0],
        x_min_max[1],
        10,
        y_min_max[0],
        y_min_max[1],
        10,
        z_min_max[0],
        z_min_max[1],
    )
    hist.GetXaxis().SetTitleOffset(3)
    hist.SetStats(False)
    hist.GetZaxis().SetLabelSize(0.01)
    hist.Draw()
    root_objects.append(hist)
    graph2d = ROOT.TGraph2D(n_points)
    root_objects.append(graph2d)
    ROOT.gStyle.SetPalette(1)
    graph2d.SetMarkerStyle(20)
    graph2d.SetTitle("")
    graph2d.Draw('same pcolz')
    for i in range(n_points):
        graph2d.SetPoint(i, x_data[i], y_data[i], z_data[i])
    #palette = ROOT.TPaletteAxis(hist.GetListOfFunctions().FindObject("palette"))
    #palette.SetX2NDC(0.99)
    canvas.SetRightMargin(0.13)
    text = ROOT.TPaveText(0.1, 0.6, 0.65, 0.7)
    text.SetBorderSize(1)
    text.SetFillColor(10)
    text.AddText(name)
    text.Draw()
    root_objects.append(text)
    name = name.replace(" ", "_")
    canvas.SetTheta(90)
    canvas.SetPhi(-90)
    canvas.Update()
    return canvas, graph2d