Line data Source code
1 : /**
2 : * @file TAMakerChannelDistanceAlgorithm.cpp
3 : *
4 : * This is part of the DUNE DAQ Application Framework, copyright 2021.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "triggeralgs/ChannelDistance/TAMakerChannelDistanceAlgorithm.hpp"
10 :
11 : #include "TRACE/trace.h"
12 : #define TRACE_NAME "TAMakerChannelDistanceAlgorithm"
13 :
14 : namespace triggeralgs {
15 :
16 : void
17 0 : TAMakerChannelDistanceAlgorithm::set_new_ta(const TriggerPrimitive& input_tp)
18 : {
19 0 : m_current_ta = TriggerActivity();
20 0 : m_current_ta.inputs.push_back(input_tp);
21 0 : m_current_lower_bound = input_tp.channel - m_max_channel_distance;
22 0 : m_current_upper_bound = input_tp.channel + m_max_channel_distance;
23 0 : return;
24 : }
25 :
26 : void
27 0 : TAMakerChannelDistanceAlgorithm::process(const TriggerPrimitive& input_tp,
28 : std::vector<TriggerActivity>& output_tas)
29 : {
30 :
31 : // Start a new TA if not already going.
32 0 : if (m_current_ta.inputs.empty()) {
33 0 : set_new_ta(input_tp);
34 0 : return;
35 : }
36 :
37 : // Check to close the TA based on time.
38 0 : if (input_tp.time_start - m_current_ta.inputs.front().time_start > m_window_length) {
39 : // Check to block the TA based on min TPs.
40 0 : if (m_current_ta.inputs.size() >= m_min_tps) {
41 0 : set_ta_attributes();
42 0 : output_tas.push_back(m_current_ta);
43 : }
44 0 : set_new_ta(input_tp);
45 0 : return;
46 : }
47 :
48 : // Check to skip the TP if it's outside the current channel bounds.
49 0 : if (input_tp.channel > m_current_upper_bound || input_tp.channel < m_current_lower_bound)
50 : return;
51 :
52 0 : m_current_ta.inputs.push_back(input_tp);
53 0 : m_current_lower_bound = std::min(m_current_lower_bound, channel_diff_t(input_tp.channel) - m_max_channel_distance);
54 0 : m_current_upper_bound = std::max(m_current_upper_bound, channel_diff_t(input_tp.channel) + m_max_channel_distance);
55 : }
56 :
57 : void
58 0 : TAMakerChannelDistanceAlgorithm::configure(const nlohmann::json& config)
59 : {
60 0 : TriggerActivityMaker::configure(config);
61 :
62 0 : if (config.contains("min_tps"))
63 0 : m_min_tps = config["min_tps"];
64 0 : if (config.contains("window_length"))
65 0 : m_window_length = config["window_length"];
66 0 : if (config.contains("max_channel_distance"))
67 0 : m_max_channel_distance = config["max_channel_distance"];
68 :
69 0 : return;
70 : }
71 :
72 : void
73 0 : TAMakerChannelDistanceAlgorithm::set_ta_attributes()
74 : {
75 0 : TriggerPrimitive first_tp = m_current_ta.inputs.front();
76 0 : TriggerPrimitive last_tp = m_current_ta.inputs.back();
77 :
78 0 : m_current_ta.channel_start = first_tp.channel;
79 0 : m_current_ta.channel_end = last_tp.channel;
80 :
81 0 : m_current_ta.time_start = first_tp.time_start;
82 0 : m_current_ta.time_end = last_tp.time_start;
83 :
84 0 : m_current_ta.detid = first_tp.detid;
85 :
86 0 : m_current_ta.algorithm = TriggerActivity::Algorithm::kChannelDistance;
87 0 : m_current_ta.type = TriggerActivity::Type::kTPC;
88 :
89 0 : m_current_ta.adc_peak = 0;
90 0 : for (const TriggerPrimitive& tp : m_current_ta.inputs) {
91 0 : m_current_ta.adc_integral += tp.adc_integral;
92 0 : if (tp.adc_peak <= m_current_ta.adc_peak)
93 0 : continue;
94 0 : m_current_ta.adc_peak = tp.adc_peak;
95 0 : m_current_ta.channel_peak = tp.channel;
96 0 : m_current_ta.time_peak = tp.samples_to_peak * 32 + tp.time_start; // FIXME: Replace STP to `time_peak` conversion.
97 : }
98 0 : m_current_ta.time_activity = m_current_ta.time_peak;
99 0 : }
100 :
101 : // Register algo in TA Factory
102 12 : REGISTER_TRIGGER_ACTIVITY_MAKER(TRACE_NAME, TAMakerChannelDistanceAlgorithm)
103 :
104 : } // namespace triggeralgs
|