-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add standalone digitization coordinates converter
- Loading branch information
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...ithms/Digitization/include/ActsExamples/Digitization/DigitizationCoordinatesConverter.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2024 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "ActsExamples/Digitization/DigitizationConfig.hpp" | ||
|
||
namespace ActsExamples { | ||
|
||
/// Utility that converts hit coordinates. | ||
class DigitizationCoordinatesConverter final { | ||
public: | ||
/// Construct the converter | ||
/// | ||
/// @param config is the configuration | ||
DigitizationCoordinatesConverter(DigitizationConfig config); | ||
|
||
/// Get const access to the config | ||
const DigitizationConfig& config() const { return m_cfg; } | ||
|
||
/// Convert the hit coordinates to the local frame. | ||
std::tuple<double, double> globalToLocal(std::uint64_t moduleId, double x, | ||
double y, double z) const; | ||
|
||
/// Convert the hit coordinates to the global frame. | ||
std::tuple<double, double, double> localToGlobal(std::uint64_t moduleId, | ||
double x, double y) const; | ||
|
||
private: | ||
/// Configuration | ||
DigitizationConfig m_cfg; | ||
}; | ||
|
||
} // namespace ActsExamples |
63 changes: 63 additions & 0 deletions
63
Examples/Algorithms/Digitization/src/DigitizationCoordinatesConverter.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2024 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#include "ActsExamples/Digitization/DigitizationCoordinatesConverter.hpp" | ||
|
||
#include "Acts/Definitions/Algebra.hpp" | ||
#include "Acts/Geometry/GeometryContext.hpp" | ||
|
||
#include <cmath> | ||
#include <stdexcept> | ||
#include <utility> | ||
|
||
ActsExamples::DigitizationCoordinatesConverter:: | ||
DigitizationCoordinatesConverter(DigitizationConfig config) | ||
: m_cfg(std::move(config)) { | ||
if (m_cfg.surfaceByIdentifier.empty()) { | ||
throw std::invalid_argument("Missing Surface-GeometryID association map"); | ||
} | ||
} | ||
|
||
std::tuple<double, double> | ||
ActsExamples::DigitizationCoordinatesConverter::globalToLocal( | ||
std::uint64_t moduleId, double x, double y, double z) const { | ||
const Acts::GeometryIdentifier moduleGeoId = moduleId; | ||
auto surfaceItr = m_cfg.surfaceByIdentifier.find(moduleGeoId); | ||
if (surfaceItr == m_cfg.surfaceByIdentifier.end()) { | ||
throw std::runtime_error("Surface not found for moduleGeoId"); | ||
} | ||
|
||
// Transform the position into the local surface frame | ||
const Acts::Surface* surfacePtr = surfaceItr->second; | ||
const auto& invTransform = | ||
surfacePtr->transform(Acts::GeometryContext()).inverse(); | ||
|
||
const Acts::Vector3 pos(x, y, z); | ||
Acts::Vector2 pos2Local = (invTransform * pos).segment<2>(0); | ||
|
||
return {pos2Local.x(), pos2Local.y()}; | ||
} | ||
|
||
std::tuple<double, double, double> | ||
ActsExamples::DigitizationCoordinatesConverter::localToGlobal( | ||
std::uint64_t moduleId, double x, double y) const { | ||
const Acts::GeometryIdentifier moduleGeoId = moduleId; | ||
auto surfaceItr = m_cfg.surfaceByIdentifier.find(moduleGeoId); | ||
if (surfaceItr == m_cfg.surfaceByIdentifier.end()) { | ||
throw std::runtime_error("Surface not found for moduleGeoId"); | ||
} | ||
|
||
// Transform the position into the global frame | ||
const Acts::Surface* surfacePtr = surfaceItr->second; | ||
const auto& transform = surfacePtr->transform(Acts::GeometryContext()); | ||
|
||
const Acts::Vector3 pos(x, y, 0); | ||
Acts::Vector3 pos2Global = (transform * pos); | ||
|
||
return {pos2Global.x(), pos2Global.y(), pos2Global.z()}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters