Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:23:51

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/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/Direction.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Surfaces/RegularSurface.hpp"
0015 #include "Acts/Surfaces/Surface.hpp"
0016 #include "Acts/Utilities/BinnedArray.hpp"
0017 
0018 #include <memory>
0019 
0020 namespace Acts {
0021 
0022 /// @class BoundarySurfaceT
0023 ///
0024 /// @tparam  volume_t the type of volume.
0025 ///
0026 /// The boundary surface class combines a Surface with the information of a
0027 /// volume.
0028 /// It's templated in the type of volume in order to allow for a return type tat
0029 /// is usable in the navigation stream.
0030 ///
0031 /// @note along/oppose definitions are given with respect to the normal vector
0032 /// of the boundary surface.
0033 ///
0034 /// @todo change to one schema with BinnedArray0D
0035 
0036 template <class volume_t>
0037 class BoundarySurfaceT {
0038 #ifndef DOXYGEN
0039   friend volume_t;
0040 #endif
0041 
0042   using VolumePtr = std::shared_ptr<const volume_t>;
0043   using VolumeArray = BinnedArray<VolumePtr>;
0044 
0045  public:
0046   /// @brief Default constructor
0047   BoundarySurfaceT() = default;
0048   /// Constructor for a Boundary with exact two Volumes attached to it
0049   /// - usually used in a volume constructor
0050   ///
0051   /// @param surface The unique surface the boundary represents
0052   /// @param inside The inside volume the boundary surface points to
0053   /// @param outside The outside volume the boundary surface points to
0054   BoundarySurfaceT(std::shared_ptr<RegularSurface> surface,
0055                    const volume_t* inside, const volume_t* outside)
0056       : m_surface(std::move(surface)),
0057         m_oppositeVolume{inside},
0058         m_alongVolume{outside} {}
0059 
0060   /// Constructor for a Boundary with exact two Volumes attached to it
0061   /// - usually used in a volume constructor
0062   ///
0063   /// @param surface The unique surface the boundary represents
0064   /// @param inside The inside volume the boundary surface points to
0065   /// @param outside The outside volume the boundary surface points to
0066   BoundarySurfaceT(std::shared_ptr<RegularSurface> surface, VolumePtr inside,
0067                    VolumePtr outside)
0068       : m_surface(std::move(surface)),
0069         m_oppositeVolume(inside.get()),
0070         m_alongVolume(outside.get()) {}
0071 
0072   /// Constructor for a Boundary with exact multiple Volumes attached to it
0073   /// - usually used in a volume constructor
0074   ///
0075   /// @param surface The unique surface the boundary represents
0076   /// @param insideArray The inside volume array the boundary surface points to
0077   /// @param outsideArray The outside volume array the boundary surface
0078   /// points to
0079   BoundarySurfaceT(std::shared_ptr<RegularSurface> surface,
0080                    std::shared_ptr<const VolumeArray> insideArray,
0081                    std::shared_ptr<const VolumeArray> outsideArray)
0082       : m_surface{std::move(surface)},
0083         m_oppositeVolumeArray{std::move(insideArray)},
0084         m_alongVolumeArray{std::move(outsideArray)} {}
0085 
0086   virtual ~BoundarySurfaceT() = default;
0087 
0088   /// Get the next Volume depending on GlobalPosition, GlobalMomentum, dir on
0089   /// the TrackParameters and the requested direction
0090   ///
0091   /// @param gctx The current geometry context object, e.g. alignment
0092   /// @param pos The global position on surface
0093   /// @param dir The direction on the surface
0094   ///
0095   /// @return The attached volume at that position
0096   virtual const volume_t* attachedVolume(const GeometryContext& gctx,
0097                                          const Vector3& pos,
0098                                          const Vector3& dir) const {
0099     const volume_t* attVolume = nullptr;
0100     // dot product with normal vector to distinguish inside/outside
0101     if ((surfaceRepresentation().normal(gctx, pos)).dot(dir) > 0.) {
0102       attVolume = m_alongVolumeArray ? m_alongVolumeArray->object(pos).get()
0103                                      : m_alongVolume;
0104     } else {
0105       attVolume = m_oppositeVolumeArray
0106                       ? m_oppositeVolumeArray->object(pos).get()
0107                       : m_oppositeVolume;
0108     }
0109     return attVolume;
0110   }
0111 
0112   /// templated onBoundary method
0113   ///
0114   /// @tparam parameters_t are the parameters to be checked
0115   ///
0116   /// @param gctx The current geometry context object, e.g. alignment
0117   /// @param pars The parameters used for this call
0118   /// @return True if the parameters are on the boundary surface
0119   template <class parameters_t>
0120   bool onBoundary(const GeometryContext& gctx, const parameters_t& pars) const {
0121     return surfaceRepresentation().isOnSurface(gctx, pars);
0122   }
0123 
0124   /// The Surface Representation of this
0125   /// @return Reference to the surface representation of this boundary
0126   virtual const RegularSurface& surfaceRepresentation() const {
0127     return *m_surface;
0128   }
0129 
0130   /// The Surface Representation of this
0131   /// @return Reference to the surface representation of this boundary
0132   RegularSurface& surfaceRepresentation() { return *m_surface; }
0133 
0134   /// Helper method: attach a Volume to this BoundarySurfaceT
0135   /// this is done during the geometry construction.
0136   ///
0137   /// @param volume The volume to be attached
0138   /// @param dir The direction for attaching
0139   void attachVolume(const volume_t* volume, Direction dir) {
0140     if (dir == Direction::Backward()) {
0141       m_oppositeVolume = volume;
0142     } else {
0143       m_alongVolume = volume;
0144     }
0145   }
0146 
0147   /// Helper method: attach a Volume to this BoundarySurfaceT
0148   /// this is done during the geometry construction.
0149   ///
0150   /// @param volumes The volume array to be attached
0151   /// @param dir The direction for attaching
0152   void attachVolumeArray(std::shared_ptr<const VolumeArray> volumes,
0153                          Direction dir) {
0154     if (dir == Direction::Backward()) {
0155       m_oppositeVolumeArray = volumes;
0156     } else {
0157       m_alongVolumeArray = volumes;
0158     }
0159   }
0160 
0161  protected:
0162   /// the represented surface by this
0163   std::shared_ptr<RegularSurface> m_surface{};
0164   /// the inside (w.r.t. normal vector) volume to point to if only one exists
0165   const volume_t* m_oppositeVolume{};
0166   /// the outside (w.r.t. normal vector) volume to point to if only one exists
0167   const volume_t* m_alongVolume{};
0168   /// the inside (w.r.t. normal vector) volume array to point to
0169   std::shared_ptr<const VolumeArray> m_oppositeVolumeArray{};
0170   /// the outside (w.r.t. normal vector) volume array to point to
0171   std::shared_ptr<const VolumeArray> m_alongVolumeArray{};
0172 };
0173 
0174 class TrackingVolume;
0175 using BoundarySurface = BoundarySurfaceT<TrackingVolume>;
0176 
0177 }  // namespace Acts