Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:43

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2017-2018 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/Definitions/Units.hpp"
0013 #include "Acts/Geometry/GeometryContext.hpp"
0014 #include "Acts/Geometry/ILayerBuilder.hpp"
0015 #include "Acts/Geometry/LayerCreator.hpp"
0016 #include "Acts/Geometry/ProtoLayerHelper.hpp"
0017 #include "Acts/Geometry/SurfaceBinningMatcher.hpp"
0018 #include "Acts/Plugins/TGeo/ITGeoIdentifierProvider.hpp"
0019 #include "Acts/Utilities/BinningType.hpp"
0020 #include "Acts/Utilities/Logger.hpp"
0021 
0022 #include <algorithm>
0023 #include <array>
0024 #include <climits>
0025 #include <functional>
0026 #include <memory>
0027 #include <string>
0028 #include <tuple>
0029 #include <utility>
0030 #include <vector>
0031 
0032 class TGeoMatrix;
0033 class TGeoVolume;
0034 class TGeoNode;
0035 
0036 namespace Acts {
0037 
0038 class TGeoDetectorElement;
0039 class ITGeoDetectorElementSplitter;
0040 class Surface;
0041 class ISurfaceMaterial;
0042 class ITGeoIdentifierProvider;
0043 class LayerCreator;
0044 class ProtoLayerHelper;
0045 
0046 /// @class TGeoLayerBuilder
0047 ///
0048 /// This parses the gGeoManager and looks for a defined combination
0049 /// of volume with contained sensitive detector element. The association
0050 /// is done by matching the names of the TGeoNode / TGeoVolume to the search
0051 /// string.
0052 ///
0053 /// The parsing can be restricted to a given parse volume (in r and z),
0054 /// and given some splitting parameters the surfaces can be automatically
0055 /// split into layers.
0056 class TGeoLayerBuilder : public ILayerBuilder {
0057  public:
0058   ///  Helper config structs for volume parsing
0059   struct LayerConfig {
0060    public:
0061     using RangeConfig = std::pair<BinningValue, std::pair<double, double>>;
0062 
0063     using SplitConfig = std::pair<BinningValue, double>;
0064 
0065     /// Identify the search volume by name
0066     std::string volumeName = "";
0067     /// Identify the sensor(s) by name
0068     std::vector<std::string> sensorNames = {};
0069     /// The local axis definition of TGeo object to Acts::Surface
0070     std::string localAxes = "XYZ";
0071     /// Parse ranges: parameter and ranges
0072     std::vector<RangeConfig> parseRanges = {};
0073     /// Layer splitting: parameter and tolerance
0074     std::vector<SplitConfig> splitConfigs = {};
0075     /// The envelope to be built around the layer
0076     std::pair<double, double> envelope = {1 * UnitConstants::mm,
0077                                           1 * UnitConstants::mm};
0078     /// Binning setup in l0: nbins (-1 -> automated), axis binning type
0079     std::vector<std::pair<int, BinningType>> binning0 = {{-1, equidistant}};
0080     /// Binning setup in l1: nbins (-1 -> automated), axis binning type
0081     std::vector<std::pair<int, BinningType>> binning1 = {{-1, equidistant}};
0082 
0083     // Default constructor
0084     LayerConfig()
0085         : volumeName(""),
0086           sensorNames({}),
0087           localAxes("XZY"),
0088           envelope(std::pair<double, double>(1 * UnitConstants::mm,
0089                                              1 * UnitConstants::mm)) {}
0090   };
0091 
0092   using ElementFactory = std::function<std::shared_ptr<TGeoDetectorElement>(
0093       const TGeoDetectorElement::Identifier&, const TGeoNode&,
0094       const TGeoMatrix& tGeoMatrix, const std::string& axes, double scalor,
0095       std::shared_ptr<const Acts::ISurfaceMaterial> material)>;
0096 
0097   static std::shared_ptr<TGeoDetectorElement> defaultElementFactory(
0098       const TGeoDetectorElement::Identifier& identifier,
0099       const TGeoNode& tGeoNode, const TGeoMatrix& tGeoMatrix,
0100       const std::string& axes, double scalor,
0101       std::shared_ptr<const Acts::ISurfaceMaterial> material);
0102 
0103   /// @struct Config
0104   /// @brief nested configuration struct for steering of the layer builder
0105   struct Config {
0106     /// String based identification
0107     std::string configurationName = "undefined";
0108     /// Unit conversion
0109     double unit = 1 * UnitConstants::cm;
0110     /// Create an identifier from TGeoNode
0111     std::shared_ptr<const ITGeoIdentifierProvider> identifierProvider = nullptr;
0112     /// Split TGeoElement if a splitter is provided
0113     std::shared_ptr<const ITGeoDetectorElementSplitter>
0114         detectorElementSplitter = nullptr;
0115     /// Factory for creating detector elements based on TGeoNodes
0116     ElementFactory elementFactory = defaultElementFactory;
0117     /// Layer creator
0118     std::shared_ptr<const LayerCreator> layerCreator = nullptr;
0119     /// ProtoLayer helper
0120     std::shared_ptr<const ProtoLayerHelper> protoLayerHelper = nullptr;
0121     /// Configuration is always | n | c | p |
0122     std::array<std::vector<LayerConfig>, 3> layerConfigurations;
0123     /// Split tolerances in R
0124     std::array<double, 3> layerSplitToleranceR = {-1., -1., -1.};
0125     /// Split tolerances in Z
0126     std::array<double, 3> layerSplitToleranceZ = {-1., -1., -1.};
0127     /// Automated binning & tolerances
0128     bool autoSurfaceBinning = false;
0129     /// The surface binning matcher
0130     Acts::SurfaceBinningMatcher surfaceBinMatcher;
0131   };
0132 
0133   /// Constructor
0134   /// @param config is the configuration struct
0135   /// @param logger the local logging instance
0136   TGeoLayerBuilder(const Config& config,
0137                    std::unique_ptr<const Logger> logger =
0138                        getDefaultLogger("TGeoLayerBuilder", Logging::INFO));
0139 
0140   /// Destructor
0141   ~TGeoLayerBuilder() override;
0142 
0143   /// LayerBuilder interface method - returning the layers at negative side
0144   ///
0145   /// @param gctx the geometry context for this build call
0146   ///
0147   const LayerVector negativeLayers(const GeometryContext& gctx) const final;
0148 
0149   /// LayerBuilder interface method - returning the central layers
0150   ///
0151   /// @param gctx the geometry context for this build call
0152   ///
0153   const LayerVector centralLayers(const GeometryContext& gctx) const final;
0154 
0155   /// LayerBuilder interface method - returning the layers at negative side
0156   ///
0157   /// @param gctx the geometry context for this build call
0158   ///
0159   const LayerVector positiveLayers(const GeometryContext& gctx) const final;
0160 
0161   /// Name identification
0162   const std::string& identification() const final;
0163 
0164   /// Set the configuration object
0165   /// @param config is the configuration struct
0166   void setConfiguration(const Config& config);
0167 
0168   /// Get the configuration object
0169   Config getConfiguration() const;
0170 
0171   /// Set logging instance
0172   void setLogger(std::unique_ptr<const Logger> newLogger);
0173 
0174   /// Return the created detector elements
0175   const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
0176   detectorElements() const;
0177 
0178  private:
0179   /// Configuration object
0180   Config m_cfg;
0181 
0182   /// layer types
0183   std::array<std::string, 3> m_layerTypes = {"Negative", "Central", "Positive"};
0184 
0185   /// Private access to the logger
0186   const Logger& logger() const { return *m_logger; }
0187 
0188   /// Logging instance
0189   std::unique_ptr<const Logger> m_logger;
0190 
0191   /// @todo make clear where the TGeoDetectorElement lives
0192   std::vector<std::shared_ptr<const TGeoDetectorElement>> m_elementStore;
0193 
0194   /// Private helper method : build layers
0195   ///
0196   /// @param gctx the geometry context of this call
0197   /// @param layers is goint to be filled
0198   /// @param type is the indication which ones to build -1 | 0 | 1
0199   void buildLayers(const GeometryContext& gctx, LayerVector& layers,
0200                    int type = 0);
0201 
0202   /// Private helper method : register splitting input
0203   void registerSplit(std::vector<double>& parameters, double test,
0204                      double tolerance, std::pair<double, double>& range) const;
0205 };
0206 
0207 inline void TGeoLayerBuilder::registerSplit(
0208     std::vector<double>& parameters, double test, double tolerance,
0209     std::pair<double, double>& range) const {
0210   bool found = false;
0211   // min/max setting
0212   range.first = std::min(range.first, test);
0213   range.second = std::max(range.second, test);
0214   // Loop and find the split parameters
0215   for (auto& splitPar : parameters) {
0216     if (std::abs(test - splitPar) < tolerance) {
0217       found = true;
0218     }
0219   }
0220   if (!found) {
0221     parameters.push_back(test);
0222   }
0223 }
0224 
0225 inline TGeoLayerBuilder::Config TGeoLayerBuilder::getConfiguration() const {
0226   return m_cfg;
0227 }
0228 
0229 inline const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
0230 TGeoLayerBuilder::detectorElements() const {
0231   return m_elementStore;
0232 }
0233 
0234 inline const std::string& TGeoLayerBuilder::identification() const {
0235   return m_cfg.configurationName;
0236 }
0237 
0238 }  // namespace Acts