Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:21

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018-2020 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 http://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/BinningType.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<ActsScalar, 2u> envelopeX{0, 0};
0078     // Envelope in Y
0079     std::array<ActsScalar, 2u> envelopeY{0, 0};
0080     // Envelope in Z
0081     std::array<ActsScalar, 2u> envelopeZ{0, 0};
0082     // An optional rotation for this
0083     std::optional<RotationMatrix3> rotation{std::nullopt};
0084   };
0085 
0086   /// @brief This struct stores the data for the construction of a cuboid
0087   /// TrackingVolume with a given number of PlaneLayers
0088   struct VolumeConfig {
0089     // Center position
0090     Vector3 position;
0091     // Lengths in x,y,z
0092     Vector3 length;
0093     // Configurations of its layers
0094     std::vector<LayerConfig> layerCfg;
0095     // Stored layers
0096     std::vector<std::shared_ptr<const Layer>> layers;
0097     // Configurations of confined volumes
0098     std::vector<VolumeConfig> volumeCfg;
0099     // Stored confined volumes
0100     std::vector<std::shared_ptr<TrackingVolume>> trackingVolumes;
0101     // Name of the volume
0102     std::string name = "Volume";
0103     // Material
0104     std::shared_ptr<const IVolumeMaterial> volumeMaterial = nullptr;
0105   };
0106 
0107   /// @brief This struct stores the configuration of the tracking geometry
0108   struct Config {
0109     // Center position
0110     Vector3 position = Vector3(0., 0., 0.);
0111     // Length in x,y,z
0112     Vector3 length = Vector3(0., 0., 0.);
0113     // Configuration of its volumes
0114     std::vector<VolumeConfig> volumeCfg = {};
0115   };
0116 
0117   /// @brief Default constructor without a configuration
0118   CuboidVolumeBuilder() = default;
0119 
0120   /// @brief Constructor that sets the config
0121   ///
0122   /// @param [in] cfg Configuration of the detector
0123   CuboidVolumeBuilder(Config& cfg) : m_cfg(cfg) {}
0124 
0125   /// @brief Setter of the config
0126   ///
0127   /// @param [in] cfg Configuration that is set
0128   void setConfig(Config& cfg) { m_cfg = cfg; }
0129 
0130   /// @brief This function creates a surface with a given configuration. A
0131   /// detector element is attached if the template parameter is non-void.
0132   ///
0133   /// @param [in] gctx the geometry context for this building
0134   /// @param [in] cfg Configuration of the surface
0135   ///
0136   /// @return Pointer to the created surface
0137   std::shared_ptr<const Surface> buildSurface(const GeometryContext& gctx,
0138                                               const SurfaceConfig& cfg) const;
0139 
0140   /// @brief This function creates a layer with a surface encapsulated with a
0141   /// given configuration. The surface gets a detector element attached if the
0142   /// template parameter is non-void.
0143   ///
0144   /// @param [in] gctx the geometry context for this building
0145   /// @param [in, out] cfg Configuration of the layer and the surface
0146   ///
0147   /// @return Pointer to the created layer
0148   std::shared_ptr<const Layer> buildLayer(const GeometryContext& gctx,
0149                                           LayerConfig& cfg) const;
0150 
0151   /// @brief This function creates a TrackingVolume with a configurable number
0152   /// of layers and surfaces. Each surface gets a detector element attached if
0153   /// the template parameter is non-void.
0154   ///
0155   /// @param [in] gctx the geometry context for this building
0156   /// @param [in, out] cfg Configuration of the TrackingVolume
0157   ///
0158   /// @return Pointer to the created TrackingVolume
0159   std::shared_ptr<TrackingVolume> buildVolume(const GeometryContext& gctx,
0160                                               VolumeConfig& cfg) const;
0161 
0162   /// @brief This function evaluates the minimum and maximum of the binning as
0163   /// given by the configurations of the surfaces and layers. The ordering
0164   /// depends on the binning value specified in the configuration of the volume.
0165   ///
0166   /// @param [in] gctx the geometry context for this building
0167   /// @param [in] cfg Container with the given surfaces and layers
0168   ///
0169   /// @return Pair containing the minimum and maximum along the binning
0170   /// direction
0171   std::pair<double, double> binningRange(const GeometryContext& gctx,
0172                                          const VolumeConfig& cfg) const;
0173 
0174   void sortVolumes(std::vector<std::pair<TrackingVolumePtr, Vector3>>& tapVec,
0175                    BinningValue bValue) const;
0176 
0177   /// @brief This function builds a world TrackingVolume based on a given
0178   /// configuration
0179   ///
0180   /// @param [in] gctx the geometry context for this building
0181   ///
0182   /// @return Pointer to the created TrackingGeometry
0183   std::shared_ptr<TrackingVolume> trackingVolume(
0184       const GeometryContext& gctx,
0185       std::shared_ptr<const TrackingVolume> /*oppositeVolume*/,
0186       std::shared_ptr<const VolumeBounds> /*outsideBounds*/) const override;
0187 
0188  private:
0189   /// Configuration of the world volume
0190   Config m_cfg;
0191 };
0192 }  // namespace Acts