DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm Class Reference

#include <TAMakerProtoDUNEBSMWindowAlgorithm.hpp>

Inheritance diagram for triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm:
[legend]
Collaboration diagram for triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm:
[legend]

Public Member Functions

void process (const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)
 TP processing function that creates & fills TAs.
 
void configure (const nlohmann::json &config)
 
 ~TAMakerProtoDUNEBSMWindowAlgorithm () override
 
- Public Member Functions inherited from triggeralgs::TriggerActivityMaker
virtual ~TriggerActivityMaker ()=default
 
void operator() (const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)
 
virtual bool preprocess (const TriggerPrimitive &input_tp)
 TP pre-processing/filtering.
 
virtual void postprocess (std::vector< TriggerActivity > &output_ta)
 Post-processing/filtering of the TAs, e.g. prescale.
 
virtual void flush (timestamp_t, std::vector< TriggerActivity > &)
 

Private Member Functions

bool compute_treelite_classification ()
 
TriggerActivity construct_ta () const
 

Private Attributes

ProtoDUNEBSMWindow m_current_window
 
timestamp_t m_last_pred_time
 
uint64_t m_primitive_count = 0
 
const int nbatch = 1
 
std::vector< float > flat_batched_inputs
 
std::vector< Entryflat_batched_Entries
 
uint32_t m_adc_threshold = 200000
 
float m_ratio_threshold = 0.65
 
float m_bdt_threshold = 0.99
 
timestamp_t m_window_length = 20000
 
std::string m_channel_map_name = "PD2VDTPCChannelMap"
 
timestamp_t m_bin_length = 4000
 
int m_num_timebins = 5
 
channel_t m_chan_bin_length = 100
 
int m_num_chanbins = 5
 
std::shared_ptr< dunedaq::detchannelmaps::TPCChannelMap > channelMap
 
DetectorPlaneMap m_det_plane_map
 
std::unique_ptr< PDVDEffectiveChannelMapm_pdvd_eff_channel_mapper = nullptr
 
bool m_pdvd_map = true
 
channel_t m_first_channel
 
channel_t m_last_channel
 
std::unique_ptr< CompiledModelInterfacem_compiled_model_interface
 

Additional Inherited Members

- Public Attributes inherited from triggeralgs::TriggerActivityMaker
std::atomic< uint64_t > m_data_vs_system_time = 0
 
std::atomic< uint64_t > m_initial_offset = 0
 
uint64_t m_prescale = 1
 Configurable prescale factor.
 
uint64_t m_ta_count = 0
 TA made count for prescaling.
 
uint32_t m_max_samples_over_threshold = std::numeric_limits<uint32_t>::max()
 Time-over-threshold TP filtering.
 

Detailed Description

Definition at line 24 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

Constructor & Destructor Documentation

◆ ~TAMakerProtoDUNEBSMWindowAlgorithm()

TAMakerProtoDUNEBSMWindowAlgorithm::~TAMakerProtoDUNEBSMWindowAlgorithm ( )
override

Definition at line 148 of file TAMakerProtoDUNEBSMWindowAlgorithm.cpp.

148 {
149 // Nothing to clean up
150}

Member Function Documentation

◆ compute_treelite_classification()

bool TAMakerProtoDUNEBSMWindowAlgorithm::compute_treelite_classification ( )
private

Definition at line 177 of file TAMakerProtoDUNEBSMWindowAlgorithm.cpp.

177 {
178
180
186 );
187
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}
void fill_entry_window(std::vector< Entry > &entry_input, std::vector< float > &input)
void bin_window(std::vector< float > &input, timestamp_t time_bin_width, channel_t chan_bin_width, int num_time_bins, int num_chan_bins, channel_t first_channel, std::unique_ptr< PDVDEffectiveChannelMap > const &effective_channel_mapper, bool use_pdvd_map)
std::unique_ptr< PDVDEffectiveChannelMap > m_pdvd_eff_channel_mapper
std::unique_ptr< CompiledModelInterface > m_compiled_model_interface

◆ configure()

void TAMakerProtoDUNEBSMWindowAlgorithm::configure ( const nlohmann::json & config)
virtual

Reimplemented from triggeralgs::TriggerActivityMaker.

Definition at line 93 of file TAMakerProtoDUNEBSMWindowAlgorithm.cpp.

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"];
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}
std::shared_ptr< dunedaq::detchannelmaps::TPCChannelMap > channelMap
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16

◆ construct_ta()

TriggerActivity TAMakerProtoDUNEBSMWindowAlgorithm::construct_ta ( ) const
private

Definition at line 153 of file TAMakerProtoDUNEBSMWindowAlgorithm.cpp.

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.
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;
169 ta.adc_peak = latest_tp_in_window.adc_peak;
170 ta.detid = latest_tp_in_window.detid;
174 return ta;
175}
std::vector< TriggerPrimitive > tp_list
A single energy deposition on a TPC or PDS channel.
std::vector< TriggerPrimitive > inputs

◆ process()

void TAMakerProtoDUNEBSMWindowAlgorithm::process ( const TriggerPrimitive & input_tp,
std::vector< TriggerActivity > & output_ta )
virtual

TP processing function that creates & fills TAs.

Parameters
input_tp[in]Input TP for the triggering algorithm
output_ta[out]Output vector of TAs to fill by the algorithm

Implements triggeralgs::TriggerActivityMaker.

Definition at line 24 of file TAMakerProtoDUNEBSMWindowAlgorithm.cpp.

25{
26
28 m_current_window.reset(input_tp);
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();
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.
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
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.";
82 }
83
84 TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TAM:BSMW] " << m_current_window;
85
87
88 return;
89
90}
void add(TriggerPrimitive const &input_tp)
void reset(TriggerPrimitive const &input_tp)
void move(TriggerPrimitive const &input_tp, timestamp_t const &window_length)
dunedaq::trgdataformats::channel_t channel_t
Definition Types.hpp:20
PlaneInfo get_plane_info(std::string channel_map_name, int detelement, int plane)

Member Data Documentation

◆ channelMap

std::shared_ptr<dunedaq::detchannelmaps::TPCChannelMap> triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::channelMap
private

Definition at line 70 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ flat_batched_Entries

std::vector<Entry> triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::flat_batched_Entries
private

Definition at line 52 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ flat_batched_inputs

std::vector<float> triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::flat_batched_inputs
private

Definition at line 50 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_adc_threshold

uint32_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_adc_threshold = 200000
private

Definition at line 55 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_bdt_threshold

float triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_bdt_threshold = 0.99
private

Definition at line 57 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_bin_length

timestamp_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_bin_length = 4000
private

Definition at line 63 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_chan_bin_length

channel_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_chan_bin_length = 100
private

Definition at line 66 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_channel_map_name

std::string triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_channel_map_name = "PD2VDTPCChannelMap"
private

Definition at line 59 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_compiled_model_interface

std::unique_ptr<CompiledModelInterface> triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_compiled_model_interface
private

Definition at line 86 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_current_window

ProtoDUNEBSMWindow triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_current_window
private

Definition at line 41 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_det_plane_map

DetectorPlaneMap triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_det_plane_map
private

Definition at line 74 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_first_channel

channel_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_first_channel
private

Definition at line 82 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_last_channel

channel_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_last_channel
private

Definition at line 83 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_last_pred_time

timestamp_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_last_pred_time
private

Definition at line 43 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_num_chanbins

int triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_num_chanbins = 5
private

Definition at line 67 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_num_timebins

int triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_num_timebins = 5
private

Definition at line 64 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_pdvd_eff_channel_mapper

std::unique_ptr<PDVDEffectiveChannelMap> triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_pdvd_eff_channel_mapper = nullptr
private

Definition at line 78 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_pdvd_map

bool triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_pdvd_map = true
private

Definition at line 80 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_primitive_count

uint64_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_primitive_count = 0
private

Definition at line 44 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_ratio_threshold

float triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_ratio_threshold = 0.65
private

Definition at line 56 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ m_window_length

timestamp_t triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::m_window_length = 20000
private

Definition at line 58 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.

◆ nbatch

const int triggeralgs::TAMakerProtoDUNEBSMWindowAlgorithm::nbatch = 1
private

Definition at line 48 of file TAMakerProtoDUNEBSMWindowAlgorithm.hpp.


The documentation for this class was generated from the following files: