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

This example shows how to measure the 2D two-point correlation function

// ========================================================================================================================
// Example code: how to model the 2D two-point correlation function in Cartesian coordinates, xi(rp, pi), in redshift-space
// ========================================================================================================================
int main () {
try {
// -------------------------------------------------------------
// ---------------- set the cosmological parameters ------------
// -------------------------------------------------------------
// ----------------------------------------------------------
// ---------------- read the input catalogue ----------------
// ----------------------------------------------------------
const std::string file_catalogue = "../input/cat.dat";
// --------------------------------------------------------------------------------------
// ---------------- construct the random catalogue (with cubic geometry) ----------------
// --------------------------------------------------------------------------------------
const double N_R = 3.; // random/data ratio
// -----------------------------------------------------------------------------------------------
// ---------------- measure the 2D two-point correlation in Cartesian coordinates ----------------
// -----------------------------------------------------------------------------------------------
// ----- output data -----
const std::string dir_pairs = "../output/";
const std::string dir_output = "../output/";
// ----- measure the 2D correlation function in Cartesian coordinates, xi(rp,pi), and store the outputs -----
const double rpMin = 5.; // minimum separation in the first dimension
const double rpMax = 50.; // maximum separation in the first dimension
const int nbins_D1 = 10; // number of bins in the first dimension
const double shift_D1 = 0.5; // spatial shift used to set the bin centre in the first dimension
const double piMin = 5.; // minimum separation in the second dimension
const double piMax = 50.; // maximum separation in the second dimension
const int nbins_D2 = 10; // number of bins in the second dimension
const double shift_D2 = 0.5; // spatial shift used to set the bin centre in the second dimension
// construct the object using a static factory
const auto xi2DCart = cbl::measure::twopt::TwoPointCorrelation::Create(cbl::measure::twopt::TwoPType::_2D_Cartesian_, catalogue, random_catalogue, cbl::BinType::_linear_, rpMin, rpMax, nbins_D1, shift_D1, cbl::BinType::_linear_, piMin, piMax, nbins_D2, shift_D2);
// measure the 2D correlation function and compute Poisson errors
xi2DCart->measure(cbl::measure::ErrorType::_Poisson_, dir_pairs);
// store the output
xi2DCart->write(dir_output, "xi_rp_pi_linlin.dat");
}
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 TwoPointCorrelation2D.
The class Catalogue.
Definition: Catalogue.h:654
The class Cosmology.
Definition: Cosmology.h:277
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
@ _createRandom_box_
random catalogue with cubic geometry (or parallelepiped) in comoving coordinates
@ _Planck15_
Planck collaboration 2015, paper XIII: Table 4, TT,TE,EE+lowP+lensing.
@ _2D_Cartesian_
2D two-point correlation function in Cartesian coordinates, ξ(rp,π)
@ _Poisson_
Poissonian error.
@ _observed_
observed coordinates (R.A., Dec, redshift)
@ _linear_
linear binning