Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 07:46:22

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/Geometry/detail/PortalPlacement.hpp"
0013 #include "Acts/Surfaces/RegularSurface.hpp"
0014 
0015 #include <memory>
0016 #include <vector>
0017 
0018 namespace Acts {
0019 class GeometryContext;
0020 struct OrientedSurface;
0021 
0022 /// Interface class to define the transform cache backend for alignable volumes.
0023 /// Alignable volumes can be dynamically moved by the client code using
0024 /// the information wrapped into the GeometryContext similar to the
0025 /// alignable surfaces. The challenge is that the boundary surfaces of
0026 /// the volume need to move accordingly and that ACTS does not know
0027 /// anything about the caching of the alignable geometry objects a
0028 /// priori.
0029 ///
0030 /// A client-based implementation of the VolumePlacementBase can be
0031 /// passed to the constructor of the Volume instead of the fixed
0032 /// transform. The Volume is then querying its global position from the
0033 /// VolumePlacements. The associated bonudary surfaces are also
0034 /// requesting their position in global space. The Volume's transform and
0035 /// the bounds can the no longer be overwritten at a later stage.
0036 ///
0037 /// An implementation of the @ref VolumePlacementBase needs to satisfy the
0038 /// following interface.
0039 ///
0040 ///  1) Transforms switching from the volume's frame into the global
0041 ///     experiment's frame and vice versa:
0042 ///
0043 ///      const Transform3& localToGlobalTransform(const GeometryContext& gctx)
0044 ///      const;
0045 ///
0046 ///      const Transform3& localToGlobalTransform(const GeometryContext& gctx)
0047 ///      const;
0048 ///
0049 ///
0050 ///  2) At the end of the tracking geometry construction, the portals
0051 ///     that are associated to the volume aligned by the
0052 ///     VolumePlacementBase are connected to this particular instance.
0053 ///     The user may override the @ref makePortalsAlignable method to
0054 ///     instantiate a customized transform cache backend. He needs to ensure
0055 ///     that the base definition of the method is called from his implementation
0056 ///     otherwise the placements aligning the portals are note created.
0057 ///
0058 ///     Every time when the portal is asked for its position in space,
0059 ///     it's forwarding the request to the VolumePlacementBase by calling the
0060 ///
0061 ///         const Transform3& portalLocalToGlobal(const GeometryContext& gctx,
0062 ///                                               const std::size_t portalIdx)
0063 ///                                               const;
0064 ///
0065 ///     method. The portalIdx is the unique index of the portal and assists
0066 ///     the client to return the appropriate transform
0067 ///
0068 ///  3)  Every time when the alignment of the volume is updated, the client
0069 ///      also needs to cache the transforms of the associated surfaces.
0070 ///      After, the central volume has moved, a loop similar to the one
0071 ///      below needs to be implemented:
0072 ///
0073 ///        for (std::size_t p = 0 ; p < nPortalPlacements(); ++p) {
0074 ///            context.cachePortal(alignPortal(Acts::Geometrycontext{context},
0075 ///            p), p);
0076 ///        }
0077 ///        context.volGlobToLocal = context.volLocToGlobal.inverse();
0078 ///
0079 ///      The @ref alignPortal is a wrapper method attaching the portal -> volume transform
0080 ///      to the aligned local -> global transform of the volume and returning
0081 ///      the result via copy.
0082 class VolumePlacementBase {
0083  public:
0084   /// Default constructor
0085   VolumePlacementBase() noexcept;
0086 
0087   /// Virtual default destructor
0088   virtual ~VolumePlacementBase();
0089 
0090   /// Delete the move constructor
0091   VolumePlacementBase(VolumePlacementBase&&) = delete;
0092   /// Delete the copy constructor
0093   VolumePlacementBase(const VolumePlacementBase&) = delete;
0094 
0095   /// Delete move assignment
0096   VolumePlacementBase& operator=(VolumePlacementBase&&) = delete;
0097   /// Delete copy assignment
0098   VolumePlacementBase& operator=(const VolumePlacementBase&) = delete;
0099 
0100   /// Receives the vector of oriented portal surfaces produced by the
0101   /// VolumeBounds and makes them to float with the alignment provided
0102   /// by the volume. It then the vector of updated oriented surfaces
0103   /// @param gctx The current geometry context object, e.g. alignment
0104   /// @param portalsToAlign: List of portals to align
0105   virtual void makePortalsAlignable(
0106       const GeometryContext& gctx,
0107       const std::vector<std::shared_ptr<RegularSurface>>& portalsToAlign);
0108 
0109   /// Number of registered SurfacePlacement objects aligning the
0110   /// associated portals with the volume
0111   /// @returns The number of registered portal placements
0112   std::size_t nPortalPlacements() const;
0113 
0114   /// Returns the transformation from the local volume coordinates to
0115   ///        the experiment's global coordinate system
0116   /// @param gctx The current geometry context object, e.g. alignment
0117   /// @returns Reference to the local -> global transform
0118   virtual const Transform3& localToGlobalTransform(
0119       const GeometryContext& gctx) const = 0;
0120 
0121   /// Returns the transformation from the experiment's global frame to the
0122   /// local volume coordinate system
0123   /// @param gctx The current geometry context object, e.g. alignment
0124   /// @returns Reference to the global -> local transform
0125   virtual const Transform3& globalToLocalTransform(
0126       const GeometryContext& gctx) const = 0;
0127 
0128   /// Returns the transform from the portal's frame to the experiment's
0129   /// global frame for the portal surface associated with the volume
0130   /// @param gctx The current geometry context object, e.g. alignment
0131   /// @param portalIdx: Internal index of the portal surface [0 - number of portals)
0132   /// @returns Reference to the local -> global transform of the i-th portal
0133   virtual const Transform3& portalLocalToGlobal(
0134       const GeometryContext& gctx, const std::size_t portalIdx) const = 0;
0135 
0136   /// Pointer to the `SurfacePlacementBase` object aligning the i-th portal
0137   /// (May be nullptr if index exceeds the number of portals)
0138   /// @param portalIdx: Internal index of the portal surface [0 - number of portals)
0139   /// @returns Pointer to the i-th portal placement
0140   const detail::PortalPlacement* portalPlacement(
0141       const std::size_t portalIdx) const;
0142   /// Pointer to the `SurfacePlacementBase` object aligning the i-th portal
0143   /// (May be nullptr if index exceeds the number of portals)
0144   /// @param portalIdx: Internal index of the portal surface [0 - number of portals)
0145   /// @returns Pointer to the i-th portal placement
0146   detail::PortalPlacement* portalPlacement(const std::size_t portalIdx);
0147 
0148  protected:
0149   /// Constructs the transform from the portal's frame into the
0150   /// experiment's global frame taking the alignment corrections
0151   /// of the associated volume into account.
0152   /// @note: The call of this function is only allowed after the
0153   ///        volume itself is moved. A swapped call order probably
0154   ///        leads to unaligned portals
0155   /// @param gctx: The geometry context carrying the current volume alignment
0156   /// @param portalIdx: Index of the portal to align
0157   /// @returns The aligned localToGlobalTransform of the i-the portal
0158   Transform3 alignPortal(const GeometryContext& gctx,
0159                          const std::size_t portalIdx) const;
0160 
0161  private:
0162   /// Resource allocation of the SurfacePlacements to align the portals
0163   std::vector<std::unique_ptr<detail::PortalPlacement>> m_portalPlacements{};
0164 };
0165 }  // namespace Acts