Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:12:21

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/Navigation/SurfaceArrayNavigationPolicy.hpp"
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Geometry/SurfaceArrayCreator.hpp"
0013 #include "Acts/Geometry/TrackingVolume.hpp"
0014 #include "Acts/Navigation/NavigationStream.hpp"
0015 
0016 namespace Acts {
0017 
0018 SurfaceArrayNavigationPolicy::SurfaceArrayNavigationPolicy(
0019     const GeometryContext& gctx, const TrackingVolume& volume,
0020     const Logger& logger, Config config)
0021     : m_volume(volume) {
0022   ACTS_VERBOSE("Constructing SurfaceArrayNavigationPolicy for volume "
0023                << volume.volumeName());
0024   ACTS_VERBOSE("~> Layer type is " << config.layerType);
0025   ACTS_VERBOSE("~> bins: " << config.bins.first << " x " << config.bins.second);
0026 
0027   SurfaceArrayCreator::Config sacConfig;
0028   // This is important! detray does not support separate transforms for the
0029   // grids (yet?), so we need to ensure that the volume and surface array
0030   // transforms are at most translated relative to one another, so that the
0031   // projection is correct.
0032   sacConfig.doPhiBinningOptimization = false;
0033   SurfaceArrayCreator sac{sacConfig, logger.clone("SrfArrCrtr")};
0034 
0035   std::vector<std::shared_ptr<const Surface>> surfaces;
0036   surfaces.reserve(volume.surfaces().size());
0037   for (const auto& surface : volume.surfaces()) {
0038     if (surface.associatedDetectorElement() == nullptr) {
0039       continue;
0040     }
0041     surfaces.push_back(surface.getSharedPtr());
0042   }
0043 
0044   ACTS_VERBOSE("Number of surfaces passed to the surface array creation: "
0045                << surfaces.size());
0046   if (surfaces.empty()) {
0047     ACTS_ERROR("The number of surfaces is 0!");
0048     throw std::runtime_error("Cannot create surface array with zero surfaces");
0049   }
0050 
0051   if (config.layerType == LayerType::Disc) {
0052     auto [binsR, binsPhi] = config.bins;
0053     m_surfaceArray =
0054         sac.surfaceArrayOnDisc(gctx, std::move(surfaces), binsPhi, binsR);
0055   } else if (config.layerType == LayerType::Cylinder) {
0056     auto [binsPhi, binsZ] = config.bins;
0057     m_surfaceArray =
0058         sac.surfaceArrayOnCylinder(gctx, std::move(surfaces), binsPhi, binsZ);
0059   } else if (config.layerType == LayerType::Plane) {
0060     ACTS_ERROR("Plane layers are not yet supported");
0061     throw std::invalid_argument("Plane layers are not yet supported");
0062   } else {
0063     throw std::invalid_argument("Unknown layer type");
0064   }
0065 
0066   if (!m_surfaceArray) {
0067     ACTS_ERROR("Failed to create surface array");
0068     throw std::runtime_error("Failed to create surface array");
0069   }
0070 }
0071 
0072 void SurfaceArrayNavigationPolicy::initializeCandidates(
0073     const NavigationArguments& args, AppendOnlyNavigationStream& stream,
0074     const Logger& logger) const {
0075   ACTS_VERBOSE("SrfArrNavPol (volume=" << m_volume.volumeName() << ")");
0076 
0077   if (!args.wantsSurfaces) {
0078     return;
0079   }
0080 
0081   ACTS_VERBOSE("Querying sensitive surfaces at " << args.position.transpose());
0082   const std::vector<const Surface*>& sensitiveSurfaces =
0083       m_surfaceArray->neighbors(args.position);
0084   ACTS_VERBOSE("~> Surface array reports " << sensitiveSurfaces.size()
0085                                            << " sensitive surfaces");
0086 
0087   for (const auto* surface : sensitiveSurfaces) {
0088     stream.addSurfaceCandidate(*surface, args.tolerance);
0089   };
0090 }
0091 
0092 const Acts::SurfaceArray& SurfaceArrayNavigationPolicy::surfaceArray() const {
0093   return *m_surfaceArray;
0094 }
0095 
0096 void SurfaceArrayNavigationPolicy::connect(NavigationDelegate& delegate) const {
0097   connectDefault<SurfaceArrayNavigationPolicy>(delegate);
0098 }
0099 
0100 }  // namespace Acts