58 if (_binning.
space ==
"fourier") {
59 throw std::domain_error(
"No custom binning specified in Fourier space.");
63 double dbin_pad = 10.;
74 for (
int ibin = 1; ibin < nbin_pad; ibin++) {
75 double edge_left = dbin_pad * ibin;
76 double centre = edge_left + dbin_pad / 2.;
83 double bin_min = dbin_pad * nbin_pad;
85 double dlnbin = (std::log(_binning.
bin_max) - std::log(bin_min))
86 /
double(_binning.
num_bins - nbin_pad);
88 for (
int ibin = nbin_pad; ibin < _binning.
num_bins; ibin++) {
89 double edge_left = bin_min * std::exp(dlnbin * (ibin - nbin_pad));
90 double edge_right = bin_min * std::exp(dlnbin * (ibin - nbin_pad + 1));
91 double centre = (edge_left + edge_right) / 2.;
95 _binning.
bin_widths.push_back(edge_right - edge_left);
109int main(
int argc,
char* argv[]) {
111 for (
int idx_arg = 1; idx_arg < argc; idx_arg++) {
112 std::string arg = argv[idx_arg];
113 if (arg ==
"-h" || arg ==
"--help") {
117 if (arg ==
"-V" || arg ==
"--version") {
123 if (argc > 2 && arg.rfind(
"-", 0) == 0) {
124 std::fprintf(stderr,
"Unknown option: %s\n\n", arg.c_str());
148 "[MAIN:TRV:A] Parameters and source data are being initialised."
163 "Failed to initialise program: missing parameter file."
166 "Failed to initialise program: missing parameter file."
178 if (exit_code != 0) {
181 "Failed to initialise program: invalidated parameters."
192 "Failed to print used parameters to file "
193 "in the measurement output directory."
215 std::string flag_data =
"false";
220 "Failed to initialise program: "
221 "unspecified data-source catalogue file."
224 "Failed to initialise program: "
225 "unspecified data-source catalogue file."
240 if (exit_code != 0) {
243 "Failed to initialise program: "
244 "unloadable data-source catalogue file."
252 std::string flag_rand =
"false";
257 "Failed to initialise program: "
258 "unspecified random-source catalogue file."
261 "Failed to initialise program: "
262 "unspecified random-source catalogue file."
277 if (exit_code != 0) {
280 "Failed to initialise program: "
281 "unloadable random-source catalogue file."
304 "[MAIN:TRV:B] Clustering statistics are being measured."
317 if (params.
binning ==
"custom") {
338 if (flag_data ==
"true") {
346#pragma omp parallel for
348 for (
int pid = 0; pid < catalogue_data.
ntotal; pid++) {
354 "A data-catalogue particle coincides with the origin."
359 los_data[pid].
pos[0] = catalogue_data[pid].pos[0] / los_mag;
360 los_data[pid].
pos[1] = catalogue_data[pid].pos[1] / los_mag;
361 los_data[pid].
pos[2] = catalogue_data[pid].pos[2] / los_mag;
366 if (flag_rand ==
"true") {
374#pragma omp parallel for
376 for (
int pid = 0; pid < catalogue_rand.
ntotal; pid++) {
382 "A random-catalogue particle coincides with the origin."
387 los_rand[pid].
pos[0] = catalogue_rand[pid].pos[0] / los_mag;
388 los_rand[pid].
pos[1] = catalogue_rand[pid].pos[1] / los_mag;
389 los_rand[pid].
pos[2] = catalogue_rand[pid].pos[2] / los_mag;
406 "[MAIN:TRV:B] Aligning catalogues inside measurement box..."
412 if (params.
volume == 0.) {
414 if (params.
nmesh == 0) {
420 double ngrid_pad[3] = {
424 catalogue_data, catalogue_rand,
430 double boxsize_pad[3] = {
434 catalogue_data, catalogue_rand,
441 catalogue_data, catalogue_rand, params.
boxsize
446 if (params.
volume == 0.) {
448 if (params.
nmesh == 0) {
455 if (params.
volume == 0.) {
457 if (params.
nmesh == 0) {
463 double ngrid_pad[3] = {
471 double boxsize_pad[3] = {
475 catalogue_rand, params.
boxsize, boxsize_pad
490 "[MAIN:TRV:B] ... aligned catalogues inside measurement box."
500 if (flag_data ==
"true" && flag_rand ==
"true") {
513 (flag_rand ==
"true") ? catalogue_rand : catalogue_data;
514 double alpha_for_norm = (flag_rand ==
"true") ? alpha : 1.;
515 double norm_factor_part = 0., norm_factor_mesh = 0., norm_factor_meshes = 0.;
517 if (params.
npoint ==
"2pt") {
519 catalogue_for_norm, alpha_for_norm
522 catalogue_for_norm, params, alpha_for_norm
528 const double PADDING = 0.1;
529 const double CELLSIZE = 10.;
530 const std::string ASSIGNMENT =
"cic";
535 catalogue_data, catalogue_rand, params, alpha,
536 PADDING, CELLSIZE, ASSIGNMENT
540 if (params.
npoint ==
"3pt") {
542 catalogue_for_norm, alpha_for_norm
545 catalogue_for_norm, params, alpha_for_norm
549 double norm_factor = 0.;
550 if (params.
npoint !=
"none") {
555 "Normalisation factors: "
556 "%.6e (particle), %.6e (mesh), %.6e (mesh-mixed) (none used).",
557 norm_factor_part, norm_factor_mesh, norm_factor_meshes
562 norm_factor = norm_factor_part;
565 "Normalisation factors: "
566 "%.6e (particle; used), %.6e (mesh), %.6e (mesh-mixed).",
567 norm_factor, norm_factor_mesh, norm_factor_meshes
572 norm_factor = norm_factor_mesh;
575 "Normalisation factors: "
576 "%.6e (particle), %.6e (mesh; used), %.6e (mesh-mixed).",
577 norm_factor_part, norm_factor, norm_factor_meshes
582 norm_factor = norm_factor_meshes;
585 "Normalisation factors: "
586 "%.6e (particle), %.6e (mesh), %.6e (mesh-mixed; used).",
587 norm_factor_part, norm_factor_mesh, norm_factor
597 char save_filepath[1024];
600 save_filepath,
sizeof(save_filepath),
"%s/pk%d%s",
603 std::FILE* save_fileptr =
nullptr;
607 catalogue_data, catalogue_rand, los_data, los_rand,
608 params, binning, norm_factor
610 save_fileptr = std::fopen(save_filepath,
"w");
612 save_fileptr, params, catalogue_data, catalogue_rand,
613 norm_factor_part, norm_factor_mesh, norm_factor_meshes
618 catalogue_data, params, binning, norm_factor
620 save_fileptr = std::fopen(save_filepath,
"w");
622 save_fileptr, params, catalogue_data,
623 norm_factor_part, norm_factor_mesh, norm_factor_meshes
627 save_fileptr, params, meas_powspec
629 std::fclose(save_fileptr);
633 save_filepath,
sizeof(save_filepath),
"%s/xi%d%s",
636 std::FILE* save_fileptr =
nullptr;
640 catalogue_data, catalogue_rand, los_data, los_rand,
641 params, binning, norm_factor
643 save_fileptr = std::fopen(save_filepath,
"w");
645 save_fileptr, params, catalogue_data, catalogue_rand,
646 norm_factor_part, norm_factor_mesh, norm_factor_meshes
651 catalogue_data, params, binning, norm_factor
653 save_fileptr = std::fopen(save_filepath,
"w");
655 save_fileptr, params, catalogue_data,
656 norm_factor_part, norm_factor_mesh, norm_factor_meshes
660 save_fileptr, params, meas_2pcf
662 std::fclose(save_fileptr);
666 save_filepath,
sizeof(save_filepath),
"%s/xiw%d%s",
671 catalogue_rand, los_rand, params, binning, alpha, norm_factor
673 std::FILE* save_fileptr = std::fopen(save_filepath,
"w");
675 save_fileptr, params, catalogue_rand,
676 norm_factor_part, norm_factor_mesh, norm_factor_meshes
679 save_fileptr, params, meas_2pcf_win
681 std::fclose(save_fileptr);
684 if (params.
form ==
"full" || params.
form ==
"diag") {
686 save_filepath,
sizeof(save_filepath),
"%s/bk%d%d%d_%s%s",
693 if (params.
form ==
"off-diag") {
695 save_filepath,
sizeof(save_filepath),
"%s/bk%d%d%d_offdiag%d%s",
701 if (params.
form ==
"row") {
703 save_filepath,
sizeof(save_filepath),
"%s/bk%d%d%d_row%d%s",
709 std::FILE* save_fileptr =
nullptr;
713 catalogue_data, catalogue_rand, los_data, los_rand,
714 params, binning, norm_factor
716 save_fileptr = std::fopen(save_filepath,
"w");
718 save_fileptr, params, catalogue_data, catalogue_rand,
719 norm_factor_part, norm_factor_mesh, norm_factor_meshes
724 catalogue_data, params, binning, norm_factor
726 save_fileptr = std::fopen(save_filepath,
"w");
728 save_fileptr, params, catalogue_data,
729 norm_factor_part, norm_factor_mesh, norm_factor_meshes
733 save_fileptr, params, meas_bispec
735 std::fclose(save_fileptr);
738 if (params.
form ==
"full" || params.
form ==
"diag") {
740 save_filepath,
sizeof(save_filepath),
"%s/zeta%d%d%d_%s%s",
747 if (params.
form ==
"off-diag") {
749 save_filepath,
sizeof(save_filepath),
"%s/zeta%d%d%d_offdiag%d%s",
755 if (params.
form ==
"row") {
757 save_filepath,
sizeof(save_filepath),
"%s/zeta%d%d%d_row%d%s",
763 std::FILE* save_fileptr =
nullptr;
767 catalogue_data, catalogue_rand, los_data, los_rand,
768 params, binning, norm_factor
770 save_fileptr = std::fopen(save_filepath,
"w");
772 save_fileptr, params, catalogue_data, catalogue_rand,
773 norm_factor_part, norm_factor_mesh, norm_factor_meshes
778 catalogue_data, params, binning, norm_factor
780 save_fileptr = std::fopen(save_filepath,
"w");
782 save_fileptr, params, catalogue_data,
783 norm_factor_part, norm_factor_mesh, norm_factor_meshes
787 save_fileptr, params, meas_3pcf
789 std::fclose(save_fileptr);
792 if (params.
form ==
"full" || params.
form ==
"diag") {
794 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_%s%s",
801 if (params.
form ==
"off-diag") {
803 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_offdiag%d%s",
809 if (params.
form ==
"row") {
811 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_row%d%s",
820 catalogue_rand, los_rand, params, binning, alpha, norm_factor, wa
822 std::FILE* save_fileptr = std::fopen(save_filepath,
"w");
824 save_fileptr, params, catalogue_rand,
825 norm_factor_part, norm_factor_mesh, norm_factor_meshes
828 save_fileptr, params, meas_3pcf_win
830 std::fclose(save_fileptr);
833 if (params.
form ==
"full" || params.
form ==
"diag") {
835 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_wa%d%d_%s%s",
842 if (params.
form ==
"off-diag") {
844 save_filepath,
sizeof(save_filepath),
845 "%s/zetaw%d%d%d_wa%d%d_offdiag%d%s",
852 if (params.
form ==
"row") {
854 save_filepath,
sizeof(save_filepath),
"%s/zetaw%d%d%d_wa%d%d_row%d%s",
866 catalogue_rand, los_rand, params, binning, alpha, norm_factor, wa
868 std::FILE* save_fileptr = std::fopen(save_filepath,
"w");
870 save_fileptr, params, catalogue_rand,
871 norm_factor_part, norm_factor_mesh, norm_factor_meshes
874 save_fileptr, params, meas_3pcf_win_wa
876 std::fclose(save_fileptr);
886 save_filepath,
sizeof(save_filepath),
"%s",
906#if defined(TRV_USE_OMP) && defined(TRV_USE_FFTWOMP)
907 fftw_cleanup_threads();
916 if (los_data !=
nullptr) {
917 delete[] los_data; los_data =
nullptr;
919 if (los_rand !=
nullptr) {
920 delete[] los_rand; los_rand =
nullptr;
929 "Number of FFTs: %d forward, %d backward.",
942 "Maximum number of concurrent 3-d grids: "
943 "%.1f complex-equivalent, %d complex, %d real.",
952 "Minimal estimate of peak memory usage: %.1f gibibytes.",
957 "Minimal estimate of peak GPU memory usage: %.1f gibibytes.",
965 "Uncleared dynamically allocated memory: %.1f gibibytes.",
973 "Uncleared dynamically allocated GPU 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
long long nmesh
number of mesh grid cells
std::string output_tag
output tag
std::string catalogue_dataset
catalogue dataset name/path (HDF5 catalogue files only)
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 cell 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.
int load_catalogue_file(const std::string &catalogue_filepath, const std::string &catalogue_columns, const std::string &catalogue_dataset="", double volume=0.)
Read in a catalogue file.
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.
double pos_span[3]
span of particle coordinates
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.
Exception raised when parameters are invalid.
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
void display_help()
Display help message in stdout.
void update_maxmem(bool gpu=false)
Update the maximum memory usage estimate.
double size_in_gb(long long num)
Return size in gibibytes.
bool is_gpu_enabled()
Check if GPU mode is enabled.
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.
void display_prog_licence(bool brief=false)
Display program licence in stdout.
double gbytesMemGPU
current (GPU) memory usage in gibibytes
bool if_filepath_is_set(const std::string &pathstr)
Check if a file path is set.
double gbytesMaxMemGPU
maximum (GPU) memory usage in gibibytes
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(bool runtime=false)
Display program information in stdout.
void exit_fatal(const std::string &msg)
Terminate the program with exit status EXIT_FAILURE.
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...
void set_ngrid_from_cutoff(trv::ParameterSet ¶ms)
Set the grid cell numbers from the box size and the Nyquist cutoff.
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.
void set_boxsize_from_expand(const double *spans, trv::ParameterSet ¶ms)
Set the box size parameters from the box expansion factor.
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.
void override_paramset_by_envvars(trv::ParameterSet ¶ms)
Override parameter set by environment variables.
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.