ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
bound_track_parameters.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s).
12#include "detray/definitions/algebra.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14#include "detray/definitions/indexing.hpp"
15#include "detray/definitions/math.hpp"
16#include "detray/definitions/track_parametrization.hpp"
17#include "detray/definitions/units.hpp"
18#include "detray/geometry/identifier.hpp"
19
20// System include(s)
21#include <limits>
22#include <ostream>
23
24namespace detray {
25
28template <concepts::algebra algebra_t>
32
33 using algebra_type = algebra_t;
40
41 // Underlying vector type related to bound track vector.
44
46
49
52 DETRAY_HOST_DEVICE
53 explicit bound_parameters_vector(const vector_type& vec) : m_vector(vec) {
54 assert(!this->is_invalid());
55 }
56
64 DETRAY_HOST_DEVICE
66 const scalar_type theta, const scalar_type qop,
67 const scalar_type t) {
68 getter::set_block(m_vector, loc_p, e_bound_loc0, 0u);
69 getter::element(m_vector, e_bound_phi, 0u) = phi;
70 getter::element(m_vector, e_bound_theta, 0u) = theta;
71 getter::element(m_vector, e_bound_qoverp, 0u) = qop;
72 getter::element(m_vector, e_bound_time, 0u) = t;
73
74 assert(!this->is_invalid());
75 }
76
80 DETRAY_HOST_DEVICE
81 bool operator==(const bound_parameters_vector& rhs) const {
82 for (unsigned int i = 0u; i < e_bound_size; i++) {
83 const auto lhs_val = getter::element(m_vector, i, 0u);
84 const auto rhs_val = getter::element(rhs.vector(), i, 0u);
85
86 if (math::fabs(lhs_val - rhs_val) >
87 std::numeric_limits<scalar_type>::epsilon()) {
88 return false;
89 }
90 }
91
92 return true;
93 }
94
98 DETRAY_HOST_DEVICE
99 scalar_type operator[](const std::size_t i) const {
100 return getter::element(m_vector, static_cast<unsigned int>(i), 0u);
101 }
102
106 DETRAY_HOST_DEVICE
107 decltype(auto) operator[](const std::size_t i) {
108 return getter::element(m_vector, static_cast<unsigned int>(i), 0u);
109 }
110
113 DETRAY_HOST_DEVICE
114 const vector_type& vector() const { return m_vector; }
115
118 DETRAY_HOST_DEVICE
119 vector_type& vector() { return m_vector; }
120
124 DETRAY_HOST_DEVICE
125 void set_vector(const vector_type& v,
126 [[maybe_unused]] const bool skip_check = false) {
127 m_vector = v;
128 assert(skip_check || !this->is_invalid());
129 }
130
132 DETRAY_HOST_DEVICE
134 return {getter::element(m_vector, e_bound_loc0, 0u),
135 getter::element(m_vector, e_bound_loc1, 0u)};
136 }
137
140 DETRAY_HOST_DEVICE
141 void set_bound_local(const point2_type& pos) {
142 assert(math::isfinite(pos[0]));
143 assert(math::isfinite(pos[1]));
144 getter::set_block(m_vector, pos, e_bound_loc0, 0u);
145 }
146
148 DETRAY_HOST_DEVICE
149 scalar_type phi() const { return getter::element(m_vector, e_bound_phi, 0u); }
150
153 DETRAY_HOST_DEVICE
154 void set_phi(const scalar_type phi) {
155 assert(math::fabs(phi) <= constant<scalar_type>::pi);
156 getter::element(m_vector, e_bound_phi, 0u) = phi;
157 }
158
160 DETRAY_HOST_DEVICE
162 return getter::element(m_vector, e_bound_theta, 0u);
163 }
164
167 DETRAY_HOST_DEVICE
169 assert(0.f < theta);
171 getter::element(m_vector, e_bound_theta, 0u) = theta;
172 }
173
175 DETRAY_HOST_DEVICE
177 const scalar_type phi{getter::element(m_vector, e_bound_phi, 0u)};
178 const scalar_type theta{getter::element(m_vector, e_bound_theta, 0u)};
179 const scalar_type sinTheta{math::sin(theta)};
180
181 return {math::cos(phi) * sinTheta, math::sin(phi) * sinTheta,
182 math::cos(theta)};
183 }
184
186 DETRAY_HOST_DEVICE
188 return getter::element(m_vector, e_bound_time, 0u);
189 }
190
193 DETRAY_HOST_DEVICE
194 void set_time(const scalar_type t) {
195 assert(math::isfinite(t));
196 getter::element(m_vector, e_bound_time, 0u) = t;
197 }
198
200 DETRAY_HOST_DEVICE
201 scalar_type qop() const {
202 return getter::element(m_vector, e_bound_qoverp, 0u);
203 }
204
207 DETRAY_HOST_DEVICE
208 void set_qop(const scalar_type qop) {
209 assert(math::isfinite(qop));
210 getter::element(m_vector, e_bound_qoverp, 0u) = qop;
211 }
212
214 DETRAY_HOST_DEVICE
216 const scalar_type theta{getter::element(m_vector, e_bound_theta, 0u)};
217 const scalar_type sinTheta{math::sin(theta)};
218 assert(sinTheta != 0.f);
219 return getter::element(m_vector, e_bound_qoverp, 0u) / sinTheta;
220 }
221
223 DETRAY_HOST_DEVICE
225 const scalar_type theta{getter::element(m_vector, e_bound_theta, 0u)};
226 const scalar_type cosTheta{math::cos(theta)};
227 assert(cosTheta != 0.f);
228 return getter::element(m_vector, e_bound_qoverp, 0u) / cosTheta;
229 }
230
233 DETRAY_HOST_DEVICE
234 scalar_type p(const scalar_type q) const {
235 assert(qop() != 0.f);
236 assert(q * qop() > 0.f);
237 return q / qop();
238 }
239
242 DETRAY_HOST_DEVICE
243 vector3_type mom(const scalar_type q) const { return p(q) * dir(); }
244
247 DETRAY_HOST_DEVICE
248 scalar_type pT(const scalar_type q) const {
249 assert(qop() != 0.f);
250 assert(q * qop() > 0.f);
251 return math::fabs(q / qop() * vector::perp(dir()));
252 }
253
256 DETRAY_HOST_DEVICE
257 scalar_type pz(const scalar_type q) const {
258 assert(qop() != 0.f);
259 assert(q * qop() > 0.f);
260 return math::fabs(q / qop() * dir()[2]);
261 }
262
266 DETRAY_HOST_DEVICE
267 constexpr bool is_invalid(const bool do_check = true) const {
268 if (!do_check) {
269 return false;
270 }
271 bool inv_elem{false};
272 bool is_all_zero{true};
273 for (std::size_t i = 0u; i < e_bound_size; ++i) {
274 inv_elem = inv_elem || !math::isfinite(getter::element(m_vector, i, 0u));
275 is_all_zero =
276 is_all_zero && (math::fabs(getter::element(m_vector, i, 0u)) == 0.f);
277 }
278
279 return (inv_elem || is_all_zero);
280 }
281
282 private:
284 DETRAY_HOST
285 friend std::ostream& operator<<(std::ostream& out_stream,
286 const bound_parameters_vector& bparam) {
287 out_stream << bparam.m_vector;
288 return out_stream;
289 }
290
291 vector_type m_vector = matrix::zero<vector_type>();
292};
293
296template <concepts::algebra algebra_t>
300
303
304 using algebra_type = algebra_t;
311
312 // Shorthand vector/matrix types related to bound track parameters.
317
319
322
328 DETRAY_HOST_DEVICE
330 const parameter_vector_type& vec,
331 const covariance_type& cov)
332 : base_type(vec), m_covariance(cov), m_identifier(sf_idx) {}
333
337 DETRAY_HOST_DEVICE
338 bool operator==(const bound_track_parameters& rhs) const {
339 if (m_identifier != rhs.surface_link()) {
340 return false;
341 }
342
343 if (!base_type::operator==(rhs)) {
344 return false;
345 }
346
347 for (unsigned int i = 0u; i < e_bound_size; i++) {
348 for (unsigned int j = 0u; j < e_bound_size; j++) {
349 const auto lhs_val = getter::element(m_covariance, i, j);
350 const auto rhs_val = getter::element(rhs.covariance(), i, j);
351
352 if (math::fabs(lhs_val - rhs_val) >
353 std::numeric_limits<scalar_type>::epsilon()) {
354 return false;
355 }
356 }
357 }
358
359 return true;
360 }
361
363 DETRAY_HOST_DEVICE
364 const geometry::identifier& surface_link() const { return m_identifier; }
365
368 DETRAY_HOST_DEVICE
369 void set_surface_link(geometry::identifier link) { m_identifier = link; }
370
374 DETRAY_HOST_DEVICE
376 const bool skip_check = false) {
377 this->set_vector(v.vector(), skip_check);
378 }
379
381 DETRAY_HOST_DEVICE
382 covariance_type& covariance() { return m_covariance; }
383
385 DETRAY_HOST_DEVICE
386 const covariance_type& covariance() const { return m_covariance; }
387
390 DETRAY_HOST_DEVICE
391 void set_covariance(const covariance_type& c) { m_covariance = c; }
392
396 DETRAY_HOST_DEVICE
397 constexpr bool is_invalid(const bool do_check = true) const {
398 if (!do_check) {
399 return false;
400 }
401 if (base_type::is_invalid()) {
402 return true;
403 }
404
405 // @TODO: Add tests positive semi-definite, check the determinant etc
406 return (m_covariance == matrix::zero<covariance_type>());
407 }
408
409 private:
411 DETRAY_HOST
412 friend std::ostream& operator<<(std::ostream& out_stream,
413 const bound_track_parameters& bparam) {
414 out_stream << "Surface: " << bparam.m_identifier << std::endl;
415 out_stream << "Param.:\n " << static_cast<parameter_vector_type>(bparam)
416 << std::endl;
417 out_stream << "Cov.:\n" << bparam.m_covariance;
418
419 return out_stream;
420 }
421
423 covariance_type m_covariance = matrix::zero<covariance_type>();
425 geometry::identifier m_identifier{};
426};
427
428namespace algebra {
429
432template <concepts::value value_t, concepts::algebra algebra_t>
433DETRAY_HOST_DEVICE constexpr decltype(auto) cast_to(
434 const bound_parameters_vector<algebra_t>& param_vec) {
435 using new_algebra_t = dalgebra<algebra_t, value_t>;
436
437 if constexpr (std::same_as<new_algebra_t, algebra_t>) {
438 return param_vec;
439 } else {
440 return bound_parameters_vector<new_algebra_t>{
441 ::detray::algebra::cast_to<value_t>(param_vec.to_vector())};
442 }
443}
444
446template <concepts::value value_t, concepts::algebra algebra_t>
447DETRAY_HOST_DEVICE constexpr decltype(auto) cast_to(
448 const bound_track_parameters<algebra_t>& param) {
449 using new_algebra_t = dalgebra<algebra_t, value_t>;
450
451 if constexpr (std::same_as<new_algebra_t, algebra_t>) {
452 return param;
453 } else {
454 const bound_parameters_vector<algebra_t>& param_vec = param;
455 return bound_track_parameters<new_algebra_t>{
456 param.surface_link(), ::detray::algebra::cast_to<value_t>(param_vec),
457 ::detray::algebra::cast_to<value_t>(param.covariance())};
458 }
459}
460
461} // namespace algebra
462
463} // namespace detray
Unique identifier for geometry objects, based on the ACTS GeometryIdentifier.
Definition identifier.hpp:36
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
get_algebra_t< A, T > dalgebra
Select the algebra backend with value type T.
Definition algebra.hpp:44
dmatrix< algebra_t, e_bound_size, 1 > bound_vector
Vector type for bound track parametrization.
Definition track_parametrization.hpp:77
get_vector3D_t< A, T > dvector3D
Three-dimensional vector type for algebra A and value type T.
Definition algebra.hpp:80
dmatrix< algebra_t, e_bound_size, e_bound_size > bound_matrix
Covariance matrix type for bound track parametrization.
Definition track_parametrization.hpp:81
get_point2D_t< A, T > dpoint2D
Two-dimensional point type for algebra A and value type T.
Definition algebra.hpp:68
scalar_type operator[](const std::size_t i) const
Convenience access to the track parameters - const.
Definition bound_track_parameters.hpp:99
algebra_t algebra_type
Algebra backend used for the vector operations.
Definition bound_track_parameters.hpp:33
scalar_type phi() const
Definition bound_track_parameters.hpp:149
point2_type bound_local() const
Definition bound_track_parameters.hpp:133
vector_type & vector()
Access the track parameters as a 6-dim vector - non-const.
Definition bound_track_parameters.hpp:119
dvector3D< algebra_t > vector3_type
Three-dimensional type for directions and momentum.
Definition bound_track_parameters.hpp:39
bound_parameters_vector()=default
Default constructor.
void set_bound_local(const point2_type &pos)
Set the bound local position.
Definition bound_track_parameters.hpp:141
bound_parameters_vector(const vector_type &vec)
Construct from a 6-dim vector of parameters.
Definition bound_track_parameters.hpp:53
void set_time(const scalar_type t)
Set the time.
Definition bound_track_parameters.hpp:194
bool operator==(const bound_parameters_vector &rhs) const
Compare all six bound parameters within scalar precision.
Definition bound_track_parameters.hpp:81
constexpr bool is_invalid(const bool do_check=true) const
Definition bound_track_parameters.hpp:267
scalar_type time() const
Definition bound_track_parameters.hpp:187
void set_qop(const scalar_type qop)
Set the q/p value.
Definition bound_track_parameters.hpp:208
const vector_type & vector() const
Access the track parameters as a 6-dim vector - const.
Definition bound_track_parameters.hpp:114
scalar_type p(const scalar_type q) const
Definition bound_track_parameters.hpp:234
vector3_type mom(const scalar_type q) const
Definition bound_track_parameters.hpp:243
bound_vector< algebra_t > vector_type
Fixed-size vector storing the six bound parameters.
Definition bound_track_parameters.hpp:43
dpoint2D< algebra_t > point2_type
Two-dimensional type for local surface coordinates.
Definition bound_track_parameters.hpp:37
friend std::ostream & operator<<(std::ostream &out_stream, const bound_parameters_vector &bparam)
Transform to a string for debugging output.
Definition bound_track_parameters.hpp:285
vector3_type dir() const
Definition bound_track_parameters.hpp:176
void set_vector(const vector_type &v, const bool skip_check=false)
Set the underlying vector.
Definition bound_track_parameters.hpp:125
scalar_type pT(const scalar_type q) const
Definition bound_track_parameters.hpp:248
scalar_type theta() const
Definition bound_track_parameters.hpp:161
scalar_type pz(const scalar_type q) const
Definition bound_track_parameters.hpp:257
void set_phi(const scalar_type phi)
Set the global phi angle.
Definition bound_track_parameters.hpp:154
scalar_type qopT() const
Definition bound_track_parameters.hpp:215
scalar_type qop() const
Definition bound_track_parameters.hpp:201
bound_parameters_vector(const point2_type &loc_p, const scalar_type phi, const scalar_type theta, const scalar_type qop, const scalar_type t)
Construct from single parameters.
Definition bound_track_parameters.hpp:65
void set_theta(const scalar_type theta)
Set the global theta angle.
Definition bound_track_parameters.hpp:168
dscalar< algebra_t > scalar_type
Scalar type used by the stored parameters.
Definition bound_track_parameters.hpp:35
scalar_type qopz() const
Definition bound_track_parameters.hpp:224
const geometry::identifier & surface_link() const
Definition bound_track_parameters.hpp:364
bound_parameters_vector< algebra_t > base_type
Base parameter-vector type inherited by this track state.
Definition bound_track_parameters.hpp:299
void set_parameter_vector(const parameter_vector_type &v, const bool skip_check=false)
Set the track parameter vector.
Definition bound_track_parameters.hpp:375
void set_surface_link(geometry::identifier link)
Set the identifier of the associated surface.
Definition bound_track_parameters.hpp:369
void set_covariance(const covariance_type &c)
Set the track parameter covariance.
Definition bound_track_parameters.hpp:391
constexpr bool is_invalid(const bool do_check=true) const
Definition bound_track_parameters.hpp:397
bound_parameters_vector< algebra_t > parameter_vector_type
Type of the bound track parameter vector.
Definition bound_track_parameters.hpp:314
covariance_type & covariance()
Definition bound_track_parameters.hpp:382
bool operator==(const bound_track_parameters &rhs) const
Compare all six bound parameters within scalar precision.
Definition bound_track_parameters.hpp:338
bound_track_parameters()=default
Default constructor sets the covaraicne to zero.
dpoint2D< algebra_t > point2_type
Two-dimensional type for local surface coordinates.
Definition bound_track_parameters.hpp:308
algebra_t algebra_type
Algebra backend used for the vector operations.
Definition bound_track_parameters.hpp:304
dvector3D< algebra_t > vector3_type
Three-dimensional type for directions and momentum.
Definition bound_track_parameters.hpp:310
bound_matrix< algebra_t > covariance_type
Matrix type storing covariance between bound parameters.
Definition bound_track_parameters.hpp:316
friend std::ostream & operator<<(std::ostream &out_stream, const bound_track_parameters &bparam)
Transform to a string for debugging output.
Definition bound_track_parameters.hpp:412
bound_track_parameters(const geometry::identifier sf_idx, const parameter_vector_type &vec, const covariance_type &cov)
Construct a bound state on a surface with a parameter vector and covariance.
Definition bound_track_parameters.hpp:329
dscalar< algebra_t > scalar_type
Scalar type used by the stored parameters.
Definition bound_track_parameters.hpp:306
const covariance_type & covariance() const
Definition bound_track_parameters.hpp:386
static constexpr scalar_t pi
π
Definition units.hpp:136