Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-13 08:04:51

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2022-2023 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Geometry/GeometryContext.hpp"
0012 #include "Acts/Navigation/NavigationDelegates.hpp"
0013 #include "Acts/Navigation/NavigationState.hpp"
0014 #include "Acts/Navigation/NavigationStateFillers.hpp"
0015 #include "Acts/Navigation/NavigationStateUpdaters.hpp"
0016 #include "Acts/Utilities/Axis.hpp"
0017 #include "Acts/Utilities/Grid.hpp"
0018 
0019 #include <stdexcept>
0020 
0021 namespace Acts::Experimental {
0022 
0023 class DetectorVolume;
0024 
0025 /// @brief  The end of world sets the volume pointer of the
0026 /// navigation state to nullptr, usually indicates the end of
0027 /// the known world, hence the name
0028 struct EndOfWorld : public IExternalNavigation {
0029   /// @brief a null volume link - explicitly
0030   ///
0031   /// @note the method parameters are ignored
0032   inline void update(const GeometryContext& /*ignored*/,
0033                      NavigationState& nState) const {
0034     nState.currentVolume = nullptr;
0035   }
0036 };
0037 
0038 /// Navigation to a connected single detector volumed
0039 using SingleDetectorVolumeNavigation =
0040     SingleObjectNavigation<IExternalNavigation, DetectorVolume,
0041                            DetectorVolumeFiller>;
0042 
0043 using SingleIndex = std::size_t;
0044 
0045 using VariableBoundAxis =
0046     Acts::Axis<Acts::AxisType::Variable, Acts::AxisBoundaryType::Bound>;
0047 using VariableBoundIndexGrid1 = Acts::Grid<SingleIndex, VariableBoundAxis>;
0048 
0049 /// @brief This holds and extracts a collection of detector
0050 /// volumes. Alternatively an extractor could also use the
0051 /// detector and its associated detector volume container for
0052 /// volume extraction.
0053 ///
0054 struct DetectorVolumesCollection {
0055   /// The volumes held by this collection
0056   std::vector<const DetectorVolume*> dVolumes = {};
0057 
0058   /// Extract a voume from a collection
0059   ///
0060   /// @note that geometry context and navigation state are ignored here
0061   /// @param index are access indices into the surfaces store
0062   ///
0063   /// @return the extracted volume
0064   inline const DetectorVolume* extract(const GeometryContext& /*gctx*/,
0065                                        const NavigationState& /*nState*/,
0066                                        const SingleIndex& index) const {
0067     return dVolumes[index];
0068   }
0069 };
0070 
0071 /// @brief This is used for volumes that are indexed in a bound
0072 /// 1-dimensional grid, e.g. a z-spaced array, or an r-spaced array
0073 /// of volumes.
0074 ///
0075 struct BoundVolumesGrid1Navigation : public IExternalNavigation {
0076   using IndexedUpdater =
0077       IndexedGridNavigation<IExternalNavigation, VariableBoundIndexGrid1,
0078                             DetectorVolumesCollection, DetectorVolumeFiller>;
0079   // The indexed updator
0080   IndexedUpdater indexedUpdater;
0081 
0082   /// Allowed constructor with explicit arguments
0083   ///
0084   /// @param gBoundaries the grid boundaries
0085   /// @param bValue the binning value
0086   /// @param cVolumes the contained volumes
0087   /// @param bTransform is the optional transform
0088   BoundVolumesGrid1Navigation(
0089       const std::vector<ActsScalar>& gBoundaries, BinningValue bValue,
0090       const std::vector<const DetectorVolume*>& cVolumes,
0091       const Transform3& bTransform = Transform3::Identity()) noexcept(false)
0092       : indexedUpdater(IndexedUpdater(VariableBoundIndexGrid1(std::make_tuple(
0093                                           VariableBoundAxis(gBoundaries))),
0094                                       {bValue}, bTransform)) {
0095     indexedUpdater.extractor.dVolumes = cVolumes;
0096 
0097     if (gBoundaries.size() != cVolumes.size() + 1u) {
0098       throw std::invalid_argument(
0099           "ExternalNavigationDelegates: mismatching boundaries and volume "
0100           "numbers");
0101     }
0102     // Initialize the grid entries
0103     for (std::size_t ib = 1u; ib < gBoundaries.size(); ++ib) {
0104       indexedUpdater.grid.at(ib) = ib - 1;
0105     }
0106   }
0107   // Deleted default constructor
0108   BoundVolumesGrid1Navigation() = delete;
0109 
0110   /// @brief This updator relies on an 1D single index grid
0111   ///
0112   /// @param gctx the geometry context
0113   /// @param nState [in,out] the navigation state to be updated
0114   inline void update(const GeometryContext& gctx,
0115                      NavigationState& nState) const {
0116     indexedUpdater.update(gctx, nState);
0117   }
0118 };
0119 
0120 }  // namespace Acts::Experimental