File indexing completed on 2025-01-18 09:27:43
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/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
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 class TGeoLayerBuilder : public ILayerBuilder {
0057 public:
0058
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
0066 std::string volumeName = "";
0067
0068 std::vector<std::string> sensorNames = {};
0069
0070 std::string localAxes = "XYZ";
0071
0072 std::vector<RangeConfig> parseRanges = {};
0073
0074 std::vector<SplitConfig> splitConfigs = {};
0075
0076 std::pair<double, double> envelope = {1 * UnitConstants::mm,
0077 1 * UnitConstants::mm};
0078
0079 std::vector<std::pair<int, BinningType>> binning0 = {{-1, equidistant}};
0080
0081 std::vector<std::pair<int, BinningType>> binning1 = {{-1, equidistant}};
0082
0083
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
0104
0105 struct Config {
0106
0107 std::string configurationName = "undefined";
0108
0109 double unit = 1 * UnitConstants::cm;
0110
0111 std::shared_ptr<const ITGeoIdentifierProvider> identifierProvider = nullptr;
0112
0113 std::shared_ptr<const ITGeoDetectorElementSplitter>
0114 detectorElementSplitter = nullptr;
0115
0116 ElementFactory elementFactory = defaultElementFactory;
0117
0118 std::shared_ptr<const LayerCreator> layerCreator = nullptr;
0119
0120 std::shared_ptr<const ProtoLayerHelper> protoLayerHelper = nullptr;
0121
0122 std::array<std::vector<LayerConfig>, 3> layerConfigurations;
0123
0124 std::array<double, 3> layerSplitToleranceR = {-1., -1., -1.};
0125
0126 std::array<double, 3> layerSplitToleranceZ = {-1., -1., -1.};
0127
0128 bool autoSurfaceBinning = false;
0129
0130 Acts::SurfaceBinningMatcher surfaceBinMatcher;
0131 };
0132
0133
0134
0135
0136 TGeoLayerBuilder(const Config& config,
0137 std::unique_ptr<const Logger> logger =
0138 getDefaultLogger("TGeoLayerBuilder", Logging::INFO));
0139
0140
0141 ~TGeoLayerBuilder() override;
0142
0143
0144
0145
0146
0147 const LayerVector negativeLayers(const GeometryContext& gctx) const final;
0148
0149
0150
0151
0152
0153 const LayerVector centralLayers(const GeometryContext& gctx) const final;
0154
0155
0156
0157
0158
0159 const LayerVector positiveLayers(const GeometryContext& gctx) const final;
0160
0161
0162 const std::string& identification() const final;
0163
0164
0165
0166 void setConfiguration(const Config& config);
0167
0168
0169 Config getConfiguration() const;
0170
0171
0172 void setLogger(std::unique_ptr<const Logger> newLogger);
0173
0174
0175 const std::vector<std::shared_ptr<const TGeoDetectorElement>>&
0176 detectorElements() const;
0177
0178 private:
0179
0180 Config m_cfg;
0181
0182
0183 std::array<std::string, 3> m_layerTypes = {"Negative", "Central", "Positive"};
0184
0185
0186 const Logger& logger() const { return *m_logger; }
0187
0188
0189 std::unique_ptr<const Logger> m_logger;
0190
0191
0192 std::vector<std::shared_ptr<const TGeoDetectorElement>> m_elementStore;
0193
0194
0195
0196
0197
0198
0199 void buildLayers(const GeometryContext& gctx, LayerVector& layers,
0200 int type = 0);
0201
0202
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
0212 range.first = std::min(range.first, test);
0213 range.second = std::max(range.second, test);
0214
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 }