Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-15 08:11:50

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     Vector3 position;
0048     // Rotation
0049     RotationMatrix3 rotation = RotationMatrix3::Identity();
0050     // Bounds
0051     std::shared_ptr<const RectangleBounds> rBounds = nullptr;
0052     // Attached material
0053     std::shared_ptr<const ISurfaceMaterial> surMat = nullptr;
0054     // Thickness
0055     double thickness = 0.;
0056     // Constructor function for optional detector elements
0057     // Arguments are transform, rectangle bounds and thickness.
0058     std::function<DetectorElementBase*(
0059         const Transform3&, std::shared_ptr<const RectangleBounds>, double)>
0060         detElementConstructor;
0061   };
0062 
0063   /// @brief This struct stores the data for the construction of a PlaneLayer
0064   struct LayerConfig {
0065     // Configuration of the surface
0066     std::vector<SurfaceConfig> surfaceCfg;
0067     // Encapsulated surface
0068     std::vector<std::shared_ptr<const Surface>> surfaces;
0069     // Boolean flag if layer is active
0070     bool active = false;
0071     // Bins in Y direction
0072     std::size_t binsY = 1;
0073     // Bins in Z direction
0074     std::size_t binsZ = 1;
0075     // Envelope in X
0076     std::array<double, 2u> envelopeX{0, 0};
0077     // Envelope in Y
0078     std::array<double, 2u> envelopeY{0, 0};
0079     // Envelope in Z
0080     std::array<double, 2u> envelopeZ{0, 0};
0081     // An optional rotation for this
0082     std::optional<RotationMatrix3> rotation{std::nullopt};
0083     // Dimension for the binning
0084     AxisDirection binningDimension = AxisDirection::AxisX;
0085   };
0086 
0087   /// @brief This struct stores the data for the construction of a cuboid
0088   /// TrackingVolume with a given number of PlaneLayers
0089   struct VolumeConfig {
0090     // Center position
0091     Vector3 position;
0092     // Lengths in x,y,z
0093     Vector3 length;
0094     // Configurations of its layers
0095     std::vector<LayerConfig> layerCfg;
0096     // Stored layers
0097     std::vector<std::shared_ptr<const Layer>> layers;
0098     // Configurations of confined volumes
0099     std::vector<VolumeConfig> volumeCfg;
0100     // Stored confined volumes
0101     std::vector<std::shared_ptr<TrackingVolume>> trackingVolumes;
0102     // Name of the volume
0103     std::string name = "Volume";
0104     // Material
0105     std::shared_ptr<const IVolumeMaterial> volumeMaterial = nullptr;
0106     // Dimension for the binning
0107     AxisDirection binningDimension = AxisDirection::AxisX;
0108   };
0109 
0110   /// @brief This struct stores the configuration of the tracking geometry
0111   struct Config {
0112     // Center position
0113     Vector3 position = Vector3(0., 0., 0.);
0114     // Length in x,y,z
0115     Vector3 length = Vector3(0., 0., 0.);
0116     // Configuration of its volumes
0117     std::vector<VolumeConfig> volumeCfg = {};
0118   };
0119 
0120   /// @brief Default constructor without a configuration
0121   CuboidVolumeBuilder() = default;
0122 
0123   /// @brief Constructor that sets the config
0124   ///
0125   /// @param [in] cfg Configuration of the detector
0126   explicit CuboidVolumeBuilder(Config& cfg) : m_cfg(cfg) {}
0127 
0128   /// @brief Setter of the config
0129   ///
0130   /// @param [in] cfg Configuration that is set
0131   void setConfig(Config& cfg) { m_cfg = cfg; }
0132 
0133   /// @brief This function creates a surface with a given configuration. A
0134   /// detector element is attached if the template parameter is non-void.
0135   ///
0136   /// @param [in] gctx the geometry context for this building
0137   /// @param [in] cfg Configuration of the surface
0138   ///
0139   /// @return Pointer to the created surface
0140   std::shared_ptr<const Surface> buildSurface(const GeometryContext& gctx,
0141                                               const SurfaceConfig& cfg) const;
0142 
0143   /// @brief This function creates a layer with a surface encapsulated with a
0144   /// given configuration. The surface gets a detector element attached if the
0145   /// template parameter is non-void.
0146   ///
0147   /// @param [in] gctx the geometry context for this building
0148   /// @param [in, out] cfg Configuration of the layer and the surface
0149   ///
0150   /// @return Pointer to the created layer
0151   std::shared_ptr<const Layer> buildLayer(const GeometryContext& gctx,
0152                                           LayerConfig& cfg) const;
0153 
0154   /// @brief This function creates a TrackingVolume with a configurable number
0155   /// of layers and surfaces. Each surface gets a detector element attached if
0156   /// the template parameter is non-void.
0157   ///
0158   /// @param [in] gctx the geometry context for this building
0159   /// @param [in, out] cfg Configuration of the TrackingVolume
0160   ///
0161   /// @return Pointer to the created TrackingVolume
0162   std::shared_ptr<TrackingVolume> buildVolume(const GeometryContext& gctx,
0163                                               VolumeConfig& cfg) const;
0164 
0165   /// @brief This function evaluates the minimum and maximum of the binning as
0166   /// given by the configurations of the surfaces and layers. The ordering
0167   /// depends on the binning value specified in the configuration of the volume.
0168   ///
0169   /// @param [in] gctx the geometry context for this building
0170   /// @param [in] cfg Container with the given surfaces and layers
0171   ///
0172   /// @return Pair containing the minimum and maximum along the binning
0173   /// direction
0174   std::pair<double, double> binningRange(const GeometryContext& gctx,
0175                                          const VolumeConfig& cfg) const;
0176 
0177   void sortVolumes(std::vector<std::pair<TrackingVolumePtr, Vector3>>& tapVec,
0178                    AxisDirection bValue) const;
0179 
0180   /// @brief This function builds a world TrackingVolume based on a given
0181   /// configuration
0182   ///
0183   /// @param [in] gctx the geometry context for this building
0184   ///
0185   /// @return Pointer to the created TrackingGeometry
0186   std::shared_ptr<TrackingVolume> trackingVolume(
0187       const GeometryContext& gctx,
0188       std::shared_ptr<const TrackingVolume> /*oppositeVolume*/,
0189       std::shared_ptr<const VolumeBounds> /*outsideBounds*/) const override;
0190 
0191  private:
0192   /// Configuration of the world volume
0193   Config m_cfg;
0194 };
0195 }  // namespace Acts