core.beam_parameters.beam_parameters module

Gather the beam parameters of all the phase spaces.

For a list of the units associated with every parameter, see Units and conventions.

class BeamParameters(z_abs: ~numpy.ndarray, gamma_kin: ~numpy.ndarray, beta_kin: ~numpy.ndarray, sigma_in: ~numpy.ndarray | None = None, element_to_index: ~typing.Callable[[str | ~core.elements.element.Element, str | None], int | slice] = <function BeamParameters.<lambda>>)

Bases: InitialBeamParameters

Hold all emittances, envelopes, etc in various planes.

z_abs

Absolute position in the linac in m.

Type:

np.ndarray

gamma_kin

Lorentz gamma factor.

Type:

np.ndarray

beta_kin

Lorentz gamma factor.

Type:

np.ndarray

sigma_in

Holds the (6, 6) \(\sigma\) beam matrix at the entrance of the linac/portion of linac. The default is None.

Type:

np.ndarray | None, optional

zdelta, z, phiw, x, y, t

Holds beam parameters respectively in the \([z-z\delta]\), \([z-z']\), \([\phi-W]\), \([x-x']\), \([y-y']\) and \([t-t']\) planes.

Type:

PhaseSpaceBeamParameters

phiw99, x99, y99

Holds 99% beam parameters respectively in the \([\phi-W]\), \([x-x']\) and \([y-y']\) planes. Only used with multiparticle simulations.

Type:

PhaseSpaceBeamParameters

element_to_index

Takes an Element, its name, 'first' or 'last' as argument, and returns corresponding index. Index should be the same in all the arrays attributes of this class: z_abs, beam_parameters attributes, etc. Used to easily get the desired properties at the proper position.

Type:

Callable[[str | Element, str | None], int | slice]

__init__(z_abs: ~numpy.ndarray, gamma_kin: ~numpy.ndarray, beta_kin: ~numpy.ndarray, sigma_in: ~numpy.ndarray | None = None, element_to_index: ~typing.Callable[[str | ~core.elements.element.Element, str | None], int | slice] = <function BeamParameters.<lambda>>) None
__post_init__() None

Declare the phase spaces.

_create_tracewin_command(warn_missing_phase_space: bool = True) list[str]

Turn emittance, alpha, beta from the proper phase-spaces into command.

When phase-spaces were not created, we return np.nan which will ultimately lead TraceWin to take this data from its .ini file.

_get_phase_spaces(reference_beam_parameters: Self, phase_space_name: str, raise_missing_phase_space_error: bool, **mismatch_kw: bool) tuple[PhaseSpaceBeamParameters | None, PhaseSpaceBeamParameters | None]

Get the two phase spaces between which mismatch will be computed.

_set_mismatch_for_transverse(raise_missing_phase_space_error: bool = True, raise_missing_mismatch_error: bool = True, **mismatch_kw: bool) None

Set t mismatch as average of x and y.

beta_kin: ndarray
element_to_index(_pos)
gamma_kin: ndarray
get(*keys: str, to_numpy: bool = True, none_to_nan: bool = False, elt: Element | None = None, pos: str | None = None, phase_space_name: str | None = None, **kwargs: Any) Any

Shorthand to get attributes from this class or its attributes.

Notes

What is particular in this getter is that all PhaseSpaceBeamParameters attributes have attributes with the same name: twiss, alpha, beta, gamma, eps, envelope_pos and envelope_energy.

Hence, you must provide either a phase_space argument which shall be in IMPLEMENTED_PHASE_SPACES, either you must append the name of the phase space to the name of the desired variable with an underscore.

See also

has()

Parameters:
  • *keys (str) – Name of the desired attributes.

  • to_numpy (bool, optional) – If you want the list output to be converted to a np.ndarray. The default is True.

  • none_to_nan (bool, optional) – To convert None to np.nan. The default is True.

  • elt (Element | None, optional) – If provided, return the attributes only at the considered Element.

  • pos ('in' | 'out' | None) – If you want the attribute at the entry, exit, or in the whole Element.

  • phase_space_name (str | None, optional) – Phase space in which you want the key. The default is None. In this case, the quantities from the zdelta phase space are taken. Otherwise, it must be in IMPLEMENTED_PHASE_SPACES.

  • **kwargs (Any) – Other arguments passed to recursive getter.

Returns:

out – Attribute(s) value(s).

Return type:

Any

set_mismatches(reference_beam_parameters: Self, *phase_space_names: str, **mismatch_kw: bool) None

Compute and set mismatch in every possible phase space.

property sigma: ndarray

Give value of sigma.

sigma_in: ndarray | None = None
sub_sigma_in(phase_space_name: str) ndarray

Give the entry \(\sigma\) beam matrix in a single phase space.

Parameters:

phase_space_name ({'x', 'y', 'zdelta'}) – Name of the phase space from which you want the \(\sigma\) beam matrix.

Returns:

sigma(2, 2) \(\sigma\) beam matrix at the linac entrance, in a single phase space.

Return type:

np.ndarray

property tracewin_command: list[str]

Return the proper input beam parameters command.

z_abs: ndarray
_to_float_if_necessary(eps: float | ndarray, alpha: float | ndarray, beta: float | ndarray) tuple[float, float, float]

Ensure that the data given to TraceWin will be float.

Deprecated since version v3.2.2.3: eps, alpha, beta will always be arrays of size 1.