File indexing completed on 2026-05-08 08:00:33
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Geometry/BlueprintBuilder.hpp"
0012 #include "Acts/Utilities/Logger.hpp"
0013 #include "ActsPlugins/Root/TGeoAxes.hpp"
0014 #include "ActsPlugins/Root/TGeoDetectorElement.hpp"
0015
0016 #include <functional>
0017 #include <memory>
0018 #include <optional>
0019 #include <span>
0020 #include <string>
0021 #include <string_view>
0022 #include <vector>
0023
0024 #include "TGeoMatrix.h"
0025
0026 class TGeoNode;
0027
0028 namespace ActsPlugins {
0029
0030
0031 class TGeoBlueprintBuilderBackend {
0032 public:
0033
0034 static constexpr std::string_view kIdentifier = "TGeoBlueprintBuilderBackend";
0035
0036
0037 struct NodeContext {
0038
0039 const TGeoNode* node = nullptr;
0040
0041 std::shared_ptr<const NodeContext> parent = nullptr;
0042 };
0043
0044
0045 struct Element {
0046
0047 std::shared_ptr<const NodeContext> context = nullptr;
0048
0049 friend bool operator==(const Element& lhs, const Element& rhs) {
0050 const NodeContext* lc = lhs.context.get();
0051 const NodeContext* rc = rhs.context.get();
0052
0053 while (lc != nullptr && rc != nullptr) {
0054 if (lc->node != rc->node) {
0055 return false;
0056 }
0057 lc = lc->parent.get();
0058 rc = rc->parent.get();
0059 }
0060
0061 return lc == nullptr && rc == nullptr;
0062 }
0063 };
0064
0065
0066 using AxisDefinition = TGeoAxes;
0067
0068 struct LayerSpec {
0069
0070 std::optional<AxisDefinition> axes;
0071
0072 std::optional<AxisDefinition> layerAxes;
0073
0074 std::optional<std::string> layerName;
0075 };
0076
0077
0078 using DetectorElement = TGeoDetectorElement;
0079
0080 using DetectorElementPtr = std::shared_ptr<DetectorElement>;
0081
0082 using DetectorElementFactory = std::function<DetectorElementPtr(
0083 const TGeoDetectorElement::Identifier&, const TGeoNode&,
0084 const TGeoMatrix&, AxisDefinition, double,
0085 std::shared_ptr<const Acts::ISurfaceMaterial>)>;
0086
0087 using ElementPredicate = std::function<bool(const Element&)>;
0088
0089 using IdentifierProvider =
0090 std::function<TGeoDetectorElement::Identifier(const Element&)>;
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 static DetectorElementPtr defaultElementFactory(
0101 const TGeoDetectorElement::Identifier& identifier,
0102 const TGeoNode& tGeoNode, const TGeoMatrix& tGeoMatrix,
0103 AxisDefinition axes, double lengthScale,
0104 std::shared_ptr<const Acts::ISurfaceMaterial> material);
0105
0106
0107 struct Config {
0108
0109 const TGeoNode* root = nullptr;
0110
0111 double lengthScale = 1.0;
0112
0113 DetectorElementFactory elementFactory = defaultElementFactory;
0114
0115 ElementPredicate sensitivePredicate = {};
0116
0117 IdentifierProvider identifierProvider = {};
0118 };
0119
0120
0121
0122
0123 explicit TGeoBlueprintBuilderBackend(const Config& cfg,
0124 const Acts::Logger& logger);
0125
0126
0127
0128
0129
0130 DetectorElementPtr createDetectorElement(const Element& element,
0131 AxisDefinition axes) const;
0132
0133
0134
0135
0136
0137 std::vector<std::shared_ptr<Acts::Surface>> makeSurfaces(
0138 std::span<const Element> sensitives, const LayerSpec& layerSpec) const;
0139
0140
0141
0142
0143
0144 std::optional<Acts::Transform3> lookupLayerTransform(
0145 const Element& element, const LayerSpec& layerSpec) const;
0146
0147
0148
0149 Element world() const;
0150
0151
0152
0153 std::string nameOf(const Element& element) const;
0154
0155
0156
0157 std::vector<Element> children(const Element& parent) const;
0158
0159
0160
0161 Element parent(const Element& element) const;
0162
0163
0164
0165
0166 bool isSensitive(const Element& element) const;
0167
0168
0169
0170
0171 const TGeoNode& nodeOf(const Element& element) const;
0172
0173
0174
0175 TGeoHMatrix transformOf(const Element& element) const;
0176
0177
0178
0179 std::string pathOf(const Element& element) const;
0180
0181
0182
0183 const Acts::Logger& logger() const { return *m_logger; }
0184
0185 private:
0186 const NodeContext& contextOf(const Element& element) const;
0187 Element makeElement(const TGeoNode& node,
0188 std::shared_ptr<const NodeContext> parent) const;
0189 TGeoDetectorElement::Identifier defaultIdentifierFor(
0190 const Element& element) const;
0191
0192 Config m_cfg;
0193 const Acts::Logger* m_logger = nullptr;
0194 Element m_world = {};
0195 mutable std::vector<DetectorElementPtr> m_detectorElementStore = {};
0196 };
0197
0198
0199 using BlueprintBuilder =
0200 Acts::Experimental::BlueprintBuilder<TGeoBlueprintBuilderBackend>;
0201
0202 using ElementLayerAssembler =
0203 Acts::Experimental::ElementLayerAssembler<TGeoBlueprintBuilderBackend>;
0204
0205 using SensorLayerAssembler =
0206 Acts::Experimental::SensorLayerAssembler<TGeoBlueprintBuilderBackend>;
0207
0208 using SensorLayer =
0209 Acts::Experimental::SensorLayer<TGeoBlueprintBuilderBackend>;
0210
0211 }
0212
0213 namespace Acts::Experimental {
0214 extern template class BlueprintBuilder<
0215 ActsPlugins::TGeoBlueprintBuilderBackend>;
0216 extern template class ElementLayerAssembler<
0217 ActsPlugins::TGeoBlueprintBuilderBackend>;
0218 extern template class SensorLayerAssembler<
0219 ActsPlugins::TGeoBlueprintBuilderBackend>;
0220 extern template class SensorLayer<ActsPlugins::TGeoBlueprintBuilderBackend>;
0221 }