File indexing completed on 2025-07-05 08:11:33
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Navigation/SurfaceArrayNavigationPolicy.hpp"
0010
0011 #include "Acts/Geometry/SurfaceArrayCreator.hpp"
0012 #include "Acts/Geometry/TrackingVolume.hpp"
0013 #include "Acts/Navigation/NavigationStream.hpp"
0014
0015 #include <algorithm>
0016
0017 namespace Acts {
0018
0019 SurfaceArrayNavigationPolicy::SurfaceArrayNavigationPolicy(
0020 const GeometryContext& gctx, const TrackingVolume& volume,
0021 const Logger& logger, Config config)
0022 : m_volume(volume) {
0023 ACTS_VERBOSE("Constructing SurfaceArrayNavigationPolicy for volume "
0024 << volume.volumeName());
0025 ACTS_VERBOSE("~> Layer type is " << config.layerType);
0026 ACTS_VERBOSE("~> bins: " << config.bins.first << " x " << config.bins.second);
0027
0028 SurfaceArrayCreator::Config sacConfig;
0029 SurfaceArrayCreator sac{sacConfig, logger.clone("SrfArrCrtr")};
0030
0031 std::vector<std::shared_ptr<const Surface>> surfaces;
0032 surfaces.reserve(volume.surfaces().size());
0033 for (const auto& surface : volume.surfaces()) {
0034 if (surface.associatedDetectorElement() == nullptr) {
0035 continue;
0036 }
0037 surfaces.push_back(surface.getSharedPtr());
0038 }
0039
0040 ACTS_VERBOSE("Number of surfaces passed to the surface array creation: "
0041 << surfaces.size());
0042 if (surfaces.empty()) {
0043 ACTS_ERROR("The number of surfaces is 0!");
0044 throw std::runtime_error("Cannot create surface array with zero surfaces");
0045 }
0046
0047 if (config.layerType == LayerType::Disc) {
0048 auto [binsR, binsPhi] = config.bins;
0049 m_surfaceArray =
0050 sac.surfaceArrayOnDisc(gctx, std::move(surfaces), binsPhi, binsR);
0051 } else if (config.layerType == LayerType::Cylinder) {
0052 auto [binsPhi, binsZ] = config.bins;
0053 m_surfaceArray =
0054 sac.surfaceArrayOnCylinder(gctx, std::move(surfaces), binsPhi, binsZ);
0055 } else if (config.layerType == LayerType::Plane) {
0056 ACTS_ERROR("Plane layers are not yet supported");
0057 throw std::invalid_argument("Plane layers are not yet supported");
0058 } else {
0059 throw std::invalid_argument("Unknown layer type");
0060 }
0061
0062 if (!m_surfaceArray) {
0063 ACTS_ERROR("Failed to create surface array");
0064 throw std::runtime_error("Failed to create surface array");
0065 }
0066 }
0067
0068 void SurfaceArrayNavigationPolicy::initializeCandidates(
0069 const NavigationArguments& args, AppendOnlyNavigationStream& stream,
0070 const Logger& logger) const {
0071 ACTS_VERBOSE("SrfArrNavPol (volume=" << m_volume.volumeName() << ")");
0072
0073 if (!args.wantsSurfaces) {
0074 return;
0075 }
0076
0077 ACTS_VERBOSE("Querying sensitive surfaces at " << args.position.transpose());
0078 const std::vector<const Surface*>& sensitiveSurfaces =
0079 m_surfaceArray->neighbors(args.position);
0080 ACTS_VERBOSE("~> Surface array reports " << sensitiveSurfaces.size()
0081 << " sensitive surfaces");
0082
0083 for (const auto* surface : sensitiveSurfaces) {
0084 stream.addSurfaceCandidate(*surface, args.tolerance);
0085 };
0086 }
0087
0088 void SurfaceArrayNavigationPolicy::connect(NavigationDelegate& delegate) const {
0089 connectDefault<SurfaceArrayNavigationPolicy>(delegate);
0090 }
0091
0092 }