CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
FuncCosmology.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 "GlobalFunc.h"
35 
36 using namespace std;
37 
38 using namespace cbl;
39 
40 
41 // ============================================================================
42 
43 
44 void cbl::Vmax_DC_distribution (std::vector<double> &dc, std::vector<double> &nObj, const std::vector<double> D_C, const std::vector<double> zobj_min, const std::vector<double> zobj_max, const double z_min, const double z_max, const double zbin_min, const double zbin_max, cosmology::Cosmology &cosm, const double Area, const int nObjRan, const bool norm, const std::string file_Vmax, const double delta_dc_Vmax, const int seed)
45 {
46  if (dc.size()>0 || nObj.size()>0) ErrorCBL("", "Vmax_DC_distribution", "GlobalFunc/FuncCosmology.cpp");
47 
48  random::UniformRandomNumbers ran(0., 1., seed);
49 
50  vector<double> err, dc_Vmax, ww;
51  double Volume, zz;
52 
53  for (unsigned int i=0; i<D_C.size(); i++) {
54  for (int j=0; j<nObjRan; j++) {
55  Volume = ran()*cosm.Volume(zobj_min[i], zobj_max[i], Area);
56  zz = cosm.max_redshift(Volume, Area, zobj_min[i]);
57  if (z_min<zz && zz<z_max) {
58  dc_Vmax.push_back(cosm.D_C(zz));
59  ww.push_back(1.);
60  }
61  }
62  }
63 
64  double fact = (norm) ? double(dc_Vmax.size())/double(D_C.size()) : dc_Vmax.size();
65 
66  double dc1 = cosm.D_C(zbin_min), dc2 = cosm.D_C(zbin_max);
67 
68  int nbin = nint((dc2-dc1))/delta_dc_Vmax;
69 
70  bool linear = 1;
71 
72  distribution(dc, nObj, err, dc_Vmax, ww, nbin, linear, file_Vmax, fact, dc1, dc2);
73 }
74 
75 
76 // ============================================================================================
77 
78 
79 double cbl::AP_shift_r (const double redshift, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2)
80 {
81  return cosm2.D_V(redshift)/cosm1.D_V(redshift);
82 }
83 
84 double cbl::AP_shift_rp (const double redshift, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2)
85 {
86  return cosm1.D_A(redshift)/cosm2.D_A(redshift);
87 }
88 
89 double cbl::AP_shift_pi (const double redshift, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2)
90 {
91  return cosm2.HH(redshift)/cosm1.HH(redshift);
92 }
93 
94 
95 // ============================================================================================
96 
97 
98 void cbl::max_separations_AP (const double Rp_max, const double Pi_max, const double redshift, const cosmology::Cosmology &cosm1, const std::vector<cosmology::Cosmology> &cosm2, double &rpM_AP, double &piM_AP, double &rM_AP)
99 {
100  vector<double> rp(cosm2.size()), pi(cosm2.size());
101 
102  for (unsigned int i=0; i<cosm2.size(); i++) {
103  rp[i] = Rp_max*AP_shift_rp(redshift,cosm1,cosm2[i]);
104  pi[i] = Pi_max*AP_shift_pi(redshift,cosm1,cosm2[i]);
105  }
106 
107  rpM_AP = Max(rp);
108  piM_AP = Max(pi);
109 
110  rM_AP = sqrt(pow(rpM_AP,2)+pow(piM_AP,2));
111 }
112 
113 
114 // ============================================================================================
115 
116 
117 double cbl::converted_xi (const double RR, const double redshift, const std::vector<double> rr, const std::vector<double> Xi, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2, const bool direction)
118 {
119  if (RR==0) ErrorCBL("RR must be >0!", "converted_xi", "GlobalFunc/FuncCosmology.cpp");
120 
121  double gamma = AP_shift_r(redshift, cosm1, cosm2);
122 
123  // direction: 0:cosm2->cosm1, 1:cosm1->cosm2
124  double lgRR = (direction) ? log10(RR/gamma) : log10(RR*gamma);
125 
126  vector<double> lgrr, lgXi;
127  for (unsigned int i=0; i<rr.size(); i++)
128  if (rr[i]>0 && Xi[i]>0) {
129  lgrr.push_back(log10(rr[i]));
130  lgXi.push_back(log10(Xi[i]));
131  }
132 
133  return pow(10., interpolated(lgRR, lgrr, lgXi, "Poly"));
134 }
135 
136 
137 // ============================================================================
138 
139 
140 double cbl::converted_xi (const double RP, const double PI, const double redshift, const std::vector<double> rp, const std::vector<double> pi, const std::vector<std::vector<double> > Xi, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2, const bool direction)
141 {
142  double fDA = AP_shift_rp(redshift, cosm1, cosm2);
143  double fH = AP_shift_pi(redshift, cosm1, cosm2);
144 
145  // direction: 0:cosm2->cosm1, 1:cosm1->cosm2
146  double _RP = (direction) ? RP*fDA : RP/fDA;
147  double _PI = (direction) ? PI*fH : PI/fH;
148 
149  return interpolated_2D(_RP, _PI, rp, pi, Xi, "Poly");
150 }
Generic functions that use one or more classes of the CosmoBolognaLib.
The class Cosmology.
Definition: Cosmology.h:277
double max_redshift(const double Volume, const double Area, const double z_min) const
maximum redshift for a given volume, sky area and minimum redshift
Definition: Cosmology.cpp:1223
double Volume(const double z1, const double z2, const double Area) const
comoving volume for a given redshift range and sky area
Definition: Cosmology.cpp:1183
double D_V(const double redshift) const
the average distance at a given redshift, used to rescale the correlation function
Definition: Cosmology.cpp:884
double HH(const double redshift=0.) const
the Hubble function
Definition: Cosmology.cpp:570
double D_A(const double redshift) const
the angular diameter distance at a given redshift
Definition: Cosmology.cpp:848
double D_C(const double redshift) const
the comoving line-of-sight distance at a given redshift
Definition: Cosmology.cpp:741
The class UniformRandomNumbers.
static const double pi
: the ratio of a circle's circumference to its diameter
Definition: Constants.h:199
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
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
Definition: Func.cpp:1654
double AP_shift_r(const double redshift, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2)
the Alcock-Pacinski factor used to shift comoving distances
double interpolated_2D(const double _x1, const double _x2, const std::vector< double > x1, const std::vector< double > x2, const std::vector< std::vector< double >> yy, const std::string type)
2D interpolation
Definition: Func.cpp:502
void max_separations_AP(const double Rp_max, const double Pi_max, const double redshift, const cosmology::Cosmology &cosm1, const std::vector< cosmology::Cosmology > &cosm2, double &rpM_AP, double &piM_AP, double &rM_AP)
the maximum comoving separations to be used for the AP test, for a given set of test cosmologies
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
T Max(const std::vector< T > vect)
maximum element of a std::vector
Definition: Kernel.h:1336
double converted_xi(const double RR, const double redshift, const std::vector< double > rr, const std::vector< double > Xi, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2, const bool direction)
the 1D two-point correlation function converted from one cosmology to another one
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
int nint(const T val)
the nearest integer
Definition: Kernel.h:915
double AP_shift_pi(const double redshift, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2)
the Alcock-Pacinski factor used to shift comoving distances parallel to the line-of-sight,...
double AP_shift_rp(const double redshift, const cosmology::Cosmology &cosm1, const cosmology::Cosmology &cosm2)
the Alcock-Pacinski factor used to shift comoving distances perpendicular to the line-of-sight,...
void Vmax_DC_distribution(std::vector< double > &dc, std::vector< double > &nObj, const std::vector< double > D_C, const std::vector< double > zobj_min, const std::vector< double > zobj_max, const double z_min, const double z_max, const double zbin_min, const double zbin_max, cosmology::Cosmology &cosm, const double Area, const int nObjRan, const bool norm=1, const std::string file_Vmax=par::defaultString, const double delta_dc_Vmax=100., const int seed=3213)
get a smoothed distribution of comoving distances, estimated with the Vmax method