CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ModelFunction_NumberCounts1D_Redshift.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<double> cbl::modelling::numbercounts::number_density_redshift (const std::vector<double> redshift, 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, true);
63 
64  std::vector<std::vector<double>> mass_function = cbl::modelling::numbercounts::mass_function(redshift, pp->Mass_vector, cosmo, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, pp->kk, Pk, "Spline", pp->k_max);
65 
66  std::vector<double> number_density(redshift.size());
67 
68  for (size_t i=0; i<redshift.size(); i++) {
69  glob::FuncGrid interpMF(pp->Mass_vector, mass_function[i], "Spline");
70  number_density[i] = interpMF.integrate_qag(pp->Mass_min, pp->Mass_max);
71  }
72 
73  return number_density;
74 }
75 
76 
77 // ===========================================================================================
78 
79 
80 std::vector<double> cbl::modelling::numbercounts::number_counts_redshift (const std::vector<double> redshift, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
81 {
82  // structure contaning the required input data
83  shared_ptr<STR_NC_data_model> pp = static_pointer_cast<STR_NC_data_model>(inputs);
84 
85  // redefine the cosmology
86  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
87 
88  // input likelihood parameters
89 
90  // set the cosmological parameters used to compute the dark matter
91  // two-point correlation function in real space
92  for (size_t i=0; i<pp->Cpar.size(); ++i) {
93  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
94  }
95 
96  // compute the power spectrum
97  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);
98 
99  std::vector<std::vector<double>> mass_function = cbl::modelling::numbercounts::mass_function (redshift, pp->Mass_vector, cosmo, pp->model_MF, pp->store_output, pp->Delta, pp->isDelta_critical, pp->kk, Pk, "Spline", pp->k_max);
100 
101  std::vector<double> number_counts(redshift.size());
102 
103  for (size_t i=0; i<redshift.size(); i++) {
104  glob::FuncGrid interpMF(pp->Mass_vector, mass_function[i], "Spline");
105  number_counts[i] = pp->area_rad*interpMF.integrate_qag(pp->Mass_min, pp->Mass_max)*cosmo.dV_dZdOmega(redshift[i], true)*(pp->edges_x[i+1]-pp->edges_x[i]);
106  }
107 
108  return number_counts;
109 }
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
double dV_dZdOmega(const double redshift, const bool angle_rad) const
the derivative of the comoving volume, d2V/(dz*dΩ) at a given redshift
Definition: Cosmology.cpp:1236
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
std::vector< double > number_counts_redshift(const std::vector< double > redshift, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
compute the number counts as a function of 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< double > number_density_redshift(const std::vector< double > redshift, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
compute the number density as a function of the 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
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38