CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
MassGrowth.cpp
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2010 by Federico Marulli and Carlo Giocoli *
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 
35 #include "Cosmology.h"
36 
37 using namespace std;
38 
39 using namespace cbl;
40 
41 
42 // =====================================================================================
43 
44 /* ======== Carlo Giocoli ======== */
45 
46 
47 // -------- Halo Mass Growth History based on Giocoli et al. 2012, Nusser and Sheth, Lacey and Coles 1993 --------
48 
49 // Differential rescaled and generalized formation redshift distribution
50 
51 double cbl::cosmology::Cosmology::pw (const double ww, const double ff, const std::string author) const
52 {
53  if (author=="NS") {
54  if (ff<0.5) coutCBL <<"Warning you are calling pw function for NS with f = "<<ff<<endl;
55  return (1./ff-1.)*2.*ww*erfc(ww/sqrt(2.))+(2.-1./ff)*sqrt(2./par::pi)*exp(-ww*ww*0.5);
56  }
57  if (author=="GTS") {
58  double alpha = 0.815*exp(-2.*ff*ff*ff)/pow(ff,0.707);
59  double Denumerator = (exp(ww*ww*0.5)+alpha-1.);
60  return alpha*ww*exp(ww*ww*0.5)/Denumerator/Denumerator;
61  }
62  else return -1.;
63 }
64 
65 
66 // =====================================================================================
67 
68 
69 // Probability that a halo of a given mass m0 at redshift z0 make a mass fraction f at redshift z
70 
71 double cbl::cosmology::Cosmology::pz (const double m0, const double z0, const double frac, const double redshift, const std::string model_model, const std::string method_SS, const bool store_output, const std::string output_root) const
72 {
73  double dcz0 = deltac(z0)/DN(z0);
74  double dcz = deltac(redshift)/DN(redshift);
75  double SS = sigma2M(m0, method_SS, redshift, store_output, output_root);
76  double mf = m0*frac;
77  double SSf = sigma2M(mf, method_SS, redshift, store_output, output_root);
78  double ww = (dcz-dcz0)/sqrt(SSf-SS);
79  if (model_model=="NS"){
80  if(frac<0.5) coutCBL <<"Warning you are calling pw function for NS with frac = "<<frac<<endl;
81  return (1./frac-1.)*2.*ww*erfc(ww/sqrt(2.))+(2.-1./frac)*sqrt(2./par::pi)*exp(-ww*ww*0.5);
82  }
83  if (model_model=="GTS"){
84  double alpha = 0.815*exp(-2.*frac*frac*frac)/pow(frac,0.707);
85  double Denumerator = (exp(ww*ww*0.5)+alpha-1.);
86  return alpha*ww*exp(ww*ww*0.5)/Denumerator/Denumerator;
87  }
88  else return -1.;
89 }
90 
91 
92 // =====================================================================================
93 
94 
95 // Cumulative rescaled and generalized formation redshift distribution
96 
97 double cbl::cosmology::Cosmology::cumPw (const double ww, const double ff, const std::string author) const
98 {
99  if(author=="NS"){
100  if(ff<0.5) coutCBL <<"Warning you are calling cumPw function for NS with f = "<<ff<<endl;
101  double F0 = erf(ww/sqrt(2.))+ww*ww*erfc(ww/sqrt(2.))-sqrt(2./par::pi)*ww*exp(-ww*ww*0.5);
102  double F1 = (1./ff-1.)-(1./ff-1.)*F0;
103  double F2 = (2.-1./ff)*(1.-erf(ww/sqrt(2.)));
104  return F1+F2;
105  }
106  if(author=="GTS"){
107  double alpha = 0.815*exp(-2.*ff*ff*ff)/pow(ff,0.707);
108  double Denumerator = (exp(0.5*ww*ww)+alpha-1.);
109  return alpha/Denumerator;
110  }
111  else return -1.;
112 }
113 
114 
115 // =====================================================================================
116 
117 
118 void cbl::cosmology::Cosmology::medianwf (const double ff, const std::string model_model, vector<double> &wf) const
119 {
120  wf.resize(3);
121 
122  if (model_model=="NS") {
123  int nn = 128;
124  vector<double> ww = linear_bin_vector(nn, 0., 5.);
125  vector<double> Pw(nn);
126  for(int i=0; i<nn; i++) {
127  double F0 = erf(ww[i]/sqrt(2.))+ww[i]*ww[i]*erfc(ww[i]/sqrt(2.))-sqrt(2./par::pi)*ww[i]*exp(-ww[i]*ww[i]*0.5);
128  double F1 = (1./ff-1.)-(1./ff-1.)*F0;
129  double F2 = (2.-1./ff)*(1.-erf(ww[i]/sqrt(2.)));
130  Pw[i] = F1+F2;
131  }
132  string type = "Poly";
133  wf[2] = interpolated(0.5, Pw, ww, type);
134  wf[1] = interpolated(0.25, Pw, ww, type);
135  wf[0] = interpolated(0.75, Pw, ww, type);
136  }
137 
138  if (model_model=="GTS") {
139  double alpha = 0.815*exp(-2*ff*ff*ff)/pow(ff, 0.707);
140  wf[2] = sqrt(2.*log(4.*alpha-(alpha-1.)));
141  wf[1] = sqrt(2.*log(alpha+1.));
142  wf[0] = sqrt(2.*log(alpha/0.75-(alpha-1.)));
143  }
144 
145 }
146 
147 
148 // =====================================================================================
149 
150 // Conditional variable w = \delta_c(zf) - \delta_c(z)/\sqrt(s(fm)-s(m))
151 // we recall that \delta_c(z) = delta_c0(z)/D+(z)
152 
153 double cbl::cosmology::Cosmology::wf (const double mm, const double redshift, const double ff, const double zf, const std::string method_SS, const bool store_output, const std::string output_root) const
154 {
155  double deltacz = deltac(redshift)/DN(redshift);
156  double deltaczf = deltac(zf)/DN(zf);
157  double SS = sigma2M(mm, method_SS, redshift, store_output, output_root);
158  double mf = mm*ff;
159  double SSf = sigma2M(mf, method_SS, redshift, store_output, output_root);
160  return (deltaczf-deltacz)/sqrt(SSf-SS);
161 }
162 
163 
164 // =====================================================================================
165 
166 // with this routine you can estimate the redshift from w given the parent halo mass (at z=z_0), z_0 and its assembled fraction f
167 
168 double cbl::cosmology::Cosmology::Redshift (const double mm, const double redshift, const double ff, const std::string method_SS, const double wwf, const bool store_output, const std::string output_root) const
169 {
170  int const nn = 128;
171  vector<double> lzi = linear_bin_vector(nn, 0., 1.7);
172  double dc0 = deltac(redshift)/DN(redshift);
173  double SS = sigma2M(mm, method_SS, redshift, store_output, output_root);
174  double mf = mm*ff;
175  double SSf = sigma2M(mf, method_SS, redshift, store_output, output_root);
176  double dd = wwf*sqrt(SSf-SS) + dc0;
177 
178  vector<double> dci(nn);
179 
180  for (int i=0; i<nn; i++) {
181  double zi = -1 + pow(10.,lzi[i]);
182  dci[i] = deltac(zi)/DN(zi);
183  }
184 
185  return -1.+pow(10.,interpolated(dd, dci, lzi, "Poly"));
186 }
187 
188 
189 // =====================================================================================
190 
191 
192 void cbl::cosmology::Cosmology::medianzf (const double ff, const double mass, const double z0, const std::string model_model, const std::string method_SS, std::vector<double> &zf, const bool store_output, const std::string output_root) const
193 {
194  vector<double> wf;
195  zf.resize(3);
196  medianwf(ff, model_model, wf);
197 
198  zf[0] = Redshift(mass, z0, ff, method_SS, wf[0], store_output, output_root);
199  zf[1] = Redshift(mass, z0, ff, method_SS, wf[1], store_output, output_root);
200  zf[2] = Redshift(mass, z0, ff, method_SS, wf[2], store_output, output_root);
201 }
202 
The class Cosmology.
#define coutCBL
CBL print message.
Definition: Kernel.h:734
void medianwf(const double ff, const std::string model_model, std::vector< double > &wf) const
median formation w
Definition: MassGrowth.cpp:118
double pw(const double ww, const double ff, const std::string author) const
differential distribution
Definition: MassGrowth.cpp:51
double cumPw(const double ww, const double ff, const std::string author) const
cumulative distribution
Definition: MassGrowth.cpp:97
double pz(const double m0, const double z0, const double frac, const double redshift, const std::string model_model, const std::string method_SS, const bool store_output=true, const std::string output_root="test") const
formation probability
Definition: MassGrowth.cpp:71
double Redshift(const double d_c=1., const double z1_guess=0., const double z2_guess=10., const double prec=0.0001) const
redshift at a given comoving distance
Definition: Cosmology.cpp:1045
void medianzf(const double ff, const double mass, const double z0, const std::string model_model, const std::string method_SS, std::vector< double > &zf, const bool store_output=true, const std::string output_root="test") const
median formation z
Definition: MassGrowth.cpp:192
double wf(const double mm, const double redshift, const double ff, const double zf, const std::string method_SS, const bool store_output=true, const std::string output_root="test") const
rescaled variable w as in Lacey and Coles 1993
Definition: MassGrowth.cpp:153
static const double pi
: the ratio of a circle's circumference to its diameter
Definition: Constants.h:199
static const double alpha
: the fine-structure constant
Definition: Constants.h:233
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
std::vector< T > linear_bin_vector(const size_t nn, const T min, const T max)
fill a std::vector with linearly spaced values
Definition: Kernel.h:1604
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