DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TCMakerHorizontalMuonAlgorithm.cpp
Go to the documentation of this file.
1
10
11#include "TRACE/trace.h"
12#define TRACE_NAME "TCMakerHorizontalMuonAlgorithm"
13
14#include <math.h>
15#include <vector>
16
17using namespace triggeralgs;
18
19using Logging::TLVL_DEBUG_ALL;
20using Logging::TLVL_DEBUG_HIGH;
21using Logging::TLVL_DEBUG_MEDIUM;
22
23void
25 std::vector<TriggerCandidate>& output_tc)
26{
27
28 std::vector<TriggerActivity::TriggerActivityData> ta_list = { static_cast<TriggerActivity::TriggerActivityData>(
29 activity) };
30
31 // The first time operator is called, reset window object.
33 m_current_window.reset(activity);
35
36 // TriggerCandidate tc = construct_tc();
37 // output_tc.push_back(tc);
38
39 // m_current_window.clear();
40 // return;
41 }
42
43 // If the difference between the current TA's start time and the start of the window
44 // is less than the specified window size, add the TA to the window.
45 else if ((activity.time_start - m_current_window.time_start) < m_window_length) {
46 TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TCM:HM] Window not yet complete, adding the activity to the window.";
47 m_current_window.add(activity);
48 }
49 // If it is not, move the window along.
50 else {
51 TLOG_DEBUG(TLVL_DEBUG_ALL)
52 << "[TCM:HM] TAWindow is at required length but specified threshold not met, shifting window along.";
54 }
55
56 // If the addition of the current TA to the window would make it longer
57 // than the specified window length, don't add it but check whether the sum of all adc in
58 // the existing window is above the specified threshold. If it is, and we are triggering on ADC,
59 // make a TA and start a fresh window with the current TP.
61 // TLOG_DEBUG(TRACE_NAME) << "ADC integral in window is greater than specified threshold.";
62 TLOG_DEBUG(TLVL_DEBUG_MEDIUM) << "[TCM:HM] m_current_window.adc_integral " << m_current_window.adc_integral
63 << " - m_adc_threshold " << m_adc_threshold;
64 tc_number++;
66 TLOG_DEBUG(TLVL_DEBUG_MEDIUM) << "[TCM:HM] tc.time_start=" << tc.time_start << " tc.time_end=" << tc.time_end
67 << " len(tc.inputs) " << tc.inputs.size();
68
69 for (const auto& ta : tc.inputs) {
70 TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TCM:HM] [TA] ta.time_start=" << ta.time_start << " ta.time_end=" << ta.time_end
71 << " ta.adc_integral=" << ta.adc_integral;
72 }
73
74 output_tc.push_back(tc);
75 // m_current_window.reset(activity);
77 }
78
79 // If the addition of the current TA to the window would make it longer
80 // than the specified window length, don't add it but check whether the number of hit channels in
81 // the existing window is above the specified threshold. If it is, and we are triggering on channels,
82 // make a TC and start a fresh window with the current TA.
84 tc_number++;
85 output_tc.push_back(construct_tc());
86
87 // m_current_window.reset(activity);
89 }
90
91 // // If it is not, move the window along.
92 // else {
93 // // TLOG_DEBUG(TRACE_NAME) << "TAWindow is at required length but specified threshold not met."
94 // // << "shifting window along.";
95 // m_current_window.move(activity, m_window_length);
96 // }
97
99 return;
100}
101
102void
103TCMakerHorizontalMuonAlgorithm::configure(const nlohmann::json& config)
104{
106
107 if (config.is_object()) {
108 if (config.contains("trigger_on_adc"))
109 m_trigger_on_adc = config["trigger_on_adc"];
110 if (config.contains("trigger_on_n_channels"))
111 m_trigger_on_n_channels = config["trigger_on_n_channels"];
112 if (config.contains("adc_threshold"))
113 m_adc_threshold = config["adc_threshold"];
114 if (config.contains("n_channels_threshold"))
115 m_n_channels_threshold = config["n_channels_threshold"];
116 if (config.contains("window_length"))
117 m_window_length = config["window_length"];
118 }
120 TLOG_DEBUG(TLVL_VERY_IMPORTANT) << "[TCM:HM] Triggering on ADC count and number of channels is not supported.";
121 throw BadConfiguration(ERS_HERE, TRACE_NAME);
122 }
124 TLOG_DEBUG(TLVL_VERY_IMPORTANT) << "[TCM:HM] Not triggering! All trigger flags are false!";
125 throw BadConfiguration(ERS_HERE, TRACE_NAME);
126 }
127
128 return;
129}
130
133{
134 TriggerActivity latest_ta_in_window = m_current_window.inputs.back();
135
138 tc.time_end = latest_ta_in_window.inputs.back().time_start;
140 tc.detid = latest_ta_in_window.detid;
141 tc.type = m_tc_type_out;
143
144 // Take the list of triggeralgs::TriggerActivity in the current
145 // window and convert them (implicitly) to detdataformats'
146 // TriggerActivityData, which is the base class of TriggerActivity
147 for (auto& ta : m_current_window.inputs) {
148 tc.inputs.push_back(ta);
149 if (ta.time_end > tc.time_end) {
150 tc.time_end = ta.time_end;
151 }
152 }
153
154 return tc;
155}
156
157bool
159{
160 // FIX ME: An adjacency check on the channels which have hits.
161 return true;
162}
163
164// Functions below this line are for debugging purposes.
165void
167{
168 m_window_record.push_back(window);
169 return;
170}
171
172void
174{
175 // FIX ME: Need to index this outfile in the name by detid or something similar.
176 std::ofstream outfile;
177 outfile.open("window_record_tcm.csv", std::ios_base::app);
178
179 for (auto window : m_window_record) {
180 outfile << window.time_start << ",";
181 outfile << window.inputs.back().time_start << ",";
182 outfile << window.inputs.back().time_start - window.time_start << ",";
183 outfile << window.adc_integral << ",";
184 outfile << window.n_channels_hit() << ",";
185 outfile << window.inputs.size() << std::endl;
186 }
187
188 outfile.close();
189
190 m_window_record.clear();
191
192 return;
193}
194
195/*
196void
197TCMakerHorizontalMuonAlgorithm::flush(timestamp_t, std::vector<TriggerCandidate>& output_tc)
198{
199 // Check the status of the current window, construct TC if conditions are met. Regardless
200 // of whether the conditions are met, reset the window.
201 if(m_current_window.adc_integral > m_adc_threshold && m_trigger_on_adc){
202 //else if(m_current_window.adc_integral > m_conf.adc_threshold && m_conf.trigger_on_adc){
203 //TLOG_DEBUG(TRACE_NAME) << "ADC integral in window is greater than specified threshold.";
204 output_tc.push_back(construct_tc());
205 }
206 else if(m_current_window.n_channels_hit() > m_n_channels_threshold && m_trigger_on_n_channels){
207 //else if(m_current_window.n_channels_hit() > m_conf.n_channels_threshold && m_conf.trigger_on_n_channels){
208 //TLOG_DEBUG(TRACE_NAME) << "Number of channels hit in the window is greater than specified threshold.";
209 output_tc.push_back(construct_tc());
210 }
211
212 //TLOG_DEBUG(TRACE_NAME) << "Clearing the current window, on the arrival of the next input_tp, the window will be
213reset."; m_current_window.clear();
214
215 return;
216}*/
217
#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