def generate_gaussian6dBunch(self,n_macroparticles, alpha_x, alpha_y, beta_x, beta_y, dispx, dispy, gamma = 3730.27): Q_s = 0.0020443 C = 26658.883 alpha_0 = [0.0003225] linear_map = LinearMap(alpha_0, C, Q_s) intensity = 1.05e11 sigma_z = 0.0059958 gamma_t = 1. / np.sqrt(alpha_0) p0 = np.sqrt(gamma**2 - 1) * m_p * c beta_z = (linear_map.eta(dp=0, gamma=gamma) * linear_map.circumference / (2 * np.pi * linear_map.Qs)) epsn_x = 3.75e-6 # [m rad] epsn_y = 3.75e-6 # [m rad] epsn_z = 4 * np.pi * sigma_z**2 * p0 / (beta_z * e) bunch = generate_Gaussian6DTwiss( macroparticlenumber=n_macroparticles, intensity=intensity, charge=e, gamma=gamma, mass=m_p, circumference=C, alpha_x=0., beta_x=1., epsn_x=epsn_x, alpha_y=0., beta_y=1., epsn_y=epsn_y, beta_z=beta_z, epsn_z=epsn_z) # Scale to correct beta and alpha bunch.x *= np.sqrt(beta_x) bunch.xp = -alpha_x/np.sqrt(beta_x) * bunch.x + 1./np.sqrt(beta_x) * bunch.xp bunch.y = np.sqrt(beta_y)*bunch.y bunch.yp = -alpha_y/np.sqrt(beta_y) * bunch.y + 1./np.sqrt(beta_y) * bunch.yp bunch.x += dispx * bunch.dp bunch.y += dispy * bunch.dp return bunch
def test_linear_map_cleans_slices(self): '''Tests whether the slice_sets are deleted when the track() method of the LinearMap is called ''' circumference = 1. Qs = 0.012 linear_map = LinearMap(self.alpha_array, circumference, Qs, printer=AccumulatorPrinter()) beam = self.create_all1_bunch() sliceset_mock = {'mock': 42} beam._slice_sets = sliceset_mock linear_map.track(beam) self.assertFalse(beam._slice_sets, 'slice_sets not deleted after ' + 'calling LinearMap.track() [changing the ' + 'z-coordinates of the beam]')
def test_linear_map_track(self): '''Tests whether only the dp and z coordinates are modified when applying the track() method of LinearMap ''' circumference = 1. Qs = 0.012 linear_map = LinearMap(self.alpha_array, circumference, Qs) beam = self.create_all1_bunch() beam2 = self.create_all1_bunch() linear_map.track(beam) self.assertTrue(np.allclose(beam.x,beam2.x), 'x coord of beam has changed in LinearMap.track()') self.assertTrue(np.allclose(beam.y,beam2.y), 'y coord of beam has changed in LinearMap.track()') self.assertTrue(np.allclose(beam.xp,beam2.xp), 'xp coord of beam has changed in LinearMap.track()') self.assertTrue(np.allclose(beam.yp,beam2.yp), 'yp coord of beam has changed in LinearMap.track()')
def create_bunch_with_params(self,alpha_x, beta_x, disp_x, gamma): np.random.seed(0) beta_y = beta_x alpha_y = alpha_x disp_y = disp_x alpha0= [0.00308] C = 6911. Qs = 0.017 epsn_x = 3.75e-6 epsn_y = 3.75e-6 linear_map = LinearMap(alpha0, Qs, C) # then transform... intensity = 1.05e11 sigma_z = 0.23 gamma_t = 1. / np.sqrt(linear_map.alpha_array[0]) p0 = np.sqrt(gamma**2 - 1) * m_p * c beta_z = np.abs((linear_map.eta(dp=0, gamma=gamma) * linear_map.circumference / (2 * np.pi * linear_map.Qs))) epsn_z = 4 * np.pi * sigma_z**2 * p0 / (beta_z * e) #print ('epsn_z: ' + str(epsn_z)) bunch = generate_Gaussian6DTwiss( macroparticlenumber=10000, intensity=intensity, charge=e, gamma=gamma, mass=m_p, circumference=linear_map.circumference, alpha_x=0., beta_x=1., epsn_x=epsn_x, alpha_y=0., beta_y=1., epsn_y=epsn_y, beta_z=beta_z, epsn_z=epsn_z) # Scale to correct beta and alpha xx = bunch.x.copy() yy = bunch.y.copy() bunch.x *= np.sqrt(beta_x) bunch.xp = -alpha_x/np.sqrt(beta_x) * xx + 1./np.sqrt(beta_x) * bunch.xp bunch.y *= np.sqrt(beta_y) bunch.yp = -alpha_y/np.sqrt(beta_y) * yy + 1./np.sqrt(beta_y) * bunch.yp bunch.x += disp_x * bunch.dp bunch.y += disp_y * bunch.dp return bunch
afile = open('bunch', 'wb') pickle.dump(bunch, afile) afile.close() # =================================== # CREATE TRANVERSE AND LONGITUDINAL MAPS # ================================== scale_factor = 2*bunch.p0 # for detuning coefficients transverse_map = TransverseMap(s, alpha_x, beta_x, D_x, alpha_y, beta_y, D_y, Q_x, Q_y, [Chromaticity(Qp_x, Qp_y), AmplitudeDetuning(app_x*scale_factor, app_y*scale_factor, app_xy*scale_factor)]) longitudinal_map = LinearMap([alpha], circumference, Q_s) # ====================================================================== # SET UP ACCELERATOR MAP AND START TRACKING # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ t0 = time.clock() #reload object from file file2 = open('bunch', 'rb') bunch = pickle.load(file2) file2.close() print('--> Begin tracking...')
from PyHEADTAIL.trackers.detuners import Chromaticity, AmplitudeDetuning from PyHEADTAIL.trackers.transverse_tracking import TransverseMap from PyHEADTAIL.trackers.simple_long_tracking import RFSystems, LinearMap import matplotlib.pyplot as plt n_turns = 1000 # 1000 turns are enough for the NAFF algorithm to compute the tune # 1. CREATE ONE TURN MAP transverse_map = TransverseMap( pp.s, pp.alpha_x, pp.beta_x, pp.D_x, pp.alpha_y, pp.beta_y, pp.D_y, pp.Q_x, pp.Q_y, [ Chromaticity(pp.Qp_x, pp.Qp_y), AmplitudeDetuning(pp.app_x, pp.app_y, pp.app_xy) ]) longitudinal_map = LinearMap([pp.alpha], pp.circumference, pp.Q_s) one_turn_map = [transverse_map[0]] + [longitudinal_map] # 2. LOAD OBJECTS FROM FILES, BUNCH AND NOISE KICKS bfile = open('input/bunch', 'rb') bunch = pickle.load(bfile) bfile.close() # calculate initial actions Jx = 1 / 2 * ((1 + pp.alpha_x**2) / pp.beta_x * bunch.x**2 + 2 * pp.alpha_x * bunch.x * bunch.xp + pp.beta_x * bunch.xp**2) Jy = 1 / 2 * ((1 + pp.alpha_y**2) / pp.beta_y * bunch.y**2 + 2 * pp.alpha_y * bunch.y * bunch.yp + pp.beta_y * bunch.yp**2) bfile = open('input/ampKicks', 'rb')