From 0ce6128b4ffc44439e7167e97ad9fcd78e05f4f5 Mon Sep 17 00:00:00 2001 From: froejdh_e Date: Wed, 21 Jan 2026 09:35:06 +0100 Subject: [PATCH 1/2] added rounding in cluster finder --- CMakeLists.txt | 7 ++++--- RELEASE.md | 1 + include/aare/ClusterFinder.hpp | 25 ++++++++++++++++++++----- include/aare/ProducerConsumerQueue.hpp | 1 + 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1de16ae..dfd7357 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -240,9 +240,7 @@ endif() add_library(aare_compiler_flags INTERFACE) target_compile_features(aare_compiler_flags INTERFACE cxx_std_17) -if(AARE_PYTHON_BINDINGS) - add_subdirectory(python) -endif() + ################# # MSVC specific # @@ -308,6 +306,9 @@ target_compile_options( endif() #GCC/Clang specific +if(AARE_PYTHON_BINDINGS) + add_subdirectory(python) +endif() if(AARE_ASAN) message(STATUS "AddressSanitizer enabled") diff --git a/RELEASE.md b/RELEASE.md index d9c0888..6ca6f44 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -16,6 +16,7 @@ ### Bugfixes: - multi threaded cluster finder doesnt drop frames if queues are full + - Round before casting in the cluster finder to avoid biasing clusters by truncating ### 2025.11.21 diff --git a/include/aare/ClusterFinder.hpp b/include/aare/ClusterFinder.hpp index 3f140a9..26ae000 100644 --- a/include/aare/ClusterFinder.hpp +++ b/include/aare/ClusterFinder.hpp @@ -148,12 +148,27 @@ class ClusterFinder { for (int ic = -dx; ic < dx + has_center_pixel_x; ic++) { if (ix + ic >= 0 && ix + ic < frame.shape(1) && iy + ir >= 0 && iy + ir < frame.shape(0)) { - CT tmp = - static_cast(frame(iy + ir, ix + ic)) - - static_cast( + + // If the cluster type is an integral type, and + // the pedestal is a floating point type then we + // need to round the value before storing it + if constexpr (std::is_integral_v /*&& + std::is_floating_point_v< + PEDESTAL_TYPE>*/) { + auto tmp = std::lround( + frame(iy + ir, ix + ic) - m_pedestal.mean(iy + ir, ix + ic)); - cluster.data[i] = - tmp; // Watch for out of bounds access + cluster.data[i] = static_cast(tmp); + } + // On the other hand if both are floating point + // or both are integral then we can just static + // cast directly + else { + auto tmp = + frame(iy + ir, ix + ic) - + m_pedestal.mean(iy + ir, ix + ic); + cluster.data[i] = static_cast(tmp); + } } i++; } diff --git a/include/aare/ProducerConsumerQueue.hpp b/include/aare/ProducerConsumerQueue.hpp index bf24c25..184ceb4 100644 --- a/include/aare/ProducerConsumerQueue.hpp +++ b/include/aare/ProducerConsumerQueue.hpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include From 9d6798b9c521d151a470d696ab2c33d838a7af86 Mon Sep 17 00:00:00 2001 From: froejdh_e Date: Wed, 21 Jan 2026 09:36:17 +0100 Subject: [PATCH 2/2] removed comment --- include/aare/ClusterFinder.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/aare/ClusterFinder.hpp b/include/aare/ClusterFinder.hpp index 26ae000..7d059ff 100644 --- a/include/aare/ClusterFinder.hpp +++ b/include/aare/ClusterFinder.hpp @@ -152,9 +152,9 @@ class ClusterFinder { // If the cluster type is an integral type, and // the pedestal is a floating point type then we // need to round the value before storing it - if constexpr (std::is_integral_v /*&& + if constexpr (std::is_integral_v && std::is_floating_point_v< - PEDESTAL_TYPE>*/) { + PEDESTAL_TYPE>) { auto tmp = std::lround( frame(iy + ir, ix + ic) - m_pedestal.mean(iy + ir, ix + ic));