CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
model_power_spectrum_angular.cpp

This example shows how to model the angular power spectrum

// ========================================================================================
// Example code: how to model the angular power spectrum
// ========================================================================================
#include "Data1D.h"
using namespace std;
using namespace cbl;
// =====================================================================
int main () {
try {
cosmology.set_sigma8(0.83);
// -----------------------------------------------------------------------------------------------------------
// ---------------- read the input catalogue (with observed coordinates: R.A., Dec, redshift) ----------------
// -----------------------------------------------------------------------------------------------------------
std::string file_catalogue = "../input/catalogue.csv";
std::vector<int> column = {1,2,3};
cbl::catalogue::Catalogue catalogue {cbl::catalogue::ObjectType::_Galaxy_, cbl::CoordinateType::_observed_, attribute, column, {file_catalogue}, 0, 1, 1, cosmology, angularUnits};
// ------------------------------------------------------------------------------------------------------------------------------------------
// ---- insert mean of the offset and slope of the normalized redshift distribution (or measure them from catalogue number count!) ----------
// ------------------------------------------------------------------------------------------------------------------------------------------
const double mean_boffset = 208.84611;
const double mean_bslope = -175.71603;
// -----------------------------------------------------------------------------------------------------------
// ------------------- construct the dataset by reading an input file ----------------------------------------
// -----------------------------------------------------------------------------------------------------------
const std::string file_measure = "../input/Cl_spherical_harmonic.dat";
const int skipped_lines = 1; //line header
const auto pow_dataset = std::make_shared<cbl::data::Data1D>(cbl::data::Data1D(file_measure, skipped_lines));
// ------------------------------------------------------
// ------------- set the modelling structure ------------
// ------------------------------------------------------
model_pow.set_data_model(cosmology, catalogue.Min(cbl::catalogue::Var::_Redshift_),catalogue.Max(cbl::catalogue::Var::_Redshift_), "EisensteinHu", true, 0, 0.001, 100., {mean_boffset, mean_bslope});
// -------------------------------------------------------
// ------------- set the priors and the model ------------
// -------------------------------------------------------
cbl::statistics::PriorDistribution Omega_matter_LCDM_prior, sigma8_prior;
Omega_matter_LCDM_prior = cbl::statistics::PriorDistribution(cbl::glob::DistributionType::_Constant_, cosmology.Omega_matter());
std::vector<cbl::statistics::PriorDistribution> CosmoPriors = {Omega_matter_LCDM_prior, sigma8_prior}; //,OmegaB_prior
model_pow.set_model_limber(CosmoPar, CosmoPriors, bias_prior);
const double xmin = 10., xmax = 30.;
model_pow.set_fit_range(xmin, xmax);
std::vector<double> ell= cbl::linear_bin_vector(xmax-xmin, xmin, xmax);
// maximise the posterior
std::vector<double> start= {1.};
model_pow.maximize_posterior(start, 10000, 1.e-5);
const string file_output = "model_bestfit.dat";
model_pow.write_model_at_bestfit("../output/",file_output, ell);
}
catch(cbl::glob::Exception &exc) { cerr << exc.what() << endl; exit(1); }
return 0;
}
The class Data1D.
int main()
main function to create the logo of the CosmoBolognaLib
Definition: Logo.cpp:41
Global functions to model the angular power spectrum.
The class Modelling_PowerSpectrum_angular.
The class Catalogue.
Definition: Catalogue.h:654
The class Cosmology.
Definition: Cosmology.h:277
The class Data1D.
Definition: Data1D.h:51
The class Exception.
Definition: Exception.h:111
const char * what() const noexcept override
the error description
Definition: Exception.h:203
void set_likelihood(const statistics::LikelihoodType likelihood_type, const std::vector< size_t > x_index={0, 2}, const int w_index=-1, const double prec=1.e-10, const int Nres=-1)
set the likelihood function
Definition: Modelling.cpp:124
void set_fit_range(const double xmin, const double xmax)
set the fit range
Definition: Modelling1D.cpp:46
virtual void write_model_at_bestfit(const std::string output_dir, const std::string output_file, const std::vector< double > xx)
write the model at xx with best-fit parameters obtained from posterior maximization
Definition: Modelling1D.cpp:68
void maximize_posterior(const std::vector< double > start, const unsigned int max_iter=10000, const double tol=1.e-6, const double epsilon=1.e-3, const int seed=666)
function that maximizes the posterior, finds the best-fit parameters and stores them in the model
Definition: Modelling.cpp:177
void set_data_model(const cbl::cosmology::Cosmology cosmology, const double z_min=0., const double z_max=10., const std::string method_Pk="CAMB", const bool NL=false, const int norm=-1, const double k_min=0.001, const double k_max=5., const std::vector< double > dN_par={}, const double fsky=1., std::vector< double > ll={}, std::vector< std::vector< double >> mixing_matrix={}, const bool interpolate_power_spectrum=false)
Set the data used to construct models of the angular power spectrum.
void set_model_limber(const std::vector< cbl::cosmology::CosmologicalParameter > cosmo_param, const std::vector< statistics::PriorDistribution > cosmo_prior, const statistics::PriorDistribution bias_prior)
set the model to fit the angular power spectrum
The class PriorDistribution.
@ _RA_
Right Ascension.
@ _Dec_
Declination.
@ _sigma8_
: the power spectrum normalisation
@ _Omega_matter_LCDM_
: the density of baryons, cold dark matter and massive neutrinos (in units of the critical density) a...
@ _Planck15_
Planck collaboration 2015, paper XIII: Table 4, TT,TE,EE+lowP+lensing.
@ _Constant_
Constant function.
@ _Uniform_
Identity function.
@ _Gaussian_Covariance_
Gaussian likelihood covariance.
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
@ _observed_
observed coordinates (R.A., Dec, redshift)
std::vector< T > linear_bin_vector(const size_t nn, const T min, const T max)
fill a std::vector with linearly spaced values
Definition: Kernel.h:1604
CoordinateUnits
the coordinate units
Definition: Kernel.h:562
@ _radians_
angle in radians