factory module
Define a factory for the BeamParameters.
- class BeamParametersFactory(is_3d: bool, is_multipart: bool)
Bases:
ABCDeclare factory method, that returns the
BeamParameters.Subclassed by every
BeamCalculator.- abstract factory_method(*args, **kwargs) BeamParameters
Create the
BeamParametersobject.
- _check_and_set_arrays(z_abs: ndarray | float, gamma_kin: ndarray | float) tuple[ndarray, ndarray, ndarray]
Ensure that inputs are arrays with proper shape, compute beta.
- _set_from_other_phase_space(beam_parameters: BeamParameters, other_phase_space_name: Literal['zdelta'], phase_space_names: Sequence[Literal['phiw', 'z']], gamma_kin: ndarray, beta_kin: ndarray) None
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.
- _set_only_emittance(beam_parameters: BeamParameters, phase_space_names: Sequence[str], emittances: Iterable[ndarray]) None
Set only the emittance.
- _set_from_transfer_matrix(beam_parameters: BeamParameters, phase_space_names: Sequence[str], transfer_matrices: Sequence[ndarray], gamma_kin: ndarray, beta_kin: ndarray) None
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.
- _set_transverse_from_x_and_y(beam_parameters: BeamParameters, other_phase_space_names: tuple[str, str], phase_space_name: str) None
Initialize
t(transverse) phase space.- Parameters:
beam_parameters (BeamParameters) – Object already holding the beam parameters in the
xandyphase spaces.
- _set_from_sigma(beam_parameters: BeamParameters, phase_space_names: Sequence[str], sigmas: Iterable[ndarray], gamma_kin: ndarray, beta_kin: ndarray) None
Initialize transfer matrices from \(\sigma\) beam matrix.
- _abc_impl = <_abc._abc_data object at 0x7fd3ce70c6c0>
- class InitialBeamParametersFactory(is_3d: bool, is_multipart: bool)
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: bool, is_multipart: bool) None
Create factory and list of phase spaces to generate.
- factory_new(sigma_in: ndarray, w_kin: float, z_abs: float = 0.0) InitialBeamParameters
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: SimulationOutput, get_kw: dict[str, Element | str | bool | None]) InitialBeamParameters
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: SimulationOutput, get_kw: dict[str, Element | str | bool | None]) dict[str, float]
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: BeamParameters, phase_space_names: Sequence[str], get_kw: dict[str, Element | str | bool | None], skip_missing_phase_spaces: bool) dict[str, dict[str, float | ndarray]]
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: InitialBeamParameters, phase_space_names: Sequence[str], sigmas: Iterable[ndarray]) None
Initialize transfer matrices from \(\sigma\) beam matrix.
- _set_from_other_phase_space(initial_beam_parameters: InitialBeamParameters, other_phase_space_name: Literal['zdelta'], phase_space_names: Sequence[Literal['phiw', 'z']]) None
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.
- _abc_impl = <_abc._abc_data object at 0x7fd3ce70c880>