Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-24 08:18:35

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