factory module
Define a factory for the BeamParameters.
- class BeamParametersFactory(is_3d, is_multipart, beam_kwargs)[source]
Bases:
ABCDeclare factory method, that returns the
BeamParameters.Subclassed by every
BeamCalculator.- abstract factory_method(*args, **kwargs)[source]
Create the
BeamParametersobject.- Return type:
- _check_and_set_arrays(z_abs, gamma_kin)[source]
Ensure that inputs are arrays with proper shape, compute beta.
- _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:
beam_parameters (BeamParameters) – 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 (numpy.ndarray) – Lorentz gamma factor.
beta_kin (numpy.ndarray) – Lorentz beta factor.
- Return type:
- _set_only_emittance(beam_parameters, phase_space_names, emittances)[source]
Set only the emittance.
- _set_from_transfer_matrix(beam_parameters, phase_space_names, transfer_matrices, gamma_kin, beta_kin)[source]
Initialize phase spaces from their transfer matrices.
- Parameters:
beam_parameters (BeamParameters) – Object holding the different phase spaces.
phase_space_names (Sequence[str]) – Names of the phase spaces to initialize.
transfer_matrices (Sequence[numpy.ndarray]) – Transfer matrix corresponding to each phase space.
gamma_kin (numpy.ndarray) – Lorentz gamma factor.
beta_kin (numpy.ndarray) – Lorentz beta factor.
beam_kwargs (dict[str, Any]) – Configuration dictionary holding initial beam parameters.
- Return type:
- _set_transverse_from_x_and_y(beam_parameters, other_phase_space_names, phase_space_name)[source]
Initialize
t(transverse) phase space.
- _set_from_sigma(beam_parameters, phase_space_names, sigmas, gamma_kin, beta_kin)[source]
Initialize transfer matrices from \(\sigma\) beam matrix.
- _abc_impl = <_abc._abc_data object at 0x73dca8581700>
- class InitialBeamParametersFactory(is_3d, is_multipart, beam_kwargs)[source]
Bases:
ABCThis is used when creating new
ListOfElements.This factory is not subclassed. Only one instance should be created.
Todo
Remove the
is_3d,is_multipartas I always create the same object withTrue,True.- __init__(is_3d, is_multipart, beam_kwargs)[source]
Create factory and list of phase spaces to generate.
- factory_new(sigma_in, w_kin, z_abs=0.0)[source]
Create the beam parameters for the beginning of the linac.
- Parameters:
sigma_in (numpy.ndarray) – \(\sigma\) beam matrix.
w_kin (float) – Kinetic energy in MeV.
z_abs (float, optional) – Absolute position of the linac start. Should be 0, which is the default.
- Returns:
Beam parameters at the start of the linac.
- Return type:
- factory_subset(simulation_output, get_kw)[source]
Generate
InitialBeamParametersfor a linac portion.- Parameters:
- Returns:
Holds information on the beam at the beginning of the linac portion.
- Return type:
- _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:
- _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
getmethod 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_spacesfromselfis not defined inoriginal_beam_parameters, and is therefore not initializable. If True, we just skip it. If False and such a case happens, anAttributeErrorwill be raised.
- Returns:
initial_phase_spaces_kw – Keys are the name of the phase spaces. The values are other dictionaries, which keys-values are
InitialPhaseSpaceBeamParametersattributes.- Return type:
- _set_from_sigma(initial_beam_parameters, phase_space_names, sigmas)[source]
Initialize transfer matrices from \(\sigma\) beam matrix.
- _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 (float) – Lorentz gamma factor.
beta_kin (float) – Lorentz beta factor.
- Return type:
- _abc_impl = <_abc._abc_data object at 0x73dca8581440>