Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-06-30 07:55:44

0001 // SPDX-License-Identifier: LGPL-3.0-or-later
0002 // Copyright (C) 2022 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 <edm4eic/CovDiag3f.h>
0010 #include <edm4eic/EDM4eicVersion.h>
0011 #include <edm4hep/Vector3f.h>
0012 #include <fmt/core.h>
0013 #include <spdlog/common.h>
0014 #include <cstddef>
0015 #include <iterator>
0016 #include <vector>
0017 
0018 namespace eicrecon {
0019 
0020 namespace {
0021   inline double get_resolution(const double pixel_size) {
0022     constexpr const double sqrt_12 = 3.4641016151;
0023     return pixel_size / sqrt_12;
0024   }
0025   inline double get_variance(const double pixel_size) {
0026     const double res = get_resolution(pixel_size);
0027     return res * res;
0028   }
0029 } // namespace
0030 
0031 void TrackerHitReconstruction::init(const dd4hep::rec::CellIDPositionConverter* converter,
0032                                     std::shared_ptr<spdlog::logger>& logger) {
0033 
0034   m_log = logger;
0035 
0036   m_converter = converter;
0037 }
0038 
0039 std::unique_ptr<edm4eic::TrackerHitCollection>
0040 TrackerHitReconstruction::process(const edm4eic::RawTrackerHitCollection& raw_hits) {
0041   using dd4hep::mm;
0042 
0043   auto rec_hits{std::make_unique<edm4eic::TrackerHitCollection>()};
0044 
0045   for (const auto& raw_hit : raw_hits) {
0046 
0047     auto id = raw_hit.getCellID();
0048 
0049     // Get position and dimension
0050     auto pos = m_converter->position(id);
0051     auto dim = m_converter->cellDimensions(id);
0052 
0053     // >oO trace
0054     if (m_log->level() == spdlog::level::trace) {
0055       m_log->trace("position x={:.2f} y={:.2f} z={:.2f} [mm]: ", pos.x() / mm, pos.y() / mm,
0056                    pos.z() / mm);
0057       m_log->trace("dimension size: {}", dim.size());
0058       for (std::size_t j = 0; j < std::size(dim); ++j) {
0059         m_log->trace(" - dimension {:<5} size: {:.2}", j, dim[j]);
0060       }
0061     }
0062 
0063     // Note about variance:
0064     //    The variance is used to obtain a diagonal covariance matrix.
0065     //    Note that the covariance matrix is written in DD4hep surface coordinates,
0066     //    *NOT* global position coordinates. This implies that:
0067     //      - XY segmentation: xx -> sigma_x, yy-> sigma_y, zz -> 0, tt -> 0
0068     //      - XZ segmentation: xx -> sigma_x, yy-> sigma_z, zz -> 0, tt -> 0
0069     //      - XYZ segmentation: xx -> sigma_x, yy-> sigma_y, zz -> sigma_z, tt -> 0
0070     //    This is properly in line with how we get the local coordinates for the hit
0071     //    in the TrackerSourceLinker.
0072 #if EDM4EIC_VERSION_MAJOR >= 7
0073     auto rec_hit =
0074 #endif
0075         rec_hits->create(raw_hit.getCellID(), // Raw DD4hep cell ID
0076                          edm4hep::Vector3f{static_cast<float>(pos.x() / mm),
0077                                            static_cast<float>(pos.y() / mm),
0078                                            static_cast<float>(pos.z() / mm)}, // mm
0079                          edm4eic::CovDiag3f{get_variance(dim[0] / mm),
0080                                             get_variance(dim[1] / mm), // variance (see note above)
0081                                             std::size(dim) > 2 ? get_variance(dim[2] / mm) : 0.},
0082                          static_cast<float>((double)(raw_hit.getTimeStamp()) / 1000.0), // ns
0083                          m_cfg.timeResolution,                                          // in ns
0084                          static_cast<float>(raw_hit.getCharge() / 1.0e6), // Collected energy (GeV)
0085                          0.0F);                                           // Error on the energy
0086 #if EDM4EIC_VERSION_MAJOR >= 7
0087     rec_hit.setRawHit(raw_hit);
0088 #endif
0089   }
0090 
0091   return rec_hits;
0092 }
0093 
0094 } // namespace eicrecon