Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:10:04

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/Grid.hpp"
0017 #include "Acts/Utilities/detail/Axis.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 EndOfWorldImpl : public INavigationDelegate {
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 /// @brief Single volume updator, it sets the current navigation
0039 /// volume to the volume in question
0040 ///
0041 struct SingleDetectorVolumeImpl : public INavigationDelegate {
0042   const DetectorVolume* dVolume = nullptr;
0043 
0044   /// @brief Allowed constructor
0045   /// @param sVolume the volume to which it points
0046   SingleDetectorVolumeImpl(const DetectorVolume* sVolume) noexcept(false)
0047       : dVolume(sVolume) {
0048     if (sVolume == nullptr) {
0049       throw std::invalid_argument(
0050           "DetectorVolumeUpdaters: nullptr provided, use EndOfWorld instead.");
0051     }
0052   }
0053 
0054   SingleDetectorVolumeImpl() = delete;
0055 
0056   /// @brief a null volume link - explicitly
0057   ///
0058   /// @note the method parameters are ignored
0059   ///
0060   inline void update(const GeometryContext& /*ignored*/,
0061                      NavigationState& nState) const {
0062     nState.currentVolume = dVolume;
0063   }
0064 };
0065 
0066 using SingleIndex = std::size_t;
0067 
0068 using VariableBoundAxis =
0069     Acts::detail::Axis<Acts::detail::AxisType::Variable,
0070                        Acts::detail::AxisBoundaryType::Bound>;
0071 using VariableBoundIndexGrid1 = Acts::Grid<SingleIndex, VariableBoundAxis>;
0072 
0073 /// @brief This holds and extracts a collection of detector
0074 /// volumes. Alternatively an extractor could also use the
0075 /// detector and its associated detector volume container for
0076 /// volume extraction.
0077 ///
0078 struct DetectorVolumesCollection {
0079   /// The volumes held by this collection
0080   std::vector<const DetectorVolume*> dVolumes = {};
0081 
0082   /// Extract a voume from a collection
0083   ///
0084   /// @note that geometry context and navigation state are ignored here
0085   /// @param index are access indices into the surfaces store
0086   ///
0087   /// @return the extracted volume
0088   inline const DetectorVolume* extract(const GeometryContext& /*gctx*/,
0089                                        const NavigationState& /*nState*/,
0090                                        const SingleIndex& index) const {
0091     return dVolumes[index];
0092   }
0093 };
0094 
0095 /// @brief This is used for volumes that are indexed in a bound
0096 /// 1-dimensional grid, e.g. a z-spaced array, or an r-spaced array
0097 /// of volumes.
0098 ///
0099 struct BoundVolumesGrid1Impl : public INavigationDelegate {
0100   using IndexedUpdater =
0101       IndexedUpdaterImpl<VariableBoundIndexGrid1, DetectorVolumesCollection,
0102                          DetectorVolumeFiller>;
0103   // The indexed updator
0104   IndexedUpdater indexedUpdater;
0105 
0106   /// Allowed constructor with explicit arguments
0107   ///
0108   /// @param gBoundaries the grid boundaries
0109   /// @param bValue the binning value
0110   /// @param cVolumes the contained volumes
0111   /// @param bTransform is the optional transform
0112   BoundVolumesGrid1Impl(
0113       const std::vector<ActsScalar>& gBoundaries, BinningValue bValue,
0114       const std::vector<const DetectorVolume*>& cVolumes,
0115       const Transform3& bTransform = Transform3::Identity()) noexcept(false)
0116       : indexedUpdater(IndexedUpdater(VariableBoundIndexGrid1(std::make_tuple(
0117                                           VariableBoundAxis(gBoundaries))),
0118                                       {bValue}, bTransform)) {
0119     indexedUpdater.extractor.dVolumes = cVolumes;
0120 
0121     if (gBoundaries.size() != cVolumes.size() + 1u) {
0122       throw std::invalid_argument(
0123           "DetectorVolumeUpdaters: mismatching boundaries and volume numbers");
0124     }
0125     // Initialize the grid entries
0126     for (std::size_t ib = 1u; ib < gBoundaries.size(); ++ib) {
0127       indexedUpdater.grid.at(ib) = ib - 1;
0128     }
0129   }
0130   // Deleted default constructor
0131   BoundVolumesGrid1Impl() = delete;
0132 
0133   /// @brief This updator relies on an 1D single index grid
0134   ///
0135   /// @param gctx the geometry context
0136   /// @param nState [in,out] the navigation state to be updated
0137   inline void update(const GeometryContext& gctx,
0138                      NavigationState& nState) const {
0139     indexedUpdater.update(gctx, nState);
0140   }
0141 };
0142 
0143 }  // namespace Acts::Experimental