Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:23:37

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2025 Chun Yuen Tsang
0003 
0004 #include "LGADHitCalibration.h"
0005 
0006 #include <Evaluator/DD4hepUnits.h>
0007 #include <Math/GenVector/Cartesian3D.h>
0008 #include <Math/GenVector/DisplacementVector3D.h>
0009 #include <algorithms/geo.h>
0010 #include <edm4eic/CovDiag3f.h>
0011 #include <edm4hep/Vector3f.h>
0012 #include <algorithm>
0013 #include <cmath>
0014 #include <gsl/pointers>
0015 #include <vector>
0016 
0017 #include "algorithms/reco/LGADHitCalibrationConfig.h"
0018 
0019 namespace eicrecon {
0020 
0021 void LGADHitCalibration::init() {
0022   m_converter = algorithms::GeoSvc::instance().cellIDPositionConverter();
0023 }
0024 
0025 void LGADHitCalibration::process(const LGADHitCalibration::Input& input,
0026                                  const LGADHitCalibration::Output& output) const {
0027   using dd4hep::mm;
0028 
0029   const auto [TDCADC_hits] = input;
0030   auto [calibrated_hits]   = output;
0031 
0032   for (const auto& TDCADC_hit : *TDCADC_hits) {
0033 
0034     auto id = TDCADC_hit.getCellID();
0035 
0036     // Get position and dimension
0037     auto pos   = m_converter->position(id);
0038     double ADC = TDCADC_hit.getCharge();
0039     double TDC = TDCADC_hit.getTimeStamp();
0040 
0041     // adc to charge
0042     double charge = ADC * m_cfg.c_slope + m_cfg.c_intercept;
0043     // TDC to time
0044     float time = TDC * m_cfg.t_slope + m_cfg.t_intercept;
0045 
0046     auto cellSize = m_converter->cellDimensions(id);
0047     // sqrt(12) factor convertes ranges of uniform distribution to it's standard deviation
0048     double varX = cellSize[0] / mm / std::sqrt(12.);
0049     varX *= varX; // square of cell size
0050     double varY = cellSize[1] / mm / std::sqrt(12.);
0051     varY *= varY;
0052     double varZ = cellSize.size() > 2 ? cellSize[2] / mm / std::sqrt(12.) : 0;
0053     varZ *= varZ;
0054 
0055     auto hit = calibrated_hits->create(
0056         id,
0057         edm4hep::Vector3f{static_cast<float>(pos.x()), static_cast<float>(pos.y()),
0058                           static_cast<float>(pos.z())},
0059         edm4eic::CovDiag3f{varX, varY, varZ}, // should be the covariance of position
0060         time,                                 // ns
0061         m_cfg.t_slope / std::sqrt(12.),       // covariance of time
0062         std::max(0., charge),                 // total ADC sum
0063         m_cfg.c_slope / std::sqrt(12.));      // Error on the energy
0064     hit.setRawHit(TDCADC_hit);
0065   }
0066 }
0067 
0068 } // namespace eicrecon