CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
FuncXi.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 
34 #include "Func.h"
35 
36 using namespace std;
37 
38 using namespace cbl;
39 
40 
41 // =====================================================================================
42 
44 
45 double cbl::glob::func_xi_GSL (double kk, void *params)
46 {
47  struct cbl::glob::STR_xi *pp = (struct cbl::glob::STR_xi *) params;
48 
49  double lgk = log10(kk);
50 
51  double lgPkK = interpolated(lgk, pp->lgkk, pp->lgPk, "Spline");
52 
53  double Int = pow(10.,lgPkK)*sin(kk*pp->rr)*kk/pp->rr;
54 
55  return Int * exp(-kk*kk*pp->aa*pp->aa); // eq. 24 of Anderson et al. 2012
56 }
57 
58 
59 // =====================================================================================
60 
61 
62 double cbl::glob::func_SSM_GSL (double kk, void *params)
63 {
64  struct cbl::glob::STR_SSM *pp = (struct cbl::glob::STR_SSM *) params;
65 
66  double fact = (pp->unit) ? 1. : pp->hh;
67  double lgk = log10(kk/fact);
68 
69  double lgPkK = interpolated(lgk, pp->lgkk, pp->lgPk, "Linear");
70  double rr = Radius(pp->mass, pp->rho);
71 
72  return pow(10.,lgPkK)*pow(TopHat_WF(kk*rr)*kk,2)/pow(fact,pp->n_spec);
73 }
74 
76 
77 // =====================================================================================
78 
79 
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)
81 {
82  double Int = -1.;
83 
84  int limit_size = 1000;
85  gsl_integration_workspace *ww = gsl_integration_workspace_alloc(limit_size);
86 
87  cbl::glob::STR_xi str;
88  str.rr = rr;
89  str.aa = aa;
90  str.lgkk = lgkk;
91  str.lgPk = lgPk;
92 
93  gsl_function Func;
94  Func.function = &glob::func_xi_GSL;
95  Func.params = &str;
96 
97  double error = -1.;
98  gsl_integration_qag(&Func, k_min, k_max, 0., prec, limit_size, 6, ww, &Int, &error);
99 
100  gsl_integration_workspace_free(ww);
101 
102  return 1./(2.*pow(par::pi, 2))*Int;
103 }
104 
105 
106 // =====================================================================================
107 
108 
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)
110 {
111  int C1 = c1-1, C2 = c2-1;
112 
113  ifstream fin(file.c_str()); checkIO(fin, file);
114 
115  double KK, PK, AA;
116  vector<double> lgkk, lgPk;
117  string line;
118 
119  while (getline(fin,line)) {
120  stringstream ss(line);
121  vector<double> cc;
122  while (ss>>AA) cc.push_back(AA);
123  if (C1<int(cc.size()) && C2<int(cc.size())) {
124  KK = cc[C1];
125  PK = cc[C2];
126  if (KK>0 && PK>0) {
127  lgkk.push_back(log10(KK));
128  lgPk.push_back(log10(PK));
129  }
130  }
131  }
132  fin.clear(); fin.close();
133 
134  return xi_from_Pk(rr, lgkk, lgPk, k_min, k_max, aa, prec);
135 }
136 
137 
138 // ============================================================================
139 
140 
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)
142 {
143  auto ff = [&] (const double rr)
144  {
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;
148  };
149 
150  const double prec = 0.0001;
151  const double Int = wrapper::gsl::GSL_integrate_qag(ff, r_min, r_max, prec);
152 
153  return 4.*par::pi*Int;
154 }
155 
156 
157 // ============================================================================
158 
159 
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)
161 {
162  int C1 = c1-1, C2 = c2-1;
163 
164  ifstream fin(file.c_str()); checkIO(fin, file);
165 
166  double RR, XI, aa;
167  vector<double> lgrr, lgxi;
168  string line;
169 
170  while (getline(fin,line)) {
171  stringstream ss(line);
172  vector<double> cc;
173  while (ss>>aa) cc.push_back(aa);
174  if (C1<int(cc.size()) && C2<int(cc.size())) {
175  RR = cc[C1];
176  XI = cc[C2];
177  if (RR>0 && XI>0) {
178  lgrr.push_back(log10(RR));
179  lgxi.push_back(log10(XI));
180  }
181  }
182  }
183  fin.clear(); fin.close();
184 
185  return Pk_from_xi (kk, lgrr, lgxi, r_min, r_max) ;
186 }
187 
188 
189 // ============================================================================
190 
191 
192 double cbl::wp (const double rp, const std::vector<double> rr, const std::vector<double> xi, const double r_max)
193 {
194  auto ff = [&] (const double rrr)
195  {
196  return interpolated(rrr, rr, xi, "Linear")/sqrt(rrr*rrr-rp*rp)*rrr;
197  };
198 
199  const double prec = 0.0001;
200  return 2.*wrapper::gsl::GSL_integrate_qag(ff, rp, r_max, prec);
201 }
202 
203 
204 // ============================================================================
205 
206 
207 double cbl::wp (const double rp, const std::string file, const double r_max)
208 {
209  ifstream fin(file.c_str()); checkIO(fin, file);
210 
211  double RR, XI;
212  vector<double> rr, xi;
213 
214  while (fin>>RR>>XI) {
215  rr.push_back(RR);
216  xi.push_back(XI);
217  }
218  fin.clear(); fin.close();
219 
220  return wp(rp, rr, xi, r_max);
221 }
222 
223 
224 // ============================================================================
225 
226 
227 double cbl::sigmaR (const double RR, const int corrType, const std::vector<double> rr, const std::vector<double> corr)
228 {
229  double sigmaR = -1;
230 
231  if (corrType==1) { // using the spherically averaged correlation function
232 
233  auto ff = [&] (const double rad)
234  {
235  const double xiR = interpolated(rad, rr, corr, "Poly");
236  return (3.-2.25*rad/RR+0.1875*pow(rad/RR, 3))*rad*rad*xiR;
237  };
238 
239  const double prec = 0.0001;
240  const double Int = wrapper::gsl::GSL_integrate_qaws (ff, 0., 2*RR, 1, 0, 0, 0, prec);
241 
242  if (1./pow(RR,3)*Int<0) ErrorCBL(conv(1./pow(RR,3)*Int,par::fDP4)+"<0!", "sigmaR", "FuncXi.cpp");
243  sigmaR = sqrt(1./pow(RR,3)*Int);
244  }
245 
246  else if (corrType==2) { // using the projected correlation function
247 
248  auto ff = [&] (const double rad)
249  {
250  const double wpR = interpolated(rad, rr, corr, "Poly");
251 
252  const double xx = rad/RR;
253 
254  const double gg = (xx<=2)
255  ? 1./(2.*par::pi)*(3.*par::pi-9.*xx+pow(xx,3))
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));
257 
258  return wpR*rad*gg;
259  };
260 
261  const double prec = 0.0001;
262  const double Int1 = wrapper::gsl::GSL_integrate_qaws(ff, 0., 1., prec);
263  const double Int2 = wrapper::gsl::GSL_integrate_qaws(ff, 1., 100., prec);
264 
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));
267  }
268 
269  else ErrorCBL("the value of corrType is not allowed!", "sigmaR", "Func.cpp");
270 
271  return sigmaR;
272 }
273 
274 
275 // ============================================================================
276 
277 
278 double cbl::xi_projected_powerlaw (const double rp, const double r0, const double gamma)
279 {
280  return rp*pow(r0/rp,gamma)*exp(lgamma(0.5))*exp(lgamma((gamma-1.)*0.5))/exp(lgamma(gamma*0.5));
281 }
282 
283 
284 // ============================================================================
285 
286 
287 double cbl::xi_ratio (const double beta)
288 {
289  return 1.+2./3.*beta+0.2*beta*beta;
290 }
291 
292 
293 // ============================================================================
294 
295 
296 double cbl::xi_ratio (const double f_sigma8, const double bias_sigma8)
297 {
298  return (bias_sigma8!=0) ? 1.+2./3.*f_sigma8/bias_sigma8+0.2*pow(f_sigma8/bias_sigma8, 2) : -1.e30;
299 }
300 
301 
302 // ============================================================================
303 
305 
306 double cbl::xi_ratio (double xx, shared_ptr<void> pp, vector<double> par)
307 {
308  (void)xx; (void)pp;
309 
310  if (par.size()==2) return xi_ratio(par[0]);
311 
312  else if (par.size()==3) return xi_ratio(par[0], par[1]);
313 
314  else return ErrorCBL("par.size()!=2 and !=3", "xi_ratio", "FuncXi.cpp");
315 }
316 
318 
319 // ============================================================================
320 
321 
322 double cbl::error_xi_ratio (const double beta, const double error_beta)
323 {
324  return (2./3.+0.4*beta)*error_beta;
325 }
326 
327 
328 // ============================================================================
329 
330 
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)
332 {
333  vector<double> xi_;
334 
335  // power-law approximation for r<rAPP
336 
337  double kk = 0;
338  while (rr[kk]<rAPP)
339  xi_.push_back(3.*pow(rr[kk++]/r0,-gamma)/(-gamma+3.));
340  kk --;
341 
342 
343  // estimate the function at r>rApp
344 
345  double Int = (rAPP>0) ? xi_[kk]*pow(rr[kk],3)/3. : 0.;
346 
347  double bin = rr[1]-rr[0];
348 
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;
352  }
353 
354  return interpolated(RR, rr, xi_, "Linear");
355 }
356 
357 
358 // ============================================================================
359 
360 
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)
362 {
363  vector<double> xi__;
364 
365 
366  // power-low approximation for r<rAPP
367 
368  double kk = 0;
369  while (rr[kk]<rAPP)
370  xi__.push_back(5.*pow(rr[kk++]/r0,-gamma)/(-gamma+5.));
371  kk --;
372 
373 
374  // estimate the function at r>rApp
375 
376  double Int = (rAPP>0) ? xi__[kk]*pow(rr[kk],5)/5. : 0.;
377 
378  double bin = rr[1]-rr[0];
379 
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;
383  }
384 
385  return interpolated(RR, rr, xi__, "Linear");
386 }
387 
388 
389 // ============================================================================
390 
391 
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)
393 {
394  vector<double> xi_;
395 
396  for (unsigned int i=0; i<xi.size(); i++)
397  xi_.push_back(xi[i]*rr[i]*rr[i]);
398 
399  cbl::glob::FuncGrid func(rr, xi_, "Spline");
400 
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);
402 
403  double int_num = (RR>rApp) ? func.integrate_qag(rApp,RR) : 0.;
404 
405  return 3./pow(RR,3.)*(int_an+int_num);
406 }
407 
408 
409 // ============================================================================
410 
411 
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)
413 {
414  vector<double> xi__;
415 
416  for (unsigned int i=0; i<xi.size(); i++)
417  xi__.push_back(xi[i]*rr[i]*rr[i]*rr[i]*rr[i]);
418 
419  cbl::glob::FuncGrid func(rr, xi__, "Spline");
420 
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);
422 
423  double int_num = (RR>rApp) ? func.integrate_qag(rApp,RR) : 0.;
424 
425  return 5./pow(RR,5.)*(int_an+int_num);
426 }
427 
428 
429 // ============================================================================
430 
432 
433 double cbl::xi2D_lin_model (double rp, double pi, shared_ptr<void> pp, vector<double> par)
434 {
435  if (par.size()!=2 && par.size()!=3 && par.size()!=4)
436  ErrorCBL("par.size() = "+conv(par.size(),par::fINT)+"!", "xi2D_lin_model", "FuncXi.cpp");
437 
438  double beta = par[0];
439  double bias = (par.size()==3) ? par[1] : 1;
440  int index = par[par.size()-1];
441 
442  shared_ptr<cbl::glob::STR_xi2D_model> vec = static_pointer_cast<cbl::glob::STR_xi2D_model>(pp);
443 
444 
445  if (vec->bias_nl) {
446  if (par.size()!=4)
447  ErrorCBL("par.size() = "+conv(par.size(),par::fINT)+"!", "xi2D_lin_model", "FuncXi.cpp");
448 
449  double bA = par[3];
450  double rr = sqrt(pow(rp, 2)+pow(pi, 2));
451  bias *= b_nl(rr, bA);
452  }
453 
454  double b2 = bias*bias;
455 
456 
457  double xi_real = vec->xi_real[index]*b2;
458  double xi_ = vec->xi_[index]*b2;
459  double xi__ = vec->xi__[index]*b2;
460 
461  double xi_0 = multipole_xi0_model(beta, xi_real);
462  double xi_2 = multipole_xi2_model(beta, xi_real, xi_);
463  double xi_4 = multipole_xi4_model(beta, xi_real, xi_, xi__);
464 
465  return xi_0+xi_2*vec->P2[index]+xi_4*vec->P4[index];
466 }
467 
469 
470 // ============================================================================
471 
472 
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)
474 {
475  double bias2 = bias*bias;
476  double Xi_real = xi_real * bias2;
477  double Xi_ = xi_ * bias2;
478  double Xi__ = xi__ * bias2;
479 
480  double xi_0 = multipole_xi0_model(beta, Xi_real);
481  double xi_2 = multipole_xi2_model(beta, Xi_real, Xi_);
482  double xi_4 = multipole_xi4_model(beta, Xi_real, Xi_, Xi__);
483 
484  return xi_0+xi_2*P_2+xi_4*P_4;
485 }
486 
487 
488 // ============================================================================
489 
490 
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)
492 {
493  double rr = sqrt(rp*rp+pi*pi);
494  double cos = pi/rr;
495 
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.;
499 
500  if (xiR<0) {
501  xiR = interpolated(rr, rad_real, xi_real, "Linear");
502  xiR_ = interpolated(rr, rad_real, xi_, "Linear");
503  xiR__ = interpolated(rr, rad_real, xi__, "Linear");
504  }
505 
506  double Bias = bias;
507  if (bias_nl) Bias *= b_nl(rr, bA);
508 
509  double bias2 = Bias*Bias;
510  xiR *= bias2;
511  xiR_ *= bias2;
512  xiR__ *= bias2;
513 
514  double xi_0 = multipole_xi0_model(beta, xiR);
515  double xi_2 = multipole_xi2_model(beta, xiR, xiR_);
516  double xi_4 = multipole_xi4_model(beta, xiR, xiR_, xiR__);
517 
518  return xi_0+xi_2*P_2(cos)+xi_4*P_4(cos);
519 }
520 
521 
522 // ============================================================================
523 
525 
526 double cbl::xi2D_model (double rp, double pi, shared_ptr<void> pp, vector<double> par)
527 {
528  (void)rp; (void)pi;
529 
530  if (par.size()<3)
531  ErrorCBL("par.size() = "+conv(par.size(),par::fINT)+"!", "xi2D_model", "FuncXi.cpp");
532 
533  shared_ptr<cbl::glob::STR_xi2D_model> vec = static_pointer_cast<cbl::glob::STR_xi2D_model>(pp);
534 
535  int index = par[par.size()-1];
536  int ind_min = index*vec->step_v;
537  int ind_max = ind_min+vec->step_v;
538 
539  double sigmav = par[1];
540 
541  vector<double> par2;
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]);
545 
546 
547  // convolution of the linear xi(rp,pi) with the velocity distribution function f(v)
548 
549  double xi2D_nl = 0;
550  double norm = 0.; // to avoid numerical problems when sigmav is too small
551 
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;
556  }
557 
558  xi2D_nl /= norm;
559 
560 
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");
563  Print(par);
564  }
565 
566  return xi2D_nl;
567 }
568 
570 
571 // ============================================================================
572 
573 
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)
575 {
576  double delta_v = (v_max-v_min)/step_v;
577 
578  double vel = v_min;
579 
580  double xi2D = 0.;
581 
582 
583  for (int k=0; k<step_v; k++) {
584 
585  double pi_new = pi-vel*var;
586 
587  double rr = sqrt(rp*rp+pi_new*pi_new);
588  double cos = pi_new/rr;
589 
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.;
593 
594  if (xiR<0) {
595  xiR = interpolated(rr, rad_real, xi_real, "Linear");
596  xiR_ = interpolated(rr, rad_real, xi_, "Linear");
597  xiR__ = interpolated(rr, rad_real, xi__, "Linear");
598  }
599 
600  double Bias = bias;
601  if (bias_nl) Bias *= b_nl(rr, bA);
602 
603  xi2D += xi2D_lin_model(beta, Bias, xiR, xiR_, xiR__, P_2(cos), P_4(cos))*f_v(vel, sigmav, FV)*delta_v;
604 
605  vel += delta_v;
606  if (index>-1) index ++;
607  }
608 
609  return xi2D;
610 }
611 
612 
613 // ============================================================================
614 
615 
616 double cbl::f_v (const double vel, const double sigmav, const int FV)
617 {
618  if (FV==0) return 1./(sigmav*sqrt(2.))*exp(-sqrt(2.)*fabs(vel)/sigmav); // exponential
619 
620  else return 1./(sigmav*sqrt(par::pi))*exp(-(vel*vel)/(sigmav*sigmav)); // gaussian
621 }
622 
623 
624 // ============================================================================
625 
626 
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)
628 {
629 
630  double sp = sqrt(pow(rp,2)+pow(pi-vel*var,2));
631  double mup = 1./sp*(pi-vel*var);
632 
633  double sigmav = sigmav0*(1.+cmu*mup*mup)*(1.+cs1*exp(-cs2*rp*rp));
634 
635  return 1./(sigmav*sqrt(2.))*exp(-sqrt(2.)*fabs(vel)/sigmav);
636 }
637 
638 
639 // ============================================================================
640 
641 
642 double cbl::f_star (const double xx, const double f_g, const double k_star)
643 {
644  double sigma_star = sqrt((4.*f_g+2.*f_g*f_g)/(k_star*k_star));
645 
646  return 1./(sigma_star*sqrt(par::pi))*exp(-xx*xx/(sigma_star*sigma_star));
647 }
648 
649 
650 // ============================================================================
651 
652 
653 double cbl::b_nl (const double rr, const double bA, const double bB, const double bC)
654 {
655  double FF = 1./(1.+pow(rr/bB,bC));
656 
657  return pow(rr,bA*FF);
658 }
659 
660 
661 // ============================================================================
662 
663 
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)
665 {
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__);
669 
670  double rr = sqrt(rp*rp+pi*pi);
671  double cos = pi/rr;
672 
673  double xiR = pfuncXiR->operator()(rr);
674  double xiR_ = pfuncXiR_->operator()(rr);
675  double xiR__ = pfuncXiR__->operator()(rr);
676 
677  double Bias = bias;
678  if (bias_nl) Bias *= b_nl(rr, bA);
679 
680  double bias2 = Bias*Bias;
681  xiR *= bias2;
682  xiR_ *= bias2;
683  xiR__ *= bias2;
684 
685  double xi_0 = multipole_xi0_model(beta, xiR);
686  double xi_2 = multipole_xi2_model(beta, xiR, xiR_);
687  double xi_4 = multipole_xi4_model(beta, xiR, xiR_, xiR__);
688 
689  return xi_0+xi_2*P_2(cos)+xi_4*P_4(cos);
690 }
691 
692 
693 // ============================================================================
694 
695 
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)
697 {
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__);
701 
702  double delta_v = (v_max-v_min)/step_v;
703 
704  double vel = v_min;
705 
706  double xi2D = 0.;
707 
708  for (int k=0; k<step_v; k++) {
709 
710  double pi_new = pi-vel*var;
711 
712  double rr = sqrt(rp*rp+pi_new*pi_new);
713  double cos = pi_new/rr;
714 
715  double xiR = pfuncXiR->operator()(rr);
716  double xiR_ = pfuncXiR_->operator()(rr);
717  double xiR__ = pfuncXiR__->operator()(rr);
718 
719  double Bias = bias;
720  if (bias_nl) Bias *= b_nl(rr, bA);
721 
722  xi2D += xi2D_lin_model(beta, Bias, xiR, xiR_, xiR__, P_2(cos), P_4(cos))*f_v(vel, sigmav, FV)*delta_v;
723 
724  vel += delta_v;
725  }
726 
727  return xi2D;
728 }
Useful generic functions.
The class FuncGrid.
Definition: FuncGrid.h:55
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
Definition: FuncGrid.cpp:187
static const char fDP2[]
conversion symbol for: double -> std::string
Definition: Constants.h:133
static const char fDP4[]
conversion symbol for: double -> std::string
Definition: Constants.h:139
static const char fDP3[]
conversion symbol for: double -> std::string
Definition: Constants.h:136
static const char fINT[]
conversion symbol for: int -> std::string
Definition: Constants.h:121
static const double pi
: the ratio of a circle's circumference to its diameter
Definition: Constants.h:199
static const double cc
: the speed of light in vacuum (the value is exact) [km/sec]
Definition: Constants.h:221
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
Definition: GSLwrapper.cpp:240
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
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
Definition: FuncXi.cpp:227
std::string conv(const T val, const char *fact)
convert a number to a std::string
Definition: Kernel.h:903
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
Definition: Kernel.h:1142
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
Definition: FuncXi.cpp:331
T Radius(const T Mass, const T Rho)
the radius of a sphere of a given mass and density
Definition: Func.h:1220
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
Definition: FuncXi.cpp:412
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
Definition: FuncXi.cpp:392
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
Definition: Kernel.cpp:160
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,...
Definition: FuncXi.cpp:278
double f_v(const double vel, const double sigmav, const int FV)
pairwise velocity distribution
Definition: FuncXi.cpp:616
T TopHat_WF(const T kR)
the top-hat window function
Definition: Func.h:1195
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 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
Definition: Func.h:1280
double error_xi_ratio(const double beta, const double error_beta)
error on the ratio between the redshift-space and real-space correlation functions
Definition: FuncXi.cpp:322
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
Definition: FuncXi.cpp:141
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
Definition: FuncXi.cpp:361
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 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
Definition: FuncXi.cpp:642
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
Definition: FuncXi.cpp:80
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
T P_2(const T x)
the Legendre polynomial P2
Definition: Func.h:1269
void WarningMsgCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL)
internal CBL warning message
Definition: Kernel.h:747
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 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
Definition: FuncXi.cpp:192
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