diff --git a/include/aare/AngleCalibration.hpp b/include/aare/AngleCalibration.hpp index 86bca3c..86a987d 100644 --- a/include/aare/AngleCalibration.hpp +++ b/include/aare/AngleCalibration.hpp @@ -205,16 +205,12 @@ class FlatField { acc.second + 1); }); - std::cout << "sum: " << sum << std::endl; - std::cout << "count: " << count << std::endl; return sum / count; } NDArray inverse_normalized_flatfield(double tolerance = 0.001) { double mean = calculate_mean(tolerance); - std::cout << "mean: " << mean << std::endl; - NDArray inverse_normalized_flatfield(flat_field.shape()); /* diff --git a/include/aare/MythenFileReader.hpp b/include/aare/MythenFileReader.hpp index 0811f76..0602520 100644 --- a/include/aare/MythenFileReader.hpp +++ b/include/aare/MythenFileReader.hpp @@ -34,21 +34,22 @@ class MythenFileReader : public HDF5FileReader { std::string current_file_name = m_base_path / (file_prefix + std::to_string(frame_index) + ".h5"); + MythenFrame frame; open_file(current_file_name); auto dataset_photon_count = get_dataset("/entry/instrument/detector/data"); - NDArray photon_counts = + frame.photon_counts = dataset_photon_count.store_as_ndarray(); + ++frame.photon_counts; + auto dataset_detector_angle = get_dataset("/entry/instrument/NDAttributes/DetectorAngle"); - double detector_angle; - dataset_detector_angle.read_into_buffer( - reinterpret_cast(&detector_angle)); + reinterpret_cast(&frame.detector_angle)); auto dataset_channel_number = get_dataset("/entry/instrument/NDAttributes/CounterMask"); @@ -64,13 +65,13 @@ class MythenFileReader : public HDF5FileReader { // significant // bit is ask Anna again - std::array channel_mask{binary_channel_numbers[0], - binary_channel_numbers[1], - binary_channel_numbers[2]}; + frame.channel_mask = std::array{binary_channel_numbers[0], + binary_channel_numbers[1], + binary_channel_numbers[2]}; close_file(); - return MythenFrame{photon_counts, detector_angle, channel_mask}; + return frame; } private: diff --git a/src/AngleCalibration.cpp b/src/AngleCalibration.cpp index 7917bd6..28a1fcd 100644 --- a/src/AngleCalibration.cpp +++ b/src/AngleCalibration.cpp @@ -236,16 +236,11 @@ void AngleCalibration::redistribute_photon_counts_to_fixed_angle_bins( throw std::runtime_error("wrong number of strips read"); } - // NDArray diffraction_angles( - // std::array{mythen_detector->num_strips()}, 0.0); - - // NDArray angle_widths( - // std::array{mythen_detector->num_strips()}, 0.0); - ssize_t num_bins1 = mythen_detector->min_angle() / histogram_bin_width; ssize_t num_bins2 = mythen_detector->max_angle() / histogram_bin_width; - std::cout << "position: " << frame.detector_angle << std::endl; + std::cout << "position: " << frame.detector_angle + << std::endl; // replace with log for (ssize_t strip_index = 0; strip_index < mythen_detector->num_strips(); ++strip_index) { @@ -274,8 +269,6 @@ void AngleCalibration::redistribute_photon_counts_to_fixed_angle_bins( diffraction_angle += (frame.detector_angle + mythen_detector->dtt0() + mythen_detector->bloffset()); - // diffraction_angles[strip_index] = diffraction_angle; - if (diffraction_angle < mythen_detector->min_angle() || diffraction_angle > mythen_detector->max_angle()) continue; @@ -283,8 +276,6 @@ void AngleCalibration::redistribute_photon_counts_to_fixed_angle_bins( double angle_covered_by_strip = angular_strip_width_from_DG_parameters(strip_index); - // angle_widths[strip_index] = angle_covered_by_strip; - double photon_count_per_bin = histogram_bin_width * corrected_photon_count / angle_covered_by_strip; @@ -331,9 +322,6 @@ void AngleCalibration::redistribute_photon_counts_to_fixed_angle_bins( } } } - - // std::string filename = "angle_widths.txt"; - // save(angle_widths, filename); } void AngleCalibration::write_to_file(const std::string &filename) { diff --git a/src/AngleCalibration.test.cpp b/src/AngleCalibration.test.cpp index 450d28b..162a69c 100644 --- a/src/AngleCalibration.test.cpp +++ b/src/AngleCalibration.test.cpp @@ -10,6 +10,7 @@ #include "test_config.hpp" #include +#include #include #include @@ -19,7 +20,7 @@ using namespace aare; template NDArray read_into_array(const std::string &filename, - const std::array size) { + const std::array size) { std::string word; NDArray array(size); try { @@ -45,11 +46,23 @@ NDArray read_into_array(const std::string &filename, return array; } +template > struct safe_make_signed { + using type = T; +}; + +template struct safe_make_signed { + using type = std::make_signed_t; +}; + template bool check_equality_of_arrays(NDView array1, NDView array2) { bool equal = true; + + using SignedT = typename safe_make_signed::type; + for (ssize_t i = 0; i < array1.size(); ++i) { - if (std::abs(array1[i] - array2[i]) > 1e-10) { + if (std::abs(static_cast(array1[i]) - + static_cast(array2[i])) > 1e-6) { std::cout << "index: " << i << std::endl; std::cout << std::setprecision(15) << array1[i] << std::endl; std::cout << std::setprecision(15) << array2[i] << std::endl; @@ -348,39 +361,21 @@ TEST_CASE("calculate new fixed angle width bins histogram", "cpp_new_photon_counts.xye"); // TODO adjust output path } -TEST_CASE("check diffraction angles") { - auto expected_diffraction_angle_filename = test_data_path() / - "AngleCalibration_Test_Data" / - "diffraction_angle.txt"; - - REQUIRE(std::filesystem::exists(expected_diffraction_angle_filename)); - - auto expected_angles = - read_into_array(expected_diffraction_angle_filename.string(), - std::array{61440}); - - auto diffraction_angle_filename = - std::filesystem::current_path() / "../build/diffraction_angles.txt"; - - auto angles = load(diffraction_angle_filename, - std::array{61440}); - - CHECK(check_equality_of_arrays(angles.view(), expected_angles.view())); -} - -TEST_CASE("check angle widths") { +TEST_CASE("compare result with python code", "[.anglecalibration][.files]") { auto expected_filename = - test_data_path() / "AngleCalibration_Test_Data" / "angle_width.txt"; + test_data_path() / "AngleCalibration_Test_Data" / "out2.xye"; REQUIRE(std::filesystem::exists(expected_filename)); - auto expected_array = read_into_array( - expected_filename.string(), std::array{61440}); + auto expected_array = read_into_array( + expected_filename.string(), std::array{61440, 3}); auto filename = - std::filesystem::current_path() / "../build/angle_widths.txt"; + std::filesystem::current_path() / "../build/cpp_new_photon_counts.xye"; - auto array = load(filename, std::array{61440}); + // auto array = load(filename, std::array{61440, 3}); + auto array = read_into_array(filename.string(), + std::array{61440, 3}); CHECK(check_equality_of_arrays(array.view(), expected_array.view())); }