Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 07:34:16

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/GeometryContext.hpp"
0013 #include "Acts/Geometry/ITrackingVolumeBuilder.hpp"
0014 #include "Acts/Utilities/AxisDefinitions.hpp"
0015 
0016 #include <array>
0017 #include <cstddef>
0018 #include <functional>
0019 #include <memory>
0020 #include <optional>
0021 #include <string>
0022 #include <utility>
0023 #include <vector>
0024 
0025 namespace Acts {
0026 class SurfacePlacementBase;
0027 class TrackingVolume;
0028 class VolumeBounds;
0029 class RectangleBounds;
0030 class ISurfaceMaterial;
0031 class IVolumeMaterial;
0032 class Surface;
0033 class Layer;
0034 
0035 /// @brief This class builds a box detector with a configurable amount of
0036 /// surfaces in it. The idea is to allow a quick configuration of a detector for
0037 /// mostly unit test applications. Therefore this class does not demand to be a
0038 /// universal construction factory but a raw first draft of the idea of factory
0039 /// that may be extended in the future.
0040 class CuboidVolumeBuilder : public ITrackingVolumeBuilder {
0041  public:
0042   /// @brief This struct stores the data for the construction of a single
0043   /// PlaneSurface
0044   struct SurfaceConfig {
0045     // Center position
0046     /// Center position of the surface
0047     Vector3 position{};
0048     // Rotation
0049     /// Rotation matrix defining surface orientation
0050     RotationMatrix3 rotation = RotationMatrix3::Identity();
0051     // Bounds
0052     /// Rectangle bounds defining surface dimensions
0053     std::shared_ptr<const RectangleBounds> rBounds = nullptr;
0054     // Attached material
0055     /// Surface material description
0056     std::shared_ptr<const ISurfaceMaterial> surMat = nullptr;
0057     // Thickness
0058     /// Material thickness of the surface
0059     double thickness = 0.;
0060     /// Constructor function for optional detector elements
0061     /// Arguments are transform, rectangle bounds and thickness.
0062     std::function<SurfacePlacementBase*(
0063         const Transform3&, std::shared_ptr<const RectangleBounds>, double)>
0064         detElementConstructor;
0065   };
0066 
0067   /// @brief This struct stores the data for the construction of a PlaneLayer
0068   struct LayerConfig {
0069     // Configuration of the surface
0070     /// Configuration objects for surfaces in this layer
0071     std::vector<SurfaceConfig> surfaceCfg;
0072     // Encapsulated surface
0073     /// Pre-built surfaces to be included in this layer
0074     std::vector<std::shared_ptr<const Surface>> surfaces;
0075     // Boolean flag if layer is active
0076     /// Flag indicating whether layer participates in track finding
0077     bool active = false;
0078     // Bins in Y direction
0079     /// Number of bins for surface arrangement in Y direction
0080     std::size_t binsY = 1;
0081     // Bins in Z direction
0082     /// Number of bins for surface arrangement in Z direction
0083     std::size_t binsZ = 1;
0084     // Envelope in X
0085     /// Envelope extensions in X direction [negative, positive]
0086     std::array<double, 2u> envelopeX{0, 0};
0087     // Envelope in Y
0088     /// Envelope extensions in Y direction [negative, positive]
0089     std::array<double, 2u> envelopeY{0, 0};
0090     // Envelope in Z
0091     /// Envelope extensions in Z direction [negative, positive]
0092     std::array<double, 2u> envelopeZ{0, 0};
0093     // An optional rotation for this
0094     /// Optional rotation transformation for this layer
0095     std::optional<RotationMatrix3> rotation{std::nullopt};
0096     // Dimension for the binning
0097     /// Axis direction for surface binning within the layer
0098     AxisDirection binningDimension = AxisDirection::AxisX;
0099   };
0100 
0101   /// @brief This struct stores the data for the construction of a cuboid
0102   /// TrackingVolume with a given number of PlaneLayers
0103   struct VolumeConfig {
0104     /// Center position of the tracking volume
0105     Vector3 position{};
0106     /// Dimensions of the volume in x, y, z directions
0107     Vector3 length{};
0108     /// Configuration objects for layers within this volume
0109     std::vector<LayerConfig> layerCfg;
0110     /// Pre-built layers to be included in this volume
0111     std::vector<std::shared_ptr<const Layer>> layers;
0112     /// Configuration objects for sub-volumes within this volume
0113     std::vector<VolumeConfig> volumeCfg;
0114     /// Pre-built sub-volumes contained within this volume
0115     std::vector<std::shared_ptr<TrackingVolume>> trackingVolumes;
0116     /// Identifier name for this tracking volume
0117     std::string name = "Volume";
0118     /// Volume material description for this tracking volume
0119     std::shared_ptr<const IVolumeMaterial> volumeMaterial = nullptr;
0120     /// Axis direction for layer binning within the volume
0121     AxisDirection binningDimension = AxisDirection::AxisX;
0122   };
0123 
0124   /// @brief This struct stores the configuration of the tracking geometry
0125   struct Config {
0126     /// Center position of the world volume
0127     Vector3 position = Vector3(0., 0., 0.);
0128     /// Dimensions of the world volume in x, y, z directions
0129     Vector3 length = Vector3(0., 0., 0.);
0130     /// Configuration objects for all volumes in the detector
0131     std::vector<VolumeConfig> volumeCfg = {};
0132   };
0133 
0134   /// @brief Default constructor without a configuration
0135   CuboidVolumeBuilder() = default;
0136 
0137   /// @brief Constructor that sets the config
0138   ///
0139   /// @param [in] cfg Configuration of the detector
0140   explicit CuboidVolumeBuilder(Config& cfg) : m_cfg(cfg) {}
0141 
0142   /// @brief Setter of the config
0143   ///
0144   /// @param [in] cfg Configuration that is set
0145   void setConfig(Config& cfg) { m_cfg = cfg; }
0146 
0147   /// @brief This function creates a surface with a given configuration. A
0148   /// detector element is attached if the template parameter is non-void.
0149   ///
0150   /// @param [in] gctx the geometry context for this building
0151   /// @param [in] cfg Configuration of the surface
0152   ///
0153   /// @return Pointer to the created surface
0154   std::shared_ptr<const Surface> buildSurface(const GeometryContext& gctx,
0155                                               const SurfaceConfig& cfg) const;
0156 
0157   /// @brief This function creates a layer with a surface encapsulated with a
0158   /// given configuration. The surface gets a detector element attached if the
0159   /// template parameter is non-void.
0160   ///
0161   /// @param [in] gctx the geometry context for this building
0162   /// @param [in, out] cfg Configuration of the layer and the surface
0163   ///
0164   /// @return Pointer to the created layer
0165   std::shared_ptr<const Layer> buildLayer(const GeometryContext& gctx,
0166                                           LayerConfig& cfg) const;
0167 
0168   /// @brief This function creates a TrackingVolume with a configurable number
0169   /// of layers and surfaces. Each surface gets a detector element attached if
0170   /// the template parameter is non-void.
0171   ///
0172   /// @param [in] gctx the geometry context for this building
0173   /// @param [in, out] cfg Configuration of the TrackingVolume
0174   ///
0175   /// @return Pointer to the created TrackingVolume
0176   std::shared_ptr<TrackingVolume> buildVolume(const GeometryContext& gctx,
0177                                               VolumeConfig& cfg) const;
0178 
0179   /// @brief This function evaluates the minimum and maximum of the binning as
0180   /// given by the configurations of the surfaces and layers. The ordering
0181   /// depends on the binning value specified in the configuration of the volume.
0182   ///
0183   /// @param [in] gctx the geometry context for this building
0184   /// @param [in] cfg Container with the given surfaces and layers
0185   ///
0186   /// @return Pair containing the minimum and maximum along the binning
0187   /// direction
0188   std::pair<double, double> binningRange(const GeometryContext& gctx,
0189                                          const VolumeConfig& cfg) const;
0190 
0191   /// Sort volumes along a given axis direction
0192   /// @param tapVec Vector of tracking volume and position pairs to sort
0193   /// @param bValue Axis direction for sorting
0194   void sortVolumes(std::vector<std::pair<TrackingVolumePtr, Vector3>>& tapVec,
0195                    AxisDirection bValue) const;
0196 
0197   /// @brief This function builds a world TrackingVolume based on a given
0198   /// configuration
0199   ///
0200   /// @param [in] gctx the geometry context for this building
0201   ///
0202   /// @return Pointer to the created TrackingGeometry
0203   std::shared_ptr<TrackingVolume> trackingVolume(
0204       const GeometryContext& gctx,
0205       std::shared_ptr<const TrackingVolume> /*oppositeVolume*/,
0206       std::shared_ptr<const VolumeBounds> /*outsideBounds*/) const override;
0207 
0208  private:
0209   /// Configuration of the world volume
0210   Config m_cfg;
0211 };
0212 }  // namespace Acts