DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
triggeralgs
src
TAMakerProtoDUNEBSMWindowAlgorithm.cpp
Go to the documentation of this file.
1
8
9
#include "
triggeralgs/ProtoDUNEBSMWindow/TAMakerProtoDUNEBSMWindowAlgorithm.hpp
"
10
11
#include "TRACE/trace.h"
12
#define TRACE_NAME "TAMakerProtoDUNEBSMWindowAlgorithm"
13
14
#include <vector>
15
#include <chrono>
16
17
using namespace
triggeralgs
;
18
using
Logging::TLVL_DEBUG_ALL
;
19
using
Logging::TLVL_DEBUG_HIGH
;
20
using
Logging::TLVL_DEBUG_LOW
;
21
using
Logging::TLVL_IMPORTANT
;
22
23
void
24
TAMakerProtoDUNEBSMWindowAlgorithm::process
(
const
TriggerPrimitive
& input_tp, std::vector<TriggerActivity>& output_ta)
25
{
26
27
if
(
m_current_window
.is_empty()){
28
m_current_window
.reset(input_tp);
29
m_last_pred_time
= input_tp.
time_start
;
30
m_primitive_count
++;
31
// first time operator is called set ROP first and last channel
32
unsigned
int
detelement =
channelMap
->get_element_id_from_offline_channel(input_tp.
channel
);
33
unsigned
int
plane =
channelMap
->get_plane_from_offline_channel(input_tp.
channel
);
34
35
PlaneInfo
plane_info =
m_det_plane_map
.get_plane_info(
m_channel_map_name
, detelement, plane);
36
m_first_channel
=
static_cast<
channel_t
>
(plane_info.
min_channel
);
37
channel_t
n_channels_on_plane =
static_cast<
channel_t
>
(plane_info.
n_channels
);
38
39
// If we are in PD-VD use 'effective' channel mapping for CRPs
40
if
(
m_pdvd_map
) {
41
m_pdvd_eff_channel_mapper
= std::make_unique<PDVDEffectiveChannelMap>(plane_info.
min_channel
, plane_info.
n_channels
);
42
43
m_first_channel
=
m_pdvd_eff_channel_mapper
->remapCollectionPlaneChannel(
m_first_channel
);
44
m_last_channel
=
m_first_channel
+
m_pdvd_eff_channel_mapper
->getNEffectiveChannels();
45
m_chan_bin_length
=
m_pdvd_eff_channel_mapper
->getNEffectiveChannels() /
m_num_chanbins
;
46
}
else
{
// still in PD-HD, so don't need effective channel
47
m_last_channel
=
m_first_channel
+ n_channels_on_plane;
48
m_chan_bin_length
= n_channels_on_plane /
m_num_chanbins
;
49
}
50
51
TLOG_DEBUG
(
TLVL_DEBUG_ALL
) <<
"[TAM:BSMW] 1st Chan = "
<<
m_first_channel
<<
", last Chan = "
<<
m_last_channel
<< std::endl
52
<<
"Number of channel bins = "
<<
m_num_chanbins
<<
", and channel bin length = "
<<
m_chan_bin_length
;
53
return
;
54
}
55
56
// If the difference between the current TP's start time and the start of the window
57
// is less than the specified window size, add the TP to the window.
58
if
((input_tp.
time_start
-
m_current_window
.time_start) <
m_window_length
){
59
TLOG_DEBUG
(
TLVL_DEBUG_HIGH
) <<
"[TAM:BSMW] Window not yet complete, adding the input_tp to the window."
;
60
m_current_window
.add(input_tp);
61
}
62
// If the addition of the current TP to the window would make it longer
63
// than the specified window length, don't add it
64
// Instead go through a series of filters and eventually a XGBoost model to determine whether to create a TA
65
else
if
(
66
(
m_current_window
.time_start -
m_last_pred_time
) >
m_bin_length
&&
// check enough time has passed since last window
67
m_current_window
.tp_list.size() > 20 &&
// need enough TPs in window to bother
68
m_current_window
.adc_integral >
m_adc_threshold
&&
// set a low minimum threshold for the ADC integral sum
69
(
m_current_window
.mean_adc_peak() /
m_current_window
.mean_tot()) >
m_ratio_threshold
&&
// mean peak / tot cut
70
compute_treelite_classification
()
// XGBoost classifier
71
)
72
{
73
TLOG_DEBUG
(
TLVL_DEBUG_LOW
) <<
"[TAM:BSMW] ADC integral in window is greater than specified threshold."
;
74
output_ta.push_back(
construct_ta
());
75
TLOG_DEBUG
(
TLVL_DEBUG_HIGH
) <<
"[TAM:BSMW] Resetting window with input_tp."
;
76
m_current_window
.reset(input_tp);
77
}
78
// If it is not, move the window along.
79
else
{
80
TLOG_DEBUG
(
TLVL_DEBUG_ALL
) <<
"[TAM:BSMW] Window is at required length but adc threshold not met, shifting window along."
;
81
m_current_window
.move(input_tp,
m_window_length
);
82
}
83
84
TLOG_DEBUG
(
TLVL_DEBUG_ALL
) <<
"[TAM:BSMW] "
<<
m_current_window
;
85
86
m_primitive_count
++;
87
88
return
;
89
90
}
91
92
void
93
TAMakerProtoDUNEBSMWindowAlgorithm::configure
(
const
nlohmann::json &config)
94
{
95
if
(config.is_object()){
96
if
(config.contains(
"channel_map_name"
))
m_channel_map_name
= config[
"channel_map_name"
];
97
if
(config.contains(
"num_time_bins"
))
m_num_timebins
= config[
"num_time_bins"
];
98
if
(config.contains(
"adc_threshold"
))
m_adc_threshold
= config[
"adc_threshold"
];
99
if
(config.contains(
"ratio_threshold"
)) {
100
m_ratio_threshold
= config[
"ratio_threshold"
];
101
m_ratio_threshold
*= 0.01;
102
}
103
if
(config.contains(
"window_length"
)) {
104
m_window_length
= config[
"window_length"
];
105
m_bin_length
=
static_cast<
timestamp_t
>
(
m_window_length
/
m_num_timebins
);
106
}
107
if
(config.contains(
"bdt_threshold"
)) {
108
uint64_t int_bdt_threshold = config[
"bdt_threshold"
];
109
if
(int_bdt_threshold <= 100)
m_bdt_threshold
=
static_cast<
float
>
(int_bdt_threshold * 0.01);
110
else
if
(int_bdt_threshold <= 1000)
m_bdt_threshold
=
static_cast<
float
>
(int_bdt_threshold * 0.001);
111
else
if
(int_bdt_threshold <= 10000)
m_bdt_threshold
=
static_cast<
float
>
(int_bdt_threshold * 0.0001);
112
else
m_bdt_threshold
=
static_cast<
float
>
(int_bdt_threshold * 0.01);
113
}
114
}
115
else
{
116
TLOG_DEBUG
(
TLVL_IMPORTANT
) <<
"[TAM:BSMW] The DEFAULT values of window_length and adc_threshold are being used."
;
117
}
118
119
TLOG_DEBUG
(
TLVL_DEBUG_ALL
) <<
"[TAM:BSMW] Bin length is "
<<
m_bin_length
<<
" for a window of "
<<
m_num_timebins
<<
120
" bins. ADC threshold across window set to "
<<
m_adc_threshold
;
121
122
channelMap
= dunedaq::detchannelmaps::make_tpc_map(
m_channel_map_name
);
123
124
// If we are in PD-VD, set boolean to true to enable effective channel mapping
125
if
(
m_channel_map_name
==
"PD2VDTPCChannelMap"
||
m_channel_map_name
==
"PD2VDBottomTPCChannelMap"
||
126
m_channel_map_name
==
"PD2VDTopTPCChannelMap"
) {
127
m_pdvd_map
=
true
;
128
}
else
{
// else we are in PD-HD and we use true channel mapping
129
m_pdvd_map
=
false
;
130
}
131
132
m_compiled_model_interface
= std::make_unique<CompiledModelInterface>(
nbatch
);
133
134
const
size_t
num_feature =
m_compiled_model_interface
->GetNumFeatures();
135
136
flat_batched_inputs
.resize(num_feature);
137
138
m_num_chanbins
= num_feature /
m_num_timebins
;
139
140
flat_batched_Entries
.clear();
141
for
(
size_t
i = 0; i < num_feature; ++i) {
142
union
Entry
zero;
143
zero.
fvalue
= 0.0;
144
flat_batched_Entries
.emplace_back(zero);
145
}
146
}
147
148
TAMakerProtoDUNEBSMWindowAlgorithm::~TAMakerProtoDUNEBSMWindowAlgorithm
() {
149
// Nothing to clean up
150
}
151
152
TriggerActivity
153
TAMakerProtoDUNEBSMWindowAlgorithm::construct_ta
()
const
154
{
155
TLOG_DEBUG
(
TLVL_DEBUG_LOW
) <<
"[TAM:BSMW] I am constructing a trigger activity!"
;
156
157
TriggerPrimitive
latest_tp_in_window =
m_current_window
.tp_list.back();
158
// The time_peak, time_activity, channel_* and adc_peak fields of this TA are irrelevent
159
// for the purpose of this trigger alg.
160
TriggerActivity
ta;
161
ta.
time_start
=
m_current_window
.time_start;
162
ta.
time_end
= latest_tp_in_window.
time_start
+ latest_tp_in_window.
samples_over_threshold
* 32;
163
ta.
time_peak
= latest_tp_in_window.
samples_to_peak
* 32 + latest_tp_in_window.
time_start
;
164
ta.
time_activity
= ta.
time_peak
;
165
ta.
channel_start
= latest_tp_in_window.
channel
;
166
ta.
channel_end
= latest_tp_in_window.
channel
;
167
ta.
channel_peak
= latest_tp_in_window.
channel
;
168
ta.
adc_integral
=
m_current_window
.adc_integral;
169
ta.
adc_peak
= latest_tp_in_window.
adc_peak
;
170
ta.
detid
= latest_tp_in_window.
detid
;
171
ta.
type
=
TriggerActivity::Type::kTPC
;
172
ta.
algorithm
=
TriggerActivity::Algorithm::kUnknown
;
173
ta.
inputs
=
m_current_window
.tp_list;
174
return
ta;
175
}
176
177
bool
TAMakerProtoDUNEBSMWindowAlgorithm::compute_treelite_classification
() {
178
179
m_last_pred_time
=
m_current_window
.time_start;
180
181
m_current_window
.bin_window(
182
flat_batched_inputs
,
m_bin_length
,
183
m_chan_bin_length
,
m_num_timebins
,
184
m_num_chanbins
,
m_first_channel
,
185
m_pdvd_eff_channel_mapper
,
m_pdvd_map
186
);
187
188
m_current_window
.fill_entry_window(
flat_batched_Entries
,
flat_batched_inputs
);
189
190
std::vector<float> result(
nbatch
, 0.0f);
191
192
m_compiled_model_interface
->Predict(
flat_batched_Entries
.data(), result.data());
193
194
return
m_compiled_model_interface
->Classify(result.data(),
m_bdt_threshold
);
195
196
}
197
198
// Register algo in TA Factory
199
REGISTER_TRIGGER_ACTIVITY_MAKER
(
TRACE_NAME
,
TAMakerProtoDUNEBSMWindowAlgorithm
)
TAMakerProtoDUNEBSMWindowAlgorithm.hpp
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::TAMakerProtoDUNEBSMWindowAlgorithm
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:25
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_primitive_count
uint64_t m_primitive_count
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:44
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_current_window
ProtoDUNEBSMWindow m_current_window
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:41
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_ratio_threshold
float m_ratio_threshold
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:56
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::~TAMakerProtoDUNEBSMWindowAlgorithm
~TAMakerProtoDUNEBSMWindowAlgorithm() override
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.cpp:148
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_chan_bin_length
channel_t m_chan_bin_length
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:66
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::flat_batched_inputs
std::vector< float > flat_batched_inputs
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:50
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_bin_length
timestamp_t m_bin_length
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:63
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::flat_batched_Entries
std::vector< Entry > flat_batched_Entries
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:52
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_last_pred_time
timestamp_t m_last_pred_time
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:43
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_num_chanbins
int m_num_chanbins
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:67
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_pdvd_map
bool m_pdvd_map
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:80
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_num_timebins
int m_num_timebins
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:64
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::nbatch
const int nbatch
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:48
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_bdt_threshold
float m_bdt_threshold
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:57
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_window_length
timestamp_t m_window_length
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:58
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_channel_map_name
std::string m_channel_map_name
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:59
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::configure
void configure(const nlohmann::json &config)
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.cpp:93
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_first_channel
channel_t m_first_channel
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:82
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::construct_ta
TriggerActivity construct_ta() const
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.cpp:153
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::compute_treelite_classification
bool compute_treelite_classification()
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.cpp:177
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_pdvd_eff_channel_mapper
std::unique_ptr< PDVDEffectiveChannelMap > m_pdvd_eff_channel_mapper
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:78
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_adc_threshold
uint32_t m_adc_threshold
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:55
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::process
void process(const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)
TP processing function that creates & fills TAs.
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.cpp:24
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_det_plane_map
DetectorPlaneMap m_det_plane_map
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:74
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_last_channel
channel_t m_last_channel
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:83
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::channelMap
std::shared_ptr< dunedaq::detchannelmaps::TPCChannelMap > channelMap
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:70
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_compiled_model_interface
std::unique_ptr< CompiledModelInterface > m_compiled_model_interface
Definition
TAMakerProtoDUNEBSMWindowAlgorithm.hpp:86
TLOG_DEBUG
#define TLOG_DEBUG(lvl,...)
Definition
Logging.hpp:112
triggeralgs
Definition
AbstractFactory.hpp:18
triggeralgs::TLVL_IMPORTANT
@ TLVL_IMPORTANT
Definition
Logging.hpp:19
triggeralgs::TLVL_DEBUG_ALL
@ TLVL_DEBUG_ALL
Definition
Logging.hpp:25
triggeralgs::TLVL_DEBUG_LOW
@ TLVL_DEBUG_LOW
Definition
Logging.hpp:22
triggeralgs::TLVL_DEBUG_HIGH
@ TLVL_DEBUG_HIGH
Definition
Logging.hpp:24
triggeralgs::timestamp_t
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition
Types.hpp:16
triggeralgs::TriggerPrimitive
dunedaq::trgdataformats::TriggerPrimitive TriggerPrimitive
Definition
TriggerPrimitive.hpp:22
triggeralgs::channel_t
dunedaq::trgdataformats::channel_t channel_t
Definition
Types.hpp:20
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::kUnknown
@ kUnknown
Definition
TriggerActivityData.hpp:28
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
triggeralgs::PlaneInfo
Definition
DetectorPlaneMap.hpp:11
triggeralgs::PlaneInfo::min_channel
int min_channel
Definition
DetectorPlaneMap.hpp:12
triggeralgs::PlaneInfo::n_channels
int n_channels
Definition
DetectorPlaneMap.hpp:13
triggeralgs::TriggerActivity
Definition
TriggerActivity.hpp:20
triggeralgs::TriggerActivity::inputs
std::vector< TriggerPrimitive > inputs
Definition
TriggerActivity.hpp:33
triggeralgs::Entry
Definition
treelitemodel.hpp:20
triggeralgs::Entry::fvalue
float fvalue
Definition
treelitemodel.hpp:22
Generated on
for DUNE-DAQ by
1.17.0