Skip to content

Physics

el_paso.physics

Functions:

el_paso.physics.en2pc

en2pc
en2pc
en2pc

Calculate the relativistic momentum (p*c) for a given total energy.

This function calculates the relativistic energy using the formula: $$ pc = \sqrt{(E/m_0c^2 + 1)^2 - 1} \cdot m_0c^2 $$ where \(E\) is the total energy, \(m_0c^2\) is the rest energy of the particle, and \(pc\) is the relativistic momentum.

Parameters:

Name Type Description Default
energy ndarray or float

The total energy in MeV.

required
species str

The species of particle ('electron', 'proton', 'helium', 'oxygen').

'electron'

Returns:

Type Description
float | NDArray[number]

np.ndarray or float: The calculated relativistic momentum times c (p*c).

Source code in el_paso/physics.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
def en2pc(energy: float | NDArray[np.number], species: ParticleLiteral = "electron") -> float | NDArray[np.number]:
    r"""Calculate the relativistic momentum (p*c) for a given total energy.

    This function calculates the relativistic energy using the formula:
    $$
    pc = \sqrt{(E/m_0c^2 + 1)^2 - 1} \cdot m_0c^2
    $$
    where $E$ is the total energy, $m_0c^2$ is the rest energy of the particle,
    and $pc$ is the relativistic momentum.

    Args:
        energy (np.ndarray or float): The total energy in MeV.
        species (str): The species of particle ('electron', 'proton', 'helium', 'oxygen').

    Returns:
        np.ndarray or float: The calculated relativistic momentum times c (p*c).

    """
    mc2 = rest_energy(species)
    # Calculate the relativistic energy

    return np.sqrt((energy / mc2 + 1) ** 2 - 1) * mc2

el_paso.physics.rest_energy

rest_energy

Return the rest energy for the input species.

Parameters:

Name Type Description Default
species str

The species of particle ('electron', 'proton', 'helium', 'oxygen').

required

Returns:

Type Description
float

np.ndarray or float: The rest energy of the species in MeV.

Raises:

Type Description
ValueError

If an unknown species is provided.

Source code in el_paso/physics.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def rest_energy(species: ParticleLiteral) -> float:
    """Return the rest energy for the input species.

    Args:
        species (str): The species of particle ('electron', 'proton', 'helium', 'oxygen').

    Returns:
        np.ndarray or float: The rest energy of the species in MeV.

    Raises:
        ValueError: If an unknown species is provided.
    """
    # Rest energy in MeV for different species
    rest_energies = {
        "electron": 0.511,  # MeV
        "proton": 938.272,  # MeV
        "helium": 3727.379,  # MeV (Helium-4 nucleus)
        "oxygen": 14958.9,  # MeV (Oxygen-16 nucleus)
    }

    # Set mc2 based on the species
    if species.lower() in rest_energies:
        mc2 = rest_energies[species.lower()]
    else:
        msg = f"Unknown species '{species}'. Valid options are 'electron', 'proton', 'helium', 'oxygen'."
        raise ValueError(msg)

    return mc2