CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
PkXizSpace.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2010 by Federico Marulli *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ********************************************************************/
20 
36 #include "Cosmology.h"
37 
38 using namespace std;
39 
40 using namespace cbl;
41 
42 
43 // =====================================================================================
44 
45 
46 double cbl::cosmology::Cosmology::xi0_Kaiser (const double rad, const double f_sigma8, const double bias_sigma8, const std::string method_Pk, const double redshift, const bool store_output, const std::string output_root, const bool xiType, const double k_star, const bool NL, const int norm, const double r_min, const double r_max, const double k_min, const double k_max, const double aa, const bool GSL, const double prec, const std::string file_par)
47 {
48  // ----- get the real-space DM xi(r) -----
49 
50  vector<double> rr, Xi;
51  get_xi(rr, Xi, method_Pk, redshift, store_output, output_root, xiType, k_star, NL, norm, r_min, r_max, k_min, k_max, aa, GSL, prec, file_par);
52 
53  double XiR = interpolated(rad, rr, Xi, "Linear");
54 
55  return xi_ratio(f_sigma8, bias_sigma8)*XiR*pow(bias_sigma8/sigma8_Pk(method_Pk, redshift, store_output, output_root), 2);
56 }
57 
58 
59 // =====================================================================================
60 
61 
62 std::vector<double> cbl::cosmology::Cosmology::xi0_Kaiser (const std::vector<double> rad, const double bias, const std::string method_Pk, const double redshift, const bool store_output, const std::string output_root, const bool NL, const int norm, const double k_min, const double k_max, const double prec, const std::string file_par)
63 {
64  const vector<double> kk = logarithmic_bin_vector(100, k_min, k_max);
65  const vector<double> Pk = this->Pk_matter(kk, method_Pk, NL, redshift, store_output, output_root, norm, k_min, k_max, prec, file_par);
66 
67  vector<double> xi = wrapper::fftlog::transform_FFTlog(rad, 1, kk, Pk, 0);
68 
69  const double fact = bias*bias*xi_ratio(linear_growth_rate(redshift, 1.)/bias);
70 
71  for (size_t i=0; i<xi.size(); i++)
72  xi[i] *= fact;
73 
74  return xi;
75 }
76 
77 
78 // =====================================================================================
79 
80 
81 double cbl::cosmology::Cosmology::xi2D_dispersionModel (const double rp, const double pi, const double f_sigma8, const double bias_sigma8, const double sigmav, const std::string method_Pk, const double redshift, const int FV, const bool NL, std::vector<double> rr, std::vector<double> &Xi, std::vector<double> &Xi_, std::vector<double> &Xi__, const bool store_output, const std::string output_root, const int index, const bool bias_nl, const double bA, const bool xiType, const double k_star, const bool xiNL, const double v_min, const double v_max, const int step_v, const int norm, const double r_min, const double r_max, const double k_min, const double k_max, const double aa, const bool GSL, const double prec, const std::string file_par)
82 {
83  if (m_sigma8<0) return ErrorCBL("sigma8<0!", "xi2D_dispersionModel", "PkXizSpace.cpp");
84 
85  double bias = bias_sigma8/m_sigma8;
86  double beta = f_sigma8/bias_sigma8;
87 
88 
89  // ----- get the real-space xi(r) -----
90 
91  if (Xi.size()==0) {
92  get_xi(rr, Xi, method_Pk, redshift, store_output, output_root, xiType, k_star, xiNL, norm, r_min, r_max, k_min, k_max, aa, GSL, prec, file_par);
93  get_barred_xi(rr, Xi, Xi_, Xi__, method_Pk, redshift, xiType, k_star, xiNL, norm, r_min, r_max, k_min, k_max, aa, prec, file_par);
94  }
95 
96 
97  // ----- adding a scale dependent bias -----
98 
99  if (bias_nl==1)
100  for (unsigned int i=0; i<Xi.size(); i++) {
101  Xi[i] *= b_nl(rr[i],bA);
102  Xi_[i] *= b_nl(rr[i],bA);
103  Xi__[i] *= b_nl(rr[i],bA);
104  }
105 
106 
107  // ----- compute xi(rp,pi) -----
108 
109  if (!NL)
110  return xi2D_lin_model(rp, pi, beta, bias, rr, Xi, Xi_, Xi__, index, 0, 0);
111 
112  else {
113  double var = (1.+redshift)/HH(redshift);
114  return xi2D_model(rp, pi, beta, bias, sigmav, rr, Xi, Xi_, Xi__, var, FV, index, 0, 0, v_min, v_max, step_v);
115  }
116 }
117 
118 
119 // =====================================================================================
120 
121 
122 double cbl::cosmology::Cosmology::xi_star (const double rr, const double redshift, const bool store_output, const std::string output_root, const double k_star, const double k_min, const double k_max, const double prec, const std::string file_par)
123 {
124  string method_Pk1 = "EisensteinHu";
125  string method_Pk2 = "CAMB";
126 
127  Pk_0(method_Pk1, redshift, store_output, output_root, k_min, k_max, prec, file_par);
128 
129  classfunc::func_xistar func(m_Omega_matter, m_Omega_baryon, m_Omega_neutrinos, m_massless_neutrinos, m_massive_neutrinos, m_Omega_DE, m_Omega_radiation, m_hh, m_scalar_amp, m_scalar_pivot, m_n_spec, m_w0, m_wa, m_fNL, m_type_NG, m_tau, m_model, m_unit, rr, redshift, store_output, output_root, k_max, k_star);
130 
131  function<double(double)> ff = bind(&classfunc::func_xistar::operator(), func, std::placeholders::_1);
132 
133  double Int1 = wrapper::gsl::GSL_integrate_qag(ff, 0., 1.e2, 1.e-3);
134  double Int2 = wrapper::gsl::GSL_integrate_qag(ff, 1.e2, 1.e3, 1.e-3);
135 
136  double Int = (rr<1) ? Int1+Int2 : Int1; // check!!!
137 
138  return 1./(2.*pow(par::pi, 2))*Int;
139 }
140 
141 
142 // =====================================================================================
143 
144 
145 double cbl::cosmology::Cosmology::xisnl_gnw (const double rp, const double pi, const double f_sigma8, const double bias_sigma8, const double bA, const double redshift, std::vector<double> rr, std::vector<double> Xi, std::vector<double> &Xi_, std::vector<double> &Xi__, const bool store_output, const std::string output_root)
146 {
147  string method_Pk = "EisensteinHu";
148 
149  return xi2D_dispersionModel(rp, pi, f_sigma8, bias_sigma8, -1, method_Pk, redshift, -1, 0, rr, Xi, Xi_, Xi__, store_output, output_root, 1, bA);
150 }
151 
152 
153 // =====================================================================================
154 
155 
156 double cbl::cosmology::Cosmology::xis_gBAO (const double rp, const double pi, const double f_sigma8, const double bias_sigma8, const double redshift, std::vector<double> rr, std::vector<double> Xi, std::vector<double> &Xi_, std::vector<double> &Xi__, const bool store_output, const std::string output_root, const double k_star, const double x_min, const double x_max, const int step_x)
157 {
158  if (m_sigma8<0) ErrorCBL("sigma8<0!", "xis_gBAO", "PkXizSpace.cpp");
159 
160  int FV = -1;
161  bool NL = 0;
162 
163  string method_Pk = "CAMB";
164 
165  vector<double> xx = linear_bin_vector(step_x, x_min, x_max);
166  double delta_x = xx[1]-xx[0];
167 
168  double xis = 0., sigmav = -1;
169 
170  double f_g = f_sigma8/m_sigma8;
171 
172  for (unsigned int k=0; k<xx.size(); k++) {
173 
174  double pi_new = pi-xx[k];
175 
176  xis += xi2D_dispersionModel(rp, pi_new, f_sigma8, bias_sigma8, sigmav, method_Pk, redshift, FV, NL, rr, Xi, Xi_, Xi__, store_output, output_root, 0, -1., 1, k_star)*f_star(xx[k], f_g, k_star)*delta_x;
177 
178  }
179 
180  return xis;
181 }
182 
183 
184 // =====================================================================================
185 
186 
187 double cbl::cosmology::Cosmology::xi2D_CW (const double rp, const double pi, const double beta, const double bias_lin, const double bA, const double sigmav0, const double cmu, const double cs1, const double cs2, const double redshift, std::vector<double> rr1, std::vector<double> Xi1, std::vector<double> rr2, std::vector<double> Xi2, std::vector<double> &Xi1_, std::vector<double> &Xi1__, std::vector<double> &Xi2_, std::vector<double> &Xi2__, const bool store_output, const std::string output_root, const bool BAO, const bool xiType, const double k_star, const bool xiNL, const double r_min, const double r_max, const double v_min, const double v_max, const int step_v, const double k_min, const double k_max, const double x_min, const double x_max, const int step_x, const double aa, const bool GSL, const double prec, const std::string file_par)
188 {
189  if (rr1.size()==0) {
190  string method_Pk1 = "EisensteinHu";
191  string method_Pk2 = "CAMB";
192  get_xi(rr1, Xi1, method_Pk1, redshift, store_output, output_root, xiType, k_star, xiNL, 1, r_min, r_max, k_min, k_max, aa, GSL, prec, file_par);
193  get_xi(rr2, Xi2, method_Pk2, redshift, store_output, output_root, xiType, k_star, xiNL, 0, r_min, r_max, k_min, k_max, aa, GSL, prec, file_par);
194  get_barred_xi(rr1, Xi1, Xi1_, Xi1__, method_Pk1, redshift, xiType, k_star, xiNL, 0, r_min, r_max, k_min, k_max, aa, prec, file_par);
195  get_barred_xi(rr2, Xi2, Xi2_, Xi2__, method_Pk2, redshift, xiType, k_star, xiNL, 0, r_min, r_max, k_min, k_max, aa, prec, file_par);
196  }
197 
198  double var = (1.+redshift)/HH(redshift);
199 
200  double delta_v = (v_max-v_min)/step_v;
201 
202  double vel = v_min;
203 
204  double xi2D = 0.;
205 
206 
207  for (int k=0; k<step_v; k++) {
208 
209  double pi_new = pi-vel*var;
210 
211  double xi_tilde = xisnl_gnw(rp, pi_new, beta, bias_lin, bA, redshift, rr1, Xi1, Xi1_, Xi1__, store_output, output_root);
212 
213  if (BAO) xi_tilde += xis_gBAO(rp, pi_new, beta, bias_lin, redshift, rr2, Xi2, Xi2_, Xi2__, store_output, output_root, k_star, x_min, x_max, step_x);
214  xi2D += xi_tilde*f_v(vel, rp, pi_new, var, sigmav0, cmu, cs1, cs2)*delta_v;
215 
216  vel += delta_v;
217  }
218 
219  return xi2D;
220 }
The class Cosmology.
double xis_gBAO(const double rp, const double pi, const double f_sigma8, const double bias_sigma8, const double redshift, std::vector< double > rr, std::vector< double > Xi, std::vector< double > &Xi_, std::vector< double > &Xi__, const bool store_output=true, const std::string output_root="test", const double k_star=-1., const double x_min=-3000., const double x_max=3000., const int step_x=500)
the function ξg,BAO(s) of the Chuang & Wang 2012 model
Definition: PkXizSpace.cpp:156
double xi2D_dispersionModel(const double rp, const double pi, const double f_sigma8, const double bias_sigma8, const double sigmav, const std::string method_Pk, const double redshift, const int FV, const bool NL, std::vector< double > rr, std::vector< double > &Xi, std::vector< double > &Xi_, std::vector< double > &Xi__, const bool store_output=true, const std::string output_root="test", const int index=-1, const bool bias_nl=0, const double bA=-1., const bool xiType=0, const double k_star=-1., const bool xiNL=0, const double v_min=-3000., const double v_max=3000., const int step_v=500, const int norm=-1, const double r_min=0.1, const double r_max=150., const double k_min=0.001, const double k_max=100., const double aa=0., const bool GSL=false, const double prec=1.e-2, const std::string file_par=par::defaultString)
2D correlation function, ξ(rp,π), predicted by the dispersion model
Definition: PkXizSpace.cpp:81
double xi0_Kaiser(const double rad, const double f_sigma8, const double bias_sigma8, const std::string method_Pk, const double redshift, const bool store_output=true, const std::string output_root="test", const bool xiType=0, const double k_star=-1., const bool NL=false, const int norm=-1, const double r_min=0.1, const double r_max=150., const double k_min=0.001, const double k_max=100., const double aa=0., const bool GSL=false, const double prec=1.e-2, const std::string file_par=par::defaultString)
monopole of the redshift-space two-point correlation function in the Kaiser limit
Definition: PkXizSpace.cpp:46
double xi_star(const double rr, const double redshift, const bool store_output=true, const std::string output_root="test", const double k_star=-1., const double k_min=0.001, const double k_max=100., const double prec=1.e-2, const std::string file_par=par::defaultString)
the function ξ* of the Chuang & Wang 2012 model
Definition: PkXizSpace.cpp:122
double xisnl_gnw(const double rp, const double pi, const double f_sigma8, const double bias_sigma8, const double bA, const double redshift, std::vector< double > rr, std::vector< double > Xi, std::vector< double > &Xi_, std::vector< double > &Xi__, const bool store_output=true, const std::string output_root="test")
the function ξg,nw(s) of the Chuang & Wang 2012 model
Definition: PkXizSpace.cpp:145
double xi2D_CW(const double rp, const double pi, const double beta, const double bias_lin, const double bA, const double sigmav0, const double cmu, const double cs1, const double cs2, const double redshift, std::vector< double > rr1, std::vector< double > Xi1, std::vector< double > rr2, std::vector< double > Xi2, std::vector< double > &Xi1_, std::vector< double > &Xi1__, std::vector< double > &Xi2_, std::vector< double > &Xi2__, const bool store_output=true, const std::string output_root="test", const bool BAO=1, const bool xiType=0, const double k_star=-1, const bool xiNL=0, const double r_min=0.1, const double r_max=150., const double v_min=-3000., const double v_max=3000., const int step_v=500, const double k_min=0.001, const double k_max=100., const double x_min=-3000., const double x_max=3000., const int step_x=500, const double aa=0., const bool GSL=false, const double prec=1.e-2, const std::string file_par=par::defaultString)
2D correlation function, ξ(rp,π), predicted by the Chuang & Wang model
Definition: PkXizSpace.cpp:187
static const double pi
: the ratio of a circle's circumference to its diameter
Definition: Constants.h:199
double bias(const double Mmin, const double sigmalgM, const double M0, const double M1, const double alpha, const std::shared_ptr< void > inputs)
the mean galaxy bias
std::vector< double > transform_FFTlog(const std::vector< double > yy, const int dir, const std::vector< double > xx, const std::vector< double > fx, const double mu=0, const double q=0, const double kr=1, const int kropt=0)
wrapper of the FFTlog to compute the discrete Fourier sine or cosine transform of a logarithmically...
Definition: FFTlog.cpp:43
double GSL_integrate_qag(gsl_function Func, const double a, const double b, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000, const int rule=6)
integral, computed using the GSL qag method
Definition: GSLwrapper.cpp:180
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
std::vector< double > Xi2(const std::vector< double > rr, const std::vector< double > kk, const std::vector< double > Pk2, const double k_cut=0.58, const double cut_pow=4, const int IntegrationMethod=1)
function to obtain the two point correlation function quadrupole
std::vector< T > logarithmic_bin_vector(const size_t nn, const T min, const T max)
fill a std::vector with logarithmically spaced values
Definition: Kernel.h:1621
std::vector< T > linear_bin_vector(const size_t nn, const T min, const T max)
fill a std::vector with linearly spaced values
Definition: Kernel.h:1604
double f_v(const double vel, const double sigmav, const int FV)
pairwise velocity distribution
Definition: FuncXi.cpp:616
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
Definition: Kernel.h:780
double xi2D_model(const double rp, const double pi, const double beta, const double bias, const double sigmav, const std::vector< double > rad_real, const std::vector< double > xi_real, const std::vector< double > xi_, const std::vector< double > xi__, const double var, const int FV, int index=-1, const bool bias_nl=0, const double bA=0., const double v_min=-3000., const double v_max=3000., const int step_v=500)
the non-linear dispersion model for ξ(rp,π)
Definition: FuncXi.cpp:574
double xi_ratio(const double beta)
the ratio between the redshift-space and real-space correlation functions
Definition: FuncXi.cpp:287
double f_star(const double xx, const double f_g, const double k_star)
velocity distribution used to model BAO
Definition: FuncXi.cpp:642
double interpolated(const double _xx, const std::vector< double > xx, const std::vector< double > yy, const std::string type)
1D interpolation
Definition: Func.cpp:445
double xi2D_lin_model(const double beta, const double bias, const double xi_real, const double xi_, const double xi__, const double P_2, const double P_4)
the linear dispersion model for ξ(rp,π)
Definition: FuncXi.cpp:473
double b_nl(const double rr, const double bA, const double bB=10., const double bC=4.)
a possible parameterization of the non-linear bias
Definition: FuncXi.cpp:653