FML
Halomodel.cpp
Go to the documentation of this file.
2#include <FML/Spline/Spline.h>
3#include <FML/Math/Math.h>
5#include "Halomodel.h"
6
7namespace FML {
8
9 namespace COSMOLOGY {
10
11 namespace HALOMODEL {
12
13 //================================================
14 // 2 for <1% accuracy. Runtime is quadratic in this
15 //================================================
17
18 // Extend a logY(logx) spline assuming
19 // Y ~ x^n close to the endpoints
20 // Useful for extending e.g. P(k) needed
21 // for halomodel calculations
23 Spline & logY_of_logx_spline,
24 double xmin_new,
25 double xmax_new,
26 int npts_new,
27 std::string label = "logY(log(x)) extrapolated"){
28
29 // Fetch logx-array from spline
30 const auto logx_array = logY_of_logx_spline.get_x_data();
31 const double logxmin = logx_array.front();
32 const double logxmax = logx_array.back();
33
34 // Compute slope near end-points
35 double slope_min = logY_of_logx_spline.deriv_x(logxmin*0.99);
36 double slope_max = logY_of_logx_spline.deriv_x(logxmax*1.01);
37
38 // Extrapolation function
39 auto logY_extrapolated = [&](double logx){
40 if(logx < logxmin){
41 return logY_of_logx_spline(logxmin) + (logx-logxmin) * slope_min;
42 } else if(logx > logxmax){
43 return logY_of_logx_spline(logxmax) + (logx-logxmax) * slope_max;
44 }
45 return logY_of_logx_spline(logx);
46 };
47
48 // Extend spline to one covering a larger region
49 const auto logx_array_new = FML::MATH::linspace(std::log(xmin_new), std::log(xmax_new), npts_new);
50 DVector logY_array_new;
51 for(const auto logx : logx_array_new){
52 logY_array_new.push_back( logY_extrapolated(logx) );
53 }
54 logY_of_logx_spline = Spline(logx_array_new, logY_array_new, label);
55 }
56
57 //================================================
58 // Take in a file with format [k, P(k)] in (h/Mpc, Mpc^3/h^3) units
59 // Read and make a spline of the dimensionless power-spectrum
60 //================================================
62 const std::string filename_pofk,
63 Spline & logDelta_of_logk_spline,
64 double normalization,
65 int col_k,
66 int col_pofk){
67
68 // Read file
69 auto data = FML::FILEUTILS::loadtxt(filename_pofk);
70
71 // Extract data, transform to Delta, normalize and spline
72 DVector logk_array, logDelta_array;
73 for(size_t i = 0; i < data.size(); i++){
74 double k = data[i][col_k];
75 double pofk = data[i][col_pofk];
76 double Delta_over_pofk = (k*k*k) / (2.0*M_PI*M_PI);
77 logk_array.push_back( std::log(k) );
78 logDelta_array.push_back( std::log( pofk * Delta_over_pofk * normalization ) );
79 }
80
81 // Make spline
82 logDelta_of_logk_spline = Spline(logk_array, logDelta_array, "logDelta(logk)");
83
84 // Extrapolate assuming ~ k^n at each end
85 // and remake spline
86 const double kmin = 1e-12;
87 const double kmax = 1e12;
88 const int npts_spline = 1000;
90 logDelta_of_logk_spline,
91 kmin,
92 kmax,
93 npts_spline,
94 "logDelta(logk) extrapolated");
95 }
96
97 //================================================
98 // Computes neff = -3 - d/dlogR sigma^2
99 // at the point where nu == deltac/sigma == 1
100 //================================================
101 std::pair<double,double> compute_neff(
102 const Spline & logsigma_of_logR_spline,
103 const Spline & lognu_of_logR_spline){
104 const double logRmin = std::log(1e-4);
105 const double logRmax = std::log(1e4);
106 const double epsilon = 1e-10;
107
108 const double lognu_goal = std::log(1.0);
109 auto condition = [&](double logR){
110 return lognu_of_logR_spline(logR) - lognu_goal;
111 };
112 const double logR = FML::MATH::find_root_bisection(condition, {logRmin, logRmax}, epsilon);
113 const double neff = -3.0 - 2.0 * logsigma_of_logR_spline.deriv_x(logR);
114 return std::pair(std::exp(logR), neff);
115 }
116
117 //================================================
118 // Computes F(R) = 1/3 * Int W(kR)^2 Delta(k)/k^2 dlogk
119 // sigmav = F(0) and sigmav100 = F(100)
120 //================================================
122 const Func1 logDelta_of_logk,
123 const WindowFunction window_of_kR,
124 double R,
125 const DVector *fiducial_logk_array){
126 auto integrand = [&](double logk){
127 const double W = window_of_kR(std::exp(logk)*R);
128 return W*W*std::exp(logDelta_of_logk(logk))*std::exp(-2*logk)/3.0;
129 };
130
131 const double kmin = 1e-8, kmax = 1e4;
132 const int npts_k = 1000;
133 auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
134 if(fiducial_logk_array != nullptr)
135 logk_array = *fiducial_logk_array;
136 auto k_array = logk_array;
137 for(auto & k : k_array) k = std::exp(k);
138 double integral = 0.0;
139 for(const auto logk : logk_array){
140 integral += integrand(logk);
141 }
142 integral *= (logk_array[1]-logk_array[0]);
143 return std::sqrt(integral);
144 }
145
146 //================================================
147 // Computes the variance Int Delta(k)W^2(kR) dlogk
148 //================================================
150 const Func1 logDelta_of_logk,
151 const WindowFunction window_of_kR,
152 Spline & logsigma_of_logR_spline,
153 const DVector *fiducial_logR_array,
154 const DVector *fiducial_logk_array){
155
156 //================================================
157 // Radius array
158 // If not provided then we generate it
159 //================================================
160 const double Rmin = 1e-8, Rmax = 1e8;
161 const int npts_R = 500;
162 auto logR_array = FML::MATH::linspace(std::log(Rmin), std::log(Rmax), npts_R);
163 if(fiducial_logR_array != nullptr)
164 logR_array = *fiducial_logR_array;
165 auto R_array = logR_array;
166 for(auto & R : R_array) R = std::exp(R);
167
168 //================================================
169 // k integration array. Linear in logk
170 // If not provided then we generate it
171 //================================================
172 const double kmin = 1e-8, kmax = 1e8;
173 const int npts_k = 500;
174 auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
175 if(fiducial_logk_array != nullptr)
176 logk_array = *fiducial_logk_array;
177 auto k_array = logk_array;
178 for(auto & k : k_array) k = std::exp(k);
179
180 //================================================
181 // Compute and spline sigma(R)
182 //================================================
183 DVector logsigma_array;
184 for(const auto R : R_array){
185
186 auto integrand = [&logDelta_of_logk,&window_of_kR](double logk, double R){
187 const double k = std::exp(logk);
188 const double W = window_of_kR(k*R);
189 return std::exp(logDelta_of_logk(logk)) * W * W;
190 };
191
192 double integral = 0.0;
193 for(const auto logk : logk_array){
194 integral += integrand(logk, R);
195 }
196 integral *= (logk_array[1]-logk_array[0]);
197 logsigma_array.push_back(0.5*std::log(integral));
198 }
199 logsigma_of_logR_spline = Spline(logR_array, logsigma_array, "sigma(R)");
200 }
201
202 //================================================
203 // M in Msun/h and R given in Mpc/h
204 //================================================
205 double RvirofM(
206 double M,
207 double DeltaVir,
208 double OmegaM,
209 double x){
210 return RofM(M, OmegaM, x) * std::pow(DeltaVir, -1.0/3.0);
211 }
212
213 //================================================
214 // R in Mpc/h to mass in Msun/h
215 //================================================
216 double RofM(
217 double M,
218 double OmegaM,
219 double x){
220 const double Mpl2overMsunH0overh = 2.493e21;
221 const double H0overh_in_hmpc = 1.0 / 2997.92458;
222 const double rho_mean_in_msunh_over_mpch3 = 3.0 * OmegaM * std::exp(-3.0*x)
223 * std::pow(H0overh_in_hmpc,3) * Mpl2overMsunH0overh;
224 return std::pow(M / (4.0 * M_PI / 3.0 * rho_mean_in_msunh_over_mpch3), 1.0/3.0);
225 }
226
227 //================================================
228 // M in Msun/h and R given in Mpc/h
229 //================================================
230 double MofRvir(
231 double Rvir,
232 double DeltaVir,
233 double OmegaM,
234 double x){
235 return MofR(Rvir, OmegaM, x) * DeltaVir;
236 }
237
238 //================================================
239 // M in Msun/h and R given in Mpc/h
240 //================================================
241 double MofR(
242 double R,
243 double OmegaM,
244 double x){
245 const double Mpl2overMsunH0overh = 2.493e21;
246 const double H0overh_in_hmpc = 1.0 / 2997.92458;
247 const double rho_mean_in_msunh_over_mpch3 = 3.0 * OmegaM * std::exp(-3.0*x)
248 * std::pow(H0overh_in_hmpc,3) * Mpl2overMsunH0overh;
249 return 4.0 * M_PI / 3.0 * rho_mean_in_msunh_over_mpch3 * std::pow(R, 3);
250 }
251
252 //================================================
253 // Computes the fourier transform y(k,R) of rho_function
254 // rho_function is 4pi*rho(r,M)r^3/M as function of (r,M)
255 // for a single M
256 //================================================
258 const Func2 & rho_function,
259 const DVector & k_array,
260 const double M,
261 const double Rvir){
262
263 int accuracy_boost = _ACCURACY_BOOST;
264
265 //================================================
266 // Determine lower integration limits
267 // by requiring rho(rmin) < 1e-6 rho(Rvir/10)
268 //================================================
269 double rho_start = rho_function(Rvir/10.0,M);
270 int power_min = 1;
271 while(power_min < 5) {
272 ++power_min;
273 double rho = rho_function(Rvir/std::pow(10,power_min),M);
274 if(rho < 1e-4 * rho_start) break;
275 };
276
277 //================================================
278 // Determine upper integration limit
279 //================================================
280 int power_max = 0;
281 while(power_max < 7) {
282 ++power_max;
283 double rho = rho_function(Rvir*std::pow(2,power_max),M);
284 if(rho == 0.0) break;
285 }
286
287 //================================================
288 // Radius integration array
289 //================================================
290 const double rmin = Rvir/std::pow(10,power_min), rmax = Rvir*std::pow(2,power_max);
291 const int npts_r = (power_max+power_min) * 50 * accuracy_boost;
292 const auto logr_array = FML::MATH::linspace(std::log(rmin), std::log(rmax), npts_r);
293 auto r_array = logr_array;
294 for(auto & r : r_array) r = std::exp(r);
295
296 DVector y_array;
297 for(const auto k : k_array){
298
299 auto integrand = [&rho_function](double k, double r, double M){
300 return rho_function(r, M) * std::sin(k*r)/(k*r);
301 };
302
303 // Integrate up to get the dimensionless y = rho(k,M)/M
304 double integral = 0.0;
305 for(const auto r : r_array){
306 integral += integrand(k, r, M);
307 }
308 integral *= (logr_array[1] - logr_array[0]);
309 y_array.push_back(integral);
310 }
311
312 // Ensure normalization in case rho is not properly normalized
313 // y(k,M) -> 1 as k -> 0
314 const double norm = y_array[0];
315 for(auto & y : y_array) y /= norm;
316
317 return y_array;
318 }
319
320 //================================================
321 // Computes the fourier transform y(k,R) of rho_function
322 // rho_function is 4pi*rho(r,M)r^3/M as function of (r,M)
323 // for all M
324 //================================================
326 const Func2 & rho_function,
327 Spline2D & y_of_logR_and_logk_spline,
328 const double DeltaVir,
329 const double OmegaM,
330 const double x,
331 const DVector *fiducial_logR_array,
332 const DVector *fiducial_logk_array){
333
334 int accuracy_boost = _ACCURACY_BOOST;
335
336 //================================================
337 // k array
338 //================================================
339 const double kmin = 1e-8, kmax = 1e8;
340 const int npts_k = 75 * accuracy_boost;
341 auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
342 if(fiducial_logk_array != nullptr)
343 logk_array = *fiducial_logk_array;
344 auto k_array = logk_array;
345 for(auto & k : k_array) k = std::exp(k);
346
347 //================================================
348 // R array
349 //================================================
350 const double Rmin = 1e-8, Rmax = 1e8;
351 const int npts_R = 75 * accuracy_boost;
352 auto logR_array = FML::MATH::linspace(std::log(Rmin), std::log(Rmax), npts_R);
353 if(fiducial_logR_array != nullptr)
354 logR_array = *fiducial_logR_array;
355 auto R_array = logR_array;
356 for(auto & R : R_array) R = std::exp(R);
357
358 DVector2D yofkandM_array(R_array.size(), DVector(k_array.size()));
359#ifdef USE_OMP
360#pragma omp parallel for schedule(dynamic,1)
361#endif
362 for(size_t i = 0; i < R_array.size(); i++){
363 const double R = R_array[i];
364 const double M = MofR(R, OmegaM, x);
365 const double Rvir = R / std::pow(DeltaVir,1.0/3.0);
366 const auto result = compute_rho_fourier_single(rho_function, k_array, M, Rvir);
367 yofkandM_array[i] = result;
368 }
369 y_of_logR_and_logk_spline = Spline2D(logR_array, logk_array, yofkandM_array, "y(logR,logk)");
370 }
371
372 //================================================
373 // Computes a spline of lognu(logR) and the
374 // inverse logR(lognu)
375 //================================================
377 const double deltac,
378 const Spline & logsigma_of_logR_spline,
379 Spline & lognu_of_logR_spline,
380 Spline & logR_of_lognu_spline,
381 const DVector *fiducial_logR_array){
382
383 //================================================
384 // Radius array
385 //================================================
386 const double logRmin = logsigma_of_logR_spline.get_xrange().first;
387 const double logRmax = logsigma_of_logR_spline.get_xrange().second;
388 const int npts_R = 500;
389 auto logR_array = FML::MATH::linspace(logRmin, logRmax, npts_R);
390 if(fiducial_logR_array != nullptr)
391 logR_array = *fiducial_logR_array;
392
393 DVector lognu_array;
394 for(const auto logR : logR_array){
395 const double sigma = std::exp(logsigma_of_logR_spline(logR));
396 const double nu = deltac/sigma;
397 lognu_array.push_back(std::log(nu));
398 }
399
400 lognu_of_logR_spline = Spline(logR_array, lognu_array, "lognu(logR)");
401 logR_of_lognu_spline = Spline(lognu_array, logR_array, "logR(lognu)");
402 }
403
404 //================================================
405 // Computes the mass-function dndlogM(logM)
406 // and n(dlogM)
407 //================================================
409 const Spline & logR_of_lognu_spline,
410 const Spline & lognu_of_logR_spline,
411 Spline & dndlogM_of_logM_spline,
412 Spline & n_of_logM_spline,
413 const Func1 & pdf_of_nu,
414 const double OmegaM,
415 const double x){
416
417 // Units of (h/Mpc)^3 (same as 1/R^3)
418 auto dndlogM_of_lognu = [&](double lognu){
419 const double nu = std::exp(lognu);
420 const double logR = logR_of_lognu_spline(lognu);
421 const double R = std::exp(logR);
422 const double f = pdf_of_nu(nu);
423 const double dnudlogR = nu * lognu_of_logR_spline.deriv_x(logR);
424 return f * std::abs(dnudlogR) / (4.0 * M_PI * R * R * R);
425 };
426
427 //================================================
428 // M array
429 //================================================
430 const double Mmin = 1e5, Mmax = 1e18;
431 const int npts_M = 500;
432 const auto logM_array = FML::MATH::linspace(std::log(Mmin),std::log(Mmax),npts_M);
433 const double dlogM = logM_array[1]-logM_array[0];
434
435 DVector dndlogM_array(npts_M), n_array(npts_M, 0.0), lognu_array(npts_M,0.0);
436 for(int i = npts_M-1; i >= 0; i--){
437 const double logM = logM_array[i];
438 const double M = std::exp(logM);
439 const double R = RofM(M, OmegaM, x);
440 const double logR = std::log(R);
441 const double lognu = lognu_of_logR_spline(logR);
442 const double dndlogM = dndlogM_of_lognu(lognu);
443 dndlogM_array[i] = dndlogM;
444 n_array[i] = dndlogM * dlogM;
445 if(i < npts_M-1)
446 n_array[i] += n_array[i+1];
447 }
448 dndlogM_of_logM_spline = Spline(logM_array, dndlogM_array, "dndlogM(logM)");
449 n_of_logM_spline = Spline(logM_array, n_array, "n(logM)");
450 }
451
452 //================================================
453 // Evaluates the one and two halo integrals
454 // P1h(k) and P2h(k) and returns splines of
455 // DeltaP = k^3P(k)/2pi^2 for both terms and
456 // the sum Delta1h+Delta2h
457 //================================================
459 const Spline & logR_of_lognu_spline,
460 const Spline2D & y_of_logR_and_logk_spline,
461 Spline & logDelta_onehalo_of_logk_spline,
462 Spline & logDelta_twohalo_of_logk_spline,
463 Spline & logDelta_full_of_logk_spline,
464 const Func1 & logDeltaLin_of_logk,
465 const Func1 & pdf_of_nu,
466 const Func1 & bias_of_nu,
467 const double eta_hmcode,
468 const double kmin,
469 const double kmax,
470 const int npts_k){
471
472 int accuracy_boost = _ACCURACY_BOOST;
473
474 //================================================
475 // nu array
476 //================================================
477 const double numin = 1e-10, numax = 10;
478 const int npts_nu = 200 * accuracy_boost;
479 const auto lognu_array = FML::MATH::linspace(std::log(numin),std::log(numax),npts_nu);
480
481 //================================================
482 // k array
483 //================================================
484 const auto logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
485 auto k_array = logk_array;
486 for(auto & k : k_array) k = std::exp(k);
487
488 auto integrand_onehalo = [&logR_of_lognu_spline,&y_of_logR_and_logk_spline,&eta_hmcode,&pdf_of_nu](double lognu, double logk){
489 const double nu = std::exp(lognu);
490 const double logR = logR_of_lognu_spline(lognu);
491 const double y = y_of_logR_and_logk_spline(logR, logk + lognu*eta_hmcode);
492 const double f = pdf_of_nu(nu);
493 const double Moverrhomean = 4.0 * M_PI / 3.0 * std::exp(3.0*logR);
494 return Moverrhomean * f * (y*y) * nu;
495 };
496
497 auto integrand_twohalo = [&eta_hmcode,&logR_of_lognu_spline,&y_of_logR_and_logk_spline,&pdf_of_nu,&bias_of_nu](double lognu, double logk){
498 const double nu = std::exp(lognu);
499 const double logR = logR_of_lognu_spline(lognu);
500 const double y = y_of_logR_and_logk_spline(logR, logk + lognu*eta_hmcode);
501 const double f = pdf_of_nu(nu);
502 const double bias = bias_of_nu(nu);
503 return bias * f * y * nu;
504 };
505
506 // This should integrate to 1
507 auto integrand_norm_onehalo = [&pdf_of_nu](double lognu){
508 const double nu = std::exp(lognu);
509 const double f = pdf_of_nu(nu);
510 return f * nu;
511 };
512
513 // This should integrate to 1
514 auto integrand_norm_twohalo = [&pdf_of_nu,&bias_of_nu](double lognu){
515 const double nu = std::exp(lognu);
516 const double f = pdf_of_nu(nu);
517 const double bias = bias_of_nu(nu);
518 return bias * f * nu;
519 };
520
521 // Compute Int fdnu and Int bf dnu
522 // Both which should be unity
523 double normone = 0.0;
524 double normtwo = 0.0;
525 for(const auto lognu : lognu_array){
526 normone += integrand_norm_onehalo(lognu);
527 normtwo += integrand_norm_twohalo(lognu);
528 }
529 normone *= (lognu_array[1]-lognu_array[0]);
530 normtwo *= (lognu_array[1]-lognu_array[0]);
531 // Sanity check Int f dnu = 1 and Int f b dnu = 1
532 if(std::abs(normone-1.0) > 0.001 or std::abs(normtwo-1.0) > 0.001){
533 // Can happen normally if massfunction is not normalized but in any case Int bf / Int f == 1
534 std::cout << "Warning: Unity check failed for Int f(nu)dnu = " << normone << " Int b(nu)f(nu)dnu = " << normtwo << "\n";
535 std::cout << "Could be that massfunction is not normalized. In that case this should be unity: " << normtwo/normone << "\n";
536 }
537
538 DVector logDelta_onehalo_array;
539 DVector logDelta_twohalo_array;
540 DVector logDelta_full_array;
541 for(const auto logk : logk_array){
542 const double k = std::exp(logk);
543
544 // Integrate up one and two halo integrals
545 double onehalo = 0.0;
546 double twohalo = 0.0;
547 double full = 0.0;
548 for(const auto lognu : lognu_array){
549 onehalo += integrand_onehalo(lognu, logk);
550 twohalo += integrand_twohalo(lognu, logk);
551 }
552 onehalo *= (lognu_array[1]-lognu_array[0]);
553 twohalo *= (lognu_array[1]-lognu_array[0]);
554
555 // Normalize
556 onehalo *= (k*k*k)/(2.0*M_PI*M_PI) / normone;
557 twohalo *= 1.0 / normtwo;
558 twohalo = twohalo * twohalo * std::exp(logDeltaLin_of_logk(logk));
559 full = onehalo + twohalo;
560
561 logDelta_onehalo_array.push_back(std::log(onehalo));
562 logDelta_twohalo_array.push_back(std::log(twohalo));
563 logDelta_full_array.push_back(std::log(full));
564
565 }
566
567 logDelta_onehalo_of_logk_spline = Spline(logk_array, logDelta_onehalo_array, "logDelta1h(logk)");
568 logDelta_twohalo_of_logk_spline = Spline(logk_array, logDelta_twohalo_array, "logDelta2h(logk)");
569 logDelta_full_of_logk_spline = Spline(logk_array, logDelta_full_array, "logDelta(logk)");
570 }
571
572 //================================================
573 // Computes the formation redshift
574 // D(zf)/D(z) sigma(M * massfrac) = deltac
575 // where the fiducial choice is massfrac = 0.01.
576 // If zf < z then we put zf=z
577 // This is used in the c(M) relation
578 // c(M) = cmin (1+zf(M))/(1+zcollapse) used in Bullock 2001
579 //================================================
581 const Spline & growthfactor_of_x_spline,
582 const Spline & logsigma_of_logR_spline,
583 Spline & formationredshift_of_logM_spline,
584 double deltac,
585 double OmegaM,
586 double xcollapse,
587 double massfraction){
588
589 // Solve D(zf)/D(z) sigma(massfraction * M, z) == deltac(z) for zf
590 // where z is collapse redshift
591 auto compute_formation_redshift = [&](double M){
592 const double Mform = massfraction * M;
593 const double R = RofM(Mform, OmegaM, xcollapse);
594 auto condition = [&](double x){
595 const double xminspline = growthfactor_of_x_spline.get_xrange().first;
596 double growthratio = growthfactor_of_x_spline(x) / growthfactor_of_x_spline(xcollapse);
597 if(x < xminspline){
598 growthratio = growthfactor_of_x_spline(xminspline) / growthfactor_of_x_spline(xcollapse);
599 growthratio *= std::exp(x-xminspline);
600 }
601 const double sigma = std::exp(logsigma_of_logR_spline(std::log(R)));
602 return growthratio * sigma - deltac;
603 };
604 double xformation = xcollapse;
605 try{
606 xformation = FML::MATH::find_root_bisection(condition, {std::log(1e-10), xcollapse}, 1e-8);
607 } catch(...){
608 }
609 return xformation;
610 };
611
612 //========================================
613 // Make R array
614 //========================================
615 const double Rmin = 1e-8, Rmax = 1e8;
616 const int npts_R = 10000;
617 const auto logR_array = FML::MATH::linspace(std::log(Rmin), std::log(Rmax), npts_R);
618
619 // Compute formation-factor (1+zf(m))/(1+zcollapse) for all radii
620 DVector formationtime_array;
621 DVector logM_array;
622 for(const auto logR : logR_array){
623 const double M = MofR(std::exp(logR), OmegaM, xcollapse);
624 const double xformation = compute_formation_redshift(M);
625 formationtime_array.push_back(std::exp(-xformation)-1.0);
626 logM_array.push_back(std::log(M));
627 }
628 formationredshift_of_logM_spline = Spline(logM_array, formationtime_array, "zf(logM)");
629 }
630
631 //===========================================
632 // Constructor
633 //===========================================
635 SphericalCollapseModel spcmodel,
636 Spline logDelta_of_logk_spline,
637 double xinput_pofk,
638 bool hmcode,
639 bool verbose,
640 double xini,
641 int npts) :
642 spcmodel(spcmodel),
643 OmegaM(spcmodel.OmegaM),
644 logDelta_of_logk_spline(logDelta_of_logk_spline),
645 xinput_pofk(xinput_pofk),
646 hmcode(hmcode),
648 xini_spherical_collapse(xini),
649 npts_spherical_collapse(npts) {
650 init();
651 }
652
653 //===========================================
654 // Halo massfunction modelling
655 // Get the fiducial option that is ST
656 //===========================================
658 return [&](double nu, HaloModel *hm){
659 const double A_ST = hm->A_ST;
660 const double p_ST = hm->p_ST;
661 const double a_ST = hm->a_ST;
662 return A_ST * (1.0 + std::pow(a_ST*nu*nu,-p_ST)) * std::exp(-a_ST*nu*nu/2.0);
663 };
664 }
666 return [&](double nu, HaloModel *hm){
667 const double deltac = hm->deltac;
668 const double p_ST = hm->p_ST;
669 const double a_ST = hm->a_ST;
670 return 1.0 + (a_ST*nu*nu-1.0)/deltac + 2.0*p_ST/deltac/(1.0+std::pow(a_ST*nu*nu,p_ST));
671 };
672 }
673
674 //===========================================
675 // Fourier smoothing filter
676 //===========================================
678 return [](double kR){
679 if(kR < 1e-6) return 1.0 - kR*kR/10.;
680 return 3.0/(kR*kR*kR)*(std::sin(kR)-kR*std::cos(kR));
681 };
682 }
683
684 //=====================================================
685 // Initialize a run. Runs in the constructor
686 //=====================================================
688
689 /*
690 // Make a linear logR-array we can use (to ensure we have range and accuracy set just one place)
691 const double Rmin = 1e-8, Rmax = 1e5;
692 const int npts_R = 150 * _ACCURACY_BOOST;
693 DVector logR_array = FML::MATH::linspace(std::log(Rmin), std::log(Rmax), npts_R);
694 fiducial_logR_array = std::make_shared<DVector>(logR_array);
695
696 // Make a linear logk-array we can use (to ensure we have range and accuracy set just one place)
697 const double kmin = 1e-5, kmax = 1e6;
698 const int npts_k = 150 * _ACCURACY_BOOST;
699 DVector logk_array = FML::MATH::linspace(std::log(kmin), std::log(kmax), npts_k);
700 fiducial_logk_array = std::make_shared<DVector>(logk_array);
701 */
702
703 if(verbose){
704 std::cout << "\n#=====================================================\n";
705 std::cout << "# Initializing the halomodel\n";
706 std::cout << "#=====================================================\n";
707 std::cout << "# OmegaM " << OmegaM << "\n";
708 std::cout << "# HMCode? " << std::boolalpha << hmcode << "\n";
709 }
710
711 //=====================================================
712 // Spherical collapse evolution
713 //=====================================================
714 if(not hmcode){
715 if(verbose)
716 std::cout << "Performing spherical collapse and computing growth\n";
717 timer.StartTiming("SphericalCollapse");
718
720 spcmodel,
721 verbose,
724
734
735 timer.EndTiming("SphericalCollapse");
736 } else {
737 if(verbose)
738 std::cout << "Computing growth\n";
740 spcmodel,
743 }
744
745 }
746
747 //=====================================================
748 // Compute everything at a given redshift, i.e.
749 // fills all the splines that depend on redshift
750 // with the correct data
751 //=====================================================
752 void HaloModel::compute_at_redshift(double zcollapse){
753 xcollapse = std::log(1.0/(1.0 + zcollapse));
754
755 if(verbose){
756 std::cout << "\n#=====================================================\n";
757 std::cout << "# Compute at z = " << zcollapse << "\n";
758 std::cout << "#=====================================================\n";
759 }
760
761 //=====================================================
762 // Functions related to the variance of the smoothed
763 // density field: smoothing filter and P(k)
764 //=====================================================
765 const double pofk_scaling_factor = std::pow(growthfactor_of_x_spline(xcollapse) / growthfactor_of_x_spline(xinput_pofk), 2);
766 const Func1 logDeltaLin_of_logk = [&](double logk){
767 return logDelta_of_logk_spline(logk) + std::log(pofk_scaling_factor);
768 };
769
770 //=====================================================
771 // Density field variance when smoothed: sigma(logR)
772 //=====================================================
773 timer.StartTiming("sigma");
774 if(verbose){
775 std::cout << "Computing sigmas\n";
776 }
778 logDeltaLin_of_logk,
782 fiducial_logk_array.get());
783 timer.EndTiming("sigma");
784
785 //=====================================================
786 // Set OmegaM and sigma8 at current redshift
787 //=====================================================
788 sigma8 = std::exp(logsigma_of_logR_spline(std::log(8.0)));
789 sigmav = compute_sigmav(logDeltaLin_of_logk, fourier_window_function, 0.0);
790 sigmav100 = compute_sigmav(logDeltaLin_of_logk, fourier_window_function, 100.0);
791
792 //=====================================================
793 // Extract deltac and DeltaVir
794 // If HMCode we use their fits
795 //=====================================================
796 if(verbose){
797 std::cout << "Computing DeltaVir and deltac\n";
798 }
799 if(hmcode){
802 } else {
805 }
808
809 //=====================================================
810 // nu(R) relation and the non-linear scale nu(R)==1
811 //=====================================================
812 if(verbose){
813 std::cout << "Computing nu-R relation\n";
814 }
815 timer.StartTiming("nu");
817 deltac,
821 fiducial_logR_array.get());
822 timer.EndTiming("nu");
823
825 rnl_nu = neff_data.first;
826 neff = neff_data.second;
827
828 //=====================================================
829 // Set the HMCode parameters
830 //=====================================================
831 if(hmcode){
832 if(verbose)
833 std::cout << "# Applying HMCode fits\n";
834 cofM_model = "Bullock2001";
840 }
843
844 if(verbose) {
845 std::cout << "# f = " << hmcode_f << "\n";
846 std::cout << "# kstar = " << hmcode_kstar << "\n";
847 std::cout << "# eta = " << hmcode_eta << "\n";
848 std::cout << "# alpha = " << hmcode_alpha << "\n";
849 std::cout << "# cmin = " << hmcode_cmin << "\n";
850 std::cout << "# deltac = " << deltac << "\n";
851 std::cout << "# DeltaVir = " << DeltaVir << "\n";
852 }
853
854 //=====================================================
855 // The mass consentration relation as in Bullock 2001
856 // needed if we want this NFW c(M,z) relation
857 //=====================================================
858 if(verbose)
859 std::cout << "Computing formation redshifts\n";
864 deltac,
865 OmegaM,
866 xcollapse);
867
868 //=====================================================
869 // The halo density profile
870 // The dimensionless combination 4pi r^3 rho(r,M) / M
871 //=====================================================
872 const Func2 rho_function = [&](double r, double M){
873 return halo_density_profile(r, M, this);
874 };
875
876 //=====================================================
877 // Fourier transform of halo density profiles
878 //=====================================================
879 if(verbose){
880 std::cout << "Computing fourier transform of rho\n";
881 }
882 timer.StartTiming("rho");
884 rho_function,
886 DeltaVir,
887 OmegaM,
888 xcollapse,
890 fiducial_logk_array.get());
891 timer.EndTiming("rho");
892
893 //=====================================================
894 // Functions related to the mass-function
895 //=====================================================
896 const Func1 pdf_of_nu = [&](double nu){
897 return halo_multiplicity_function(nu, this);
898 };
899 const Func1 bias_of_nu = [&](double nu){
900 return halo_bias_function(nu, this);
901 };
902
903 //=====================================================
904 // Prediction for the mass-function
905 //=====================================================
906 if(verbose){
907 std::cout << "Computing massfunction\n";
908 }
909 timer.StartTiming("n");
915 pdf_of_nu,
916 OmegaM,
917 xcollapse);
918 timer.EndTiming("n");
919
920 //=====================================================
921 // Prediction for the power-spectrum
922 //=====================================================
923 if(verbose){
924 std::cout << "Computing halomodel pofk\n";
925 }
926 timer.StartTiming("Pofk");
933 logDeltaLin_of_logk,
934 pdf_of_nu,
935 bias_of_nu,
937 kmin_pofk,
938 kmax_pofk,
939 npts_pofk);
940 timer.EndTiming("Pofk");
941
942 //=====================================================
943 // Process these in case of modifications
944 //=====================================================
945 if(hmcode or hmcode_f != 0.0 or hmcode_kstar > 0.0 or hmcode_alpha != 1.0){
947 DVector logDeltaHM_onehalo_of_logk, logDeltaHM_twohalo_of_logk, logDeltaHM_full_of_logk;
948 if(verbose)
949 std::cout << "Adjusting haloterms: kstar = " << hmcode_kstar << " alpha = " << hmcode_alpha << " f = " << hmcode_f << "\n";
950 for(auto logk : logk_array){
951 const double k = std::exp(logk);
952 double Delta_onehalo = std::exp(logDeltaHM_onehalo_of_logk_spline(logk));
953 double Delta_twohalo = std::exp(logDeltaHM_twohalo_of_logk_spline(logk));
954 double Delta_full = std::exp(logDeltaHM_full_of_logk_spline(logk));
955 double Delta_lin = std::exp(logDeltaLin_of_logk(logk));
956
957 // In HMCode we just use the linear power-spectrum as the twohalo term
958 if(hmcode)
959 Delta_twohalo = Delta_lin;
960
961 // (BAO) damping of twohalo term
962 if(hmcode_f != 0.0){
963 Delta_twohalo *= std::max(1e-12,(1.0 - hmcode_f * std::pow( std::tanh(k * sigmav / std::sqrt(hmcode_f)), 2) ));
964 }
965
966 // Damping of onehalo term at low k
967 if(hmcode_kstar > 0.0){
968 double k_over_kstar = std::min(k/hmcode_kstar, 20.0);
969 double factor = k_over_kstar < 1e-5 ? k_over_kstar*k_over_kstar : 1.0 - std::exp(-k_over_kstar*k_over_kstar);
970 Delta_onehalo *= factor;
971 }
972
973 // Set a minimum value as we are going to spline the log of this shit
974 if(Delta_onehalo < 1e-30) Delta_onehalo = 1e-30;
975 if(Delta_twohalo < 1e-30) Delta_twohalo = 1e-30;
976 if(Delta_full< 1e-30) Delta_full = 1e-30;
977
978 // Combine two terms using an l_alpha norm
979 if(hmcode_alpha != 1.0)
980 Delta_full = std::pow(std::pow(Delta_onehalo, hmcode_alpha) + std::pow(Delta_twohalo, hmcode_alpha), 1.0/hmcode_alpha);
981 else
982 Delta_full = Delta_onehalo + Delta_twohalo;
983
984 logDeltaHM_onehalo_of_logk.push_back(std::log(Delta_onehalo));
985 logDeltaHM_twohalo_of_logk.push_back(std::log(Delta_twohalo));
986 logDeltaHM_full_of_logk.push_back(std::log(Delta_full));
987 }
988
989 // Remake splines
990 logDeltaHM_onehalo_of_logk_spline = Spline(logk_array, logDeltaHM_onehalo_of_logk, "logDelta1h(logk)");
991 logDeltaHM_twohalo_of_logk_spline = Spline(logk_array, logDeltaHM_twohalo_of_logk, "logDelta2h(logk)");
992 logDeltaHM_full_of_logk_spline = Spline(logk_array, logDeltaHM_full_of_logk, "logDelta(logk)");
993 }
994
995 }
996
997 //=====================================================
998 // c(M) relation for NFW halos with options of using
999 // Bullock 2001 or simple fit
1000 //=====================================================
1002 return [&](double M, HaloModel *hm){
1003 if(hm->cofM_model == "Bullock2001"){
1004 const double zf = hm->formationredshift_of_logM_spline(std::log(M));
1005 const double z = std::exp(-hm->xcollapse)-1;
1006 return hm->hmcode_cmin * std::max(1.0, (1.0+zf)/(1+z) );
1007 }
1008 // Simple c = c0/(1+z) * (M/M0)^(-beta) power-law model
1009 return hm->cofM_0 * std::pow(M / hm->cofM_M0, -hm->cofM_beta) * std::exp(hm->xcollapse);
1010 };
1011 }
1012
1013 //=====================================================
1014 // The density profile 4pi r^3 rho(r,M)/M for NFW halos
1015 // with option of applying the HMCode modifications
1016 //=====================================================
1018 return [&](double r, double M, HaloModel *hm){
1019 const double DeltaVir = hm->DeltaVir;
1020 const double OmegaM = hm->OmegaM;
1021 const double x = hm->xcollapse;
1022 const double c = hm->halo_mass_concentration_relation(M,hm);
1023 const double R = RofM(M, OmegaM, x);
1024 double Rvir = R / std::pow(DeltaVir,1.0/3.0);
1025
1026 // The modification Rvir *= nu^eta is for the halo bloating effect
1027 // Fiducial value is 0.0 which has no effect
1028 // This can be included *either* here or when doing the 1h 2h integrals
1029 // Rvir *= std::pow(std::exp(hm->lognu_of_logR_spline(std::log(R))), hm->hmcode_eta);
1030 // but not both. Currently we do this in the y-integral
1031
1032 const double rs = Rvir / c;
1033 if(r > Rvir) return 0.0;
1034 return std::pow(r/rs, 3) / ( (r/rs) * (1 + r/rs) * (1 + r/rs) ) / (std::log(1 + c) - c/(1 + c));
1035 };
1036 }
1037
1039 std::string filename,
1040 double zmin,
1041 double zmax,
1042 int npts_z) const {
1043
1044 const auto x_array = FML::MATH::linspace(std::log(1.0/(1.0+zmax)), std::log(1.0/(1.0+zmin)), npts_z);;
1045 std::ofstream fp(filename);
1046
1047 if(hmcode){
1048
1049 fp << "# z deltaC(z) DeltaVir(z) kstar(z) fdamp(z) eta(z) cmin(z) [HMCode]\n";
1050 for(const auto x : x_array){
1051 const double z = std::exp(-x)-1;
1052 fp << std::setw(10) << z << " ";
1053 fp << std::setw(10) << get_deltac_hmcode(x) << " ";
1054 fp << std::setw(10) << get_DeltaVir_hmcode(x) << " ";
1055 fp << std::setw(10) << get_kstar_hmcode(x) << " ";
1056 fp << std::setw(10) << get_f_hmcode(x) << " ";
1057 fp << std::setw(10) << get_eta_hmcode(x) << " ";
1058 fp << std::setw(10) << get_cmin_hmcode(x) << " ";
1059 fp << "\n";
1060
1061 }
1062
1063 } else {
1064
1065 fp << "# z deltaC(z) DeltaVir(z)\n";
1066 for(const auto x : x_array){
1067 const double z = std::exp(-x)-1;
1068 fp << std::setw(10) << z << " ";
1069 fp << std::setw(10) << deltac_of_x_spline(x) << " ";
1070 fp << std::setw(10) << DeltaVir_of_x_spline(x) << " ";
1071 fp << "\n";
1072 }
1073
1074 }
1075 }
1076
1077 //=====================================================
1078 // Output dndlogM over whole range computed
1079 //=====================================================
1081 std::string filename,
1082 double Mmin,
1083 double Mmax,
1084 int npts_M) const {
1085 const auto logM_array = FML::MATH::linspace(std::log(Mmin), std::log(Mmax), npts_M);;
1086 std::ofstream fp(filename);
1087 fp << "# M (Msun/h) dlogndlogM n (h/Mpc)^3 R (Mpc/h) Rvir (Mpc/h) nu [z = " << std::to_string(std::exp(-xcollapse)-1) << "]\n";
1088 for(const auto logM : logM_array){
1089 const double M = std::exp(logM);
1090 const double R = RofM(M, this->OmegaM, xcollapse);
1091 const double Rvir = RvirofM(M, DeltaVir, this->OmegaM, xcollapse);
1092 const double logR = std::log(R);
1093 const double lognu = lognu_of_logR_spline(logR);
1094 const double nu = std::exp(lognu);
1095 const double dlogndlogM = dndlogM_of_logM_spline(logM);
1096 const double n = n_of_logM_spline(logM);
1097 fp << std::setw(10) << M << " ";
1098 fp << std::setw(10) << dlogndlogM << " ";
1099 fp << std::setw(10) << n << " ";
1100 fp << std::setw(10) << R << " ";
1101 fp << std::setw(10) << Rvir << " ";
1102 fp << std::setw(10) << nu << " ";
1103 fp << "\n";
1104 }
1105 }
1106
1107 //=====================================================
1108 // Output P(k) over whole range computed
1109 //=====================================================
1111 std::string filename,
1112 double kmin,
1113 double kmax,
1114 int npts_k) const {
1115
1116#ifdef HMCODETESTING
1117 Spline logDeltaNL_of_logk_spline;
1118 read_pofk_file("pofk_nl_hmcode.txt",logDeltaNL_of_logk_spline);
1119#endif
1120
1121 //const auto logk_array = logDeltaHM_full_of_logk_spline.get_x_data();
1122 const auto logk_array = FML::MATH::linspace(std::log(kmin),std::log(kmax), npts_k);
1123 std::ofstream fp(filename);
1124 fp << "# k (h/Mpc) P_NL(k) P_Lin(k) P_1h(k) P_2h(k) (Mpc/h)^3 [z = " << std::to_string(std::exp(-xcollapse)-1) << "]\n";
1125 for(const auto logk : logk_array){
1126 const double k = std::exp(logk);
1127 const double Delta_over_P = 2.0 * M_PI * M_PI / (k*k*k);
1128 const double scaling = std::pow(growthfactor_of_x_spline(xcollapse) / growthfactor_of_x_spline(xinput_pofk), 2);
1129 fp << std::setw(10) << k << " ";
1130 fp << std::setw(10) << Delta_over_P * std::exp(logDeltaHM_full_of_logk_spline(logk)) << " ";
1131 fp << std::setw(10) << Delta_over_P * std::exp(logDelta_of_logk_spline(logk)) * scaling << " ";
1132 fp << std::setw(10) << Delta_over_P * std::exp(logDeltaHM_onehalo_of_logk_spline(logk)) << " ";
1133 fp << std::setw(10) << Delta_over_P * std::exp(logDeltaHM_twohalo_of_logk_spline(logk)) << " ";
1134#ifdef HMCODETESTING
1135 fp << std::exp(logDeltaHM_full_of_logk_spline(logk))/std::exp(logDeltaNL_of_logk_spline(logk)) << " ";
1136#endif
1137 fp << "\n";
1138 }
1139 }
1140
1141 //=====================================================
1142 // Show some info about what we have computed
1143 //=====================================================
1144 void HaloModel::info() const {
1145 const bool extraverbose = true;
1146
1147 std::cout << "\n#=====================================================\n";
1148 std::cout << "# Halomodel info ( z = " << (isnan(xcollapse) ? " not yet set " : std::to_string(std::exp(-xcollapse)-1.0)) << " )\n";
1149 std::cout << "#=====================================================\n";
1150 std::cout << "# OmegaM : " << OmegaM << "\n";
1151 std::cout << "# fnu : " << fnu << "\n";
1152 std::cout << "# DeltaVirModifier : " << DeltaVir_multiplier << "\n";
1153 std::cout << "# cofMModifier : " << cofM_multiplier << "\n";
1154 std::cout << "# deltacModifier : " << deltac_multiplier << "\n";
1155 std::cout << "# Massfunction : " << halo_massfunction << "\n";
1156 if(halo_massfunction == "ShethTormen1999")
1157 std::cout << "# with a : " << a_ST << " p : " << p_ST << "\n";
1158 std::cout << "# Density profile : " << halo_profile << "\n";
1159 if(halo_profile == "NFW")
1160 std::cout << "# with c(M) : " << cofM_model << "\n";
1161 if(hmcode)
1162 std::cout << "# Running with HMCode settings\n";
1163
1164 if(isnan(xcollapse)){
1165 // Compute sigma8 to be able to output it for debug purposes
1166 const Func1 logDeltaLin_of_logk = [&](double logk){
1167 return logDelta_of_logk_spline(logk);
1168 };
1169 Spline _logsigma_of_logR_spline;
1171 logDeltaLin_of_logk,
1173 _logsigma_of_logR_spline,
1174 fiducial_logR_array.get(),
1175 fiducial_logk_array.get());
1176 double sigma8ic = std::exp(_logsigma_of_logR_spline(std::log(8.0)));
1177 std::cout << "# sigma8 of provided Plin at z = " << std::exp(-xinput_pofk)-1 << " is " << sigma8ic << "\n";
1178 std::cout << "# NB: compute_at_redshift has not yet been run so not much more computed\n";
1179 return;
1180 }
1181
1182 std::cout << "# Current z : " << std::exp(-xcollapse)-1.0 << "\n";
1183 std::cout << "# deltaC : " << deltac << "\n";
1184 std::cout << "# DeltaVir : " << DeltaVir << "\n";
1185
1187 std::cout << "# znl : " << std::exp(-xnl_of_x_spline(xcollapse))-1.0 << "\n";
1188 std::cout << "# zturnaround : " << std::exp(-xta_of_x_spline(xcollapse))-1.0 << "\n";
1189 std::cout << "# zvir : " << std::exp(-xvir_of_x_spline(xcollapse))-1.0 << "\n";
1190 }
1191
1193 std::cout << "# sigma8 : " << std::exp(logsigma_of_logR_spline(std::log(8.0))) << "\n";
1194 std::cout << "# sigmav : " << sigmav << " (Mpc/h)\n";
1195 std::cout << "# sigmav100 : " << sigmav100 << " (Mpc/h)\n";
1196 std::cout << "# rnl_nu : " << rnl_nu << " (Mpc/h)\n";
1197 std::cout << "# knl_nu : " << 1.0/rnl_nu << " (h/Mpc)\n";
1198 std::cout << "# neff : " << neff << "\n";
1199
1200 if(extraverbose){
1201 spcmodel.info();
1203 }
1204 }
1205
1206 //=====================================================
1207 // HMCode fits
1208 //=====================================================
1209 double HaloModel::get_deltac_hmcode(double x) const{
1210 double Dofx_over_Dofx_sigma = growthfactor_of_x_spline(x)/growthfactor_of_x_spline(xcollapse);
1211 double sigma8ofx = sigma8 * Dofx_over_Dofx_sigma;
1212 double OmegaMofx = spcmodel.OmegaMofx(x);
1213 double deltacofx = 1.59 + 0.0314*std::log(sigma8ofx);
1214 deltacofx *= 1.0 + 0.0123*std::log10(OmegaMofx);
1215 deltacofx *= (1.+0.262*fnu);
1216 return deltacofx;
1217 }
1218
1219 double HaloModel::get_DeltaVir_hmcode(double x) const{
1220 double DeltaVirofx = 418.0 * std::pow(spcmodel.OmegaMofx(x),-0.352);
1221 DeltaVirofx *= (1.+0.916*fnu);
1222 return DeltaVirofx;
1223 }
1224
1225 double HaloModel::get_eta_hmcode(double x) const{
1226 double Dofx_over_Dofx_sigma = growthfactor_of_x_spline(x)/growthfactor_of_x_spline(xcollapse);
1227 double sigma8ofx = sigma8 * Dofx_over_Dofx_sigma;
1228 double etaofx = 0.603-0.3*sigma8ofx;
1229 return etaofx;
1230 }
1231
1232 double HaloModel::get_f_hmcode(double x) const{
1233 double Dofx_over_Dofx_sigma = growthfactor_of_x_spline(x)/growthfactor_of_x_spline(xcollapse);
1234 double sigmav100ofx = sigmav100 * Dofx_over_Dofx_sigma;
1235 double fofx = std::max(std::min(0.0095*std::pow(sigmav100ofx, 1.37), 0.99), 1e-3);
1236 return fofx;
1237 }
1238
1239 double HaloModel::get_kstar_hmcode(double x) const{
1240 double Dofx_over_Dofx_sigma = growthfactor_of_x_spline(x)/growthfactor_of_x_spline(xcollapse);
1241 double sigmavofx = sigmav * Dofx_over_Dofx_sigma;
1242 double kstarofx = 0.584/sigmavofx;
1243 return kstarofx;
1244 }
1245
1246 double HaloModel::get_cmin_hmcode([[maybe_unused]] double x) const{
1247 return 3.13;
1248 }
1249
1251 // NB: this is only at the current redshift
1252 return 3.24*std::pow(1.85,neff);
1253 }
1254
1255 }
1256 }
1257}
const std::string filename
Definition: Main.cpp:63
const double OmegaM
Definition: Main.cpp:65
Class for computing the standard halomodel predictions for plus or just doing spherical collapse.
Definition: Halomodel.h:62
HaloBiasFunction halo_bias_function
Definition: Halomodel.h:96
void output_nofM(std::string filename, double Mmin=1e8, double Mmax=1e16, int npts_M=100) const
Definition: Halomodel.cpp:1080
double get_f_hmcode(double x) const
Definition: Halomodel.cpp:1232
void compute_at_redshift(double zcollapse)
Definition: Halomodel.cpp:752
double get_DeltaVir_hmcode(double x) const
Definition: Halomodel.cpp:1219
std::shared_ptr< DVector > fiducial_logR_array
Definition: Halomodel.h:146
double get_cmin_hmcode(double x) const
Definition: Halomodel.cpp:1246
HaloMultiplicityFunction halo_multiplicity_function
Definition: Halomodel.h:95
void output_deltac(std::string filename, double zmin=0.0, double zmax=10.0, int npts_z=100) const
Definition: Halomodel.cpp:1038
double get_deltac_hmcode(double x) const
Definition: Halomodel.cpp:1209
std::shared_ptr< DVector > fiducial_logk_array
Definition: Halomodel.h:147
void output_pofk(std::string filename, double kmin=1e-5, double kmax=100, int npts_k=1000) const
Definition: Halomodel.cpp:1110
SphericalCollapseModel spcmodel
Definition: Halomodel.h:65
double get_kstar_hmcode(double x) const
Definition: Halomodel.cpp:1239
double get_eta_hmcode(double x) const
Definition: Halomodel.cpp:1225
Class for doing general spherical collapse calculations, i.e.
void run_at_all_redshifts(Spline &deltac_of_x_spline, Spline &DeltaVir_of_x_spline, Spline &xta_of_x_spline, Spline &xnl_of_x_spline, Spline &xvir_of_x_spline, Spline &delta_ini_of_x_spline, Spline &growthfactor_of_x_spline, Spline &growthrate_of_x_spline)
Perform the spherical collapse calculation for a given model with collapse at for several values of ...
The class contains all the info about the model needed to run the spherical collapse and halomodel Co...
This is a wrapper class for easy use of GSL splines It is (OpenMP) thread safe as long as splines are...
Definition: Spline.h:80
double deriv_x(double x) const
Get the value of the first derivative of the spline.
Definition: Spline.cpp:275
DVector get_x_data()
Get the raw GSL data for x used to create the spline.
Definition: Spline.h:165
std::pair< double, double > get_xrange() const
Get the range the spline was created on.
Definition: Spline.cpp:277
void StartTiming(const char *name)
Start timing.
Definition: Timings.h:63
void PrintAllTimings() const
Output all the recorded timings.
Definition: Timings.h:41
double EndTiming(const char *name, bool print=false)
End timing.
Definition: Timings.h:83
FML::INTERPOLATION::SPLINE::Spline2D Spline2D
Definition: Halomodel.h:30
std::function< double(double)> WindowFunction
Definition: Halomodel.h:41
double RofM(double M, double OmegaM, double x)
Definition: Halomodel.cpp:216
void compute_lognu_of_logR(const double deltac, const Spline &logsigma_of_logR_spline, Spline &lognu_of_logR_spline, Spline &logR_of_lognu_spline, const DVector *fiducial_logR_array)
Definition: Halomodel.cpp:376
std::function< double(double, HaloModel *hm)> HaloMultiplicityFunction
Definition: Halomodel.h:39
void compute_sigma(const Func1 logDelta_of_logk, const WindowFunction window_of_kR, Spline &logsigma_of_logR_spline, const DVector *fiducial_logR_array, const DVector *fiducial_logk_array)
Definition: Halomodel.cpp:149
void powerlaw_extend_logY_of_logx_spline(Spline &logY_of_logx_spline, double xmin_new, double xmax_new, int npts_new, std::string label="logY(log(x)) extrapolated")
Definition: Halomodel.cpp:22
double compute_sigmav(const Func1 logDelta_of_logk, const WindowFunction window_of_kR, double R, const DVector *fiducial_logk_array)
Definition: Halomodel.cpp:121
FML::SOLVERS::ODESOLVER::DVector DVector
Definition: Halomodel.h:24
std::function< double(double, HaloModel *hm)> HaloBiasFunction
Definition: Halomodel.h:40
std::pair< double, double > compute_neff(const Spline &logsigma_of_logR_spline, const Spline &lognu_of_logR_spline)
Definition: Halomodel.cpp:101
void compute_one_and_two_halo_terms(const Spline &logR_of_lognu_spline, const Spline2D &y_of_logR_and_logk_spline, Spline &logDelta_onehalo_of_logk_spline, Spline &logDelta_twohalo_of_logk_spline, Spline &logDelta_full_of_logk_spline, const Func1 &logDeltaLin_of_logk, const Func1 &pdf_of_nu, const Func1 &bias_of_nu, const double eta_hmcode, const double kmin, const double kmax, const int npts_k)
Definition: Halomodel.cpp:458
cofMFunction get_nfw_halo_mass_concentration_relation()
Definition: Halomodel.cpp:1001
void compute_formation_redshift_factor(const Spline &growthfactor_of_x_spline, const Spline &logsigma_of_logR_spline, Spline &formationredshift_of_logM_spline, double deltac, double OmegaM, double xcollapse, double massfraction)
Definition: Halomodel.cpp:580
DVector compute_rho_fourier_single(const Func2 &rho_function, const DVector &k_array, const double M, const double Rvir)
Definition: Halomodel.cpp:257
HaloBiasFunction get_sheth_tormen_halo_bias_function()
Definition: Halomodel.cpp:665
std::function< double(double, double, HaloModel *hm)> RhoFunction
Definition: Halomodel.h:37
FML::INTERPOLATION::SPLINE::Spline Spline
Definition: Halomodel.h:29
double MofRvir(double Rvir, double DeltaVir, double OmegaM, double x)
Definition: Halomodel.cpp:230
WindowFunction get_tophat_window_fourier()
Definition: Halomodel.cpp:677
double RvirofM(double M, double DeltaVir, double OmegaM, double x)
Definition: Halomodel.cpp:205
RhoFunction get_nfw_halo_density_profile()
Definition: Halomodel.cpp:1017
std::function< double(double, HaloModel *hm)> cofMFunction
Definition: Halomodel.h:38
HaloMultiplicityFunction get_sheth_tormen_halo_multiplicity_function()
Definition: Halomodel.cpp:657
void compute_rho_fourier(const Func2 &rho_function, Spline2D &y_of_logR_and_logk_spline, const double DeltaVir, const double OmegaM, const double x, const DVector *fiducial_logR_array, const DVector *fiducial_logk_array)
Definition: Halomodel.cpp:325
void compute_massfunction(const Spline &logR_of_lognu_spline, const Spline &lognu_of_logR_spline, Spline &dndlogM_of_logM_spline, Spline &n_of_logM_spline, const Func1 &pdf_of_nu, const double OmegaM, const double x)
Definition: Halomodel.cpp:408
void read_pofk_file(const std::string filename_pofk, Spline &logDelta_of_logk_spline, double normalization, int col_k, int col_pofk)
Definition: Halomodel.cpp:61
FML::SOLVERS::ODESOLVER::DVector2D DVector2D
Definition: Halomodel.h:25
std::function< double(double, double)> Func2
Definition: Halomodel.h:32
double MofR(double R, double OmegaM, double x)
Definition: Halomodel.cpp:241
std::function< double(double)> Func1
Definition: Halomodel.h:31
void compute_growthfactor(const SphericalCollapseModel &model, Spline &growthfactor_of_x_spline, Spline &growthrate_of_x_spline, const double xini, const double xend, const int npts)
Computes the growth factor (not normalized) and growth rate for a given model and returns splines wit...
DVector2D loadtxt(std::string filename, int nreserve_rows, int nreserve_cols)
Similar to pythons loadtxt function Gives warning if file is not regular Skips lines starting with #,...
Definition: FileUtils.cpp:189
DVector linspace(double xmin, double xmax, int num)
Python linspace. Generate a lineary spaced array.
Definition: Math.cpp:269
double find_root_bisection(const std::function< double(double)> &function, std::pair< double, double > xrange, double epsilon)
Find roots using bisection.
Definition: Math.cpp:51
Definition: CAMBReader.h:10
return y
Definition: Global.h:265
const double exp
Definition: Global.h:259
dndlogM
Definition: example.py:66
deltac
Definition: example.py:67
bool verbose
Definition: example.py:19
float z
Definition: example.py:56
bool hmcode
Definition: example.py:18
data
Definition: test.py:10
x
Definition: test.py:18