Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorVolumeFinders.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DetectorVolumeFinders.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022-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 
9 #pragma once
10 
20 
21 #include <stdexcept>
22 
23 namespace Acts {
24 namespace Experimental {
25 
27  inline void update(const GeometryContext& /*gctx*/,
28  NavigationState& /*nState*/) const {}
29 };
30 
32  inline void update(const GeometryContext& gctx,
33  NavigationState& nState) const {
34  if (nState.currentDetector == nullptr) {
35  throw std::runtime_error(
36  "DetectorVolumeFinders: no detector set to navigation state.");
37  }
38 
39  const auto& volumes = nState.currentDetector->rootVolumes();
40  for (const auto v : volumes) {
41  if (v->inside(gctx, nState.position)) {
42  nState.currentVolume = v;
43  v->detectorVolumeUpdator()(gctx, nState);
44  return;
45  }
46  }
47  nState.currentVolume = nullptr;
48  }
49 };
50 
52  inline void update(const GeometryContext& gctx,
53  NavigationState& nState) const {
54  if (nState.currentVolume == nullptr) {
55  throw std::runtime_error(
56  "DetectorVolumeFinders: no volume set to navigation state.");
57  }
58 
59  const auto& volumes = nState.currentVolume->volumes();
60  for (const auto v : volumes) {
61  if (v->inside(gctx, nState.position)) {
62  nState.currentVolume = v;
63  v->detectorVolumeUpdator()(gctx, nState);
64  return;
65  }
66  }
67  }
68 };
69 
72  DetectorVolumeUpdator vFinder;
73  vFinder.connect<&RootVolumeFinder::update>(
74  std::make_unique<const RootVolumeFinder>());
75  return vFinder;
76 }
77 
80  DetectorVolumeUpdator vFinder;
81  vFinder.connect<&TrialAndErrorVolumeFinder::update>(
82  std::make_unique<const TrialAndErrorVolumeFinder>());
83  return vFinder;
84 }
85 
88  DetectorVolumeUpdator vFinder;
89  vFinder.connect<&NoopFinder::update>(std::make_unique<const NoopFinder>());
90  return vFinder;
91 }
92 
103  inline static const DetectorVolume* extract(
104  [[maybe_unused]] const GeometryContext& gctx,
105  const NavigationState& nState, size_t index) noexcept(false) {
106  if (nState.currentDetector == nullptr) {
107  throw std::runtime_error("IndexedVolumeExtractor: no detector given.");
108  }
109  // Get the volume container from the detector
110  const auto& volumes = nState.currentDetector->volumes();
111  return volumes[index];
112  }
113 };
114 
118 template <typename grid_type>
120  IndexedUpdatorImpl<grid_type, IndexedDetectorVolumeExtractor,
122 
123 } // namespace Experimental
124 } // namespace Acts