CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ModelFunction_TwoPointCorrelation_wedges.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2016 by Federico Marulli and Alfonso Veropalumbo *
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 
38 
39 using namespace std;
40 
41 using namespace cbl;
42 
43 
44 // ============================================================================================
45 
46 
47 std::vector<double> cbl::modelling::twopt::xi_Wedges (const std::vector<double> rr, const std::vector<int> dataset_order, const std::vector<std::vector<double>> mu_integral_limits, const std::string model, const std::vector<double> parameter, const std::vector<std::shared_ptr<glob::FuncGrid>> pk_interp, const double prec, const double alpha_perp, const double alpha_par)
48 {
49  vector<vector<double>> Xil = Xi_l(rr, 3, model, parameter, pk_interp, prec, alpha_perp, alpha_par);
50 
51  vector<double> XiW(rr.size());
52 
53  for (size_t i=0; i<rr.size(); i++) {
54  const double mu_min = mu_integral_limits[dataset_order[i]][0];
55  const double mu_max = mu_integral_limits[dataset_order[i]][1];
56 
57  const double f2 = 0.5*((pow(mu_max, 3)-pow(mu_min, 3))/(mu_max-mu_min)-1.);
58  const double f4 = 0.125*((7.*(pow(mu_max, 5)-pow(mu_min, 5))-10.*(pow(mu_max, 3)-pow(mu_min, 3)))/(mu_max-mu_min)+3.);
59 
60  XiW[i] = Xil[0][i]+f2*Xil[1][i]+f4*Xil[2][i];
61  }
62 
63  return XiW;
64 }
65 
66 
67 // ============================================================================================
68 
69 
70 std::vector<std::vector<double>> cbl::modelling::twopt::xi_Wedges (const std::vector<double> rr, const int nWedges, const std::vector<std::vector<double>> mu_integral_limits, const std::string model, const std::vector<double> parameter, const std::vector<std::shared_ptr<glob::FuncGrid>> pk_interp, const double prec, const double alpha_perp, const double alpha_par)
71 {
72  vector<vector<double>> Xil = Xi_l(rr, 3, model, parameter, pk_interp, prec, alpha_perp, alpha_par);
73 
74  vector<vector<double>> XiW(nWedges, vector<double>(rr.size(), 0));
75 
76  for (int i=0; i<nWedges; i++) {
77  const double mu_min = mu_integral_limits[i][0];
78  const double mu_max = mu_integral_limits[i][1];
79 
80  const double f2 = 0.5*((pow(mu_max, 3)-pow(mu_min, 3))/(mu_max-mu_min)-1.);
81  const double f4 = 0.125*((7.*(pow(mu_max, 5)-pow(mu_min, 5))-10.*(pow(mu_max, 3)-pow(mu_min, 3)))/(mu_max-mu_min)+3.);
82 
83  for (size_t j=0; j<rr.size(); j++)
84  XiW[i][j] = Xil[0][j]+f2*Xil[1][j]+f4*Xil[2][j];
85  }
86 
87  return XiW;
88 }
89 
90 
91 // ============================================================================================
92 
93 
94 std::vector<double> cbl::modelling::twopt::xiWedges (const std::vector<double> rad, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
95 {
96  // structure contaning the required input data
97  shared_ptr<STR_data_model> pp = static_pointer_cast<STR_data_model>(inputs);
98 
99  // input parameters
100  vector<shared_ptr<glob::FuncGrid>> pk_interp(2);
101  vector<shared_ptr<glob::FuncGrid>> pk_interp_dispersion(1);
102  vector<shared_ptr<glob::FuncGrid>> pk_interp_Scoccimarro_CPT(3);
103  vector<shared_ptr<glob::FuncGrid>> pk_interp_TNS_CPT(17);
104  vector<shared_ptr<glob::FuncGrid>> pk_interp_eTNS_CPT(25);
105  std::vector<double> Xi_wedge;
106 
107  if (pp->Pk_mu_model=="dispersion_dewiggled") {
108  pk_interp[0] = pp->func_Pk;
109  pk_interp[1] = pp->func_Pk_NW;
110  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, {parameter[2], parameter[3], parameter[4]/pp->sigma8_z, parameter[5]/pp->sigma8_z, parameter[6] }, pk_interp, pp->prec, parameter[0], parameter[1]);
111  }
112 
113  else if (pp->Pk_mu_model=="dispersion_modecoupling") {
114  pk_interp[0] = pp->func_Pk;
115  pk_interp[1] = pp->func_Pk1loop;
116  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, {parameter[2]/pp->sigma8_z, parameter[3]/pp->sigma8_z, parameter[4], parameter[4] }, pk_interp, pp->prec, parameter[0], parameter[1]);
117  }
118 
119  else if (pp->Pk_mu_model=="dispersion_Gauss" || pp->Pk_mu_model=="dispersion_Lorentz") {
120  pk_interp_dispersion[0] = pp->func_Pk;
121  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, { parameter[0]/pp->sigma8_z, parameter[1]/pp->sigma8_z, parameter[2] }, pk_interp_dispersion, pp->prec, parameter[3], parameter[4]);
122  }
123 
124  else if (pp->Pk_mu_model=="ScoccimarroGauss" || pp->Pk_mu_model=="ScoccimarroLorentz") {
125  pk_interp_Scoccimarro_CPT[0] = pp->func_Pk_DeltaDelta;
126  pk_interp_Scoccimarro_CPT[1] = pp->func_Pk_DeltaTheta;
127  pk_interp_Scoccimarro_CPT[2] = pp->func_Pk_ThetaTheta;
128  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, { parameter[0]/pp->sigma8_z, parameter[1]/pp->sigma8_z, parameter[2] }, pk_interp_Scoccimarro_CPT, pp->prec, parameter[3], parameter[4]);
129  }
130 
131  else if (pp->Pk_mu_model=="Scoccimarro_Pezzotta_Gauss" || pp->Pk_mu_model=="Scoccimarro_Pezzotta_Lorentz") {
132  pk_interp[0] = pp->func_Pk;
133  pk_interp[1] = pp->func_Pk_nonlin;
134  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, { parameter[0]/pp->sigma8_z, parameter[1]/pp->sigma8_z, parameter[2], parameter[3], parameter[4] }, pk_interp, pp->prec, parameter[5], parameter[6]);
135  }
136 
137  else if (pp->Pk_mu_model=="Scoccimarro_Bel_Gauss" || pp->Pk_mu_model=="Scoccimarro_Bel_Lorentz") {
138  pk_interp[0] = pp->func_Pk;
139  pk_interp[1] = pp->func_Pk_nonlin;
140  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, { parameter[0]/pp->sigma8_z, parameter[1]/pp->sigma8_z, parameter[2], parameter[3], parameter[4], parameter[5], parameter[6], parameter[7] }, pk_interp, pp->prec, parameter[8], parameter[9]);
141  }
142 
143  else if (pp->Pk_mu_model=="TNS_Gauss" || pp->Pk_mu_model=="TNS_Lorentz") {
144  pk_interp_TNS_CPT[0] = pp->func_Pk_DeltaDelta;
145  pk_interp_TNS_CPT[1] = pp->func_Pk_DeltaTheta;
146  pk_interp_TNS_CPT[2] = pp->func_Pk_ThetaTheta;
147  pk_interp_TNS_CPT[3] = pp->func_Pk_A11;
148  pk_interp_TNS_CPT[4] = pp->func_Pk_A12;
149  pk_interp_TNS_CPT[5] = pp->func_Pk_A22;
150  pk_interp_TNS_CPT[6] = pp->func_Pk_A23;
151  pk_interp_TNS_CPT[7] = pp->func_Pk_A33;
152  pk_interp_TNS_CPT[8] = pp->func_Pk_B12;
153  pk_interp_TNS_CPT[9] = pp->func_Pk_B13;
154  pk_interp_TNS_CPT[10] = pp->func_Pk_B14;
155  pk_interp_TNS_CPT[11] = pp->func_Pk_B22;
156  pk_interp_TNS_CPT[12] = pp->func_Pk_B23;
157  pk_interp_TNS_CPT[13] = pp->func_Pk_B24;
158  pk_interp_TNS_CPT[14] = pp->func_Pk_B33;
159  pk_interp_TNS_CPT[15] = pp->func_Pk_B34;
160  pk_interp_TNS_CPT[16] = pp->func_Pk_B44;
161  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, { parameter[0]/pp->sigma8_z, parameter[1]/pp->sigma8_z, parameter[2] }, pk_interp_TNS_CPT, pp->prec, parameter[3], parameter[4]);
162  }
163 
164  else if (pp->Pk_mu_model=="eTNS_Gauss" || pp->Pk_mu_model=="eTNS_Lorentz") {
165  pk_interp_eTNS_CPT[0] = pp->func_Pk_DeltaDelta;
166  pk_interp_eTNS_CPT[1] = pp->func_Pk_DeltaTheta;
167  pk_interp_eTNS_CPT[2] = pp->func_Pk_ThetaTheta;
168  pk_interp_eTNS_CPT[3] = pp->func_Pk_A11;
169  pk_interp_eTNS_CPT[4] = pp->func_Pk_A12;
170  pk_interp_eTNS_CPT[5] = pp->func_Pk_A22;
171  pk_interp_eTNS_CPT[6] = pp->func_Pk_A23;
172  pk_interp_eTNS_CPT[7] = pp->func_Pk_A33;
173  pk_interp_eTNS_CPT[8] = pp->func_Pk_B12;
174  pk_interp_eTNS_CPT[9] = pp->func_Pk_B13;
175  pk_interp_eTNS_CPT[10] = pp->func_Pk_B14;
176  pk_interp_eTNS_CPT[11] = pp->func_Pk_B22;
177  pk_interp_eTNS_CPT[12] = pp->func_Pk_B23;
178  pk_interp_eTNS_CPT[13] = pp->func_Pk_B24;
179  pk_interp_eTNS_CPT[14] = pp->func_Pk_B33;
180  pk_interp_eTNS_CPT[15] = pp->func_Pk_B34;
181  pk_interp_eTNS_CPT[16] = pp->func_Pk_B44;
182  pk_interp_eTNS_CPT[17] = pp->func_Pk_b2d;
183  pk_interp_eTNS_CPT[18] = pp->func_Pk_b2v;
184  pk_interp_eTNS_CPT[19] = pp->func_Pk_b22;
185  pk_interp_eTNS_CPT[20] = pp->func_Pk_bs2d;
186  pk_interp_eTNS_CPT[21] = pp->func_Pk_bs2v;
187  pk_interp_eTNS_CPT[22] = pp->func_Pk_b2s2;
188  pk_interp_eTNS_CPT[23] = pp->func_Pk_bs22;
189  pk_interp_eTNS_CPT[24] = pp->func_sigma32Pklin;
190  Xi_wedge = xi_Wedges(rad, pp->dataset_order, pp->mu_integral_limits, pp->Pk_mu_model, { parameter[0]/pp->sigma8_z, parameter[1]/pp->sigma8_z, parameter[2]/pp->sigma8_z, parameter[3], parameter[6] }, pk_interp_eTNS_CPT, pp->prec, parameter[4], parameter[5]);
191  }
192 
193  else ErrorCBL("the chosen model ("+pp->Pk_mu_model+") is not currently implemented!", "xiWedges", "ModelFunction_TwoPointCorrelation_wedges.cpp");
194 
195  return Xi_wedge;
196 
197 }
198 
199 
200 // ============================================================================================
201 
202 
203 std::vector<double> cbl::modelling::twopt::xiWedges_BAO (const std::vector<double> rad, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
204 {
205  // structure contaning the required input data
206  shared_ptr<STR_data_model> pp = static_pointer_cast<STR_data_model>(inputs);
207 
208  vector<double> Xi(rad.size());
209 
210  // input parameters
211 
212  // AP parameter that contains the distance information
213  double alpha_perpendicular = parameter[0];
214 
215  // AP parameter that contains the distance information
216  double alpha_parallel = parameter[1];
217 
218  for (size_t i=0; i<rad.size(); i++) {
219  const int wedge = pp->dataset_order[i];
220  const double rr = rad[i];
221 
222  double mu_min = double(wedge)/pp->nWedges;
223  double mu_max = double(wedge+1)/pp->nWedges;
224  const double delta = (mu_max-mu_min);
225 
226  const double B = parameter[2+wedge];
227  const double A0 = parameter[4+wedge];
228  const double A1 = parameter[6+wedge];
229  const double A2 = parameter[8+wedge];
230 
231  auto integrand = [&] (const double mu_fid)
232  {
233  return twopt::Xi_polar(rr, mu_fid, alpha_perpendicular, alpha_parallel, pp->func_multipoles);
234  };
235 
236 
237  Xi[i] = B*wrapper::gsl::GSL_integrate_qag(integrand, mu_min, mu_max)/delta+A0+A1/rr+A2/(rr*rr);
238  }
239 
240  return Xi;
241 }
Global functions to model two-point correlation functions of any type.
Functions to model the wedges of the two-point correlation function.
std::vector< std::vector< double > > xi_Wedges(const std::vector< double > rr, const int nWedges, const std::vector< std::vector< double >> mu_integral_limits, const std::string model, const std::vector< double > parameter, const std::vector< std::shared_ptr< glob::FuncGrid >> pk_interp, const double prec=1.e-5, const double alpha_perp=1, const double alpha_par=1.)
the model wedges of the two-point correlation function
std::vector< double > xiWedges(const std::vector< double > rad, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
the model wedges of the two-point correlation function
std::vector< std::vector< double > > Xi_l(const std::vector< double > rr, const int nmultipoles, const std::string model, const std::vector< double > parameter, const std::vector< std::shared_ptr< glob::FuncGrid >> pk_interp, const double prec=1.e-5, const double alpha_perp=1., const double alpha_par=1.)
the multipole of order l of the two-point correlation function
std::vector< double > xiWedges_BAO(const std::vector< double > rad, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
return the wedges of the two-point correlation function, intended for anisotropic BAO measurements
double Xi_polar(const double rad_fid, const double mu_fid, const double alpha_perpendicular, const double alpha_parallel, const std::vector< std::shared_ptr< cbl::glob::FuncGrid >> xi_multipoles)
the polar two-point correlation function
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
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