Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:17:50

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 - 2025 Whitney Armstrong, Sylvester Joosten, Wouter Deconinck, Dmitry Romanov
0003 
0004 #include "TrackerHitReconstruction.h"
0005 
0006 #include <Evaluator/DD4hepUnits.h>
0007 #include <Math/GenVector/Cartesian3D.h>
0008 #include <Math/GenVector/DisplacementVector3D.h>
0009 #include <algorithms/logger.h>
0010 #include <edm4eic/CovDiag3f.h>
0011 #include <edm4hep/Vector3f.h>
0012 #include <fmt/core.h>
0013 #include <cstddef>
0014 #include <iterator>
0015 #include <vector>
0016 
0017 namespace eicrecon {
0018 
0019 namespace {
0020   inline double get_resolution(const double pixel_size) {
0021     constexpr const double sqrt_12 = 3.4641016151;
0022     return pixel_size / sqrt_12;
0023   }
0024   inline double get_variance(const double pixel_size) {
0025     const double res = get_resolution(pixel_size);
0026     return res * res;
0027   }
0028 } // namespace
0029 
0030 void TrackerHitReconstruction::process(const Input& input, const Output& output) const {
0031   using dd4hep::mm;
0032 
0033   const auto [raw_hits] = input;
0034   auto [rec_hits]       = output;
0035 
0036   for (const auto& raw_hit : *raw_hits) {
0037 
0038     auto id = raw_hit.getCellID();
0039 
0040     // Get position and dimension
0041     auto pos = m_converter->position(id);
0042     auto dim = m_converter->cellDimensions(id);
0043 
0044     // >oO trace
0045     if (level() == algorithms::LogLevel::kTrace) {
0046       trace("position x={:.2f} y={:.2f} z={:.2f} [mm]: ", pos.x() / mm, pos.y() / mm, pos.z() / mm);
0047       trace("dimension size: {}", dim.size());
0048       for (std::size_t j = 0; j < std::size(dim); ++j) {
0049         trace(" - dimension {:<5} size: {:.2}", j, dim[j]);
0050       }
0051     }
0052 
0053     // Note about variance:
0054     //    The variance is used to obtain a diagonal covariance matrix.
0055     //    Note that the covariance matrix is written in DD4hep surface coordinates,
0056     //    *NOT* global position coordinates. This implies that:
0057     //      - XY segmentation: xx -> sigma_x, yy-> sigma_y, zz -> 0, tt -> 0
0058     //      - XZ segmentation: xx -> sigma_x, yy-> sigma_z, zz -> 0, tt -> 0
0059     //      - XYZ segmentation: xx -> sigma_x, yy-> sigma_y, zz -> sigma_z, tt -> 0
0060     //    This is properly in line with how we get the local coordinates for the hit
0061     //    in the TrackerSourceLinker.
0062     auto rec_hit = rec_hits->create(
0063         raw_hit.getCellID(), // Raw DD4hep cell ID
0064         edm4hep::Vector3f{static_cast<float>(pos.x() / mm), static_cast<float>(pos.y() / mm),
0065                           static_cast<float>(pos.z() / mm)}, // mm
0066         edm4eic::CovDiag3f{get_variance(dim[0] / mm),
0067                            get_variance(dim[1] / mm), // variance (see note above)
0068                            std::size(dim) > 2 ? get_variance(dim[2] / mm) : 0.},
0069         static_cast<float>((double)(raw_hit.getTimeStamp()) / 1000.0), // ns
0070         m_cfg.timeResolution,                                          // in ns
0071         static_cast<float>(raw_hit.getCharge() / 1.0e6),               // Collected energy (GeV)
0072         0.0F);                                                         // Error on the energy
0073     rec_hit.setRawHit(raw_hit);
0074   }
0075 }
0076 
0077 } // namespace eicrecon