forked from sPHENIX-Collaboration/acts
/
DirectNavigator.hpp
221 lines (197 loc) · 8.03 KB
/
DirectNavigator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// This file is part of the Acts project.
//
// Copyright (C) 2019 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once
#include "Acts/Geometry/BoundarySurfaceT.hpp"
#include "Acts/Geometry/Layer.hpp"
#include "Acts/Geometry/TrackingGeometry.hpp"
#include "Acts/Geometry/TrackingVolume.hpp"
#include "Acts/Propagator/ConstrainedStep.hpp"
#include "Acts/Propagator/Propagator.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include <iomanip>
#include <iterator>
#include <sstream>
#include <string>
#include <boost/algorithm/string.hpp>
namespace Acts {
/// DirectNavigator class
///
/// This is a fully guided navigator that progresses through
/// a pre-given sequence of surfaces.
///
/// This can either be used as a validation tool, for truth
/// tracking, or track refitting
class DirectNavigator {
public:
/// The sequentially crossed surfaces
using SurfaceSequence = std::vector<const Surface*>;
using SurfaceIter = std::vector<const Surface*>::iterator;
/// Defaulted Constructed
DirectNavigator() = default;
/// The tolerance used to define "surface reached"
double tolerance = s_onSurfaceTolerance;
/// Nested Actor struct, called Initializer
///
/// This is needed for the initialization of the
/// surface sequence
struct Initializer {
/// The Surface sequence
SurfaceSequence navSurfaces = {};
/// Actor result / state
struct this_result {
bool initialized = false;
};
using result_type = this_result;
/// Defaulting the constructor
Initializer() = default;
/// Actor operator call
/// @tparam statet Type of the full propagator state
/// @tparam stepper_t Type of the stepper
///
/// @param state the entire propagator state
/// @param r the result of this Actor
template <typename propagator_state_t, typename stepper_t>
void operator()(propagator_state_t& state, const stepper_t& /*unused*/,
result_type& r) const {
// Only act once
if (not r.initialized) {
// Initialize the surface sequence
state.navigation.navSurfaces = navSurfaces;
state.navigation.navSurfaceIter =
state.navigation.navSurfaces.begin();
r.initialized = true;
}
}
/// Actor operator call - resultless, unused
template <typename propagator_state_t, typename stepper_t>
void operator()(propagator_state_t& /*unused*/,
const stepper_t& /*unused*/) const {}
};
/// Nested State struct
///
/// It acts as an internal state which is
/// created for every propagation/extrapolation step
/// and keep thread-local navigation information
struct State {
/// Externally provided surfaces - expected to be ordered
/// along the path
SurfaceSequence navSurfaces = {};
/// Iterator the the next surface
SurfaceIter navSurfaceIter = navSurfaces.begin();
/// Navigation state - external interface: the start surface
const Surface* startSurface = nullptr;
/// Navigation state - external interface: the current surface
const Surface* currentSurface = nullptr;
/// Navigation state - external interface: the target surface
const Surface* targetSurface = nullptr;
/// Navigation state - starting layer
const Layer* startLayer = nullptr;
/// Navigation state - target layer
const Layer* targetLayer = nullptr;
/// Navigation state: the start volume
const TrackingVolume* startVolume = nullptr;
/// Navigation state: the current volume
const TrackingVolume* currentVolume = nullptr;
/// Navigation state: the target volume
const TrackingVolume* targetVolume = nullptr;
/// Navigation state - external interface: target is reached
bool targetReached = false;
/// Navigation state - external interface: a break has been detected
bool navigationBreak = false;
};
/// @brief Navigator status call
///
/// @tparam propagator_state_t is the type of Propagatgor state
/// @tparam stepper_t is the used type of the Stepper by the Propagator
///
/// @param [in,out] state is the mutable propagator state object
/// @param [in] stepper Stepper in use
template <typename propagator_state_t, typename stepper_t>
void status(propagator_state_t& state, const stepper_t& stepper) const {
const auto& logger = state.options.logger;
// Screen output
ACTS_VERBOSE("Entering navigator::status.");
// Navigator status always resets the current surface
state.navigation.currentSurface = nullptr;
// Output the position in the sequence
ACTS_VERBOSE(std::distance(state.navigation.navSurfaceIter,
state.navigation.navSurfaces.end())
<< " out of " << state.navigation.navSurfaces.size()
<< " surfaces remain to try.");
// Check if we are on surface
if (state.navigation.navSurfaceIter !=
state.navigation.navSurfaces.end()) {
// Establish the surface status
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, **state.navigation.navSurfaceIter, false);
if (surfaceStatus == Intersection3D::Status::onSurface) {
// Set the current surface
state.navigation.currentSurface = *state.navigation.navSurfaceIter;
ACTS_VERBOSE("Current surface set to "
<< state.navigation.currentSurface->geometryId())
// Move the sequence to the next surface
++state.navigation.navSurfaceIter;
if (state.navigation.navSurfaceIter !=
state.navigation.navSurfaces.end()) {
ACTS_VERBOSE("Next surface candidate is "
<< (*state.navigation.navSurfaceIter)->geometryId());
stepper.releaseStepSize(state.stepping);
}
} else if (surfaceStatus == Intersection3D::Status::reachable) {
ACTS_VERBOSE("Next surface reachable at distance "
<< stepper.outputStepSize(state.stepping));
}
}
}
/// @brief Navigator target call
///
/// @tparam propagator_state_t is the type of Propagatgor state
/// @tparam stepper_t is the used type of the Stepper by the Propagator
///
/// @param [in,out] state is the mutable propagator state object
/// @param [in] stepper Stepper in use
template <typename propagator_state_t, typename stepper_t>
void target(propagator_state_t& state, const stepper_t& stepper) const {
const auto& logger = state.options.logger;
// Screen output
ACTS_VERBOSE("Entering navigator::target.");
// Navigator target always resets the current surface
state.navigation.currentSurface = nullptr;
// Output the position in the sequence
ACTS_VERBOSE(std::distance(state.navigation.navSurfaceIter,
state.navigation.navSurfaces.end())
<< " out of " << state.navigation.navSurfaces.size()
<< " surfaces remain to try.");
if (state.navigation.navSurfaceIter !=
state.navigation.navSurfaces.end()) {
// Establish & update the surface status
auto surfaceStatus = stepper.updateSurfaceStatus(
state.stepping, **state.navigation.navSurfaceIter, false);
if (surfaceStatus == Intersection3D::Status::unreachable) {
ACTS_VERBOSE(
"Surface not reachable anymore, switching to next one in "
"sequence");
// Move the sequence to the next surface
++state.navigation.navSurfaceIter;
} else {
ACTS_VERBOSE("Navigation stepSize set to "
<< stepper.outputStepSize(state.stepping));
}
} else {
// Set the navigation break
state.navigation.navigationBreak = true;
// If no externally provided target is given, the target is reached
if (state.navigation.targetSurface == nullptr) {
state.navigation.targetReached = true;
// Announce it then
ACTS_VERBOSE("No target Surface, job done.");
}
}
}
};
} // namespace Acts