From 4acf484bafb607fc36ab4530c694cccea2e4524c Mon Sep 17 00:00:00 2001 From: Alessandro Thea Date: Wed, 12 Nov 2025 17:07:17 +0100 Subject: [PATCH 1/3] Properly populating TA fields in the simpleadcwindow ta maker. --- .../TAMakerADCSimpleWindowAlgorithm.hpp | 4 ++-- src/TAMakerADCSimpleWindowAlgorithm.cpp | 23 ++++++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp b/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp index 70b722a..15e5050 100644 --- a/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp +++ b/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp @@ -12,7 +12,7 @@ #include "triggeralgs/TriggerActivityFactory.hpp" #include "triggeralgs/Types.hpp" -#include +#include namespace triggeralgs { class TAMakerADCSimpleWindowAlgorithm : public TriggerActivityMaker @@ -83,7 +83,7 @@ class TAMakerADCSimpleWindowAlgorithm : public TriggerActivityMaker timestamp_t time_start; uint32_t adc_integral; - std::vector tp_list; + std::deque tp_list; }; TriggerActivity construct_ta() const; diff --git a/src/TAMakerADCSimpleWindowAlgorithm.cpp b/src/TAMakerADCSimpleWindowAlgorithm.cpp index d95875b..16a2d88 100644 --- a/src/TAMakerADCSimpleWindowAlgorithm.cpp +++ b/src/TAMakerADCSimpleWindowAlgorithm.cpp @@ -84,23 +84,34 @@ TAMakerADCSimpleWindowAlgorithm::construct_ta() const TLOG_DEBUG(TLVL_DEBUG_LOW) << "[TAM:ADCSW] I am constructing a trigger activity!"; //TLOG_DEBUG(TRACE_NAME) << m_current_window; - TriggerPrimitive latest_tp_in_window = m_current_window.tp_list.back(); - // The time_peak, time_activity, channel_* and adc_peak fields of this TA are irrelevent - // for the purpose of this trigger alg. + const TriggerPrimitive& latest_tp_in_window = m_current_window.tp_list.back(); + uint64_t ch_min{latest_tp_in_window.channel}, ch_max{latest_tp_in_window.channel}; + + std::vector tp_list; + tp_list.reserve(m_current_window.tp_list.size()); + + for( const auto& tp : m_current_window.tp_list ) { + + ch_min = std::min(ch_min, tp.channel); + ch_max = std::max(ch_max, tp.channel); + + tp_list.push_back(tp); + } + TriggerActivity ta; ta.time_start = m_current_window.time_start; ta.time_end = latest_tp_in_window.time_start + latest_tp_in_window.samples_over_threshold * 32; // FIXME: Replace the hard-coded SOT to TOT scaling. ta.time_peak = latest_tp_in_window.samples_to_peak * 32 + latest_tp_in_window.time_start; // FIXME: Replace STP to `time_peak` conversion. ta.time_activity = ta.time_peak; - ta.channel_start = latest_tp_in_window.channel; - ta.channel_end = latest_tp_in_window.channel; + ta.channel_start = ch_min; + ta.channel_end = ch_max; ta.channel_peak = latest_tp_in_window.channel; ta.adc_integral = m_current_window.adc_integral; ta.adc_peak = latest_tp_in_window.adc_peak; ta.detid = latest_tp_in_window.detid; ta.type = TriggerActivity::Type::kTPC; ta.algorithm = TriggerActivity::Algorithm::kADCSimpleWindow; - ta.inputs = m_current_window.tp_list; + ta.inputs.swap(tp_list); return ta; } From 19a5895b92b21e7ab8633dc93ab33d12fdb4a1ea Mon Sep 17 00:00:00 2001 From: Alessandro Thea Date: Wed, 12 Nov 2025 17:27:16 +0100 Subject: [PATCH 2/3] Corrected the remaining TA fields in the SADCWin TA Maker --- src/TAMakerADCSimpleWindowAlgorithm.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/TAMakerADCSimpleWindowAlgorithm.cpp b/src/TAMakerADCSimpleWindowAlgorithm.cpp index 16a2d88..497f037 100644 --- a/src/TAMakerADCSimpleWindowAlgorithm.cpp +++ b/src/TAMakerADCSimpleWindowAlgorithm.cpp @@ -86,6 +86,11 @@ TAMakerADCSimpleWindowAlgorithm::construct_ta() const const TriggerPrimitive& latest_tp_in_window = m_current_window.tp_list.back(); uint64_t ch_min{latest_tp_in_window.channel}, ch_max{latest_tp_in_window.channel}; + uint64_t time_max{latest_tp_in_window.time_start + latest_tp_in_window.samples_over_threshold * 32}; + + uint64_t adc_peak{latest_tp_in_window.adc_peak}; + uint64_t ch_peak{dunedaq::trgdataformats::INVALID_CHANNEL}; + timestamp_t time_peak{dunedaq::trgdataformats::INVALID_TIMESTAMP}; std::vector tp_list; tp_list.reserve(m_current_window.tp_list.size()); @@ -94,20 +99,26 @@ TAMakerADCSimpleWindowAlgorithm::construct_ta() const ch_min = std::min(ch_min, tp.channel); ch_max = std::max(ch_max, tp.channel); + time_max = std::max(time_max, tp.time_start + tp.samples_over_threshold * 32); + if (tp.adc_peak > adc_peak) { + adc_peak = tp.adc_peak; + ch_peak = tp.channel; + time_peak = time_peak; + } tp_list.push_back(tp); } TriggerActivity ta; ta.time_start = m_current_window.time_start; - ta.time_end = latest_tp_in_window.time_start + latest_tp_in_window.samples_over_threshold * 32; // FIXME: Replace the hard-coded SOT to TOT scaling. - ta.time_peak = latest_tp_in_window.samples_to_peak * 32 + latest_tp_in_window.time_start; // FIXME: Replace STP to `time_peak` conversion. + ta.time_end = time_max; + ta.time_peak = time_peak; ta.time_activity = ta.time_peak; ta.channel_start = ch_min; ta.channel_end = ch_max; - ta.channel_peak = latest_tp_in_window.channel; + ta.channel_peak = ch_peak; ta.adc_integral = m_current_window.adc_integral; - ta.adc_peak = latest_tp_in_window.adc_peak; + ta.adc_peak = adc_peak; ta.detid = latest_tp_in_window.detid; ta.type = TriggerActivity::Type::kTPC; ta.algorithm = TriggerActivity::Algorithm::kADCSimpleWindow; From add9886cdc696f264946bce1eccbbfc8bd0fd5c8 Mon Sep 17 00:00:00 2001 From: Alessandro Thea Date: Tue, 18 Nov 2025 15:55:52 +0100 Subject: [PATCH 3/3] Cleanup --- .../TAMakerADCSimpleWindowAlgorithm.hpp | 62 +++----------- src/TAMakerADCSimpleWindowAlgorithm.cpp | 84 ++++++++++++++++++- 2 files changed, 93 insertions(+), 53 deletions(-) diff --git a/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp b/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp index 15e5050..1339709 100644 --- a/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp +++ b/include/triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp @@ -23,69 +23,31 @@ class TAMakerADCSimpleWindowAlgorithm : public TriggerActivityMaker void configure(const nlohmann::json &config); -private: class Window { public: + friend std::ostream& operator<<(std::ostream& os, const Window& window); + bool is_empty() const{ return tp_list.empty(); }; - void add(TriggerPrimitive const &input_tp){ - // Add the input TP's contribution to the total ADC and add it to - // the TP list. - adc_integral += input_tp.adc_integral; - tp_list.push_back(input_tp); - }; + + void add(TriggerPrimitive const &input_tp); + void clear(){ tp_list.clear(); }; - void move(TriggerPrimitive const &input_tp, timestamp_t const &window_length){ - // Find all of the TPs in the window that need to be removed - // if the input_tp is to be added and the size of the window - // is to be conserved. - // Substract those TPs' contribution from the total window ADC. - uint32_t n_tps_to_erase = 0; - for(auto tp : tp_list){ - if(!(input_tp.time_start-tp.time_start < window_length)){ - n_tps_to_erase++; - adc_integral -= tp.adc_integral; - } - else break; - } - // Erase the TPs from the window. - tp_list.erase(tp_list.begin(), tp_list.begin()+n_tps_to_erase); - // Make the window start time the start time of what is now the - // first TP. - if(tp_list.size()!=0){ - time_start = tp_list.front().time_start; - add(input_tp); - } - else reset(input_tp); - }; - void reset(TriggerPrimitive const &input_tp){ - // Empty the TP list. - tp_list.clear(); - // Set the start time of the window to be the start time of the - // input_tp. - time_start = input_tp.time_start; - // Start the total ADC integral. - adc_integral = input_tp.adc_integral; - // Add the input TP to the TP list. - tp_list.push_back(input_tp); - }; - friend std::ostream& operator<<(std::ostream& os, const Window& window){ - if(window.is_empty()) os << "Window is empty!\n"; - else{ - os << "Window start: " << window.time_start << ", end: " << window.tp_list.back().time_start; - os << ". Total of: " << window.adc_integral << " ADC counts with " << window.tp_list.size() << " TPs.\n"; - } - return os; - }; + + void move(TriggerPrimitive const &input_tp, timestamp_t const &window_length); + + void reset(TriggerPrimitive const &input_tp); timestamp_t time_start; uint32_t adc_integral; std::deque tp_list; }; +private: + TriggerActivity construct_ta() const; Window m_current_window; @@ -95,6 +57,8 @@ class TAMakerADCSimpleWindowAlgorithm : public TriggerActivityMaker uint32_t m_adc_threshold = 1200000; timestamp_t m_window_length = 100000; }; + + } // namespace triggeralgs #endif // TRIGGERALGS_ADCSIMPLEWINDOW_TRIGGERACTIVITYMAKERADCSIMPLEWINDOW_HPP_ diff --git a/src/TAMakerADCSimpleWindowAlgorithm.cpp b/src/TAMakerADCSimpleWindowAlgorithm.cpp index 497f037..4cf31ed 100644 --- a/src/TAMakerADCSimpleWindowAlgorithm.cpp +++ b/src/TAMakerADCSimpleWindowAlgorithm.cpp @@ -14,12 +14,80 @@ #include -using namespace triggeralgs; + + +namespace triggeralgs { + +// using namespace triggeralgs; using Logging::TLVL_DEBUG_ALL; using Logging::TLVL_DEBUG_HIGH; using Logging::TLVL_DEBUG_LOW; using Logging::TLVL_IMPORTANT; +void +TAMakerADCSimpleWindowAlgorithm::Window::add(TriggerPrimitive const &input_tp){ + // Add the input TP's contribution to the total ADC and add it to + // the TP list. + adc_integral += input_tp.adc_integral; + tp_list.push_back(input_tp); +}; + +void +TAMakerADCSimpleWindowAlgorithm::Window::move(TriggerPrimitive const &input_tp, timestamp_t const &window_length){ + // Find all of the TPs in the window that need to be removed + // if the input_tp is to be added and the size of the window + // is to be conserved. + // Substract those TPs' contribution from the total window ADC. + uint32_t n_tps_to_erase = 0; + for(auto tp : tp_list){ + if(!(input_tp.time_start-tp.time_start < window_length)){ + n_tps_to_erase++; + adc_integral -= tp.adc_integral; + } + else break; + } + // Erase the TPs from the window. + tp_list.erase(tp_list.begin(), tp_list.begin()+n_tps_to_erase); + // Make the window start time the start time of what is now the + // first TP. + if(tp_list.size()!=0){ + time_start = tp_list.front().time_start; + add(input_tp); + } + else reset(input_tp); +}; + + +void +TAMakerADCSimpleWindowAlgorithm::Window::reset(TriggerPrimitive const &input_tp){ + // Empty the TP list. + tp_list.clear(); + // Set the start time of the window to be the start time of the + // input_tp. + time_start = input_tp.time_start; + // Start the total ADC integral. + adc_integral = input_tp.adc_integral; + // Add the input TP to the TP list. + tp_list.push_back(input_tp); +}; + + + +std::ostream& +operator<<(std::ostream& os, const TAMakerADCSimpleWindowAlgorithm::Window& window) +{ + if (window.is_empty()) { + os << "Window is empty!\n"; + } else { + os << "Window start: " << window.time_start + << ", end: " << window.tp_list.back().time_start + << ". Total of: " << window.adc_integral + << " ADC counts with " << window.tp_list.size() + << " TPs.\n"; + } + return os; +} + void TAMakerADCSimpleWindowAlgorithm::process(const TriggerPrimitive& input_tp, std::vector& output_ta) { @@ -86,7 +154,7 @@ TAMakerADCSimpleWindowAlgorithm::construct_ta() const const TriggerPrimitive& latest_tp_in_window = m_current_window.tp_list.back(); uint64_t ch_min{latest_tp_in_window.channel}, ch_max{latest_tp_in_window.channel}; - uint64_t time_max{latest_tp_in_window.time_start + latest_tp_in_window.samples_over_threshold * 32}; + uint64_t time_min{latest_tp_in_window.time_start}, time_max{latest_tp_in_window.time_start + latest_tp_in_window.samples_over_threshold * 32}; uint64_t adc_peak{latest_tp_in_window.adc_peak}; uint64_t ch_peak{dunedaq::trgdataformats::INVALID_CHANNEL}; @@ -95,10 +163,14 @@ TAMakerADCSimpleWindowAlgorithm::construct_ta() const std::vector tp_list; tp_list.reserve(m_current_window.tp_list.size()); + + // Copy the queue into the vector + // And compute TA parameters for( const auto& tp : m_current_window.tp_list ) { ch_min = std::min(ch_min, tp.channel); ch_max = std::max(ch_max, tp.channel); + time_min = std::min(time_min, tp.time_start); time_max = std::max(time_max, tp.time_start + tp.samples_over_threshold * 32); if (tp.adc_peak > adc_peak) { adc_peak = tp.adc_peak; @@ -110,10 +182,11 @@ TAMakerADCSimpleWindowAlgorithm::construct_ta() const } TriggerActivity ta; - ta.time_start = m_current_window.time_start; + + ta.time_start = time_min; ta.time_end = time_max; ta.time_peak = time_peak; - ta.time_activity = ta.time_peak; + ta.time_activity = time_peak; ta.channel_start = ch_min; ta.channel_end = ch_max; ta.channel_peak = ch_peak; @@ -126,5 +199,8 @@ TAMakerADCSimpleWindowAlgorithm::construct_ta() const return ta; } + // Register algo in TA Factory REGISTER_TRIGGER_ACTIVITY_MAKER(TRACE_NAME, TAMakerADCSimpleWindowAlgorithm) + +}