factory module

Define a factory for the BeamParameters.

class BeamParametersFactory(is_3d, is_multipart, beam_kwargs)[source]

Bases: ABC

Declare factory method, that returns the BeamParameters.

Subclassed by every BeamCalculator.

Parameters:
__init__(is_3d, is_multipart, beam_kwargs)[source]

Initialize the class.

Parameters:
Return type:

None

_determine_phase_spaces(is_3d, is_multipart)[source]
Parameters:
Return type:

tuple[str, ...]

abstractmethod factory_method(*args, **kwargs)[source]

Create the BeamParameters object.

Return type:

BeamParameters

_check_and_set_arrays(z_abs, gamma_kin)[source]

Ensure that inputs are arrays with proper shape, compute beta.

Parameters:
Return type:

tuple[ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]], ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]

_check_sigma_in(sigma_in)[source]

Change shape of sigma_in if necessary.

Parameters:

sigma_in (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]])

Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]

_set_from_other_phase_space(beam_parameters, other_phase_space_name, phase_space_names, gamma_kin, beta_kin)[source]

Instantiate a phase space from another one.

Parameters:
Return type:

None

_set_only_emittance(beam_parameters, phase_space_names, emittances)[source]

Set only the emittance.

Parameters:
Return type:

None

_set_from_transfer_matrix(beam_parameters, phase_space_names, transfer_matrices, gamma_kin, beta_kin)[source]

Initialize phase spaces from their transfer matrices.

Parameters:
Return type:

None

_set_transverse_from_x_and_y(beam_parameters, other_phase_space_names, phase_space_name)[source]

Initialize t (transverse) phase space.

Parameters:
  • beam_parameters (BeamParameters) – Object already holding the beam parameters in the x and y phase spaces.

  • other_phase_space_names (tuple[str, str])

  • phase_space_name (str)

Return type:

None

_set_from_sigma(beam_parameters, phase_space_names, sigmas, gamma_kin, beta_kin)[source]

Initialize transfer matrices from \(\sigma\) beam matrix.

Parameters:
Return type:

None

_abc_impl = <_abc._abc_data object at 0x7318fb342440>
class InitialBeamParametersFactory(is_3d, is_multipart, beam_kwargs)[source]

Bases: ABC

This is used when creating new ListOfElements.

This factory is not subclassed. Only one instance should be created.

Todo

Remove the is_3d, is_multipart as I always create the same object with True, True.

Parameters:
__init__(is_3d, is_multipart, beam_kwargs)[source]

Create factory and list of phase spaces to generate.

Parameters:
  • is_3d (bool) – If the simulation is in 3D.

  • is_multipart (bool) – If the simulation is a multiparticle.

  • beam_kwargs (BeamKwargs) – Configuration dict holding some constants of the beam.

Return type:

None

factory_new(sigma_in, w_kin, z_abs=0.0)[source]

Create the beam parameters for the beginning of the linac.

Parameters:
  • sigma_in (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – \(\sigma\) beam matrix.

  • w_kin (float) – Kinetic energy in MeV.

  • z_abs (float, default: 0.0) – Absolute position of the linac start. Should be 0, which is the default.

Returns:

Beam parameters at the start of the linac.

Return type:

InitialBeamParameters

factory_subset(simulation_output, get_kw)[source]

Generate InitialBeamParameters for a linac portion.

Parameters:
  • simulation_output (SimulationOutput) – Object from which the beam parameters data will be taken.

  • get_kw (dict[str, Element | str | bool | None]) – dict that can be passed to the get method and that will return the data at the beginning of the linac portion.

Returns:

Holds information on the beam at the beginning of the linac portion.

Return type:

InitialBeamParameters

_initial_beam_parameters_kw(simulation_output, get_kw)[source]

Generate the kw to instantiate the InitialBeamParameters.

Parameters:
Returns:

Dictionary of keyword arguments for InitialBeamParameters.

Return type:

dict[str, float]

_initial_phase_space_beam_parameters_kw(original_beam_parameters, phase_space_names, get_kw, skip_missing_phase_spaces)[source]

Get all beam data at proper position and store it in a dict.

Parameters:
  • original_beam_parameters (BeamParameters) – Object holding original beam parameters.

  • get_kw (dict[str, Element | str | bool | None]) – dict that can be passed to the get method and that will return the data at the beginning of the linac portion.

  • skip_missing_phase_spaces (bool) – To handle when a phase space from phase_spaces from self is not defined in original_beam_parameters, and is therefore not initializable. If True, we just skip it. If False and such a case happens, an AttributeError will be raised.

  • phase_space_names (Sequence[str])

Return type:

dict[str, dict[str, float | ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]]]

Returns:

Keys are the name of the phase spaces. The values are other dictionaries, which keys-values are InitialPhaseSpaceBeamParameters attributes.

_set_from_sigma(initial_beam_parameters, phase_space_names, sigmas)[source]

Initialize transfer matrices from \(\sigma\) beam matrix.

Parameters:
Return type:

None

_set_from_other_phase_space(initial_beam_parameters, other_phase_space_name, phase_space_names)[source]

Instantiate a phase space from another one.

Parameters:
  • initial_beam_parameters (InitialBeamParameters) – Object holding the beam parameters in different phase spaces.

  • other_phase_space_name (Literal['zdelta']) – Name of the phase space from which the new phase space will be initialized.

  • phase_space_names (Sequence[Literal['phiw', 'z']]) – Name of the phase spaces that will be created.

  • gamma_kin – Lorentz gamma factor.

  • beta_kin – Lorentz beta factor.

Return type:

None

_abc_impl = <_abc._abc_data object at 0x7318fb341d40>