def get_dynap(h5_filename, sigmax, sigmay, nturns, i): ob = mfm.h5_to_dict(h5_filename) #Ax = ob['horizontal_amp_mm']/sigmax #Ay = ob['vertical_amp_mm']/sigmay last_turn = ob['survived_turns'] da_index = np.argmax(last_turn < nturns) r_max_sigma = 10. r_min_sigma = 0.1 r_step = 0.1 N_r = int(round((r_max_sigma - r_min_sigma) / r_step)) + 1 theta_step = (3. / 180.) * np.pi theta_min_rad = (i) * theta_step theta_max_rad = (i + 1) * theta_step N_theta = int(round((theta_max_rad - theta_min_rad) / theta_step)) xy_norm = footprint.initial_xy_polar(r_min=r_min_sigma, r_max=r_max_sigma, r_N=N_r, theta_min=theta_min_rad, theta_max=theta_max_rad, theta_N=N_theta) #return Ax[da_index], Ay[da_index] r = da_index * r_step + r_min_sigma theta = theta_min_rad return r * np.cos(theta), r * np.sin(theta)
partCO = pickle.load(fid) with open(fOptics, 'rb') as fid: optics = pickle.load(fid) part = pysixtrack.Particles(**partCO) beta_x = optics['betx'] beta_y = optics['bety'] sigmax = np.sqrt(beta_x * epsn_x / part.beta0 / part.gamma0) sigmay = np.sqrt(beta_y * epsn_y / part.beta0 / part.gamma0) xy_norm = footprint.initial_xy_polar(r_min=r_min_sigma, r_max=r_max_sigma, r_N=N_r, theta_min=theta_min_rad, theta_max=theta_max_rad, theta_N=N_theta) DpxDpy_wrt_CO = np.zeros_like(xy_norm) for ii in range(xy_norm.shape[0]): for jj in range(xy_norm.shape[1]): DpxDpy_wrt_CO[ii, jj, 0] = xy_norm[ii, jj, 0] * np.sqrt( epsn_x / part.beta0 / part.gamma0 / beta_x) DpxDpy_wrt_CO[ii, jj, 1] = xy_norm[ii, jj, 1] * np.sqrt( epsn_y / part.beta0 / part.gamma0 / beta_y) with open('DpxDpy_for_DA.pkl', 'wb') as fid: pickle.dump({
Dy_wrt_CO_m=0., Dpy_wrt_CO_rad=0., Dsigma_wrt_CO_m=0., Ddelta_wrt_CO=0., n_turns=n_turns_beta, verbose=True) beta_x, x_max, px_cut = hp.betafun_from_ellip(x_tbt, px_tbt) beta_y, y_max, py_cut = hp.betafun_from_ellip(y_tbt, py_tbt) sigmax = np.sqrt(beta_x * epsn_x / part.beta0 / part.gamma0) sigmay = np.sqrt(beta_y * epsn_y / part.beta0 / part.gamma0) xy_norm = footprint.initial_xy_polar(r_min=1e-2, r_max=r_max_sigma, r_N=N_r_footp + 1, theta_min=np.pi / 100, theta_max=np.pi / 2 - np.pi / 100, theta_N=N_theta_footp) DpxDpy_wrt_CO = np.zeros_like(xy_norm) for ii in range(xy_norm.shape[0]): for jj in range(xy_norm.shape[1]): DpxDpy_wrt_CO[ii, jj, 0] = xy_norm[ii, jj, 0] * \ np.sqrt(epsn_x / part.beta0 / part.gamma0 / beta_x) DpxDpy_wrt_CO[ii, jj, 1] = xy_norm[ii, jj, 1] * \ np.sqrt(epsn_y / part.beta0 / part.gamma0 / beta_y) with open('DpxDpy_for_footprint.pkl', 'wb') as fid: pickle.dump({
part.y += 1e-5 x_tbt, px_tbt, y_tbt, py_tbt, sigma_tbt, delta_tbt = hp.track_particle_pysixtrack( line, part=part, Dx_wrt_CO_m=0., Dpx_wrt_CO_rad=0., Dy_wrt_CO_m=0., Dpy_wrt_CO_rad=0., Dsigma_wrt_CO_m=0., Ddelta_wrt_CO=0., n_turns=n_turns_beta, verbose=True) beta_x, x_max, px_cut = hp.betafun_from_ellip(x_tbt, px_tbt) beta_y, y_max, py_cut = hp.betafun_from_ellip(y_tbt, py_tbt) sigmax = np.sqrt(beta_x * epsn_x / part.beta0 / part.gamma0) sigmay = np.sqrt(beta_y * epsn_y / part.beta0 / part.gamma0) xy_norm = footprint.initial_xy_polar(r_min=1e-2, r_max=r_max_sigma, r_N=N_r_footp + 1, theta_min=np.pi / 100, theta_max=np.pi / 2 - np.pi / 100, theta_N=N_theta_footp) DpxDpy_wrt_CO = np.zeros_like(xy_norm) for ii in range(xy_norm.shape[0]): for jj in range(xy_norm.shape[1]): DpxDpy_wrt_CO[ii, jj, 0] = xy_norm[ii, jj, 0] * np.sqrt(epsn_x / part.beta0 / part.gamma0 / beta_x) DpxDpy_wrt_CO[ii, jj, 1] = xy_norm[ii, jj, 1] * np.sqrt(epsn_y / part.beta0 / part.gamma0 / beta_y) with open('DpxDpy_for_footprint.pkl', 'wb') as fid: pickle.dump({ 'DpxDpy_wrt_CO': DpxDpy_wrt_CO, 'xy_norm': xy_norm, }, fid)
import matplotlib.pyplot as plt import numpy as np import os import scipy.constants import math import sys import tune_diagram import footprint import NAFFlib plt.style.use('kostas') sig = 1.157751566e-05 n = 15 xy = footprint.initial_xy_polar(sig, n * sig, n, 0.01 * np.pi, np.pi * (1 / 2. - 0.01), 10) trackdir = 'tracks/' if not os.path.exists(trackdir): os.makedirs(trackdir) temptxt = open('temp.txt', 'w') temptxt.write('call, file="toy.seq";\n') temptxt.write('Beam, particle=proton, npart:=1.e11, energy = 6500.0;\n') temptxt.write('use, sequence=toymachine;\n') temptxt.write('track, file={0}/track;\n'.format(trackdir.strip('/'))) for x in xy: for y in x: temptxt.write( 'start, x={0:.10f}, y={1:.10f}, px=0, py=0, t=0,pt=1.e-4;\n'. format(y[0], y[1])) temptxt.write('run, turns = 100;\n') temptxt.write('endtrack;\n')