42 m_cosmo = std::make_shared<cosmology::Cosmology>(cosm);
50 m_nbins = (int)(redshift_edges.size()-1);
57 cbl::ErrorCBL(
"Different number of redshift bins and input models!",
"set_SSC",
"SuperSampleCovariance");
66 m_cosmo = std::make_shared<cosmology::Cosmology>(cosm);
67 m_cosmo->set_unit(
false);
69 m_cosmo_param = cosmo_param;
70 m_method_Pk = method_Pk;
72 m_store_output = store_output;
74 m_nbins = (int)(W_mean.size());
76 m_precision = precision;
78 m_compute_gaussian_window(delta_z, W_mean, W_std);
80 if (m_nbins != (
int)(m_response_func.size()))
81 cbl::ErrorCBL(
"Different number of redshift bins and input models!",
"set_SSC",
"SuperSampleCovariance");
90 m_nsteps = (int)((redshift_edges[redshift_edges.size()-1]-redshift_edges[0])/delta_z + 1);
91 if (m_nsteps < m_nbins)
92 cbl::ErrorCBL(
"m_nsteps can not be lower than the number of redshift bins!",
"m_compute_topHat_window",
"SuperSampleCovariance");
94 m_redshifts.resize(m_nsteps);
95 m_windows.resize(m_nbins);
97 for (
int i=0; i<m_nbins; i++) {
98 m_windows[i].resize(m_nsteps);
99 double iter = redshift_edges[0]-delta_z;
100 double Delta_z = redshift_edges[i+1] - redshift_edges[i];
101 for (
int j=0; j<m_nsteps; j++) {
103 m_redshifts[j] = iter;
104 if ((iter>redshift_edges[i]) && (iter<=redshift_edges[i+1]))
105 m_windows[i][j] = 1/Delta_z;
116 double max_z = W_mean[W_mean.size()-1]+3.5*W_std[W_mean.size()-1];
117 double min_z = W_mean[0]-3.5*W_std[0];
119 m_nsteps = (int)((max_z - min_z) / delta_z + 1);
120 m_redshifts.resize(m_nsteps);
121 m_windows.resize(m_nbins);
123 for (
int i=0; i<m_nbins; i++) {
124 m_windows[i].resize(m_nsteps);
125 double iter = min_z - delta_z;
126 for (
int j=0; j<m_nsteps; j++) {
128 m_redshifts[j] = iter;
129 m_windows[i][j] = exp( - (m_redshifts[j] - W_mean[i]) * (m_redshifts[j] - W_mean[i]) / (2*W_std[i]*W_std[i]) ) / sqrt(2*
cbl::par::pi*W_std[i]*W_std[i]);
141 std::vector<double> comov_dist(m_nsteps), dV(m_nsteps), growthf(m_nsteps);
142 for (
int i=0; i<m_nsteps; i++){
143 comov_dist[i] = cosmo.
D_C(m_redshifts[i]);
144 dV[i] = comov_dist[i] * comov_dist[i] * cosmo.
D_H() * cosmo.
EE_inv(m_redshifts[i]);
145 growthf[i] = cosmo.
DN(m_redshifts[i]);
149 std::vector<double> Inorm(m_nbins);
150 std::vector<std::vector<double>> integrand (m_nbins,std::vector<double>(m_nsteps));
151 for (
int i=0; i<m_nbins; i++){
152 for (
int s=0; s<m_nsteps; s++){
153 integrand[i][s] = dV[s] * m_windows[i][s] * m_windows[i][s] / 1.e10;
156 Inorm[i] = integ.
integrate_cquad(m_redshifts[0], m_redshifts[m_redshifts.size()-1]) * 1.e10;
160 const double h = cosmo.
hh();
161 const double keq = 0.02/h;
162 const double klogwidth = 10;
163 double max_comov_dist = comov_dist[comov_dist.size()-1];
164 double min_comov_dist = comov_dist[0];
168 if (keq<(1./max_comov_dist))
169 kmin = keq/klogwidth;
171 kmin = (1./max_comov_dist)/klogwidth;
172 if (keq>(1./min_comov_dist))
173 kmax = keq*klogwidth;
175 kmax = min_comov_dist*klogwidth;
177 const double nk = pow(2,m_precision);
178 const double logkmin = log(kmin);
179 const double logkmax = log(kmax);
180 std::vector<double> logk(nk);
181 std::vector<double> kk(nk);
182 for (
size_t i=0; i<logk.size(); i++) {
183 logk[i]=logkmin+i*(logkmax-logkmin)/(nk-1);
187 std::vector<double> Pk_new = cosmo.
Pk_matter(kk,
"EisensteinHu", m_NL, 0., m_store_output,
"test", -1, 1.e-4, 100., 1.e-2,
cbl::par::defaultString,
false);
188 std::vector<std::vector<double>> Uarr(m_nbins, std::vector<double>(logk.size()));
189 std::vector<double> kr(m_nsteps);
190 std::vector<std::vector<double>> integrand2(m_nbins, std::vector<double>(m_nsteps));
191 for (
int i=0; i<m_nbins; i++) {
192 for (
size_t j=0; j<logk.size(); j++) {
193 for (
size_t s=0; s<m_redshifts.size(); s++) {
194 kr[s] = kk[j]*comov_dist[s];
195 integrand2[i][s] = dV[s] * m_windows[i][s] * m_windows[i][s] * growthf[s] * sin(kr[s]) / kr[s] / 1.e10;
198 Uarr[i][j] = integ.
integrate_cquad(m_redshifts[0], m_redshifts[m_redshifts.size()-1]) * 1.e10;
203 std::vector<std::vector<double>> Cl_zero(m_nbins,std::vector<double>(m_nbins));
204 std::vector<std::vector<double>> U1(m_nbins, std::vector<double>(logk.size()));
205 std::vector<std::vector<double>> U2(m_nbins, std::vector<double>(logk.size()));
206 std::vector<std::vector<double>> integrand3(m_nbins, std::vector<double>(logk.size()));
207 for (
int i=0; i<m_nbins; i++){
208 for (
size_t j=0; j<logk.size(); j++){
209 U1[i][j] = Uarr[i][j]/Inorm[i];
211 for (
int k=i; k<m_nbins; k++){
212 for (
size_t j=0; j<logk.size(); j++){
213 U2[k][j] = Uarr[k][j]/Inorm[k];
214 integrand3[k][j] = kk[j] * kk[j] * Pk_new[j] * U1[i][j] * U2[k][j] * 1.e10;
222 for (
int i=0; i<m_nbins; i++){
223 for (
int j=0; j<m_nbins; j++){
224 Cl_zero[i][j] = Cl_zero[std::min(i,j)][std::max(i,j)];
227 std::vector<std::vector<double>> Sij(m_nbins, std::vector<double>(m_nbins));
228 for (
int i=0; i<m_nbins; i++){
229 for (
int j=0; j<m_nbins; j++){
230 Sij[i][j] = Cl_zero[i][j] / m_area;
247 for (
size_t i=0; i<m_cosmo_param.size(); ++i)
250 std::vector<std::vector<double>> Sij = m_compute_Sij(cosmo);
272 std::string mkdir =
"mkdir -p "+dir;
if (system(mkdir.c_str())) {}
275 std::string file_out = dir+file;
276 std::ofstream fout(file_out.c_str());
280 fout <<
"### [1] i # [2] j # [3] window[i][j] # [4] redshift " << std::endl;
282 for (
size_t i=0; i<m_windows.size(); ++i)
283 for (
size_t j=0; j<m_windows[i].size(); ++j)
284 fout << setiosflags(std::ios::fixed) << std::setprecision(precision) << std::setw(15) << std::right << i
285 <<
" " << setiosflags(std::ios::fixed) << std::setprecision(precision) << std::setw(15) << std::right << j
286 <<
" " << setiosflags(std::ios::fixed) << std::setprecision(precision) << std::setw(15) << std::right << m_windows[i][j]
287 <<
" " << setiosflags(std::ios::fixed) << std::setprecision(precision) << std::setw(15) << std::right << m_redshifts[j] << std::endl;
289 fout.close(); std::cout << std::endl;
coutCBL <<
"I wrote the file: " << file_out << std::endl;
299 std::vector<std::vector<double>> Sij = m_compute_Sij(*m_cosmo);
302 std::string mkdir =
"mkdir -p "+dir;
if (system(mkdir.c_str())) {}
305 std::string file_out = dir+file;
306 std::ofstream fout(file_out.c_str());
310 fout <<
"### [1] i # [2] j # [3] S_ij " << std::endl;
312 for (
size_t i=0; i<Sij.size(); ++i)
313 for (
size_t j=0; j<Sij[i].size(); ++j)
314 fout << setiosflags(std::ios::fixed) << std::setprecision(precision) << std::setw(15) << std::right << i
315 <<
" " << setiosflags(std::ios::fixed) << std::setprecision(precision) << std::setw(15) << std::right << j
316 <<
" " << setiosflags(std::ios::fixed) << std::setprecision(precision) << std::setw(15) << std::right << Sij[i][j] << std::endl;
318 fout.close(); std::cout << std::endl;
coutCBL <<
"I wrote the file: " << file_out << std::endl;
#define coutCBL
CBL print message.
The class SuperSampleCovariance.
double DN(const double redshift, const double redshift_norm=0., const double prec=1.e-4) const
the normalised amplitude of the growing mode at a given redshift,
void set_parameter(const CosmologicalParameter parameter, const double value)
set the value of one cosmological paramter
double hh() const
get the private member Cosmology::m_hh
double D_H() const
get the private member Cosmology::m_D_H
std::vector< double > Pk_matter(const std::vector< double > kk, const std::string method_Pk, const bool NL, const double redshift, const bool store_output=true, const std::string output_root="test", const int norm=-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, const bool unit1=false)
the dark matter power spectrum
double EE_inv(const double redshift=0.) const
inverse of the auxiliary function used to compute the Hubble function integrand of the comoving dista...
double D_C(const double redshift) const
the comoving line-of-sight distance at a given redshift
int m_nbins
number of redshift bins
std::vector< std::shared_ptr< statistics::Model > > m_response_func
pointer to the response function of the probe
void m_compute_topHat_window(const double delta_z, const std::vector< double > redshift_edges)
compute the top-hat window functions in the redshift bins
std::vector< std::vector< double > > operator()(std::vector< double > ¶meter) const
get
bool m_store_output
store Pk output
void m_compute_gaussian_window(const double delta_z, const std::vector< double > W_mean, const std::vector< double > W_std)
compute the Gaussian window functions in the redshift bins
int Sij_dimension()
return the dimension of the Sij matrix
std::vector< std::vector< double > > m_compute_Sij(cbl::cosmology::Cosmology cosmo) const
compute the S_ij matrix
void write_window_function(const std::string dir, const std::string file)
write the window functions on file
double m_area
survey area in steradians
std::shared_ptr< cosmology::Cosmology > m_cosmo
pointer to the Cosmology object
std::vector< cbl::cosmology::CosmologicalParameter > m_cosmo_param
names of the cosmological parameters
void write_Sij(const std::string dir, const std::string file)
Write the matrix on file.
std::vector< std::vector< double > > get_window_function()
return the window functions
std::string m_method_Pk
method used to compute the power spectrum
double m_precision
precision of the array
bool m_NL
linear o non-linear power-spectrum
SuperSampleCovariance(cbl::cosmology::Cosmology cosm, const std::vector< cbl::cosmology::CosmologicalParameter > cosmo_param, const std::vector< double > redshift_edges, const double area, const std::string method_Pk="EisensteinHu", const double delta_z=0.001, const double precision=10, const bool NL=false, const bool store_output=false)
Default constructor, used to compute the matrix, assuming top-hat window functions....
double integrate_cquad(const double a, const double b, const double rel_err=1.e-2, const double abs_err=1.e-6, const int nevals=100)
compute the definite integral with GSL cquad method
static const std::string defaultString
default std::string value
static const double pi
: the ratio of a circle's circumference to its diameter
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