DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
triggeralgs
src
TAMakerPlaneCoincidenceAlgorithm.cpp
Go to the documentation of this file.
1
8
9
#include "
triggeralgs/PlaneCoincidence/TAMakerPlaneCoincidenceAlgorithm.hpp
"
10
#include "TRACE/trace.h"
11
#define TRACE_NAME "TAMakerPlaneCoincidenceAlgorithm"
12
#include <vector>
13
14
using namespace
triggeralgs
;
15
16
using
Logging::TLVL_DEBUG_MEDIUM
;
17
18
void
19
TAMakerPlaneCoincidenceAlgorithm::process
(
const
TriggerPrimitive
& input_tp, std::vector<TriggerActivity>& output_ta)
20
{
21
22
// Get the plane from which this hit arrived:
23
// U (induction) = 0, Y (induction) = 1, Z (collection) = 2, unconnected channel = 9999
24
uint plane =
channelMap
->get_plane_from_offline_channel(input_tp.
channel
);
25
bool
isU = plane == 0;
// Induction1 = U
26
bool
isY = plane == 1;
// Induction2 = Y
27
bool
isZ = plane == 2;
// Collection = Z
28
29
// The first time operator() is called, reset the window object(s).
30
if
(
m_induction1_window
.is_empty() && isU) {
m_induction1_window
.reset(input_tp);
m_primitive_count
++;
return
; }
31
if
(
m_induction2_window
.is_empty() && isY) {
m_induction2_window
.reset(input_tp);
m_primitive_count
++;
return
; }
32
if
(
m_collection_window
.is_empty() && isZ) {
m_collection_window
.reset(input_tp);
m_primitive_count
++;
return
; }
33
34
// If the difference between the current TP's start time and the start of the window
35
// is less than the specified window size, add the TP to the corresponding window.
36
if
(isU && (input_tp.
time_start
-
m_induction1_window
.time_start) <
m_window_length
)
m_induction1_window
.add(input_tp);
37
if
(isY && (input_tp.
time_start
-
m_induction2_window
.time_start) <
m_window_length
)
m_induction2_window
.add(input_tp);
38
if
(isZ && (input_tp.
time_start
-
m_collection_window
.time_start) <
m_window_length
)
m_collection_window
.add(input_tp);
39
40
// ISSUE - We are checking the collection plane window too early: Every time we are NOT receiving a collection plane
41
// TP, we're checking the trigger conditions. Fix this immediately and rerun trigger runs to test.
42
43
// ===================================================================================
44
// Below this line, we begin our hierarchy of checks for a low energy event,
45
// taking advantage of the newly gained induction hits window.
46
// ===================================================================================
47
48
// Our windows have ADC Sum, Time Over Threshold, Multiplicity & Adjacency properties.
49
// Take advantage of these to screen the activities passed to more involved checks.
50
51
// 1) REQUIRE ADC SPIKE FROM INDUCTION AND CHECK ADJACENCY ===========================
52
// We're looking for a localised spike of ADC (short time window) and then a short
53
// adjacency corresponding to an electron track/shower.
54
55
// ISSUE - We are checking the collection plane window too early and too frequently probably:
56
// Every time we are NOT receiving a collection plane TP, we're checking the trigger conditions.
57
// Fix this immediately and rerun trigger runs to test.
58
// Introduce bool to check for collection window completeness:
59
bool
collectionComplete = (input_tp.
time_start
-
m_collection_window
.time_start) >
m_window_length
;
60
// Then require that the collection window be complete in the adjacency checks
61
if
(!collectionComplete) { }
// Do nothing
62
else
if
(collectionComplete && (
m_induction1_window
.adc_integral +
m_induction2_window
.adc_integral +
m_collection_window
.adc_integral)
63
>
m_adc_threshold
&&
check_adjacency
(
m_collection_window
) >=
m_adjacency_threshold
){
64
65
TLOG_DEBUG
(
TLVL_DEBUG_MEDIUM
) <<
"[TAM:PC] Emitting low energy trigger with "
<<
m_induction1_window
.adc_integral <<
" U "
66
<<
m_induction2_window
.adc_integral <<
" Y induction ADC sums and "
67
<<
check_adjacency
(
m_collection_window
) <<
" adjacent collection hits."
;
68
69
// Initial studies - output the TPs of the collection plane window that caused this trigger
70
add_window_to_record
(
m_collection_window
);
71
dump_window_record
();
72
m_window_record
.clear();
73
74
// Initial studies - Also dump the TPs that have contributed to this TA decision
75
for
(
auto
tp :
m_collection_window
.inputs)
dump_tp
(tp);
76
77
// We have fulfilled our trigger condition, construct a TA and reset/flush the windows
78
// to ensure they're all in the same "time zone"!
79
output_ta.push_back(
construct_ta
(
m_collection_window
));
80
if
(isZ)
m_collection_window
.reset(input_tp);
81
else
m_collection_window
.clear();
82
if
(isU)
m_induction1_window
.reset(input_tp);
83
else
m_induction1_window
.clear();
84
if
(isY)
m_induction2_window
.reset(input_tp);
85
else
m_induction2_window
.clear();
86
}
87
88
// Otherwise, slide the relevant window along using the current TP.
89
else
{
90
if
(isU)
m_induction1_window
.move(input_tp,
m_window_length
);
91
else
if
(isY)
m_induction2_window
.move(input_tp,
m_window_length
);
92
else
if
(isZ)
m_collection_window
.move(input_tp,
m_window_length
);
93
}
94
m_primitive_count
++;
95
96
return
;
97
}
98
99
void
100
TAMakerPlaneCoincidenceAlgorithm::configure
(
const
nlohmann::json& config)
101
{
102
TriggerActivityMaker::configure
(config);
103
104
if
(config.is_object()) {
105
if
(config.contains(
"adc_threshold"
))
106
m_adc_threshold
= config[
"adc_threshold"
];
107
if
(config.contains(
"window_length"
))
108
m_window_length
= config[
"window_length"
];
109
if
(config.contains(
"adjacency_tolerance"
))
110
m_adj_tolerance
= config[
"adjacency_tolerance"
];
111
if
(config.contains(
"adjacency_threshold"
))
112
m_adjacency_threshold
= config[
"adjacency_threshold"
];
113
}
114
115
}
116
117
TriggerActivity
118
TAMakerPlaneCoincidenceAlgorithm::construct_ta
(
TPWindow
m_current_window
)
const
119
{
120
121
TriggerPrimitive
latest_tp_in_window =
m_current_window
.inputs.back();
122
123
TriggerActivity
ta;
124
ta.
time_start
=
m_current_window
.time_start;
125
ta.
time_end
= latest_tp_in_window.
time_start
+ latest_tp_in_window.
samples_over_threshold
* 32;
// FIXME: Replace the hard-coded SOT to TOT scaling.
126
ta.
time_peak
= latest_tp_in_window.
samples_to_peak
* 32 + latest_tp_in_window.
time_start
;
// FIXME: Replace hard-coded STP to `time_peak` conversion.
127
ta.
time_activity
= ta.
time_peak
;
128
ta.
channel_start
= latest_tp_in_window.
channel
;
129
ta.
channel_end
= latest_tp_in_window.
channel
;
130
ta.
channel_peak
= latest_tp_in_window.
channel
;
131
ta.
adc_integral
=
m_current_window
.adc_integral;
132
ta.
adc_peak
= latest_tp_in_window.
adc_peak
;
133
ta.
detid
= latest_tp_in_window.
detid
;
134
ta.
type
=
TriggerActivity::Type::kTPC
;
135
ta.
algorithm
=
TriggerActivity::Algorithm::kPlaneCoincidence
;
136
ta.
inputs
=
m_current_window
.inputs;
137
138
return
ta;
139
}
140
141
uint16_t
142
TAMakerPlaneCoincidenceAlgorithm::check_adjacency
(
TPWindow
window)
const
143
{
144
/* This function returns the adjacency value for the current window, where adjacency
145
* is defined as the maximum number of consecutive wires containing hits. It accepts
146
* a configurable tolerance paramter, which allows up to adj_tolerance missing hits
147
* on adjacent wires before restarting the adjacency count. */
148
149
uint16_t adj = 1;
// Initialise adjacency, 1 for the first wire.
150
uint16_t max = 0;
// Maximum adjacency of window, which this function returns
151
unsigned
int
channel = 0;
// Current channel ID
152
unsigned
int
next_channel = 0;
// Next channel ID
153
unsigned
int
next = 0;
// The next position in the hit channels vector
154
unsigned
int
tol_count = 0;
// Tolerance count, should not pass adj_tolerance
155
156
/* Generate a channelID ordered list of hit channels for this window */
157
std::vector<int> chanList;
158
for
(
auto
tp : window.
inputs
) {
159
chanList.push_back(tp.channel);
160
}
161
std::sort(chanList.begin(), chanList.end());
162
163
/* ADAJACENCY LOGIC ====================================================================
164
* Adjcancency Tolerance = Number of times prepared to skip missed hits before resetting
165
* the adjacency count. This accounts for things like dead channels / missed TPs. */
166
for
(
size_t
i = 0; i < chanList.size(); ++i) {
167
168
next = (i + 1) % chanList.size();
// Loops back when outside of channel list range
169
channel = chanList.at(i);
170
next_channel = chanList.at(next);
// Next channel with a hit
171
172
// End of vector condition.
173
if
(next_channel == 0) { next_channel = channel - 1; }
174
175
// Skip same channel hits.
176
if
(next_channel == channel) {
continue
; }
177
178
// If next hit is on next channel, increment the adjacency count.
179
else
if
(next_channel == channel + 1){ ++adj; }
180
181
// If next channel is not on the next hit, but the 'second next', increase adjacency
182
// but also tally up with the tolerance counter.
183
else
if
((next_channel == channel + 2 || next_channel == channel + 3) && (tol_count <
m_adj_tolerance
)) {
184
++adj;
185
for
(
size_t
i = 0 ; i < next_channel-channel ; ++i) ++tol_count;
186
}
187
188
// If next hit isn't within reach, end the adjacency count and check for a new max.
189
// Reset variables for next iteration.
190
else
{
191
if
(adj > max) { max = adj; }
192
adj = 1;
193
tol_count = 0;
194
}
195
}
196
197
return
max;
198
}
199
200
// =====================================================================================
201
// Functions below this line are for debugging and performance study purposes.
202
// =====================================================================================
203
void
204
TAMakerPlaneCoincidenceAlgorithm::add_window_to_record
(
TPWindow
window)
205
{
206
m_window_record
.push_back(window);
207
return
;
208
}
209
210
// Function to dump the details of the TA window currently on record
211
void
212
TAMakerPlaneCoincidenceAlgorithm::dump_window_record
()
213
{
214
std::ofstream outfile;
215
outfile.open(
"window_record_tam.csv"
, std::ios_base::app);
216
217
for
(
auto
window :
m_window_record
) {
218
outfile << window.time_start <<
","
;
219
outfile << window.inputs.back().time_start <<
","
;
220
outfile << window.inputs.back().time_start - window.time_start <<
","
;
221
outfile << window.adc_integral <<
","
;
222
outfile << window.n_channels_hit() <<
","
;
// Number of unique channels with hits
223
outfile << window.inputs.size() <<
","
;
// Number of TPs in TPWindow
224
outfile << window.inputs.back().channel <<
","
;
// Last TP Channel ID
225
outfile << window.inputs.back().time_start <<
","
;
// Last TP start time
226
outfile << window.inputs.front().channel <<
","
;
// First TP Channel ID
227
outfile << window.inputs.front().time_start <<
","
;
// First TP start time
228
outfile <<
check_adjacency
(window) <<
","
;
// New adjacency value for the window
229
outfile <<
check_sot
(window) << std::endl;
// Summed window SOT
230
}
231
232
outfile.close();
233
m_window_record
.clear();
234
235
return
;
236
}
237
238
// Function to add current TP details to a text file for testing and debugging.
239
void
240
TAMakerPlaneCoincidenceAlgorithm::dump_tp
(
TriggerPrimitive
const
& input_tp)
241
{
242
std::ofstream outfile;
243
outfile.open(
"triggered_coldbox_tps.txt"
, std::ios_base::app);
244
245
// Output relevant TP information to file
246
outfile << input_tp.
time_start
<<
" "
;
247
outfile << input_tp.
samples_over_threshold
<<
" "
;
// 50MHz ticks
248
outfile << input_tp.
samples_to_peak
<<
" "
;
249
outfile << input_tp.
channel
<<
" "
;
// Offline channel ID
250
outfile << input_tp.
adc_integral
<<
" "
;
251
outfile << input_tp.
adc_peak
<<
" "
;
252
outfile << input_tp.
detid
<<
" "
;
// Det ID - Identifies detector element
253
outfile.close();
254
255
return
;
256
}
257
258
int
259
TAMakerPlaneCoincidenceAlgorithm::check_sot
(
TPWindow
m_current_window
)
const
260
{
261
// Here, we just want to sum up all the sot values for each TP within window,
262
// and return this sot of the window.
263
int
window_sot = 0;
264
for
(
auto
tp :
m_current_window
.inputs) {
265
window_sot += tp.samples_over_threshold;
266
}
267
268
return
window_sot;
269
}
270
271
// Regiser algo in TA Factory
272
REGISTER_TRIGGER_ACTIVITY_MAKER
(
TRACE_NAME
,
TAMakerPlaneCoincidenceAlgorithm
)
273
// END OF TA MAKER - LOW ENERGY EVENTS
TRACE_NAME
#define TRACE_NAME
Definition
TimestampEstimatorTimeSync.cpp:17
REGISTER_TRIGGER_ACTIVITY_MAKER
#define REGISTER_TRIGGER_ACTIVITY_MAKER(tam_name, tam_class)
Definition
TriggerActivityFactory.hpp:14
triggeralgs::TAMakerPlaneCoincidenceAlgorithm
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:27
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_window_length
timestamp_t m_window_length
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:56
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::channelMap
std::shared_ptr< dunedaq::detchannelmaps::TPCChannelMap > channelMap
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:59
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_adjacency_threshold
uint16_t m_adjacency_threshold
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:48
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::dump_tp
void dump_tp(TriggerPrimitive const &input_tp)
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:240
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_induction1_window
TPWindow m_induction1_window
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:43
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_primitive_count
uint64_t m_primitive_count
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:37
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::configure
void configure(const nlohmann::json &config)
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:100
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_adc_threshold
uint32_t m_adc_threshold
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:51
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::check_adjacency
uint16_t check_adjacency(TPWindow window) const
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:142
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::construct_ta
TriggerActivity construct_ta(TPWindow m_current_window) const
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:118
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_induction2_window
TPWindow m_induction2_window
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:44
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::check_sot
int check_sot(TPWindow m_current_window) const
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:259
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::dump_window_record
void dump_window_record()
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:212
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_adj_tolerance
uint16_t m_adj_tolerance
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:52
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::add_window_to_record
void add_window_to_record(TPWindow window)
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:204
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_window_record
std::vector< TPWindow > m_window_record
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:65
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_current_window
TPWindow m_current_window
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:36
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::process
void process(const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)
TP processing function that creates & fills TAs.
Definition
TAMakerPlaneCoincidenceAlgorithm.cpp:19
triggeralgs::TAMakerPlaneCoincidenceAlgorithm::m_collection_window
TPWindow m_collection_window
Definition
TAMakerPlaneCoincidenceAlgorithm.hpp:42
triggeralgs::TPWindow
Definition
TPWindow.hpp:21
triggeralgs::TPWindow::inputs
std::vector< TriggerPrimitive > inputs
Definition
TPWindow.hpp:40
triggeralgs::TriggerActivityMaker::configure
virtual void configure(const nlohmann::json &config)
Definition
TriggerActivityMaker.hpp:111
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::TriggerPrimitive
dunedaq::trgdataformats::TriggerPrimitive TriggerPrimitive
Definition
TriggerPrimitive.hpp:22
TAMakerPlaneCoincidenceAlgorithm.hpp
dunedaq::trgdataformats::TriggerActivityData::algorithm
Algorithm algorithm
Definition
TriggerActivityData.hpp:57
dunedaq::trgdataformats::TriggerActivityData::channel_peak
channel_t channel_peak
Definition
TriggerActivityData.hpp:52
dunedaq::trgdataformats::TriggerActivityData::time_activity
timestamp_t time_activity
Definition
TriggerActivityData.hpp:49
dunedaq::trgdataformats::TriggerActivityData::adc_integral
uint64_t adc_integral
Definition
TriggerActivityData.hpp:53
dunedaq::trgdataformats::TriggerActivityData::Type::kTPC
@ kTPC
Definition
TriggerActivityData.hpp:22
dunedaq::trgdataformats::TriggerActivityData::type
Type type
Definition
TriggerActivityData.hpp:56
dunedaq::trgdataformats::TriggerActivityData::time_peak
timestamp_t time_peak
Definition
TriggerActivityData.hpp:48
dunedaq::trgdataformats::TriggerActivityData::Algorithm::kPlaneCoincidence
@ kPlaneCoincidence
Definition
TriggerActivityData.hpp:35
dunedaq::trgdataformats::TriggerActivityData::adc_peak
uint16_t adc_peak
Definition
TriggerActivityData.hpp:54
dunedaq::trgdataformats::TriggerActivityData::channel_end
channel_t channel_end
Definition
TriggerActivityData.hpp:51
dunedaq::trgdataformats::TriggerActivityData::time_end
timestamp_t time_end
Definition
TriggerActivityData.hpp:47
dunedaq::trgdataformats::TriggerActivityData::channel_start
channel_t channel_start
Definition
TriggerActivityData.hpp:50
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::TriggerPrimitive::detid
uint64_t detid
Definition
TriggerPrimitive.hpp:33
dunedaq::trgdataformats::TriggerPrimitive::channel
uint64_t channel
Definition
TriggerPrimitive.hpp:36
dunedaq::trgdataformats::TriggerPrimitive::samples_over_threshold
uint64_t samples_over_threshold
Definition
TriggerPrimitive.hpp:38
dunedaq::trgdataformats::TriggerPrimitive::adc_peak
uint64_t adc_peak
Definition
TriggerPrimitive.hpp:43
dunedaq::trgdataformats::TriggerPrimitive::time_start
uint64_t time_start
Definition
TriggerPrimitive.hpp:39
dunedaq::trgdataformats::TriggerPrimitive::samples_to_peak
uint64_t samples_to_peak
Definition
TriggerPrimitive.hpp:40
dunedaq::trgdataformats::TriggerPrimitive::adc_integral
uint64_t adc_integral
Definition
TriggerPrimitive.hpp:42
triggeralgs::TriggerActivity
Definition
TriggerActivity.hpp:20
triggeralgs::TriggerActivity::inputs
std::vector< TriggerPrimitive > inputs
Definition
TriggerActivity.hpp:33
Generated on
for DUNE-DAQ by
1.17.0