# Source code notes on `AnalyticDensityProf`

¶

This section of the documentation provides background material and detailed implementation notes
on the functions and methods of the primary base class used to model the spatial distribution
of matter and galaxies within halos,
`AnalyticDensityProf`

.
This as an abstract base class and so it cannot itself be instantiated; only concrete
sub-classes can be used to directly model the spatial profile of halos.

The purpose of the `AnalyticDensityProf`

class is to provide a template for any Halotools model of the spatial distribution
of points within a halo. So in Halotools, any analytical model for how either matter or galaxies
are spatially distributed within their halos will subclass from the
`AnalyticDensityProf`

class.

This tutorial is organized as follows. The Halo Mass and Radius Definitions section
reviews how halo boundaries and masses are defined with respect to a cosmologically
evolving reference density. The Spatial Profiles of Halos section covers
the mathematics of halo density profiles, including explicit derivations
of the exact form of all equations are they are implemented in code.
The tutorial concludes with the Constructor of the AnalyticDensityProf class section by describing how the
`__init__`

constructor standardizes the attributes and behavior
of the class to facilitate mock-making with a uniform syntax.

## Halo Mass and Radius Definitions¶

### Basic equations¶

The `AnalyticDensityProf`

class models
a dark matter halo to be a spherically symmetric overdensity relative to some reference
density, \(\rho_{\rm ref}(z)\). The reference density is typically either the critical
energy density of the universe, \(\rho_{\rm crit}(z)\), or the mean matter density
\(\rho_{\rm m}(z) = \Omega_{m}(z)\rho_{\rm crit}(z)\). In the spherical-overdensity
definition of a halo, the spherical boundary of a halo is defined such that the region inside
the spherical shell has a fixed density

the redshift-dependence of \(\rho_{\rm thresh}\) reflects both the evolution of the reference density \(\rho_{\rm ref}\) as well as any possible redshift-dependence in the scalar multiple \(\Delta_{\rm ref}\).

The cosmological model determines \(\rho_{\rm ref}(z)\); the choice of a halo mass definition is determined by how one chooses \(\Delta_{\rm ref}(z)\). Typically, one chooses \(\Delta_{\rm ref}\) to be some redshift-independent multiple of the reference density. In the conventional notation for this choice, \(\Delta_{\rm ref}(z) = 500c\) refers to the case where

and \(\Delta_{\rm ref}(z) = 200m\) is shorthand for

The other common choice for \(\Delta_{\rm ref}(z)\) is \(\Delta_{\rm vir}(z)\), which defined by the solution of the gravitational collapse of a top-hat overdensity evolving in an expanding background.

Once a choice is made for \(\Delta_{\rm ref}(z)\), the mass of a spherically symmetric halo is defined by:

This equation defines the relationship between the total mass of a halo \(M_{\Delta}\) and the halo boundary \(R_{\Delta}\).

### Computing the relevant quantities¶

In Halotools, the reference densities are computed using the `cosmology`

sub-package of Astropy,
and the remaining quantities are computed in the
`profile_models`

sub-package,
specifically the `profile_helpers`

module.

Quantity | Source Code |
---|---|

\(\rho_{\rm thresh}(z)\) | `density_threshold` |

\(\Delta_{\rm vir}(z)\) | `delta_vir` |

\(M_{\Delta}(z)\) | `halo_radius_to_halo_mass` |

\(R_{\Delta}(z)\) | `halo_mass_to_halo_radius` |

\(\rho_{\rm crit}(z)\) | `critical_density` |

\(\Omega_{\rm m}(z)\) | `Om` |

## Spatial Profiles of Halos¶

### Basic equations¶

For a given choice of \(\Delta_{\rm ref}(z)\), the mass of a spherically symmetric halo is is related to the spatial profile of the matter in its interior via:

This equation defines the normalization of the halo profile \(\rho_{\rm prof}(r)\), which for any
sub-class of `AnalyticDensityProf`

is
computed with the
`mass_density`

method.

For numerical stability, it is always preferable to work with order-unity quantities rather than astronomical numbers. So throughout the `profile_models`

sub-package, most methods
work with the *scaled radius*, \(\tilde{r}\), defined as:

and the `dimensionless_mass_density`

,
\(\tilde{\rho}_{\rm prof}\), defined as:

In the implementation of `AnalyticDensityProf`

,
for reasons of numerical stability a profile is actually defined by \(\tilde{\rho}_{\rm prof}(\tilde{r})\),
and \(\rho_{\rm prof}(r)\) is a derived quantity.

In fact, in order to define a new
profile model, one only need define a sub-class
`AnalyticDensityProf`

and provide an
implementation of the `dimensionless_mass_density`

method, as *all* other profile quantities can be computed from this function.

### Convenience functions¶

In addition to the `dimensionless_mass_density`

method that defines the profile, instances of the
`AnalyticDensityProf`

class
have a number of other useful bound methods:

#### Enclosed mass¶

The mass enclosed within a given radius is defined as:

which can be computed via the
`enclosed_mass`

method
of the `AnalyticDensityProf`

class,
or any of its sub-classes.

#### Cumulative mass PDF¶

One particularly important quantity in making mocks is \(P_{\rm prof}(<\tilde{r})\), the cumulative probability of finding a randomly selected particle at a scaled-radius position less than \(\tilde{r}\):

This function is computed by
the `cumulative_mass_PDF`

method
of the `AnalyticDensityProf`

class.
The \(P_{\rm prof}(<\tilde{r})\) is used by
`MonteCarloGalProf`

to help generate Monte Carlo realizations of halo density profiles.

For reasons of numerical stability, in the Halotools implementation
of the `enclosed_mass`

method
the quantity \(M_{\Delta}(<r)\) is computed as
\(M_{\Delta}(<r) = P_{\rm prof}(<\tilde{r})M_{\Delta}\).

#### Virial velocity¶

A halo’s *virial velocity* \(V_{\rm vir}\) is defined as:

Intuitively, the virial velocity is the speed of a tracer particle on a
circular orbit at a distance \(R_{\Delta}\) from the center of a halo in virial equilibrium.
You can compute \(V_{\rm vir}\) via
the `virial_velocity`

method
of the `AnalyticDensityProf`

class,
or any of its subclasses.

#### Circular velocity profile¶

The circular velocity profile, \(V_{\rm circ}(r)\), is defined as:

where *G* is Newton’s constant. Intuitively, \(V_{\rm circ}(r)\) is the speed of
a tracer particle on a bound circular orbit at a distance *r* from the
center of a virialized halo. You can compute \(V_{\rm circ}(r)\) with
the `circular_velocity`

method
of the `AnalyticDensityProf`

class,
or any of its sub-classes.

For reasons of numerical stability, when computing \(V_{\rm circ}(r)\)
it is useful to use the *dimensionless-circular velocity*,
\(\tilde{V}_{\rm circ}(r)\), defined as

so that \(V_{\rm circ}(r) = \tilde{V}_{\rm circ}(r)V_{\rm vir}\).

In the actual Halotools implementation \(\tilde{V}_{\rm circ}(r)\) is computed using

To see that this alternative method of calculation is correct:

where the second equality follows from the definition of \(V_{\rm circ}\). Since the numerator in the final expression is \(P_{\rm prof}(<r)\) and the denominator is \(\tilde{r}\), we arrive at

This is why in the source code for the
`dimensionless_circular_velocity`

method, the returned quantity is \(\sqrt{P_{\rm prof}(<\tilde{r})/\tilde{r}}\). Then the source code for the `circular_velocity`

method simply multiplies the returned value of `dimensionless_circular_velocity`

by \(V_{\rm vir}\).

#### Maximum circular velocity¶

The maximum circular velocity \(V_{\rm max}\) is defined as the maximum value attained by
\(V_{\rm circ}(r)\) over the entire profile of the halo. Halotools computes \(V_{\rm max}\)
by using Scipy’s zero-finder `minimize`

. You can compute \(V_{\rm max}\)
using the `vmax`

method of the `AnalyticDensityProf`

class,
or any of its sub-classes.

### Computing the relevant quantities¶

Quantity | Source Code |
---|---|

\(\rho_{\rm prof}(r)\) | `mass_density` |

\(\tilde{\rho}_{\rm prof}(\tilde{r})\) | `dimensionless_mass_density` |

\(M_{\Delta}(<r)\) | `enclosed_mass` |

\(P_{\rm prof}(<\tilde{r})\) | `cumulative_mass_PDF` |

\(V_{\rm vir}\) | `virial_velocity` |

\(V_{\rm circ}(r)\) | `circular_velocity` |

\(\tilde{V}_{\rm circ}(r)\) | `dimensionless_circular_velocity` |

## Constructor of the `AnalyticDensityProf`

class¶

In this final section of the tutorial, we will look closely at the `__init__`

constructor to see how it creates a standardized interface for the purpose of making mock catalogs with the Halotools factories.

The `AnalyticDensityProf`

constructor has three required arguments: `cosmology`

, `redshift`

and `mdef`

. Binding these attributes to the instance accomplishes several things:

- When an instance of an
`AnalyticDensityProf`

sub-class is incorporated into a composite model, these attributes will be compared against the corresponding attributes of other component models so that composite model consistency is ensured.

- A fixed value for the
`density_threshold`

attribute can be bound to the instance that is consistent with the returned value of the`profile_helpers.density_threshold`

function. - The string
`mdef`

is parsed with the`model_defaults.get_halo_boundary_key`

function and the returned value is bound to the`halo_boundary_key`

instance attribute. This guarantees that during mock-making, the appropriate column of the`CachedHaloCatalog`

halo_table will be automatically chosen for all methods of the`AnalyticDensityProf`

sub-class instance requiring this knowledge. - Likewise,
`mdef`

is parsed with the`model_defaults.get_halo_mass_key`

function and the returned value is bound to the`prim_haloprop_key`

instance attribute. This guarantees that the`AnalyticDensityProf`

sub-class instance will use the halo_table column that is consistent with the input mass definition.

At the conclusion of the constructor, a few empty sequences are bound to the instance. These are documented in the The param_dict mechanism and Explanation of the prof_param_keys mechanism.