mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-01-22 02:42:02 +01:00
function to write to file
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -131,7 +132,7 @@ class MythenDetectorSpecifications {
|
|||||||
ssize_t num_strips() { return num_strips_; }
|
ssize_t num_strips() { return num_strips_; }
|
||||||
|
|
||||||
private:
|
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 pitch_ = 0.05; // strip width [mm]
|
||||||
static constexpr double min_angle_ =
|
static constexpr double min_angle_ =
|
||||||
-180.0; // maybe shoudnt be static but configurable
|
-180.0; // maybe shoudnt be static but configurable
|
||||||
@@ -254,11 +255,21 @@ class AngleCalibration {
|
|||||||
offsets.reserve(mythen_detector->max_modules());
|
offsets.reserve(mythen_detector->max_modules());
|
||||||
|
|
||||||
exposure_rate = 1. / mythen_detector->exposure_time();
|
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] */
|
/** set the histogram bin width [degrees] */
|
||||||
void set_histogram_bin_width(double bin_width) {
|
void set_histogram_bin_width(double bin_width) {
|
||||||
histogram_bin_width = 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; }
|
double get_histogram_bin_width() { return histogram_bin_width; }
|
||||||
@@ -325,6 +336,8 @@ class AngleCalibration {
|
|||||||
NDView<double, 1> new_statistical_weights,
|
NDView<double, 1> new_statistical_weights,
|
||||||
NDView<double, 1> new_errors);
|
NDView<double, 1> new_errors);
|
||||||
|
|
||||||
|
void write_to_file(const std::string &filename);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// TODO: Design maybe have a struct with three vectors, store all three
|
// TODO: Design maybe have a struct with three vectors, store all three
|
||||||
// sets of parameters as member variables
|
// sets of parameters as member variables
|
||||||
@@ -351,6 +364,8 @@ class AngleCalibration {
|
|||||||
|
|
||||||
double histogram_bin_width = 0.0036; // [degrees]
|
double histogram_bin_width = 0.0036; // [degrees]
|
||||||
|
|
||||||
|
ssize_t num_bins{};
|
||||||
|
|
||||||
double exposure_rate;
|
double exposure_rate;
|
||||||
|
|
||||||
std::shared_ptr<MythenFileReader>
|
std::shared_ptr<MythenFileReader>
|
||||||
|
|||||||
@@ -151,10 +151,6 @@ double AngleCalibration::angular_strip_width(const size_t strip_index) {
|
|||||||
void AngleCalibration::calculate_fixed_bin_angle_width_histogram(
|
void AngleCalibration::calculate_fixed_bin_angle_width_histogram(
|
||||||
const size_t start_frame_index, const size_t end_frame_index) {
|
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<double, 1>(std::array<ssize_t, 1>{num_bins});
|
new_photon_counts = NDArray<double, 1>(std::array<ssize_t, 1>{num_bins});
|
||||||
|
|
||||||
new_photon_count_errors =
|
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
|
} // namespace aare
|
||||||
|
|||||||
Reference in New Issue
Block a user