Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:51

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