Playing with CAMB/CosmoMC

Play with CAMB/CosmoMC
Gong-Bo Zhao
ICG, Portsmouth
May, 2010
Why CAMB/CosmoMC?
 Very efficient
 Well-structured (modulised) -- easy to tweak and hack
 Well-supported – cosmocoffee.info
 Popular – mainstream numeric tool in cosmology
2
ICG PhD lectures
May, 2010
This 4.5-hr course is to …
 Show you how to run CAMB/CosmoMC
 Link CAMB equations to Ma&Bertschinger ‘96
 Show several useful examples of hacking CAMB
-- dynamical dark energy, modified gravity
 Guide you how to modify CAMB/CosmoMC
for your own research purpose
 Show you useful numerical tricks extensively
used in CAMB
3
ICG PhD lectures
May, 2010
This course is not on …
 Theory (see Kazuya, Rob and Cyril’s lectures)
 Fortran programming (See Numerical Recipe)
4
ICG PhD lectures
May, 2010
Warming-ups
 Download, compile and run CAMB
camb.info
make clean; make all
./camb params.ini
 Change model parameters in params.ini and make CMB, P(k) plots
change cosmo. params
add neutrinos
do CMB lensing
do vector and tensor modes
compare with Wayne Hu’s plots at
http://background.uchicago.edu/~whu/metaanim.html
5
ICG PhD lectures
May, 2010
Look into the code…
Analyze the code using
“understand for fortran”
http://www.scitools.com/download/
(choose the free 15-day trial version)
Structure of CAMB
Messy?
Not really!!
7
ICG PhD lectures
May, 2010
Structure of CAMB
preparation
core
output results
8
ICG PhD lectures
May, 2010
Structure of CAMB_GetResults
9
ICG PhD lectures
May, 2010
Structure of CMBmain
10
ICG PhD lectures
May, 2010
Structure of CMBmain
11
ICG PhD lectures
May, 2010
CAMB language A,B,C
a' da /d
=
, tau = conformal time
a
a
dgrho = 8Ga2   ii , dgq = 8Ga2  (  i  pi )v i
Background : grho = 8Ga 2 , adotoa =
T  :
i
i
clxc = c , clxb = b , clxq = DE
G
12

:
h'6'
etak = k, z = h' /(2k), sigma =
2k
ICG PhD lectures
May, 2010
CAMB vs. M+B ’96
astro-ph/9506072
' k 2 = 4 Ga2 ( P )
' k = dgq/2
Differential equations to evolve in CAMB
1
clxcdot =  kz
 'c =  h'
2
1 a'
2
h' = 4Ga2T00
k 
z = (0.5dgrho/ k + k)/adotoa
2a
Constraint equations (algebraic)
h'6'
2
=
sigma = z +1.5dgq/k
2k

Hacking 1: Dynamical DE
Task:
Default CAMB only works for constant w. Modify it to
implement the CPL parametrisa-tion, i.e. w(a)=w0+wa(1-a)
and calculate the luminosity distance, CMB and P(k) for a model
of {-1.5, +(-)0.4}. Compare your spectra with that of the
LCDM model.
14
ICG PhD lectures
May, 2010
Start the game!
Spot the dark energy stuff in CAMB
We need w(a), dw/da, Int {[1+w(a)]dlna}
Files to hack: equations.f90, inidriver.F90
Subroutine/functions to hack: dtauda, fderivs, output
Change the background and the DE perturbation
equations!!
15
ICG PhD lectures
May, 2010
Background evolution
X   exp{3 1 [1 w(a')]dln a'}
0
X
a
For constant w (default CAMB)
grhoa2=grhoa2+grhov*a2**2
 For functional w (hacked)
grhoa2=grhoa2+grhov*Funcofw(a,..)*a2
16
ICG PhD lectures
May, 2010
function Funcofw(a,deriv)
implicit none
real(dl) a, Funcofw, a0
real(dl) w0, wa
integer deriv
if (a .lt. 1.d-8) then
a0 = 1.d-8
else
a0 = a
end if
if (deriv==0) then
Funcofw = w0+wa*(1.d0-a0)
else if (deriv ==1) then
Funcofw = -wa*a0
else if (deriv ==2) then
Funcofw = a0**(2.d0 - 3.d0*(1.d0+w0+wa))*exp(3.d0*wa*(a0-1.d0))
end if
end function Funcofw
17
ICG PhD lectures
May, 2010
Output m
In inidriver.F90
open(unit=50,file=‘dL_SN.dat’)
do i=1, 1000
zz(i)=1.7d0+dble(i-1)/dble(1000-1)
write(50,'(100e15.6)') zz(i), 5*log10((1+zz(i)) &
**2*AngularDiameterDistance(zz(i)))+25
end do
close(50)
18
ICG PhD lectures
May, 2010
DE perturbation equations
ayprime(EV%w_ix)= -3*adotoa*(cs2_lam-Funcofw(a,0))*(clxq+3*adotoa*&
(1+Funcofw(a,0))*vq/k) -(1+Funcofw(a,0))*k*vq -&
(1+Funcofw(a,0))*k*z -3*adotoa*adotoa*Funcofw(a,1)*vq/k
ayprime(EV%w_ix+1) = -adotoa*(1-3*cs2_lam)*vq +
k*cs2_lam*clxq/(1+Funcofw(a,0))
20
ICG PhD lectures
May, 2010
21
ICG PhD lectures
May, 2010
Output Dark Energy perturbation dDE(h), vDE(h) at k=10-3
Mpc-1
 Note that in CAMB language
dDE = y(EV%w_ix)
vDE = y(EV%w_ix+1)
 Uncomment the stuff in cmbmain.f90,
EV%q=1.d-3; EV%q2=EV%q**2
tol1=tol/exp(AccuracyBoost-1)
do j=1,6000
tauend = taustart * exp(j/6000._dl*log(CP%tau0/taustart))
call GaugeInterface_EvolveScal(EV,tau,y,tauend,tol1,ind,c,w)
write (*,’(4E15.5)') tauend,1/y(1)-1, y(EV%w_ix) ,y(EV%w_ix+1)
end do
stop
23
ICG PhD lectures
May, 2010
Weller and Lewis, 2003
Singularity?!
 Output CMB Cl’s for the model w0=-1.5, wa=+1.0 to see
what happens.
 This singularity stems from the fact that w crosses -1.
Technically, it’s due to the term of dw/dz/(1+w).
 No-Go Theorem: The w for single fluid (scalar field) cannot
cross -1 in GR! For proof, see Appendix of astroph/0703202.
 Solution: astro-ph/0507482 (quintom scenario),
or arXiv:0808.3125 (PPF implementation)
26
ICG PhD lectures
May, 2010
27
ICG PhD lectures
May, 2010
29
ICG PhD lectures
May, 2010
One further step?
Generalize our hacked code to make it
work for an arbitrary w(z).
Leave it to you guys to play with it for fun!!
Hacking 2: TO BE OR NOT TO BE
??
-- MODIFY CAMB TO WORK IN MODIFIED
GRAVITY
Task
Default CAMB only works in GR. Modify it to implement MG.
Reproduce the plots on my website.
http://userweb.port.ac.uk/~zhaog/MGCAMB.html
31
ICG PhD lectures
May, 2010
Universe is Accelerating
Atoms
Dark Matter
 ?!
Scalar-tensor gravity
(e.g. Chameleon, f(R)…)
DGP, Degravitation
…
Indistinguishable at the background level
Need to study the structure growth to break the degeneracy
32
Linear perturbation in FRW universe
Modified
Gravity
General Relativity
33
What to do technically?
 Given m(a,k) and
g(a,k), we need to solve
k2F
= -m(a,k) 4pG a2rD
F/Y =
g(a,k)
in the synchronous gauge, which is used in CAMB.
Note that
34
ICG PhD lectures
May, 2010
 So we have
 Finally, we have (for details, see Appendix of 0809.3791),
35
ICG PhD lectures
May, 2010
 Note that in default CAMB, d (overdensity for different
species) and h (metric perturbation in synchronous
gauge) are actually evolved, and other Einstein equations are used
as constraint equations (see this slide).
 In MG, we need to evolve d and a, and get h from
constraint equations.
 To add one more variable to evolve in CAMB, we need to define it,
set initial condition for it, and change fderivs and output properly.
 See how to modify the code in the lecture.
36
ICG PhD lectures
May, 2010
1 1k a
1 1k a
(a,k) 
,  (a,k) 
2 s
2 s
1  2 k a
1  2 k a
2
37
ICG PhD lectures
s
2
s
May, 2010
38
ICG PhD lectures
May, 2010
Fit your own parameters using CosmoMC
CosmoMC fits your model parameters to data by
exploring the parameter space in a smart way
(Metropolis-Hastings algorithm). It calls CAMB to
calculate the theoretical spectra of a model, and
compare to data.
39
ICG PhD lectures
May, 2010
How to add your own parameter to CosmoMC?
 Tell CosmoMC your parameters’ names in CMB_Cls_simple.f90
 Define them in cmbtype.f90
 Map them in params_CMB.f90
 Change the # of parameters in settings.f90
 Done!!
 See the example in the lecture!!
40
ICG PhD lectures
May, 2010
Astro-ph/0511625
41
ICG PhD lectures
May, 2010
Useful references
 Camb.info; cosmologist.info/cosmomc/
 Cosmocoffee.info
 M+B: astro-ph/9506072
 Jussi’s ICG lectures: www.icg.port.ac.uk/~valiviij/
 Numerical Recipe: www.nr.com
 Plotting software: OriginPro, Matlab, IDL, gnuplot
42
ICG PhD lectures
May, 2010
Have fun!!
43
ICG PhD lectures
May, 2010