DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TCMakerChannelAdjacencyAlgorithm.cpp
Go to the documentation of this file.
1
11
12#include "TRACE/trace.h"
13#define TRACE_NAME "TCMakerChannelAdjacencyAlgorithm"
14
15#include <math.h>
16#include <vector>
17
18using namespace triggeralgs;
19
20using Logging::TLVL_DEBUG_ALL;
21using Logging::TLVL_DEBUG_HIGH;
22using Logging::TLVL_DEBUG_MEDIUM;
23using Logging::TLVL_VERY_IMPORTANT;
24
25void
27 std::vector<TriggerCandidate>& output_tc)
28{
29
30 // The first time process() is called, reset window object.
32 m_current_window.reset(activity);
34 }
35
36 // If the difference between the current TA's start time and the start of the window
37 // is less than the specified window size, add the TA to the window.
38 else if ((activity.time_start - m_current_window.time_start) < m_window_length) {
39 TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TCM:CA] Window not yet complete, adding the activity to the window.";
40 m_current_window.add(activity);
41 }
42 // If it is not, move the window along.
43 else {
44 TLOG_DEBUG(TLVL_DEBUG_ALL)
45 << "[TCM:CA] TAWindow is at required length but specified threshold not met, shifting window along.";
47 }
48
49 // If the addition of the current TA to the window would make it longer
50 // than the specified window length, don't add it but check whether the sum of all adc in
51 // the existing window is above the specified threshold. If it is, and we are triggering on ADC,
52 // make a TA and start a fresh window with the current TP.
54 TLOG_DEBUG(TLVL_DEBUG_MEDIUM) << "[TCM:CA] m_current_window.adc_integral " << m_current_window.adc_integral
55 << " - m_adc_threshold " << m_adc_threshold;
57 TLOG_DEBUG(TLVL_DEBUG_MEDIUM) << "[TCM:CA] tc.time_start=" << tc.time_start << " tc.time_end=" << tc.time_end
58 << " len(tc.inputs) " << tc.inputs.size();
59
60 for (const auto& ta : tc.inputs) {
61 TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TCM:CA] [TA] ta.time_start=" << ta.time_start << " ta.time_end=" << ta.time_end
62 << " ta.adc_integral=" << ta.adc_integral;
63 }
64
65 output_tc.push_back(tc);
67 }
68
69 // If the addition of the current TA to the window would make it longer
70 // than the specified window length, don't add it but check whether the number of hit channels in
71 // the existing window is above the specified threshold. If it is, and we are triggering on channels,
72 // make a TC and start a fresh window with the current TA.
74 output_tc.push_back(construct_tc());
76 }
77
79 return;
80}
81
82void
84{
86
87 if (config.is_object()) {
88 if (config.contains("trigger_on_adc"))
89 m_trigger_on_adc = config["trigger_on_adc"];
90 if (config.contains("trigger_on_n_channels"))
91 m_trigger_on_n_channels = config["trigger_on_n_channels"];
92 if (config.contains("adc_threshold"))
93 m_adc_threshold = config["adc_threshold"];
94 if (config.contains("n_channels_threshold"))
95 m_n_channels_threshold = config["n_channels_threshold"];
96 if (config.contains("window_length"))
97 m_window_length = config["window_length"];
98 }
99
100 // Both trigger flags were false. This will never trigger.
102 TLOG_DEBUG(TLVL_VERY_IMPORTANT) << "[TCM:CA] Not triggering! All trigger flags are false!";
103 throw BadConfiguration(ERS_HERE, TRACE_NAME);
104 }
105
106 return;
107}
108
111{
112 TriggerActivity latest_ta_in_window = m_current_window.inputs.back();
113
116 tc.time_end = latest_ta_in_window.inputs.back().time_start;
118 tc.detid = latest_ta_in_window.detid;
119 tc.type = m_tc_type_out;
121
122 // Take the list of triggeralgs::TriggerActivity in the current
123 // window and convert them (implicitly) to detdataformats'
124 // TriggerActivityData, which is the base class of TriggerActivity
125 for (auto& ta : m_current_window.inputs) {
126 tc.inputs.push_back(ta);
127 if (ta.time_end > tc.time_end) {
128 tc.time_end = ta.time_end;
129 }
130 }
131
132 return tc;
133}
134
135// Functions below this line are for debugging purposes.
136void
138{
139 m_window_record.push_back(window);
140 return;
141}
142
#define ERS_HERE
#define REGISTER_TRIGGER_CANDIDATE_MAKER(tcm_name, tcm_class)
timestamp_t time_start
Definition TAWindow.hpp:52
void clear()
Clear all inputs.
Definition TAWindow.cpp:35
void add(const TriggerActivity &input_ta)
Add the input TA's contribution to the total ADC, increase the hit count of all of the channels which...
Definition TAWindow.cpp:16
std::vector< TriggerActivity > inputs
Definition TAWindow.hpp:55
bool is_empty() const
Definition TAWindow.hpp:22
void reset(TriggerActivity const &input_ta)
Reset window content on the input.
Definition TAWindow.cpp:79
uint16_t n_channels_hit()
Definition TAWindow.hpp:34
void move(TriggerActivity const &input_ta, timestamp_t const &window_length)
Find all of the TAs in the window that need to be removed if the input_ta is to be added and the size...
Definition TAWindow.cpp:45
void process(const TriggerActivity &, std::vector< TriggerCandidate > &)
TA processing function that creates & fills TCs.
TriggerCandidate::Type m_tc_type_out
Configurable TC type output.
virtual void configure(const nlohmann::json &config)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TRACE_NAME
std::vector< TriggerPrimitive > inputs
std::vector< dunedaq::trgdataformats::TriggerActivityData > inputs