From 9cfe1ac5e69c3be367ed3d696b9a53342951ebe5 Mon Sep 17 00:00:00 2001 From: Alice Date: Fri, 30 May 2025 10:54:13 +0200 Subject: [PATCH] function to write to file --- include/aare/AngleCalibration.hpp | 17 ++++++++++++++++- src/AngleCalibration.cpp | 21 +++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/include/aare/AngleCalibration.hpp b/include/aare/AngleCalibration.hpp index 225db4b..f97bd93 100644 --- a/include/aare/AngleCalibration.hpp +++ b/include/aare/AngleCalibration.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -131,7 +132,7 @@ class MythenDetectorSpecifications { ssize_t num_strips() { return num_strips_; } private: - static constexpr size_t strips_per_module_ = 1280; + static constexpr size_t strips_per_module_ = 1280; static constexpr double pitch_ = 0.05; // strip width [mm] static constexpr double min_angle_ = -180.0; // maybe shoudnt be static but configurable @@ -254,11 +255,21 @@ class AngleCalibration { offsets.reserve(mythen_detector->max_modules()); exposure_rate = 1. / mythen_detector->exposure_time(); + + num_bins = mythen_detector->max_angle() / histogram_bin_width - + mythen_detector->min_angle() / + histogram_bin_width; // TODO only works if negative + // and positive angle } /** set the histogram bin width [degrees] */ void set_histogram_bin_width(double bin_width) { histogram_bin_width = bin_width; + + num_bins = mythen_detector->max_angle() / histogram_bin_width - + mythen_detector->min_angle() / + histogram_bin_width; // TODO only works if negative + // and positive angle } double get_histogram_bin_width() { return histogram_bin_width; } @@ -325,6 +336,8 @@ class AngleCalibration { NDView new_statistical_weights, NDView new_errors); + void write_to_file(const std::string &filename); + protected: // TODO: Design maybe have a struct with three vectors, store all three // sets of parameters as member variables @@ -351,6 +364,8 @@ class AngleCalibration { double histogram_bin_width = 0.0036; // [degrees] + ssize_t num_bins{}; + double exposure_rate; std::shared_ptr diff --git a/src/AngleCalibration.cpp b/src/AngleCalibration.cpp index 1c5e82e..3dcef71 100644 --- a/src/AngleCalibration.cpp +++ b/src/AngleCalibration.cpp @@ -151,10 +151,6 @@ double AngleCalibration::angular_strip_width(const size_t strip_index) { void AngleCalibration::calculate_fixed_bin_angle_width_histogram( const size_t start_frame_index, const size_t end_frame_index) { - ssize_t num_bins = mythen_detector->max_angle() / histogram_bin_width - - mythen_detector->min_angle() / - histogram_bin_width; // TODO only works if negative - // and positive angle new_photon_counts = NDArray(std::array{num_bins}); new_photon_count_errors = @@ -276,4 +272,21 @@ void AngleCalibration::redistribute_photon_counts_to_fixed_angle_bins( } } } + +void AngleCalibration::write_to_file(const std::string &filename) { + std::ofstream output_file(filename); + + if (!output_file) { + std::cerr << "Error opening file!" + << std::endl; // TODO: replace with log + } + + output_file << std::fixed << std::setprecision(6); + for (ssize_t i = 0; i < num_bins; ++i) { + output_file << i * histogram_bin_width << " " << new_photon_counts[i] + << " " << new_photon_count_errors[i] << std::endl; + } + output_file.close(); +} + } // namespace aare