File indexing completed on 2025-10-20 07:59:41
0001
0002
0003
0004
0005
0006
0007
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/Utilities/BinningType.hpp"
0019 #include "Acts/Utilities/Logger.hpp"
0020 #include "ActsPlugins/Root/ITGeoIdentifierProvider.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 class Surface;
0038 class ISurfaceMaterial;
0039 class ITGeoIdentifierProvider;
0040 class LayerCreator;
0041 class ProtoLayerHelper;
0042 }
0043
0044 namespace ActsPlugins {
0045
0046 class TGeoDetectorElement;
0047 class ITGeoDetectorElementSplitter;
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 class TGeoLayerBuilder : public Acts::ILayerBuilder {
0060 public:
0061
0062 struct LayerConfig {
0063 public:
0064 using RangeConfig =
0065 std::pair<Acts::AxisDirection, std::pair<double, double>>;
0066
0067
0068 using SplitConfig = std::pair<Acts::AxisDirection, double>;
0069
0070
0071
0072 std::string volumeName = "";
0073
0074 std::vector<std::string> sensorNames = {};
0075
0076 std::string localAxes = "XYZ";
0077
0078 std::vector<RangeConfig> parseRanges = {};
0079
0080 std::vector<SplitConfig> splitConfigs = {};
0081
0082 std::pair<double, double> envelope = {1 * Acts::UnitConstants::mm,
0083 1 * Acts::UnitConstants::mm};
0084
0085 std::vector<std::pair<int, Acts::BinningType>> binning0 = {
0086 {-1, Acts::equidistant}};
0087
0088 std::vector<std::pair<int, Acts::BinningType>> binning1 = {
0089 {-1, Acts::equidistant}};
0090
0091
0092 LayerConfig() = default;
0093 };
0094
0095
0096 using ElementFactory = std::function<std::shared_ptr<TGeoDetectorElement>(
0097 const TGeoDetectorElement::Identifier&, const TGeoNode&,
0098 const TGeoMatrix& tGeoMatrix, const std::string& axes, double scalor,
0099 std::shared_ptr<const Acts::ISurfaceMaterial> material)>;
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 static std::shared_ptr<TGeoDetectorElement> defaultElementFactory(
0110 const TGeoDetectorElement::Identifier& identifier,
0111 const TGeoNode& tGeoNode, const TGeoMatrix& tGeoMatrix,
0112 const std::string& axes, double scalor,
0113 std::shared_ptr<const Acts::ISurfaceMaterial> material);
0114
0115
0116
0117 struct Config {
0118
0119 std::string configurationName = "undefined";
0120
0121 double unit = 1 * Acts::UnitConstants::cm;
0122
0123 std::shared_ptr<const ITGeoIdentifierProvider> identifierProvider = nullptr;
0124
0125 std::shared_ptr<const ITGeoDetectorElementSplitter>
0126 detectorElementSplitter = nullptr;
0127
0128 ElementFactory detectorElementFactory = defaultElementFactory;
0129
0130 std::shared_ptr<const Acts::LayerCreator> layerCreator = nullptr;
0131
0132 std::shared_ptr<const Acts::ProtoLayerHelper> protoLayerHelper = nullptr;
0133
0134 std::array<std::vector<LayerConfig>, 3> layerConfigurations;
0135
0136 std::array<double, 3> layerSplitToleranceR = {-1., -1., -1.};
0137
0138 std::array<double, 3> layerSplitToleranceZ = {-1., -1., -1.};
0139
0140 bool autoSurfaceBinning = false;
0141
0142 Acts::SurfaceBinningMatcher surfaceBinMatcher;
0143 };
0144
0145
0146
0147
0148 explicit TGeoLayerBuilder(const Config& config,
0149 std::unique_ptr<const Acts::Logger> logger =
0150 Acts::getDefaultLogger("TGeoLayerBuilder",
0151 Acts::Logging::INFO));
0152
0153
0154 ~TGeoLayerBuilder() override;
0155
0156
0157
0158
0159
0160
0161 const Acts::LayerVector negativeLayers(
0162 const Acts::GeometryContext& gctx) const final;
0163
0164
0165
0166
0167
0168
0169 const Acts::LayerVector centralLayers(
0170 const Acts::GeometryContext& gctx) const final;
0171
0172
0173
0174
0175
0176
0177 const Acts::LayerVector positiveLayers(
0178 const Acts::GeometryContext& gctx) const final;
0179
0180
0181
0182 const std::string& identification() const final;
0183
0184
0185
0186 void setConfiguration(const Config& config);
0187
0188
0189
0190 Config getConfiguration() const;
0191
0192
0193
0194 void setLogger(std::unique_ptr<const Acts::Logger> newLogger);
0195
0196
0197
0198 const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
0199 detectorElements() const;
0200
0201 private:
0202
0203 Config m_cfg;
0204
0205
0206 std::array<std::string, 3> m_layerTypes = {"Negative", "Central", "Positive"};
0207
0208
0209 const Acts::Logger& logger() const { return *m_logger; }
0210
0211
0212 std::unique_ptr<const Acts::Logger> m_logger;
0213
0214
0215 std::vector<std::shared_ptr<const TGeoDetectorElement>> m_elementStore;
0216
0217
0218
0219
0220
0221
0222 void buildLayers(const Acts::GeometryContext& gctx, Acts::LayerVector& layers,
0223 int type = 0);
0224
0225
0226 void registerSplit(std::vector<double>& parameters, double test,
0227 double tolerance, std::pair<double, double>& range) const;
0228 };
0229
0230 inline void TGeoLayerBuilder::registerSplit(
0231 std::vector<double>& parameters, double test, double tolerance,
0232 std::pair<double, double>& range) const {
0233 bool found = false;
0234
0235 range.first = std::min(range.first, test);
0236 range.second = std::max(range.second, test);
0237
0238 for (const auto& splitPar : parameters) {
0239 if (std::abs(test - splitPar) < tolerance) {
0240 found = true;
0241 }
0242 }
0243 if (!found) {
0244 parameters.push_back(test);
0245 }
0246 }
0247
0248 inline TGeoLayerBuilder::Config TGeoLayerBuilder::getConfiguration() const {
0249 return m_cfg;
0250 }
0251
0252 inline const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
0253 TGeoLayerBuilder::detectorElements() const {
0254 return m_elementStore;
0255 }
0256
0257 inline const std::string& TGeoLayerBuilder::identification() const {
0258 return m_cfg.configurationName;
0259 }
0260
0261 }