45 std::vector<double>
cbl::modelling::angularpk::Cl_mixed(std::vector<double> l_mixing, std::vector<std::vector<double>> mixing_matrix, std::vector<double> l, std::vector<double> Cl,
double fsky){
50 std::vector<double>
Cl_mixed(l.size(), 0);
52 for (
size_t j=0; j<l.size(); ++j)
53 for (
size_t i=0; i<l.size(); ++i)
54 Cl_mixed[j]+=mixing_matrix[j+l[0]][i+l[0]]*Cl[i]*_fsky;
66 shared_ptr<STR_data_model> pp = static_pointer_cast<STR_data_model>(inputs);
71 for (
size_t i=0; i<pp->Cpar.size(); ++i)
76 if(pp->z_min_bin2>0 && pp->z_max_bin2>0){
77 lower_limit = min(pp->z_min, pp->z_min_bin2);
78 upper_limit = max(pp->z_max, pp->z_max_bin2);
81 lower_limit = pp->z_min;
82 upper_limit = pp->z_max;
86 const double prec = 1.e-5;
89 const int limit_size = 1000;
92 std::function<double(
double)> integrand_limber = [&l, &par, &pk_interp, &cosmo, &inputs, &z_vector, &kk] (
double redshift)
94 shared_ptr<STR_data_model> pp = static_pointer_cast<STR_data_model>(inputs);
98 if(par.size()>pp->Cpar.size()+4 && pp->dN_par_bin2.size()==0){
99 offset = par[pp->Cpar.size()+1];
100 slope = par[pp->Cpar.size()+2];
104 double distribution_bin2=0;
105 for (
size_t i=0; i<pp->dN_par.size(); ++i){
106 if(redshift<pp->z_max && redshift>pp->z_min)
110 distribution+=par[pp->Cpar.size()]+par[pp->Cpar.size()+1]*redshift;
111 if(pp->dN_par_bin2.size()>0){
112 for (
size_t i=0; i<pp->dN_par_bin2.size(); ++i)
113 if(redshift<pp->z_max_bin2 && redshift>pp->z_min_bin2)
114 distribution_bin2 += pp->dN_par_bin2[i]*pow(redshift, i);
115 else distribution_bin2=0;
116 distribution_bin2+=offset+slope*redshift;
119 std::vector<double> pk_interpolated;
120 std::vector<std::vector<double>> Pk_interp;
121 double kk_exact=double(l+0.5)/cosmo.
D_C(redshift);
122 size_t index_k=10000;
123 double kk_diff=10000;
124 for(
size_t i=0; i<kk.size(); ++i)
125 if(abs(kk[i]-kk_exact)<kk_diff){
126 kk_diff=abs(kk[i]-kk_exact);
129 if(index_k!=0) kk[index_k]=kk_exact;
131 std::vector<std::vector<double>> interp_matrix={{redshift}, {kk[index_k]}};
133 pk_interpolated=pk_interp.
eval_func(interp_matrix);
136 double inv_d2= 1/(cosmo.
D_C(redshift)*cosmo.
D_C(redshift));
137 if(pp->dN_par_bin2.size()>0)
return distribution*distribution_bin2*pk_interpolated[0]*inv_d2*cosmo.
HH(redshift)*_cc;
142 std::vector<double> parameter_integrand;
143 parameter_integrand.emplace_back(l);
144 for (
size_t i=0; i<par.size(); ++i) parameter_integrand.emplace_back(par[i]);
157 shared_ptr<STR_data_model> pp = static_pointer_cast<STR_data_model>(inputs);
163 for (
size_t i=0; i<pp->Cpar.size(); ++i)
167 if(par.size()>pp->Cpar.size()+4 && pp->dN_par_bin2.size()==0){
168 offset = par[pp->Cpar.size()+2];
169 slope = par[pp->Cpar.size()+3];
174 double distribution_bin2=0;
175 for (
size_t i=0; i<pp->dN_par.size(); ++i){
176 if(redshift<pp->z_max && redshift>pp->z_min){
181 distribution+=par[pp->Cpar.size()+1]+par[pp->Cpar.size()+2]*redshift;
182 if(pp->dN_par_bin2.size()>0){
183 for (
size_t i=0; i<pp->dN_par_bin2.size(); ++i)
184 if(redshift<pp->z_max_bin2 && redshift>pp->z_min_bin2){
185 distribution_bin2 += pp->dN_par_bin2[i]*pow(redshift, i);
187 else distribution_bin2=0;
188 distribution_bin2+=offset+slope*redshift;
193 double Pk=cosmo.
Pk_matter({double((l+0.5)/cosmo.
D_C(redshift))}, pp->method_Pk, pp->NL, redshift,
false,
"test", pp->norm, pp->k_min, pp->k_max)[0];
195 double inv_d2= 1/(cosmo.
D_C(redshift)*cosmo.
D_C(redshift));
196 if(pp->dN_par_bin2.size()>0)
return distribution*distribution_bin2*Pk*inv_d2*cosmo.
HH(redshift)*_cc;
208 shared_ptr<STR_data_model> pp = static_pointer_cast<STR_data_model>(inputs);
212 if(pp->z_min_bin2>0 && pp->z_max_bin2>0){
213 lower_limit = min(pp->z_min, pp->z_min_bin2);
214 upper_limit = max(pp->z_max, pp->z_max_bin2);
217 lower_limit = pp->z_min;
218 upper_limit = pp->z_max;
222 const double prec = 1.e-5;
225 const int limit_size = 1000;
228 std::vector<double> parameter_integrand;
229 parameter_integrand.emplace_back(l);
230 for (
size_t i=0; i<parameter.size(); ++i) parameter_integrand.emplace_back(parameter[i]);
243 shared_ptr<STR_data_model> pp = static_pointer_cast<STR_data_model>(inputs);
248 for (
size_t i=0; i<pp->Cpar.size(); ++i)
251 vector<double> Cl(l.size(), 0);
254 double bias = parameter[pp->Cpar.size()];
256 if(pp->interpolate_power_spectrum==
false)
260 std::vector<double> kk, z_vector;
261 double kk_step=0.0002, z_step=0.03;
262 double kk_min=double((*std::min_element(std::begin(l), std::end(l))+0.5)/cosmo.
D_C(pp->z_max)), kk_max=double((*max_element(std::begin(l), std::end(l))+0.5)/cosmo.
D_C(pp->z_min));
263 for(
size_t i=0; i<(pp->z_max-pp->z_min)/z_step +1; ++i) z_vector.emplace_back(pp->z_min+i*z_step);
264 for(
size_t i=0; i<(kk_max-kk_min)/kk_step+1; ++i) kk.emplace_back(kk_min+i*kk_step);
266 std::vector<std::vector<double>> Pk=cosmo.
Pk_matter(kk, pp->method_Pk, pp->NL, z_vector,
false,
"test", pp->norm, pp->k_min, pp->k_max);
269 for (
size_t i=0; i<l.size(); i++)
273 if(pp->mixing_matrix.size()!=0) Cl=
Cl_mixed(pp->ll, pp->mixing_matrix, l, Cl, pp->fsky);
275 if(pp->dN_par_bin2.size()>0){
276 double bias_bin2 = parameter[pp->Cpar.size()+1];
277 for (
size_t i =0; i<Cl.size(); i++) Cl[i] *=
bias*bias_bin2;
282 for (
size_t i =0; i<Cl.size(); i++) Cl[i] *=
bias*
bias;
Global functions to model the angular power spectrum.
std::vector< double > Cl_mixed(std::vector< double > l_mixing, std::vector< std::vector< double >> mixing_matrix, std::vector< double > l, std::vector< double > Cl, double fsky)
the angular power spectrum convolved with the mixing matrix
double integral_limber_exact(double l, std::vector< double > parameter, std::shared_ptr< void > input)
the integrand function in the Limber approximation for the calculus of angular power spectrum
double integral_limber_interp(double l, std::vector< double > z_vector, std::vector< double > kk, cbl::glob::FuncGrid2D pk_interp, std::vector< double > parameter, std::shared_ptr< void > input)
the integrand function in the Limber approximation for the calculus of angular power spectrum
std::vector< double > Cl_limber(const std::vector< double > l, const std::shared_ptr< void > inputs, std::vector< double > ¶meter)
the model for the angular power spectrum
double integrand_limber_exact(double redshift, std::shared_ptr< void > pp, std::vector< double > par)
the integrand function in the Limber approximation for the calculus of angular power spectrum
double Omega_baryon() const
get the private member Cosmology::m_Omega_baryon
void set_parameter(const CosmologicalParameter parameter, const double value)
set the value of one cosmological paramter
double sigma8() const
get the private member Cosmology::m_sigma8
double HH(const double redshift=0.) const
the Hubble function
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 Omega_matter() const
get the private member Cosmology::m_Omega_matter
double D_C(const double redshift) const
the comoving line-of-sight distance at a given redshift
std::vector< double > eval_func(const std::vector< std::vector< double >> xx) const
evaluate the function at the xx points
static const double cc
: the speed of light in vacuum (the value is exact) [km/sec]
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
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
The global namespace of the CosmoBolognaLib
void distribution(std::vector< double > &xx, std::vector< double > &fx, std::vector< double > &err, const std::vector< double > FF, const std::vector< double > WW, const int nbin, const bool linear=true, const std::string file_out=par::defaultString, const double fact=1., const double V1=par::defaultDouble, const double V2=par::defaultDouble, const std::string bin_type="Linear", const bool conv=false, const double sigma=0.)
derive and store the number distribution of a given std::vector
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
std::vector< std::vector< T > > transpose(std::vector< std::vector< T >> matrix)
transpose a matrix