diff --git a/include/aare/Cluster.hpp b/include/aare/Cluster.hpp index cc102c4..46be10d 100644 --- a/include/aare/Cluster.hpp +++ b/include/aare/Cluster.hpp @@ -100,4 +100,20 @@ struct is_cluster> : std::true_type {}; // Cluster template constexpr bool is_cluster_v = is_cluster::value; +template >> +struct extract_template_arguments; // Forward declaration + +// helper struct to extract template argument +template +struct extract_template_arguments< + Cluster> { + + using type = T; + static constexpr int cluster_size_x = ClusterSizeX; + static constexpr int cluster_size_y = ClusterSizeY; + using coordtype = CoordType; +}; + } // namespace aare diff --git a/include/aare/ClusterFile.hpp b/include/aare/ClusterFile.hpp index eb6cc86..bc0ebd1 100644 --- a/include/aare/ClusterFile.hpp +++ b/include/aare/ClusterFile.hpp @@ -429,16 +429,24 @@ bool ClusterFile::is_selected(ClusterType &cl) { return false; } } - // TODO types are wrong generalize + + auto cluster_size_x = extract_template_arguments< + std::remove_reference_t>::cluster_size_x; + auto cluster_size_y = extract_template_arguments< + std::remove_reference_t>::cluster_size_y; + + size_t cluster_center_index = + (cluster_size_x / 2) + (cluster_size_y / 2) * cluster_size_x; + if (m_noise_map) { - int32_t sum_1x1 = cl.data[4]; // central pixel - int32_t sum_2x2 = - cl.max_sum_2x2().first; // highest sum of 2x2 subclusters - int32_t sum_3x3 = cl.sum(); // sum of all pixels + auto sum_1x1 = cl.data[cluster_center_index]; // central pixel + auto sum_2x2 = cl.max_sum_2x2().first; // highest sum of 2x2 subclusters + auto total_sum = cl.sum(); // sum of all pixels auto noise = (*m_noise_map)(cl.y, cl.x); // TODO! check if this is correct - if (sum_1x1 <= noise || sum_2x2 <= 2 * noise || sum_3x3 <= 3 * noise) { + if (sum_1x1 <= noise || sum_2x2 <= 2 * noise || + total_sum <= 3 * noise) { return false; } } diff --git a/src/ClusterVector.test.cpp b/src/ClusterVector.test.cpp index c354891..c6a36d8 100644 --- a/src/ClusterVector.test.cpp +++ b/src/ClusterVector.test.cpp @@ -187,8 +187,8 @@ TEST_CASE("Concatenate two cluster vectors where we need to allocate", } struct ClusterTestData { - int8_t ClusterSizeX; - int8_t ClusterSizeY; + uint8_t ClusterSizeX; + uint8_t ClusterSizeY; std::vector index_map_x; std::vector index_map_y; }; @@ -213,8 +213,8 @@ TEST_CASE("Gain Map Calculation Index Map", "[.ClusterVector][.gain_map]") { {-2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}}); - int8_t ClusterSizeX = clustertestdata.ClusterSizeX; - int8_t ClusterSizeY = clustertestdata.ClusterSizeY; + uint8_t ClusterSizeX = clustertestdata.ClusterSizeX; + uint8_t ClusterSizeY = clustertestdata.ClusterSizeY; std::vector index_map_x(ClusterSizeX * ClusterSizeY); std::vector index_map_y(ClusterSizeX * ClusterSizeY);