Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VolumeAssociationTest.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file VolumeAssociationTest.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2023 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
14 
15 #include <exception>
16 #include <memory>
17 #include <string>
18 #include <vector>
19 
22  : IAlgorithm(cfg.name, level), m_cfg(cfg) {
23  if (m_cfg.detector == nullptr) {
24  throw std::invalid_argument("Missing detector object");
25  }
26  if (m_cfg.randomNumbers == nullptr) {
27  throw std::invalid_argument("Missing random numbers tool");
28  }
29  if (m_cfg.randomRange.size() < 2) {
30  throw std::invalid_argument(
31  "Random range needs to be at least 2-dimensional");
32  }
33 }
34 
36  const AlgorithmContext& ctx) const {
37  auto rng = m_cfg.randomNumbers->spawnGenerator(ctx);
38 
39  // Setup random number distributions for some quantities
40  std::uniform_real_distribution<Acts::ActsScalar> phiDist(-M_PI, M_PI);
41  std::uniform_real_distribution<Acts::ActsScalar> rDist(0.,
42  m_cfg.randomRange[0u]);
43  std::uniform_real_distribution<Acts::ActsScalar> zDist(-m_cfg.randomRange[1u],
44  m_cfg.randomRange[1u]);
45 
46  // Lemma for vector creation
47  auto testPosition = [&]() -> Acts::Vector3 {
48  Acts::ActsScalar r = rDist(rng);
50  Acts::ActsScalar z = zDist(rng);
51  return Acts::Vector3(r * cos(phi), r * sin(phi), z);
52  };
53 
54  std::size_t failedSearch = 0;
55  std::size_t failedAssignment = 0;
56  for (std::size_t it = 0; it < m_cfg.ntests; ++it) {
57  auto pos = testPosition();
58  auto dv = m_cfg.detector->findDetectorVolume(ctx.geoContext, pos);
59  if (dv == nullptr) {
60  ++failedSearch;
61  }
62  if (not dv->inside(ctx.geoContext, pos)) {
63  ++failedAssignment;
64  }
65  }
66  if (failedSearch > 0) {
67  ACTS_ERROR("Failed to find detector volume " << failedSearch << " times");
68  }
69  if (failedAssignment > 0) {
70  ACTS_ERROR("Failed to assign detector volume " << failedAssignment
71  << " times");
72  }
73 
74  return ProcessCode::SUCCESS;
75 }