From eb6862ff9913726273878e198a76d662b21c1074 Mon Sep 17 00:00:00 2001 From: mazzol_a Date: Fri, 25 Apr 2025 12:03:59 +0200 Subject: [PATCH] changed name of GainMap to InvertedGainMap --- include/aare/CalculateEta.hpp | 4 ++-- include/aare/ClusterFile.hpp | 19 ++++++++++++------- include/aare/ClusterVector.hpp | 12 +++++++----- include/aare/GainMap.hpp | 24 ++++++++++++++---------- python/src/cluster_file.hpp | 3 --- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/include/aare/CalculateEta.hpp b/include/aare/CalculateEta.hpp index 37bdf00..db17dad 100644 --- a/include/aare/CalculateEta.hpp +++ b/include/aare/CalculateEta.hpp @@ -40,8 +40,8 @@ template calculate_eta2(const ClusterVector &clusters) { NDArray eta2({static_cast(clusters.size()), 2}); - for (const ClusterType &cluster : clusters) { - auto e = calculate_eta2(cluster); + for (size_t i = 0; i < clusters.size(); i++) { + auto e = calculate_eta2(clusters[i]); eta2(i, 0) = e.x; eta2(i, 1) = e.y; } diff --git a/include/aare/ClusterFile.hpp b/include/aare/ClusterFile.hpp index f705cfa..ef78874 100644 --- a/include/aare/ClusterFile.hpp +++ b/include/aare/ClusterFile.hpp @@ -46,8 +46,8 @@ class ClusterFile { std::optional m_roi; /*Region of interest, will be applied if set*/ std::optional> m_noise_map; /*Noise map to cut photons, will be applied if set*/ - std::optional m_gain_map; /*Gain map to apply to the clusters, will - be applied if set*/ + std::optional m_gain_map; /*Gain map to apply to the + clusters, will be applied if set*/ public: /** @@ -160,16 +160,21 @@ class ClusterFile { } /** - * @brief Set the gain map to use when reading clusters. If set the gain map will be applied - * to the clusters that pass ROI and noise_map selection. The gain map is expected to be in ADU/energy. + * @brief Set the gain map to use when reading clusters. If set the gain map + * will be applied to the clusters that pass ROI and noise_map selection. + * The gain map is expected to be in ADU/energy. */ void set_gain_map(const NDView gain_map) { - m_gain_map = GainMap(gain_map); + m_gain_map = InvertedGainMap(gain_map); } - void set_gain_map(const GainMap &gain_map) { m_gain_map = gain_map; } + void set_gain_map(const InvertedGainMap &gain_map) { + m_gain_map = gain_map; + } - void set_gain_map(const GainMap &&gain_map) { m_gain_map = gain_map; } + void set_gain_map(const InvertedGainMap &&gain_map) { + m_gain_map = gain_map; + } /** * @brief Close the file. If not closed the file will be diff --git a/include/aare/ClusterVector.hpp b/include/aare/ClusterVector.hpp index 5630278..c8b1ea1 100644 --- a/include/aare/ClusterVector.hpp +++ b/include/aare/ClusterVector.hpp @@ -76,8 +76,9 @@ class ClusterVector> { std::vector sum() { std::vector sums(m_data.size()); - std::transform(m_data.begin(), m_data.end(), sums.begin(), - [](const T &cluster) { return cluster.sum(); }); + std::transform( + m_data.begin(), m_data.end(), sums.begin(), + [](const ClusterType &cluster) { return cluster.sum(); }); return sums; } @@ -90,9 +91,10 @@ class ClusterVector> { std::vector sum_2x2() { std::vector sums_2x2(m_data.size()); - std::transform( - m_data.begin(), m_data.end(), sums_2x2.begin(), - [](const T &cluster) { return cluster.max_sum_2x2().first; }); + std::transform(m_data.begin(), m_data.end(), sums_2x2.begin(), + [](const ClusterType &cluster) { + return cluster.max_sum_2x2().first; + }); return sums_2x2; } diff --git a/include/aare/GainMap.hpp b/include/aare/GainMap.hpp index 23ed467..ac558d0 100644 --- a/include/aare/GainMap.hpp +++ b/include/aare/GainMap.hpp @@ -1,6 +1,7 @@ /************************************************ - * @file ApplyGainMap.hpp - * @short function to apply gain map of image size to a vector of clusters + * @file GainMap.hpp + * @short function to apply gain map of image size to a vector of clusters - + *note stored gainmap is inverted for efficient aaplication to images ***********************************************/ #pragma once @@ -12,18 +13,17 @@ namespace aare { -class GainMap { +class InvertedGainMap { public: - explicit GainMap(const NDArray &gain_map) + explicit InvertedGainMap(const NDArray &gain_map) : m_gain_map(gain_map) { - for (auto &item : m_gain_map) { + for (auto &item : m_gain_map) { item = 1.0 / item; } + }; - }; - - explicit GainMap(const NDView gain_map) { + explicit InvertedGainMap(const NDView gain_map) { m_gain_map = NDArray(gain_map); for (auto &item : m_gain_map) { item = 1.0 / item; @@ -41,14 +41,18 @@ class GainMap { int64_t index_cluster_center_x = ClusterSizeX / 2; int64_t index_cluster_center_y = ClusterSizeY / 2; - for (T &cl : clustervec) { + for (size_t i = 0; i < clustervec.size(); i++) { + auto &cl = clustervec[i]; if (cl.x > 0 && cl.y > 0 && cl.x < m_gain_map.shape(1) - 1 && cl.y < m_gain_map.shape(0) - 1) { for (size_t j = 0; j < ClusterSizeX * ClusterSizeY; j++) { size_t x = cl.x + j % ClusterSizeX - index_cluster_center_x; size_t y = cl.y + j / ClusterSizeX - index_cluster_center_y; - cl.data[j] = static_cast(cl.data[j] * m_gain_map(y, x)); //cast after conversion to keep precision + cl.data[j] = static_cast( + static_cast(cl.data[j]) * + m_gain_map( + y, x)); // cast after conversion to keep precision } } else { // clear edge clusters diff --git a/python/src/cluster_file.hpp b/python/src/cluster_file.hpp index 3e7aa48..ac384b2 100644 --- a/python/src/cluster_file.hpp +++ b/python/src/cluster_file.hpp @@ -59,9 +59,6 @@ void define_cluster_file_io_bindings(py::module &m, self.set_gain_map(view); }) - // void set_gain_map(const GainMap &gain_map); //TODO do i need a - // gainmap constructor? - .def("close", &ClusterFile::close) .def("write_frame", &ClusterFile::write_frame) .def("__enter__", [](ClusterFile &self) { return &self; })