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.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
- pymadng_utils.physics.dp2pt(dp, beta0=1.0)[source]¶
Convert relative momentum deviation
dp/pto MAD-NGpt.Uses the cancellation-free identity
sqrt(a) - b = (a - b^2)/(sqrt(a) + b)to avoid catastrophic cancellation: the naivesqrt((1+dp)^2 + 1/beta0^2 - 1) - 1/beta0subtracts two ~1 quantities to yield a ~dp result, losing ~3 significant digits for smalldp(relative error up to ~1e-12). The rewritten numerator2*dp + dp^2carries no cancellation, giving machine-precision accuracy.>>> round(dp2pt(1e-3, beta0=0.519753), 8) 0.00051994
- pymadng_utils.physics.pt2dp(pt, beta0=1.0)[source]¶
Convert MAD-NG
ptto relative momentum deviationdp/p.Uses the cancellation-free identity
sqrt(a) - 1 = (a - 1)/(sqrt(a) + 1): the naivesqrt(1 + 2*pt/beta0 + pt^2) - 1loses ~3 significant digits for smallpt(it issqrt(1 + small) - 1), whereas the rewritten numerator2*pt/beta0 + pt^2has no cancellation and stays accurate to machine precision.>>> round(pt2dp(dp2pt(1e-3, 0.519753), 0.519753), 12) 0.001