From 8eb0fbff3470bc56ec798101435f5e90e069b027 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Tue, 30 Jun 2020 14:57:15 -0400 Subject: Added utility for producing moments from raw distributions. --- process_distributions.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 process_distributions.cpp diff --git a/process_distributions.cpp b/process_distributions.cpp new file mode 100644 index 0000000..210b686 --- /dev/null +++ b/process_distributions.cpp @@ -0,0 +1,66 @@ + + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) { + std::vector all_args; + + if (argc > 1) { + all_args.assign(argv + 1, argv + argc); + } + + for (std::string filename : all_args) { + std::ifstream in_file; + in_file.open(filename); + + if (!in_file.is_open()) { + std::cout << "Failed to open " << filename << ".\n"; + } else { + + unsigned n_moms = 5; + std::vector o(n_moms); + std::vector δo(n_moms); + + uint64_t norm = 0; + + uint64_t j = 0; + uint64_t a; + + while (in_file >> a) { + norm += a; + for (unsigned i = 0; i < n_moms; i++) { + o[i] += a * pow(j + 1, i + 1); + δo[i] += a * pow(j + 1, 2 * (i + 1)); + } + j++; + } + + in_file.close(); + + for (unsigned i = 0; i < n_moms; i++) { + o[i] /= norm; + δo[i] = sqrt(δo[i]) / norm; + } + + std::ofstream out_file; + out_file.open(filename + ".processed"); + + for (unsigned i = 0; i < n_moms; i++) { + out_file << o[i] << " " << δo[i] << "\n"; + } + + out_file.close(); + + std::cout << "Finished processing " << filename << ".\n"; + } + } + + return 0; +} -- cgit v1.2.3