DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TAMakerADCSimpleWindowAlgorithm.cpp
Go to the documentation of this file.
1
10
11#include "TRACE/trace.h"
12#define TRACE_NAME "TAMakerADCSimpleWindowAlgorithm"
13
14#include <vector>
15
16
17
18
19namespace triggeralgs {
20
21// using namespace triggeralgs;
26
27void
29 // Add the input TP's contribution to the total ADC and add it to
30 // the TP list.
31 adc_integral += input_tp.adc_integral;
32 tp_list.push_back(input_tp);
33}
34
35void
37 // Find all of the TPs in the window that need to be removed
38 // if the input_tp is to be added and the size of the window
39 // is to be conserved.
40 // Substract those TPs' contribution from the total window ADC.
41 uint32_t n_tps_to_erase = 0;
42 for(auto tp : tp_list){
43 if(input_tp.time_start-tp.time_start >= window_length){
44 n_tps_to_erase++;
45 adc_integral -= tp.adc_integral;
46 } else {
47 break;
48 }
49 }
50 // Erase the TPs from the window.
51 tp_list.erase(tp_list.begin(), tp_list.begin()+n_tps_to_erase);
52
53 // Make the window start time the start time of what is now the
54 // first TP.
55 if(!tp_list.empty()){
56 time_start = tp_list.front().time_start;
57 add(input_tp);
58 } else {
59 reset(input_tp);
60 }
61}
62
63
64void
66 // Empty the TP list.
67 tp_list.clear();
68 // Set the start time of the window to be the start time of the
69 // input_tp.
70 time_start = input_tp.time_start;
71 // Start the total ADC integral.
72 adc_integral = input_tp.adc_integral;
73 // Add the input TP to the TP list.
74 tp_list.push_back(input_tp);
75}
76
77
78
79std::ostream&
80operator<<(std::ostream& os, const TAMakerADCSimpleWindowAlgorithm::Window& window)
81{
82 if (window.is_empty()) {
83 os << "Window is empty!\n";
84 } else {
85 os << "Window start: " << window.time_start
86 << ", end: " << window.tp_list.back().time_start
87 << ". Total of: " << window.adc_integral
88 << " ADC counts with " << window.tp_list.size()
89 << " TPs.\n";
90 }
91 return os;
92}
93
94void
95TAMakerADCSimpleWindowAlgorithm::process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_ta)
96{
97
98 // The first time operator is called, reset
99 // window object.
101 m_current_window.reset(input_tp);
103 return;
104 }
105
106 // If the difference between the current TP's start time and the start of the window
107 // is less than the specified window size, add the TP to the window.
109 TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TAM:ADCSW] Window not yet complete, adding the input_tp to the window.";
110 m_current_window.add(input_tp);
111 }
112 // If the addition of the current TP to the window would make it longer
113 // than the specified window length, don't add it but check whether the sum of all adc in
114 // the existing window is above the specified threshold. If it is, make a TA and start
115 // a fresh window with the current TP.
117 TLOG_DEBUG(TLVL_DEBUG_LOW) << "[TAM:ADCSW] ADC integral in window is greater than specified threshold.";
118 output_ta.push_back(construct_ta());
119 TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TAM:ADCSW] Resetting window with input_tp.";
120 m_current_window.reset(input_tp);
121 }
122 // If it is not, move the window along.
123 else{
124 TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TAM:ADCSW] Window is at required length but adc threshold not met, shifting window along.";
126 }
127
128 TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TAM:ADCSW] " << m_current_window;
129
131
132 return;
133}
134
135void
137{
139
140 //FIXME use some schema here
141 if (config.is_object()){
142 if (config.contains("window_length")) m_window_length = config["window_length"];
143 if (config.contains("adc_threshold")) m_adc_threshold = config["adc_threshold"];
144 }
145 else{
146 TLOG_DEBUG(TLVL_IMPORTANT) << "[TAM:ADCSW] The DEFAULT values of window_length and adc_threshold are being used.";
147 }
148 TLOG_DEBUG(TLVL_IMPORTANT) << "[TAM:ADCSW] If the total ADC of trigger primitives with times within a "
149 << m_window_length << " tick time window is above " << m_adc_threshold << " counts, a trigger will be issued.";
150}
151
154{
155 TLOG_DEBUG(TLVL_DEBUG_LOW) << "[TAM:ADCSW] I am constructing a trigger activity!";
156 //TLOG_DEBUG(TRACE_NAME) << m_current_window;
157
158 const TriggerPrimitive& last_tp = m_current_window.tp_list.back();
159 uint64_t ch_min{last_tp.channel}, ch_max{last_tp.channel};
160 uint64_t time_min{last_tp.time_start}, time_max{last_tp.time_start + last_tp.samples_over_threshold * k_sample_to_dts_ticks};
161
162 uint64_t adc_peak{last_tp.adc_peak};
163 uint64_t ch_peak{last_tp.channel};
165
166
167 std::vector<TriggerPrimitive> tp_list;
168 tp_list.reserve(m_current_window.tp_list.size());
169
170
171 // Copy the queue into the vector
172 // And compute TA parameters
173 for( const auto& tp : m_current_window.tp_list ) {
174
175 ch_min = std::min(ch_min, tp.channel);
176 ch_max = std::max(ch_max, tp.channel);
177 time_min = std::min(time_min, tp.time_start);
178 time_max = std::max(time_max, tp.time_start + tp.samples_over_threshold * k_sample_to_dts_ticks); // FIXME: Replace the hard-coded SOT to TOT scaling.
179 if (tp.adc_peak > adc_peak) {
180 adc_peak = tp.adc_peak;
181 ch_peak = tp.channel;
182 time_peak = tp.time_start + tp.samples_to_peak * k_sample_to_dts_ticks; // FIXME: Replace the hard-coded STP to `time_peak` conversion.
183 }
184
185 tp_list.push_back(tp);
186 }
187
189
190 ta.time_start = time_min;
191 ta.time_end = time_max;
192 ta.time_peak = time_peak;
194 ta.channel_start = ch_min;
195 ta.channel_end = ch_max;
196 ta.channel_peak = ch_peak;
198 ta.adc_peak = adc_peak;
199 ta.detid = last_tp.detid;
202 ta.inputs.swap(tp_list);
203 return ta;
204}
205
206
207// Register algo in TA Factory
209
210}
#define TRACE_NAME
#define REGISTER_TRIGGER_ACTIVITY_MAKER(tam_name, tam_class)
void move(TriggerPrimitive const &input_tp, timestamp_t const &window_length)
void process(const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)
TP processing function that creates & fills TAs.
virtual void configure(const nlohmann::json &config)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
@ TLVL_DEBUG_HIGH
Definition Logging.hpp:24
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16
std::ostream & operator<<(std::ostream &os, const ProtoDUNEBSMWindow &window)
A single energy deposition on a TPC or PDS channel.
std::vector< TriggerPrimitive > inputs