CAMB sources: for number counts, lensing and dark-age 21cm power spectra
plus thermal history, perturbed recombination, CMB cross-correlations

Based on CAMB. At some point it may be integrated into the main code, but not yet.

Features: The paper for the counts calculation is arXiv:1105.5292, and the main reference for the 21cm results is astro-ph/0702600 (BibTex).

Download the Fortran 90 source code. This version November 2013. The code is also available via CAMB_sources branch of CAMB's git repository.

See CosmoCoffee for support.

This code is based on CAMB which is based on CMBFAST which is partly based on COSMICS. It uses RECFAST for the ionization history.


If you are familiar with CAMB this should be quite familiar. The main parameters are in the params.ini file - see the comments in this file for description. Sample files params_lensing.ini and params_counts.ini are also provided to give typical settings for lensing and number count results. Install and run e.g. like this:

At low L the results are fully spherical and calculated by direct integration of source functions against spherical Bessel functions. The code assumes you have a finite-width window function (specified in modules.f90, implemented as a Gaussian in redshift by default), and integrals are integrated by parts (as in CAMB) so the window functions should be smooth. On small scales results can be calculated accurately much faster using the Limber approximation if you have set limber_windows = T, with the full spherical result being used at lower L. Limber can also be used for counts window functions on scales much narrower than the window width; the code tries to guess the appropriate scale at which to switch. Cross-correlation spectra should work as longer the domains of validity of the Limber approximation overlap. The limber_phiphi input parameter specifies the Limber L to use for the CMB lensing potential, and Limber is always switched for other window functions at higher L (so decrease limber_phiphi to use Limber to lower L, which is often accurate except for e.g. cross-correlation with the CMB temperature).


Set the scalar_covariance_output_file to output a file with all of the auto and cross power spectra (by default _scalCovCls.dat). The (partially redundant) format of this file is columns of the form
L C_11 C_12... C_1n C_21 C_22 .... C_nn
where C_{ij} is L(L+1)CijL/2pi and the fields are ordered T, E, Phi, win_1, win_2..., where Phi is the CMB lensing potential. The power spectra are unlensed and dimensionless.

There are some supplied plotting scripts in ./python folder, e.g. see for a sample script to plot a matrix results in the _scalCovCls.dat file. You can also use the supplied plotWindowCl MatLab script e.g.

plots the angular cross-spectrum of the first and second window functions (CMB lensing potential is index 0,E index -1, and T index -2). You can also plot comparisons of multiple files with same L ranges (useful for testing numerical stability with different accuracy settings), e.g.
Transfer functions are the same as in CAMB, except when you are generating 21cm power spectrum in which case the matter power spectrum file becomes that for the monopole source, and the columns in the transfer function output file are
k/h Delta_CDM/k^2 Delta_b/k^2 Monopole_source/k^2 v_newtonian/k^2 Delta_Tg/k^2 ...
where all quantities are in the synchronous gauge and "..." denotes the same as for CAMB.
scalCls file
Angular power spectra are also output to output_root_scalCls.dat. The columns are in the more confusing but less redundant form as used by earlier versions of CAMB sources:
l C_TT C_EE C_TE C_Phi C_PhiT C_win_1 C_win_2 ... C_Win_T1 C_Win_T2 .... C_win1_win2 ...
Here all C_l are l(l+1)C_l/2pi except for C_Phi and C_PhiT which are C_Phi= l^4 C_l_phi where C_l_phi is the (CMB) lensing potential power spectrum and C_PhiT = l^3 C_l_phiT. So for two window functions, columns 7 and 8 are their auto-spectra, and 11 is their cross-spectrum.

Non-linear evolution

By default compiles with Halofit for non-linear corrections at low redshift. Supplied code second_PT.f90 (not tested recently) instead uses third-order Newtonian perturbation theory. Change NONLINEAR in the Makefile to use this instead. Note that Halofit gives non-linear power spectra. second_PT instead gives just the non-linear correction (which is much smaller than the linear term at high redshift).

Included terms

CAMB sources can calculate the linear-theory number count and 21cm dark-age power spectra including all GR and velocity effects. For the counts you can determine which terms are included using the counts_xxx parameters in the .ini file; these should all be true, in addition to DoRedshiftLensing to include all the effects. Setting just e.g. counts_density=T would include only the Newtonian-gauge density source term, neglecting redshift distortions and the many other effects. The CMB always includes all terms, so if you only want ISW you'd have to edit the output routine in equations.f90 (but of course the correlation with number counts is dominated by the ISW contribution anyway).

Web page maintained by Antony Lewis.