From 09399f7b8263379b0a2f7feccf9585ad5f8b94ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Fr=C3=B6jdh?= Date: Mon, 3 Aug 2026 10:08:25 +0200 Subject: [PATCH] format --- include/aare/ClusterFinder.hpp | 34 +++++++++++------------- include/aare/FastPedestal.hpp | 27 +++++++------------ include/aare/hist/PixelHistogramImpl.hpp | 6 ++--- python/src/bind_Cluster.hpp | 1 - python/src/bind_ClusterCollector.hpp | 1 - python/src/bind_ClusterFileSink.hpp | 4 +-- python/src/bind_ClusterFinder.hpp | 1 - python/src/bind_ClusterFinderMT.hpp | 1 - python/src/bind_ClusterVector.hpp | 1 - python/src/module_config.hpp | 2 +- 10 files changed, 30 insertions(+), 48 deletions(-) diff --git a/include/aare/ClusterFinder.hpp b/include/aare/ClusterFinder.hpp index af41cda..ef4daa5 100644 --- a/include/aare/ClusterFinder.hpp +++ b/include/aare/ClusterFinder.hpp @@ -3,10 +3,10 @@ #include "aare/ClusterFile.hpp" #include "aare/ClusterVector.hpp" #include "aare/Dtype.hpp" +#include "aare/FastPedestal.hpp" #include "aare/NDArray.hpp" #include "aare/NDView.hpp" #include "aare/Pedestal.hpp" -#include "aare/FastPedestal.hpp" #include "aare/defs.hpp" #include @@ -74,8 +74,6 @@ class ClusterFinder { NDArray noise() { return m_pedestal.std(); } void clear_pedestal() { m_pedestal.clear(); } - - void update_threshold() { m_threshold = m_pedestal.std() * m_nSigma; } /** @@ -94,6 +92,7 @@ class ClusterFinder { m_clusters = ClusterVector{}; return tmp; } + private: /** * @brief Process a single pixel: scan its cluster window, decide whether it @@ -102,8 +101,8 @@ class ClusterFinder { * (border pixels), if false they are assumed in bounds (interior pixels). */ template - void process_pixel(const NDView &frame, - const int iy, const int ix) { + void process_pixel(const NDView &frame, const int iy, + const int ix) { constexpr int dy = ClusterSizeY / 2; constexpr int dx = ClusterSizeX / 2; constexpr int has_center_pixel_x = ClusterSizeX % 2; @@ -114,9 +113,9 @@ class ClusterFinder { const int cols = static_cast(frame.shape(1)); const int rows = static_cast(frame.shape(0)); - const auto center = (static_cast(iy) * - static_cast(cols)) + - static_cast(ix); + const auto center = + (static_cast(iy) * static_cast(cols)) + + static_cast(ix); const auto *corrected = m_pd_corrected_frame.data(); const PEDESTAL_TYPE threshold = m_threshold.data()[center]; const PEDESTAL_TYPE value = corrected[center]; @@ -140,9 +139,9 @@ class ClusterFinder { } } else { for (int ir = -dy; ir < dy + has_center_pixel_y; ir++) { - const auto *pixel = - corrected + static_cast(iy + ir) * cols + - (ix - dx); + const auto *pixel = corrected + + static_cast(iy + ir) * cols + + (ix - dx); for (int k = 0; k < ClusterSizeX; k++) { const PEDESTAL_TYPE val = pixel[k]; total += val; @@ -177,9 +176,9 @@ class ClusterFinder { const PEDESTAL_TYPE corrected_value = corrected[(static_cast(y) * cols) + x]; - if constexpr ( - std::is_integral_v && - std::is_floating_point_v) { + if constexpr (std::is_integral_v && + std::is_floating_point_v< + PEDESTAL_TYPE>) { cluster.data[i] = static_cast( std::lround(corrected_value)); } else { @@ -236,15 +235,14 @@ class ClusterFinder { m_clusters.set_frame_number(frame_number); - - const int rows = static_cast(frame.shape(0)); const int cols = static_cast(frame.shape(1)); // TODO! See if we can get the same performace using the operator- // m_pd_corrected_frame = frame - m_pedestal.view(); - - //here we should be able to safely assume that the frame and corrected frame have the same size + + // here we should be able to safely assume that the frame and corrected + // frame have the same size auto n_pixels = frame.size(); auto pd = m_pedestal.view().data(); auto corrected = m_pd_corrected_frame.data(); diff --git a/include/aare/FastPedestal.hpp b/include/aare/FastPedestal.hpp index b371be9..a6c200c 100644 --- a/include/aare/FastPedestal.hpp +++ b/include/aare/FastPedestal.hpp @@ -18,17 +18,17 @@ namespace aare { template class FastPedestal { // Did we accumulate enough samples and updated the mean? - bool m_ready = false; + bool m_ready = false; uint32_t m_rows; uint32_t m_cols; uint32_t m_samples; - double m_inv_samples; // precompute 1/m_samples for faster division + double m_inv_samples; // precompute 1/m_samples for faster division uint32_t m_cur_samples = 0; // number of samples accumulated so far - // For cache locality we want to keep sum and sum2 close. Improves performance - // for random access. + // For cache locality we want to keep sum and sum2 close. Improves + // performance for random access. struct Entry { double sum; double sum2; @@ -46,11 +46,11 @@ template class FastPedestal { size_t rc_to_index(uint32_t row, uint32_t col) const { return (static_cast(row) * m_cols) + col; } + public: FastPedestal(uint32_t rows, uint32_t cols, uint32_t n_samples = 1000) : m_rows(rows), m_cols(cols), m_samples(n_samples), - m_inv_samples(1.0 / n_samples), - m_sum({rows, cols}, Entry{0, 0}), + m_inv_samples(1.0 / n_samples), m_sum({rows, cols}, Entry{0, 0}), m_mean({rows, cols}, PEDESTAL_TYPE(0)) { assert(rows > 0 && cols > 0 && n_samples > 0); } @@ -64,9 +64,7 @@ template class FastPedestal { return m_mean(row, col); } - PEDESTAL_TYPE mean(ssize_t index) const { - return m_mean[index]; - } + PEDESTAL_TYPE mean(ssize_t index) const { return m_mean[index]; } NDArray variance() { NDArray res({m_rows, m_cols}); @@ -102,7 +100,6 @@ template class FastPedestal { return std::sqrt(variance(index)); } - bool ready() const { return m_ready; } uint32_t cur_samples() const { return m_cur_samples; } @@ -113,7 +110,6 @@ template class FastPedestal { m_ready = false; } - template void push(NDView frame) { if (frame.shape() != std::array{m_rows, m_cols}) { throw std::runtime_error( @@ -164,7 +160,6 @@ template class FastPedestal { uint32_t cols() const { return m_cols; } uint32_t n_samples() const { return m_samples; } - /** * @brief Update one pixel using its flat index. * @@ -180,18 +175,15 @@ template class FastPedestal { auto &entry = m_sum[index]; entry.sum += val - entry.sum * m_inv_samples; entry.sum2 += val * val - entry.sum2 * m_inv_samples; - m_mean[index] = - static_cast(entry.sum * m_inv_samples); + m_mean[index] = static_cast(entry.sum * m_inv_samples); } - template void push(const uint32_t row, const uint32_t col, const T val_) { if (!ready()) { throw std::runtime_error("Pedestal is not ready, cannot push"); } - const auto index = - (static_cast(row) * m_cols) + col; + const auto index = (static_cast(row) * m_cols) + col; push_fast(index, val_); } @@ -216,6 +208,5 @@ template class FastPedestal { m_mean[i] = static_cast(entry.sum * m_inv_samples); } } - }; } // namespace aare diff --git a/include/aare/hist/PixelHistogramImpl.hpp b/include/aare/hist/PixelHistogramImpl.hpp index 8008ec0..86c1acc 100644 --- a/include/aare/hist/PixelHistogramImpl.hpp +++ b/include/aare/hist/PixelHistogramImpl.hpp @@ -105,15 +105,13 @@ void PixelHistogramImpl::fill_unchecked(int row, int col, int bin = static_cast((value - m_xmin) * m_scale); // Guard against floating-point rounding pushing val just below bin = std::clamp(bin, 0, m_n_bins - 1); - auto& cell = m_values(row, col, bin); + auto &cell = m_values(row, col, bin); if constexpr (std::is_integral_v) { - if (cell >= - std::numeric_limits::max()) { + if (cell >= std::numeric_limits::max()) { return; } } ++cell; - } template diff --git a/python/src/bind_Cluster.hpp b/python/src/bind_Cluster.hpp index 2349b17..5416d04 100644 --- a/python/src/bind_Cluster.hpp +++ b/python/src/bind_Cluster.hpp @@ -11,7 +11,6 @@ namespace py = pybind11; - using namespace aare; #pragma GCC diagnostic push diff --git a/python/src/bind_ClusterCollector.hpp b/python/src/bind_ClusterCollector.hpp index bdbe76b..01dd03c 100644 --- a/python/src/bind_ClusterCollector.hpp +++ b/python/src/bind_ClusterCollector.hpp @@ -18,7 +18,6 @@ namespace py = pybind11; - using namespace aare; #pragma GCC diagnostic push diff --git a/python/src/bind_ClusterFileSink.hpp b/python/src/bind_ClusterFileSink.hpp index 6caf7a2..b366886 100644 --- a/python/src/bind_ClusterFileSink.hpp +++ b/python/src/bind_ClusterFileSink.hpp @@ -27,8 +27,8 @@ void define_ClusterFileSink(py::module &m, const std::string &typestr) { using ClusterType = Cluster; - //TODO! adapt to set pedestal type (needs templating of ClusterFileSink) - //or maybe access through base class? + // TODO! adapt to set pedestal type (needs templating of ClusterFileSink) + // or maybe access through base class? py::class_>(m, class_name.c_str()) .def(py::init *, const std::filesystem::path &>()) diff --git a/python/src/bind_ClusterFinder.hpp b/python/src/bind_ClusterFinder.hpp index fa97915..c13d330 100644 --- a/python/src/bind_ClusterFinder.hpp +++ b/python/src/bind_ClusterFinder.hpp @@ -18,7 +18,6 @@ namespace py = pybind11; - using namespace aare; #pragma GCC diagnostic push diff --git a/python/src/bind_ClusterFinderMT.hpp b/python/src/bind_ClusterFinderMT.hpp index 2484d98..b3acf70 100644 --- a/python/src/bind_ClusterFinderMT.hpp +++ b/python/src/bind_ClusterFinderMT.hpp @@ -18,7 +18,6 @@ namespace py = pybind11; - using namespace aare; #pragma GCC diagnostic push diff --git a/python/src/bind_ClusterVector.hpp b/python/src/bind_ClusterVector.hpp index 08faf49..a0aa9c2 100644 --- a/python/src/bind_ClusterVector.hpp +++ b/python/src/bind_ClusterVector.hpp @@ -16,7 +16,6 @@ namespace py = pybind11; - using namespace aare; #pragma GCC diagnostic push diff --git a/python/src/module_config.hpp b/python/src/module_config.hpp index f166de5..e2f4e8a 100644 --- a/python/src/module_config.hpp +++ b/python/src/module_config.hpp @@ -1,5 +1,5 @@ #pragma once #include -//Configure module wide pedestal type for cluster finding +// Configure module wide pedestal type for cluster finding using pd_type = double; \ No newline at end of file