DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
triggeralgs
src
TCMakerHorizontalMuonAlgorithm.cpp
Go to the documentation of this file.
1
8
9
#include "
triggeralgs/HorizontalMuon/TCMakerHorizontalMuonAlgorithm.hpp
"
10
11
#include "TRACE/trace.h"
12
#define TRACE_NAME "TCMakerHorizontalMuonAlgorithm"
13
14
#include <math.h>
15
#include <vector>
16
17
using namespace
triggeralgs
;
18
19
using
Logging::TLVL_DEBUG_ALL
;
20
using
Logging::TLVL_DEBUG_HIGH
;
21
using
Logging::TLVL_DEBUG_MEDIUM
;
22
23
void
24
TCMakerHorizontalMuonAlgorithm::process
(
const
TriggerActivity
& activity,
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.
32
if
(
m_current_window
.is_empty()) {
33
m_current_window
.reset(activity);
34
m_activity_count
++;
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."
;
53
m_current_window
.move(activity,
m_window_length
);
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.
60
if
(
m_current_window
.adc_integral >
m_adc_threshold
&&
m_trigger_on_adc
) {
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
++;
65
TriggerCandidate
tc =
construct_tc
();
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);
76
m_current_window
.clear();
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.
83
else
if
(
m_current_window
.n_channels_hit() >
m_n_channels_threshold
&&
m_trigger_on_n_channels
) {
84
tc_number
++;
85
output_tc.push_back(
construct_tc
());
86
87
// m_current_window.reset(activity);
88
m_current_window
.clear();
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
98
m_activity_count
++;
99
return
;
100
}
101
102
void
103
TCMakerHorizontalMuonAlgorithm::configure
(
const
nlohmann::json& config)
104
{
105
TriggerCandidateMaker::configure
(config);
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
}
119
if
(
m_trigger_on_adc
&&
m_trigger_on_n_channels
) {
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
}
123
if
(!
m_trigger_on_adc
&& !
m_trigger_on_n_channels
) {
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
131
TriggerCandidate
132
TCMakerHorizontalMuonAlgorithm::construct_tc
()
const
133
{
134
TriggerActivity
latest_ta_in_window =
m_current_window
.inputs.back();
135
136
TriggerCandidate
tc;
137
tc.
time_start
=
m_current_window
.time_start;
138
tc.
time_end
= latest_ta_in_window.
inputs
.back().time_start;
139
tc.
time_candidate
=
m_current_window
.time_start;
140
tc.
detid
= latest_ta_in_window.
detid
;
141
tc.
type
=
m_tc_type_out
;
142
tc.
algorithm
=
TriggerCandidate::Algorithm::kHorizontalMuon
;
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
157
bool
158
TCMakerHorizontalMuonAlgorithm::check_adjacency
()
const
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.
165
void
166
TCMakerHorizontalMuonAlgorithm::add_window_to_record
(
TAWindow
window)
167
{
168
m_window_record
.push_back(window);
169
return
;
170
}
171
172
void
173
TCMakerHorizontalMuonAlgorithm::dump_window_record
()
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
/*
196
void
197
TCMakerHorizontalMuonAlgorithm::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
213
reset."; m_current_window.clear();
214
215
return;
216
}*/
217
218
REGISTER_TRIGGER_CANDIDATE_MAKER
(
TRACE_NAME
,
TCMakerHorizontalMuonAlgorithm
)
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::TCMakerHorizontalMuonAlgorithm
Definition
TCMakerHorizontalMuonAlgorithm.hpp:20
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_current_window
TAWindow m_current_window
Definition
TCMakerHorizontalMuonAlgorithm.hpp:32
triggeralgs::TCMakerHorizontalMuonAlgorithm::tc_number
int tc_number
Definition
TCMakerHorizontalMuonAlgorithm.hpp:41
triggeralgs::TCMakerHorizontalMuonAlgorithm::dump_window_record
void dump_window_record()
Definition
TCMakerHorizontalMuonAlgorithm.cpp:173
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_trigger_on_adc
bool m_trigger_on_adc
Definition
TCMakerHorizontalMuonAlgorithm.hpp:36
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_trigger_on_n_channels
bool m_trigger_on_n_channels
Definition
TCMakerHorizontalMuonAlgorithm.hpp:37
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_window_record
std::vector< TAWindow > m_window_record
Definition
TCMakerHorizontalMuonAlgorithm.hpp:46
triggeralgs::TCMakerHorizontalMuonAlgorithm::construct_tc
TriggerCandidate construct_tc() const
Definition
TCMakerHorizontalMuonAlgorithm.cpp:132
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_n_channels_threshold
uint16_t m_n_channels_threshold
Definition
TCMakerHorizontalMuonAlgorithm.hpp:39
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_adc_threshold
uint32_t m_adc_threshold
Definition
TCMakerHorizontalMuonAlgorithm.hpp:38
triggeralgs::TCMakerHorizontalMuonAlgorithm::add_window_to_record
void add_window_to_record(TAWindow window)
Definition
TCMakerHorizontalMuonAlgorithm.cpp:166
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_activity_count
uint64_t m_activity_count
Definition
TCMakerHorizontalMuonAlgorithm.hpp:33
triggeralgs::TCMakerHorizontalMuonAlgorithm::check_adjacency
bool check_adjacency() const
Definition
TCMakerHorizontalMuonAlgorithm.cpp:158
triggeralgs::TCMakerHorizontalMuonAlgorithm::m_window_length
timestamp_t m_window_length
Definition
TCMakerHorizontalMuonAlgorithm.hpp:40
triggeralgs::TCMakerHorizontalMuonAlgorithm::configure
void configure(const nlohmann::json &config)
Definition
TCMakerHorizontalMuonAlgorithm.cpp:103
triggeralgs::TCMakerHorizontalMuonAlgorithm::process
void process(const TriggerActivity &, std::vector< TriggerCandidate > &)
TA processing function that creates & fills TCs.
Definition
TCMakerHorizontalMuonAlgorithm.cpp:24
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
TCMakerHorizontalMuonAlgorithm.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::kHorizontalMuon
@ kHorizontalMuon
Definition
TriggerCandidateData.hpp:72
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
Generated on
for DUNE-DAQ by
1.17.0