File indexing completed on 2026-11-23 09:24:11
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/tools/old/interface.hpp>
0010 #include <boost/test/unit_test.hpp>
0011
0012 #include "Acts/Definitions/Algebra.hpp"
0013 #include "Acts/Geometry/CylinderLayer.hpp"
0014 #include "Acts/Geometry/DiscLayer.hpp"
0015 #include "Acts/Geometry/Extent.hpp"
0016 #include "Acts/Geometry/GeometryContext.hpp"
0017 #include "Acts/Geometry/LayerCreator.hpp"
0018 #include "Acts/Geometry/ProtoLayer.hpp"
0019 #include "Acts/Geometry/SurfaceArrayCreator.hpp"
0020 #include "Acts/Surfaces/CylinderBounds.hpp"
0021 #include "Acts/Surfaces/PlanarBounds.hpp"
0022 #include "Acts/Surfaces/PlaneSurface.hpp"
0023 #include "Acts/Surfaces/RadialBounds.hpp"
0024 #include "Acts/Surfaces/RectangleBounds.hpp"
0025 #include "Acts/Surfaces/Surface.hpp"
0026 #include "Acts/Surfaces/SurfaceArray.hpp"
0027 #include "Acts/Utilities/BinningType.hpp"
0028 #include "Acts/Utilities/IAxis.hpp"
0029 #include "Acts/Utilities/Logger.hpp"
0030 #include "ActsTests/CommonHelpers/FloatComparisons.hpp"
0031
0032 #include <cstddef>
0033 #include <fstream>
0034 #include <iomanip>
0035 #include <iostream>
0036 #include <memory>
0037 #include <numbers>
0038 #include <set>
0039 #include <string>
0040 #include <utility>
0041 #include <vector>
0042
0043 #include <boost/format.hpp>
0044
0045 using namespace Acts;
0046
0047 namespace ActsTests {
0048
0049
0050 GeometryContext tgContext = GeometryContext::dangerouslyDefaultConstruct();
0051
0052 using SrfVec = std::vector<std::shared_ptr<const Surface>>;
0053
0054 void draw_surfaces(const SrfVec& surfaces, const std::string& fname) {
0055 std::ofstream os;
0056 os.open(fname);
0057
0058 os << std::fixed << std::setprecision(4);
0059
0060 std::size_t nVtx = 0;
0061 for (const auto& srfx : surfaces) {
0062 std::shared_ptr<const PlaneSurface> srf =
0063 std::dynamic_pointer_cast<const PlaneSurface>(srfx);
0064 const PlanarBounds* bounds =
0065 dynamic_cast<const PlanarBounds*>(&srf->bounds());
0066
0067 for (const auto& vtxloc : bounds->vertices()) {
0068 Vector3 vtx = srf->localToGlobalTransform(tgContext) *
0069 Vector3(vtxloc.x(), vtxloc.y(), 0);
0070 os << "v " << vtx.x() << " " << vtx.y() << " " << vtx.z() << "\n";
0071 }
0072
0073
0074 os << "f";
0075 for (std::size_t i = 1; i <= bounds->vertices().size(); ++i) {
0076 os << " " << nVtx + i;
0077 }
0078 os << "\n";
0079
0080 nVtx += bounds->vertices().size();
0081 }
0082
0083 os.close();
0084 }
0085
0086 struct LayerCreatorFixture {
0087 std::shared_ptr<const SurfaceArrayCreator> p_SAC;
0088 std::shared_ptr<LayerCreator> p_LC;
0089
0090 std::vector<std::shared_ptr<const Surface>> m_surfaces;
0091
0092 LayerCreatorFixture() {
0093 p_SAC = std::make_shared<const SurfaceArrayCreator>(
0094 SurfaceArrayCreator::Config(),
0095 getDefaultLogger("SurfaceArrayCreator", Logging::VERBOSE));
0096 LayerCreator::Config cfg;
0097 cfg.surfaceArrayCreator = p_SAC;
0098 p_LC = std::make_shared<LayerCreator>(
0099 cfg, getDefaultLogger("LayerCreator", Logging::VERBOSE));
0100 }
0101
0102
0103
0104 bool checkBinContentSize(const SurfaceArray* sArray, std::size_t n) {
0105 std::size_t nBins = sArray->size();
0106 bool result = true;
0107 for (std::size_t i = 0; i < nBins; ++i) {
0108 if (!sArray->isValidBin(i)) {
0109 continue;
0110 }
0111 const std::span<const Surface* const> binContent = sArray->at(i);
0112 BOOST_TEST_INFO("Bin: " << i);
0113 BOOST_CHECK_GE(binContent.size(), n);
0114 result = result && binContent.size() >= n;
0115 }
0116
0117 return result;
0118 }
0119
0120 SrfVec fullPhiTestSurfacesEC(std::size_t n = 10, double shift = 0,
0121 double zbase = 0, double r = 10) {
0122 SrfVec res;
0123
0124 double phiStep = 2 * std::numbers::pi / n;
0125 for (std::size_t i = 0; i < n; ++i) {
0126 double z = zbase + ((i % 2 == 0) ? 1 : -1) * 0.2;
0127
0128 Transform3 trans;
0129 trans.setIdentity();
0130 trans.rotate(Eigen::AngleAxisd(i * phiStep + shift, Vector3(0, 0, 1)));
0131 trans.translate(Vector3(r, 0, z));
0132
0133 auto bounds = std::make_shared<const RectangleBounds>(2, 1);
0134 std::shared_ptr<PlaneSurface> srf =
0135 Surface::makeShared<PlaneSurface>(trans, bounds);
0136
0137 res.push_back(srf);
0138 m_surfaces.push_back(
0139 std::move(srf));
0140 }
0141
0142 return res;
0143 }
0144
0145 SrfVec fullPhiTestSurfacesBRL(int n = 10, double shift = 0, double zbase = 0,
0146 double incl = std::numbers::pi / 9.,
0147 double w = 2, double h = 1.5) {
0148 SrfVec res;
0149
0150 double phiStep = 2 * std::numbers::pi / n;
0151 for (int i = 0; i < n; ++i) {
0152 double z = zbase;
0153
0154 Transform3 trans;
0155 trans.setIdentity();
0156 trans.rotate(Eigen::AngleAxisd(i * phiStep + shift, Vector3(0, 0, 1)));
0157 trans.translate(Vector3(10, 0, z));
0158 trans.rotate(Eigen::AngleAxisd(incl, Vector3(0, 0, 1)));
0159 trans.rotate(Eigen::AngleAxisd(std::numbers::pi / 2., Vector3(0, 1, 0)));
0160
0161 auto bounds = std::make_shared<const RectangleBounds>(w, h);
0162 std::shared_ptr<PlaneSurface> srf =
0163 Surface::makeShared<PlaneSurface>(trans, bounds);
0164
0165 res.push_back(srf);
0166 m_surfaces.push_back(
0167 std::move(srf));
0168 }
0169
0170 return res;
0171 }
0172
0173 SrfVec makeBarrel(int nPhi, int nZ, double w, double h) {
0174 double z0 = -(nZ - 1) * w;
0175 SrfVec res;
0176
0177 for (int i = 0; i < nZ; i++) {
0178 double z = i * w * 2 + z0;
0179 std::cout << "z=" << z << std::endl;
0180 SrfVec ring =
0181 fullPhiTestSurfacesBRL(nPhi, 0, z, std::numbers::pi / 9., w, h);
0182 res.insert(res.end(), ring.begin(), ring.end());
0183 }
0184
0185 return res;
0186 }
0187
0188 std::pair<SrfVec, std::vector<std::pair<const Surface*, const Surface*>>>
0189 makeBarrelStagger(int nPhi, int nZ, double shift = 0,
0190 double incl = std::numbers::pi / 9., double w = 2,
0191 double h = 1.5) {
0192 double z0 = -(nZ - 1) * w;
0193 SrfVec res;
0194
0195 std::vector<std::pair<const Surface*, const Surface*>> pairs;
0196
0197 for (int i = 0; i < nZ; i++) {
0198 double z = i * w * 2 + z0;
0199
0200 double phiStep = 2 * std::numbers::pi / nPhi;
0201 for (int j = 0; j < nPhi; ++j) {
0202 Transform3 trans;
0203 trans.setIdentity();
0204 trans.rotate(Eigen::AngleAxisd(j * phiStep + shift, Vector3(0, 0, 1)));
0205 trans.translate(Vector3(10, 0, z));
0206 trans.rotate(Eigen::AngleAxisd(incl, Vector3(0, 0, 1)));
0207 trans.rotate(
0208 Eigen::AngleAxisd(std::numbers::pi / 2., Vector3(0, 1, 0)));
0209
0210 auto bounds = std::make_shared<const RectangleBounds>(w, h);
0211 std::shared_ptr<PlaneSurface> srfA =
0212 Surface::makeShared<PlaneSurface>(trans, bounds);
0213
0214 Vector3 nrm = srfA->normal(tgContext);
0215 Transform3 transB = trans;
0216 transB.pretranslate(nrm * 0.1);
0217 std::shared_ptr<PlaneSurface> srfB =
0218 Surface::makeShared<PlaneSurface>(transB, bounds);
0219
0220 pairs.push_back(std::make_pair(srfA.get(), srfB.get()));
0221
0222 res.push_back(srfA);
0223 res.push_back(srfB);
0224 m_surfaces.push_back(std::move(srfA));
0225 m_surfaces.push_back(std::move(srfB));
0226 }
0227 }
0228
0229 return {res, pairs};
0230 }
0231 };
0232
0233 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0234
0235 BOOST_FIXTURE_TEST_CASE(LayerCreator_createCylinderLayer, LayerCreatorFixture) {
0236 std::vector<std::shared_ptr<const Surface>> srf;
0237
0238 srf = makeBarrel(30, 7, 2, 1.5);
0239 draw_surfaces(srf, "LayerCreator_createCylinderLayer_BRL_1.obj");
0240
0241
0242 double envR = 0.1, envZ = 0.5;
0243 ProtoLayer pl(tgContext, srf);
0244 pl.envelope[AxisDirection::AxisR] = {envR, envR};
0245 pl.envelope[AxisDirection::AxisZ] = {envZ, envZ};
0246 std::shared_ptr<CylinderLayer> layer =
0247 std::dynamic_pointer_cast<CylinderLayer>(
0248 p_LC->cylinderLayer(tgContext, srf, equidistant, equidistant, pl));
0249
0250
0251 double rMax = 10.6071, rMin = 9.59111;
0252 CHECK_CLOSE_REL(layer->layerThickness(), (rMax - rMin) + 2. * envR, 1e-3);
0253
0254 const CylinderBounds* bounds = &layer->bounds();
0255 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eR), (rMax + rMin) / 2., 1e-3);
0256 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eHalfLengthZ), 14 + envZ, 1e-3);
0257 auto axes = layer->surfaceArray()->getAxes();
0258 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30u);
0259 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7u);
0260 CHECK_CLOSE_REL(axes.at(0)->getMin(), -std::numbers::pi, 1e-3);
0261 CHECK_CLOSE_REL(axes.at(0)->getMax(), std::numbers::pi, 1e-3);
0262 CHECK_CLOSE_REL(axes.at(1)->getMin(), -14, 1e-3);
0263 CHECK_CLOSE_REL(axes.at(1)->getMax(), 14, 1e-3);
0264
0265
0266
0267 ProtoLayer pl2(tgContext, srf);
0268 pl2.envelope[AxisDirection::AxisR] = {envR, envR};
0269 pl2.envelope[AxisDirection::AxisZ] = {envZ, envZ};
0270 layer = std::dynamic_pointer_cast<CylinderLayer>(
0271 p_LC->cylinderLayer(tgContext, srf, 30, 7, pl2));
0272 CHECK_CLOSE_REL(layer->layerThickness(), (rMax - rMin) + 2 * envR, 1e-3);
0273 bounds = &layer->bounds();
0274 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eR), (rMax + rMin) / 2., 1e-3);
0275 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eHalfLengthZ), 14 + envZ, 1e-3);
0276 axes = layer->surfaceArray()->getAxes();
0277 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30u);
0278 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7u);
0279 CHECK_CLOSE_REL(axes.at(0)->getMin(), -std::numbers::pi, 1e-3);
0280 CHECK_CLOSE_REL(axes.at(0)->getMax(), std::numbers::pi, 1e-3);
0281 CHECK_CLOSE_REL(axes.at(1)->getMin(), -14, 1e-3);
0282 CHECK_CLOSE_REL(axes.at(1)->getMax(), 14, 1e-3);
0283
0284 layer = std::dynamic_pointer_cast<CylinderLayer>(
0285 p_LC->cylinderLayer(tgContext, srf, 13, 3, pl2));
0286 CHECK_CLOSE_REL(layer->layerThickness(), (rMax - rMin) + 2 * envR, 1e-3);
0287 bounds = &layer->bounds();
0288 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eR), (rMax + rMin) / 2., 1e-3);
0289 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eHalfLengthZ), 14 + envZ, 1e-3);
0290 axes = layer->surfaceArray()->getAxes();
0291 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 13u);
0292 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 3u);
0293 CHECK_CLOSE_REL(axes.at(0)->getMin(), -std::numbers::pi, 1e-3);
0294 CHECK_CLOSE_REL(axes.at(0)->getMax(), std::numbers::pi, 1e-3);
0295 CHECK_CLOSE_REL(axes.at(1)->getMin(), -14, 1e-3);
0296 CHECK_CLOSE_REL(axes.at(1)->getMax(), 14, 1e-3);
0297
0298
0299 ProtoLayer pl3;
0300 pl3.extent.range(AxisDirection::AxisR).set(1, 20);
0301 pl3.extent.range(AxisDirection::AxisZ).set(-25, 25);
0302 layer = std::dynamic_pointer_cast<CylinderLayer>(
0303 p_LC->cylinderLayer(tgContext, srf, equidistant, equidistant, pl3));
0304 CHECK_CLOSE_REL(layer->layerThickness(), 19, 1e-3);
0305 bounds = &layer->bounds();
0306 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eR), 10.5, 1e-3);
0307 CHECK_CLOSE_REL(bounds->get(CylinderBounds::eHalfLengthZ), 25, 1e-3);
0308
0309 axes = layer->surfaceArray()->getAxes();
0310 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30u);
0311 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7u);
0312 CHECK_CLOSE_REL(axes.at(0)->getMin(), -std::numbers::pi, 1e-3);
0313 CHECK_CLOSE_REL(axes.at(0)->getMax(), std::numbers::pi, 1e-3);
0314 CHECK_CLOSE_REL(axes.at(1)->getMin(), -25, 1e-3);
0315 CHECK_CLOSE_REL(axes.at(1)->getMax(), 25, 1e-3);
0316 }
0317
0318 BOOST_FIXTURE_TEST_CASE(LayerCreator_createDiscLayer, LayerCreatorFixture) {
0319 std::vector<std::shared_ptr<const Surface>> surfaces;
0320 auto ringa = fullPhiTestSurfacesEC(30, 0, 0, 10);
0321 surfaces.insert(surfaces.end(), ringa.begin(), ringa.end());
0322 auto ringb = fullPhiTestSurfacesEC(30, 0, 0, 15);
0323 surfaces.insert(surfaces.end(), ringb.begin(), ringb.end());
0324 auto ringc = fullPhiTestSurfacesEC(30, 0, 0, 20);
0325 surfaces.insert(surfaces.end(), ringc.begin(), ringc.end());
0326 draw_surfaces(surfaces, "LayerCreator_createDiscLayer_EC_1.obj");
0327
0328 ProtoLayer pl(tgContext, surfaces);
0329 pl.extent.range(AxisDirection::AxisZ).set(-10, 10);
0330 pl.extent.range(AxisDirection::AxisR).set(5., 25.);
0331 std::shared_ptr<DiscLayer> layer = std::dynamic_pointer_cast<DiscLayer>(
0332 p_LC->discLayer(tgContext, surfaces, equidistant, equidistant, pl));
0333 CHECK_CLOSE_REL(layer->layerThickness(), 20, 1e-3);
0334 const RadialBounds* bounds =
0335 dynamic_cast<const RadialBounds*>(&layer->bounds());
0336 CHECK_CLOSE_REL(bounds->rMin(), 5, 1e-3);
0337 CHECK_CLOSE_REL(bounds->rMax(), 25, 1e-3);
0338 auto axes = layer->surfaceArray()->getAxes();
0339 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 3u);
0340 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 30u);
0341 CHECK_CLOSE_REL(axes.at(0)->getMin(), 5, 1e-3);
0342 CHECK_CLOSE_REL(axes.at(0)->getMax(), 25, 1e-3);
0343 CHECK_CLOSE_REL(axes.at(1)->getMin(), -std::numbers::pi, 1e-3);
0344 CHECK_CLOSE_REL(axes.at(1)->getMax(), std::numbers::pi, 1e-3);
0345 checkBinContentSize(layer->surfaceArray(), 1);
0346
0347
0348
0349
0350
0351
0352
0353 double envMinR = 1, envMaxR = 1, envZ = 5;
0354 std::size_t nBinsR = 3, nBinsPhi = 30;
0355 ProtoLayer pl2(tgContext, surfaces);
0356 pl2.envelope[AxisDirection::AxisR] = {envMinR, envMaxR};
0357 pl2.envelope[AxisDirection::AxisZ] = {envZ, envZ};
0358 layer = std::dynamic_pointer_cast<DiscLayer>(
0359 p_LC->discLayer(tgContext, surfaces, nBinsR, nBinsPhi, pl2));
0360
0361 double rMin = 8, rMax = 22.0227;
0362 CHECK_CLOSE_REL(layer->layerThickness(), 0.4 + 2 * envZ, 1e-3);
0363 bounds = dynamic_cast<const RadialBounds*>(&layer->bounds());
0364 CHECK_CLOSE_REL(bounds->rMin(), rMin - envMinR, 1e-3);
0365 CHECK_CLOSE_REL(bounds->rMax(), rMax + envMaxR, 1e-3);
0366 axes = layer->surfaceArray()->getAxes();
0367 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), nBinsR);
0368 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
0369 CHECK_CLOSE_REL(axes.at(0)->getMin(), rMin, 1e-3);
0370 CHECK_CLOSE_REL(axes.at(0)->getMax(), rMax, 1e-3);
0371 CHECK_CLOSE_REL(axes.at(1)->getMin(), -std::numbers::pi, 1e-3);
0372 CHECK_CLOSE_REL(axes.at(1)->getMax(), std::numbers::pi, 1e-3);
0373 checkBinContentSize(layer->surfaceArray(), 1);
0374
0375
0376
0377
0378
0379
0380
0381 layer = std::dynamic_pointer_cast<DiscLayer>(
0382 p_LC->discLayer(tgContext, surfaces, equidistant, equidistant, pl2));
0383 CHECK_CLOSE_REL(layer->layerThickness(), 0.4 + 2 * envZ, 1e-3);
0384 bounds = dynamic_cast<const RadialBounds*>(&layer->bounds());
0385 CHECK_CLOSE_REL(bounds->rMin(), rMin - envMinR, 1e-3);
0386 CHECK_CLOSE_REL(bounds->rMax(), rMax + envMaxR, 1e-3);
0387 axes = layer->surfaceArray()->getAxes();
0388 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), nBinsR);
0389 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), nBinsPhi);
0390 CHECK_CLOSE_REL(axes.at(0)->getMin(), rMin, 1e-3);
0391 CHECK_CLOSE_REL(axes.at(0)->getMax(), rMax, 1e-3);
0392 CHECK_CLOSE_REL(axes.at(1)->getMin(), -std::numbers::pi, 1e-3);
0393 CHECK_CLOSE_REL(axes.at(1)->getMax(), std::numbers::pi, 1e-3);
0394 checkBinContentSize(layer->surfaceArray(), 1);
0395
0396
0397
0398
0399
0400
0401 }
0402
0403 BOOST_FIXTURE_TEST_CASE(LayerCreator_barrelStagger, LayerCreatorFixture) {
0404 auto barrel = makeBarrelStagger(30, 7, 0, std::numbers::pi / 9.);
0405 auto brl = barrel.first;
0406 draw_surfaces(brl, "LayerCreator_barrelStagger.obj");
0407
0408 double envR = 0, envZ = 0;
0409 ProtoLayer pl(tgContext, brl);
0410 pl.envelope[AxisDirection::AxisR] = {envR, envR};
0411 pl.envelope[AxisDirection::AxisZ] = {envZ, envZ};
0412 std::shared_ptr<CylinderLayer> layer =
0413 std::dynamic_pointer_cast<CylinderLayer>(
0414 p_LC->cylinderLayer(tgContext, brl, equidistant, equidistant, pl));
0415
0416 auto axes = layer->surfaceArray()->getAxes();
0417 BOOST_CHECK_EQUAL(axes.at(0)->getNBins(), 30u);
0418 BOOST_CHECK_EQUAL(axes.at(1)->getNBins(), 7u);
0419
0420
0421 for (const auto& pr : barrel.second) {
0422 auto A = pr.first;
0423 auto B = pr.second;
0424
0425
0426
0427
0428
0429
0430 Vector3 ctr = A->referencePosition(tgContext, AxisDirection::AxisR);
0431 const std::span<const Surface* const> binContent =
0432 layer->surfaceArray()->at(tgContext, ctr, ctr.normalized());
0433
0434 std::set<const Surface*> exp({A, B});
0435 BOOST_CHECK(std::ranges::includes(binContent, exp));
0436 }
0437 }
0438
0439 BOOST_AUTO_TEST_SUITE_END()
0440
0441 }