File indexing completed on 2025-01-31 09:16:45
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 <numbers>
0018 #include <string>
0019 #include <vector>
0020
0021 ActsExamples::VolumeAssociationTest::VolumeAssociationTest(
0022 const Config& cfg, Acts::Logging::Level level)
0023 : IAlgorithm(cfg.name, level), m_cfg(cfg) {
0024 if (m_cfg.detector == nullptr) {
0025 throw std::invalid_argument("Missing detector object");
0026 }
0027 if (m_cfg.randomNumbers == nullptr) {
0028 throw std::invalid_argument("Missing random numbers tool");
0029 }
0030 if (m_cfg.randomRange.size() < 2) {
0031 throw std::invalid_argument(
0032 "Random range needs to be at least 2-dimensional");
0033 }
0034 }
0035
0036 ActsExamples::ProcessCode ActsExamples::VolumeAssociationTest::execute(
0037 const AlgorithmContext& ctx) const {
0038 auto rng = m_cfg.randomNumbers->spawnGenerator(ctx);
0039
0040
0041 std::uniform_real_distribution<double> phiDist(-std::numbers::pi,
0042 std::numbers::pi);
0043 std::uniform_real_distribution<double> rDist(0., m_cfg.randomRange[0u]);
0044 std::uniform_real_distribution<double> zDist(-m_cfg.randomRange[1u],
0045 m_cfg.randomRange[1u]);
0046
0047
0048 auto testPosition = [&]() -> Acts::Vector3 {
0049 double r = rDist(rng);
0050 double phi = phiDist(rng);
0051 double z = zDist(rng);
0052 return Acts::Vector3(r * cos(phi), r * sin(phi), z);
0053 };
0054
0055 std::size_t failedSearch = 0;
0056 std::size_t failedAssignment = 0;
0057 for (std::size_t it = 0; it < m_cfg.ntests; ++it) {
0058 auto pos = testPosition();
0059 auto dv = m_cfg.detector->findDetectorVolume(ctx.geoContext, pos);
0060 if (dv == nullptr) {
0061 ++failedSearch;
0062 }
0063 if (!dv->inside(ctx.geoContext, pos)) {
0064 ++failedAssignment;
0065 }
0066 }
0067 if (failedSearch > 0) {
0068 ACTS_ERROR("Failed to find detector volume " << failedSearch << " times");
0069 }
0070 if (failedAssignment > 0) {
0071 ACTS_ERROR("Failed to assign detector volume " << failedAssignment
0072 << " times");
0073 }
0074
0075 return ProcessCode::SUCCESS;
0076 }