summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--process_distributions.cpp66
1 files changed, 66 insertions, 0 deletions
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 <cinttypes>
+#include <cmath>
+#include <fstream>
+#include <sstream>
+#include <string>
+#include <vector>
+#include <iostream>
+#include <iomanip>
+
+int main(int argc, char *argv[]) {
+ std::vector<std::string> 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<double> o(n_moms);
+ std::vector<double> δ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;
+}