Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:17

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 "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   // Take first transform as reference transform
0023   auto refRotation = volumes[0u]->transform(gctx).rotation();
0024   // Loop over rest and recursively test
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<double>
0039 Acts::Experimental::detail::DetectorVolumeConsistency::checkCenterAlignment(
0040     const GeometryContext& gctx,
0041     const std::vector<std::shared_ptr<Experimental::DetectorVolume>>& volumes,
0042     AxisDirection axisValue) {
0043   std::vector<double> distances = {};
0044   // First it needs to surfive the rotation check
0045   checkRotationAlignment(gctx, volumes);
0046 
0047   // Get the reference axis
0048   Vector3 refAxis =
0049       volumes[0u]->transform(gctx).rotation().col(toUnderlying(axisValue));
0050 
0051   for (auto [iv, v] : enumerate(volumes)) {
0052     if (iv > 0) {
0053       Vector3 lastCenter = volumes[iv - 1]->transform(gctx).translation();
0054       Vector3 curCenter = v->transform(gctx).translation();
0055       Vector3 diff(curCenter - lastCenter);
0056       // Check if the difference is aligned with the reference axis
0057       if (!diff.normalized().isApprox(refAxis)) {
0058         std::string message = "ConsitencyChecker: center ";
0059         message += toString(curCenter);
0060         message += " of volume ";
0061         message += std::to_string(iv);
0062         message += " is not aligned with center ";
0063         message += toString(lastCenter);
0064         message += " of previous volume.";
0065         message += " Axis mismatch:  ";
0066         message += toString(refAxis);
0067         message += " vs. ";
0068         message += toString(diff.normalized());
0069         throw std::invalid_argument(message.c_str());
0070       }
0071       // Check if the projection is positive
0072       if (diff.dot(refAxis) < 0.) {
0073         std::string message = "ConsitencyChecker: center of volume ";
0074         message += std::to_string(iv);
0075         message += std::string(" is not ordered with previous volume");
0076         throw std::invalid_argument(message.c_str());
0077       }
0078       distances.push_back(diff.norm());
0079     }
0080   }
0081   return distances;
0082 }