def get_radius(x, xp, y, yp): gamma_rel, beta_rel, p0, mass = get_rel_params(7e12) term_1_x = np.mean(np.multiply(x, x)) - np.multiply(np.mean(x), np.mean(x)) term_2_x = np.mean(np.multiply(x, xp)) - np.multiply( np.mean(x), np.mean(xp)) term_3_x = np.mean(np.multiply(xp, x)) - np.multiply( np.mean(xp), np.mean(x)) term_4_x = np.mean(np.multiply(xp, xp)) - np.multiply( np.mean(xp), np.mean(xp)) term_1_y = np.mean(np.multiply(y, y)) - np.multiply(np.mean(y), np.mean(y)) term_2_y = np.mean(np.multiply(y, yp)) - np.multiply( np.mean(y), np.mean(yp)) term_3_y = np.mean(np.multiply(yp, y)) - np.multiply( np.mean(yp), np.mean(y)) term_4_y = np.mean(np.multiply(yp, yp)) - np.multiply( np.mean(yp), np.mean(yp)) det_x = np.multiply(term_1_x, term_4_x) - np.multiply(term_3_x, term_2_x) em_x = np.sqrt(abs(det_x)) det_y = np.multiply(term_1_y, term_4_y) - np.multiply(term_3_y, term_2_y) em_y = np.sqrt(abs(det_y)) return np.sqrt(em_x), np.sqrt(em_y)
def get_radius(x, xp, y, yp): gamma_rel, beta_rel, p0, mass = get_rel_params(7e12) term_1_x = np.mean(np.multiply(x,x)) - np.multiply(np.mean(x), np.mean(x)) term_2_x = np.mean(np.multiply(x,xp)) - np.multiply(np.mean(x),np.mean(xp)) term_3_x = np.mean(np.multiply(xp,x)) - np.multiply(np.mean(xp), np.mean(x)) term_4_x = np.mean(np.multiply(xp,xp)) - np.multiply(np.mean(xp),np.mean(xp)) term_1_y = np.mean(np.multiply(y,y)) - np.multiply(np.mean(y), np.mean(y)) term_2_y = np.mean(np.multiply(y,yp)) - np.multiply(np.mean(y),np.mean(yp)) term_3_y = np.mean(np.multiply(yp,y)) - np.multiply(np.mean(yp), np.mean(y)) term_4_y = np.mean(np.multiply(yp,yp)) - np.multiply(np.mean(yp),np.mean(yp)) det_x = np.multiply(term_1_x, term_4_x) - np.multiply(term_3_x, term_2_x) em_x = np.sqrt(abs(det_x)) det_y = np.multiply(term_1_y, term_4_y) - np.multiply(term_3_y, term_2_y) em_y = np.sqrt(abs(det_y)) return np.sqrt(em_x), np.sqrt(em_y)
import numpy as np import matplotlib.pyplot as plt import util #From Andrea's library https://github.com/KFubuki/Toolkit alpha_y = -0.000764 beta_y = 0.150235 orb_y = 0.0 orbp_y = 295e-6 E = 7e12 gamma_rel, beta_rel, p0, mass = util.get_rel_params(E) eps = 2.5e-6 #[m*rad] eps_g = eps/(beta_rel*gamma_rel) #[m*rad] print "eps=",eps, "eps_g=",eps_g plot_maxsig = 10.0 gamma_y = (1+alpha_y**2)/beta_y coll_nsig = 5.7*np.sqrt(3.5e-6/eps) print "coll_nsig =",coll_nsig, "(effective at eps=",eps,", reference nsig=5.7)" def do_floquet(x,xp, alpha,beta): "Floquet transform" return (x/np.sqrt(beta), (x*alpha)/np.sqrt(beta) + xp*np.sqrt(beta)) def do_floquet_inverse(x2,xp2,alpha,beta): "Inverse floquet transform" return (x2*np.sqrt(beta), -(x2*alpha)/np.sqrt(beta) + xp2/np.sqrt(beta))
def dist_generator(particles, energy, machine, fort13, jobs, factor, emittance_x, emittance_y, alpha_x, alpha_y, beta_x, beta_y, offset_x, offset_xp, offset_y, offset_yp, dispersion_x, dispersion_y, bunch, spread, seed): job_str = '%s'%jobs # Getting the Transverse sigmas (amplitudes of phase space ellipse) # -------------------------------------------------------------------------------------------------------------- gamma_rel, beta_rel, p0, mass = get_rel_params(energy) tx_max, txp_max = get_sigmas(alpha_x, beta_x, emittance_x, dispersion_x, spread, beta_rel, gamma_rel) ty_max, typ_max = get_sigmas(alpha_y, beta_y, emittance_y, dispersion_y, spread, beta_rel, gamma_rel) # Seeding # -------------------------------------------------------------------------------------------------------------- if seed == 0: myseed = random.randint(0, 429496729) else: myseed = seed with open('seed.txt', 'a') as g: print >> g, 'job ', job_str ,'seed ', myseed np.random.seed(myseed) random.seed(myseed) # Generating the Transverse Distribution # -------------------------------------------------------------------------------------------------------------- x_t = np.asarray(np.random.normal(0, factor * tx_max, round(particles))) xp_t = np.asarray(np.random.normal(0, factor * txp_max, round(particles))) y_t = np.asarray(np.random.normal(0, factor * ty_max, round(particles))) yp_t = np.asarray(np.random.normal(0, factor * typ_max, round(particles))) # Rotating the Transverse Distribution # -------------------------------------------------------------------------------------------------------------- angle_x = np.arctan(-alpha_x/beta_x) x = x_t*np.cos(angle_x) - xp_t*np.sin(angle_x) xp = x_t*np.sin(angle_x) + xp_t*np.cos(angle_x) angle_y = np.arctan(-alpha_y/beta_y) y = y_t*np.cos(angle_y) - yp_t*np.sin(angle_y) yp = y_t*np.sin(angle_y) + yp_t*np.cos(angle_y) # Generating the Longitudinal Distribution # -------------------------------------------------------------------------------------------------------------- z = [] E = [] dp = [] while len(z) < particles: # Generate for as long time as is needed particle_z = random.gauss(0,1) particle_e = random.gauss(0,1) trial_z = particle_z * bunch trial_e = energy * (1 + particle_e*spread) #eV trial_p = np.sqrt((trial_e - mass) * (trial_e + mass)) dPP = (trial_p - p0) / p0 h = get_bucket(machine, plot=False, z=trial_z, DELTA=dPP) # Longitudinal contour if machine=='HL_coll' or machine=='HL_coll_200' or machine=='HL_coll_tcp' or machine=='HL_coll_tcp_200': Hmargin = -0.01 elif machine=='SPS_inj': Hmargin = -1 if h <= Hmargin: z.append(float(trial_z)) E.append(float(trial_e)) dp.append(dPP) else: print 'Outside margin, trying again,', h zz = np.asarray(z) EE = np.asarray(E) ddp = np.asarray(dp) if fort13=='False': outfile = 'init_dist_' + job_str + '.txt' with open(outfile, 'w') as f: for e1, e2, e3, e4, e5, e6 in zip(x, xp, y, yp, zz*1e3, EE*1e-6): f.write('%8.6e %8.6e %8.6e %8.6e %8.6e %8.6e\n' % (e1, e2, e3, e4, e5, e6)) elif fort13=='True': outfile = 'fort.13' with open(outfile, 'w') as f: for i in xrange(0, particles, 2): f.write(str((x[i] + offset_x)*1e3) + "\n") #mm f.write(str((xp[i] + offset_xp)*1e3) + "\n") #mrad f.write(str((y[i] + offset_y)*1e3) + "\n") #mm f.write(str((yp[i] + offset_yp)*1e3) + "\n") #mrad f.write(str(zz[i]*1e3) + "\n") #mm f.write(str(ddp[i]) + "\n") #- f.write(str((x[i+1] + offset_x)*1e3) + "\n") #mm f.write(str((xp[i+1] + offset_xp)*1e3) + "\n") #mrad f.write(str((y[i+1] + offset_y)*1e3) + "\n") #mm f.write(str((yp[i+1] + offset_yp)*1e3) + "\n") #mrad f.write(str(zz[i+1]*1e3) + "\n") #mm f.write(str(ddp[i+1]) + "\n") #- f.write(str(energy*1e-6) + "\n") #MeV f.write(str(EE[i]*1e-6) + "\n") #MeV f.write(str(EE[i+1]*1e-6) + "\n") #MeV else: print 'Please input True or False in the fourth argument'
def dist_generator(particles, energy, machine, fort13, jobs, factor, emittance_x, emittance_y, alpha_x, alpha_y, beta_x, beta_y, offset_x, offset_xp, offset_y, offset_yp, dispersion_x, dispersion_y, bunch, spread, seed): job_str = '%s' % jobs # Getting the Transverse sigmas (amplitudes of phase space ellipse) # -------------------------------------------------------------------------------------------------------------- gamma_rel, beta_rel, p0, mass = get_rel_params(energy) tx_max, txp_max = get_sigmas(alpha_x, beta_x, emittance_x, dispersion_x, spread, beta_rel, gamma_rel) ty_max, typ_max = get_sigmas(alpha_y, beta_y, emittance_y, dispersion_y, spread, beta_rel, gamma_rel) # Seeding # -------------------------------------------------------------------------------------------------------------- if seed == 0: myseed = random.randint(0, 429496729) else: myseed = seed with open('seed.txt', 'a') as g: print >> g, 'job ', job_str, 'seed ', myseed np.random.seed(myseed) random.seed(myseed) # Generating the Transverse Distribution # -------------------------------------------------------------------------------------------------------------- x_t = np.asarray(np.random.normal(0, factor * tx_max, round(particles))) xp_t = np.asarray(np.random.normal(0, factor * txp_max, round(particles))) y_t = np.asarray(np.random.normal(0, factor * ty_max, round(particles))) yp_t = np.asarray(np.random.normal(0, factor * typ_max, round(particles))) # Rotating the Transverse Distribution # -------------------------------------------------------------------------------------------------------------- angle_x = np.arctan(-alpha_x / beta_x) x = x_t * np.cos(angle_x) - xp_t * np.sin(angle_x) xp = x_t * np.sin(angle_x) + xp_t * np.cos(angle_x) angle_y = np.arctan(-alpha_y / beta_y) y = y_t * np.cos(angle_y) - yp_t * np.sin(angle_y) yp = y_t * np.sin(angle_y) + yp_t * np.cos(angle_y) # Generating the Longitudinal Distribution # -------------------------------------------------------------------------------------------------------------- z = [] E = [] dp = [] while len(z) < particles: # Generate for as long time as is needed particle_z = random.gauss(0, 1) particle_e = random.gauss(0, 1) trial_z = particle_z * bunch trial_e = energy * (1 + particle_e * spread) #eV trial_p = np.sqrt((trial_e - mass) * (trial_e + mass)) dPP = (trial_p - p0) / p0 h = get_bucket(machine, plot=False, z=trial_z, DELTA=dPP) # Longitudinal contour if machine == 'HL_coll' or machine == 'HL_coll_200' or machine == 'HL_coll_tcp' or machine == 'HL_coll_tcp_200': Hmargin = -0.01 elif machine == 'SPS_inj': Hmargin = -1 if h <= Hmargin: z.append(float(trial_z)) E.append(float(trial_e)) dp.append(dPP) else: print 'Outside margin, trying again,', h zz = np.asarray(z) EE = np.asarray(E) ddp = np.asarray(dp) if fort13 == 'False': outfile = 'init_dist_' + job_str + '.txt' with open(outfile, 'w') as f: for e1, e2, e3, e4, e5, e6 in zip(x, xp, y, yp, zz * 1e3, EE * 1e-6): f.write('%8.6e %8.6e %8.6e %8.6e %8.6e %8.6e\n' % (e1, e2, e3, e4, e5, e6)) elif fort13 == 'True': outfile = 'fort.13' with open(outfile, 'w') as f: for i in xrange(0, particles, 2): f.write(str((x[i] + offset_x) * 1e3) + "\n") #mm f.write(str((xp[i] + offset_xp) * 1e3) + "\n") #mrad f.write(str((y[i] + offset_y) * 1e3) + "\n") #mm f.write(str((yp[i] + offset_yp) * 1e3) + "\n") #mrad f.write(str(zz[i] * 1e3) + "\n") #mm f.write(str(ddp[i]) + "\n") #- f.write(str((x[i + 1] + offset_x) * 1e3) + "\n") #mm f.write(str((xp[i + 1] + offset_xp) * 1e3) + "\n") #mrad f.write(str((y[i + 1] + offset_y) * 1e3) + "\n") #mm f.write(str((yp[i + 1] + offset_yp) * 1e3) + "\n") #mrad f.write(str(zz[i + 1] * 1e3) + "\n") #mm f.write(str(ddp[i + 1]) + "\n") #- f.write(str(energy * 1e-6) + "\n") #MeV f.write(str(EE[i] * 1e-6) + "\n") #MeV f.write(str(EE[i + 1] * 1e-6) + "\n") #MeV else: print 'Please input True or False in the fourth argument'
import scipy import pylab from util import GetData from util import get_rel_params # ------------------------------------------------------------------------------ # Define your input DUMP file # ------------------------------------------------------------------------------ infile = sys.argv[1] total_turns = np.int(sys.argv[2]) # ------------------------------------------------------------------------------ # Relativistic parameters # ------------------------------------------------------------------------------ gamma_rel, beta_rel, p0, mass = get_rel_params(26e9) # ------------------------------------------------------------------------------ # Initialization of arrays # ------------------------------------------------------------------------------ t = np.zeros(total_turns) term_1_x = np.zeros(total_turns) term_2_x = np.zeros(total_turns) term_3_x = np.zeros(total_turns) term_4_x = np.zeros(total_turns) term_1_y = np.zeros(total_turns) term_2_y = np.zeros(total_turns) term_3_y = np.zeros(total_turns) term_4_y = np.zeros(total_turns)
print '>> Dictionary was not correctly created' return d x = get_turns(x_tot, turns) xp = get_turns(xp_tot, turns) y = get_turns(y_tot, turns) yp = get_turns(yp_tot, turns) z = get_turns(z_tot, turns) e = get_turns(e_tot, turns) # ------------------------------------------------------------------------------ # PLOTTING # ------------------------------------------------------------------------------ if machine == 'HL_coll': gamma_rel, beta_rel, p0, mass = get_rel_params(7e12) alpha_x = 0.003485 alpha_y = -0.000764 beta_x = 0.150739 beta_y = 0.150235 sigma_x, sigma_xp = get_sigmas(alpha_x, beta_x, 2.5e-6, 0.003652, 1.13e-4, beta_rel, gamma_rel) sigma_y, sigma_yp = get_sigmas(alpha_y, beta_y, 2.5e-6, 0.000517, 1.13e-4, beta_rel, gamma_rel) sigma_z = 0.0755 lines = 40 offset_x = -7.5e-4 offset_xp = 0.0 offset_y = 0.0