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 | ~lightwin.core.elements.element.Element, str | None], int | slice] = <function BeamParameters.<lambda> at 0x7f36f979d4e0>)

Bases: InitialBeamParameters

Hold all emittances, envelopes, etc in various planes.

Parameters:
  • z_abs (numpy.ndarray) – Absolute position in the linac in m.

  • gamma_kin (numpy.ndarray) – Lorentz gamma factor.

  • beta_kin (numpy.ndarray) – Lorentz gamma factor.

  • sigma_in (numpy.ndarray | None, optional) – Holds the (6, 6) \(\sigma\) beam matrix at the entrance of the linac/portion of linac. The default is None.

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

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

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

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

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

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

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

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

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

  • element_to_index (Callable[[str | Element, str | None], int | slice]) – 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.

z_abs: ndarray
gamma_kin: ndarray
beta_kin: ndarray
sigma_in: ndarray | None = None
element_to_index(_pos)
__post_init__() None

Declare the phase spaces.

get(*keys: str, to_numpy: bool = True, none_to_nan: bool = False, elt: Element | None = None, pos: Literal['in', 'out'] | None = None, phase_space_name: Literal['zdelta', 'z', 'phiw', 'x', 'y', 't', 'phiw99', 'x99', 'y99'] | None = None, **kwargs: Any) Any

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 PHASE_SPACES, either or ypu must append the name of the phase space to the name of the desired variable with an underscore.

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 (Literal["in", "out"] | None, optional) – If you want the attribute at the entry, exit, or in the whole Element. The default is None, in which case you get an array with keys from the start to the end of the 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 PHASE_SPACES.

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

Returns:

out – Attribute(s) value(s).

Return type:

Any

property sigma: ndarray

Give value of sigma.

sub_sigma_in(phase_space_name: Literal['x', 'y', 'zdelta']) ndarray

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

Parameters:

phase_space_name (Literal["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:

numpy.ndarray

property tracewin_command: list[str]

Return the proper input beam parameters command.

_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.

set_mismatches(reference_beam_parameters: Self, *phase_space_names: Literal['zdelta', 'z', 'phiw', 'x', 'y', 't', 'phiw99', 'x99', 'y99'], **mismatch_kw: bool) None

Compute and set mismatch in every possible phase space.

_get_phase_spaces(reference_beam_parameters: Self, phase_space_name: Literal['zdelta', 'z', 'phiw', 'x', 'y', 't', 'phiw99', 'x99', 'y99'], 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.

__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 | ~lightwin.core.elements.element.Element, str | None], int | slice] = <function BeamParameters.<lambda> at 0x7f36f979d4e0>) None
_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.