45 double cbl::glob::func_xi_GSL (
double kk,
void *params)
47 struct cbl::glob::STR_xi *pp = (
struct cbl::glob::STR_xi *) params;
49 double lgk = log10(kk);
51 double lgPkK =
interpolated(lgk, pp->lgkk, pp->lgPk,
"Spline");
53 double Int = pow(10.,lgPkK)*sin(kk*pp->rr)*kk/pp->rr;
55 return Int * exp(-kk*kk*pp->aa*pp->aa);
62 double cbl::glob::func_SSM_GSL (
double kk,
void *params)
64 struct cbl::glob::STR_SSM *pp = (
struct cbl::glob::STR_SSM *) params;
66 double fact = (pp->unit) ? 1. : pp->hh;
67 double lgk = log10(kk/fact);
69 double lgPkK =
interpolated(lgk, pp->lgkk, pp->lgPk,
"Linear");
70 double rr =
Radius(pp->mass, pp->rho);
72 return pow(10.,lgPkK)*pow(
TopHat_WF(kk*rr)*kk,2)/pow(fact,pp->n_spec);
80 double cbl::xi_from_Pk (
const double rr,
const std::vector<double> lgkk,
const std::vector<double> lgPk,
const double k_min,
const double k_max,
const double aa,
const double prec)
84 int limit_size = 1000;
85 gsl_integration_workspace *ww = gsl_integration_workspace_alloc(limit_size);
87 cbl::glob::STR_xi str;
94 Func.function = &glob::func_xi_GSL;
98 gsl_integration_qag(&Func, k_min, k_max, 0., prec, limit_size, 6, ww, &Int, &error);
100 gsl_integration_workspace_free(ww);
102 return 1./(2.*pow(
par::pi, 2))*Int;
109 double cbl::xi_from_Pk (
const double rr,
const std::string file,
const int c1,
const int c2,
const double k_min,
const double k_max,
const double aa,
const double prec)
111 int C1 = c1-1, C2 = c2-1;
113 ifstream fin(file.c_str());
checkIO(fin, file);
116 vector<double> lgkk, lgPk;
119 while (getline(fin,line)) {
120 stringstream ss(line);
122 while (ss>>AA)
cc.push_back(AA);
123 if (C1<
int(
cc.size()) && C2<
int(
cc.size())) {
127 lgkk.push_back(log10(KK));
128 lgPk.push_back(log10(PK));
132 fin.clear(); fin.close();
134 return xi_from_Pk(rr, lgkk, lgPk, k_min, k_max, aa, prec);
141 double cbl::Pk_from_xi (
const double kk,
const std::vector<double> lgrr,
const std::vector<double> lgxi,
const double r_min,
const double r_max)
143 auto ff = [&] (
const double rr)
145 const double lgr = log10(rr);
146 const double lgxiR =
interpolated(lgr, lgrr, lgxi,
"Linear");
147 return pow(10., lgxiR)*sin(rr*kk)*rr/kk;
150 const double prec = 0.0001;
160 double cbl::Pk_from_xi (
const double kk,
const std::string file,
const int c1,
const int c2,
const double r_min,
const double r_max)
162 int C1 = c1-1, C2 = c2-1;
164 ifstream fin(file.c_str());
checkIO(fin, file);
167 vector<double> lgrr, lgxi;
170 while (getline(fin,line)) {
171 stringstream ss(line);
173 while (ss>>aa)
cc.push_back(aa);
174 if (C1<
int(
cc.size()) && C2<
int(
cc.size())) {
178 lgrr.push_back(log10(RR));
179 lgxi.push_back(log10(XI));
183 fin.clear(); fin.close();
185 return Pk_from_xi (kk, lgrr, lgxi, r_min, r_max) ;
192 double cbl::wp (
const double rp,
const std::vector<double> rr,
const std::vector<double> xi,
const double r_max)
194 auto ff = [&] (
const double rrr)
196 return interpolated(rrr, rr, xi,
"Linear")/sqrt(rrr*rrr-rp*rp)*rrr;
199 const double prec = 0.0001;
207 double cbl::wp (
const double rp,
const std::string file,
const double r_max)
209 ifstream fin(file.c_str());
checkIO(fin, file);
212 vector<double> rr, xi;
214 while (fin>>RR>>XI) {
218 fin.clear(); fin.close();
220 return wp(rp, rr, xi, r_max);
227 double cbl::sigmaR (
const double RR,
const int corrType,
const std::vector<double> rr,
const std::vector<double> corr)
233 auto ff = [&] (
const double rad)
236 return (3.-2.25*rad/RR+0.1875*pow(rad/RR, 3))*rad*rad*xiR;
239 const double prec = 0.0001;
243 sigmaR = sqrt(1./pow(RR,3)*Int);
246 else if (corrType==2) {
248 auto ff = [&] (
const double rad)
252 const double xx = rad/RR;
254 const double gg = (xx<=2)
256 : 1./(2.*
par::pi)*((-pow(xx,4)+11.*pow(xx,2)-28.)/sqrt(pow(xx,2)-4.)+pow(xx,3)-9.*xx+6.*asin(2./xx));
261 const double prec = 0.0001;
265 if (1./pow(RR,3)*(Int1+Int2)<0)
ErrorCBL(
conv(1./pow(RR,3)*(Int1+Int2),
par::fDP4)+
"<0",
"sigmaR",
"FuncXi.cpp");
266 sigmaR = sqrt(1./pow(RR,3)*(Int1+Int2));
269 else ErrorCBL(
"the value of corrType is not allowed!",
"sigmaR",
"Func.cpp");
280 return rp*pow(r0/rp,gamma)*exp(lgamma(0.5))*exp(lgamma((gamma-1.)*0.5))/exp(lgamma(gamma*0.5));
289 return 1.+2./3.*beta+0.2*beta*beta;
298 return (bias_sigma8!=0) ? 1.+2./3.*f_sigma8/bias_sigma8+0.2*pow(f_sigma8/bias_sigma8, 2) : -1.e30;
306 double cbl::xi_ratio (
double xx, shared_ptr<void> pp, vector<double> par)
310 if (par.size()==2)
return xi_ratio(par[0]);
312 else if (par.size()==3)
return xi_ratio(par[0], par[1]);
314 else return ErrorCBL(
"par.size()!=2 and !=3",
"xi_ratio",
"FuncXi.cpp");
324 return (2./3.+0.4*beta)*error_beta;
331 double cbl::barred_xi_direct (
const double RR,
const std::vector<double> rr,
const std::vector<double> xi,
const double rAPP,
const double r0,
const double gamma)
339 xi_.push_back(3.*pow(rr[kk++]/r0,-gamma)/(-gamma+3.));
345 double Int = (rAPP>0) ? xi_[kk]*pow(rr[kk],3)/3. : 0.;
347 double bin = rr[1]-rr[0];
349 for (
unsigned int i=kk+1; i<rr.size(); i++) {
350 xi_.push_back(3./pow(rr[i],3)*(Int+xi[i]*pow(rr[i],2)*bin));
351 Int += xi[i]*pow(rr[i],2)*bin;
361 double cbl::barred_xi__direct (
const double RR,
const std::vector<double> rr,
const std::vector<double> xi,
const double rAPP,
const double r0,
const double gamma)
370 xi__.push_back(5.*pow(rr[kk++]/r0,-gamma)/(-gamma+5.));
376 double Int = (rAPP>0) ? xi__[kk]*pow(rr[kk],5)/5. : 0.;
378 double bin = rr[1]-rr[0];
380 for (
unsigned int i=kk+1; i<rr.size(); i++) {
381 xi__.push_back(5./pow(rr[i],5)*(Int+xi[i]*pow(rr[i],4)*bin));
382 Int += xi[i]*pow(rr[i],4)*bin;
392 double cbl::barred_xi_ (
const double RR,
const std::vector<double> rr,
const std::vector<double> xi,
const double rApp,
const double r0,
const double gamma)
396 for (
unsigned int i=0; i<xi.size(); i++)
397 xi_.push_back(xi[i]*rr[i]*rr[i]);
401 double int_an = (RR<rApp) ? 1./((3.-gamma)*pow(r0,-gamma))*pow(RR,3.-gamma) : 1./((3.-gamma)*pow(r0,-gamma))*pow(rApp,3.-gamma);
403 double int_num = (RR>rApp) ? func.
integrate_qag(rApp,RR) : 0.;
405 return 3./pow(RR,3.)*(int_an+int_num);
412 double cbl::barred_xi__ (
const double RR,
const std::vector<double> rr,
const std::vector<double> xi,
const double rApp,
const double r0,
const double gamma)
416 for (
unsigned int i=0; i<xi.size(); i++)
417 xi__.push_back(xi[i]*rr[i]*rr[i]*rr[i]*rr[i]);
421 double int_an = (RR<rApp) ? 1./((5.-gamma)*pow(r0,-gamma))*pow(RR,5.-gamma) : 1./((5.-gamma)*pow(r0,-gamma))*pow(rApp,5.-gamma);
423 double int_num = (RR>rApp) ? func.
integrate_qag(rApp,RR) : 0.;
425 return 5./pow(RR,5.)*(int_an+int_num);
435 if (par.size()!=2 && par.size()!=3 && par.size()!=4)
438 double beta = par[0];
439 double bias = (par.size()==3) ? par[1] : 1;
440 int index = par[par.size()-1];
442 shared_ptr<cbl::glob::STR_xi2D_model> vec = static_pointer_cast<cbl::glob::STR_xi2D_model>(pp);
450 double rr = sqrt(pow(rp, 2)+pow(
pi, 2));
457 double xi_real = vec->xi_real[index]*b2;
458 double xi_ = vec->xi_[index]*b2;
459 double xi__ = vec->xi__[index]*b2;
465 return xi_0+xi_2*vec->P2[index]+xi_4*vec->P4[index];
473 double cbl::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)
476 double Xi_real = xi_real * bias2;
477 double Xi_ = xi_ * bias2;
478 double Xi__ = xi__ * bias2;
484 return xi_0+xi_2*
P_2+xi_4*
P_4;
491 double cbl::xi2D_lin_model (
const double rp,
const double pi,
const double beta,
const double bias,
const std::vector<double> rad_real,
const std::vector<double> xi_real,
const std::vector<double> xi_,
const std::vector<double> xi__,
const int index,
const bool bias_nl,
const double bA)
493 double rr = sqrt(rp*rp+
pi*
pi);
496 double xiR = (index>-1) ? xi_real[index] : -1.;
497 double xiR_ = (index>-1) ? xi_[index] : -1.;
498 double xiR__ = (index>-1) ? xi__[index] : -1.;
507 if (bias_nl) Bias *=
b_nl(rr, bA);
509 double bias2 = Bias*Bias;
518 return xi_0+xi_2*
P_2(cos)+xi_4*
P_4(cos);
526 double cbl::xi2D_model (
double rp,
double pi, shared_ptr<void> pp, vector<double> par)
533 shared_ptr<cbl::glob::STR_xi2D_model> vec = static_pointer_cast<cbl::glob::STR_xi2D_model>(pp);
535 int index = par[par.size()-1];
536 int ind_min = index*vec->step_v;
537 int ind_max = ind_min+vec->step_v;
539 double sigmav = par[1];
542 par2.push_back(par[0]);
543 par2.push_back(par[2]);
544 for (
unsigned int i=3; i<par.size(); i++) par2.push_back(par[i]);
552 for (
int i=ind_min; i<ind_max; i++) {
553 par2[par2.size()-1] = i;
554 xi2D_nl +=
xi2D_lin_model(vec->rp[i], vec->pi[i], pp, par2)*
f_v(vec->vel[i], sigmav, vec->FV)*vec->delta_v;
555 norm +=
f_v(vec->vel[i], sigmav, vec->FV)*vec->delta_v;
561 if (fabs(norm-1)>0.1) {
562 WarningMsgCBL(
"sigmav = "+
conv(sigmav,
par::fDP2)+
" ---> norm = " +
conv(norm,
par::fDP3) +
", the number of bins used for the convolution with f(v) should be increased!",
"xi2D_model",
"FuncXi.cpp");
574 double cbl::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,
const bool bias_nl,
const double bA,
const double v_min,
const double v_max,
const int step_v)
576 double delta_v = (v_max-v_min)/step_v;
583 for (
int k=0; k<step_v; k++) {
585 double pi_new =
pi-vel*var;
587 double rr = sqrt(rp*rp+pi_new*pi_new);
588 double cos = pi_new/rr;
590 double xiR = (index>-1) ? xi_real[index] : -1.;
591 double xiR_ = (index>-1) ? xi_[index] : -1.;
592 double xiR__ = (index>-1) ? xi__[index] : -1.;
601 if (bias_nl) Bias *=
b_nl(rr, bA);
606 if (index>-1) index ++;
616 double cbl::f_v (
const double vel,
const double sigmav,
const int FV)
618 if (FV==0)
return 1./(sigmav*sqrt(2.))*exp(-sqrt(2.)*fabs(vel)/sigmav);
620 else return 1./(sigmav*sqrt(
par::pi))*exp(-(vel*vel)/(sigmav*sigmav));
627 double cbl::f_v (
const double vel,
const double rp,
const double pi,
const double var,
const double sigmav0,
const double cmu,
const double cs1,
const double cs2)
630 double sp = sqrt(pow(rp,2)+pow(
pi-vel*var,2));
631 double mup = 1./sp*(
pi-vel*var);
633 double sigmav = sigmav0*(1.+cmu*mup*mup)*(1.+cs1*exp(-cs2*rp*rp));
635 return 1./(sigmav*sqrt(2.))*exp(-sqrt(2.)*fabs(vel)/sigmav);
642 double cbl::f_star (
const double xx,
const double f_g,
const double k_star)
644 double sigma_star = sqrt((4.*f_g+2.*f_g*f_g)/(k_star*k_star));
646 return 1./(sigma_star*sqrt(
par::pi))*exp(-xx*xx/(sigma_star*sigma_star));
653 double cbl::b_nl (
const double rr,
const double bA,
const double bB,
const double bC)
655 double FF = 1./(1.+pow(rr/bB,bC));
657 return pow(rr,bA*FF);
664 double cbl::xi2D_lin_model (
const double rp,
const double pi,
const double beta,
const double bias,
const std::shared_ptr<void> funcXiR,
const std::shared_ptr<void> funcXiR_,
const std::shared_ptr<void> funcXiR__,
const bool bias_nl,
const double bA)
666 shared_ptr<glob::FuncGrid> pfuncXiR = static_pointer_cast<glob::FuncGrid>(funcXiR);
667 shared_ptr<glob::FuncGrid> pfuncXiR_ = static_pointer_cast<glob::FuncGrid>(funcXiR_);
668 shared_ptr<glob::FuncGrid> pfuncXiR__ = static_pointer_cast<glob::FuncGrid>(funcXiR__);
670 double rr = sqrt(rp*rp+
pi*
pi);
673 double xiR = pfuncXiR->operator()(rr);
674 double xiR_ = pfuncXiR_->operator()(rr);
675 double xiR__ = pfuncXiR__->operator()(rr);
678 if (bias_nl) Bias *=
b_nl(rr, bA);
680 double bias2 = Bias*Bias;
689 return xi_0+xi_2*
P_2(cos)+xi_4*
P_4(cos);
696 double cbl::xi2D_model (
const double rp,
const double pi,
const double beta,
const double bias,
const double sigmav,
const std::shared_ptr<void> funcXiR,
const std::shared_ptr<void> funcXiR_,
const std::shared_ptr<void> funcXiR__,
const double var,
const int FV,
const bool bias_nl,
const double bA,
const double v_min,
const double v_max,
const int step_v)
698 shared_ptr<glob::FuncGrid> pfuncXiR = static_pointer_cast<glob::FuncGrid>(funcXiR);
699 shared_ptr<glob::FuncGrid> pfuncXiR_ = static_pointer_cast<glob::FuncGrid>(funcXiR_);
700 shared_ptr<glob::FuncGrid> pfuncXiR__ = static_pointer_cast<glob::FuncGrid>(funcXiR__);
702 double delta_v = (v_max-v_min)/step_v;
708 for (
int k=0; k<step_v; k++) {
710 double pi_new =
pi-vel*var;
712 double rr = sqrt(rp*rp+pi_new*pi_new);
713 double cos = pi_new/rr;
715 double xiR = pfuncXiR->operator()(rr);
716 double xiR_ = pfuncXiR_->operator()(rr);
717 double xiR__ = pfuncXiR__->operator()(rr);
720 if (bias_nl) Bias *=
b_nl(rr, bA);
Useful generic functions.
double integrate_qag(const double a, const double b, const double rel_err=1.e-2, const double abs_err=1.e-6, const int limit_size=1000, const int rule=6)
compute the definite integral with GSL qag method
static const char fDP2[]
conversion symbol for: double -> std::string
static const char fDP4[]
conversion symbol for: double -> std::string
static const char fDP3[]
conversion symbol for: double -> std::string
static const char fINT[]
conversion symbol for: int -> std::string
static const double pi
: the ratio of a circle's circumference to its diameter
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_qaws(gsl_function Func, const double a, const double b, const double alpha=0, const double beta=0, const int mu=1, const int nu=0, const double rel_err=1.e-3, const double abs_err=0, const int limit_size=1000)
integral, computed using the GSL qaws method
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
double sigmaR(const double RR, const int corrType, const std::vector< double > rr, const std::vector< double > corr)
the rms mass fluctuation within a given radius
std::string conv(const T val, const char *fact)
convert a number to a std::string
void Print(const T value, const int prec, const int ww, const std::string header="", const std::string end="\n", const bool use_coutCBL=true, std::ostream &stream=std::cout, const std::string colour=cbl::par::col_default)
function to print values with a proper homegenised format
double barred_xi_direct(const double RR, const std::vector< double > rr, const std::vector< double > xi, const double rAPP=0., const double r0=-1., const double gamma=1.)
the barred correlation function
T Radius(const T Mass, const T Rho)
the radius of a sphere of a given mass and density
double barred_xi__(const double RR, const std::vector< double > rr, const std::vector< double > xi, const double rAPP=0., const double r0=-1., const double gamma=1.)
the double barred correlation function
double barred_xi_(const double RR, const std::vector< double > rr, const std::vector< double > xi, const double rAPP=0., const double r0=-1., const double gamma=1.)
the barred correlation function
double multipole_xi0_model(const double beta, const double xi_real)
the model multipole ξ0 of the two-point correlation function
void checkIO(const std::ifstream &fin, const std::string file="NULL")
check if an input file can be opened
double xi_projected_powerlaw(const double rp, const double r0, const double gamma)
the projected correlation function, wp(rp), computed by modelling the two-point correlation function,...
double f_v(const double vel, const double sigmav, const int FV)
pairwise velocity distribution
T TopHat_WF(const T kR)
the top-hat window function
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
double multipole_xi4_model(const double beta, const double xi_real, const double xi_, const double xi__)
the model multipole ξ4 of the two-point correlation function
T P_4(const T x)
the Legendre polynomial P4
double error_xi_ratio(const double beta, const double error_beta)
error on the ratio between the redshift-space and real-space correlation functions
double Pk_from_xi(const double kk, const std::vector< double > lgrr, const std::vector< double > lgxi, const double r_min=0.03, const double r_max=100.)
the power spectrum computed from the Fourier transform of the two-point correlation function
double barred_xi__direct(const double RR, const std::vector< double > rr, const std::vector< double > xi, const double rAPP=0., const double r0=-1., const double gamma=1.)
the double barred correlation function
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,π)
double xi_ratio(const double beta)
the ratio between the redshift-space and real-space correlation functions
double multipole_xi2_model(const double beta, const double xi_real, const double xi_)
the model multipole ξ2 of the two-point correlation function
double f_star(const double xx, const double f_g, const double k_star)
velocity distribution used to model BAO
double xi_from_Pk(const double rr, const std::vector< double > lgkk, const std::vector< double > lgPk, const double k_min=0., const double k_max=100., const double aa=0., const double prec=1.e-2)
the two-point correlation function computed from the Fourier transform of the power spectrum
double interpolated(const double _xx, const std::vector< double > xx, const std::vector< double > yy, const std::string type)
1D interpolation
T P_2(const T x)
the Legendre polynomial P2
void WarningMsgCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL)
internal CBL warning message
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,π)
double wp(const double rp, const std::vector< double > rr, const std::vector< double > xi, const double r_max=100.)
the projected two-point correlation function
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