Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-26 07:54:34

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   BoundarySurfaceT()
0047       : m_surface(nullptr),
0048         m_oppositeVolume(nullptr),
0049         m_alongVolume(nullptr),
0050         m_oppositeVolumeArray(nullptr),
0051         m_alongVolumeArray(nullptr) {}
0052 
0053   /// Constructor for a Boundary with exact two Volumes attached to it
0054   /// - usually used in a volume constructor
0055   ///
0056   /// @param surface The unique surface the boundary represents
0057   /// @param inside The inside volume the boundary surface points to
0058   /// @param outside The outside volume the boundary surface points to
0059   BoundarySurfaceT(std::shared_ptr<const RegularSurface> surface,
0060                    const volume_t* inside, const volume_t* outside)
0061       : m_surface(std::move(surface)),
0062         m_oppositeVolume(inside),
0063         m_alongVolume(outside),
0064         m_oppositeVolumeArray(nullptr),
0065         m_alongVolumeArray(nullptr) {}
0066 
0067   /// Constructor for a Boundary with exact two Volumes attached to it
0068   /// - usually used in a volume constructor
0069   ///
0070   /// @param surface The unique surface the boundary represents
0071   /// @param inside The inside volume the boundary surface points to
0072   /// @param outside The outside volume the boundary surface points to
0073   BoundarySurfaceT(std::shared_ptr<const RegularSurface> surface,
0074                    VolumePtr inside, VolumePtr outside)
0075       : m_surface(std::move(surface)),
0076         m_oppositeVolume(inside.get()),
0077         m_alongVolume(outside.get()),
0078         m_oppositeVolumeArray(nullptr),
0079         m_alongVolumeArray(nullptr) {}
0080 
0081   /// Constructor for a Boundary with exact multiple Volumes attached to it
0082   /// - usually used in a volume constructor
0083   ///
0084   /// @param surface The unique surface the boundary represents
0085   /// @param insideArray The inside volume array the boundary surface points to
0086   /// @param outsideArray The outside volume array the boundary surface
0087   /// points to
0088   BoundarySurfaceT(std::shared_ptr<const RegularSurface> surface,
0089                    std::shared_ptr<const VolumeArray> insideArray,
0090                    std::shared_ptr<const VolumeArray> outsideArray)
0091       : m_surface(std::move(surface)),
0092         m_oppositeVolume(nullptr),
0093         m_alongVolume(nullptr),
0094         m_oppositeVolumeArray(insideArray),
0095         m_alongVolumeArray(outsideArray) {}
0096 
0097   virtual ~BoundarySurfaceT() = default;
0098 
0099   /// Get the next Volume depending on GlobalPosition, GlobalMomentum, dir on
0100   /// the TrackParameters and the requested direction
0101   ///
0102   /// @param gctx The current geometry context object, e.g. alignment
0103   /// @param pos The global position on surface
0104   /// @param dir The direction on the surface
0105   ///
0106   /// @return The attached volume at that position
0107   virtual const volume_t* attachedVolume(const GeometryContext& gctx,
0108                                          const Vector3& pos,
0109                                          const Vector3& dir) const {
0110     const volume_t* attVolume = nullptr;
0111     // dot product with normal vector to distinguish inside/outside
0112     if ((surfaceRepresentation().normal(gctx, pos)).dot(dir) > 0.) {
0113       attVolume = m_alongVolumeArray ? m_alongVolumeArray->object(pos).get()
0114                                      : m_alongVolume;
0115     } else {
0116       attVolume = m_oppositeVolumeArray
0117                       ? m_oppositeVolumeArray->object(pos).get()
0118                       : m_oppositeVolume;
0119     }
0120     return attVolume;
0121   }
0122 
0123   /// templated onBoundary method
0124   ///
0125   /// @tparam parameters_t are the parameters to be checked
0126   ///
0127   /// @param gctx The current geometry context object, e.g. alignment
0128   /// @param pars The parameters used for this call
0129   /// @return True if the parameters are on the boundary surface
0130   template <class parameters_t>
0131   bool onBoundary(const GeometryContext& gctx, const parameters_t& pars) const {
0132     return surfaceRepresentation().isOnSurface(gctx, pars);
0133   }
0134 
0135   /// The Surface Representation of this
0136   /// @return Reference to the surface representation of this boundary
0137   virtual const RegularSurface& surfaceRepresentation() const {
0138     return *m_surface;
0139   }
0140 
0141   /// Helper method: attach a Volume to this BoundarySurfaceT
0142   /// this is done during the geometry construction.
0143   ///
0144   /// @param volume The volume to be attached
0145   /// @param dir The direction for attaching
0146   void attachVolume(const volume_t* volume, Direction dir) {
0147     if (dir == Direction::Backward()) {
0148       m_oppositeVolume = volume;
0149     } else {
0150       m_alongVolume = volume;
0151     }
0152   }
0153 
0154   /// Helper method: attach a Volume to this BoundarySurfaceT
0155   /// this is done during the geometry construction.
0156   ///
0157   /// @param volumes The volume array to be attached
0158   /// @param dir The direction for attaching
0159   void attachVolumeArray(std::shared_ptr<const VolumeArray> volumes,
0160                          Direction dir) {
0161     if (dir == Direction::Backward()) {
0162       m_oppositeVolumeArray = volumes;
0163     } else {
0164       m_alongVolumeArray = volumes;
0165     }
0166   }
0167 
0168  protected:
0169   /// the represented surface by this
0170   std::shared_ptr<const RegularSurface> m_surface;
0171   /// the inside (w.r.t. normal vector) volume to point to if only one exists
0172   const volume_t* m_oppositeVolume;
0173   /// the outside (w.r.t. normal vector) volume to point to if only one exists
0174   const volume_t* m_alongVolume;
0175   /// the inside (w.r.t. normal vector) volume array to point to
0176   std::shared_ptr<const VolumeArray> m_oppositeVolumeArray;
0177   /// the outside (w.r.t. normal vector) volume array to point to
0178   std::shared_ptr<const VolumeArray> m_alongVolumeArray;
0179 };
0180 
0181 class TrackingVolume;
0182 using BoundarySurface = BoundarySurfaceT<TrackingVolume>;
0183 
0184 }  // namespace Acts