LCOV - code coverage report
Current view: top level - triggeralgs/src - TCMakerHorizontalMuonAlgorithm.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 1.1 % 88 1
Test Date: 2025-12-21 13:07:08 Functions: 6.7 % 15 1

            Line data    Source code
       1              : /**
       2              :  * @file TCMakerHorizontalMuonAlgorithm.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/HorizontalMuon/TCMakerHorizontalMuonAlgorithm.hpp"
      10              : 
      11              : #include "TRACE/trace.h"
      12              : #define TRACE_NAME "TCMakerHorizontalMuonAlgorithm"
      13              : 
      14              : #include <math.h>
      15              : #include <vector>
      16              : 
      17              : using namespace triggeralgs;
      18              : 
      19              : using Logging::TLVL_DEBUG_ALL;
      20              : using Logging::TLVL_DEBUG_HIGH;
      21              : using Logging::TLVL_DEBUG_MEDIUM;
      22              : 
      23              : void
      24            0 : TCMakerHorizontalMuonAlgorithm::process(const TriggerActivity& activity,
      25              :                                                 std::vector<TriggerCandidate>& output_tc)
      26              : {
      27              : 
      28            0 :   std::vector<TriggerActivity::TriggerActivityData> ta_list = { static_cast<TriggerActivity::TriggerActivityData>(
      29            0 :     activity) };
      30              : 
      31              :   // The first time operator is called, reset window object.
      32            0 :   if (m_current_window.is_empty()) {
      33            0 :     m_current_window.reset(activity);
      34            0 :     m_activity_count++;
      35              : 
      36              :     // TriggerCandidate tc = construct_tc();
      37              :     // output_tc.push_back(tc);
      38              : 
      39              :     // m_current_window.clear();
      40              :     // return;
      41              :   }
      42              : 
      43              :   // If the difference between the current TA's start time and the start of the window
      44              :   // is less than the specified window size, add the TA to the window.
      45            0 :   else if ((activity.time_start - m_current_window.time_start) < m_window_length) {
      46            0 :     TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TCM:HM] Window not yet complete, adding the activity to the window.";
      47            0 :     m_current_window.add(activity);
      48              :   }
      49              :   // If it is not, move the window along.
      50              :   else {
      51            0 :     TLOG_DEBUG(TLVL_DEBUG_ALL)
      52            0 :       << "[TCM:HM] TAWindow is at required length but specified threshold not met, shifting window along.";
      53            0 :     m_current_window.move(activity, m_window_length);
      54              :   }
      55              : 
      56              :   // If the addition of the current TA to the window would make it longer
      57              :   // than the specified window length, don't add it but check whether the sum of all adc in
      58              :   // the existing window is above the specified threshold. If it is, and we are triggering on ADC,
      59              :   // make a TA and start a fresh window with the current TP.
      60            0 :   if (m_current_window.adc_integral > m_adc_threshold && m_trigger_on_adc) {
      61              :     // TLOG_DEBUG(TRACE_NAME) << "ADC integral in window is greater than specified threshold.";
      62            0 :     TLOG_DEBUG(TLVL_DEBUG_MEDIUM) << "[TCM:HM] m_current_window.adc_integral " << m_current_window.adc_integral
      63            0 :                                   << " - m_adc_threshold " << m_adc_threshold;
      64            0 :     tc_number++;
      65            0 :     TriggerCandidate tc = construct_tc();
      66            0 :     TLOG_DEBUG(TLVL_DEBUG_MEDIUM) << "[TCM:HM] tc.time_start=" << tc.time_start << " tc.time_end=" << tc.time_end
      67            0 :                                   << " len(tc.inputs) " << tc.inputs.size();
      68              : 
      69            0 :     for (const auto& ta : tc.inputs) {
      70            0 :       TLOG_DEBUG(TLVL_DEBUG_ALL) << "[TCM:HM] [TA] ta.time_start=" << ta.time_start << " ta.time_end=" << ta.time_end
      71            0 :                                  << " ta.adc_integral=" << ta.adc_integral;
      72              :     }
      73              : 
      74            0 :     output_tc.push_back(tc);
      75              :     // m_current_window.reset(activity);
      76            0 :     m_current_window.clear();
      77            0 :   }
      78              : 
      79              :   // If the addition of the current TA to the window would make it longer
      80              :   // than the specified window length, don't add it but check whether the number of hit channels in
      81              :   // the existing window is above the specified threshold. If it is, and we are triggering on channels,
      82              :   // make a TC and start a fresh window with the current TA.
      83            0 :   else if (m_current_window.n_channels_hit() > m_n_channels_threshold && m_trigger_on_n_channels) {
      84            0 :     tc_number++;
      85            0 :     output_tc.push_back(construct_tc());
      86              : 
      87              :     // m_current_window.reset(activity);
      88            0 :     m_current_window.clear();
      89              :   }
      90              : 
      91              :   // // If it is not, move the window along.
      92              :   // else {
      93              :   //   // TLOG_DEBUG(TRACE_NAME) << "TAWindow is at required length but specified threshold not met."
      94              :   //   //                        << "shifting window along.";
      95              :   //   m_current_window.move(activity, m_window_length);
      96              :   // }
      97              : 
      98            0 :   m_activity_count++;
      99            0 :   return;
     100            0 : }
     101              : 
     102              : void
     103            0 : TCMakerHorizontalMuonAlgorithm::configure(const nlohmann::json& config)
     104              : {
     105            0 :   TriggerCandidateMaker::configure(config);
     106              : 
     107            0 :   if (config.is_object()) {
     108            0 :     if (config.contains("trigger_on_adc"))
     109            0 :       m_trigger_on_adc = config["trigger_on_adc"];
     110            0 :     if (config.contains("trigger_on_n_channels"))
     111            0 :       m_trigger_on_n_channels = config["trigger_on_n_channels"];
     112            0 :     if (config.contains("adc_threshold"))
     113            0 :       m_adc_threshold = config["adc_threshold"];
     114            0 :     if (config.contains("n_channels_threshold"))
     115            0 :       m_n_channels_threshold = config["n_channels_threshold"];
     116            0 :     if (config.contains("window_length"))
     117            0 :       m_window_length = config["window_length"];
     118              :   }
     119            0 :   if (m_trigger_on_adc && m_trigger_on_n_channels) {
     120            0 :     TLOG_DEBUG(TLVL_VERY_IMPORTANT) << "[TCM:HM] Triggering on ADC count and number of channels is not supported.";
     121            0 :     throw BadConfiguration(ERS_HERE, TRACE_NAME);
     122              :   }
     123            0 :   if (!m_trigger_on_adc && !m_trigger_on_n_channels) {
     124            0 :     TLOG_DEBUG(TLVL_VERY_IMPORTANT) << "[TCM:HM] Not triggering! All trigger flags are false!";
     125            0 :     throw BadConfiguration(ERS_HERE, TRACE_NAME);
     126              :   }
     127              : 
     128            0 :   return;
     129              : }
     130              : 
     131              : TriggerCandidate
     132            0 : TCMakerHorizontalMuonAlgorithm::construct_tc() const
     133              : {
     134            0 :   TriggerActivity latest_ta_in_window = m_current_window.inputs.back();
     135              : 
     136            0 :   TriggerCandidate tc;
     137            0 :   tc.time_start = m_current_window.time_start;
     138            0 :   tc.time_end = latest_ta_in_window.inputs.back().time_start;
     139            0 :   tc.time_candidate = m_current_window.time_start;
     140            0 :   tc.detid = latest_ta_in_window.detid;
     141            0 :   tc.type = m_tc_type_out;
     142            0 :   tc.algorithm = TriggerCandidate::Algorithm::kHorizontalMuon;
     143              : 
     144              :   // Take the list of triggeralgs::TriggerActivity in the current
     145              :   // window and convert them (implicitly) to detdataformats'
     146              :   // TriggerActivityData, which is the base class of TriggerActivity
     147            0 :   for (auto& ta : m_current_window.inputs) {
     148            0 :     tc.inputs.push_back(ta);
     149            0 :     if (ta.time_end > tc.time_end) {
     150            0 :       tc.time_end = ta.time_end;
     151              :     }
     152              :   }
     153              : 
     154            0 :   return tc;
     155            0 : }
     156              : 
     157              : bool
     158            0 : TCMakerHorizontalMuonAlgorithm::check_adjacency() const
     159              : {
     160              :   // FIX ME: An adjacency check on the channels which have hits.
     161            0 :   return true;
     162              : }
     163              : 
     164              : // Functions below this line are for debugging purposes.
     165              : void
     166            0 : TCMakerHorizontalMuonAlgorithm::add_window_to_record(TAWindow window)
     167              : {
     168            0 :   m_window_record.push_back(window);
     169            0 :   return;
     170              : }
     171              : 
     172              : void
     173            0 : TCMakerHorizontalMuonAlgorithm::dump_window_record()
     174              : {
     175              :   // FIX ME: Need to index this outfile in the name by detid or something similar.
     176            0 :   std::ofstream outfile;
     177            0 :   outfile.open("window_record_tcm.csv", std::ios_base::app);
     178              : 
     179            0 :   for (auto window : m_window_record) {
     180            0 :     outfile << window.time_start << ",";
     181            0 :     outfile << window.inputs.back().time_start << ",";
     182            0 :     outfile << window.inputs.back().time_start - window.time_start << ",";
     183            0 :     outfile << window.adc_integral << ",";
     184            0 :     outfile << window.n_channels_hit() << ",";
     185            0 :     outfile << window.inputs.size() << std::endl;
     186            0 :   }
     187              : 
     188            0 :   outfile.close();
     189              : 
     190            0 :   m_window_record.clear();
     191              : 
     192            0 :   return;
     193            0 : }
     194              : 
     195              : /*
     196              : void
     197              : TCMakerHorizontalMuonAlgorithm::flush(timestamp_t, std::vector<TriggerCandidate>& output_tc)
     198              : {
     199              :   // Check the status of the current window, construct TC if conditions are met. Regardless
     200              :   // of whether the conditions are met, reset the window.
     201              :   if(m_current_window.adc_integral > m_adc_threshold && m_trigger_on_adc){
     202              :   //else if(m_current_window.adc_integral > m_conf.adc_threshold && m_conf.trigger_on_adc){
     203              :     //TLOG_DEBUG(TRACE_NAME) << "ADC integral in window is greater than specified threshold.";
     204              :     output_tc.push_back(construct_tc());
     205              :   }
     206              :   else if(m_current_window.n_channels_hit() > m_n_channels_threshold && m_trigger_on_n_channels){
     207              :   //else if(m_current_window.n_channels_hit() > m_conf.n_channels_threshold && m_conf.trigger_on_n_channels){
     208              :     //TLOG_DEBUG(TRACE_NAME) << "Number of channels hit in the window is greater than specified threshold.";
     209              :     output_tc.push_back(construct_tc());
     210              :   }
     211              : 
     212              :   //TLOG_DEBUG(TRACE_NAME) << "Clearing the current window, on the arrival of the next input_tp, the window will be
     213              : reset."; m_current_window.clear();
     214              : 
     215              :   return;
     216              : }*/
     217              : 
     218           12 : REGISTER_TRIGGER_CANDIDATE_MAKER(TRACE_NAME, TCMakerHorizontalMuonAlgorithm)
        

Generated by: LCOV version 2.0-1