line = xt.Line.from_dict(dict_line_xtrack)

partCO = xp.Particles.from_dict(dict_line_xtrack['particle_on_tracker_co'])

(x_tbt_sixtrack, px_tbt_sixtrack, y_tbt_sixtrack, py_tbt_sixtrack,
 zeta_tbt_sixtrack, delta_tbt_sixtrack, extra) = hp.track_particle_sixtrack(
        partCO=partCO, Dx_wrt_CO_m=np.array(displace_x),
        Dpx_wrt_CO_rad=0,
        Dy_wrt_CO_m=np.array(displace_y), Dpy_wrt_CO_rad=0.,
        Dzeta_wrt_CO_m=0., Ddelta_wrt_CO=0., n_turns=num_turns,
        input_folder='../')

tracker = xt.Tracker(line=line)

particles = xp.build_particles(particle_on_co=partCO,
        mode='shift',
        x=np.array(displace_x),
        y=np.array(displace_y))

tracker.track(particles, turn_by_turn_monitor=True, num_turns=num_turns)

print('Xtrack')
print(tracker.record_last_track.x.transpose())
print('Sixtrack')
print(x_tbt_sixtrack)

assert np.allclose(tracker.record_last_track.x[0, :], x_tbt_sixtrack[:,0],
       rtol=1e-15, atol=9e-11)
assert np.allclose(tracker.record_last_track.y[0, :], y_tbt_sixtrack[:,0],
       rtol=1e-15, atol=9e-11)
assert np.allclose(tracker.record_last_track.delta[0, :], delta_tbt_sixtrack[:,0],
       rtol=1e-15, atol=5e-11)
WW = np.array(line_dict['WW_finite_diffs'])
WWinv = np.array(line_dict['WWInv_finite_diffs'])
assert np.max(np.abs(np.dot(WW, WWinv) - np.eye(6))) < 1e-10

ampl_sigmas = 0.2
norm_emit_x = 2.5e-6
geom_emit_x = norm_emit_x / particles.beta0 / particles.gamma0

n_part = 100
theta = np.linspace(0, 2 * np.pi, n_part)
x_norm = ampl_sigmas * np.sqrt(geom_emit_x) * np.cos(theta)
px_norm = ampl_sigmas * np.sqrt(geom_emit_x) * np.sin(theta)

particles_matched = xp.build_particles(particle_on_co=partCO,
                                       x_norm=x_norm,
                                       px_norm=px_norm,
                                       R_matrix=np.array(
                                           line_dict['RR_finite_diffs']))
particles_test = particles_matched.copy()
tracker.track(particles_test, num_turns=10)

i_matched = np.argmax(particles_matched.x)
i_test = np.argmax(particles_test.x)
assert np.abs(particles_test.x[i_test] - particles_matched.x[i_matched]) < 1e-6
assert np.abs(particles_test.px[i_test] -
              particles_matched.px[i_matched]) < 1e-7

import matplotlib.pyplot as plt
plt.close('all')
plt.figure(1)
plt.plot(particles_matched.x, particles_matched.px)
Esempio n. 3
0
    bb.q0 = 0

# # Switch off all beam-beam lenses
crabs, crab_names = ltest.get_elements_of_type([xt.RFMultipole])
#for cc in crabs:
#    cc.pn = [-90]
#    cc.ps = [-90]

# for cc in crabs:
#     cc.knl[0] *= -1

with open('../optics_orbit_at_start_ring_from_madx.json', 'r') as fid:
    ddd = json.load(fid)
partco = xp.Particles.from_dict(ddd['particle_on_madx_co'])
z_slices = s_rel * 2.0
partco = xp.build_particles(particle_on_co=partco, mode='shift', zeta=z_slices)

tracker = xt.Tracker(line=ltest)
tracker.track(partco, turn_by_turn_monitor='ONE_TURN_EBE')
first_turn = tracker.record_last_track

tracker.track(partco, turn_by_turn_monitor='ONE_TURN_EBE')
second_turn = tracker.record_last_track

plt.figure(2)
axcox = plt.subplot(2, 1, 1)
axcoy = plt.subplot(2, 1, 2, sharex=axcox)
plt.suptitle('Check closed orbit 2 turns')
axcox.plot(first_turn.s[iho, :], first_turn.x[iho, :])
axcox.plot(second_turn.s[iho, :], second_turn.x[iho, :])