LCOV - code coverage report
Current view: top level - triggeralgs/src - TAMakerADCSimpleWindowAlgorithm.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 2.1 % 47 1
Test Date: 2025-12-21 13:07:08 Functions: 7.7 % 13 1

            Line data    Source code
       1              : /**
       2              :  * @file TAMakerADCSimpleWindowAlgorithm.cpp
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2021.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "triggeralgs/ADCSimpleWindow/TAMakerADCSimpleWindowAlgorithm.hpp"
      10              : 
      11              : #include "TRACE/trace.h"
      12              : #define TRACE_NAME "TAMakerADCSimpleWindowAlgorithm"
      13              : 
      14              : #include <vector>
      15              : 
      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            0 : TAMakerADCSimpleWindowAlgorithm::process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_ta)
      25              : {
      26              :   
      27              :   // The first time operator is called, reset
      28              :   // window object.
      29            0 :   if(m_current_window.is_empty()){
      30            0 :     m_current_window.reset(input_tp);
      31            0 :     m_primitive_count++;
      32            0 :     return;
      33              :   } 
      34              : 
      35              :   // If the difference between the current TP's start time and the start of the window
      36              :   // is less than the specified window size, add the TP to the window.
      37            0 :   if((input_tp.time_start - m_current_window.time_start) < m_window_length){
      38            0 :     TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TAM:ADCSW] Window not yet complete, adding the input_tp to the window.";
      39            0 :     m_current_window.add(input_tp);
      40              :   }
      41              :   // If the addition of the current TP to the window would make it longer
      42              :   // than the specified window length, don't add it but check whether the sum of all adc in
      43              :   // the existing window is above the specified threshold. If it is, make a TA and start 
      44              :   // a fresh window with the current TP.
      45            0 :   else if(m_current_window.adc_integral > m_adc_threshold){
      46            0 :     TLOG_DEBUG(TLVL_DEBUG_LOW) << "[TAM:ADCSW] ADC integral in window is greater than specified threshold.";
      47            0 :     output_ta.push_back(construct_ta());
      48            0 :     TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TAM:ADCSW] Resetting window with input_tp.";
      49            0 :     m_current_window.reset(input_tp);
      50              :   }
      51              :   // If it is not, move the window along.
      52              :   else{
      53            0 :     TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TAM:ADCSW] Window is at required length but adc threshold not met, shifting window along.";
      54            0 :     m_current_window.move(input_tp, m_window_length);
      55              :   }
      56              :   
      57            0 :   TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TAM:ADCSW] " << m_current_window;
      58              : 
      59            0 :   m_primitive_count++;
      60              : 
      61            0 :   return;
      62              : }
      63              : 
      64              : void
      65            0 : TAMakerADCSimpleWindowAlgorithm::configure(const nlohmann::json& config)
      66              : {
      67            0 :   TriggerActivityMaker::configure(config);
      68              : 
      69              :   //FIXME use some schema here
      70            0 :   if (config.is_object()){
      71            0 :     if (config.contains("window_length")) m_window_length = config["window_length"];
      72            0 :     if (config.contains("adc_threshold")) m_adc_threshold = config["adc_threshold"];
      73              :   }
      74              :   else{
      75            0 :     TLOG_DEBUG(TLVL_IMPORTANT) << "[TAM:ADCSW] The DEFAULT values of window_length and adc_threshold are being used.";
      76              :   }
      77            0 :   TLOG_DEBUG(TLVL_IMPORTANT) << "[TAM:ADCSW] If the total ADC of trigger primitives with times within a "
      78            0 :                          << m_window_length << " tick time window is above " << m_adc_threshold << " counts, a trigger will be issued.";
      79            0 : }
      80              : 
      81              : TriggerActivity
      82            0 : TAMakerADCSimpleWindowAlgorithm::construct_ta() const
      83              : {
      84            0 :   TLOG_DEBUG(TLVL_DEBUG_LOW) << "[TAM:ADCSW] I am constructing a trigger activity!";
      85              :   //TLOG_DEBUG(TRACE_NAME) << m_current_window;
      86              : 
      87            0 :   TriggerPrimitive latest_tp_in_window = m_current_window.tp_list.back();
      88              :   // The time_peak, time_activity, channel_* and adc_peak fields of this TA are irrelevent
      89              :   // for the purpose of this trigger alg.
      90            0 :   TriggerActivity ta;
      91            0 :   ta.time_start = m_current_window.time_start;
      92            0 :   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.
      93            0 :   ta.time_peak = latest_tp_in_window.samples_to_peak * 32 + latest_tp_in_window.time_start;  // FIXME: Replace STP to `time_peak` conversion.
      94            0 :   ta.time_activity = ta.time_peak;
      95            0 :   ta.channel_start = latest_tp_in_window.channel;
      96            0 :   ta.channel_end = latest_tp_in_window.channel;
      97            0 :   ta.channel_peak = latest_tp_in_window.channel;
      98            0 :   ta.adc_integral = m_current_window.adc_integral;
      99            0 :   ta.adc_peak = latest_tp_in_window.adc_peak;
     100            0 :   ta.detid = latest_tp_in_window.detid;
     101            0 :   ta.type = TriggerActivity::Type::kTPC;
     102            0 :   ta.algorithm = TriggerActivity::Algorithm::kADCSimpleWindow;
     103            0 :   ta.inputs = m_current_window.tp_list;
     104            0 :   return ta;
     105            0 : }
     106              : 
     107              : // Register algo in TA Factory
     108           12 : REGISTER_TRIGGER_ACTIVITY_MAKER(TRACE_NAME, TAMakerADCSimpleWindowAlgorithm)
        

Generated by: LCOV version 2.0-1