with open('particle_on_CO.pkl', 'rb') as fid:
    partCO = pickle.load(fid)

part = pysixtrack.Particles(**partCO)

# Track a particle to get betas
part.x += 1e-5
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,

with open('line.pkl', 'rb') as fid:
    line = pickle.load(fid)

with open('particle_on_CO.pkl', 'rb') as fid:
    partCO = pickle.load(fid)

part = pysixtrack.Particles(**partCO)

# Track a particle to get betas
part.x += 1e-5
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)
Ejemplo n.º 3
0
with open('particle_on_CO.pkl', 'rb') as fid:
    partCO = pickle.load(fid)

with open('DpxDpy_for_footprint.pkl', 'rb') as fid:
    temp_data = pickle.load(fid)

xy_norm = temp_data['xy_norm']
DpxDpy_wrt_CO = temp_data['DpxDpy_wrt_CO']


if track_with == 'PySixtrack':

    part = pysixtrack.Particles(**partCO)

    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=DpxDpy_wrt_CO[:, :, 0].flatten(),
        Dy_wrt_CO_m=0, Dpy_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 1].flatten(),
        Dsigma_wrt_CO_m=0., Ddelta_wrt_CO=0., n_turns=n_turns, verbose=True)

    info = track_with

elif track_with == 'Sixtrack':
    x_tbt, px_tbt, y_tbt, py_tbt, sigma_tbt, delta_tbt = hp.track_particle_sixtrack(
        partCO=partCO, Dx_wrt_CO_m=0., Dpx_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 0].flatten(),
        Dy_wrt_CO_m=0, Dpy_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 1].flatten(),
        Dsigma_wrt_CO_m=0., Ddelta_wrt_CO=0., n_turns=n_turns)
    info = track_with

elif track_with == 'Sixtracklib':
    x_tbt, px_tbt, y_tbt, py_tbt, sigma_tbt, delta_tbt = hp.track_particle_sixtracklib(
        line=line, partCO=partCO, Dx_wrt_CO_m=0., Dpx_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 0].flatten(),
        Dy_wrt_CO_m=0., Dpy_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 1].flatten(),
with open('particle_on_CO.pkl', 'rb') as fid:
    partCO = pickle.load(fid)

with open('DpxDpy_for_footprint.pkl', 'rb') as fid:
    temp_data = pickle.load(fid)

xy_norm = temp_data['xy_norm']
DpxDpy_wrt_CO = temp_data['DpxDpy_wrt_CO']


if track_with == 'PySixtrack':

    part = pysixtrack.Particles(**partCO)

    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=DpxDpy_wrt_CO[:, :, 0].flatten(),
        Dy_wrt_CO_m=0, Dpy_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 1].flatten(),
        Dsigma_wrt_CO_m=0., Ddelta_wrt_CO=0., n_turns=n_turns, verbose=True)

elif track_with == 'Sixtrack':
    x_tbt, px_tbt, y_tbt, py_tbt, sigma_tbt, delta_tbt = hp.track_particle_sixtrack(
        partCO=partCO, Dx_wrt_CO_m=0., Dpx_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 0].flatten(),
        Dy_wrt_CO_m=0, Dpy_wrt_CO_rad=DpxDpy_wrt_CO[:, :, 1].flatten(),
        Dsigma_wrt_CO_m=0., Ddelta_wrt_CO=0., n_turns=n_turns)

else:
    raise ValueError('What?!')

n_part = x_tbt.shape[1]
Qx = np.zeros(n_part)
Qy = np.zeros(n_part)
    partCO = pickle.load(fid)

Dx_m = 1e-4
Dpx_rad = 1e-6
Dy_m = 2e-4
Dpy_rad = 3e-6
Dsigma_m = 2e-3
Ddelta = 0.

part = pysixtrack.Particles(**partCO)

dict_tbt = {}

print('Tracking PyST')
x_tbt_pyST, px_tbt_pyST, y_tbt_pyST, py_tbt_pyST, sigma_tbt_pyST, delta_tbt_pyST = hp.track_particle_pysixtrack(
    line, part=part, Dx_wrt_CO_m=Dx_m, Dpx_wrt_CO_rad=Dpx_rad,
    Dy_wrt_CO_m=Dy_m, Dpy_wrt_CO_rad=Dpy_rad,
    Dsigma_wrt_CO_m=Dsigma_m, Ddelta_wrt_CO=Ddelta, n_turns=n_turns, verbose=True)
dict_tbt['PyST'] = {kk:vv for kk,vv in zip('x y px py sigma delta'.split(), 
         [x_tbt_pyST, px_tbt_pyST, y_tbt_pyST, py_tbt_pyST, sigma_tbt_pyST, delta_tbt_pyST])}
print('Tracking ST')
x_tbt_ST, px_tbt_ST, y_tbt_ST, py_tbt_ST, sigma_tbt_ST, delta_tbt_ST = hp.track_particle_sixtrack(
    partCO=partCO, Dx_wrt_CO_m=np.array([Dx_m, Dx_m]), Dpx_wrt_CO_rad=Dpx_rad,
    Dy_wrt_CO_m=Dy_m, Dpy_wrt_CO_rad=Dpy_rad,
    Dsigma_wrt_CO_m=Dsigma_m, Ddelta_wrt_CO=Ddelta, n_turns=n_turns)
dict_tbt['ST'] = {kk:vv for kk,vv in zip('x y px py sigma delta'.split(), 
         [x_tbt_ST, px_tbt_ST, y_tbt_ST, py_tbt_ST, sigma_tbt_ST, delta_tbt_ST])}
print('Tracking STlib')
x_tbt_STl, px_tbt_STl, y_tbt_STl, py_tbt_STl, sigma_tbt_STl, delta_tbt_STl = hp.track_particle_sixtracklib(
    line, partCO=partCO, Dx_wrt_CO_m=np.array([Dx_m, Dx_m]), Dpx_wrt_CO_rad=Dpx_rad,
    Dy_wrt_CO_m=Dy_m, Dpy_wrt_CO_rad=Dpy_rad,
    Dsigma_wrt_CO_m=Dsigma_m, Ddelta_wrt_CO=Ddelta, n_turns=n_turns)
    Ddelta_wrt_CO=Ddelta,
    n_turns=n_turns)
dict_tbt['STlib'] = {
    kk: vv
    for kk, vv in zip('x y px py sigma delta'.split(), [
        x_tbt_STl, px_tbt_STl, y_tbt_STl, py_tbt_STl, sigma_tbt_STl,
        delta_tbt_STl
    ])
}
print('Tracking PyST')
x_tbt_pyST, px_tbt_pyST, y_tbt_pyST, py_tbt_pyST, sigma_tbt_pyST, delta_tbt_pyST = hp.track_particle_pysixtrack(
    line,
    part=part,
    Dx_wrt_CO_m=Dx_m,
    Dpx_wrt_CO_rad=Dpx_rad,
    Dy_wrt_CO_m=Dy_m,
    Dpy_wrt_CO_rad=Dpy_rad,
    Dsigma_wrt_CO_m=Dsigma_m,
    Ddelta_wrt_CO=Ddelta,
    n_turns=n_turns,
    verbose=True)
dict_tbt['PyST'] = {
    kk: vv
    for kk, vv in zip('x y px py sigma delta'.split(), [
        x_tbt_pyST, px_tbt_pyST, y_tbt_pyST, py_tbt_pyST, sigma_tbt_pyST,
        delta_tbt_pyST
    ])
}

plt.close('all')
fig1 = plt.figure(1, figsize=(8 * 1.5, 6 * 1.2))