def getAxisFieldFunction(fl_name): """ This function will read the .FSO file and extract the axis field Ez(z). """ fl_in = open(fl_name, "r") lns = fl_in.readlines() fl_in.close() func = Function() i_start = -1 for i in range(len(lns)): if (lns[i].find(" Z(cm) Ez(V/m)") >= 0): i_start = i + 1 break for i in range(i_start, len(lns)): res_arr = lns[i].split() if (len(res_arr) != 2): break x = 0.01 * float(res_arr[0]) y = float(res_arr[1]) func.add(x, y) #fix for the field at the 0 region func1 = Function() for i in range(1, func.getSize()): ind = func.getSize() - i x = -func.x(ind) y = func.y(ind) func1.add(x, y) for i in range(func.getSize()): x = func.x(i) y = func.y(i) func1.add(x, y) return func1
#------------------------------------------------------- import sys import math from orbit_utils import Function f = Function() def FF(x): return math.sin(x) n = 10 step = 2*math.pi/n for i in range(n): x = step*i+0.1*((1.0*i)/n)**2; y = FF(x) err = y*0.001 f.add(x,y,err) f.dump() print "=======================================" for i in range(n): x = f.x(i) y = f.y(i) err = f.getYErr(x) print "i="," x,y,err= %10.7f %10.7f %10.7f "%(x,y,err*1000)
g_func.add(z,g) #---- let's set energy and momentum mass = 0.938272 + 2*0.000511 eKin = 0.0025 momentum = math.sqrt(eKin*(eKin + 2*mass)) Brho = 3.33564*momentum # [T*m] charge = -1.0 #---- now let's prepare array of 4x4 (transport) #---- and 6x6 (Twiss params transport) matrices matrix_arr = [] for ind in range(1,g_func.getSize()): z0 = g_func.x(ind-1) z1 = g_func.x(ind) g0 = g_func.y(ind-1) g1 = g_func.y(ind) z_avg = (z1+z0)/2 g_avg = (g0+g1)/2 g_avg *= charge dL = z1-z0 #print "debug dL=",dL, " y= %12.3f "%y_avg #---- this is a transport 4x4 matrix for coordinates x,x',y,y' trMtrx = Matrix(4,4) k2 = abs(g_avg/Brho) kq = math.sqrt(k2) sin_kL = math.sin(kq*dL) cos_kL = math.cos(kq*dL) sinh_kL = math.sinh(kq*dL) cosh_kL = math.cosh(kq*dL) if(g_avg == 0.):