Physics utilities

pymadng_utils.physics contains particle rest masses and numerically stable conversions between relative momentum deviation dp/p and MAD-NG’s longitudinal coordinate pt. Pass the reference-beam relativistic beta to dp2pt and pt2dp; accelerator descriptors and MAD-NG interfaces provide beam-aware wrappers.

Particle masses and dp/p <-> pt conversions, following MAD-NG’s definitions.

pymadng_utils.physics.particle_mass(particle)[source]

Return the MAD-NG particle mass in GeV.

Parameters:

particle (str)

Return type:

float

pymadng_utils.physics.beta_from_energy(energy, particle='proton')[source]

Compute relativistic beta from total energy [GeV] and particle name.

>>> round(beta_from_energy(0.93827208816 + 0.160), 6)  # PSB flat bottom
0.519753
Parameters:
Return type:

float

pymadng_utils.physics.dp2pt(dp, beta0=1.0)[source]

Convert relative momentum deviation dp/p to MAD-NG pt.

Uses the cancellation-free identity sqrt(a) - b = (a - b^2)/(sqrt(a) + b) to avoid catastrophic cancellation: the naive sqrt((1+dp)^2 + 1/beta0^2 - 1) - 1/beta0 subtracts two ~1 quantities to yield a ~dp result, losing ~3 significant digits for small dp (relative error up to ~1e-12). The rewritten numerator 2*dp + dp^2 carries no cancellation, giving machine-precision accuracy.

>>> round(dp2pt(1e-3, beta0=0.519753), 8)
0.00051994
Parameters:
Return type:

float

pymadng_utils.physics.pt2dp(pt, beta0=1.0)[source]

Convert MAD-NG pt to relative momentum deviation dp/p.

Uses the cancellation-free identity sqrt(a) - 1 = (a - 1)/(sqrt(a) + 1): the naive sqrt(1 + 2*pt/beta0 + pt^2) - 1 loses ~3 significant digits for small pt (it is sqrt(1 + small) - 1), whereas the rewritten numerator 2*pt/beta0 + pt^2 has no cancellation and stays accurate to machine precision.

>>> round(pt2dp(dp2pt(1e-3, 0.519753), 0.519753), 12)
0.001
Parameters:
Return type:

float