Warning, file /acts/Plugins/GeoModel/src/detail/GeoPolygonConverter.cpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsPlugins/GeoModel/detail/GeoPolygonConverter.hpp"
0010
0011 #include "Acts/Definitions/Common.hpp"
0012 #include "Acts/Definitions/Units.hpp"
0013 #include "Acts/Surfaces/DiamondBounds.hpp"
0014 #include "Acts/Surfaces/PlaneSurface.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/Surface.hpp"
0017 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0018 #include "Acts/Utilities/TransformHelpers.hpp"
0019 #include "ActsPlugins/GeoModel/GeoModelConversionError.hpp"
0020
0021 #include <algorithm>
0022
0023 #include <GeoModelKernel/GeoBox.h>
0024 #include <GeoModelKernel/GeoFullPhysVol.h>
0025 #include <GeoModelKernel/GeoLogVol.h>
0026 #include <GeoModelKernel/GeoShape.h>
0027 #include <GeoModelKernel/Units.h>
0028
0029 using namespace Acts;
0030
0031 Result<ActsPlugins::GeoModelSensitiveSurface>
0032 ActsPlugins::detail::GeoPolygonConverter::operator()(
0033 const PVConstLink& geoPV, const GeoSimplePolygonBrep& polygon,
0034 const Transform3& absTransform, SurfaceBoundFactory& boundFactory,
0035 bool sensitive) const {
0036
0037 static constexpr double unitLength =
0038 UnitConstants::mm / GeoModelKernelUnits::millimeter;
0039
0040
0041 const Transform3 transform = makeTransform3(
0042 absTransform.rotation(), unitLength * absTransform.translation());
0043
0044 int nVertices = polygon.getNVertices();
0045 std::vector<std::vector<double>> vertices;
0046
0047 for (int i = 0; i < nVertices; i++) {
0048 vertices.push_back({polygon.getXVertex(i), polygon.getYVertex(i)});
0049 }
0050
0051 std::ranges::sort(vertices, {}, [](const auto& v) { return v[1]; });
0052 if (nVertices == 4) {
0053 double hlxnegy = std::abs(vertices[0][0] - vertices[1][0]) / 2;
0054 double hlxposy = std::abs(vertices[2][0] - vertices[3][0]) / 2;
0055 double hly = std::abs(vertices[0][1] - vertices[3][1]) / 2;
0056 std::array<double, 3> halfLengths = {hlxnegy, hlxposy, hly};
0057
0058
0059 double halfXnegY = unitLength * halfLengths[0];
0060 double halfXposY = unitLength * halfLengths[1];
0061 double halfY = unitLength * halfLengths[2];
0062 auto trapBounds =
0063 boundFactory.makeBounds<TrapezoidBounds>(halfXnegY, halfXposY, halfY);
0064 if (!sensitive) {
0065 auto surface = Surface::makeShared<PlaneSurface>(transform, trapBounds);
0066 return std::make_tuple(nullptr, surface);
0067 }
0068
0069 auto detectorElement =
0070 GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0071 geoPV, trapBounds, transform, unitLength * polygon.getDZ());
0072 auto surface = detectorElement->surface().getSharedPtr();
0073
0074 return std::make_tuple(detectorElement, surface);
0075 } else if (nVertices == 6) {
0076 double hlxnegy = std::abs(vertices[0][0] - vertices[1][0]) / 2;
0077 double hlxzeroy = std::abs(vertices[2][0] - vertices[3][0]) / 2;
0078 double hlxposy = std::abs(vertices[4][0] - vertices[5][0]) / 2;
0079 double hly = std::abs(vertices[0][1] - vertices[4][1]) / 2;
0080 std::array<double, 5> halfLengths = {hlxnegy, hlxzeroy, hlxposy, hly, hly};
0081
0082
0083 double halfXnegY = unitLength * halfLengths[0];
0084 double halfXzeroY = unitLength * halfLengths[1];
0085 double halfXposY = unitLength * halfLengths[2];
0086 double halfYnegX = unitLength * halfLengths[3];
0087 double halfYposX = unitLength * halfLengths[4];
0088
0089 auto diamondBounds = boundFactory.makeBounds<DiamondBounds>(
0090 halfXnegY, halfXzeroY, halfXposY, halfYnegX, halfYposX);
0091 if (!sensitive) {
0092 auto surface =
0093 Surface::makeShared<PlaneSurface>(transform, diamondBounds);
0094 return std::make_tuple(nullptr, surface);
0095 }
0096
0097 auto detectorElement =
0098 GeoModelDetectorElement::createDetectorElement<PlaneSurface>(
0099 geoPV, diamondBounds, transform, unitLength * polygon.getDZ());
0100 auto surface = detectorElement->surface().getSharedPtr();
0101
0102 return std::make_tuple(detectorElement, surface);
0103 } else {
0104 throw std::runtime_error("GeoSimplePolygonBrep with " +
0105 std::to_string(nVertices) +
0106 " vertices can not be converted");
0107 }
0108 }