File indexing completed on 2025-07-15 08:13:14
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "Acts/Plugins/GeoModel/detail/GeoPolygonConverter.hpp"
0010
0011 #include "Acts/Definitions/Common.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Plugins/GeoModel/GeoModelConversionError.hpp"
0014 #include "Acts/Surfaces/DiamondBounds.hpp"
0015 #include "Acts/Surfaces/PlaneSurface.hpp"
0016 #include "Acts/Surfaces/RectangleBounds.hpp"
0017 #include "Acts/Surfaces/Surface.hpp"
0018 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0019
0020 #include <algorithm>
0021
0022 #include <GeoModelKernel/GeoBox.h>
0023 #include <GeoModelKernel/GeoFullPhysVol.h>
0024 #include <GeoModelKernel/GeoLogVol.h>
0025 #include <GeoModelKernel/GeoShape.h>
0026 #include <GeoModelKernel/Units.h>
0027
0028 Acts::Result<Acts::GeoModelSensitiveSurface>
0029 Acts::detail::GeoPolygonConverter::operator()(
0030 const PVConstLink& geoPV, const GeoSimplePolygonBrep& polygon,
0031 const Transform3& absTransform, SurfaceBoundFactory& boundFactory,
0032 bool sensitive) const {
0033
0034 static constexpr double unitLength =
0035 Acts::UnitConstants::mm / GeoModelKernelUnits::millimeter;
0036
0037
0038 Transform3 transform = Transform3::Identity();
0039 transform.translation() = unitLength * absTransform.translation();
0040 auto rotation = absTransform.rotation();
0041
0042 int nVertices = polygon.getNVertices();
0043 std::vector<std::vector<double>> vertices;
0044
0045 for (int i = 0; i < nVertices; i++) {
0046 vertices.push_back({polygon.getXVertex(i), polygon.getYVertex(i)});
0047 }
0048
0049 std::ranges::sort(vertices, {}, [](const auto& v) { return v[1]; });
0050 if (nVertices == 4) {
0051 double hlxnegy = std::abs(vertices[0][0] - vertices[1][0]) / 2;
0052 double hlxposy = std::abs(vertices[2][0] - vertices[3][0]) / 2;
0053 double hly = std::abs(vertices[0][1] - vertices[3][1]) / 2;
0054 std::vector<double> halfLengths = {hlxnegy, hlxposy, hly};
0055
0056
0057 Vector3 colX = rotation.col(0);
0058 Vector3 colY = rotation.col(1);
0059 Vector3 colZ = rotation.col(2);
0060 rotation.col(0) = colX;
0061 rotation.col(1) = colY;
0062 rotation.col(2) = colZ;
0063 transform.linear() = rotation;
0064
0065 double halfXnegY = unitLength * halfLengths[0];
0066 double halfXposY = unitLength * halfLengths[1];
0067 double halfY = unitLength * halfLengths[2];
0068 auto trapBounds = boundFactory.makeBounds<Acts::TrapezoidBounds>(
0069 halfXnegY, halfXposY, halfY);
0070 if (!sensitive) {
0071 auto surface = Surface::makeShared<PlaneSurface>(transform, trapBounds);
0072 return std::make_tuple(nullptr, surface);
0073 }
0074
0075 auto detectorElement =
0076 GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0077 geoPV, trapBounds, transform, unitLength * polygon.getDZ());
0078 auto surface = detectorElement->surface().getSharedPtr();
0079
0080 return std::make_tuple(detectorElement, surface);
0081 } else if (nVertices == 6) {
0082 double hlxnegy = std::abs(vertices[0][0] - vertices[1][0]) / 2;
0083 double hlxzeroy = std::abs(vertices[2][0] - vertices[3][0]) / 2;
0084 double hlxposy = std::abs(vertices[4][0] - vertices[5][0]) / 2;
0085 double hly = std::abs(vertices[0][1] - vertices[4][1]) / 2;
0086 std::vector<double> halfLengths = {hlxnegy, hlxzeroy, hlxposy, hly, hly};
0087
0088
0089
0090 Vector3 colX = rotation.col(0);
0091 Vector3 colY = rotation.col(1);
0092 Vector3 colZ = rotation.col(2);
0093 rotation.col(0) = colX;
0094 rotation.col(1) = colY;
0095 rotation.col(2) = colZ;
0096 transform.linear() = rotation;
0097
0098
0099 double halfXnegY = unitLength * halfLengths[0];
0100 double halfXzeroY = unitLength * halfLengths[1];
0101 double halfXposY = unitLength * halfLengths[2];
0102 double halfYnegX = unitLength * halfLengths[3];
0103 double halfYposX = unitLength * halfLengths[4];
0104
0105 auto diamondBounds = boundFactory.makeBounds<Acts::DiamondBounds>(
0106 halfXnegY, halfXzeroY, halfXposY, halfYnegX, halfYposX);
0107 if (!sensitive) {
0108 auto surface =
0109 Surface::makeShared<PlaneSurface>(transform, diamondBounds);
0110 return std::make_tuple(nullptr, surface);
0111 }
0112
0113 auto detectorElement =
0114 GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0115 geoPV, diamondBounds, transform, unitLength * polygon.getDZ());
0116 auto surface = detectorElement->surface().getSharedPtr();
0117
0118 return std::make_tuple(detectorElement, surface);
0119 } else {
0120 throw std::runtime_error("GeoSimplePolygonBrep with " +
0121 std::to_string(nVertices) +
0122 " vertices can not be converted");
0123 }
0124 }