File indexing completed on 2025-01-18 09:11:35
0001
0002
0003
0004
0005
0006
0007
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 DigitizationAlgorithm::Config config)
0022 : m_cfg(std::move(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
0037 const Acts::Surface* surfacePtr = surfaceItr->second;
0038 const auto& invTransform =
0039 surfacePtr->transform(Acts::GeometryContext()).inverse();
0040
0041 const Acts::Vector3 pos(x, y, z);
0042 Acts::Vector2 pos2Local = (invTransform * pos).segment<2>(0);
0043
0044 return {pos2Local.x(), pos2Local.y()};
0045 }
0046
0047 std::tuple<double, double, double>
0048 DigitizationCoordinatesConverter::localToGlobal(std::uint64_t moduleId,
0049 double x, double y) const {
0050 const Acts::GeometryIdentifier moduleGeoId = moduleId;
0051 auto surfaceItr = m_cfg.surfaceByIdentifier.find(moduleGeoId);
0052 if (surfaceItr == m_cfg.surfaceByIdentifier.end()) {
0053 throw std::runtime_error("Surface not found for moduleGeoId");
0054 }
0055
0056
0057 const Acts::Surface* surfacePtr = surfaceItr->second;
0058 const auto& transform = surfacePtr->transform(Acts::GeometryContext());
0059
0060 const Acts::Vector3 pos(x, y, 0);
0061 Acts::Vector3 pos2Global = (transform * pos);
0062
0063 return {pos2Global.x(), pos2Global.y(), pos2Global.z()};
0064 }
0065
0066 }