Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:34

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/VolumeStructureBuilder.hpp"
0013 #include "Acts/Geometry/VolumeBounds.hpp"
0014 
0015 #include <memory>
0016 #include <vector>
0017 
0018 using namespace Acts;
0019 using namespace Acts::Experimental;
0020 
0021 GeometryContext tContext;
0022 
0023 BOOST_AUTO_TEST_SUITE(Detector)
0024 
0025 // Test misconfiguration exception
0026 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderMisconfigured) {
0027   VolumeStructureBuilder::Config misConfig;
0028 
0029   BOOST_CHECK_THROW(
0030       VolumeStructureBuilder builder1(
0031           misConfig, getDefaultLogger("Builder1", Logging::VERBOSE)),
0032       std::invalid_argument);
0033 
0034   misConfig.boundValues = {0., 1., 2., 3.};
0035   BOOST_CHECK_THROW(
0036       VolumeStructureBuilder builder2(
0037           misConfig, getDefaultLogger("Builder2", Logging::VERBOSE)),
0038       std::invalid_argument);
0039 }
0040 
0041 // Test the creation of conical bounds
0042 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCone) {
0043   // Conical volume from parameters
0044   VolumeStructureBuilder::Config coneValsConfig;
0045   coneValsConfig.boundValues = {0.2, -200., 0.3, -300., 100.};
0046   coneValsConfig.boundsType = VolumeBounds::BoundsType::eCone;
0047 
0048   VolumeStructureBuilder coneBuilderVals(
0049       coneValsConfig,
0050       getDefaultLogger("ConeStructureBuilderVals", Logging::VERBOSE));
0051 
0052   auto [transformVals, boundsVals, portalGeneratorVals] =
0053       coneBuilderVals.construct(tContext);
0054   BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
0055   BOOST_REQUIRE(boundsVals != nullptr);
0056   BOOST_CHECK_EQUAL(boundsVals->type(), VolumeBounds::BoundsType::eCone);
0057   BOOST_CHECK_EQUAL(boundsVals->values().size(), 7u);
0058   BOOST_CHECK_EQUAL(boundsVals->values().at(0u), 0.2);
0059   BOOST_CHECK_EQUAL(boundsVals->values().at(1u), -200.);
0060   BOOST_CHECK_EQUAL(boundsVals->values().at(2u), 0.3);
0061   BOOST_CHECK_EQUAL(boundsVals->values().at(3u), -300.);
0062   BOOST_CHECK_EQUAL(boundsVals->values().at(4u), 100.);
0063 
0064   // Misconfigured - values not complete
0065   VolumeStructureBuilder::Config coneMis1Config;
0066   coneMis1Config.boundValues = {100., 200.};
0067   coneMis1Config.boundsType = VolumeBounds::BoundsType::eCone;
0068 
0069   VolumeStructureBuilder coneBuilderMis1(
0070       coneMis1Config,
0071       getDefaultLogger("ConeStructureBuilderMis1", Logging::VERBOSE));
0072 
0073   BOOST_CHECK_THROW(coneBuilderMis1.construct(tContext), std::runtime_error);
0074 
0075   // Misconfigured - tried with extent
0076   VolumeStructureBuilder::Config coneMis2Config;
0077   coneMis2Config.extent = Extent{};
0078   coneMis2Config.boundsType = VolumeBounds::BoundsType::eCone;
0079 
0080   VolumeStructureBuilder coneBuilderMis2(
0081       coneMis2Config,
0082       getDefaultLogger("ConeStructureBuilderMis2", Logging::VERBOSE));
0083 
0084   BOOST_CHECK_THROW(coneBuilderMis2.construct(tContext), std::runtime_error);
0085 }
0086 
0087 // Test the creation of a cubic bounds
0088 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCuboid) {
0089   // Cuboid volume from parameters
0090   VolumeStructureBuilder::Config cuboidValsConfig;
0091   cuboidValsConfig.boundValues = {100., 200., 300.};
0092   cuboidValsConfig.boundsType = VolumeBounds::BoundsType::eCuboid;
0093 
0094   VolumeStructureBuilder cuboidBuilderVals(
0095       cuboidValsConfig,
0096       getDefaultLogger("CuboidStructureBuilderVals", Logging::VERBOSE));
0097 
0098   auto [transformVals, boundsVals, portalGeneratorVals] =
0099       cuboidBuilderVals.construct(tContext);
0100   BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
0101   BOOST_REQUIRE(boundsVals != nullptr);
0102   BOOST_CHECK_EQUAL(boundsVals->type(), VolumeBounds::BoundsType::eCuboid);
0103   BOOST_CHECK_EQUAL(boundsVals->values().size(), 3u);
0104   BOOST_CHECK_EQUAL(boundsVals->values().at(0u), 100.);
0105   BOOST_CHECK_EQUAL(boundsVals->values().at(1u), 200.);
0106   BOOST_CHECK_EQUAL(boundsVals->values().at(2u), 300.);
0107 
0108   // Cuboid volume from extent
0109   Extent cuboidExtent;
0110   cuboidExtent.set(AxisDirection::AxisX, -100, 100);
0111   cuboidExtent.set(AxisDirection::AxisY, -200, 200);
0112   cuboidExtent.set(AxisDirection::AxisZ, -300, 300);
0113 
0114   VolumeStructureBuilder::Config cuboidExtentConfig;
0115   cuboidExtentConfig.boundsType = VolumeBounds::BoundsType::eCuboid;
0116   cuboidExtentConfig.extent = cuboidExtent;
0117 
0118   VolumeStructureBuilder cuboidBuilderExtent(
0119       cuboidExtentConfig,
0120       getDefaultLogger("CuboidStructureBuilderExtent", Logging::VERBOSE));
0121 
0122   auto [transformExtent, boundsExtent, portalGeneratorExtent] =
0123       cuboidBuilderExtent.construct(tContext);
0124 
0125   BOOST_CHECK(transformExtent.isApprox(Transform3::Identity()));
0126   BOOST_REQUIRE(boundsExtent != nullptr);
0127   BOOST_CHECK_EQUAL(boundsExtent->type(), VolumeBounds::BoundsType::eCuboid);
0128   BOOST_CHECK_EQUAL(boundsExtent->values().size(), 3u);
0129   BOOST_CHECK_EQUAL(boundsExtent->values().at(0u), 100.);
0130   BOOST_CHECK_EQUAL(boundsExtent->values().at(1u), 200.);
0131   BOOST_CHECK_EQUAL(boundsExtent->values().at(2u), 300.);
0132 
0133   // Misconfigured - values not correct
0134   VolumeStructureBuilder::Config cuboidMis1Config;
0135   cuboidMis1Config.boundValues = {100., 200.};
0136   cuboidMis1Config.boundsType = VolumeBounds::BoundsType::eCuboid;
0137 
0138   VolumeStructureBuilder cuboidBuilderMis1(
0139       cuboidMis1Config,
0140       getDefaultLogger("CuboidStructureBuilderMis1", Logging::VERBOSE));
0141 
0142   BOOST_CHECK_THROW(cuboidBuilderMis1.construct(tContext), std::runtime_error);
0143 
0144   // Misconfigured - extent not correct
0145   VolumeStructureBuilder::Config cuboidMis2Config;
0146   cuboidMis2Config.extent = Extent{};
0147   cuboidMis2Config.boundsType = VolumeBounds::BoundsType::eCuboid;
0148 
0149   VolumeStructureBuilder cuboidBuilderMis2(
0150       cuboidMis2Config,
0151       getDefaultLogger("CuboidStructureBuilderMis2", Logging::VERBOSE));
0152 
0153   BOOST_CHECK_THROW(cuboidBuilderMis2.construct(tContext), std::runtime_error);
0154 }
0155 
0156 // Test the creation of cutout cylinder bounds
0157 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCutoutCylinder) {
0158   // Cutout Cylinder volume from parameters
0159   VolumeStructureBuilder::Config ccylValsConfig;
0160   ccylValsConfig.boundValues = {100, 120., 200, 300., 280.};
0161   ccylValsConfig.boundsType = VolumeBounds::BoundsType::eCutoutCylinder;
0162 
0163   VolumeStructureBuilder ccylBuilderVals(
0164       ccylValsConfig,
0165       getDefaultLogger("CutoutCylinderStructureBuilderVals", Logging::VERBOSE));
0166 
0167   auto [transformVals, boundsVals, portalGeneratorVals] =
0168       ccylBuilderVals.construct(tContext);
0169   BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
0170   BOOST_REQUIRE(boundsVals != nullptr);
0171   BOOST_CHECK_EQUAL(boundsVals->type(),
0172                     VolumeBounds::BoundsType::eCutoutCylinder);
0173   BOOST_CHECK_EQUAL(boundsVals->values().size(), 5u);
0174   BOOST_CHECK_EQUAL(boundsVals->values().at(0u), 100.);
0175   BOOST_CHECK_EQUAL(boundsVals->values().at(1u), 120.);
0176   BOOST_CHECK_EQUAL(boundsVals->values().at(2u), 200.);
0177   BOOST_CHECK_EQUAL(boundsVals->values().at(3u), 300.);
0178   BOOST_CHECK_EQUAL(boundsVals->values().at(4u), 280.);
0179 
0180   // Misconfigured - values not complete
0181   VolumeStructureBuilder::Config ccylMis1Config;
0182   ccylMis1Config.boundValues = {100., 200.};
0183   ccylMis1Config.boundsType = VolumeBounds::BoundsType::eCutoutCylinder;
0184 
0185   VolumeStructureBuilder ccylBuilderMis1(
0186       ccylMis1Config,
0187       getDefaultLogger("CutoutCylinderStructureBuilderMis1", Logging::VERBOSE));
0188 
0189   BOOST_CHECK_THROW(ccylBuilderMis1.construct(tContext), std::runtime_error);
0190 
0191   // Misconfigured - trying from extent
0192   VolumeStructureBuilder::Config ccylMis2Config;
0193   ccylMis2Config.extent = Extent{};
0194   ccylMis2Config.boundsType = VolumeBounds::BoundsType::eCutoutCylinder;
0195 
0196   VolumeStructureBuilder ccylBuilderMis2(
0197       ccylMis2Config,
0198       getDefaultLogger("CutoutCylinderStructureBuilderMis2", Logging::VERBOSE));
0199 
0200   BOOST_CHECK_THROW(ccylBuilderMis2.construct(tContext), std::runtime_error);
0201 }
0202 
0203 // Test the creation of cylindrical bounds
0204 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderCylinder) {
0205   // Cylinder volume from parameters
0206   VolumeStructureBuilder::Config cylValsConfig;
0207   cylValsConfig.boundValues = {100, 200, 400., 0.3, 0.};
0208   cylValsConfig.boundsType = VolumeBounds::BoundsType::eCylinder;
0209 
0210   VolumeStructureBuilder cylBuilderVals(
0211       cylValsConfig,
0212       getDefaultLogger("CylinderStructureBuilderVals", Logging::VERBOSE));
0213 
0214   auto [transformVals, boundsVals, portalGeneratorVals] =
0215       cylBuilderVals.construct(tContext);
0216   BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
0217   BOOST_REQUIRE(boundsVals != nullptr);
0218   BOOST_CHECK_EQUAL(boundsVals->type(), VolumeBounds::BoundsType::eCylinder);
0219   BOOST_CHECK_EQUAL(boundsVals->values().size(), 7u);
0220   BOOST_CHECK_EQUAL(boundsVals->values().at(0u), 100.);
0221   BOOST_CHECK_EQUAL(boundsVals->values().at(1u), 200.);
0222   BOOST_CHECK_EQUAL(boundsVals->values().at(2u), 400.);
0223   BOOST_CHECK_EQUAL(boundsVals->values().at(3u), 0.3);
0224 
0225   // Cylinder volume from extent
0226   Extent cylinderExtent;
0227   cylinderExtent.set(AxisDirection::AxisR, 100., 200.);
0228   cylinderExtent.set(AxisDirection::AxisZ, -800., 0.);
0229 
0230   VolumeStructureBuilder::Config cylExtentConfig;
0231   cylExtentConfig.extent = cylinderExtent;
0232   cylExtentConfig.boundsType = VolumeBounds::BoundsType::eCylinder;
0233 
0234   VolumeStructureBuilder cylBuilderExtent(
0235       cylExtentConfig,
0236       getDefaultLogger("CylinderStructureBuilderExtent", Logging::VERBOSE));
0237 
0238   auto [transformExtent, boundsExtent, portalGeneratorExtent] =
0239       cylBuilderExtent.construct(tContext);
0240 
0241   Transform3 shifted = Transform3::Identity();
0242   shifted.pretranslate(Vector3(0., 0., -400.));
0243 
0244   BOOST_CHECK(transformExtent.isApprox(shifted));
0245   BOOST_REQUIRE(boundsExtent != nullptr);
0246   BOOST_CHECK_EQUAL(boundsExtent->type(), VolumeBounds::BoundsType::eCylinder);
0247   BOOST_CHECK_EQUAL(boundsExtent->values().size(), 7u);
0248   BOOST_CHECK_EQUAL(boundsExtent->values().at(0u), 100.);
0249   BOOST_CHECK_EQUAL(boundsExtent->values().at(1u), 200.);
0250   BOOST_CHECK_EQUAL(boundsExtent->values().at(2u), 400.);
0251 
0252   // Misconfigured - values not complete
0253   VolumeStructureBuilder::Config cylMis1Config;
0254   cylMis1Config.boundValues = {100., 200.};
0255   cylMis1Config.boundsType = VolumeBounds::BoundsType::eCylinder;
0256 
0257   VolumeStructureBuilder cylBuilderMis1(
0258       cylMis1Config,
0259       getDefaultLogger("CylinderStructureBuilderMis1", Logging::VERBOSE));
0260 
0261   BOOST_CHECK_THROW(cylBuilderMis1.construct(tContext), std::runtime_error);
0262 
0263   // Misconfigured - trying from extent
0264   VolumeStructureBuilder::Config cylMis2Config;
0265   cylMis2Config.extent = Extent{};
0266   cylMis2Config.boundsType = VolumeBounds::BoundsType::eCylinder;
0267 
0268   VolumeStructureBuilder cylBuilderMis2(
0269       cylMis2Config,
0270       getDefaultLogger("CylinderStructureBuilderMis2", Logging::VERBOSE));
0271 
0272   BOOST_CHECK_THROW(cylBuilderMis2.construct(tContext), std::runtime_error);
0273 }
0274 
0275 // Test the creation of generic cuboid bounds
0276 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderGenericCuboid) {
0277   // Cuboid volume from parameters
0278   VolumeStructureBuilder::Config gcubValsConfig;
0279   gcubValsConfig.boundValues = {0, 0, 0, 2,   0, 0.4, 2,   1, 0.4, 0, 1, 0,
0280                                 0, 0, 1, 1.8, 0, 1,   1.8, 1, 1,   0, 1, 1};
0281   gcubValsConfig.boundsType = VolumeBounds::BoundsType::eGenericCuboid;
0282 
0283   VolumeStructureBuilder gcubBuilderVals(
0284       gcubValsConfig,
0285       getDefaultLogger("GenericCuboidStructureBuilderVals", Logging::VERBOSE));
0286 
0287   auto [transformVals, boundsVals, portalGeneratorVals] =
0288       gcubBuilderVals.construct(tContext);
0289   BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
0290   BOOST_REQUIRE(boundsVals != nullptr);
0291   BOOST_CHECK_EQUAL(boundsVals->type(),
0292                     VolumeBounds::BoundsType::eGenericCuboid);
0293   BOOST_CHECK_EQUAL(boundsVals->values().size(), 24u);
0294 
0295   // Misconfigured - values not complete
0296   VolumeStructureBuilder::Config gcubMis1Config;
0297   gcubMis1Config.boundsType = VolumeBounds::BoundsType::eGenericCuboid;
0298   gcubMis1Config.boundValues = {100.};
0299 
0300   VolumeStructureBuilder gcubBuilderMis1(
0301       gcubMis1Config,
0302       getDefaultLogger("GenericCuboidStructureBuilderMis1", Logging::VERBOSE));
0303 
0304   BOOST_CHECK_THROW(gcubBuilderMis1.construct(tContext), std::runtime_error);
0305 
0306   // Misconfigured - tried with extent
0307   VolumeStructureBuilder::Config gcubMis2Config;
0308   gcubMis2Config.boundsType = VolumeBounds::BoundsType::eGenericCuboid;
0309   gcubMis2Config.extent = Extent{};
0310 
0311   VolumeStructureBuilder gcubBuilderMis2(
0312       gcubMis2Config,
0313       getDefaultLogger("GenericCuboidStructureBuilderMis2", Logging::VERBOSE));
0314 }
0315 
0316 // Test the creation of the trapezoidal bounds
0317 BOOST_AUTO_TEST_CASE(VolumeStructureBuilderTrapezoid) {
0318   // Cuboid volume from parameters
0319   VolumeStructureBuilder::Config trapValsConfig;
0320   trapValsConfig.boundValues = {100., 200., 300., 10.};
0321   trapValsConfig.boundsType = VolumeBounds::BoundsType::eTrapezoid;
0322 
0323   VolumeStructureBuilder trapBuilderVals(
0324       trapValsConfig,
0325       getDefaultLogger("TrapezoidStructureBuilderVals", Logging::VERBOSE));
0326 
0327   auto [transformVals, boundsVals, portalGeneratorVals] =
0328       trapBuilderVals.construct(tContext);
0329   BOOST_CHECK(transformVals.isApprox(Transform3::Identity()));
0330   BOOST_REQUIRE(boundsVals != nullptr);
0331   BOOST_CHECK_EQUAL(boundsVals->type(), VolumeBounds::BoundsType::eTrapezoid);
0332   BOOST_CHECK_EQUAL(boundsVals->values().size(), 6u);
0333   BOOST_CHECK_EQUAL(boundsVals->values().at(0u), 100.);
0334   BOOST_CHECK_EQUAL(boundsVals->values().at(1u), 200.);
0335   BOOST_CHECK_EQUAL(boundsVals->values().at(2u), 300.);
0336   BOOST_CHECK_EQUAL(boundsVals->values().at(3u), 10.);
0337 
0338   // Misconfigured - values not complete
0339   VolumeStructureBuilder::Config trapMis1Config;
0340   trapMis1Config.boundsType = VolumeBounds::BoundsType::eTrapezoid;
0341   trapMis1Config.boundValues = {100., 200.};
0342 
0343   VolumeStructureBuilder trapBuilderMis1(
0344       trapMis1Config,
0345       getDefaultLogger("TrapezoidStructureBuilderMis1", Logging::VERBOSE));
0346 
0347   BOOST_CHECK_THROW(trapBuilderMis1.construct(tContext), std::runtime_error);
0348 
0349   // Misconfigured - tried with extent
0350   VolumeStructureBuilder::Config trapMis2Config;
0351   trapMis2Config.boundsType = VolumeBounds::BoundsType::eTrapezoid;
0352   trapMis2Config.extent = Extent{};
0353 
0354   VolumeStructureBuilder trapBuilderMis2(
0355       trapMis2Config,
0356       getDefaultLogger("TrapezoidStructureBuilderMis2", Logging::VERBOSE));
0357 }
0358 
0359 BOOST_AUTO_TEST_SUITE_END()