DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
triggeralgs
src
TCMakerChannelAdjacencyAlgorithm.cpp
Go to the documentation of this file.
1
8
9
#include "
triggeralgs/ChannelAdjacency/TCMakerChannelAdjacencyAlgorithm.hpp
"
10
#include "
triggeralgs/Logging.hpp
"
11
12
#include "TRACE/trace.h"
13
#define TRACE_NAME "TCMakerChannelAdjacencyAlgorithm"
14
15
#include <math.h>
16
#include <vector>
17
18
using namespace
triggeralgs
;
19
20
using
Logging::TLVL_DEBUG_ALL
;
21
using
Logging::TLVL_DEBUG_HIGH
;
22
using
Logging::TLVL_DEBUG_MEDIUM
;
23
using
Logging::TLVL_VERY_IMPORTANT
;
24
25
void
26
TCMakerChannelAdjacencyAlgorithm::process
(
const
TriggerActivity
& activity,
27
std::vector<TriggerCandidate>& output_tc)
28
{
29
30
// The first time process() is called, reset window object.
31
if
(
m_current_window
.is_empty()) {
32
m_current_window
.reset(activity);
33
m_activity_count
++;
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."
;
46
m_current_window
.move(activity,
m_window_length
);
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.
53
if
(
m_current_window
.adc_integral >
m_adc_threshold
&&
m_trigger_on_adc
) {
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
;
56
TriggerCandidate
tc =
construct_tc
();
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);
66
m_current_window
.clear();
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.
73
else
if
(
m_current_window
.n_channels_hit() >
m_n_channels_threshold
&&
m_trigger_on_n_channels
) {
74
output_tc.push_back(
construct_tc
());
75
m_current_window
.clear();
76
}
77
78
m_activity_count
++;
79
return
;
80
}
81
82
void
83
TCMakerChannelAdjacencyAlgorithm::configure
(
const
nlohmann::json& config)
84
{
85
TriggerCandidateMaker::configure
(config);
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.
101
if
(!
m_trigger_on_adc
&& !
m_trigger_on_n_channels
) {
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
109
TriggerCandidate
110
TCMakerChannelAdjacencyAlgorithm::construct_tc
()
const
111
{
112
TriggerActivity
latest_ta_in_window =
m_current_window
.inputs.back();
113
114
TriggerCandidate
tc;
115
tc.
time_start
=
m_current_window
.time_start;
116
tc.
time_end
= latest_ta_in_window.
inputs
.back().time_start;
117
tc.
time_candidate
=
m_current_window
.time_start;
118
tc.
detid
= latest_ta_in_window.
detid
;
119
tc.
type
=
m_tc_type_out
;
120
tc.
algorithm
=
TriggerCandidate::Algorithm::kChannelAdjacency
;
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.
136
void
137
TCMakerChannelAdjacencyAlgorithm::add_window_to_record
(
TAWindow
window)
138
{
139
m_window_record
.push_back(window);
140
return
;
141
}
142
143
REGISTER_TRIGGER_CANDIDATE_MAKER
(
TRACE_NAME
,
TCMakerChannelAdjacencyAlgorithm
)
ERS_HERE
#define ERS_HERE
Definition
LocalContext.hpp:141
TRACE_NAME
#define TRACE_NAME
Definition
TimestampEstimatorTimeSync.cpp:17
REGISTER_TRIGGER_CANDIDATE_MAKER
#define REGISTER_TRIGGER_CANDIDATE_MAKER(tcm_name, tcm_class)
Definition
TriggerCandidateFactory.hpp:14
triggeralgs::TAWindow
Definition
TAWindow.hpp:20
triggeralgs::TCMakerChannelAdjacencyAlgorithm
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:20
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_trigger_on_adc
bool m_trigger_on_adc
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:35
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_window_record
std::vector< TAWindow > m_window_record
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:43
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_activity_count
uint64_t m_activity_count
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:32
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_current_window
TAWindow m_current_window
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:31
triggeralgs::TCMakerChannelAdjacencyAlgorithm::add_window_to_record
void add_window_to_record(TAWindow window)
Definition
TCMakerChannelAdjacencyAlgorithm.cpp:137
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_n_channels_threshold
uint16_t m_n_channels_threshold
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:38
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_window_length
timestamp_t m_window_length
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:39
triggeralgs::TCMakerChannelAdjacencyAlgorithm::construct_tc
TriggerCandidate construct_tc() const
Definition
TCMakerChannelAdjacencyAlgorithm.cpp:110
triggeralgs::TCMakerChannelAdjacencyAlgorithm::process
void process(const TriggerActivity &, std::vector< TriggerCandidate > &)
TA processing function that creates & fills TCs.
Definition
TCMakerChannelAdjacencyAlgorithm.cpp:26
triggeralgs::TCMakerChannelAdjacencyAlgorithm::configure
void configure(const nlohmann::json &config)
Definition
TCMakerChannelAdjacencyAlgorithm.cpp:83
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_trigger_on_n_channels
bool m_trigger_on_n_channels
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:36
triggeralgs::TCMakerChannelAdjacencyAlgorithm::m_adc_threshold
uint32_t m_adc_threshold
Definition
TCMakerChannelAdjacencyAlgorithm.hpp:37
triggeralgs::TriggerCandidateMaker::m_tc_type_out
TriggerCandidate::Type m_tc_type_out
Configurable TC type output.
Definition
TriggerCandidateMaker.hpp:138
triggeralgs::TriggerCandidateMaker::configure
virtual void configure(const nlohmann::json &config)
Definition
TriggerCandidateMaker.hpp:101
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
triggeralgs
Definition
AbstractFactory.hpp:18
triggeralgs::TLVL_DEBUG_MEDIUM
@ TLVL_DEBUG_MEDIUM
Definition
Logging.hpp:23
triggeralgs::TLVL_DEBUG_ALL
@ TLVL_DEBUG_ALL
Definition
Logging.hpp:25
triggeralgs::TLVL_VERY_IMPORTANT
@ TLVL_VERY_IMPORTANT
Definition
Logging.hpp:18
triggeralgs::TLVL_DEBUG_HIGH
@ TLVL_DEBUG_HIGH
Definition
Logging.hpp:24
TCMakerChannelAdjacencyAlgorithm.hpp
dunedaq::trgdataformats::TriggerActivityData::time_start
timestamp_t time_start
Definition
TriggerActivityData.hpp:46
dunedaq::trgdataformats::TriggerActivityData::detid
detid_t detid
Definition
TriggerActivityData.hpp:55
dunedaq::trgdataformats::TriggerCandidateData::type
Type type
Definition
TriggerCandidateData.hpp:94
dunedaq::trgdataformats::TriggerCandidateData::time_candidate
timestamp_t time_candidate
Definition
TriggerCandidateData.hpp:88
dunedaq::trgdataformats::TriggerCandidateData::time_end
timestamp_t time_end
Definition
TriggerCandidateData.hpp:87
dunedaq::trgdataformats::TriggerCandidateData::time_start
timestamp_t time_start
Definition
TriggerCandidateData.hpp:86
dunedaq::trgdataformats::TriggerCandidateData::Algorithm::kChannelAdjacency
@ kChannelAdjacency
Definition
TriggerCandidateData.hpp:79
dunedaq::trgdataformats::TriggerCandidateData::algorithm
Algorithm algorithm
Definition
TriggerCandidateData.hpp:95
dunedaq::trgdataformats::TriggerCandidateData::detid
detid_t detid
Definition
TriggerCandidateData.hpp:93
triggeralgs::TriggerActivity
Definition
TriggerActivity.hpp:20
triggeralgs::TriggerActivity::inputs
std::vector< TriggerPrimitive > inputs
Definition
TriggerActivity.hpp:33
triggeralgs::TriggerCandidate
Definition
TriggerCandidate.hpp:20
triggeralgs::TriggerCandidate::inputs
std::vector< dunedaq::trgdataformats::TriggerActivityData > inputs
Definition
TriggerCandidate.hpp:33
Logging.hpp
Generated on
for DUNE-DAQ by
1.17.0