Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:11:39

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 #pragma once
0010 
0011 #include "Acts/Geometry/Layer.hpp"
0012 #include "Acts/Geometry/TrackingVolume.hpp"
0013 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0014 #include "Acts/Surfaces/Surface.hpp"
0015 #include "Acts/Surfaces/SurfaceArray.hpp"
0016 #include "Acts/Utilities/Intersection.hpp"
0017 
0018 #include <variant>
0019 
0020 namespace Acts::detail {
0021 
0022 using AnyIntersectionObject =
0023     std::variant<const Surface*, const Layer*, const BoundarySurface*>;
0024 
0025 /// @brief A candidate object for navigation
0026 struct NavigationObjectCandidate {
0027   AnyIntersectionObject object;
0028   const Surface* representation = nullptr;
0029   BoundaryTolerance boundaryTolerance;
0030 
0031   NavigationObjectCandidate(AnyIntersectionObject _object,
0032                             const Surface* _representation,
0033                             BoundaryTolerance _boundaryTolerance)
0034       : object(_object),
0035         representation(_representation),
0036         boundaryTolerance(_boundaryTolerance) {}
0037 
0038   std::pair<SurfaceMultiIntersection, AnyIntersectionObject> intersect(
0039       const GeometryContext& gctx, const Vector3& position,
0040       const Vector3& direction, double tolerance) const {
0041     auto intersection = representation->intersect(gctx, position, direction,
0042                                                   boundaryTolerance, tolerance);
0043 
0044     if (std::holds_alternative<const Surface*>(object)) {
0045       const auto& surface = std::get<const Surface*>(object);
0046       return {intersection, surface};
0047     }
0048     if (std::holds_alternative<const Layer*>(object)) {
0049       const auto& layer = std::get<const Layer*>(object);
0050       return {intersection, layer};
0051     }
0052     if (std::holds_alternative<const BoundarySurface*>(object)) {
0053       const auto& boundary = std::get<const BoundarySurface*>(object);
0054       return {intersection, boundary};
0055     }
0056     throw std::runtime_error("unknown type");
0057   }
0058 };
0059 
0060 /// Composes an intersection and a bounds check into a navigation candidate.
0061 /// This is used to consistently update intersections after creation.
0062 struct IntersectedNavigationObject {
0063   SurfaceIntersection intersection;
0064   AnyIntersectionObject anyObject;
0065   BoundaryTolerance boundaryTolerance;
0066 
0067   IntersectedNavigationObject(SurfaceIntersection _intersection,
0068                               AnyIntersectionObject _anyObject,
0069                               BoundaryTolerance _boundaryTolerance)
0070       : intersection(_intersection),
0071         anyObject(_anyObject),
0072         boundaryTolerance(_boundaryTolerance) {}
0073 
0074   template <typename object_t>
0075   bool checkType() const {
0076     return std::holds_alternative<const object_t*>(anyObject);
0077   }
0078 
0079   template <typename object_t>
0080   const object_t* object() const {
0081     return std::get<const object_t*>(anyObject);
0082   }
0083 
0084   static bool forwardOrder(const IntersectedNavigationObject& aCandidate,
0085                            const IntersectedNavigationObject& bCandidate) {
0086     return Intersection3D::pathLengthOrder(
0087         aCandidate.intersection.intersection(),
0088         bCandidate.intersection.intersection());
0089   }
0090 };
0091 
0092 /// @brief Emplace all navigation candidates for a given volume
0093 inline void emplaceAllVolumeCandidates(
0094     std::vector<NavigationObjectCandidate>& candidates,
0095     const TrackingVolume& volume, bool resolveSensitive, bool resolveMaterial,
0096     bool resolvePassive,
0097     const BoundaryTolerance& boundaryToleranceSurfaceApproach,
0098     const Logger& logger) {
0099   auto addCandidate = [&](AnyIntersectionObject object,
0100                           const Surface* representation,
0101                           const BoundaryTolerance& boundaryTolerance) {
0102     candidates.emplace_back(object, representation, boundaryTolerance);
0103   };
0104 
0105   // Get all boundary candidates
0106   {
0107     ACTS_VERBOSE("Searching for boundaries.");
0108 
0109     const auto& boundaries = volume.boundarySurfaces();
0110 
0111     ACTS_VERBOSE("Found " << boundaries.size() << " boundaries.");
0112 
0113     for (const auto& boundary : boundaries) {
0114       addCandidate(boundary.get(), &boundary->surfaceRepresentation(),
0115                    BoundaryTolerance::None());
0116     }
0117   }
0118 
0119   // Get all layer candidates
0120   {
0121     ACTS_VERBOSE("Searching for layers.");
0122 
0123     const auto& layers = volume.confinedLayers()->arrayObjects();
0124 
0125     ACTS_VERBOSE("Found " << layers.size() << " layers.");
0126 
0127     for (const auto& layer : layers) {
0128       if (!layer->resolve(resolveSensitive, resolveMaterial, resolvePassive)) {
0129         continue;
0130       }
0131 
0132       if (!resolveSensitive ||
0133           layer->surfaceRepresentation().surfaceMaterial() != nullptr) {
0134         addCandidate(layer.get(), &layer->surfaceRepresentation(),
0135                      BoundaryTolerance::None());
0136       }
0137 
0138       if (layer->approachDescriptor() != nullptr) {
0139         const auto& approaches =
0140             layer->approachDescriptor()->containedSurfaces();
0141 
0142         for (const auto& approach : approaches) {
0143           addCandidate(layer.get(), approach, BoundaryTolerance::None());
0144         }
0145       }
0146 
0147       // Get all surface candidates from layers
0148       {
0149         ACTS_VERBOSE("Searching for surfaces.");
0150 
0151         if (layer->surfaceArray() != nullptr) {
0152           const auto& surfaces = layer->surfaceArray()->surfaces();
0153 
0154           ACTS_VERBOSE("Found " << surfaces.size() << " surfaces.");
0155 
0156           for (const auto& surface : surfaces) {
0157             addCandidate(surface, surface, boundaryToleranceSurfaceApproach);
0158           }
0159         }
0160       }
0161     }
0162   }
0163 }
0164 
0165 }  // namespace Acts::detail