CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
Modelling_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 
37 #include "Modelling_Cosmology.h"
39 
40 using namespace std;
41 
42 using namespace cbl;
43 
44 
45 // ============================================================================================
46 
47 
48 shared_ptr<cbl::modelling::cosmo::CMB_DistancePrior> cbl::modelling::cosmo::CMB_DistancePrior::Create (const string distance_prior_name)
49 {
50  if (distance_prior_name == "Aubourg15_Planck15")
51  return move(unique_ptr<cbl::modelling::cosmo::Aubourg15_Planck15>(new cbl::modelling::cosmo::Aubourg15_Planck15()));
52  else if (distance_prior_name == "Aubourg15_WMAP09")
53  return move(unique_ptr<cbl::modelling::cosmo::Aubourg15_WMAP09>(new cbl::modelling::cosmo::Aubourg15_WMAP09()));
54  else ErrorCBL("no such type of distance_prior_name!", "Create", "Modelling_Cosmology.cpp");
55 
56  return NULL;
57 }
58 
59 
60 // ============================================================================================
61 
62 
63 cbl::modelling::cosmo::Modelling_Cosmology::Modelling_Cosmology (const std::shared_ptr<cbl::data::Data> dataset, const std::vector<std::string> data_type)
64 {
65  m_data = dataset;
66  m_data_type = data_type;
67 }
68 
69 
70 // ============================================================================================
71 
72 
74 {
75  m_cosmology = move(make_shared<cbl::cosmology::Cosmology>(cosmology));
76 }
77 
78 
79 // ============================================================================================
80 
81 
82 void cbl::modelling::cosmo::Modelling_Cosmology::set_cosmological_parameters(const vector<cbl::cosmology::CosmologicalParameter> cosmoPar_name, const vector<cbl::statistics::PriorDistribution> cosmoPar_prior, const string distance_prior, const vector<string> external_dataset)
83 {
84  (void)distance_prior;
85  (void)external_dataset;
86 
87  const size_t nParams = cosmoPar_name.size();
88  checkDim(cosmoPar_prior, nParams, "cosmoPar_prior");
89 
90  vector<statistics::ParameterType> cosmoPar_type(nParams, statistics::ParameterType::_Base_);
91  vector<string> cosmoPar_string(nParams);
92 
93  for (size_t i=0; i<nParams; i++)
94  cosmoPar_string[i] = CosmologicalParameter_name(cosmoPar_name[i]);
95 
96  m_data_model.cosmology = m_cosmology;
97  m_data_model.Cpar = cosmoPar_name;
98  m_data_model.data_type = m_data_type;
99 
100  if(distance_prior != par::defaultString){
101  m_data_model.distance_prior = cbl::modelling::cosmo::CMB_DistancePrior::Create(distance_prior);
102  m_data_fit = cbl::data::join_dataset({m_data, m_data_model.distance_prior->dataset()});
103  m_fit_range = true;
104  }
105 
106  // input data used to construct the model
107  auto inputs = make_shared<STR_data_model_cosmology>(m_data_model);
108 
109  // set the priors
110  m_set_prior(cosmoPar_prior);
111 
112  // construct the model
113  if(distance_prior != par::defaultString)
114  m_model = make_shared<statistics::Model1D>(statistics::Model1D(&cbl::modelling::cosmo::cosmological_measurements_model_CMB_DistancePrior, nParams, cosmoPar_type, cosmoPar_string, inputs));
115  else
116  m_model = make_shared<statistics::Model1D>(statistics::Model1D(&cbl::modelling::cosmo::cosmological_measurements_model, nParams, cosmoPar_type, cosmoPar_string, inputs));
117 }
The class Modelling_Cosmology.
The class Modelling_Cosmology.
The class Cosmology.
Definition: Cosmology.h:277
void set_fiducial_cosmology(const cbl::cosmology::Cosmology cosmology)
set the fiducial cosmology
Modelling_Cosmology()=default
default constuctor
void set_cosmological_parameters(const std::vector< cbl::cosmology::CosmologicalParameter > cosmoPar_name, const std::vector< cbl::statistics::PriorDistribution > cosmoPar_prior, const std::string distance_prior=par::defaultString, const std::vector< std::string > external_dataset={})
set the cosmological parameters
The class Model1D.
Definition: Model1D.h:60
static const std::string defaultString
default std::string value
Definition: Constants.h:336
std::string CosmologicalParameter_name(const CosmologicalParameter parameter)
name of the cosmological parameter
Definition: Cosmology.cpp:45
std::shared_ptr< data::Data > join_dataset(std::vector< std::shared_ptr< data::Data >> dataset)
merge dataset (only work for one dataset type)
Definition: Data.cpp:261
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
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
void checkDim(const std::vector< T > vect, const int val, const std::string vector, bool equal=true)
check if the dimension of a std::vector is equal/lower than an input value
Definition: Kernel.h:1532
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