Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:21

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