File indexing completed on 2025-08-05 08:09:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Geometry/VolumeAssociationTest.hpp"
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Detector/Detector.hpp"
0013 #include "Acts/Detector/DetectorVolume.hpp"
0014
0015 #include <exception>
0016 #include <memory>
0017 #include <string>
0018 #include <vector>
0019
0020 ActsExamples::VolumeAssociationTest::VolumeAssociationTest(
0021 const Config& cfg, Acts::Logging::Level level)
0022 : IAlgorithm(cfg.name, level), m_cfg(cfg) {
0023 if (m_cfg.detector == nullptr) {
0024 throw std::invalid_argument("Missing detector object");
0025 }
0026 if (m_cfg.randomNumbers == nullptr) {
0027 throw std::invalid_argument("Missing random numbers tool");
0028 }
0029 if (m_cfg.randomRange.size() < 2) {
0030 throw std::invalid_argument(
0031 "Random range needs to be at least 2-dimensional");
0032 }
0033 }
0034
0035 ActsExamples::ProcessCode ActsExamples::VolumeAssociationTest::execute(
0036 const AlgorithmContext& ctx) const {
0037 auto rng = m_cfg.randomNumbers->spawnGenerator(ctx);
0038
0039
0040 std::uniform_real_distribution<Acts::ActsScalar> phiDist(-M_PI, M_PI);
0041 std::uniform_real_distribution<Acts::ActsScalar> rDist(0.,
0042 m_cfg.randomRange[0u]);
0043 std::uniform_real_distribution<Acts::ActsScalar> zDist(-m_cfg.randomRange[1u],
0044 m_cfg.randomRange[1u]);
0045
0046
0047 auto testPosition = [&]() -> Acts::Vector3 {
0048 Acts::ActsScalar r = rDist(rng);
0049 Acts::ActsScalar phi = phiDist(rng);
0050 Acts::ActsScalar z = zDist(rng);
0051 return Acts::Vector3(r * cos(phi), r * sin(phi), z);
0052 };
0053
0054 std::size_t failedSearch = 0;
0055 std::size_t failedAssignment = 0;
0056 for (std::size_t it = 0; it < m_cfg.ntests; ++it) {
0057 auto pos = testPosition();
0058 auto dv = m_cfg.detector->findDetectorVolume(ctx.geoContext, pos);
0059 if (dv == nullptr) {
0060 ++failedSearch;
0061 }
0062 if (!dv->inside(ctx.geoContext, pos)) {
0063 ++failedAssignment;
0064 }
0065 }
0066 if (failedSearch > 0) {
0067 ACTS_ERROR("Failed to find detector volume " << failedSearch << " times");
0068 }
0069 if (failedAssignment > 0) {
0070 ACTS_ERROR("Failed to assign detector volume " << failedAssignment
0071 << " times");
0072 }
0073
0074 return ProcessCode::SUCCESS;
0075 }