File indexing completed on 2025-01-18 09:12:31
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Detector/Blueprint.hpp"
0012 #include "Acts/Detector/detail/BlueprintDrawer.hpp"
0013 #include "Acts/Detector/detail/BlueprintHelper.hpp"
0014
0015 #include <exception>
0016 #include <fstream>
0017
0018 namespace Acts::Experimental {
0019 class IInternalStructureBuilder {};
0020 }
0021
0022 BOOST_AUTO_TEST_SUITE(Experimental)
0023
0024 BOOST_AUTO_TEST_CASE(BlueprintHelperSorting) {
0025
0026 std::vector<Acts::AxisDirection> detectorBinning = {
0027 Acts::AxisDirection::AxisR};
0028 std::vector<double> detectorBoundaries = {0., 50., 100.};
0029 auto detector = std::make_unique<Acts::Experimental::Blueprint::Node>(
0030 "detector", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0031 detectorBoundaries, detectorBinning);
0032
0033 BOOST_CHECK_EQUAL(detector->parent, nullptr);
0034 BOOST_CHECK(detector->children.empty());
0035 BOOST_CHECK_EQUAL(detector->name, "detector");
0036
0037 std::vector<Acts::AxisDirection> pixelsBinning = {Acts::AxisDirection::AxisZ};
0038 std::vector<double> pixelsBoundaries = {20., 50., 100.};
0039
0040 auto pixels = std::make_unique<Acts::Experimental::Blueprint::Node>(
0041 "pixels", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0042 pixelsBoundaries, pixelsBinning);
0043
0044 std::vector<double> beamPipeBoundaries = {0., 20., 100.};
0045 auto beamPipe = std::make_unique<Acts::Experimental::Blueprint::Node>(
0046 "beam_pipe", Acts::Transform3::Identity(), Acts::VolumeBounds::eOther,
0047 beamPipeBoundaries);
0048
0049 std::vector<double> gapBoundaries = {20., 50., 10.};
0050 auto gap0 = std::make_unique<Acts::Experimental::Blueprint::Node>(
0051 "gap0", Acts::Transform3::Identity() * Acts::Translation3(0., 0., -90.),
0052 Acts::VolumeBounds::eCylinder, gapBoundaries);
0053
0054 std::vector<double> layerBoundaries = {20., 50., 80.};
0055 auto layer = std::make_unique<Acts::Experimental::Blueprint::Node>(
0056 "layer", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0057 layerBoundaries,
0058 std::make_shared<Acts::Experimental::IInternalStructureBuilder>());
0059
0060 auto gap1 = std::make_unique<Acts::Experimental::Blueprint::Node>(
0061 "gap1", Acts::Transform3::Identity() * Acts::Translation3(0., 0., 90.),
0062 Acts::VolumeBounds::eCylinder, gapBoundaries);
0063
0064
0065 pixels->add(std::move(gap1));
0066 pixels->add(std::move(gap0));
0067 pixels->add(std::move(layer));
0068
0069 detector->add(std::move(pixels));
0070 detector->add(std::move(beamPipe));
0071
0072 std::ofstream fs("detector_unordered.dot");
0073 Acts::Experimental::detail::BlueprintDrawer::dotStream(fs, *detector);
0074 fs.close();
0075
0076
0077 Acts::Experimental::detail::BlueprintHelper::sort(*detector);
0078
0079
0080 BOOST_CHECK_EQUAL(detector->children.front()->name, "beam_pipe");
0081 BOOST_CHECK_EQUAL(detector->children.back()->name, "pixels");
0082 BOOST_CHECK_EQUAL(detector->children.back()->children.front()->name, "gap0");
0083 BOOST_CHECK_EQUAL(detector->children.back()->children[1u]->name, "layer");
0084 BOOST_CHECK_EQUAL(detector->children.back()->children.back()->name, "gap1");
0085
0086 std::ofstream fs2("detector_ordered.dot");
0087 Acts::Experimental::detail::BlueprintDrawer::dotStream(fs2, *detector);
0088 fs2.close();
0089 }
0090
0091 BOOST_AUTO_TEST_CASE(BlueprintCylindricalGapFilling) {
0092
0093 double detectorIr = 0.;
0094 double detectorOr = 120.;
0095 double detectorHz = 400.;
0096
0097
0098 double beamPipeOr = 20.;
0099
0100
0101 double pixelIr = 25;
0102 double pixelOr = 115;
0103 double pixelEcHz = 50;
0104
0105 auto innerBuilder =
0106 std::make_shared<Acts::Experimental::IInternalStructureBuilder>();
0107
0108
0109 std::vector<Acts::AxisDirection> detectorBinning = {
0110 Acts::AxisDirection::AxisR};
0111 std::vector<double> detectorBoundaries = {detectorIr, detectorOr, detectorHz};
0112
0113
0114 auto detector = std::make_unique<Acts::Experimental::Blueprint::Node>(
0115 "detector", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0116 detectorBoundaries, detectorBinning);
0117
0118
0119 std::vector<double> beamPipeBoundaries = {detectorIr, beamPipeOr, detectorHz};
0120 auto beamPipe = std::make_unique<Acts::Experimental::Blueprint::Node>(
0121 "beam_pipe", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0122 beamPipeBoundaries, innerBuilder);
0123 detector->add(std::move(beamPipe));
0124
0125
0126 std::vector<double> pixelBoundaries = {pixelIr, pixelOr, detectorHz};
0127 std::vector<Acts::AxisDirection> pixelBinning = {Acts::AxisDirection::AxisZ};
0128 auto pixel = std::make_unique<Acts::Experimental::Blueprint::Node>(
0129 "pixel", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0130 pixelBoundaries, pixelBinning);
0131
0132
0133 std::vector<double> pixelEcBoundaries = {pixelIr, pixelOr - 5., pixelEcHz};
0134 std::vector<Acts::AxisDirection> pixelEcBinning = {
0135 Acts::AxisDirection::AxisZ};
0136
0137 auto pixelNec = std::make_unique<Acts::Experimental::Blueprint::Node>(
0138 "pixelNec",
0139 Acts::Transform3::Identity() *
0140 Acts::Translation3(0., 0., -detectorHz + pixelEcHz),
0141 Acts::VolumeBounds::eCylinder, pixelEcBoundaries, pixelEcBinning);
0142
0143
0144 std::vector<double> pixelNecBoundaries = {pixelIr + 2, pixelOr - 7., 10.};
0145 auto pixelNecLayer = std::make_unique<Acts::Experimental::Blueprint::Node>(
0146 "pixelNecLayer",
0147 Acts::Transform3::Identity() *
0148 Acts::Translation3(0., 0., -detectorHz + pixelEcHz),
0149 Acts::VolumeBounds::eCylinder, pixelNecBoundaries, innerBuilder);
0150
0151 pixelNec->add(std::move(pixelNecLayer));
0152
0153
0154 std::vector<double> pixelBarrelBoundaries = {pixelIr + 1, pixelOr - 1.,
0155 detectorHz - 2 * pixelEcHz};
0156 std::vector<Acts::AxisDirection> pixelBarrelBinning = {
0157 Acts::AxisDirection::AxisR};
0158
0159 auto pixelBarrel = std::make_unique<Acts::Experimental::Blueprint::Node>(
0160 "pixelBarrel", Acts::Transform3::Identity(),
0161 Acts::VolumeBounds::eCylinder, pixelBarrelBoundaries, pixelBarrelBinning);
0162
0163 std::vector<double> pixelBarrelL0Boundaries = {60, 65.,
0164 detectorHz - 2 * pixelEcHz};
0165 auto pixelBarrelL0 = std::make_unique<Acts::Experimental::Blueprint::Node>(
0166 "pixelBarrelL0", Acts::Transform3::Identity(),
0167 Acts::VolumeBounds::eCylinder, pixelBarrelL0Boundaries, innerBuilder);
0168
0169 std::vector<double> pixelBarrelL1Boundaries = {100, 105.,
0170 detectorHz - 2 * pixelEcHz};
0171 auto pixelBarrelL1 = std::make_unique<Acts::Experimental::Blueprint::Node>(
0172 "pixelBarrelL1", Acts::Transform3::Identity(),
0173 Acts::VolumeBounds::eCylinder, pixelBarrelL1Boundaries, innerBuilder);
0174 pixelBarrel->add(std::move(pixelBarrelL0));
0175 pixelBarrel->add(std::move(pixelBarrelL1));
0176
0177 auto pixelPec = std::make_unique<Acts::Experimental::Blueprint::Node>(
0178 "pixelPec",
0179 Acts::Transform3::Identity() *
0180 Acts::Translation3(0., 0., +detectorHz - pixelEcHz),
0181 Acts::VolumeBounds::eCylinder, pixelEcBoundaries, pixelEcBinning);
0182
0183 std::vector<double> pixelPecBoundaries = {pixelIr + 2, pixelOr - 7., 10.};
0184 auto pixelPecLayer = std::make_unique<Acts::Experimental::Blueprint::Node>(
0185 "pixelPecLayer",
0186 Acts::Transform3::Identity() *
0187 Acts::Translation3(0., 0., detectorHz - pixelEcHz),
0188 Acts::VolumeBounds::eCylinder, pixelPecBoundaries, innerBuilder);
0189
0190 pixelPec->add(std::move(pixelPecLayer));
0191
0192
0193 pixel->add(std::move(pixelNec));
0194 pixel->add(std::move(pixelPec));
0195 pixel->add(std::move(pixelBarrel));
0196
0197 detector->add(std::move(pixel));
0198
0199 std::ofstream fs("detector_with_gaps.dot");
0200 Acts::Experimental::detail::BlueprintDrawer::dotStream(fs, *detector);
0201 fs.close();
0202
0203
0204 BOOST_CHECK_EQUAL(detector->children.size(), 2u);
0205 BOOST_CHECK_EQUAL(detector->children[0u]->name, "beam_pipe");
0206 BOOST_CHECK_EQUAL(detector->children[1u]->name, "pixel");
0207
0208
0209 Acts::Experimental::detail::BlueprintHelper::fillGaps(*detector);
0210
0211
0212 BOOST_CHECK_EQUAL(detector->children.size(), 4u);
0213 BOOST_CHECK_EQUAL(detector->children[0u]->name, "beam_pipe");
0214 BOOST_CHECK_EQUAL(detector->children[1u]->name, "detector_gap_0");
0215 BOOST_CHECK_EQUAL(detector->children[2u]->name, "pixel");
0216 BOOST_CHECK_EQUAL(detector->children[3u]->name, "detector_gap_1");
0217
0218
0219 BOOST_CHECK_EQUAL(detector->children[1u]->boundaryValues[0], beamPipeOr);
0220 BOOST_CHECK_EQUAL(detector->children[1u]->boundaryValues[1], pixelIr);
0221 BOOST_CHECK_EQUAL(detector->children[1u]->boundaryValues[2], detectorHz);
0222
0223 BOOST_CHECK_EQUAL(detector->children[3u]->boundaryValues[0], pixelOr);
0224 BOOST_CHECK_EQUAL(detector->children[3u]->boundaryValues[1], detectorOr);
0225 BOOST_CHECK_EQUAL(detector->children[3u]->boundaryValues[2], detectorHz);
0226
0227
0228 BOOST_CHECK_EQUAL(detector->children[2u]->children.size(), 3u);
0229 BOOST_CHECK_EQUAL(detector->children[2u]->children[0u]->children.size(), 3u);
0230 BOOST_CHECK_EQUAL(detector->children[2u]->children[1u]->children.size(), 5u);
0231 BOOST_CHECK_EQUAL(detector->children[2u]->children[2u]->children.size(), 3u);
0232
0233
0234 BOOST_CHECK_EQUAL(
0235 detector->children[2u]->children[0u]->children[0]->boundaryValues[0],
0236 pixelIr);
0237 BOOST_CHECK_EQUAL(
0238 detector->children[2u]->children[0u]->children[0]->boundaryValues[1],
0239 pixelOr);
0240
0241 BOOST_CHECK_EQUAL(
0242 detector->children[2u]->children[0u]->children[1]->boundaryValues[0],
0243 pixelIr);
0244 BOOST_CHECK_EQUAL(
0245 detector->children[2u]->children[0u]->children[1]->boundaryValues[1],
0246 pixelOr);
0247
0248 BOOST_CHECK_EQUAL(
0249 detector->children[2u]->children[0u]->children[2]->boundaryValues[0],
0250 pixelIr);
0251 BOOST_CHECK_EQUAL(
0252 detector->children[2u]->children[0u]->children[2]->boundaryValues[1],
0253 pixelOr);
0254
0255 std::ofstream fs2("detector_without_gaps.dot");
0256 Acts::Experimental::detail::BlueprintDrawer::dotStream(fs2, *detector);
0257 fs2.close();
0258 }
0259
0260 BOOST_AUTO_TEST_CASE(BlueprintCylindricalGapException) {
0261 auto innerBuilder =
0262 std::make_shared<Acts::Experimental::IInternalStructureBuilder>();
0263
0264
0265 std::vector<double> detectorBoundaries = {0., 50., 100.};
0266 std::vector<Acts::AxisDirection> detectorBinning = {
0267 Acts::AxisDirection::AxisX};
0268 auto detector = std::make_unique<Acts::Experimental::Blueprint::Node>(
0269 "detector", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0270 detectorBoundaries, detectorBinning);
0271
0272
0273 std::vector<double> volTwoBoundaries = {0., 20., 100.};
0274 auto vol = std::make_unique<Acts::Experimental::Blueprint::Node>(
0275 "vol", Acts::Transform3::Identity(), Acts::VolumeBounds::eCylinder,
0276 volTwoBoundaries, innerBuilder);
0277 detector->add(std::move(vol));
0278
0279
0280 BOOST_CHECK_THROW(
0281 Acts::Experimental::detail::BlueprintHelper::fillGaps(*detector),
0282 std::runtime_error);
0283 }
0284
0285 BOOST_AUTO_TEST_SUITE_END()