Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-12 08:02:26

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2024 Souvik Paul, Chun Yuen Tsang, Prithwish Tribedy
0003 // Special Acknowledgement: Kolja Kauder
0004 //
0005 // Convert ADC pulses into ADC and TDC values
0006 
0007 #include <podio/RelationRange.h>
0008 #include <stdlib.h>
0009 #include <algorithm>
0010 #include <cmath>
0011 #include <gsl/pointers>
0012 #include <limits>
0013 #include <vector>
0014 
0015 #include "EICROCDigitization.h"
0016 #include "algorithms/digi/EICROCDigitizationConfig.h"
0017 
0018 namespace eicrecon {
0019 
0020 void EICROCDigitization::process(const EICROCDigitization::Input& input,
0021                                  const EICROCDigitization::Output& output) const {
0022   const auto [simhits] = input;
0023   auto [rawhits]       = output;
0024 
0025   double thres  = m_cfg.t_thres;
0026   int adc_range = m_cfg.adc_range;
0027 
0028   for (const auto& pulse : *simhits) {
0029     int tdc  = std::numeric_limits<int>::max();
0030     int adc  = 0;
0031     double V = 0.0;
0032 
0033     int time_bin          = 0;
0034     double adc_prev       = 0;
0035     auto adcs             = pulse.getAdcCounts();
0036     double n_EICROC_cycle = static_cast<int>(std::floor(pulse.getTime() / m_cfg.tMax + 1e-3));
0037     for (const auto adc : adcs) {
0038       if (adc_prev >= thres && adc <= thres) {
0039         tdc = time_bin + n_EICROC_cycle * m_cfg.tdc_range;
0040       }
0041       if (std::abs(adc) > std::abs(V)) // To get peak of the Analog signal
0042         V = adc;
0043       adc_prev = adc;
0044       ++time_bin;
0045     }
0046 
0047     // limit the range of adc values
0048     adc = std::min(static_cast<double>(adc_range), std::round(-V));
0049     // only store valid hits
0050     if (tdc < std::numeric_limits<int>::max())
0051       rawhits->create(pulse.getCellID(), adc, tdc);
0052     //-----------------------------------------------------------
0053   }
0054 } // EICROCDigitization:process
0055 } // namespace eicrecon