Skip to main content
Sandbox Physics
How the universe became transparent

Comparing Saha, a three-level atom and a frozen CLASS reference

Sandbox Physics ·

The Python replay compares hydrogen recombination with the HyRec-2 output archived in CLASS v3.3.4. Between redshifts 1500 and 100 the sampled three-level results agree within 4 percent. At redshift 50 the difference is 8.8 percent. A separate calculation checks the spectral kernels and shows why differently defined chemical-potential and Compton amplitudes can differ even for a similar thermal history.

This comparison uses the CLASS v3.3.4 release at commit e85808324f51fc694d12e3ed7439552a3c3f9540. It reads four archived files. The curves and coefficients in those files serve as numerical references for the Python calculation. CLASS v3.3.4 on GitHub

Files, versions and units

All scripts use only the Python 3 standard library and were run with Python 3.9.6. The materials are in this collection's materials folder:

Redshift is dimensionless and the scripts integrate in s=ln⁡(1+z)s=\ln(1+z). Densities are in m−3\mathrm{m^{-3}}, rates in s−1\mathrm{s^{-1}}, energies in joules internally and electronvolts in the text. Spectra are in kJy sr−1\mathrm{kJy\,sr^{-1}}, where 1 kJy sr−1=10−23 W m−2 Hz−1 sr−11\,\mathrm{kJy\,sr^{-1}}=10^{-23}\,\mathrm{W\,m^{-2}\,Hz^{-1}\,sr^{-1}}. The background takes h=0.6736h=0.6736, T0=2.7255 KT_0=2.7255\,\mathrm K, Ωb=0.04941\Omega_{\mathrm b}=0.04941, Ωcb=0.3124\Omega_{\mathrm{cb}}=0.3124, helium mass fraction 0.2450.245 and Neff=3.046N_{\mathrm{eff}}=3.046. These match external/HyRec2020/input.dat in CLASS, except that the one massive neutrino is treated as massless radiation.

mkdir ac75-check && cd ac75-check
base=https://sandboxphysics.com/stories/cosmic-transparency/materials
for name in ac75_model.py inputs.json run_recombination.py check_distortion_kernels.py compare_class_files.py hyrec-reference-extract.json; do curl -fsSLO "$base/$name"; done
python3 -I run_recombination.py inputs.json hyrec-reference-extract.json my-recombination-output.json
python3 -I check_distortion_kernels.py my-kernel-checks.json
git clone --depth 1 --branch v3.3.4 https://github.com/lesgourg/class_public.git
python3 -I compare_class_files.py class_public my-class-comparison.json

The comparison script refuses to run if any of the four CLASS files has a different SHA256 from the one written in the script. Compare your three new JSON files with the saved ones; on another machine the last digits may differ.

Step 1: three histories at the same redshifts

The script solves the three-level equation from Saha at redshift 1800 down to 50, with a backward-Euler step of 5×10−45\times10^{-4} in ss. Backward Euler evaluates the rate at the end of each step and solves for it with Newton iterations, which keeps the stiff early phase stable.

Table 5.1 Free-electron fraction from recombination-output.json.
RedshiftSahaThree-level, factor 1.14Three-level, factor 1.00HyRec-2 fileThree-level minus HyRec-2, relative
150015000.9470.9470.95460.95460.95460.95460.95490.9549−0.0003-0.0003
130013000.2100.2100.56460.56460.56460.56460.56120.5612+0.0060+0.0060
110011000.004690.004690.14240.14240.14260.14260.14470.1447−0.0160-0.0160
9009001.6×10−51.6\times10^{-5}0.012230.012230.012490.012490.012690.01269−0.0367-0.0367
2002001.2×10−531.2\times10^{-53}3.39×10−43.39\times10^{-4}3.83×10−43.83\times10^{-4}3.36×10−43.36\times10^{-4}+0.0064+0.0064

The last column is the difference relative to HyRec-2. From redshift 1500 to 100, its largest magnitude at the sampled points is 0.0390.039. At redshift 200, changing the case-B factor from 1.14 to 1.00 increases the three-level result by about 13 percent. This coefficient controls the late freeze-out.

The three-level calculation peaks at 1081.0 and reaches unit optical depth at 1092.0. Integrating the HyRec-2 file below redshift 1600 gives 1080 and 1089.8, respectively. Planck’s derived redshift z∗=1089.92±0.25z_\ast=1089.92\pm0.25 uses the unit-depth convention without reionization, as computed in CAMB. Planck Collaboration, 2018, Table 2 CAMB derived-redshift calculation

Step 2: numerical checks and failure cases

Halving the step changes the unit-depth redshift by 0.0780.078 and changes xx at redshift 1100 by −5.2×10−4-5.2\times10^{-4} relative to the original. The discrepancy with HyRec-2 is larger than either step-size effect. The comparison alone does not isolate which physical assumptions account for it.

Two failures are saved on purpose. An explicit Euler step of 5×10−35\times10^{-3} overshoots the Saha balance at the start and produces nan by redshift 1500. Starting the three-level solution from Saha at redshift 1300 instead of 1800 gives x=0.105x=0.105 at redshift 1100, against 0.1420.142. By 1300 the true history has already left Saha, so the starting value is already wrong, and that error carries through to redshift 1100.

Step 3: the full HyRec-2 file

The comparison script reads all 8000 rows of external/HyRec2020/output_xe.dat. Over redshifts 50 to 1600 the largest relative difference is +8.8+8.8 per cent, at redshift 50. The model lets gas share the photon temperature down to redshift 50. Real gas cools faster late in the dark ages, which changes the recombination rate, so this assumption is the most likely cause; we have not isolated it. At redshift 8000 the file gives xe=1.16341x_{\mathrm e}=1.16341, against 1+2fHe=1.163431+2f_{\mathrm{He}}=1.16343 for fully ionized helium. This confirms that the file counts helium electrons, so comparisons above redshift 1600 must allow for them.

Step 4: the distortion shapes without reusing their formulas

check_distortion_kernels.py tests the closed forms GG, YY and MM against quantities they do not contain:

  1. Simpson integrals of energy and number against exact Planck integrals: GG carries 4 times the blackbody energy and 3 times its number; YY carries 4 and 4×10−94\times10^{-9}; MM carries 0.713950.71395 and 4×10−54\times10^{-5}. The inverse of 0.713950.71395 is 1.40071.4007, the coefficient used for μ\mu.
  2. A finite-difference Kompaneets operator applied to the Planck occupation number reproduces YY to 1.7×10−71.7\times10^{-7} of its peak.
  3. A Bose–Einstein spectrum with μ=10−6\mu=10^{-6}, its temperature refitted to keep the photon number, reproduces MM to 6.6×10−56.6\times10^{-5} of its peak.

Zero crossings come out at 217.51 GHz217.51\,\mathrm{GHz} for YY and 124.5 GHz124.5\,\mathrm{GHz} for MM.

Step 5: energy in the CosmoTherm Green's functions

The archived Greens_data.dat file includes 120 redshifts, and the CLASS documentation describes it as adapted from CosmoTherm 1.0.3. The comparison script first integrates each raw spectral column over its frequency grid and divides by the tabulated blackbody energy. This diagnostic uses the columns as stored. Chluba, 2013, section 2

Table 5.2 Energy from the raw Green’s-function columns, relative to the released energy.
Release redshiftEnergy over released energy
1.0×1031.0\times10^{3}1.00001.0000
1.1×1051.1\times10^{5}1.00041.0004
2.6×1052.6\times10^{5}0.99910.9991
5.6×1055.6\times10^{5}0.9860.986
1.8×1061.8\times10^{6}0.9310.931
3.3×1063.3\times10^{6}0.8380.838
5.0×1065.0\times10^{6}1.0131.013

The raw columns integrate to within 0.1 percent of unity at the checks through 2.6×1052.6\times10^5. The CLASS generator multiplies each column by the blackbody visibility and restores the separately tabulated temperature shift as a blackbody difference per unit injected energy. Repeating those two steps on the full tabulated frequency grid, the ratio at z≃3.3×106z\simeq3.3\times10^6 rises from 0.8380.838 to 0.9970.997. The raw-column table therefore shows why those corrections matter, and is not a test of full energy closure. CLASS projection generator

Step 6: two different ways to split a distortion

FIRAS_branching_ratios.dat lists, for each release redshift, the μ\mu, yy and temperature shift per unit Δρ/ργ\Delta\rho/\rho_\gamma. The comparison script repeats the steps of external/distortions/generate_PCA_files.py on the 43 FIRAS frequencies from 68 to 639 GHz. It builds orthonormal vectors from YY, then MM, then GG by Gram–Schmidt and projects each Green's function onto them, the procedure written as equations 3.10 to 3.15 by Lucca and colleagues. Lucca and colleagues, 2020, section 3.2.2 The repeat matches the table: at z=5×104z=5\times10^{4} the table gives μ\mu per unit energy of 1.5011.501, and our projection at the nearest tabulated redshift, 4.96×1044.96\times10^{4}, gives 1.4881.488.

The Lab uses the soft branching fits instead, and these differ strongly in the transition era. At z=5×104z=5\times10^{4} they give 0.7430.743 against the table's 1.5011.501; at z=2×104z=2\times10^{4}, 0.1770.177 against 0.3410.341. Above 5×1055\times10^{5} their μ\mu values agree within 3 per cent, and at 2×1052\times10^{5} within 9 per cent. Below 5×1035\times10^{3} their yy values agree within 0.3 per cent.

These coefficients describe specific decompositions. The projection depends on the frequency channels and on the order used to orthogonalize the shapes. The soft formulas can also misestimate the total spectrum because they omit the residual distortion. Compare full responses on the same grid before using differences in a single coefficient as an accuracy test. Lucca and colleagues, 2020, footnote 13

Accuracy of the hydrogen and distortion calculations

For the sampled range from redshift 1500 to 100, this hydrogen calculation follows the saved HyRec-2 electron history to within 4 percent. The step-halving test measures numerical sensitivity, and the analytic checks cover the separate shape kernels. The model omits helium, the thermal evolution of the gas and the cascade of injected particles. The CLASS-file comparison evaluates saved responses and their projections.

Reusable checklist for the next code comparison:

  1. Pin the reference version and record file checksums.
  2. Match every background parameter, and list the ones you could not match.
  3. Compare at fixed redshifts and in derived summaries such as the visibility peak.
  4. Halve the step and confirm the gap to the reference is larger than the change.
  5. Save at least one failure case, so a reader can see what a wrong setup looks like.
  6. Check every shape against a quantity it does not contain: a moment, a limit or an independent operator.
  7. Before comparing split parameters, confirm both sides use the same definition of the split.

The HyRec-2 extract and the three CLASS files are read under attribution to their authors. No licence file was found in the CLASS v3.3.4 tree, so Sandbox Physics redistributes only the 60-row extract and asks readers to download the original files from the release.

Sources

  1. CLASS v3.3.4 on GitHub
  2. Planck Collaboration, 2018, Table 2
  3. CAMB derived-redshift calculation
  4. Chluba, 2013, section 2
  5. CLASS projection generator
  6. Lucca and colleagues, 2020, section 3.2.2

Keep reading

What this page links to directly

See this series on the content map →

How the universe became transparent · Reading path

From a blackbody to limits on hidden energy

  1. ArticleWhat can tiny departures from a perfect blackbody record?
  2. ArticleSaha balance and the recombination bottleneck
  3. ArticleOptical depth and the visibility function
  4. ArticleThermalization, chemical-potential and Compton distortions
  5. You are hereComparing Saha, a three-level atom and a frozen CLASS reference
  6. ArticleHow to read the decaying dark matter limits of Lucca and colleagues
Something broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy