File indexing completed on 2025-01-18 09:11:23
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Geometry/LayerBlueprintNode.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0013 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0014 #include "Acts/Geometry/ProtoLayer.hpp"
0015 #include "Acts/Geometry/VolumeBounds.hpp"
0016 #include "Acts/Utilities/GraphViz.hpp"
0017
0018 namespace Acts {
0019
0020 Volume& LayerBlueprintNode::build(const BlueprintOptions& options,
0021 const GeometryContext& gctx,
0022 const Logger& logger) {
0023 if (m_surfaces.empty()) {
0024 ACTS_ERROR("LayerBlueprintNode: no surfaces provided");
0025 throw std::invalid_argument("LayerBlueprintNode: no surfaces provided");
0026 }
0027
0028 ACTS_DEBUG(prefix() << "Building Layer " << name() << " from "
0029 << m_surfaces.size() << " surfaces");
0030 ACTS_VERBOSE(prefix() << " -> layer type: " << m_layerType);
0031 ACTS_VERBOSE(prefix() << " -> transform:\n" << m_transform.matrix());
0032
0033 Extent extent;
0034
0035 ProtoLayer protoLayer{gctx, m_surfaces, m_transform.inverse()};
0036 ACTS_VERBOSE(prefix() << "Built proto layer: " << protoLayer);
0037
0038 extent.addConstrain(protoLayer.extent, m_envelope);
0039
0040 ACTS_VERBOSE(prefix() << " -> layer extent: " << extent);
0041
0042 buildVolume(extent, logger);
0043 assert(m_volume != nullptr && "Volume not built from proto layer");
0044
0045 for (auto& surface : m_surfaces) {
0046 m_volume->addSurface(surface);
0047 }
0048
0049 return StaticBlueprintNode::build(options, gctx, logger);
0050 }
0051
0052 void LayerBlueprintNode::buildVolume(const Extent& extent,
0053 const Logger& logger) {
0054 ACTS_VERBOSE(prefix() << "Building volume for layer " << name());
0055 using enum AxisDirection;
0056 using enum LayerType;
0057
0058 std::shared_ptr<VolumeBounds> bounds;
0059 switch (m_layerType) {
0060 case Cylinder:
0061 case Disc: {
0062 double minR = extent.min(AxisR);
0063 double maxR = extent.max(AxisR);
0064 double hlZ = extent.interval(AxisZ) / 2.0;
0065 bounds = std::make_shared<CylinderVolumeBounds>(minR, maxR, hlZ);
0066 break;
0067 }
0068 case Plane: {
0069 double hlX = extent.interval(AxisX) / 2.0;
0070 double hlY = extent.interval(AxisY) / 2.0;
0071 double hlZ = extent.interval(AxisZ) / 2.0;
0072 bounds = std::make_shared<CuboidVolumeBounds>(hlX, hlY, hlZ);
0073 break;
0074 }
0075 }
0076
0077 assert(bounds != nullptr);
0078
0079 ACTS_VERBOSE(prefix() << " -> bounds: " << *bounds);
0080
0081 Transform3 transform = m_transform;
0082 transform.translation() =
0083 Vector3{extent.medium(AxisX), extent.medium(AxisY), extent.medium(AxisZ)};
0084
0085 ACTS_VERBOSE(prefix() << " -> adjusted transform:\n" << transform.matrix());
0086
0087 m_volume =
0088 std::make_unique<TrackingVolume>(transform, std::move(bounds), m_name);
0089 }
0090
0091 const std::string& LayerBlueprintNode::name() const {
0092 return m_name;
0093 }
0094
0095 LayerBlueprintNode& LayerBlueprintNode::setSurfaces(
0096 std::vector<std::shared_ptr<Surface>> surfaces) {
0097 m_surfaces = std::move(surfaces);
0098 return *this;
0099 }
0100
0101 const std::vector<std::shared_ptr<Surface>>& LayerBlueprintNode::surfaces()
0102 const {
0103 return m_surfaces;
0104 }
0105
0106 LayerBlueprintNode& LayerBlueprintNode::setTransform(
0107 const Transform3& transform) {
0108 m_transform = transform;
0109 return *this;
0110 }
0111
0112 const Transform3& LayerBlueprintNode::transform() const {
0113 return m_transform;
0114 }
0115
0116 LayerBlueprintNode& LayerBlueprintNode::setEnvelope(
0117 const ExtentEnvelope& envelope) {
0118 m_envelope = envelope;
0119 return *this;
0120 }
0121
0122 const ExtentEnvelope& LayerBlueprintNode::envelope() const {
0123 return m_envelope;
0124 }
0125
0126 LayerBlueprintNode& LayerBlueprintNode::setLayerType(LayerType layerType) {
0127 m_layerType = layerType;
0128 return *this;
0129 }
0130
0131 const LayerBlueprintNode::LayerType& LayerBlueprintNode::layerType() const {
0132 return m_layerType;
0133 }
0134
0135 void LayerBlueprintNode::addToGraphviz(std::ostream& os) const {
0136 std::stringstream ss;
0137 ss << "<b>" << name() << "</b>";
0138 ss << "<br/>";
0139 ss << m_layerType;
0140
0141 GraphViz::Node node{
0142 .id = name(), .label = ss.str(), .shape = GraphViz::Shape::Diamond};
0143
0144 os << node;
0145
0146 BlueprintNode::addToGraphviz(os);
0147 }
0148
0149 }