TransferMap Class
Description
The TransferMap
class inherits from the Transformation
base class and implements a first-order (linear)
transformation of particle coordinates. It is designed to handle both main sections of elements and optionally
their entrance and exit edges, if the element supports them. The TransferMap
calculates new particle coordinates using
a first-order transfer matrix and translation vector.
Inheritance
- Inherits:
Transformation
Constructor
__init__(self, create_tm_param_func, delta_e_func, tm_type: TMTypes, length: float, delta_length: float = 0.0)
Parameters
- create_tm_param_func: A callback function for creating first-order transformation parameters (e.g., rotated transfer matrix, translation vector, etc.).
- delta_e_func (
Callable
): A callback function for calculating the energy change . - tm_type (
TMTypes
): Specifies the transformation type (MAIN
,ENTRANCE
, orEXIT
). - length (
float
): The length of the element for the main transformation. - delta_length (
float
, optional): Defines a partial length of the element if only a portion of it is considered. Defaults to0.0
.
Class Methods
from_element(cls, element: Element, tm_type: TMTypes = TMTypes.MAIN, delta_l=None, **params)
Creates a TransferMap
from a MagneticLattice
element.
It uses the element’s methods to generate transfer parameters for entrance, main, and exit transformations (where applicable).
Parameters
- element (
Element
): The beamline element for which theTransferMap
is created. - tm_type (
TMTypes
, optional): The transformation type (MAIN
,ENTRANCE
, orEXIT
). Defaults toMAIN
. - delta_l (
float
, optional): A partial length for the transformation. IfNone
, the entire element length is used. - params: Additional keyword parameters.
Returns
- A new
TransferMap
instance with the first-order transformation parameters derived from the element.
Instance Methods
map_function(self, X, energy: float) -> np.ndarray
Calculates the new particle coordinates by applying the first-order transformation.
- Retrieves the transformation parameters via
get_params(energy)
. - Calls
mul_p_array(X, energy=energy)
to apply the transformation.
Parameters
- X (
np.ndarray
): A array of phase-space coordinates . - energy (
float
): The beam energy.
Returns
- A transformed array of updated coordinates.
mul_p_array(self, rparticles, energy=0.) -> np.ndarray
Applies the first-order transformation directly to the given coordinates.
- Obtains parameters (rotated transfer matrix
R
and translation vectorB
). - Computes the updated coordinates .
- Overwrites
rparticles
with the updated coordinates.
Parameters
- rparticles (
np.ndarray
): The array of particle phase-space coordinates . - energy (
float
, optional): The beam energy. Defaults to0.
.
Returns
- The updated array
rparticles
.
multiply_with_tm(self, tm: 'TransferMap', length: float) -> 'TransferMap'
Combines two TransferMap
objects into a single new TransferMap
, effectively performing .
- Gets the combined transformation parameters from the product of the two transformations.
- Creates and returns a new
TransferMap
with the combined length and energy-change function.
Parameters
- tm (
TransferMap
): AnotherTransferMap
to be multiplied. - length (
float
): The combined length for the newTransferMap
.
Returns
- A new
TransferMap
instance that represents the product ofself
andtm
.
__mul__(self, m)
Implements the *
operator for TransferMap
objects.
- Parameters:
- m: Another object, such as
TransferMap
,Particle
, orTwiss
.
- m: Another object, such as
- Returns:
- The result of multiplying
m
with thisTransferMap
, which can be a transformed object or a newTransferMap
.
- The result of multiplying
- Raises:
- Exception: If
m
is not a recognized type or does not implement a compatiblemultiply_with_tm
method.
- Exception: If