Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-30 07:46:06

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Digitization/DigitizationCoordinatesConverter.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "ActsExamples/Digitization/DigitizationAlgorithm.hpp"
0014 
0015 #include <stdexcept>
0016 #include <utility>
0017 
0018 namespace ActsExamples {
0019 
0020 DigitizationCoordinatesConverter::DigitizationCoordinatesConverter(
0021     const DigitizationAlgorithm::Config& config)
0022     : m_cfg(config) {
0023   if (m_cfg.surfaceByIdentifier.empty()) {
0024     throw std::invalid_argument("Missing Surface-GeometryID association map");
0025   }
0026 }
0027 
0028 std::tuple<double, double> DigitizationCoordinatesConverter::globalToLocal(
0029     std::uint64_t moduleId, double x, double y, double z) const {
0030   const Acts::GeometryIdentifier moduleGeoId(moduleId);
0031   auto surfaceItr = m_cfg.surfaceByIdentifier.find(moduleGeoId);
0032   if (surfaceItr == m_cfg.surfaceByIdentifier.end()) {
0033     throw std::runtime_error("Surface not found for moduleGeoId");
0034   }
0035 
0036   const Acts::GeometryContext gctx =
0037       Acts::GeometryContext::dangerouslyDefaultConstruct();
0038 
0039   // Transform the position into the local surface frame
0040   const Acts::Surface* surfacePtr = surfaceItr->second;
0041   const auto invTransform = surfacePtr->localToGlobalTransform(gctx).inverse();
0042 
0043   const Acts::Vector3 pos(x, y, z);
0044   Acts::Vector2 pos2Local = (invTransform * pos).segment<2>(0);
0045 
0046   return {pos2Local.x(), pos2Local.y()};
0047 }
0048 
0049 std::tuple<double, double, double>
0050 DigitizationCoordinatesConverter::localToGlobal(std::uint64_t moduleId,
0051                                                 double x, double y) const {
0052   const Acts::GeometryIdentifier moduleGeoId{moduleId};
0053   auto surfaceItr = m_cfg.surfaceByIdentifier.find(moduleGeoId);
0054   if (surfaceItr == m_cfg.surfaceByIdentifier.end()) {
0055     throw std::runtime_error("Surface not found for moduleGeoId");
0056   }
0057 
0058   const Acts::GeometryContext gctx =
0059       Acts::GeometryContext::dangerouslyDefaultConstruct();
0060 
0061   // Transform the position into the global frame
0062   const Acts::Surface* surfacePtr = surfaceItr->second;
0063   const auto& transform = surfacePtr->localToGlobalTransform(gctx);
0064 
0065   const Acts::Vector3 pos(x, y, 0);
0066   Acts::Vector3 pos2Global = (transform * pos);
0067 
0068   return {pos2Global.x(), pos2Global.y(), pos2Global.z()};
0069 }
0070 
0071 }  // namespace ActsExamples