Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-17 07:58:36

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