CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ModelFunction_NumberCounts1D_Mass.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 std::vector<double> cbl::modelling::numbercounts::mass_function_mass (const std::vector<double> mass, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
46 {
47  // structure contaning the required input data
48  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
49 
50  // redefine the cosmology
51  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
52 
53  // input likelihood parameters
54 
55  // set the cosmological parameters used to compute the dark matter
56  // two-point correlation function in real space
57  for (size_t i=0; i<pp->Cpar.size(); ++i)
58  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
59 
60  // compute the power spectrum
61  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);
62 
63  return cbl::modelling::numbercounts::mass_function (mass, cosmo, pp->redshift, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, pp->kk, Pk, "Spline", pp->k_max);
64 }
65 
66 
67 // ===========================================================================================
68 
69 
70 std::vector<double> cbl::modelling::numbercounts::number_density_mass (const std::vector<double> mass, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
71 {
72  // structure contaning the required input data
73  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
74 
75  // redefine the cosmology
76  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
77 
78  // input likelihood parameters
79 
80  // set the cosmological parameters used to compute the dark matter
81  // two-point correlation function in real space
82  for (size_t i=0; i<pp->Cpar.size(); ++i)
83  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
84 
85  // compute the power spectrum
86  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);
87 
88  std::vector<double> mass_function = cbl::modelling::numbercounts::mass_function (pp->Mass_vector, cosmo, pp->redshift, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, pp->kk, Pk, "Spline", pp->k_max);
89 
90  glob::FuncGrid interp_MF (pp->Mass_vector, mass_function, "Spline");
91 
92  std::vector<double> number_density(mass.size());
93 
94  for (size_t i=0; i<mass.size(); i++)
95  number_density[i] = interp_MF.integrate_qag(pp->edges_x[i], pp->edges_x[i+1]);
96 
97  return number_density;
98 }
99 
100 
101 // ===========================================================================================
102 
103 
104 std::vector<double> cbl::modelling::numbercounts::number_counts_mass (const std::vector<double> mass, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
105 {
106  (void)mass;
107 
108  // structure contaning the required input data
109  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
110 
111  // redefine the cosmology
112  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
113 
114  // input likelihood parameters
115 
116  // set the cosmological parameters used to compute the dark matter
117  // two-point correlation function in real space
118  for (size_t i=0; i<pp->Cpar.size(); ++i)
119  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
120 
121  // compute the power spectrum
122  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);
123 
124  const std::vector<cbl::glob::FuncGrid> interp = cbl::modelling::numbercounts::sigmaM_dlnsigmaM (pp->Mass_vector, cosmo, pp->kk, Pk, "Spline", pp->k_max);
125 
126  std::vector<double> number_counts(pp->edges_x.size()-1);
127 
128  for (size_t j=0; j<pp->edges_x.size()-1; j++) {
129  number_counts[j] = cbl::modelling::numbercounts::number_counts(pp->z_min, pp->z_max, pp->edges_x[j], pp->edges_x[j+1], cosmo, pp->area_rad, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, interp[0], interp[1]);
130  }
131 
132  return number_counts;
133 }
134 
135 
136 // ===========================================================================================
137 
138 
139 std::vector<double> cbl::modelling::numbercounts::number_counts_mass_snapshot (const std::vector<double> mass, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
140 {
141  (void)mass;
142 
143  // structure contaning the required input data
144  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
145 
146  // redefine the cosmology
147  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
148 
149  // input likelihood parameters
150 
151  // set the cosmological parameters used to compute the dark matter
152  // two-point correlation function in real space
153  for (size_t i=0; i<pp->Cpar.size(); ++i)
154  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
155 
156  // compute the power spectrum
157  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);
158 
159  std::vector<double> mass_function = cbl::modelling::numbercounts::mass_function (pp->Mass_vector, cosmo, pp->redshift, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, pp->kk, Pk, "Spline", pp->k_max);
160 
161  glob::FuncGrid interp_MF (pp->Mass_vector, mass_function, "Spline");
162 
163  std::vector<double> number_counts(pp->edges_x.size()-1);
164 
165  for (size_t i=0; i<pp->edges_x.size()-1; i++) {
166  number_counts[i] = pp->Volume*interp_MF.integrate_qag(pp->edges_x[i], pp->edges_x[i+1]); //*(maxM-minM);
167  }
168 
169  return number_counts;
170 }
171 
Global functions to model number counts.
The class Cosmology.
Definition: Cosmology.h:277
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 FuncGrid.
Definition: FuncGrid.h:55
double integrate_qag(const double a, const double b, const double rel_err=1.e-2, const double abs_err=1.e-6, const int limit_size=1000, const int rule=6)
compute the definite integral with GSL qag method
Definition: FuncGrid.cpp:187
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< double > mass_function_mass(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
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
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< double > number_density_mass(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
std::vector< double > number_counts_mass_snapshot(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 for a simulation snapshot
std::vector< double > number_counts_mass(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
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38