# README — TREECOOL files for GADGET (UV background)

This document summarizes the transformations applied to the original files
to obtain four OpenGadget3-ready TREECOOL files, all sharing the **same final
format**:

```
  log10(1+z)  Gamma_HI[1/s]  Gamma_HeI[1/s]  Gamma_HeII[1/s]  eps_HI[erg/s]  eps_HeI[erg/s]  eps_HeII[erg/s]
```

- no header, no comment lines
- 7 space-separated columns, in this order
- column 1: `%.3f` (e.g. `0.000`)
- columns 2-7: scientific notation `%.5e`, 6 significant digits
  (e.g. `3.03516e-14`)
- numeric style identical to `TREECOOL_weuse` 

Ionization columns (Gamma) are per-ion rates, in 1/s.
Heating columns (eps) are per-ion rates, in **erg/s**
(not eV/s — see below).

---

## 1. HM12.pdf → TREECOOL.HM12.dat

**Source:** raw output of the CUBA v6.3 code (Nov 2011), Haardt & Madau
(2012) model.

**Original format:**
- PDF with 11 header lines (model flags/parameters) + 7 column-label lines,
  followed by the data table
- 8 columns: `z  HI_i  HI_h  HeI_i  HeI_h  HeII_i  HeII_h  Compton`
  (interleaved ionization/heating order per species, plus Compton heating)
- **linear** redshift (not log10(1+z)), from z=0 to z=15.1, 59 rows
- units stated in the header: ionization in 1/s, heating **in eV/s**

**Transformations applied:**
1. Extracted the text from the PDF, isolated the numeric table from the
   header lines
2. `z` → `log10(1+z)`
3. Reordered the columns: `HI_i, HeI_i, HeII_i` (ionization) followed by
   `HI_h, HeI_h, HeII_h` (heating)
4. **Removed the Compton column** (not part of the standard TREECOOL format)
5. Heating columns converted from eV/s to erg/s:
   `eps [erg/s] = eps [eV/s] × 1.602176634e-12`

**Resulting range:** log10(1+z) from 0 to 1.207 → z from 0 to 15.1

---

## 2. TREECOOL.HM96_P-Gadget2.dat 

**Source:** Legacy file

**Original format:**
- PDF (2 pages), no header/comments, already 7 columns in the correct order
  (`log10(1+z), Gamma_HI, Gamma_HeI, Gamma_HeII, eps_HI, eps_HeI, eps_HeII`)
- already in erg/s for the heating columns
- log10(1+z) from 0 to 0.850 (z from 0 to ~6.08), constant step of 0.005,
  171 rows
- last row with all exact zeros (hard cutoff of the UV background at z~6.08)

**Resulting range:** log10(1+z) from 0 to 0.850 → z from 0 to ~6.08
(unchanged)

---

## 3. fg20_treecool_eff_rescaled_heating_rates_068.dat → TREECOOL.FG20.dat

**Source:** Faucher-Giguère et al. (2020) model, "effective/rescaled"
heating rates.

**Original format:**
- already plain text, 7 columns, no header
- already in the correct order and already in erg/s for heating
- log10(1+z) from 0 to 0.970 (z from 0 to ~8.32), step 0.005, 195 rows
- some values floored at 1e-40 instead of exact zero (to avoid issues in
  logarithmic interpolation)

**Transformations applied:**
1. No numeric transformation: only rewritten with the standard numeric
   style (matched to `weuse`)

**Resulting range:** log10(1+z) from 0 to 0.970 → z from 0 to ~8.32
(unchanged)

---

## 4. parameters_Q18.txt → Q18_formatted.txt → TREECOOL.KS19_Q18.dat

**Source:** Khaire & Srianand (2018) model, "QSO SED 1.8" quasar spectrum.

**Original format (`parameters_Q18.txt`):**
- text file with a comment header:
  `## Units: Gamma (s^-1) & H (eV s^-1)`
- 7 columns: `z, Gamma_HI, Gamma_HeI, Gamma_HeII, H_HI, H_HeI, H_HeII`
  (already in the correct order)
- **linear** z (not log10(1+z))
- non-uniform grid: step 0.1 up to z=6, then 0.2 up to z=10, then 0.5 up
  to z=15
- heating **in eV/s** (as stated in the header)

**Intermediate step — `Formatting_ourWay.py` → `Q18_formatted.txt`:**
- only transformation applied: `z` → `log10(1+z)`
- the other 6 columns left unchanged (still in eV/s for heating)

**Final transformation — → `TREECOOL.KS19_Q18.dat`:**
- heating columns converted from eV/s to erg/s:
  `eps [erg/s] = eps [eV/s] × 1.602176634e-12`
- rewritten with the standard numeric style

**Resulting range:** log10(1+z) from 0 to 1.204 → z from 0 to ~16.0
(unchanged)

---

## Note on units

`HM12.pdf` and `parameters_Q18.txt` provided heating rates in **eV/s**
(the "native" unit typically output by spectral synthesis codes), while
`TREECOOL_weuse.pdf` and `fg20_...dat` had already been converted to
**erg/s** in an earlier stage of the work. To make the four files truly
comparable and interchangeably usable in GADGET, the following factor was
applied during conversion:

```
1 eV = 1.602176634e-12 erg
```

to the heating columns only (columns 5, 6, 7) of the files that needed it
(HM12, Q18). The ionization columns (2, 3, 4) were left unchanged in all
files, since they were already in 1/s everywhere.

---

## Redshift range summary

| Final file | log10(1+z) max | z max |
|---|---|---|
| TREECOOL.HM96_P-Gadget2.dat | 0.850 | ~6.08 |
| TREECOOL.FG20.dat | 0.970 | ~8.32 |
| TREECOOL.HM12.dat | 1.207 | ~15.1 |
| TREECOOL.KS19_Q18.dat | 1.204 | ~16.0 |

The four files cover different redshift ranges (by choice, not modified).
