#import "importer/main.typ": *
#import "helpers.typ": *
#import "@preview/physica:0.9.5": *

= Overview of the #beorn framework <procedure>

This section presents the model describing the sources of radiation that drive reionization. We explain how #beorn implements this model to generate 3-d maps of the IGM during the epoch of reionization. The code of #beorn as well as usage instructions are publicly available under #link("https://github.com/cosmic-reionization/BEoRN", "https://github.com/cosmic-reionization/BEoRN")#footnote[
  For an explicit overview of the changes referenced here, please refer to #link("https://github.com/moll-re/BEoRN")
].


== The halo mass model of reionization <hmreio>

The distinguishing feature
// don't like that word
of #beorn is the parametrization of sources of radiation through the properties of their host dark matter halos. This approach is based on the model presented by @schneider2023cosmologicalforecast21cmpower and gives a description
// bad word
of the 21-cm signal through the treatment of flux profiles around sources. Using these profiles and allowing them to overlap enables efficient computations of the ionization state of the IGM without the need for detailed radiative transfer simulations. The following description follows the derivation made by @schneider2023cosmologicalforecast21cmpower @Schneider_2021 and we refer to these works for components that are not defined here.

The model describes the emission of ionizing radiation by galaxies. It assumes that the sources are hosted by dark matter halos and expresses the star formation and radiation properties as a function of the halo mass $M_"h"$ and mass accretion rate $dot(M_"h")$. The modeling
// maybe treatment
of the halo mass evolution is discussed in @halo_mass_history. The model itself simply considers an arbitrary but known halo mass accretion history $M_"h" (z)$.

The emission of radiation revolves around the star formation rate $dot(M)_star$ which is simply assumed to be proportional to the halo mass accretion rate via
$
  dot(M)_star = f_star (M_"h") dot dot(M_"h")
$ <eq:star_formation_rate>
where the star formation efficiency $f_star$ introduces a mass dependence that enables the suppression of star formation in low mass halos and the implementation of a cooling limit.
Motivated by abundance matching, @schneider2023cosmologicalforecast21cmpower use the double power law
$
  f_star (M_"h") = f_(star,0) dot (2 (Omega_b / Omega_m)) / ((M_"h"/M_"p")^(gamma_1) + (M_"h"/M_"p")^(gamma_2)) dot S(M_"h")
$ <eq:star_formation_efficiency>
with $M_"p"$ the pivot mass where the efficiency peaks, and $gamma_1$, $gamma_2$ are the low and high mass slopes, and $f_(star,0)$ is the normalization chosen at a value of $f_(star,0) #sym.tilde 0.1$. An additional suppression factor $S(M_"h")$ is introduced to account for reduced star formation in low mass halos whose effect is discussed by @Schaeffer_2023.


=== Expression of the profiles
Derived from the star formation rate the halo model predicts the production and distribution of photons in three distinct energy bands:
Lyman-$alpha$ photons, ionizing UV photons, and X-ray photons. Each of these bands has a different effect on the IGM and is treated separately.
// Not really sure that's true
==== Lyman-$alpha$ flux profile
Lyman-$alpha$ photons induce a coupling between the spin temperature and the kinetic temperature of the gas. This effect, known as the Wouthuysen-Field effect
#cite(<Wouthuysen>, form: "normal")
#cite(<Field>, form: "normal"),
causes a characteristic absorption and emission feature in the 21-cm signal. Before the cosmic dawn the gas temperature is lower than the background temperature and the coupling leads to absorption. As the first stars heat the gas, the signal transitions to emission.

The Lyman-$alpha$ flux profile around a halo of mass $M$ at redshift $z$ is given by
$
  rho_alpha (r bar M, z) = (1 + z)^2 / (4 pi r^2) dot sum_(n=2)^(n_m)f_n dot epsilon_alpha (nu prime) dot f_star dot dot(M)(z prime bar M, z)
$
which depends on the lookback redshift $z prime$ at which the photon was emitted, hence the expression in terms of $nu prime = nu dot (1+z prime) slash (1+z)$.

Finally the position dependent coefficient is expressed as
$
  x_alpha (r bar M, z) = (1.81 dot 10^11) / (1 + z) dot S_alpha (z) dot rho_alpha (r bar M, z)
$
using a suppression factor $S_alpha (z)$.

==== Temperature profile
The temperature of the IGM around the sources has a strong impact on the 21-cm signal. It is governed by two effects: the cooling temperature of the adiabatically expanding universe and the heating due to X-ray photons emitted by the newly formed stars. The heating profile $rho_h$ follows
$
  3/2 dot derivative(rho_h (r bar M, z), z) = (3 rho_h (r bar M, z)) / (1 + z) - (rho_"xray" (r bar M, z)) /(k_B (1 + z) H(z))
$
which is based on the flux profile of x-ray photons $rho_"xray" (r bar M, z)$. The Boltzmann constant is given by $k_B$ and $H(z)$ is the Hubble parameter at redshift $z$.


==== Reionization profile

The comoving ionized volume around a source of ionizing photons satisfies the differential equation
$
  derivative(V, t) = dot(N)_"ion"(t) / overline(n)_H^0 - alpha_B dot C / a^3 dot overline(n)_H^0 dot V
$
where $alpha_B$ is the recombination coefficient, $C$ is the clumping factor, $a$ is the scale factor, and $overline(n)_H^0$ is the mean density of hydrogen.

Ionizing photons, i.e. photons with energies above $13.6 "eV"$ ,experience a large optical depth, which justifies the sharp cutoff of the ionization profile at the bubble radius $R_b = root(3, 3/ (4pi) V(M,z))$. The radial dependence of the ionized fraction is expressed through the Heaviside step function $theta_"H"$ and reads
$
x_("HII")(r bar M, z) = theta_"H" lr([R_b (M, z) - r], size: #150%)
$

=== Expression of the reionization signal

The above profiles express the local effect of radiation around a single halo as a 1-d simplification. A representation of a typical profile can be seen in @fig:alpha_evolution_vs_redshift. Using an estimate of the spatial distribution of halos, these profiles can be applied to generate a full 3-d map if we assume spherical symmetry.

The observable signal of the 21-cm line is obtained from a combination of the mapped quantities. It is expressed as the differential brightness temperature $d T_"b"$ which describes the contrast between the foreground and the CMB background.
// might want to rephrase that
Following e.g. @Pritchard2012 an expression for $d T_"b"$ is given by
$
  d T_"b" (bold(x), z) tilde.eq T_0 (z) dot x_"HI" (bold(x), z)  dot (1 + delta_b (bold(x), z)) dot (x_alpha (bold(x), z)) / (1 + x_alpha (bold(x), z) ) dot ((1 - T_"CMB" (z)) / (T_"gas" (bold(x), z)))
$ <eq:dTb>
// where $T_0 (z) = 27 "mK" sqrt((1 + z)/10 (0.15 / (Omega_m h^2))) (Omega_b h^2 / 0.023)$, $x_"HI"$ is the neutral hydrogen fraction, $delta_b$ is the baryonic overdensity, $x_alpha$ is the coupling coefficient introduced by the Wouthuysen-Field effect, $T_"CMB"$ is the temperature of the CMB, and $T_"gas"$ is the kinetic temperature of the gas. The expression assumes that the spin temperature is closely coupled to the kinetic temperature which is valid in most regimes of interest during reionization.
where the background radiation originates from the CMB. The above considerations give us the values of $x_"HI"$, $x_alpha$, and $T_"gas"$. The baryonic overdensity $delta_b$ is assumed to trace the dark matter overdensity $delta_"dm"$ which is obtained from the underlying #nbody simulation. The amplitude of the signal is given by
$
  T_0 (z) = 27 dot (Omega_b h^2) / 0.023 dot sqrt((1 + z)/10 0.15 / (Omega_m h^2)) "mK"
$
where $Omega_m$ and $Omega_b$ are the matter and baryonic density parameters.



== Simulation steps
The simulation procedure revolves around the implementation of the above spherical radiation profiles around halos. We give a brief overview of the main steps here. For a more detailed description of the implementation we refer to @Schaeffer_2023. We discuss our improvements and changes to the original implementation in @implementation.

=== Halo catalog - #nbody simulations
As a prerequisite, the generation of map data requires a spatial distribution of dark matter halos as well as the underlying density field. Each snapshot can be used to generate a map at the corresponding redshift. #beorn has been successfully validated against mock maps generated by `21cmFAST` #cite(<21cmfast>, form: "normal")
and produced meaningful signals by using the #pkdgrav #cite(<potter2016pkdgrav3trillionparticlecosmological>, form: "normal") simulation suite.

=== Computation of radiation profiles
In accordance with the astrophysical parameters set by the user, radiation profiles are computed in order to be applied according to the halo catalog in a subsequent step. The computation of the profiles is deliberately separated from their application onto halos for a more efficient processing. The range of halo masses and redshifts covered by this precomputation is largely determined by the underlying halo catalog since it provides upper bounds on the halo masses
#footnote[
  The minimum halo mass that needs to be considered is already constrained by the atomic cooling limit. Depending on the mass resolution of the simulation it might not even be reached.
].

=== Painting with the binned approach <painting>
The last step consists of applying the ionization and temperature distributions defined by the profiles onto a 3-d grid. This is done by iterating over the halos in the catalog and using their corresponding profile. For a given profile a 3-d kernel is generated and mapped onto the grid via convolution using the fast fourier transform implemented by the `astropy` #cite(<astropy:2022>, form: "normal") package. We refer to this procedure as "painting" since the addition of the contributions of each halo allows us to sequentially build up the final map. In general, contributions from multiple halos can overlap without any restrictions. The ionization map is treated specially: In order to conserve the overall number of ionizing photons, we ensure that each cell is only ionized once.
// If multiple halos contribute to the ionization of a cell, the excess photons are redistributed to neighboring cells until they are either used up or reach the edge of the simulation box.

The usage of precomputed profiles is crucial to the efficiency of the simulation but it introduces a discretization in halo mass since each halo is assigned the profile of the closest mass bin. The effect of this simplification has been shown to converge for a sufficient number of mass bins by @Schaeffer_2023.

One final step is required to ensure consistent painting: While the contributions to the temperature and coupling maps can be simply added, the ionization map requires a binary treatment. Cells cannot be ionized past a value of $x_"HII" = 1$. Discarding the excesses would violate photon conservation. A redistribution of the excess photons to neighboring cells is performed to ensure that the total number of ionizations matches the total number of emitted photons.


=== Derivation of global quantities
The global signal as well as the power spectrum are derived from the map data and compared to other models or observations. Being derived from a full 3-d #nbody simulation, the results are sensitive to the underlying cosmology and the detailed profile modeling. This means that the results depend on the underlying astrophysical model.
