56 if (_binning.
space ==
"fourier") {
57 throw std::domain_error(
"No custom binning specified in Fourier space.");
61 double dbin_pad = 10.;
72 for (
int ibin = 1; ibin < nbin_pad; ibin++) {
73 double edge_left = dbin_pad * ibin;
74 double centre = edge_left + dbin_pad / 2.;
81 double bin_min = dbin_pad * nbin_pad;
83 double dlnbin = (std::log(_binning.
bin_max) - std::log(bin_min))
84 /
double(_binning.
num_bins - nbin_pad);
86 for (
int ibin = nbin_pad; ibin < _binning.
num_bins; ibin++) {
87 double edge_left = bin_min * std::exp(dlnbin * (ibin - nbin_pad));
88 double edge_right = bin_min * std::exp(dlnbin * (ibin - nbin_pad + 1));
89 double centre = (edge_left + edge_right) / 2.;
93 _binning.
bin_widths.push_back(edge_right - edge_left);
107int main(
int argc,
char* argv[]) {
126 "[MAIN:TRV:A] Parameters and source data are being initialised."
141 "Failed to initialise program: missing parameter file."
144 "Failed to initialise program: missing parameter file.\n"
153 "Failed to initialise program: invalidated parameters."
156 "Failed to initialise program: invalidated parameters.\n"
165 "Failed to print used parameters to file "
166 "in the measurement output directory."
188 std::string flag_data =
"false";
193 "Failed to initialise program: "
194 "unspecified data-source catalogue file."
197 "Failed to initialise program: "
198 "unspecified data-source catalogue file.\n"
207 "Failed to initialise program: "
208 "unloadable data-source catalogue file."
211 "Failed to initialise program: "
212 "unloadable data-source catalogue file.\n"
220 std::string flag_rand =
"false";
225 "Failed to initialise program: "
226 "unspecified random-source catalogue file."
229 "Failed to initialise program: "
230 "unspecified random-source catalogue file.\n"
239 "Failed to initialise program: "
240 "unloadable random-source catalogue file."
243 "Failed to initialise program: "
244 "unloadable random-source catalogue file.\n"
267 "[MAIN:TRV:B] Clustering statistics are being measured."
280 if (params.
binning ==
"custom") {
301 if (flag_data ==
"true") {
309#pragma omp parallel for
311 for (
int pid = 0; pid < catalogue_data.
ntotal; pid++) {
317 "A data-catalogue particle coincides with the origin."
322 los_data[pid].
pos[0] = catalogue_data[pid].pos[0] / los_mag;
323 los_data[pid].
pos[1] = catalogue_data[pid].pos[1] / los_mag;
324 los_data[pid].
pos[2] = catalogue_data[pid].pos[2] / los_mag;
329 if (flag_rand ==
"true") {
337#pragma omp parallel for
339 for (
int pid = 0; pid < catalogue_rand.
ntotal; pid++) {
345 "A random-catalogue particle coincides with the origin."
350 los_rand[pid].
pos[0] = catalogue_rand[pid].pos[0] / los_mag;
351 los_rand[pid].
pos[1] = catalogue_rand[pid].pos[1] / los_mag;
352 los_rand[pid].
pos[2] = catalogue_rand[pid].pos[2] / los_mag;
369 "[MAIN:TRV:B] Aligning catalogues inside measurement box..."
377 double ngrid_pad[3] = {
381 catalogue_data, catalogue_rand,
387 double boxsize_pad[3] = {
391 catalogue_data, catalogue_rand,
398 catalogue_data, catalogue_rand, params.
boxsize
408 double ngrid_pad[3] = {
416 double boxsize_pad[3] = {
420 catalogue_rand, params.
boxsize, boxsize_pad
435 "[MAIN:TRV:B] ... aligned catalogues inside measurement box."
445 if (flag_data ==
"true" && flag_rand ==
"true") {
458 (flag_rand ==
"true") ? catalogue_rand : catalogue_data;
459 double alpha_for_norm = (flag_rand ==
"true") ? alpha : 1.;
460 double norm_factor_part = 0., norm_factor_mesh = 0., norm_factor_meshes = 0.;
462 if (params.
npoint ==
"2pt") {
464 catalogue_for_norm, alpha_for_norm
467 catalogue_for_norm, params, alpha_for_norm
473 const double PADDING = 0.1;
474 const double CELLSIZE = 10.;
475 const std::string ASSIGNMENT =
"cic";
480 catalogue_data, catalogue_rand, params, alpha,
481 PADDING, CELLSIZE, ASSIGNMENT
485 if (params.
npoint ==
"3pt") {
487 catalogue_for_norm, alpha_for_norm
490 catalogue_for_norm, params, alpha_for_norm
494 double norm_factor = 0.;
495 if (params.
npoint !=
"none") {
500 "Normalisation factors: "
501 "%.6e (particle), %.6e (mesh), %.6e (mesh-mixed) (none used).",
502 norm_factor_part, norm_factor_mesh, norm_factor_meshes
507 norm_factor = norm_factor_part;
510 "Normalisation factors: "
511 "%.6e (particle; used), %.6e (mesh), %.6e (mesh-mixed).",
512 norm_factor, norm_factor_mesh, norm_factor_meshes
517 norm_factor = norm_factor_mesh;
520 "Normalisation factors: "
521 "%.6e (particle), %.6e (mesh; used), %.6e (mesh-mixed).",
522 norm_factor_part, norm_factor, norm_factor_meshes
527 norm_factor = norm_factor_meshes;
530 "Normalisation factors: "
531 "%.6e (particle), %.6e (mesh), %.6e (mesh-mixed; used).",
532 norm_factor_part, norm_factor_mesh, norm_factor
542 char save_filepath[1024];
545 save_filepath,
sizeof(save_filepath),
"%s/pk%d%s",
548 std::FILE* save_fileptr =
nullptr;
552 catalogue_data, catalogue_rand, los_data, los_rand,
553 params, binning, norm_factor
555 save_fileptr = std::fopen(save_filepath,
"w");
557 save_fileptr, params, catalogue_data, catalogue_rand,
558 norm_factor_part, norm_factor_mesh, norm_factor_meshes
563 catalogue_data, params, binning, norm_factor
565 save_fileptr = std::fopen(save_filepath,
"w");
567 save_fileptr, params, catalogue_data,
568 norm_factor_part, norm_factor_mesh, norm_factor_meshes
572 save_fileptr, params, meas_powspec
574 std::fclose(save_fileptr);
578 save_filepath,
sizeof(save_filepath),
"%s/xi%d%s",
581 std::FILE* save_fileptr =
nullptr;
585 catalogue_data, catalogue_rand, los_data, los_rand,
586 params, binning, norm_factor
588 save_fileptr = std::fopen(save_filepath,
"w");
590 save_fileptr, params, catalogue_data, catalogue_rand,
591 norm_factor_part, norm_factor_mesh, norm_factor_meshes
596 catalogue_data, params, binning, norm_factor
598 save_fileptr = std::fopen(save_filepath,
"w");
600 save_fileptr, params, catalogue_data,
601 norm_factor_part, norm_factor_mesh, norm_factor_meshes
605 save_fileptr, params, meas_2pcf
607 std::fclose(save_fileptr);
611 save_filepath,
sizeof(save_filepath),
"%s/xiw%d%s",
616 catalogue_rand, los_rand, params, binning, alpha, norm_factor
618 std::FILE* save_fileptr = std::fopen(save_filepath,
"w");
620 save_fileptr, params, catalogue_rand,
621 norm_factor_part, norm_factor_mesh, norm_factor_meshes
624 save_fileptr, params, meas_2pcf_win
626 std::fclose(save_fileptr);
629 if (params.
form ==
"full" || params.
form ==
"diag") {
631 save_filepath,
sizeof(save_filepath),
"%s/bk%d%d%d_%s%s",
638 if (params.
form ==
"off-diag") {
640 save_filepath,
sizeof(save_filepath),
"%s/bk%d%d%d_offdiag%d%s",
646 if (params.
form ==
"row") {
648 save_filepath,
sizeof(save_filepath),
"%s/bk%d%d%d_row%d%s",
654 std::FILE* save_fileptr =
nullptr;
658 catalogue_data, catalogue_rand, los_data, los_rand,
659 params, binning, norm_factor
661 save_fileptr = std::fopen(save_filepath,
"w");
663 save_fileptr, params, catalogue_data, catalogue_rand,
664 norm_factor_part, norm_factor_mesh, norm_factor_meshes
669 catalogue_data, params, binning, norm_factor
671 save_fileptr = std::fopen(save_filepath,
"w");
673 save_fileptr, params, catalogue_data,
674 norm_factor_part, norm_factor_mesh, norm_factor_meshes
678 save_fileptr, params, meas_bispec
680 std::fclose(save_fileptr);
683 if (params.
form ==
"full" || params.
form ==
"diag") {
685 save_filepath,
sizeof(save_filepath),
"%s/zeta%d%d%d_%s%s",
692 if (params.
form ==
"off-diag") {
694 save_filepath,
sizeof(save_filepath),
"%s/zeta%d%d%d_offdiag%d%s",
700 if (params.
form ==
"row") {
702 save_filepath,
sizeof(save_filepath),
"%s/zeta%d%d%d_row%d%s",
708 std::FILE* save_fileptr =
nullptr;
712 catalogue_data, catalogue_rand, los_data, los_rand,
713 params, binning, norm_factor
715 save_fileptr = std::fopen(save_filepath,
"w");
717 save_fileptr, params, catalogue_data, catalogue_rand,
718 norm_factor_part, norm_factor_mesh, norm_factor_meshes
723 catalogue_data, params, binning, norm_factor
725 save_fileptr = std::fopen(save_filepath,
"w");
727 save_fileptr, params, catalogue_data,
728 norm_factor_part, norm_factor_mesh, norm_factor_meshes
732 save_fileptr, params, meas_3pcf
734 std::fclose(save_fileptr);
737 if (params.
form ==
"full" || params.
form ==
"diag") {
739 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_%s%s",
746 if (params.
form ==
"off-diag") {
748 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_offdiag%d%s",
754 if (params.
form ==
"row") {
756 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_row%d%s",
765 catalogue_rand, los_rand, params, binning, alpha, norm_factor, wa
767 std::FILE* save_fileptr = std::fopen(save_filepath,
"w");
769 save_fileptr, params, catalogue_rand,
770 norm_factor_part, norm_factor_mesh, norm_factor_meshes
773 save_fileptr, params, meas_3pcf_win
775 std::fclose(save_fileptr);
778 if (params.
form ==
"full" || params.
form ==
"diag") {
780 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_wa%d%d_%s%s",
787 if (params.
form ==
"off-diag") {
789 save_filepath,
sizeof(save_filepath),
790 "%s/zetaw%d%d%d_wa%d%d_offdiag%d%s",
797 if (params.
form ==
"row") {
799 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_wa%d%d_row%d%s",
811 catalogue_rand, los_rand, params, binning, alpha, norm_factor, wa
813 std::FILE* save_fileptr = std::fopen(save_filepath,
"w");
815 save_fileptr, params, catalogue_rand,
816 norm_factor_part, norm_factor_mesh, norm_factor_meshes
819 save_fileptr, params, meas_3pcf_win_wa
821 std::fclose(save_fileptr);
831 save_filepath,
sizeof(save_filepath),
"%s",
850#if defined(TRV_USE_OMP) && defined(TRV_USE_FFTWOMP)
851 fftw_cleanup_threads();
859 if (los_data !=
nullptr) {
860 delete[] los_data; los_data =
nullptr;
862 if (los_rand !=
nullptr) {
863 delete[] los_rand; los_rand =
nullptr;
872 "Number of FFTs: %d forward, %d backward.",
885 "Maximum number of concurrent 3-d grids: "
886 "%.1f complex-equivalent, %d complex, %d real.",
895 "Minimal estimate of peak memory usage: %.1f gibibytes.",
902 "Uncleared dynamically allocated memory: %.1f gibibytes.",
Isotropic coordinate binning.
std::vector< double > bin_widths
bin widths
std::vector< double > bin_edges
bin edges
std::vector< double > bin_centres
bin centres
std::string space
coordinate space
double bin_max
highest bin edge
void set_bins(double coord_min, double coord_max, int nbin)
Set bins.
int num_bins
number of bins
Field (pseudo-two-point) statistics.
trv::BinnedVectors record_binned_vectors(trv::Binning &binning, const std::string &save_file)
Record binned vectors given a binning scheme.
std::string alignment
box alignment: {"centre" (default), "pad"}
std::string catalogue_columns
catalogue data columns (comma-separated without space)
std::string output_tag
output tag
std::string save_binned_vectors
int ELL
spherical degree associated with the line of sight
int i_wa
first order of the wide-angle correction term
double padfactor
padding factor
double volume
box volume (in Mpc^3/h^3)
int print_to_file(char *out_parameter_filepath)
Print out extracted parameters to a file in the output measurement directory.
int read_from_file(char *parameter_filepath)
Read parameters from a file.
std::string norm_convention
std::string statistic_type
std::string measurement_dir
measurement/output directory
std::string catalogue_type
catalogue type: {"survey", "random", "sim", "none"}
int ell1
spherical degree associated with the first wavevector
std::string padscale
padding scale (if alignment is "pad"): {"box" (default), "grid"}
int ell2
spherical degree associated with the second wavevector
int ngrid[3]
grid number in each dimension
std::string data_catalogue_file
data catalogue file
std::string npoint
N-point case: {"2pt", "3pt", "none"}
std::string rand_catalogue_file
random catalogue file
int idx_bin
fixed bin index in "off-fiag"/"row" form three-point measurements
int j_wa
second order of the wide-angle correction term
double boxsize[3]
box size (in Mpc/h) in each dimension
std::string use_fftw_wisdom
use FFTW wisdom: {"false" (default), <path-to-dir>}
static void centre_in_box(ParticleCatalogue &catalogue, const double boxsize[3])
Centre a catalogue in a box.
void finalise_particles()
Finalise particle data container.
static void pad_grids(ParticleCatalogue &catalogue, const double boxsize[3], const int ngrid[3], const double ngrid_pad[3])
Pad a catalogue in a box.
int load_catalogue_file(const std::string &catalogue_filepath, const std::string &catalogue_columns, double volume=0.)
Read in a catalogue file.
int ntotal
total number of particles
void offset_coords_for_periodicity(const double boxsize[3])
Offset particle positions for periodic boundary conditions.
static void pad_in_box(ParticleCatalogue &catalogue, const double boxsize[3], const double boxsize_pad[3])
Pad a catalogue in a box.
double wstotal
total sample weight of particles
Exception raised when an input/output operation fails.
void info(const char *fmt_string,...)
Emit a information-level message.
void error(const char *fmt_string,...)
Emit a warning-level message.
void warn(const char *fmt_string,...)
Emit a warning-level message.
void stat(const char *fmt_string,...)
Emit a status-level message.
void reset_level(LogLevel level)
Reset the logger threshold level.
Clustering measurement data objects.
I/O support including custom exceptions and utility functions.
Provide tracking of program resources and exceptions.
void print_measurement_header_to_file(std::FILE *fileptr, trv::ParameterSet ¶ms, trv::ParticleCatalogue &catalogue_data, trv::ParticleCatalogue &catalogue_rand, double norm_factor_part, double norm_factor_mesh, double norm_factor_meshes)
Print the pre-measurement header to a file including information about the catalogue(s) and mesh grid...
void print_measurement_datatab_to_file(std::FILE *fileptr, trv::ParameterSet ¶ms, trv::PowspecMeasurements &meas_powspec)
Print measurements as a data table to a file.
double get_vec3d_magnitude(std::vector< double > vec)
Return the magnitude of a 3-d vector.
double gbytesMem
current memory usage in gibibytes
double size_in_gb(long long num)
Return size in gibibytes.
void update_maxmem()
Update the maximum memory usage estimate.
void display_prog_licence()
Display program licence in stdout.
void display_prog_logo()
Display program logo in stdout.
float max_count_grid
maximum number of grids
Logger logger
default logger (at NSET logging level)
int max_count_rgrid
maximum number of 3-d real grids
void make_write_dir(std::string dirstr)
Make write directory.
bool if_filepath_is_set(const std::string &pathstr)
Check if a file path is set.
int max_count_cgrid
maximum number of 3-d complex grids
void display_prog_logbars(int endpoint)
Display program log bars in stdout.
int count_fft
number of FFTs
double gbytesMaxMem
maximum memory usage in gibibytes
int count_ifft
number of IFFTs
void display_prog_info()
Display program information in stdout.
double calc_bispec_normalisation_from_particles(ParticleCatalogue &particles, double alpha=1.)
Calculate particle-based bispectrum normalisation.
trv::ThreePCFMeasurements compute_3pcf_in_gpp_box(ParticleCatalogue &catalogue_data, trv::ParameterSet ¶ms, trv::Binning &rbinning, double norm_factor)
Compute three-point correlation function in a periodic box in the global plane-parallel approximation...
trv::TwoPCFWindowMeasurements compute_corrfunc_window(trv::ParticleCatalogue &catalogue_rand, trv::LineOfSight *los_rand, trv::ParameterSet ¶ms, trv::Binning rbinning, double alpha, double norm_factor)
Compute two-point correlation function window from a random catalogue and optionally save the results...
trv::TwoPCFMeasurements compute_corrfunc(ParticleCatalogue &catalogue_data, ParticleCatalogue &catalogue_rand, LineOfSight *los_data, LineOfSight *los_rand, trv::ParameterSet ¶ms, trv::Binning &rbinning, double norm_factor)
Compute two-point correlation function from paired survey-type catalogues.
trv::PowspecMeasurements compute_powspec_in_gpp_box(ParticleCatalogue &catalogue_data, trv::ParameterSet ¶ms, trv::Binning kbinning, double norm_factor)
Compute power spectrum in a periodic box in the global plane-parallel approximation.
trv::BispecMeasurements compute_bispec_in_gpp_box(ParticleCatalogue &catalogue_data, trv::ParameterSet ¶ms, trv::Binning kbinning, double norm_factor)
Compute bispectrum in a periodic box in the global plane-parallel approximation.
trv::ThreePCFWindowMeasurements compute_3pcf_window(ParticleCatalogue &catalogue_rand, LineOfSight *los_rand, trv::ParameterSet ¶ms, trv::Binning &rbinning, double alpha, double norm_factor, bool wide_angle=false)
Compute three-point correlation function window from a random catalogue.
double calc_powspec_normalisation_from_particles(ParticleCatalogue &particles, double alpha=1.)
Calculate particle-based power spectrum normalisation.
double calc_bispec_normalisation_from_mesh(ParticleCatalogue &particles, trv::ParameterSet ¶ms, double alpha=1.)
Calculate mesh-based bispectrum normalisation.
double calc_powspec_normalisation_from_mesh(trv::ParticleCatalogue &particles, trv::ParameterSet ¶ms, double alpha=1.)
Calculate mesh-based power spectrum normalisation.
trv::PowspecMeasurements compute_powspec(ParticleCatalogue &catalogue_data, ParticleCatalogue &catalogue_rand, LineOfSight *los_data, LineOfSight *los_rand, trv::ParameterSet ¶ms, trv::Binning &kbinning, double norm_factor)
Compute power spectrum from paired survey-type catalogues.
trv::BispecMeasurements compute_bispec(ParticleCatalogue &catalogue_data, ParticleCatalogue &catalogue_rand, LineOfSight *los_data, LineOfSight *los_rand, trv::ParameterSet ¶ms, trv::Binning &kbinning, double norm_factor)
Compute bispectrum from paired survey-type catalogues.
trv::ThreePCFMeasurements compute_3pcf(ParticleCatalogue &catalogue_data, ParticleCatalogue &catalogue_rand, LineOfSight *los_data, LineOfSight *los_rand, trv::ParameterSet ¶ms, trv::Binning &rbinning, double norm_factor)
Compute three-point correlation function from paired survey-type catalogues.
trv::TwoPCFMeasurements compute_corrfunc_in_gpp_box(ParticleCatalogue &catalogue_data, trv::ParameterSet ¶ms, trv::Binning &rbinning, double norm_factor)
Compute two-point correlation function in a periodic box in the global plane-parallel approximation.
double calc_powspec_normalisation_from_meshes(trv::ParticleCatalogue &particles_data, trv::ParticleCatalogue &particles_rand, trv::ParameterSet ¶ms, double alpha)
Calculate power spectrum normalisation from mixed meshes.
Program parameter configuration.
Particle containers with I/O methods and operations.
double pos[3]
3-d position vector
Power spectrum measurements.
Three-point correlation function measurements.
Three-point correlation function window measurements.
Two-point correlation function measurements.
Two-point correlation function window measurements.
Three-point statistic computations.
int main(int argc, char *argv[])
A 'black-box' program for measuring two- and three-point clustering statistics.
void _set_custom_bins(trv::Binning &_binning)
Set 'custom' binning.
Two-point statistic computations.