Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:03

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s).
0012 #include "detray/definitions/algebra.hpp"
0013 #include "detray/tracks/free_track_parameters.hpp"
0014 
0015 // System include(s).
0016 #include <ostream>
0017 
0018 namespace detray::detail {
0019 
0020 /// @brief describes a straight-line trajectory
0021 template <concepts::algebra algebra_t>
0022 class ray {
0023  public:
0024   using algebra_type = algebra_t;
0025   using scalar_type = dscalar<algebra_type>;
0026   using point3_type = dpoint3D<algebra_type>;
0027   using vector3_type = dvector3D<algebra_type>;
0028   using transform3_type = dtransform3D<algebra_type>;
0029 
0030   ray() = default;
0031 
0032   /// Parametrized constructor from a position and direction
0033   ///
0034   /// @param pos the track position
0035   /// @param dir the track momentum direction
0036   DETRAY_HOST_DEVICE ray(point3_type &&pos, vector3_type &&dir)
0037       : _pos{std::move(pos)}, _dir{std::move(dir)} {}
0038 
0039   /// Parametrized constructor that complies with track interface
0040   ///
0041   /// @param pos the track position
0042   /// @param dir the track momentum direction
0043   DETRAY_HOST_DEVICE ray(const point3_type &pos, const scalar_type /*time*/,
0044                          const vector3_type &dir, const scalar_type /*qop*/)
0045       : _pos{pos}, _dir{dir} {}
0046 
0047   /// Parametrized constructor that complies with track interface
0048   ///
0049   /// @param track the track state that should be approximated
0050   template <typename A>
0051   DETRAY_HOST_DEVICE explicit ray(const free_track_parameters<A> &track)
0052       : ray(track.pos(), track.dir()) {
0053     assert(!track.is_invalid());
0054   }
0055 
0056   /// @returns position on the ray (compatible with tracks/intersectors)
0057   DETRAY_HOST_DEVICE const point3_type &pos() const { return _pos; }
0058 
0059   /// @returns position on the ray parameterized by path length
0060   DETRAY_HOST_DEVICE point3_type pos(const scalar_type s) const {
0061     // Direction is always normalized in the constructor
0062     return _pos + s * _dir;
0063   }
0064 
0065   /// @param position new position on the ray
0066   DETRAY_HOST_DEVICE void set_pos(point3_type pos) { _pos = pos; }
0067 
0068   /// @returns direction of the ray (compatible with tracks/intersectors)
0069   DETRAY_HOST_DEVICE const vector3_type &dir() const { return _dir; }
0070 
0071   /// @returns direction of the ray parameterized by path length
0072   DETRAY_HOST_DEVICE const vector3_type &dir(const scalar_type /*s*/) const {
0073     return this->dir();
0074   }
0075 
0076   /// @param dir new direction of the ray
0077   DETRAY_HOST_DEVICE void set_dir(vector3_type dir) { _dir = dir; }
0078 
0079   /// @returns the q over p value: Zero for ray
0080   DETRAY_HOST_DEVICE
0081   constexpr scalar_type qop() const { return 0.f; }
0082 
0083   /// Print
0084   DETRAY_HOST
0085   friend std::ostream &operator<<(std::ostream &os, const ray &r) {
0086     os << "ray: ";
0087     os << "ori = " << r._pos;
0088     os << ", dir = " << r._dir << std::endl;
0089 
0090     return os;
0091   }
0092 
0093  private:
0094   /// origin of ray
0095   point3_type _pos{0.f, 0.f, 0.f};
0096   /// direction of ray
0097   vector3_type _dir{0.f, 0.f, 1.f};
0098 };
0099 
0100 // Deduce the type of algebra from the track
0101 template <typename A>
0102 DETRAY_HOST_DEVICE ray(const free_track_parameters<A> &) -> ray<A>;
0103 
0104 }  // namespace detray::detail