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

This example shows how to model the 2D two-point correlation function in redshift space

// ===================================================================================================================
// Example code: how to model the Cartesian 2D two-point correlation function to constrain the linear bias and sigmav
// ===================================================================================================================
int main () {
try {
// --------------------------------------------------------------------------------
// ---------------- use default cosmological parameters and set sigma8 ------------
// --------------------------------------------------------------------------------
cosmology.set_sigma8(0.8);
// -----------------------------------------------------------------------------------------------------------
// ---------------- read the input catalogue (with observed coordinates: R.A., Dec, redshift) ----------------
// -----------------------------------------------------------------------------------------------------------
const std::string file_catalogue = "../input/cat.dat";
// ----------------------------------------------------------------
// ---------------- construct the random catalogue ----------------
// ----------------------------------------------------------------
const double N_R = 3.; // random/data ratio
// --------------------------------------------------------------------------------------
// ---------------- measure the projected two-point correlation function ----------------
// --------------------------------------------------------------------------------------
// binning parameters and output data
const double rMin = 5.; // minimum separation
const double rMax = 50.; // maximum separation
const int nbins = 10; // number of bins
const double shift = 0.5; // spatial shift used to set the bin centre
const std::string dir = "../output/";
const std::string file = "xi2D.dat";
// measure the 2D Cartesian two-point correlation function and estimate Poissonian errors
const auto TwoP = cbl::measure::twopt::TwoPointCorrelation::Create(cbl::measure::twopt::TwoPType::_2D_Cartesian_, catalogue, random_catalogue, cbl::BinType::_linear_, rMin, rMax, nbins, shift, cbl::BinType::_linear_, rMin, rMax, nbins, shift);
TwoP->measure(cbl::measure::ErrorType::_Poisson_, dir, {dir});
TwoP->write(dir, file);
// ----------------------------------------------------------------------------------------------------------------------------------
// ----------------- model the Cartesian 2D two-point correlation function and estimate the linear bias and sigmav -----------------
// ----------------------------------------------------------------------------------------------------------------------------------
cbl::modelling::twopt::Modelling_TwoPointCorrelation2D_cartesian model_twop(TwoP); // object used for modelling
// flat prior for f*sigma8
const std::vector<double> fsigma8_limits = {0., 1.};
const cbl::statistics::PriorDistribution fsigma8_prior {cbl::glob::DistributionType::_Uniform_, fsigma8_limits[0], fsigma8_limits[1], 413414};
// flat prior for b*sigma8
const std::vector<double> bsigma8_limits = {0.8*cosmology.sigma8(), 3.*cosmology.sigma8()};
const cbl::statistics::PriorDistribution bsigma8_prior {cbl::glob::DistributionType::_Uniform_, bsigma8_limits[0], bsigma8_limits[1], 63656};
// flat prior for sigmav
//const std::vector<double> sigmav_limits = {1., 1000.};
const cbl::statistics::PriorDistribution sigmav_prior {cbl::glob::DistributionType::_Constant_, 0.};// sigmav_limits[0], sigmav_limits[1], 5411};
// mean redshift of the sample
const double redshift = 1.;
// set the data used to construct de model
model_twop.set_data_model(cosmology, redshift);
// set the model for the redshift-space 2D two-point correlation
model_twop.set_model_dispersion(fsigma8_prior, bsigma8_prior, sigmav_prior);
// ----------------------------------------------------------------------
// ------------- run chains and write output chain and model ------------
// ----------------------------------------------------------------------
const double min = 1., max = 40.;
model_twop.set_fit_range(min, max, min, max);
const int chain_size = 100;
const int nwalkers = 10;
const int seed = 666;
std::vector<double> starting_parameters = {0.5, 1.5, 100.};
const std::string chain_file = "chain_cartesian_bias_sigmav.dat";
model_twop.sample_posterior(chain_size, nwalkers, seed);
const int burn_in = 0;
const int thin = 1;
model_twop.show_results(burn_in, thin);
model_twop.write_chain(dir, chain_file, burn_in, thin);
model_twop.write_model_from_chains(dir, "model", {}, {}, burn_in, thin);
}
catch(cbl::glob::Exception &exc) { std::cerr << exc.what() << std::endl; exit(1); }
return 0;
}
int main()
main function to create the logo of the CosmoBolognaLib
Definition: Logo.cpp:41
The class Modelling_TwoPointCorrelation2D_cartesian.
The class Catalogue.
Definition: Catalogue.h:654
The class Cosmology.
Definition: Cosmology.h:277
void set_sigma8(const double sigma8=-1.)
set the value of σ8
Definition: Cosmology.h:1547
double sigma8() const
get the private member Cosmology::m_sigma8
Definition: Cosmology.h:1212
The class Exception.
Definition: Exception.h:111
const char * what() const noexcept override
the error description
Definition: Exception.h:203
static std::shared_ptr< TwoPointCorrelation > Create(const TwoPType type, const catalogue::Catalogue data, const catalogue::Catalogue random, const BinType binType, const double Min, const double Max, const int nbins, const double shift, const CoordinateUnits angularUnits=CoordinateUnits::_radians_, std::function< double(double)> angularWeight=nullptr, const bool compute_extra_info=false, const double random_dilution_fraction=1.)
static factory used to construct two-point correlation functions of any type
void write_chain(const std::string output_dir, const std::string output_file, const int start=0, const int thin=1, const bool is_FITS_format=false, const int prec=5, const int ww=14)
write the chains obtained after the MCMC sampling
Definition: Modelling.cpp:250
void show_results(const int start=0, const int thin=1, const int nbins=50, const bool show_mode=false, const int ns=-1)
show the results of the MCMC sampling on screen
Definition: Modelling.cpp:269
virtual void write_model_from_chains(const std::string output_dir, const std::string output_file, const std::vector< double > xx, const int start=0, const int thin=1)
write the model at xx computing 16th, 50th and 84th percentiles from the chains
Definition: Modelling1D.cpp:80
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 sample_posterior(const int chain_size, const int nwalkers, const int seed=666, const double aa=2, const bool parallel=true)
sample the posterior, initializing the chains by drawing from the prior distributions
Definition: Modelling.cpp:187
void set_fit_range(const double xmin, const double xmax)
set the fit range
Definition: Modelling1D.cpp:46
void set_model_dispersion(const statistics::PriorDistribution fsigma8_prior={}, const statistics::PriorDistribution bsigma8_prior={}, const statistics::PriorDistribution sigmav_prior={}, const statistics::PriorDistribution alpha_perp_prior={cbl::glob::DistributionType::_Constant_, 1.}, const statistics::PriorDistribution alpha_par_prior={cbl::glob::DistributionType::_Constant_, 1.})
set the dispersion model to fit the 2D two-point correlation function, in Cartesian coordinates
void set_data_model(const cbl::cosmology::Cosmology cosmology={}, const double redshift=0., const std::string method_Pk="CAMB", const double sigmaNL=0, const bool NL=true, const int FV=0, const bool store_output=true, const std::string output_root="test", const bool bias_nl=false, const double bA=-1., const bool xiType=false, const double k_star=-1., const bool xiNL=false, const double v_min=-5000., const double v_max=5000., const int step_v=500, const int norm=-1, const double r_min=0.1, const double r_max=150., const double k_min=0., const double k_max=100., const int step=200, const double aa=0., const bool GSL=true, const double prec=1.e-2, const std::string file_par=par::defaultString)
set the parameters for the computation of the dark matter two-point correlation function
The class PriorDistribution.
@ _createRandom_box_
random catalogue with cubic geometry (or parallelepiped) in comoving coordinates
@ _Constant_
Constant function.
@ _Uniform_
Identity function.
@ _2D_Cartesian_
2D two-point correlation function in Cartesian coordinates, ξ(rp,π)
@ _Poisson_
Poissonian error.
@ _Gaussian_Error_
Gaussian likelihood error.
@ _observed_
observed coordinates (R.A., Dec, redshift)
@ _linear_
linear binning