File indexing completed on 2025-10-13 08:19:44
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Geometry/DiscLayer.hpp"
0012 #include "Acts/Geometry/GeometryContext.hpp"
0013 #include "Acts/Geometry/GeometryHierarchyMap.hpp"
0014 #include "Acts/Geometry/Layer.hpp"
0015 #include "Acts/Geometry/LayerCreator.hpp"
0016 #include "Acts/Geometry/SurfaceArrayCreator.hpp"
0017 #include "Acts/Surfaces/DiscSurface.hpp"
0018 #include "Acts/Surfaces/PlaneSurface.hpp"
0019 #include "Acts/Surfaces/RadialBounds.hpp"
0020 #include "Acts/Surfaces/TrapezoidBounds.hpp"
0021 #include "ActsPlugins/ActSVG/LayerSvgConverter.hpp"
0022 #include "ActsPlugins/ActSVG/SvgUtils.hpp"
0023 #include "ActsTests/CommonHelpers/CylindricalTrackingGeometry.hpp"
0024
0025 #include <fstream>
0026 #include <memory>
0027 #include <numbers>
0028 #include <vector>
0029
0030 using namespace Acts;
0031 using namespace ActsPlugins;
0032
0033 namespace ActsTests {
0034
0035 GeometryContext tgContext;
0036
0037 std::shared_ptr<const LayerCreator> lCreator(nullptr);
0038
0039 void setupTools() {
0040 if (lCreator == nullptr) {
0041 LayerCreator::Config lCreatorCfg;
0042 lCreatorCfg.surfaceArrayCreator =
0043 std::make_shared<const SurfaceArrayCreator>();
0044 lCreator = std::make_shared<const LayerCreator>(lCreatorCfg);
0045 }
0046 }
0047
0048 std::shared_ptr<Layer> generateDiscLayer(double rInner, double rOuter,
0049 unsigned int quarterSegments,
0050 unsigned int nRings,
0051 bool useTrapezoids = false) {
0052
0053 setupTools();
0054 unsigned int fullSegments = 4 * quarterSegments;
0055 std::vector<std::shared_ptr<const Surface>> moduleSurfaces;
0056 double phiStep = 2 * std::numbers::pi / fullSegments;
0057 double rStep = (rOuter - rInner) / nRings;
0058
0059 moduleSurfaces.reserve(fullSegments * nRings);
0060
0061 if (!useTrapezoids) {
0062 for (unsigned int ir = 0; ir < nRings; ++ir) {
0063 std::shared_ptr<const RadialBounds> rBounds = nullptr;
0064 rBounds = std::make_shared<RadialBounds>(
0065 rInner + ir * rStep - 0.025 * rInner,
0066 rInner + (ir + 1u) * rStep + 0.025 * rInner, 0.55 * phiStep, 0.);
0067 for (unsigned int is = 0; is < fullSegments; ++is) {
0068
0069 auto placement = Transform3::Identity();
0070 if ((is % 2) != 0u) {
0071 placement.pretranslate(Vector3{0., 0., 2.});
0072 }
0073 placement.rotate(Eigen::AngleAxisd(is * phiStep, Vector3(0, 0, 1)));
0074 auto dModule = Surface::makeShared<DiscSurface>(placement, rBounds);
0075 moduleSurfaces.push_back(dModule);
0076 }
0077 }
0078 } else {
0079 for (unsigned int ir = 0; ir < nRings; ++ir) {
0080
0081 double radius = rInner + (ir + 0.5) * rStep;
0082 double yHalf = rStep * 0.5125;
0083
0084 double xHalfMin =
0085 1.15 * (rInner + ir * rStep) * std::numbers::pi / fullSegments;
0086 double xHalfMax =
0087 1.15 * (rInner + (ir + 1) * rStep) * std::numbers::pi / fullSegments;
0088
0089 std::shared_ptr<const TrapezoidBounds> tBounds =
0090 std::make_shared<const TrapezoidBounds>(xHalfMin, xHalfMax, yHalf);
0091 for (unsigned int is = 0; is < fullSegments; ++is) {
0092
0093 double cphi = -std::numbers::pi + is * phiStep;
0094 Vector3 center(radius * std::cos(cphi), radius * std::sin(cphi),
0095 (is % 2) * 2 + (ir % 2) * 5);
0096
0097 Vector3 localY(std::cos(cphi), std::sin(cphi), 0.);
0098 Vector3 localZ(0., 0., 1.);
0099 Vector3 localX = localY.cross(localZ);
0100 RotationMatrix3 rotation;
0101 rotation.col(0) = localX;
0102 rotation.col(1) = localY;
0103 rotation.col(2) = localZ;
0104 Transform3 placement(Translation3(center) * rotation);
0105
0106 auto dModule = Surface::makeShared<PlaneSurface>(placement, tBounds);
0107 moduleSurfaces.push_back(dModule);
0108 }
0109 }
0110 }
0111
0112 return lCreator->discLayer(tgContext, moduleSurfaces, nRings, fullSegments);
0113 }
0114
0115 BOOST_AUTO_TEST_SUITE(ActSvgSuite)
0116
0117 BOOST_AUTO_TEST_CASE(DiscLayerRadialSvg) {
0118
0119 Svg::Style discLayerStyle;
0120 discLayerStyle.fillColor = {51, 153, 255};
0121 discLayerStyle.fillOpacity = 0.75;
0122 discLayerStyle.highlightColor = {255, 153, 51};
0123 discLayerStyle.highlights = {"mouseover", "mouseout"};
0124 discLayerStyle.strokeColor = {25, 25, 25};
0125 discLayerStyle.strokeWidth = 0.5;
0126 discLayerStyle.quarterSegments = 72u;
0127
0128 GeometryIdentifier geoID{0};
0129
0130
0131 auto discLayer = generateDiscLayer(100, 250, 32u, 4u);
0132
0133 Svg::LayerConverter::Options lOptions;
0134 lOptions.name = "disc_layer_sectors";
0135 lOptions.surfaceStyles =
0136 GeometryHierarchyMap<Svg::Style>({{geoID, discLayerStyle}});
0137
0138
0139 auto discLayerSheets =
0140 Svg::LayerConverter::convert(tgContext, *discLayer, lOptions);
0141
0142 for (const auto& s : discLayerSheets) {
0143 Svg::toFile({s}, s._id + ".svg");
0144 }
0145 }
0146
0147 BOOST_AUTO_TEST_CASE(DiscLayerTrapezoidSvg) {
0148
0149 Svg::Style discLayerStyle;
0150 discLayerStyle.fillColor = {51, 153, 255};
0151 discLayerStyle.fillOpacity = 0.75;
0152 discLayerStyle.highlightColor = {255, 153, 51};
0153 discLayerStyle.highlights = {"mouseover", "mouseout"};
0154 discLayerStyle.strokeColor = {25, 25, 25};
0155 discLayerStyle.strokeWidth = 0.5;
0156 discLayerStyle.quarterSegments = 72u;
0157
0158 GeometryIdentifier geoID{0};
0159
0160
0161 auto discLayer = generateDiscLayer(100, 250, 32u, 4u, true);
0162
0163 Svg::LayerConverter::Options lOptions;
0164 lOptions.name = "disc_layer_trapezoid";
0165 lOptions.surfaceStyles =
0166 GeometryHierarchyMap<Svg::Style>({{geoID, discLayerStyle}});
0167
0168
0169 auto discLayerSheets =
0170 Svg::LayerConverter::convert(tgContext, *discLayer, lOptions);
0171
0172 for (const auto& s : discLayerSheets) {
0173 Svg::toFile({s}, s._id + ".svg");
0174 }
0175 }
0176
0177 BOOST_AUTO_TEST_CASE(CylinderLayerSvg) {
0178
0179 Svg::Style cylinderLayerStyle;
0180 cylinderLayerStyle.fillColor = {51, 153, 255};
0181 cylinderLayerStyle.fillOpacity = 0.75;
0182 cylinderLayerStyle.highlightColor = {255, 153, 51};
0183 cylinderLayerStyle.highlights = {"mouseover", "mouseout"};
0184 cylinderLayerStyle.strokeColor = {25, 25, 25};
0185 cylinderLayerStyle.strokeWidth = 0.5;
0186 cylinderLayerStyle.quarterSegments = 72u;
0187
0188 GeometryIdentifier geoID{0};
0189
0190 CylindricalTrackingGeometry cGeometry(tgContext);
0191 auto tGeometry = cGeometry();
0192 auto pixelVolume =
0193 tGeometry->lowestTrackingVolume(tgContext, Vector3(50., 0., 0.));
0194 if (pixelVolume != nullptr && pixelVolume->confinedLayers() != nullptr) {
0195 auto layers = pixelVolume->confinedLayers()->arrayObjects();
0196 std::size_t il = 0;
0197 for (const auto& layer : layers) {
0198 if (layer->surfaceArray() == nullptr) {
0199 continue;
0200 }
0201
0202 Svg::LayerConverter::Options lOptions;
0203 lOptions.name = "cylinder_layer_" + std::to_string(il++);
0204 lOptions.surfaceStyles =
0205 GeometryHierarchyMap<Svg::Style>({{geoID, cylinderLayerStyle}});
0206
0207
0208 auto layerSheets =
0209 Svg::LayerConverter::convert(tgContext, *layer, lOptions);
0210 for (const auto& s : layerSheets) {
0211 Svg::toFile({s}, s._id + ".svg");
0212 }
0213 }
0214 }
0215 }
0216
0217 BOOST_AUTO_TEST_CASE(PlaeyLayerSvg) {}
0218
0219 BOOST_AUTO_TEST_SUITE_END()
0220
0221 }