File indexing completed on 2025-08-06 08:10:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Detector/detail/DetectorVolumeConsistency.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/DetectorVolume.hpp"
0013 #include "Acts/Utilities/StringHelpers.hpp"
0014
0015 #include <stdexcept>
0016
0017 void Acts::Experimental::detail::DetectorVolumeConsistency::
0018 checkRotationAlignment(
0019 const GeometryContext& gctx,
0020 const std::vector<std::shared_ptr<Experimental::DetectorVolume>>&
0021 volumes) {
0022
0023 auto refRotation = volumes[0u]->transform(gctx).rotation();
0024
0025 for (auto [iv, v] : Acts::enumerate(volumes)) {
0026 if (iv > 0) {
0027 auto curRotation = v->transform(gctx).rotation();
0028 if (!curRotation.isApprox(refRotation)) {
0029 std::string message = "ConsitencyChecker: rotation of volume ";
0030 message += std::to_string(iv);
0031 message += std::string(" is not aligned with previous volume");
0032 throw std::invalid_argument(message.c_str());
0033 }
0034 }
0035 }
0036 }
0037
0038 std::vector<Acts::ActsScalar>
0039 Acts::Experimental::detail::DetectorVolumeConsistency::checkCenterAlignment(
0040 const GeometryContext& gctx,
0041 const std::vector<std::shared_ptr<Experimental::DetectorVolume>>& volumes,
0042 BinningValue axisValue) {
0043 std::vector<ActsScalar> distances = {};
0044
0045 checkRotationAlignment(gctx, volumes);
0046
0047
0048 Vector3 refAxis = volumes[0u]->transform(gctx).rotation().col(axisValue);
0049
0050 for (auto [iv, v] : enumerate(volumes)) {
0051 if (iv > 0) {
0052 Vector3 lastCenter = volumes[iv - 1]->transform(gctx).translation();
0053 Vector3 curCenter = v->transform(gctx).translation();
0054 Vector3 diff(curCenter - lastCenter);
0055
0056 if (!diff.normalized().isApprox(refAxis)) {
0057 std::string message = "ConsitencyChecker: center ";
0058 message += toString(curCenter);
0059 message += " of volume ";
0060 message += std::to_string(iv);
0061 message += " is not aligned with center ";
0062 message += toString(lastCenter);
0063 message += " of previous volume.";
0064 message += " Axis mismatch: ";
0065 message += toString(refAxis);
0066 message += " vs. ";
0067 message += toString(diff.normalized());
0068 throw std::invalid_argument(message.c_str());
0069 }
0070
0071 if (diff.dot(refAxis) < 0.) {
0072 std::string message = "ConsitencyChecker: center of volume ";
0073 message += std::to_string(iv);
0074 message += std::string(" is not ordered with previous volume");
0075 throw std::invalid_argument(message.c_str());
0076 }
0077 distances.push_back(diff.norm());
0078 }
0079 }
0080 return distances;
0081 }