From 808497da7af55736e2c805363b5cb69728cbfd4d Mon Sep 17 00:00:00 2001 From: adam-abed-abud Date: Thu, 11 Apr 2024 10:20:43 +0200 Subject: [PATCH 1/5] Developing TPG threshold by plane --- .../wibeth/WIBEthFrameProcessor.hpp | 12 ++++++++-- .../fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp | 5 +++-- .../wibeth/tpg/ProcessAbsRSAVX2.hpp | 5 +++-- .../wibeth/tpg/ProcessStandardRSAVX2.hpp | 7 +++--- .../wibeth/tpg/ProcessingInfo.hpp | 15 ++++++++++--- src/wibeth/WIBEthFrameProcessor.cpp | 22 ++++++++++++++----- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp b/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp index 2dc5e8d..4a98888 100644 --- a/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp +++ b/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp @@ -58,7 +58,7 @@ class WIBEthFrameHandler { void reset(); - void initialize(uint16_t threshold_value, uint16_t memory_factor, uint16_t scale_factor, int16_t frug_streaming_acclimt); + void initialize(uint16_t memory_factor, uint16_t scale_factor, int16_t frug_streaming_acclimt); uint16_t* get_hits_dest(); @@ -157,7 +157,10 @@ class WIBEthFrameProcessor : public readoutlibs::TaskRawDataProcessorModel m_channel_mask_vec; std::set m_channel_mask_set; - uint16_t m_tpg_threshold; + + uint16_t m_tpg_threshold_collection; + uint16_t m_tpg_threshold_induction1; + uint16_t m_tpg_threshold_induction2; // Algorithm used to form a trigger primitive dunedaq::trgdataformats::TriggerPrimitive::Algorithm m_tp_algo = trgdataformats::TriggerPrimitive::Algorithm::kUnknown; @@ -185,6 +188,11 @@ class WIBEthFrameProcessor : public readoutlibs::TaskRawDataProcessorModel m_register_memory_factor = {0}; + // Create an array to store the values of the TPG threshold + // This is to be used for setting a different value by plane + // By default set it to 150 + std::array m_tpg_threshold = {150}; + std::function& info)> m_assigned_tpg_algorithm_function; diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp index d7f15ee..434f875 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp @@ -42,6 +42,8 @@ process_window_avx2(ProcessingInfo& info) // from the previous go-around. ChanState& state = info.chanState; + __m256i threshold = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.threshold) + ireg); // NOLINT + __m256i median = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.pedestals) + ireg); // NOLINT // The accumulator that we increase/decrease when the current // sample is greater/less than the median @@ -93,8 +95,7 @@ process_window_avx2(ProcessingInfo& info) // -------------------------------------------------------------- // Mask for channels that are over the threshold in this step - // FIXED THRESHOLD - __m256i threshold = _mm256_set1_epi16(info.threshold); + // Define a register for elements above the threhsold __m256i is_over = _mm256_cmpgt_epi16(s, threshold); // Mask for channels that left "over threshold" state this step diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp index 11cbf50..6019419 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp @@ -55,6 +55,8 @@ process_window_rs_avx2(ProcessingInfo& info) // from the previous go-around. ChanState& state = info.chanState; + __m256i threshold = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.threshold) + ireg); // NOLINT + __m256i median = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.pedestals) + ireg); // NOLINT //__m256i quantile25 = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.quantile25) + ireg); // NOLINT //__m256i quantile75 = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.quantile75) + ireg); // NOLINT @@ -183,8 +185,7 @@ process_window_rs_avx2(ProcessingInfo& info) // IQR-based THRESHOLD //__m256i is_over = _mm256_cmpgt_epi16(RS, sigma * info.threshold); - // FIXED THRESHOLD - __m256i threshold = _mm256_set1_epi16(info.threshold); + // Define a register for elements above the threhsold __m256i is_over = _mm256_cmpgt_epi16(RS, threshold); diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp index b44ddf3..3a82178 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp @@ -31,7 +31,7 @@ process_window_standard_rs_avx2(ProcessingInfo& info) // Scaling factor to stop the ADCs from overflowing // (may not needs this, depends on magnitude of FIR output) - const __m256i scale_factor = _mm256_set1_epi16(info.rs_scale_factor); + //const __m256i scale_factor = _mm256_set1_epi16(info.rs_scale_factor); // The maximum value that sigma can have before the threshold overflows a 16-bit signed integer //const __m256i sigmaMax = _mm256_set1_epi16((1 << 15) / (info.multiplier * info.threshold)); @@ -55,6 +55,8 @@ process_window_standard_rs_avx2(ProcessingInfo& info) // from the previous go-around. ChanState& state = info.chanState; + __m256i threshold = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.threshold) + ireg); // NOLINT + __m256i median = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.pedestals) + ireg); // NOLINT //__m256i quantile25 = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.quantile25) + ireg); // NOLINT //__m256i quantile75 = _mm256_lddqu_si256(reinterpret_cast<__m256i*>(state.quantile75) + ireg); // NOLINT @@ -178,8 +180,7 @@ process_window_standard_rs_avx2(ProcessingInfo& info) // IQR-based THRESHOLD //__m256i is_over = _mm256_cmpgt_epi16(RS, sigma * info.threshold); - // FIXED THRESHOLD - __m256i threshold = _mm256_set1_epi16(info.threshold); + // Define a register for elements above the threhsold __m256i is_over = _mm256_cmpgt_epi16(RS, threshold); diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp index 775fd20..cf849e6 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp @@ -23,6 +23,7 @@ struct ChanState ChanState() { for (size_t i = 0; i < NREGISTERS * SAMPLES_PER_REGISTER; ++i) { + threshold[i] = 0; pedestals[i] = 0; accum[i] = 0; RS[i] = 0; @@ -39,6 +40,7 @@ struct ChanState } } + alignas(32) int16_t __restrict__ threshold[NREGISTERS * SAMPLES_PER_REGISTER]; alignas(32) int16_t __restrict__ pedestals[NREGISTERS * SAMPLES_PER_REGISTER]; alignas(32) int16_t __restrict__ accum[NREGISTERS * SAMPLES_PER_REGISTER]; @@ -74,7 +76,6 @@ struct ProcessingInfo uint8_t last_register_, // NOLINT uint16_t* __restrict__ output_, // NOLINT const uint8_t exponent_, // NOLINT - uint16_t threshold_, // NOLINT uint16_t rs_memory_factor_, // NOLINT uint16_t rs_scale_factor_, // NOLINT int16_t frugal_streaming_accumulator_limit_, // NOLINT @@ -86,7 +87,6 @@ struct ProcessingInfo , last_register(last_register_) , output(output_) , exponent(exponent_) - , threshold(threshold_) , rs_memory_factor(rs_memory_factor_) , rs_scale_factor(rs_scale_factor_) , frugal_streaming_accumulator_limit(frugal_streaming_accumulator_limit_) @@ -95,6 +95,16 @@ struct ProcessingInfo , nhits(nhits_) {} + // Set TPG threshold by plane + void setThresholdState(std::array& register_threshold + ) + { + // Set the threshold values + for (size_t j = 0; j < NREGISTERS * SAMPLES_PER_REGISTER; ++j) { + chanState.threshold[j] = register_threshold[j]; + } + + } // Set the initial state from the window starting at first_msg_p template @@ -153,7 +163,6 @@ struct ProcessingInfo uint8_t last_register; // NOLINT uint16_t* __restrict__ output; // NOLINT uint8_t exponent; // NOLINT - uint16_t threshold; // NOLINT uint16_t rs_memory_factor; // NOLINT uint16_t rs_scale_factor; // NOLINT int16_t frugal_streaming_accumulator_limit; // NOLINT diff --git a/src/wibeth/WIBEthFrameProcessor.cpp b/src/wibeth/WIBEthFrameProcessor.cpp index bef71b1..de12917 100644 --- a/src/wibeth/WIBEthFrameProcessor.cpp +++ b/src/wibeth/WIBEthFrameProcessor.cpp @@ -72,7 +72,7 @@ WIBEthFrameHandler::reset() } void -WIBEthFrameHandler::initialize(uint16_t threshold_value, uint16_t memory_factor, uint16_t scale_factor, int16_t frug_streaming_acclimt) +WIBEthFrameHandler::initialize(uint16_t memory_factor, uint16_t scale_factor, int16_t frug_streaming_acclimt) { if(m_hits_dest == nullptr) {m_hits_dest = new uint16_t[100000];} @@ -83,7 +83,6 @@ WIBEthFrameHandler::initialize(uint16_t threshold_value, uint16_t memory_factor, swtpg_wibeth::NUM_REGISTERS_PER_FRAME, m_hits_dest, m_tpg_exponent, - threshold_value, memory_factor, scale_factor, frug_streaming_acclimt, @@ -116,8 +115,7 @@ WIBEthFrameProcessor::start(const nlohmann::json& args) m_tps_suppressed_too_long = 0; m_tps_send_failed = 0; - m_wibeth_frame_handler->initialize(m_tpg_threshold, - m_tpg_rs_memory_factor, + m_wibeth_frame_handler->initialize(m_tpg_rs_memory_factor, m_tpg_rs_scale_factor, m_tpg_frugal_streaming_accumulator_limit ); @@ -217,7 +215,12 @@ WIBEthFrameProcessor::conf(const nlohmann::json& cfg) // AAA: The set provides faster look up than a std::vector m_channel_mask_set.insert(m_channel_mask_vec.begin(), m_channel_mask_vec.end()); - m_tpg_threshold = config.tpg_threshold; + m_tpg_threshold_collection = config.tpg_threshold; + m_tpg_threshold_induction1 = config.tpg_threshold; + m_tpg_threshold_induction2 = config.tpg_threshold; + + + m_crate_no = config.crate_id; m_slot_no = config.slot_id; @@ -439,12 +442,18 @@ WIBEthFrameProcessor::find_hits(constframeptr fp, WIBEthFrameHandler* frame_hand m_register_channels[i] = chan_value; if (m_enable_simple_threshold_on_collection) { - // If the given channel is a collection then set R (memory factor) to zero + // If the given channel is a collection then set R (memory factor) to zero for collection if (m_channel_map->get_plane_from_offline_channel(chan_value) == 0 ) { m_register_memory_factor[i] = 0; + m_tpg_threshold[i] = m_tpg_threshold_collection; + } else if (m_channel_map->get_plane_from_offline_channel(chan_value) == 1) { + m_register_memory_factor[i] = m_tpg_rs_memory_factor; + m_tpg_threshold[i] = m_tpg_threshold_induction1; } else { m_register_memory_factor[i] = m_tpg_rs_memory_factor; + m_tpg_threshold[i] = m_tpg_threshold_induction2; } + // } else { m_register_memory_factor[i] = m_tpg_rs_memory_factor; } @@ -455,6 +464,7 @@ WIBEthFrameProcessor::find_hits(constframeptr fp, WIBEthFrameHandler* frame_hand m_tp_channel_rate_map[frame_handler->register_channel_map.channel[i]] = 0; } + frame_handler->m_tpg_processing_info->setThresholdState(m_tpg_threshold); frame_handler->m_tpg_processing_info->setState(registers_array, m_register_memory_factor); From b3957e1fa5fafbc1b4baf34b6044d392f7002076 Mon Sep 17 00:00:00 2001 From: aeoranday Date: Thu, 25 Apr 2024 09:21:02 +0200 Subject: [PATCH 2/5] Added plane threshold config setting. --- src/wibeth/WIBEthFrameProcessor.cpp | 33 ++++++++++++----------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/wibeth/WIBEthFrameProcessor.cpp b/src/wibeth/WIBEthFrameProcessor.cpp index de12917..f842109 100644 --- a/src/wibeth/WIBEthFrameProcessor.cpp +++ b/src/wibeth/WIBEthFrameProcessor.cpp @@ -215,12 +215,10 @@ WIBEthFrameProcessor::conf(const nlohmann::json& cfg) // AAA: The set provides faster look up than a std::vector m_channel_mask_set.insert(m_channel_mask_vec.begin(), m_channel_mask_vec.end()); - m_tpg_threshold_collection = config.tpg_threshold; - m_tpg_threshold_induction1 = config.tpg_threshold; - m_tpg_threshold_induction2 = config.tpg_threshold; - - - + // Use config._threshold if it is non-zero, else default to config.tpg_threshold. + m_tpg_threshold_collection = config.collection_threshold ? config.collection_threshold : config.tpg_threshold; + m_tpg_threshold_induction1 = config.induction1_threshold ? config.induction1_threshold : config.tpg_threshold; + m_tpg_threshold_induction2 = config.induction2_threshold ? config.induction2_threshold : config.tpg_threshold; m_crate_no = config.crate_id; m_slot_no = config.slot_id; @@ -441,21 +439,16 @@ WIBEthFrameProcessor::find_hits(constframeptr fp, WIBEthFrameHandler* frame_hand auto chan_value = frame_handler->register_channel_map.channel[i]; m_register_channels[i] = chan_value; - if (m_enable_simple_threshold_on_collection) { - // If the given channel is a collection then set R (memory factor) to zero for collection - if (m_channel_map->get_plane_from_offline_channel(chan_value) == 0 ) { - m_register_memory_factor[i] = 0; - m_tpg_threshold[i] = m_tpg_threshold_collection; - } else if (m_channel_map->get_plane_from_offline_channel(chan_value) == 1) { - m_register_memory_factor[i] = m_tpg_rs_memory_factor; - m_tpg_threshold[i] = m_tpg_threshold_induction1; - } else { - m_register_memory_factor[i] = m_tpg_rs_memory_factor; - m_tpg_threshold[i] = m_tpg_threshold_induction2; - } - // - } else { + if (m_channel_map->get_plane_from_offline_channel(chan_value) == 0 ) { // Collection + // If SimpleThreshold on collection, then set the memory factor to 0, else use the common memory factor. + m_register_memory_factor[i] = m_enable_simple_threshold_on_collection ? 0 : m_tpg_rs_memory_factor; + m_tpg_threshold[i] = m_tpg_threshold_collection; + } else if (m_channel_map->get_plane_from_offline_channel(chan_value) == 1) { // Induction 1 + m_register_memory_factor[i] = m_tpg_rs_memory_factor; + m_tpg_threshold[i] = m_tpg_threshold_induction1; + } else { // Induction 2 m_register_memory_factor[i] = m_tpg_rs_memory_factor; + m_tpg_threshold[i] = m_tpg_threshold_induction2; } //TLOG () << "Index number " << i << " offline channel " << frame_handler->register_channel_map.channel[i]; From 1f10ee93303d1aea1767f1a4c6b479d273ac02b9 Mon Sep 17 00:00:00 2001 From: aeoranday Date: Thu, 25 Apr 2024 13:30:59 +0200 Subject: [PATCH 3/5] Added NAIVE thresholding per plane (channel). --- include/fdreadoutlibs/wibeth/tpg/ProcessNaive.hpp | 3 ++- include/fdreadoutlibs/wibeth/tpg/ProcessNaiveRS.hpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessNaive.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessNaive.hpp index 9a6ecf1..1dc764c 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessNaive.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessNaive.hpp @@ -63,6 +63,7 @@ process_window_naive(ProcessingInfo& info) int16_t& accum = state.accum[ichan]; // Variables for hit finding + int16_t& threshold = state.threshold[ichan]; // Threshold for this channel. uint16_t& prev_was_over = state.prev_was_over[ichan]; // was the previous sample over threshold? uint16_t& hit_charge = state.hit_charge[ichan]; uint16_t& hit_tover = state.hit_tover[ichan]; // time over threshold @@ -90,7 +91,7 @@ process_window_naive(ProcessingInfo& info) // -------------------------------------------------------------- // Hit finding // -------------------------------------------------------------- - bool is_over = sample > info.threshold; + bool is_over = sample > threshold; //printf("% 5d % 5d % 5d % 5d\n", (uint16_t)ichan, (uint16_t)itime, sample, info.threshold); // NOLINT if (is_over) { // Simulate saturated add diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessNaiveRS.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessNaiveRS.hpp index e5db9b9..d4ae760 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessNaiveRS.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessNaiveRS.hpp @@ -57,6 +57,7 @@ process_window_naive_RS(ProcessingInfo& info) //int16_t& quantile75 = state.quantile75[ichan]; // Variables for hit finding + int16_t& threshold = state.threshold[ichan]; // Threshold for this channel. uint16_t& prev_was_over = state.prev_was_over[ichan]; // was the previous sample over threshold? uint16_t& hit_charge = state.hit_charge[ichan]; uint16_t& hit_tover = state.hit_tover[ichan]; // time over threshold @@ -116,7 +117,7 @@ process_window_naive_RS(ProcessingInfo& info) // -------------------------------------------------------------- // Hit finding // -------------------------------------------------------------- - bool is_over = RS > info.threshold; + bool is_over = RS > threshold; if (is_over) { // Simulate saturated add int32_t tmp_charge = hit_charge; From a4113464fe24a22e2ffd08cca06856af83fe4138 Mon Sep 17 00:00:00 2001 From: aeoranday Date: Mon, 6 May 2024 06:47:00 +0200 Subject: [PATCH 4/5] Fixed the plane numbering. --- include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp | 2 +- include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp | 2 +- .../fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp | 2 +- include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp | 4 +++- .../fdreadoutlibs/wibeth/tpg/TPGConstants_wibeth.hpp | 3 +++ src/wibeth/WIBEthFrameProcessor.cpp | 10 +++++----- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp index 434f875..2376921 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessAVX2.hpp @@ -29,7 +29,7 @@ process_window_avx2(ProcessingInfo& info) // Pointer to keep track of where we'll write the next output hit __m256i* output_loc = (__m256i*)(info.output); // NOLINT(readability/casting) - const __m256i iota = _mm256_set_epi16(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); + const __m256i iota = _mm256_lddqu_si256((__m256i*) IOTA); int nhits = 0; diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp index 6019419..c04deed 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessAbsRSAVX2.hpp @@ -39,7 +39,7 @@ process_window_rs_avx2(ProcessingInfo& info) // Pointer to keep track of where we'll write the next output hit __m256i* output_loc = (__m256i*)(info.output); // NOLINT(readability/casting) - const __m256i iota = _mm256_set_epi16(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); + const __m256i iota = _mm256_lddqu_si256((__m256i*) IOTA); int nhits = 0; diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp index 3a82178..d4ee3fb 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessStandardRSAVX2.hpp @@ -39,7 +39,7 @@ process_window_standard_rs_avx2(ProcessingInfo& info) // Pointer to keep track of where we'll write the next output hit __m256i* output_loc = (__m256i*)(info.output); // NOLINT(readability/casting) - const __m256i iota = _mm256_set_epi16(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); + const __m256i iota = _mm256_lddqu_si256((__m256i*) IOTA); int nhits = 0; diff --git a/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp b/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp index cf849e6..49d298d 100644 --- a/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/ProcessingInfo.hpp @@ -101,7 +101,9 @@ struct ProcessingInfo { // Set the threshold values for (size_t j = 0; j < NREGISTERS * SAMPLES_PER_REGISTER; ++j) { - chanState.threshold[j] = register_threshold[j]; + const size_t i = IOTA[j % SAMPLES_PER_REGISTER]; + const size_t reg_idx = j / SAMPLES_PER_REGISTER; + chanState.threshold[j] = register_threshold[i + reg_idx * SAMPLES_PER_REGISTER]; } } diff --git a/include/fdreadoutlibs/wibeth/tpg/TPGConstants_wibeth.hpp b/include/fdreadoutlibs/wibeth/tpg/TPGConstants_wibeth.hpp index 5d43794..3c0e6d9 100644 --- a/include/fdreadoutlibs/wibeth/tpg/TPGConstants_wibeth.hpp +++ b/include/fdreadoutlibs/wibeth/tpg/TPGConstants_wibeth.hpp @@ -30,6 +30,9 @@ const constexpr std::size_t BYTES_PER_REGISTER = 32; // How many samples are in a register const constexpr std::size_t SAMPLES_PER_REGISTER = 16; +// Order of the channels after frame expansion. +const constexpr std::uint16_t IOTA[SAMPLES_PER_REGISTER] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + // One netio message's worth of channel ADCs after // expansion: 64 frames per message times 4 registers per frame times // 32 bytes (256 bits) per register diff --git a/src/wibeth/WIBEthFrameProcessor.cpp b/src/wibeth/WIBEthFrameProcessor.cpp index f842109..6415cf1 100644 --- a/src/wibeth/WIBEthFrameProcessor.cpp +++ b/src/wibeth/WIBEthFrameProcessor.cpp @@ -439,16 +439,16 @@ WIBEthFrameProcessor::find_hits(constframeptr fp, WIBEthFrameHandler* frame_hand auto chan_value = frame_handler->register_channel_map.channel[i]; m_register_channels[i] = chan_value; - if (m_channel_map->get_plane_from_offline_channel(chan_value) == 0 ) { // Collection + if (m_channel_map->get_plane_from_offline_channel(chan_value) == 2 ) { // Collection // If SimpleThreshold on collection, then set the memory factor to 0, else use the common memory factor. m_register_memory_factor[i] = m_enable_simple_threshold_on_collection ? 0 : m_tpg_rs_memory_factor; m_tpg_threshold[i] = m_tpg_threshold_collection; - } else if (m_channel_map->get_plane_from_offline_channel(chan_value) == 1) { // Induction 1 - m_register_memory_factor[i] = m_tpg_rs_memory_factor; - m_tpg_threshold[i] = m_tpg_threshold_induction1; - } else { // Induction 2 + } else if (m_channel_map->get_plane_from_offline_channel(chan_value) == 1) { // Induction 2 m_register_memory_factor[i] = m_tpg_rs_memory_factor; m_tpg_threshold[i] = m_tpg_threshold_induction2; + } else { // Induction 1 + m_register_memory_factor[i] = m_tpg_rs_memory_factor; + m_tpg_threshold[i] = m_tpg_threshold_induction1; } //TLOG () << "Index number " << i << " offline channel " << frame_handler->register_channel_map.channel[i]; From 119fc48e61afa9531ae050e53ef6d77f1e276332 Mon Sep 17 00:00:00 2001 From: aeoranday Date: Thu, 9 May 2024 10:56:18 +0200 Subject: [PATCH 5/5] Updated TPG threshold word chioce for planes 0,1,2. --- .../wibeth/WIBEthFrameProcessor.hpp | 10 +++---- src/wib2/WIB2FrameProcessor.cpp | 2 +- src/wibeth/WIBEthFrameProcessor.cpp | 30 +++++++++---------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp b/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp index 4a98888..2cef7a9 100644 --- a/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp +++ b/include/fdreadoutlibs/wibeth/WIBEthFrameProcessor.hpp @@ -146,7 +146,7 @@ class WIBEthFrameProcessor : public readoutlibs::TaskRawDataProcessorModel m_channel_mask_vec; std::set m_channel_mask_set; - uint16_t m_tpg_threshold_collection; - uint16_t m_tpg_threshold_induction1; - uint16_t m_tpg_threshold_induction2; + uint16_t m_tpg_threshold_plane0; + uint16_t m_tpg_threshold_plane1; + uint16_t m_tpg_threshold_plane2; // Algorithm used to form a trigger primitive dunedaq::trgdataformats::TriggerPrimitive::Algorithm m_tp_algo = trgdataformats::TriggerPrimitive::Algorithm::kUnknown; @@ -184,7 +184,7 @@ class WIBEthFrameProcessor : public readoutlibs::TaskRawDataProcessorModel m_register_memory_factor = {0}; diff --git a/src/wib2/WIB2FrameProcessor.cpp b/src/wib2/WIB2FrameProcessor.cpp index 4d36973..709adb2 100644 --- a/src/wib2/WIB2FrameProcessor.cpp +++ b/src/wib2/WIB2FrameProcessor.cpp @@ -209,7 +209,7 @@ WIB2FrameProcessor::conf(const nlohmann::json& cfg) // AAA: The set provides faster look up than a std::vector m_channel_mask_set.insert(m_channel_mask_vec.begin(), m_channel_mask_vec.end()); - m_tpg_threshold_selected = config.tpg_threshold; + m_tpg_threshold_selected = config.tpg_threshold_default; m_crate_no = config.crate_id; m_slot_no = config.slot_id; diff --git a/src/wibeth/WIBEthFrameProcessor.cpp b/src/wibeth/WIBEthFrameProcessor.cpp index 6415cf1..a7b21ba 100644 --- a/src/wibeth/WIBEthFrameProcessor.cpp +++ b/src/wibeth/WIBEthFrameProcessor.cpp @@ -183,13 +183,13 @@ WIBEthFrameProcessor::conf(const nlohmann::json& cfg) } else if (m_tpg_algorithm == "AbsRS" ) { m_tp_algo = trgdataformats::TriggerPrimitive::Algorithm::kAbsRunningSum; m_assigned_tpg_algorithm_function = &swtpg_wibeth::process_window_rs_avx2; - // Enable simple threshold on collection is used only if you are using a Running Sum algorithm - m_enable_simple_threshold_on_collection = config.enable_simple_threshold_on_collection; + // Enable simple threshold on plane 2 is used only if you are using a Running Sum algorithm + m_enable_simple_threshold_on_plane2 = config.enable_simple_threshold_on_plane2; } else if (m_tpg_algorithm == "StandardRS" ) { m_tp_algo = trgdataformats::TriggerPrimitive::Algorithm::kRunningSum; m_assigned_tpg_algorithm_function = &swtpg_wibeth::process_window_standard_rs_avx2; - // Enable simple threshold on collection is used only if you are using a Running Sum algorithm - m_enable_simple_threshold_on_collection = config.enable_simple_threshold_on_collection; + // Enable simple threshold on plane 2 is used only if you are using a Running Sum algorithm + m_enable_simple_threshold_on_plane2 = config.enable_simple_threshold_on_plane2; } else { throw TPGAlgorithmInexistent(ERS_HERE, m_tpg_algorithm); } @@ -216,9 +216,9 @@ WIBEthFrameProcessor::conf(const nlohmann::json& cfg) m_channel_mask_set.insert(m_channel_mask_vec.begin(), m_channel_mask_vec.end()); // Use config._threshold if it is non-zero, else default to config.tpg_threshold. - m_tpg_threshold_collection = config.collection_threshold ? config.collection_threshold : config.tpg_threshold; - m_tpg_threshold_induction1 = config.induction1_threshold ? config.induction1_threshold : config.tpg_threshold; - m_tpg_threshold_induction2 = config.induction2_threshold ? config.induction2_threshold : config.tpg_threshold; + m_tpg_threshold_plane2 = config.tpg_threshold_plane2 ? config.tpg_threshold_plane2 : config.tpg_threshold_default; + m_tpg_threshold_plane1 = config.tpg_threshold_plane1 ? config.tpg_threshold_plane1 : config.tpg_threshold_default; + m_tpg_threshold_plane0 = config.tpg_threshold_plane0 ? config.tpg_threshold_plane0 : config.tpg_threshold_default; m_crate_no = config.crate_id; m_slot_no = config.slot_id; @@ -439,16 +439,16 @@ WIBEthFrameProcessor::find_hits(constframeptr fp, WIBEthFrameHandler* frame_hand auto chan_value = frame_handler->register_channel_map.channel[i]; m_register_channels[i] = chan_value; - if (m_channel_map->get_plane_from_offline_channel(chan_value) == 2 ) { // Collection - // If SimpleThreshold on collection, then set the memory factor to 0, else use the common memory factor. - m_register_memory_factor[i] = m_enable_simple_threshold_on_collection ? 0 : m_tpg_rs_memory_factor; - m_tpg_threshold[i] = m_tpg_threshold_collection; - } else if (m_channel_map->get_plane_from_offline_channel(chan_value) == 1) { // Induction 2 + if (m_channel_map->get_plane_from_offline_channel(chan_value) == 2 ) { + // If SimpleThreshold on plane 2, then set the memory factor to 0, else use the common memory factor. + m_register_memory_factor[i] = m_enable_simple_threshold_on_plane2 ? 0 : m_tpg_rs_memory_factor; + m_tpg_threshold[i] = m_tpg_threshold_plane2; + } else if (m_channel_map->get_plane_from_offline_channel(chan_value) == 1) { m_register_memory_factor[i] = m_tpg_rs_memory_factor; - m_tpg_threshold[i] = m_tpg_threshold_induction2; - } else { // Induction 1 + m_tpg_threshold[i] = m_tpg_threshold_plane1; + } else { m_register_memory_factor[i] = m_tpg_rs_memory_factor; - m_tpg_threshold[i] = m_tpg_threshold_induction1; + m_tpg_threshold[i] = m_tpg_threshold_plane0; } //TLOG () << "Index number " << i << " offline channel " << frame_handler->register_channel_map.channel[i];