CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ModelFunction_NumberCounts2D_RedshiftMass.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 
37 
38 using namespace std;
39 
40 using namespace cbl;
41 
42 
43 // ===========================================================================================
44 
45 
46 std::vector<std::vector<double>> cbl::modelling::numbercounts::mass_function_redshift_mass (const std::vector<double> redshift, const std::vector<double> mass, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
47 {
48  // structure contaning the required input data
49  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
50 
51  // redefine the cosmology
52  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
53 
54  // input likelihood parameters
55 
56  // set the cosmological parameters used to compute the dark matter
57  // two-point correlation function in real space
58  for (size_t i=0; i<pp->Cpar.size(); ++i)
59  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
60 
61  // compute the power spectrum
62  std::vector<double> Pk = cosmo.Pk_matter(pp->kk, pp->method_Pk, false, 0., pp->store_output, pp->output_root, pp->norm, pp->k_min, pp->k_max, pp->prec, pp->file_par);
63 
64  return cbl::modelling::numbercounts::mass_function(redshift, mass, cosmo, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, pp->kk, Pk, "Spline", pp->k_max);
65 }
66 
67 
68 // ===========================================================================================
69 
70 
71 std::vector<std::vector<double>> cbl::modelling::numbercounts::number_density_redshift_mass (const std::vector<double> redshift, const std::vector<double> mass, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
72 {
73  (void)redshift; (void)mass;
74 
75  // structure contaning the required input data
76  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
77 
78  // redefine the cosmology
79  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
80 
81  // input likelihood parameters
82 
83  // set the cosmological parameters used to compute the dark matter
84  // two-point correlation function in real space
85  for (size_t i=0; i<pp->Cpar.size(); ++i)
86  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
87 
88  // compute the power spectrum
89  std::vector<double> Pk = cosmo.Pk_matter(pp->kk, pp->method_Pk, false, 0., pp->store_output, pp->output_root, pp->norm, pp->k_min, pp->k_max, pp->prec, pp->file_par);
90 
91  std::vector<std::vector<double>> mass_function = cbl::modelling::numbercounts::mass_function (pp->z_vector, pp->Mass_vector, cosmo, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, pp->kk, Pk, "Spline", pp->k_max);
92 
93  glob::FuncGrid2D interp_MF (pp->z_vector, pp->Mass_vector, mass_function, "Linear");
94 
95  std::vector<std::vector<double>> number_density(pp->edges_x.size()-1, std::vector<double>(pp->edges_y.size()-1));
96  for (size_t i=0; i<pp->edges_x.size()-1; i++) {
97  for (size_t j=0; j<pp->edges_y.size()-1; j++) {
98  number_density[i][j] = interp_MF.IntegrateVegas(pp->edges_x[i], pp->edges_x[i+1], pp->edges_y[j], pp->edges_y[j+1]);
99  }
100  }
101 
102  return number_density;
103 }
104 
105 
106 // ===========================================================================================
107 
108 
109 std::vector<std::vector<double>> cbl::modelling::numbercounts::number_counts_redshift_mass (const std::vector<double> redshift, const std::vector<double> mass, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
110 {
111  (void)redshift; (void)mass;
112 
113  // structure contaning the required input data
114  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
115 
116  // redefine the cosmology
117  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
118 
119  // input likelihood parameters
120 
121  // set the cosmological parameters used to compute the dark matter
122  // two-point correlation function in real space
123  const size_t npar = (pp->is_sigma8_free) ? pp->Cpar.size() : pp->Cpar.size()-1;
124  for (size_t i=0; i<npar; ++i)
125  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
126 
127  // Moved below for convenience...
128  //if (!pp->is_sigma8_free) parameter[pp->Cpar.size()-1] = cosmo.sigma8();
129 
130  // compute the power spectrum
131  const std::vector<double> Pk = cosmo.Pk_matter(pp->kk, pp->method_Pk, false, 0., pp->store_output, pp->output_root, pp->norm, pp->k_min, pp->k_max, pp->prec, pp->file_par, true);
132 
133  const std::vector<cbl::glob::FuncGrid> interp = cbl::modelling::numbercounts::sigmaM_dlnsigmaM(pp->Mass_vector, cosmo, pp->kk, Pk, "Spline", pp->k_max);
134 
135  // SigmaM has been computed in the previous line, just take sigma8 from it -> M8 = Mass(8., cosmo.rho_m()), probably...
136  if (!pp->is_sigma8_free) parameter[pp->Cpar.size()-1] = interp[0](Mass(8., cosmo.rho_m()));
137 
138  std::vector<std::vector<double>> number_counts(pp->edges_x.size()-1, std::vector<double>(pp->edges_y.size()-1));
139  for (size_t i=0; i<pp->edges_x.size()-1; i++) {
140  for (size_t j=0; j<pp->edges_y.size()-1; j++) {
141  number_counts[i][j] = cbl::modelling::numbercounts::number_counts(pp->edges_x[i], pp->edges_x[i+1], pp->edges_y[j], pp->edges_y[j+1], cosmo, pp->area_rad, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, interp[0], interp[1]);
142  }
143  }
144 
145  return number_counts;
146 }
Global functions to model number counts.
The class Cosmology.
Definition: Cosmology.h:277
double rho_m(const double redshift=0., const bool unit1=false, const bool nu=false) const
the mean cosmic background density
Definition: Cosmology.cpp:1274
void set_parameter(const CosmologicalParameter parameter, const double value)
set the value of one cosmological paramter
Definition: Cosmology.cpp:424
std::vector< double > Pk_matter(const std::vector< double > kk, const std::string method_Pk, const bool NL, const double redshift, const bool store_output=true, const std::string output_root="test", const int norm=-1, const double k_min=0.001, const double k_max=100., const double prec=1.e-2, const std::string file_par=par::defaultString, const bool unit1=false)
the dark matter power spectrum
Definition: PkXi.cpp:1331
The class FuncGrid2D.
Definition: FuncGrid.h:302
double IntegrateVegas(const double xmin, const double xmax, const double ymin, const double ymax) const
evaluate the 2D integral of the interpolated function using the Vegas routine from CUBA libraries
Definition: FuncGrid.cpp:355
void sigmaM_dlnsigmaM(double &sigmaM, double &dlnsigmaM, const double mass, const cbl::glob::FuncGrid interp_Pk, const double kmax, const double rho)
compute
std::vector< std::vector< double > > mass_function_redshift_mass(const std::vector< double > redshift, const std::vector< double > mass, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
compute the mass function as a function of the mass and redshift
double mass_function(const double mass, cosmology::Cosmology cosmology, const double redshift, const std::string model_MF, const bool store_output, const double Delta, const bool isDelta_critical, const cbl::glob::FuncGrid interp_Pk, const double kmax)
compute the mass function
std::vector< std::vector< double > > number_counts_redshift_mass(const std::vector< double > redshift, const std::vector< double > mass, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
compute the number counts as a function of the mass and redshift
double number_counts(const double redshift_min, const double redshift_max, const double Mass_min, const double Mass_max, cosmology::Cosmology cosmology, const double Area, const std::string model_MF, const bool store_output, const double Delta, const bool isDelta_critical, const glob::FuncGrid interp_sigmaM, const glob::FuncGrid interp_DlnsigmaM)
compute the number counts as function of mass and redshift
std::vector< std::vector< double > > number_density_redshift_mass(const std::vector< double > redshift, const std::vector< double > mass, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
compute the number density as a function of the mass and redshift
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
T Mass(const T RR, const T Rho)
the mass of a sphere of a given radius and density
Definition: Func.h:1243