vector module

Define simple classes to lighten Particle.

class Vector(x=None, y=None, z=None, is_extrapolated=False)[source]

Bases: object

Hold a vector with three coordinates.

Parameters:
__init__(x=None, y=None, z=None, is_extrapolated=False)[source]

Create empty lists.

Parameters:
append(coords)[source]

Append new coordinates. Reset array.

Parameters:

coords (Sequence[float])

Return type:

None

reorder(ordered_time_idx)[source]

Sort coordinates by increasing time values.

Parameters:

ordered_time_idx (ndarray[tuple[int, ...], dtype[int64]])

Return type:

None

extrapolate(*args, **kwargs)[source]

Extrapolate vector one time step further.

Return type:

None

normalize()[source]

Normalize to proper units.

Return type:

None

property array: ndarray[tuple[int, ...], dtype[float64]]

2D array, of shape (N, 3) where N is number of time steps.

Note

array[10, 0]: x coordinate at 11th time step array[0, 10]: NO

property to_list: list[ndarray[tuple[int, ...], dtype[float64]]]

List of positions, each of size 3.

property last: ndarray[tuple[int, ...], dtype[float64]]

1D array containing last coordinates.

property first: ndarray[tuple[int, ...], dtype[float64]]

1D array containing first coordinates.

property n_steps: int

Return number of stored time steps.

property extrapolated: ndarray[tuple[int, ...], dtype[float64]]

Shortcut to self._extrapolated.array.

class Momentum(x=None, y=None, z=None, is_extrapolated=False)[source]

Bases: Vector

Specialized class for momentum.

Parameters:
__init__(x=None, y=None, z=None, is_extrapolated=False)[source]

Create empty lists.

Parameters:
extrapolate(known_times, desired_times, poly_fit_deg, n_points=3)[source]

Extrapolate the momentum.

Parameters:
  • known_times (NDArray) – 1D array containing x-data used for extrapolation.

  • desired_times (NDArray) – 1D array containing time momentum should be extrapolated on. Should not start at 0.

  • poly_fit_deg (int) – Degree of the polynomial fit.

  • n_points (int) – Number of time steps to extrapolate on.

Return type:

None

emission_energy(mass_eV)[source]

Get first energy in eV.

Parameters:

mass_eV (float)

Return type:

float

collision_energy(mass_eV)[source]

Get last energy in eV.

Parameters:

mass_eV (float)

Return type:

float

class Position(x=None, y=None, z=None, is_extrapolated=False)[source]

Bases: Vector

Specialized class for position.

Parameters:
extrapolate(momentum, delta_t)[source]

Extrapolate the position using the last known momentum.

This is a first-order approximation. We consider that the momentum is constant over desired_time. Not adapted to extrapolation on long time spans.

Todo

Check is position is normalized or not.

Parameters:
  • momentum (NDArray | Momentum) – 1D array containing last known momentum, adimensionned. You can also directly provide the Momentum instance.

  • delta_t (Iterable[float] | NDArray[np.float64]) – 1D array containing time at which position should be extrapolated. Should look like [delta, 2*delta, 3*delta].

Return type:

None

normalize()[source]

Change units to \(\mathrm{mm}\).

Return type:

None