Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:55:35

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 <algorithm>
0008 #include <cmath>
0009 #include <cstdlib>
0010 #include <gsl/pointers>
0011 #include <limits>
0012 #include <podio/RelationRange.h>
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 V   = 0;
0031 
0032     int time_bin          = 0;
0033     double adc_prev       = 0;
0034     auto adcs             = pulse.getAdcCounts();
0035     double n_EICROC_cycle = static_cast<int>(std::floor(pulse.getTime() / m_cfg.tMax + 1e-3));
0036     for (const auto adc : adcs) {
0037       if (adc_prev >= thres && adc <= thres) {
0038         tdc = time_bin + n_EICROC_cycle * m_cfg.tdc_range;
0039       }
0040       if (std::abs(adc) > std::abs(V)) { // To get peak of the Analog signal
0041         V = adc;
0042       }
0043       adc_prev = adc;
0044       ++time_bin;
0045     }
0046 
0047     // limit the range of adc values
0048     int adc = std::min(adc_range, -V);
0049     // only store valid hits
0050     if (tdc < std::numeric_limits<int>::max()) {
0051       rawhits->create(pulse.getCellID(), adc, tdc);
0052     }
0053     //-----------------------------------------------------------
0054   }
0055 } // EICROCDigitization:process
0056 } // namespace eicrecon