core.beam_parameters.helper module
Define functions useful for beam parameters calculations.
For more information on the units that are used in this module, see Units and conventions.
- envelopes_from_sigma(phase_space_name: str, sigma: ndarray) ndarray
Compute the envelopes.
Units are \(mm\) for the position envelope in \([z-\delta]\), \([x-x']\), \([y-y']\). Units are \(%\) for the energy envelope in \([z-\delta]\), and \(mrad\) for \([x-x']\) and \([y-y']\).
- Parameters:
phase_space_name (str) – Name of the phase space, used to set the proper normalization.
sigma (np.ndarray) –
(n, 2, 2)
(or(2, 2)
) array holding \(\sigma\) beam matrix.
- Returns:
envelopes –
(n, 2)
(or(2, )
) array with position envelope in first column, energy envelope in second.- Return type:
np.ndarray
- envelopes_from_twiss_eps(twiss: ndarray, eps: ndarray | float) ndarray
Compute the envelopes from the Twiss parameters and emittance.
- Parameters:
twiss (np.ndarray) –
(n, 3)
(or(3, )
) array of Twiss parameters.eps (np.ndarray) –
(n, )
array of emittance. If the phase space is \([\phi-W]\), the emittance should be normalized. Else, it should be un-normalized.
- Returns:
envelopes –
(n, 2)
(or(2, )
) array with position envelope in first column, energy envelope in second.- Return type:
np.ndarray
- eps_from_other_phase_space(other_phase_space_name: str, phase_space_name: str, eps_other: ndarray, gamma_kin: ndarray, beta_kin: ndarray) tuple[ndarray, ndarray]
- eps_from_other_phase_space(other_phase_space_name: str, phase_space_name: str, eps_other: float, gamma_kin: float, beta_kin: float) tuple[float, float]
Convert emittance from another phase space.
Output emittance is normalized if input is, and is un-normalized if the input emittance is not normalized.
Warning
old funct returned eps with same normalisation state as given eps_other
- Parameters:
other_phase_space_name (str) – Name of the original phase space.
phase_space_name (str) – Name of the phase space, used to ensure correct normalization/denormalization.
eps_other (np.ndarray | float) –
(n, )
array (or float) of emittance of starting phase-space.gamma_kin (np.ndarray | float) –
(n, )
array (or float) of Lorentz gamma.beta_kin (np.ndarray | float) –
(n, )
array (or float) of Lorentz beta
- Returns:
eps_no_normalisation (np.ndarray | float) –
(n, )
array (or float) of emittance, not normalized.eps_normalized (np.ndarray | float) –
(n, )
array (or float) of emittance, normalized.
- eps_from_sigma(phase_space_name: str, sigma: ndarray, gamma_kin: ndarray, beta_kin: ndarray) tuple[ndarray, ndarray]
- eps_from_sigma(phase_space_name: str, sigma: ndarray, gamma_kin: float, beta_kin: float) tuple[float, float]
Compute emittance from \(\sigma\) beam matrix.
In the \([z-\delta]\) phase space, emittance is in \(\pi.\mathrm{mm.\%}\). In the transverse phase spaces, emittance is in \(\pi.\mathrm{mm.mrad}\). \(\sigma\) is always in SI units.
- Parameters:
phase_space_name (str) – Name of the phase space, used to apply proper normalization factor.
sigma (np.ndarray) –
(n, 2, 2)
(or(2, 2)
) \(\sigma\) beam matrix in SI units.gamma_kin (np.ndarray | float) –
(n, )
(or float) Lorentz gamma factor.beta_kin (np.ndarray | float) –
(n, )
(or float) Lorentz beta factor.
- Returns:
eps_no_normalisation (np.ndarray | float) –
(n, )
array (or float) of emittance, not normalized.eps_normalized (np.ndarray float) –
(n, )
array (or float) of emittance, normalized.
- mismatch_from_arrays(ref: ndarray, fix: ndarray, transp: bool = False) ndarray
Compute the mismatch factor between two ellipses.
- reconstruct_sigma(phase_space_name: str, sigma_00: ndarray, sigma_01: ndarray, eps: ndarray, tol: float = 1e-08, eps_is_normalized: bool = False, gamma_kin: ndarray | None = None, beta_kin: ndarray | None = None) ndarray
Set \(\sigma\) matrix from the two top components and emittance.
Inputs are in \(\mathrm{mm}\) and \(\mathrm{mrad}\), but the \(\sigma\) matrix is in SI units (\(\mathrm{m}\) and \(\mathrm{rad}\)).
See also
- Parameters:
phase_space_name (str) – Name of the phase space.
sigma_00 (np.ndarray) –
(n, )
array of top-left sigma matrix components.sigma_01 (np.ndarray) –
(n, )
array of top-right (bottom-left) sigma matrix components.eps (np.ndarray) –
(n, )
un-normalized emittance array, in units consistent withsigma_00
andsigma_01
.tol (float, optional) –
sigma_00
is set to np.nan where it is undertol
to avoidRuntimeWarning
. The default is1e-8
.eps_is_normalized (bool, optional) – To tell if the given emittance is already normalized. The default is True. In this case, it is de-normalized and
gamma_kin
must be provided.gamma_kin (np.ndarray | None, optional) – Lorentz gamma factor. The default is None. It is mandatory to give it if the emittance is given unnormalized.
beta_kin (np.ndarray | None, optional) – Lorentz beta factor. The default is None. In this case, we compute it from
gamma_kin
.
- Returns:
sigma –
(n, 2, 2)
full sigma matrix along the linac.- Return type:
np.ndarray
- resample_twiss_on_fix(z_ref: ndarray, twiss_ref: ndarray, z_fix: ndarray) ndarray
Interpolate ref Twiss on fix Twiss to compute mismatch afterwards.
- sigma_from_transfer_matrices(sigma_in: ndarray, tm_cumul: ndarray) ndarray
Compute the \(\sigma\) beam matrices over the linac.
sigma_in
and transfer matrices shall have same units, in the same phase space.- Parameters:
tm_cumul (np.ndarray) –
(n, 2, 2)
cumulated transfer matrices along the linac.sigma_in (np.ndarray) –
(2, 2)
\(\sigma\) beam matrix at the linac entrance.
- Returns:
sigma –
(n, 2, 2)
\(\sigma\) beam matrix along the linac.- Return type:
np.ndarray
- twiss_from_other_phase_space(other_phase_space_name: str, phase_space_name: str, twiss_other: ndarray, gamma_kin: ndarray | float, beta_kin: ndarray | float) ndarray
Compute Twiss parameters from Twiss parameters in another plane.
- Parameters:
other_phase_space_name (str) – Name of the original phase space.
phase_space_name (str) – Name of the phase space.
twiss_other (np.ndarray) –
(n, 3)
Twiss array from original phase space.gamma_kin (np.ndarray | float) –
(n, )
array (or float) of Lorentz gamma.beta_kin (np.ndarray | float) –
(n, )
array (or float) of Lorentz beta
- Returns:
twiss –
(n, 3)
array of Twiss parameters.- Return type:
np.ndarray
- twiss_from_sigma(phase_space_name: str, sigma: ndarray, eps_no_normalisation: ndarray | float, tol: float = 1e-08) ndarray
Compute the Twiss parameters using the \(\sigma\) matrix.
In the \([z-\delta]\) phase space, emittance and Twiss are in \(\mathrm{mm}\) and \(\mathrm{\%}\). In the transverse phase spaces, emittance and Twiss are in \(\mathrm{mm}\) and \(\mathrm{mrad}\). \(\sigma\) is always in SI units.
Todo
Would be better if all emittances had the same units? Check consistency with rest of the code…
Todo
Check if property setter work with the *= thingy
- Parameters:
phase_space_name (str) – Name of the phase space, used to set the proper normalization.
sigma (np.ndarray) –
(n, 2, 2)
array (or(2, 2)
) holding \(\sigma\) beam matrix.eps_no_normalisation (np.ndarray | float) –
(n, )
array (or float) of unnormalized emittance.tol (float, optional) –
eps_no_normalisation
is set to np.nan where it is undertol
to avoidRuntimeWarning
. The default is1e-8
.
- Returns:
twiss –
(n, 3)
(or(3, )
) array of Twiss parameters.- Return type:
np.ndarray