From 7ce02006f279b84e8782397ea27ebb56e7de519a Mon Sep 17 00:00:00 2001 From: froejdh_e Date: Fri, 10 Jan 2025 17:26:23 +0100 Subject: [PATCH] clear pedestal --- include/aare/ClusterFile.hpp | 9 ++++++- include/aare/ClusterFinder.hpp | 1 + include/aare/ClusterFinderMT.hpp | 9 +++++++ include/aare/Pedestal.hpp | 4 ++- python/src/cluster.hpp | 2 ++ src/ClusterFile.cpp | 42 +++++++++++++++++--------------- 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/include/aare/ClusterFile.hpp b/include/aare/ClusterFile.hpp index 82740785..8a0a907b 100644 --- a/include/aare/ClusterFile.hpp +++ b/include/aare/ClusterFile.hpp @@ -33,6 +33,12 @@ typedef enum { pTopRight = 8 } pixel; +struct Eta2 { + double x; + double y; + corner c; +}; + struct ClusterAnalysis { uint32_t c; int32_t tot; @@ -74,7 +80,8 @@ int analyze_data(int32_t *data, int32_t *t2, int32_t *t3, char *quad, int analyze_cluster(Cluster3x3& cl, int32_t *t2, int32_t *t3, char *quad, double *eta2x, double *eta2y, double *eta3x, double *eta3y); + NDArray calculate_eta2( ClusterVector& clusters); -std::array calculate_eta2( Cluster3x3& cl); +Eta2 calculate_eta2( Cluster3x3& cl); } // namespace aare diff --git a/include/aare/ClusterFinder.hpp b/include/aare/ClusterFinder.hpp index 4a06c311..84b207b3 100644 --- a/include/aare/ClusterFinder.hpp +++ b/include/aare/ClusterFinder.hpp @@ -47,6 +47,7 @@ class ClusterFinder { NDArray pedestal() { return m_pedestal.mean(); } NDArray noise() { return m_pedestal.std(); } + void clear_pedestal() { m_pedestal.clear(); } /** * @brief Move the clusters from the ClusterVector in the ClusterFinder to a diff --git a/include/aare/ClusterFinderMT.hpp b/include/aare/ClusterFinderMT.hpp index 6090ca8f..1efb8439 100644 --- a/include/aare/ClusterFinderMT.hpp +++ b/include/aare/ClusterFinderMT.hpp @@ -215,6 +215,15 @@ class ClusterFinderMT { m_current_thread++; } + void clear_pedestal() { + if (!m_processing_threads_stopped) { + throw std::runtime_error("ClusterFinderMT is still running"); + } + for (auto &cf : m_cluster_finders) { + cf->clear_pedestal(); + } + } + /** * @brief Return the pedestal currently used by the cluster finder * @param thread_index index of the thread diff --git a/include/aare/Pedestal.hpp b/include/aare/Pedestal.hpp index ab73cb9b..102d7304 100644 --- a/include/aare/Pedestal.hpp +++ b/include/aare/Pedestal.hpp @@ -89,6 +89,7 @@ template class Pedestal { m_sum = 0; m_sum2 = 0; m_cur_samples = 0; + m_mean = 0; } @@ -97,6 +98,7 @@ template class Pedestal { m_sum(row, col) = 0; m_sum2(row, col) = 0; m_cur_samples(row, col) = 0; + m_mean(row, col) = 0; } @@ -119,7 +121,7 @@ template class Pedestal { /** * Push but don't update the cached mean. Speeds up the process - * when intitializing the pedestal. + * when initializing the pedestal. * */ template void push_no_update(NDView frame) { diff --git a/python/src/cluster.hpp b/python/src/cluster.hpp index 768593a7..e9718865 100644 --- a/python/src/cluster.hpp +++ b/python/src/cluster.hpp @@ -72,6 +72,7 @@ void define_cluster_finder_mt_bindings(py::module &m) { return; }, py::arg(), py::arg("frame_number") = 0) + .def("clear_pedestal", &ClusterFinderMT::clear_pedestal) .def("sync", &ClusterFinderMT::sync) .def("stop", &ClusterFinderMT::stop) .def("start", &ClusterFinderMT::start) @@ -121,6 +122,7 @@ void define_cluster_finder_bindings(py::module &m) { auto view = make_view_2d(frame); self.push_pedestal_frame(view); }) + .def("clear_pedestal", &ClusterFinder::clear_pedestal) .def_property_readonly("pedestal", [](ClusterFinder &self) { auto pd = new NDArray{}; diff --git a/src/ClusterFile.cpp b/src/ClusterFile.cpp index 4d0d6df8..48f5c9ae 100644 --- a/src/ClusterFile.cpp +++ b/src/ClusterFile.cpp @@ -262,19 +262,19 @@ std::vector ClusterFile::read_cluster_with_cut(size_t n_clusters, NDArray calculate_eta2(ClusterVector &clusters) { NDArray eta2({static_cast(clusters.size()), 2}); for (size_t i = 0; i < clusters.size(); i++) { - // int32_t t2; - // auto* ptr = reinterpret_cast (clusters.element_ptr(i) + 2 * - // sizeof(int16_t)); analyze_cluster(clusters.at(i), &t2, - // nullptr, nullptr, &eta2(i,0), &eta2(i,1) , nullptr, nullptr); - auto [x, y] = calculate_eta2(clusters.at(i)); - eta2(i, 0) = x; - eta2(i, 1) = y; + auto e = calculate_eta2(clusters.at(i)); + eta2(i, 0) = e.x; + eta2(i, 1) = e.y; } return eta2; } -std::array calculate_eta2(Cluster3x3 &cl) { - std::array eta2{}; +/** + * @brief Calculate the eta2 values for a 3x3 cluster and return them in a Eta2 struct + * containing etay, etax and the corner of the cluster. +*/ +Eta2 calculate_eta2(Cluster3x3 &cl) { + Eta2 eta{}; std::array tot2; tot2[0] = cl.data[0] + cl.data[1] + cl.data[3] + cl.data[4]; @@ -287,39 +287,43 @@ std::array calculate_eta2(Cluster3x3 &cl) { switch (c) { case cBottomLeft: if ((cl.data[3] + cl.data[4]) != 0) - eta2[0] = + eta.x = static_cast(cl.data[4]) / (cl.data[3] + cl.data[4]); if ((cl.data[1] + cl.data[4]) != 0) - eta2[1] = + eta.y = static_cast(cl.data[4]) / (cl.data[1] + cl.data[4]); + eta.c = cBottomLeft; break; case cBottomRight: if ((cl.data[2] + cl.data[5]) != 0) - eta2[0] = + eta.x = static_cast(cl.data[5]) / (cl.data[4] + cl.data[5]); if ((cl.data[1] + cl.data[4]) != 0) - eta2[1] = + eta.y = static_cast(cl.data[4]) / (cl.data[1] + cl.data[4]); + eta.c = cBottomRight; break; case cTopLeft: if ((cl.data[7] + cl.data[4]) != 0) - eta2[0] = + eta.x = static_cast(cl.data[4]) / (cl.data[3] + cl.data[4]); if ((cl.data[7] + cl.data[4]) != 0) - eta2[1] = + eta.y = static_cast(cl.data[7]) / (cl.data[7] + cl.data[4]); + eta.c = cTopLeft; break; case cTopRight: if ((cl.data[5] + cl.data[4]) != 0) - eta2[0] = + eta.x = static_cast(cl.data[5]) / (cl.data[5] + cl.data[4]); if ((cl.data[7] + cl.data[4]) != 0) - eta2[1] = + eta.y = static_cast(cl.data[7]) / (cl.data[7] + cl.data[4]); + eta.c = cTopRight; break; - // default:; + // no default to allow compiler to warn about missing cases } - return eta2; + return eta; } int analyze_cluster(Cluster3x3 &cl, int32_t *t2, int32_t *t3, char *quad,