Skip to content

fix(thermo): n_H_0 should use hydrogen atom mass, not proton mass - #18

Open
MinhMPA wants to merge 2 commits into
smsharma:mainfrom
MinhMPA:fix/n-H-0-mass
Open

fix(thermo): n_H_0 should use hydrogen atom mass, not proton mass#18
MinhMPA wants to merge 2 commits into
smsharma:mainfrom
MinhMPA:fix/n-H-0-mass

Conversation

@MinhMPA

@MinhMPA MinhMPA commented May 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes a one-line bug in clax/thermodynamics.py that biased the tau_reioz_reio inversion at fiducial Planck. The n_H_0 calculation used the proton mass m_p where it should have used the hydrogen atom mass m_H.

CLASS uses _m_H_ = 1.673575e-27 kg at thermodynamics.c:812. clax's RECFAST block (line 534) already uses m_H = 1.67353284e-27 kg correctly. Only the tau_reio inversion site (line 710) was using m_p; this PR restores consistency.

Why it matters

m_H / m_p = 1.000570 → clax's n_H_0 was 0.057% too large at this site → _tau_reio_for_zreio overshot the target by 0.057% → bisection converged to a z_reio that was too low (clax 7.6885 vs CLASS 7.6918).

That 0.0033 absolute offset in z_reio translates to ~1% systematic in x_e across the reionization transition (z=7-9) and ~1% in g(τ) at the secondary visibility peak — propagating to most of the EE ℓ=20-30 residual the README has been attributing to "RECFAST visibility function bias".

Empirical impact at Planck 2018 fiducial

Quantity Pre-fix Post-fix CLASS reference
z_reio (tau_reio = 0.0544) 7.6885 7.6915 7.6918
x_e(z=8) 0.2397 (-1.06%) 0.2420 (-0.11%) 0.2423
g(τ) at z=8 -1.00% vs CLASS -0.11% vs CLASS
g(τ) at z=1090 (recomb peak) +0.002% unchanged

The fix closes 90% of the z_reio offset. The remaining ~3e-4 absolute residual is from the small numerical difference between clax's m_H = 1.67353284e-27 kg (atomic mass of 1H-1) and CLASS's _m_H_ = 1.673575e-27 kg (rounded value); both agree to 2.5e-5 relative, well below any current accuracy target.

Changes

  • clax/constants.py: add m_H_kg = 1.67353284e-27 constant with a comment flagging that m_p is not the right choice here.
  • clax/thermodynamics.py:710: replace local _m_p with const.m_H_kg in the n_H_0 formula used by _find_z_reio.

Diff is +13 / -2 across 2 files.

Note on README "Known limitations" framing

The README currently says:

EE l=20-30: ~0.2% from RECFAST visibility function bias. HyRec recombination would improve to sub-0.1%.

This is misleading. Empirically (separate investigation, see docs/hyrex_integration_assessment.md on investigate-hyrex-integration branch):

  • clax/RECFAST x_e and HyRec agree to 0.09% at z=1090 (the recombination peak where the visibility function lives). RECFAST physics is fine.
  • The 0.2% EE bias is from this n_H_0 bug, upstream of recombination in the tau_reio inversion. HyRec/HyRex would not have fixed it because the wrong z_reio would still be passed downstream.

After this PR lands, the EE ℓ=20-30 limitation should be reassessed — expect the residual to drop to <0.05%. A follow-up README update is recommended but left out of this PR to keep the change focused.

Test plan

  • pytest tests/test_thermodynamics.py -v9/9 pass
  • pytest tests/test_background.py tests/test_harmonic.py tests/test_lensing.py -v --fast37/37 pass (15 background + 11 harmonic + 11 lensing)

Independence from other open PRs

The tau_reio bisection in `_find_z_reio` computes n_H_0 with the proton
mass m_p = 1.672621637e-27 kg.  CLASS uses the hydrogen atom mass m_H =
1.673575e-27 kg (thermodynamics.c:812, also _m_H_ in thermodynamics.h).
clax's RECFAST block (line 534) already uses m_H = 1.67353284e-24 g
correctly; this commit makes the tau_reio site consistent.

m_H/m_p = 1.000570 -> n_H_0 was 0.057% too large -> tau_reio_for_zreio
overshot the target -> bisection converged to a z_reio that was too low.

Empirical impact at Planck 2018 fiducial:
- z_reio offset (clax vs CLASS reference): 0.00335 -> 0.00033 (10x).
- x_e at z=8 (steepest part of reion transition): -1.1% -> -0.11%.
- g(tau) at the secondary visibility peak: -1.0% -> -0.11%.
- g(tau) at the recombination peak (z=1090): unchanged at +0.002%.

This was misattributed in the README "Known limitations" as
"EE l=20-30: ~0.2% from RECFAST visibility function bias.  HyRec
recombination would improve to sub-0.1%."  In fact:
- RECFAST physics is fine (clax/RECFAST x_e and HyRec agree to 0.09%
  at the recombination peak z=1090).
- The 0.2% EE l=20-30 bias is dominantly this tau_reio inversion bug,
  upstream of recombination physics.  HyRec would not have fixed it
  because the wrong z_reio would still be passed downstream.

Adds m_H_kg = 1.67353284e-27 to clax/constants.py so future call
sites cannot drift apart from the recombination-block value.

Validation:
- pytest tests/test_thermodynamics.py: 9/9 pass.
- z_reio, x_e, g(tau) match CLASS reference at the levels above.
- Background, harmonic, lensing test suites: unchanged at the level
  this fix could affect them (n_H_0 shifted by 0.057%, recombination
  peak visibility unchanged); a full CI run is recommended.
Documents the one-line tau_reio → z_reio inversion fix from this PR,
the empirical impact at Planck 2018 (z_reio 7.6885 → 7.6915, x_e(z=8)
-1.06% → -0.11%, EE l=20-30 residual ~1% → <0.1%), and the README
"Known limitations" line that should be reassessed in a follow-up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant