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

This example shows how to measure the monopole of the two-point correlation function and estimate the errors with different methods

// ============================================================================================================================
// Example code: how to measure the angle-averaged two-point correlation function, estimating the errors with different methods
// ============================================================================================================================
#include "GlobalFunc.h"
int main () {
try {
// -----------------------------------------------------------------
// ---------------- use default cosmological parameters ------------
// -----------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------
// ---------------- read the input catalogue (with observed coordinates: R.A., Dec, redshift) ----------------
// -----------------------------------------------------------------------------------------------------------
const std::string file_catalogue = "../input/cat.dat";
// --------------------------------------------------------------------------------------
// ---------------- construct the random catalogue (with cubic geometry) ----------------
// --------------------------------------------------------------------------------------
const double N_R = 3.; // random/data ratio
// construct the sub-regions used for jackknife and bootstrap
std::cout << "I'm constructing the sub-regions used for jackknife and bootstrap..." << std::endl;
const int nx = 3, ny = 3, nz = 3;
cbl::set_ObjectRegion_SubBoxes(catalogue, random_catalogue, nx, ny, nz);
// --------------------------------------------------------------------------------------------
// ---------------- measure the monopole of the two-point correlation function ----------------
// --------------------------------------------------------------------------------------------
// binning parameters
const double rMin = 10.; // minimum separation
const double rMax = 30.; // maximum separation
const int nbins = 3; // number of bins
const double shift = 0.5; // spatial shift used to set the bin centre
// construct the object used to measure the two-point correlation function
cbl::measure::twopt::TwoPointCorrelation1D_monopole TwoP {catalogue, random_catalogue, cbl::BinType::_logarithmic_, rMin, rMax, nbins, shift};
// Input/Output directories
const std::string dir_output = "../output/";
const std::string dir_pairs = dir_output+"pairs/";
// measure the monopole and compute Poissonian errors
TwoP.measure(cbl::measure::ErrorType::_Poisson_, dir_pairs);
TwoP.write(dir_output, "xi_PoissonianErrors.dat");
// measure the monopole and compute errors with jackknife (in cubic geometry)
TwoP.measure(cbl::measure::ErrorType::_Jackknife_, dir_pairs);
TwoP.write(dir_output, "xi_JackknifeErrors.dat");
// measure the monopole and compute errors with bootstrap
const int nM = 100; // number of mocks generated for bootstrap resampling
TwoP.measure(cbl::measure::ErrorType::_Bootstrap_, dir_pairs, {dir_pairs}, "", nM);
TwoP.write(dir_output, "xi_BootstrapErrors.dat");
cbl::Print(TwoP.dataset()->covariance());
}
catch(cbl::glob::Exception &exc) { std::cerr << exc.what() << std::endl; exit(1); }
return 0;
}
Generic functions that use one or more classes of the CosmoBolognaLib.
int main()
main function to create the logo of the CosmoBolognaLib
Definition: Logo.cpp:41
The class TwoPointCorrelation1D_monopole.
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
@ _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.
@ _Bootstrap_
Bootstrap resampling.
@ _Poisson_
Poissonian error.
@ _Jackknife_
Jackknife resampling.
void Print(const T value, const int prec, const int ww, const std::string header="", const std::string end="\n", const bool use_coutCBL=true, std::ostream &stream=std::cout, const std::string colour=cbl::par::col_default)
function to print values with a proper homegenised format
Definition: Kernel.h:1142
@ _observed_
observed coordinates (R.A., Dec, redshift)
void set_ObjectRegion_SubBoxes(catalogue::Catalogue &data, const int nx, const int ny, const int nz)
set the object region in sub-boxes
Definition: SubSample.cpp:236
@ _logarithmic_
logarithmic binning