Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-11 07:49:48

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/Extent.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Surfaces/Surface.hpp"
0014 #include "Acts/Utilities/AxisDefinitions.hpp"
0015 
0016 #include <iostream>
0017 #include <memory>
0018 #include <utility>
0019 #include <vector>
0020 
0021 namespace Acts {
0022 
0023 namespace detail {
0024 
0025 /// @class ProtoLayerBase
0026 ///
0027 /// Base class containing common functionality for ProtoLayer implementations
0028 /// @note This will go away once we remove the Gen1 geometry which assumes this only takes const pointers.
0029 struct ProtoLayerBase {
0030  public:
0031   /// The extent of the ProtoLayer
0032   Extent extent;
0033 
0034   /// The envelope parameters
0035   ExtentEnvelope envelope = ExtentEnvelope::Zero();
0036 
0037   /// The local transform
0038   Transform3 transform = Transform3::Identity();
0039 
0040   /// Get the parameters : min
0041   /// @param aDir The accessed axis direction
0042   /// @param addenv The steering if enevlope is added or not
0043   double min(AxisDirection aDir, bool addenv = true) const;
0044 
0045   // Get the  parameters : max
0046   /// @param aDir The accessed axis direction
0047   /// @param addenv The steering if enevlope is added or not
0048   double max(AxisDirection aDir, bool addenv = true) const;
0049 
0050   // Get the  parameters : medium
0051   /// @param aDir The accessed axis direction
0052   /// @param addenv The steering if enevlope is added or not
0053   double medium(AxisDirection aDir, bool addenv = true) const;
0054 
0055   // Get the  parameters : range
0056   /// @param aDir The accessed axis direction
0057   /// @param addenv The steering if enevlope is added or not
0058   double range(AxisDirection aDir, bool addenv = true) const;
0059 
0060   /// Output to ostream
0061   /// @param sl the input ostream
0062   std::ostream& toStream(std::ostream& sl) const;
0063 
0064  protected:
0065   /// Helper method which performs the actual min/max calculation
0066   ///
0067   /// @param gctx The current geometry context object, e.g. alignment
0068   /// @param surfaces The surfaces to build this protolayer out of
0069   /// @param extent The extent to modify
0070   /// @param transform The transform to use
0071   static void measureImpl(const GeometryContext& gctx,
0072                           const std::vector<const Surface*>& surfaces,
0073                           Extent& extent, const Transform3& transform);
0074 };
0075 
0076 /// @struct ProtoLayerT
0077 ///
0078 /// Encapsulates min/max boundaries that will be turned into a layer.
0079 /// The struct allows this information to be obtained in a consistent
0080 /// way, or be caller provided.
0081 template <bool IsConst>
0082 struct ProtoLayerT : public ProtoLayerBase {
0083   using SurfacePtr = std::conditional_t<IsConst, const Surface*, Surface*>;
0084   using SurfaceType = std::conditional_t<IsConst, const Surface, Surface>;
0085 
0086   /// Constructor
0087   ///
0088   /// Loops over a provided vector of surface and calculates the various
0089   /// min/max values in one go. Also takes into account the thickness
0090   /// of an associated DetectorElement, if it exists.
0091   ///
0092   /// @param gctx The current geometry context object, e.g. alignment
0093   /// @param surfaces The vector of surfaces to consider
0094   /// @param transformIn The local transform to evaluate the sizing in
0095   ProtoLayerT(const GeometryContext& gctx,
0096               const std::vector<SurfacePtr>& surfaces,
0097               const Transform3& transformIn = Transform3::Identity())
0098       : m_surfaces(surfaces) {
0099     transform = transformIn;
0100     std::vector<const Surface*> constSurfaces;
0101     if constexpr (!IsConst) {
0102       constSurfaces.reserve(surfaces.size());
0103       for (auto* sf : surfaces) {
0104         constSurfaces.push_back(sf);
0105       }
0106       measureImpl(gctx, constSurfaces, extent, transform);
0107     } else {
0108       measureImpl(gctx, surfaces, extent, transform);
0109     }
0110   }
0111 
0112   /// Constructor
0113   ///
0114   /// Loops over a provided vector of surface and calculates the various
0115   /// min/max values in one go. Also takes into account the thickness
0116   /// of an associated DetectorElement, if it exists.
0117   ///
0118   /// @param gctx The current geometry context object, e.g. alignment
0119   /// @param surfaces The vector of surfaces to consider
0120   /// @param transformIn The local transform to evaluate the sizing in
0121   ProtoLayerT(const GeometryContext& gctx,
0122               const std::vector<std::shared_ptr<SurfaceType>>& surfaces,
0123               const Transform3& transformIn = Transform3::Identity()) {
0124     transform = transformIn;
0125     m_surfaces.reserve(surfaces.size());
0126     for (const auto& sf : surfaces) {
0127       m_surfaces.push_back(sf.get());
0128     }
0129     std::vector<const Surface*> constSurfaces;
0130     if constexpr (!IsConst) {
0131       constSurfaces.reserve(surfaces.size());
0132       for (auto* sf : m_surfaces) {
0133         constSurfaces.push_back(sf);
0134       }
0135       measureImpl(gctx, constSurfaces, extent, transform);
0136     } else {
0137       measureImpl(gctx, m_surfaces, extent, transform);
0138     }
0139   }
0140 
0141   /// Constructor that accepts non-const shared pointers even when IsConst is
0142   /// true
0143   ///
0144   /// @param gctx The current geometry context object, e.g. alignment
0145   /// @param surfaces The vector of surfaces to consider
0146   /// @param transformIn The local transform to evaluate the sizing in
0147   ProtoLayerT(const GeometryContext& gctx,
0148               const std::vector<std::shared_ptr<Surface>>& surfaces,
0149               const Transform3& transformIn = Transform3::Identity())
0150     requires IsConst
0151   {
0152     transform = transformIn;
0153     m_surfaces.reserve(surfaces.size());
0154     for (const auto& sf : surfaces) {
0155       m_surfaces.push_back(sf.get());
0156     }
0157     measureImpl(gctx, m_surfaces, extent, transform);
0158   }
0159 
0160   ProtoLayerT() = default;
0161 
0162   /// Output stream operator
0163   /// @param sl the input ostream
0164   /// @param pl the ProtoLayer to be printed
0165   /// @return the output ostream
0166   friend std::ostream& operator<<(std::ostream& sl, const ProtoLayerT& pl) {
0167     return pl.toStream(sl);
0168   }
0169 
0170   /// Give access to the surfaces used/assigned to the ProtoLayer
0171   const std::vector<SurfacePtr>& surfaces() const { return m_surfaces; }
0172 
0173   /// Add a surface, this will also increase the extent
0174   /// @param gctx The current geometry context object, e.g. alignment
0175   /// @param surface The surface which is added to the ProtoLayer
0176   void add(const GeometryContext& gctx, SurfaceType& surface) {
0177     m_surfaces.push_back(&surface);
0178     std::vector<const Surface*> constSurfaces;
0179     if constexpr (!IsConst) {
0180       constSurfaces.reserve(m_surfaces.size());
0181       for (auto* sf : m_surfaces) {
0182         constSurfaces.push_back(sf);
0183       }
0184       measureImpl(gctx, constSurfaces, extent, transform);
0185     } else {
0186       measureImpl(gctx, m_surfaces, extent, transform);
0187     }
0188   }
0189 
0190  protected:
0191   /// Store the list of surfaces used for this proto layer
0192   std::vector<SurfacePtr> m_surfaces = {};
0193 };
0194 
0195 }  // namespace detail
0196 
0197 struct MutableProtoLayer : public detail::ProtoLayerT<false> {
0198   using detail::ProtoLayerT<false>::ProtoLayerT;
0199 };
0200 
0201 // Forward-declaration friendly class for backward compatibility
0202 struct ProtoLayer : public detail::ProtoLayerT<true> {
0203   using detail::ProtoLayerT<true>::ProtoLayerT;
0204 
0205   explicit ProtoLayer(const MutableProtoLayer& other);
0206 };
0207 
0208 }  // namespace Acts