# AC69 cluster mass calibration reproduction package

Part 1 reruns hydrostatic fits for two X-COP clusters and compares published PSZ2 and
CFHT masses in their original units. Part 2 simulates a survey to show how mass bias
moves the inferred sigma8.

## Run

    python3 -m pip install -r requirements.txt
    python3 reproduce.py          # recompute and compare with expected-outputs.json (exit 0 on pass)
    python3 reproduce.py --write  # overwrite expected-outputs.json

The ZIP preserves the paths of the inputs and helper scripts. This release passed in
Python 3.12.12, NumPy 1.26.4 and SciPy 1.13.1. The separate site downloads have flat names.

## Data credit

`inputs/xcop-a2029.json` and `inputs/xcop-a2319.json` are copies of selected columns from
the X-COP public data release (XMM-Newton density, temperature and pressure profiles,
Planck SZ pressure profiles, gas fraction profiles and NFW fit parameters), downloaded
as one archive from https://dominiqueeckert.wixsite.com/xcop/data. Values are copied
unchanged; units follow the FITS headers. The X-COP team asks users of the data to cite:

- V. Ghirardini et al., Universal thermodynamic properties of the intracluster medium over
  two decades in radius in the X-COP sample, arXiv:1805.00042 (thermodynamic profiles);
- S. Ettori et al., Hydrostatic mass profiles in X-COP galaxy clusters, arXiv:1805.00035
  (mass profiles);
- D. Eckert et al., Non-thermal pressure support in X-COP galaxy clusters, arXiv:1805.00034
  (gas mass and gas fraction).

The SHA-256 of the archive and of every FITS file used is stored in each input file.
`scripts/astronomy/ac69/extract-xcop-inputs.py` in the site repository rebuilds the inputs
from the unpacked archive (it needs astropy).

The independent observations in `inputs/observed-catalogues.json` are PSZ2 entries 21 and
322 (NASA HEASARC mirror of the Planck R2.08 union) and Herbonnet et al.'s CFHT row 26
(arXiv:1912.04414v1, Appendix Table A2). Use the exact TAP query and arXiv source URL in
the file. The repository's `scripts/astronomy/ac69/extract-catalogue-comparison.py` can
rerun the extraction from those two frozen responses. Its optional source-audit dependency
is Astropy 7.1.1.

## Files

| File | Role |
| --- | --- |
| scripts/xcop_hydrostatic_masses.py | Fits the density (Vikhlinin et al. 2006 form) and the pressure (generalised NFW, all X-ray and SZ points, one free SZ scale factor), then computes the hydrostatic mass, R500, the gas fraction, the mass implied by a universal gas fraction of 0.131 and the mass that the Planck 2015 X-ray-calibrated Y-M relation gives for the measured Y500. |
| scripts/cluster_mass_function.py | Tinker et al. 2008 mass function on an Eisenstein and Hu 1998 no-wiggle spectrum, M500c, flat Lambda-CDM with h = 0.7, Omega_m = 0.3. |
| scripts/cluster_count_selection.py | Toy SZ survey: Planck 2015 XXIV Eq. (7) Y-M relation with (1 - b), lognormal scatter 0.173, Gaussian noise that grows with cluster size, detection at S/N > 6, 65 percent of the sky, 0 < z < 1. Analytic counts, a Monte Carlo check and the sigma8 needed for each assumed (1 - b). |
| scripts/compare_catalogues.py | Matches Planck and weak-lensing rows, interpolates hydrostatic mass at the lensing aperture, and repeats the pressure fit with the central bins masked. |
| inputs/observed-catalogues.json | Pinned PSZ2 and CFHT weak-lensing observations, with source checksums. |
| requirements.txt | Versions for the offline analysis. |
| reproduce.py | Runs everything and compares with expected-outputs.json. |
| inputs/xcop-a2029.json, inputs/xcop-a2319.json | Frozen X-COP columns with checksums. |
| expected-outputs.json | Outputs of the last --write run, with the software versions used. |
| provenance.json | Sources, conventions, corrections and checksums. |

## Units and conventions

- Masses in solar masses without h; R500 and radii in kpc; M500 encloses 500 times the
  critical density at the cluster redshift, flat Lambda-CDM with H0 = 70 km/s/Mpc and
  Omega_m = 0.3.
- Electron density in cm^-3, electron pressure in keV cm^-3. The X-COP pressure columns are
  in units of P500 from the FITS header; the code multiplies by that P500.
- Gas density rho_gas = 0.61 m_p (n_e + n_p) with n_e = 1.17 n_p (Eckert et al. 2019, Sect. 2).
- Hydrostatic mass M(<r) = -r^2 (dP_e/dr) / (G mu m_p n_e) with mu = 0.61. Only the electron
  pressure enters, so the mass is a thermal-only hydrostatic mass.
- Y500 = sigma_T / (m_e c^2) times the volume integral of P_e inside R500, in Mpc^2. It is
  the spherical Y500 defined in Section 1 of Planck 2015 XXIV. The catalogue blind
  Y(5 R500) is a separate quantity in arcmin^2. The replay retains its columns and uses
  the catalogue mass proxy directly.

## What is checked

1. Our hydrostatic M500 against the published X-COP value: A2029 8.28e14 against 8.65e14
   (ratio 0.957); A2319 7.57e14 against 7.68e14 (ratio 0.985). The published masses come
   from forward fits with covariance matrices that this script ignores.
2. Gas fraction at our R500: A2029 0.140 (X-COP 0.140 at their R500), A2319 0.187 (0.190).
   A2319 is far above the universal 0.131, the case Eckert et al. read as non-thermal
   pressure support. A constant non-thermal fraction would need to be about 0.30.
3. Three mass estimates from the same profiles, in units of 1e14 solar masses:

   | Cluster | hydrostatic | universal gas fraction | Planck Y-M (X-ray calibrated) |
   | --- | --- | --- | --- |
   | A2029 | 8.28 | 9.22 | 8.44 |
   | A2319 | 7.57 | 14.7 | 10.0 |

   The Planck relation is calibrated on hydrostatic X-ray masses, so for A2029 it lands
   close to our hydrostatic mass. A2319 has more pressure for its hydrostatic mass than the
   calibration sample, so its Y-based mass comes out higher.
4. Mass function: n(>M) at z = 0.2 for three sigma8 and three masses. The site test suite
   compares the same numbers with colossus 1.4.0 (agreement better than 1 percent in
   dn/dlnM).
5. Toy survey with true sigma8 = 0.81 and true 1 - b = 0.8: 481.9 expected detections.
   The mean of 200 Monte Carlo surveys is 483.1 with a standard deviation of 19.7, 0.86
   standard errors from the analytic value. If the analyst assumes the hydrostatic masses
   are true (1 - b = 1), the same counts require sigma8 = 0.739; with 1 - b = 0.6 they
   require 0.916. Planck 2015 XXIV found that agreement with the primary CMB needs
   1 - b = 0.58 +/- 0.04.

## Matched catalogue comparison

| Method, A2029 | Mass in 1e14 solar masses |
| --- | --- |
| Published X-COP hydrostatic M500 | 8.65 |
| PSZ2 catalogue M500 proxy | 7.039 +0.199 / -0.193 |
| CFHT lensing NFW M500 fit | 12.1 +/- 2.5 |
| CFHT lensing deprojected mass at 1.52 Mpc | 10.8 +1.9 / -2.3 |
| X-COP hydrostatic profile at the same 1.52 Mpc | 9.215 |

The ratio at the same radius is 0.853. The central radius is fixed for this comparison;
the published lensing radius and mass errors are correlated. The table compares measurements
of a single object and does not estimate a sample calibration. PSZ2 also supplies a proxy
for A2319 (8.735). The frozen CFHT table has no matching A2319 row.

## Failure cases kept on purpose

- In the overlap region the frozen SZ pressure points sit below the X-ray points in most
  X-COP clusters: the median ratio is 0.73 for A2029 and 0.89 for A2319 (0.73 to 1.24 over
  all 12 clusters). The SZ table header labels its unit "P/K500" while the X-ray table says
  "P/P500".
  Figure 4 of Ghirardini et al. uses one pressure scale for both. The fit allows one
  free scale factor. With all bins it gives 0.756 and 0.922 for A2029 and A2319. After the
  source paper’s three-bin cut those become 0.888 and 1.096.
- Without that factor, a single generalised NFW profile through both data sets put A2029's
  concentration at the lower bound and its outer slope at the upper bound, with
  chi-square 131 for 24 points. Even with the factor, A2029's fit sits at the outer-slope
  bound (concentration 0.080, outer slope 12, chi-square 75.8 for 24 points). The parameters are degenerate there; the
  logarithmic pressure slope at R500 (-2.69), which the mass depends on, is stable.
- The toy survey fits only the total count, so sigma8 and 1 - b are completely degenerate.
  The noise model is a simplification and the count of 482 is tuned to be Planck-like, not
  a prediction of the Planck catalogue.
