CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ModelFunction_Cosmology.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 
36 
37 using namespace std;
38 
39 using namespace cbl;
40 
41 
42 // ============================================================================================
43 
44 
45 double cbl::modelling::cosmo::cosmological_measurements (const double redshift, const std::string data_type, const cbl::cosmology::Cosmology cosmology)
46 {
47  if (data_type=="DV")
48  return cosmology.D_V(redshift);
49 
50  else if (data_type=="DV/rs")
51  return cosmology.D_V(redshift)/cosmology.rs();
52 
53  else if (data_type=="rs/DV")
54  return cosmology.rs()/cosmology.D_V(redshift);
55 
56  else if(data_type=="DA")
57  return cosmology.D_A(redshift);
58 
59  else if (data_type=="DA/rs")
60  return cosmology.D_A(redshift)/cosmology.rs();
61 
62  else if (data_type=="rs/DA")
63  return cosmology.rs()/cosmology.D_A(redshift);
64 
65  else if(data_type=="DM")
66  return cosmology.D_M(redshift);
67 
68  else if (data_type=="DM/rs")
69  return cosmology.D_M(redshift)/cosmology.rs();
70 
71  else if (data_type=="rs/DM")
72  return cosmology.rs()/cosmology.D_M(redshift);
73 
74  else if(data_type=="HH")
75  return cosmology.HH(redshift);
76 
77  else if (data_type=="HH*rs")
78  return cosmology.HH(redshift)*cosmology.rs();
79 
80  else if(data_type=="DH")
81  return cbl::par::cc/cosmology.HH(redshift);
82 
83  else if (data_type=="DH/rs")
84  return cbl::par::cc/cosmology.HH(redshift)/cosmology.rs();
85 
86  else if (data_type=="rs/DH")
87  return cosmology.rs()/(cbl::par::cc/cosmology.HH(redshift));
88 
89  else if (data_type=="DL")
90  return cosmology.D_L(redshift);
91 
92  else
93  ErrorCBL("the input data_type is not allowed!", "cosmological_measurements", "ModelFunction_Cosmology.cpp");
94 
95  return 0;
96 }
97 
98 
99 // ============================================================================================
100 
101 
102 std::vector<double> cbl::modelling::cosmo::cosmological_measurements_model (const std::vector<double> redshift, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
103 {
104  // structure contaning the required input data
105  shared_ptr<STR_data_model_cosmology> pp = static_pointer_cast<STR_data_model_cosmology>(inputs);
106 
107  // redefine the cosmology
108  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
109 
110  // input likelihood parameters
111 
112  // set the cosmological parameters used to compute the dark matter
113  // two-point correlation function in real space
114  for (size_t i=0; i<pp->Cpar.size(); ++i)
115  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
116 
117  vector<double> output;
118 
119  for(size_t i=0; i<redshift.size(); i++)
120  output.push_back(cbl::modelling::cosmo::cosmological_measurements(redshift[i], pp->data_type[i], cosmo));
121 
122  return output;
123 }
124 
125 
126 // ============================================================================================
127 
128 
129 std::vector<double> cbl::modelling::cosmo::cosmological_measurements_model_CMB_DistancePrior (const std::vector<double> redshift, const std::shared_ptr<void> inputs, std::vector<double> &parameter)
130 {
131  // structure contaning the required input data
132  shared_ptr<STR_data_model_cosmology> pp = static_pointer_cast<STR_data_model_cosmology>(inputs);
133 
134  // redefine the cosmology
135  cbl::cosmology::Cosmology cosmo = *pp->cosmology;
136 
137  // input likelihood parameters
138 
139  // set the cosmological parameters used to compute the dark matter
140  // two-point correlation function in real space
141  for (size_t i=0; i<pp->Cpar.size(); ++i)
142  cosmo.set_parameter(pp->Cpar[i], parameter[i]);
143 
144  vector<double> output;
145 
146  for(size_t i=0; i<redshift.size()-pp->distance_prior->dataset()->ndata(); i++)
147  output.push_back(cbl::modelling::cosmo::cosmological_measurements(redshift[i], pp->data_type[i], cosmo));
148 
149  vector<double> mm = pp->distance_prior->model(cosmo);
150  for(size_t i=0; i<mm.size(); i++)
151  output.push_back(mm[i]);
152 
153  return output;
154 }
Global functions to model two-point correlation functions of any type.
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 D_V(const double redshift) const
the average distance at a given redshift, used to rescale the correlation function
Definition: Cosmology.cpp:884
double HH(const double redshift=0.) const
the Hubble function
Definition: Cosmology.cpp:570
double rs() const
get the sound horizon at recombination
Definition: Cosmology.h:1289
double D_A(const double redshift) const
the angular diameter distance at a given redshift
Definition: Cosmology.cpp:848
double D_L(const double redshift) const
the luminosity distance at a given redshift
Definition: Cosmology.cpp:875
double D_M(const double redshift) const
the comoving transverse distance at a given redshift
Definition: Cosmology.cpp:832
static const double cc
: the speed of light in vacuum (the value is exact) [km/sec]
Definition: Constants.h:221
std::vector< double > cosmological_measurements_model(const std::vector< double > redshift, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
model for the generic cosmological measurements
std::vector< double > cosmological_measurements_model_CMB_DistancePrior(const std::vector< double > redshift, const std::shared_ptr< void > inputs, std::vector< double > &parameter)
model for the generic cosmological measurements plus distance prior from CMB experiments
double cosmological_measurements(const double redshift, const std::string data_type, const cbl::cosmology::Cosmology cosmology)
generic cosmological measurements
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
Definition: Kernel.h:780