beam_calculation.envelope_3d.transfer_matrices_p module

Define every element transfer matrix.

Units are taken exactly as in TraceWin, i.e. fifth line is z (m) and sixth line is dp/p.

Todo

3D field maps?

Todo

Maybe it would be clearer to compose r_xx, r_yy, r_zz. As an example, the zz_drift is used in several places.

Todo

Will be necessary to separate this module into several sub-packages

Todo

more math, less numpy. look at envelope 1d version

_focusing_strength(gradient: float, magnetic_rigidity: float) float

Compute focusing strength of the quadrupole.

_horizontal_defocusing_quadrupole(focusing_strength: float, delta_s: float, gamma_in_min2: float) ndarray

Transfer matrix of a quadrupole defocusing in horizontal plane.

_horizontal_focusing_quadrupole(focusing_strength: float, delta_s: float, gamma_in_min2: float) ndarray

Transfer matrix of a quadrupole focusing in horizontal plane.

_magnetic_rigidity(beta: float, gamma: float) float

Compute magnetic rigidity of particle.

_quadrupole_trigo_hyperbolic(focusing_strength: float, delta_s: float) tuple[float, float, float, float]

Pre-compute some parameters for the quadrupole transfer matrix.

Todo

As I am working on floats and not on np arrays, maybe the functions from the cmath package would be more adapted?

drift(gamma_in: float, delta_s: float, n_steps: int = 1, **kwargs) tuple[ndarray, ndarray, None]

Calculate the transfer matrix of a drift.

Parameters:
  • delta_s (float) – Size of the drift in mm.

  • gamma_in (float) – Lorentz gamma at entry of drift.

  • n_steps (int, optional) – Number of integration steps. The number of integration steps has no influence on the results. The default is one. It is different from unity when crossing a failed field map, as it allows to keep the same size of transfer_matrix and gamma_phi between nominal and fixed linacs.

Returns:

  • transfer_matrix (np.ndarray) – (n_steps, 6, 6) array containing the transfer matrices.

  • gamma_phi (np.ndarray) – (n_steps, 2) with Lorentz gamma in first column and relative phase in second column.

  • itg_field (None) – Dummy variable for consistency with the field map function.

e_func(z: float, e_spat: Callable[[float], float], phi: float, phi_0: float) float

Give the electric field at position z and phase phi.

The field is normalized and should be multiplied by k_e.

field_map_rk4(gamma_in: float, d_z: float, n_steps: int, omega0_rf: float, k_e: float, phi_0_rel: float, e_spat: Callable[[float], float], **kwargs) tuple[ndarray, ndarray, float]

Calculate the transfer matrix of a FIELD_MAP using Runge-Kutta.

quad(gamma_in: float, delta_s: float, gradient: float, **kwargs) tuple[ndarray, ndarray, None]

Calculate the transfer matrix of a quadrupole.

Parameters:
  • delta_s (float) – Size of the drift in m.

  • gamma_in (float) – Lorentz gamma at entry of drift.

  • n_steps (int, optional) – Number of integration steps. The number of integration steps has no influence on the results. The default is one. It is different from unity when crossing a failed field map, as it allows to keep the same size of transfer_matrix and gamma_phi between nominal and fixed linacs.

  • gradient (float) – Quadrupole gradient in T/m.

Returns:

  • transfer_matrix (np.ndarray) – (1, 6, 6) array containing the transfer matrices.

  • gamma_phi (np.ndarray) – (1, 2) with Lorentz gamma in first column and relative phase in second column.

  • itg_field (None) – Dummy variable for consistency with the field map function.

thin_lense(gamma_in: float, gamma_out: float, gamma_phi_m: ndarray, half_dz: float, delta_gamma_m_max: float, phi_0: float, omega0_rf: float, delta_e_max: float) ndarray

Thin lense approximation: drift-acceleration-drift.

Parameters:
  • gamma_in (float) – gamma at entrance of first drift.

  • gamma_out (float) – gamma at exit of first drift.

  • gamma_phi_m (np.ndarray) – gamma and phase at the thin acceleration drift.

  • half_dz (float) – Half a spatial step in m.

  • delta_gamma_m_max (float) – Max gamma increase if the cos(phi + phi_0) of the acc. field is 1.

  • phi_0 (float) – Input phase of the cavity.

  • omega0_rf (float) – Pulsation of the cavity.

  • delta_e_max (float) – Derivative of the electric field.

Returns:

transfer_matrix – Transfer matrix of the thin lense.

Return type:

np.ndarray