DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
triggeralgs
src
TCMakerMichelElectronAlgorithm.cpp
Go to the documentation of this file.
1
8
9
#include "
triggeralgs/MichelElectron/TCMakerMichelElectronAlgorithm.hpp
"
10
11
#include "TRACE/trace.h"
12
#define TRACE_NAME "TCMakerMichelElectronAlgorithm"
13
14
#include <vector>
15
16
using namespace
triggeralgs
;
17
18
using
Logging::TLVL_DEBUG_ALL
;
19
using
Logging::TLVL_DEBUG_HIGH
;
20
using
Logging::TLVL_DEBUG_LOW
;
21
using
Logging::TLVL_DEBUG_INFO
;
22
using
Logging::TLVL_VERY_IMPORTANT
;
23
24
void
25
TCMakerMichelElectronAlgorithm::process
(
const
TriggerActivity
& activity,
26
std::vector<TriggerCandidate>& output_tc)
27
{
28
29
std::vector<TriggerActivity::TriggerActivityData> ta_list = {
static_cast<
TriggerActivity::TriggerActivityData
>
(
30
activity) };
31
32
// The first time process() is called, reset window object.
33
if
(
m_current_window
.is_empty()) {
34
m_current_window
.reset(activity);
35
m_activity_count
++;
36
// Trivial TC Logic:
37
// If the request has been made to not trigger on number of channels or
38
// total adc, simply construct a trigger candidate from any single activity.
39
if
((!
m_trigger_on_adc
) && (!
m_trigger_on_n_channels
)) {
40
41
// add_window_to_record(m_current_window);
42
// dump_window_record();
43
TLOG_DEBUG
(
TLVL_DEBUG_LOW
) <<
"[TCM:ME] Constructing TC."
;
44
45
TriggerCandidate
tc =
construct_tc
();
46
output_tc.push_back(tc);
47
48
// Clear the current window (only has a single TA in it)
49
m_current_window
.clear();
50
}
51
return
;
52
}
53
54
// FIX ME: Only want to call this if running in debug mode.
55
// add_window_to_record(m_current_window);
56
57
// If the difference between the current TA's start time and the start of the window
58
// is less than the specified window size, add the TA to the window.
59
if
((activity.
time_start
-
m_current_window
.time_start) <
m_window_length
) {
60
TLOG_DEBUG
(
TLVL_DEBUG_HIGH
) <<
"[TCM:ME] Window not yet complete, adding the activity to the window."
;
61
m_current_window
.add(activity);
62
}
63
// If the addition of the current TA to the window would make it longer
64
// than the specified window length, don't add it but check whether the sum of all adc in
65
// the existing window is above the specified threshold. If it is, and we are triggering on ADC,
66
// make a TA and start a fresh window with the current TP.
67
else
if
(
m_current_window
.adc_integral >
m_adc_threshold
&&
m_trigger_on_adc
) {
68
TLOG_DEBUG
(
TLVL_DEBUG_LOW
) <<
"[TCM:ME] ADC integral in window is greater than specified threshold."
;
69
TriggerCandidate
tc =
construct_tc
();
70
71
output_tc.push_back(tc);
72
TLOG_DEBUG
(
TLVL_DEBUG_HIGH
) <<
"[TCM:ME] Resetting window with activity."
;
73
m_current_window
.reset(activity);
74
}
75
// If the addition of the current TA to the window would make it longer
76
// than the specified window length, don't add it but check whether the number of hit channels in
77
// the existing window is above the specified threshold. If it is, and we are triggering on channels,
78
// make a TC and start a fresh window with the current TA.
79
else
if
(
m_current_window
.n_channels_hit() >
m_n_channels_threshold
&&
m_trigger_on_n_channels
) {
80
tc_number
++;
81
// output_tc.push_back(construct_tc());
82
m_current_window
.reset(activity);
83
TLOG_DEBUG
(
TLVL_DEBUG_INFO
) <<
"[TCM:ME] Should not see this!"
;
84
}
85
// If it is not, move the window along.
86
else
{
87
TLOG_DEBUG
(
TLVL_DEBUG_HIGH
) <<
"[TCM:ME] Window is at required length but specified threshold not met, shifting window along."
;
88
m_current_window
.move(activity,
m_window_length
);
89
}
90
91
//TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TCM:ME] " m_current_window;
92
93
m_activity_count
++;
94
95
// if(m_activity_count % 500 == 0) dump_window_record();
96
97
return
;
98
}
99
100
void
101
TCMakerMichelElectronAlgorithm::configure
(
const
nlohmann::json& config)
102
{
103
TriggerCandidateMaker::configure
(config);
104
105
// FIX ME: Use some schema here. Also can't work out how to pass booleans.
106
if
(config.is_object()) {
107
if
(config.contains(
"trigger_on_adc"
))
108
m_trigger_on_adc
= config[
"trigger_on_adc"
];
109
if
(config.contains(
"trigger_on_n_channels"
))
110
m_trigger_on_n_channels
= config[
"trigger_on_n_channels"
];
111
if
(config.contains(
"adc_threshold"
))
112
m_adc_threshold
= config[
"adc_threshold"
];
113
if
(config.contains(
"n_channels_threshold"
))
114
m_n_channels_threshold
= config[
"n_channels_threshold"
];
115
if
(config.contains(
"window_length"
))
116
m_window_length
= config[
"window_length"
];
117
// if (config.contains("channel_map")) m_channel_map = config["channel_map"];
118
}
119
if
(
m_trigger_on_adc
&&
m_trigger_on_n_channels
) {
120
TLOG_DEBUG
(
TLVL_VERY_IMPORTANT
) <<
"[TCM:ME] Triggering on ADC count and number of channels is not supported."
;
121
throw
BadConfiguration(
ERS_HERE
,
TRACE_NAME
);
122
}
123
if
(!
m_trigger_on_adc
&& !
m_trigger_on_n_channels
) {
124
TLOG_DEBUG
(
TLVL_DEBUG_LOW
) <<
"[TCM:ME] Both trigger flags are false. Passing TAs through 1:1."
;
125
}
126
127
return
;
128
}
129
130
TriggerCandidate
131
TCMakerMichelElectronAlgorithm::construct_tc
()
const
132
{
133
TriggerActivity
latest_ta_in_window =
m_current_window
.inputs.back();
134
135
TriggerCandidate
tc;
136
tc.
time_start
=
m_current_window
.time_start;
137
tc.
time_end
= latest_ta_in_window.
time_end
;
138
tc.
time_candidate
=
m_current_window
.time_start;
139
tc.
detid
= latest_ta_in_window.
detid
;
140
tc.
type
=
m_tc_type_out
;
141
tc.
algorithm
=
TriggerCandidate::Algorithm::kMichelElectron
;
142
143
// Take the list of triggeralgs::TriggerActivity in the current
144
// window and convert them (implicitly) to detdataformats'
145
// TriggerActivityData, which is the base class of TriggerActivity
146
for
(
auto
& ta :
m_current_window
.inputs) {
147
tc.
inputs
.push_back(ta);
148
}
149
150
return
tc;
151
}
152
153
bool
154
TCMakerMichelElectronAlgorithm::check_adjacency
()
const
155
{
156
// FIX ME: An adjacency check on the channels which have hits.
157
return
true
;
158
}
159
160
// Functions below this line are for debugging purposes.
161
void
162
TCMakerMichelElectronAlgorithm::add_window_to_record
(
Window
window)
163
{
164
m_window_record
.push_back(window);
165
return
;
166
}
167
168
void
169
TCMakerMichelElectronAlgorithm::dump_window_record
()
170
{
171
// FIX ME: Need to index this outfile in the name by detid or something similar.
172
std::ofstream outfile;
173
outfile.open(
"window_record_tcm.csv"
, std::ios_base::app);
174
175
for
(
auto
window :
m_window_record
) {
176
outfile << window.time_start <<
","
;
177
outfile << window.inputs.back().time_start <<
","
;
178
outfile << window.inputs.back().time_start - window.time_start <<
","
;
179
outfile << window.adc_integral <<
","
;
180
outfile << window.n_channels_hit() <<
","
;
181
outfile << window.inputs.size() << std::endl;
182
}
183
184
outfile.close();
185
186
m_window_record
.clear();
187
188
return
;
189
}
190
191
/*
192
void
193
TCMakerMichelElectronAlgorithm::flush(timestamp_t, std::vector<TriggerCandidate>& output_tc)
194
{
195
// Check the status of the current window, construct TC if conditions are met. Regardless
196
// of whether the conditions are met, reset the window.
197
if(m_current_window.adc_integral > m_adc_threshold && m_trigger_on_adc){
198
//else if(m_current_window.adc_integral > m_conf.adc_threshold && m_conf.trigger_on_adc){
199
//TLOG_DEBUG(TRACE_NAME) << "ADC integral in window is greater than specified threshold.";
200
output_tc.push_back(construct_tc());
201
}
202
else if(m_current_window.n_channels_hit() > m_n_channels_threshold && m_trigger_on_n_channels){
203
//else if(m_current_window.n_channels_hit() > m_conf.n_channels_threshold && m_conf.trigger_on_n_channels){
204
//TLOG_DEBUG(TRACE_NAME) << "Number of channels hit in the window is greater than specified threshold.";
205
output_tc.push_back(construct_tc());
206
}
207
208
//TLOG_DEBUG(TRACE_NAME) << "Clearing the current window, on the arrival of the next input_tp, the window will be
209
reset."; m_current_window.clear();
210
211
return;
212
}*/
213
214
REGISTER_TRIGGER_CANDIDATE_MAKER
(
TRACE_NAME
,
TCMakerMichelElectronAlgorithm
)
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::TCMakerMichelElectronAlgorithm::Window
Definition
TCMakerMichelElectronAlgorithm.hpp:33
triggeralgs::TCMakerMichelElectronAlgorithm
Definition
TCMakerMichelElectronAlgorithm.hpp:21
triggeralgs::TCMakerMichelElectronAlgorithm::m_n_channels_threshold
uint16_t m_n_channels_threshold
Definition
TCMakerMichelElectronAlgorithm.hpp:139
triggeralgs::TCMakerMichelElectronAlgorithm::m_trigger_on_adc
bool m_trigger_on_adc
Definition
TCMakerMichelElectronAlgorithm.hpp:136
triggeralgs::TCMakerMichelElectronAlgorithm::m_trigger_on_n_channels
bool m_trigger_on_n_channels
Definition
TCMakerMichelElectronAlgorithm.hpp:137
triggeralgs::TCMakerMichelElectronAlgorithm::m_window_length
timestamp_t m_window_length
Definition
TCMakerMichelElectronAlgorithm.hpp:140
triggeralgs::TCMakerMichelElectronAlgorithm::m_current_window
Window m_current_window
Definition
TCMakerMichelElectronAlgorithm.hpp:127
triggeralgs::TCMakerMichelElectronAlgorithm::m_window_record
std::vector< Window > m_window_record
Definition
TCMakerMichelElectronAlgorithm.hpp:148
triggeralgs::TCMakerMichelElectronAlgorithm::m_adc_threshold
uint32_t m_adc_threshold
Definition
TCMakerMichelElectronAlgorithm.hpp:138
triggeralgs::TCMakerMichelElectronAlgorithm::dump_window_record
void dump_window_record()
Definition
TCMakerMichelElectronAlgorithm.cpp:169
triggeralgs::TCMakerMichelElectronAlgorithm::construct_tc
TriggerCandidate construct_tc() const
Definition
TCMakerMichelElectronAlgorithm.cpp:131
triggeralgs::TCMakerMichelElectronAlgorithm::tc_number
int tc_number
Definition
TCMakerMichelElectronAlgorithm.hpp:141
triggeralgs::TCMakerMichelElectronAlgorithm::process
void process(const TriggerActivity &, std::vector< TriggerCandidate > &)
The function that gets call when there is a new activity.
Definition
TCMakerMichelElectronAlgorithm.cpp:25
triggeralgs::TCMakerMichelElectronAlgorithm::m_activity_count
uint64_t m_activity_count
Definition
TCMakerMichelElectronAlgorithm.hpp:128
triggeralgs::TCMakerMichelElectronAlgorithm::configure
void configure(const nlohmann::json &config)
Definition
TCMakerMichelElectronAlgorithm.cpp:101
triggeralgs::TCMakerMichelElectronAlgorithm::add_window_to_record
void add_window_to_record(Window window)
Definition
TCMakerMichelElectronAlgorithm.cpp:162
triggeralgs::TCMakerMichelElectronAlgorithm::check_adjacency
bool check_adjacency() const
Definition
TCMakerMichelElectronAlgorithm.cpp:154
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_ALL
@ TLVL_DEBUG_ALL
Definition
Logging.hpp:25
triggeralgs::TLVL_VERY_IMPORTANT
@ TLVL_VERY_IMPORTANT
Definition
Logging.hpp:18
triggeralgs::TLVL_DEBUG_INFO
@ TLVL_DEBUG_INFO
Definition
Logging.hpp:21
triggeralgs::TLVL_DEBUG_LOW
@ TLVL_DEBUG_LOW
Definition
Logging.hpp:22
triggeralgs::TLVL_DEBUG_HIGH
@ TLVL_DEBUG_HIGH
Definition
Logging.hpp:24
TCMakerMichelElectronAlgorithm.hpp
dunedaq::trgdataformats::TriggerActivityData::time_end
timestamp_t time_end
Definition
TriggerActivityData.hpp:47
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::kMichelElectron
@ kMichelElectron
Definition
TriggerCandidateData.hpp:73
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::TriggerCandidate
Definition
TriggerCandidate.hpp:20
triggeralgs::TriggerCandidate::inputs
std::vector< dunedaq::trgdataformats::TriggerActivityData > inputs
Definition
TriggerCandidate.hpp:33
Generated on
for DUNE-DAQ by
1.17.0