Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:12

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 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Visualization/IVisualization3D.hpp"
0013 
0014 namespace Acts {
0015 
0016 /// Class which models a ray. It is defined by a starting point and a
0017 /// direction.
0018 /// @tparam value_t The floating point type to use
0019 /// @tparam DIM The number of dimensions in which this ray is defined (2 or 3)
0020 template <typename value_t, std::size_t DIM>
0021 class Ray {
0022  public:
0023   /// Re expose the value type
0024   using value_type = value_t;
0025   /// Vertex type based on the value type and dimension
0026   using VertexType = Eigen::Matrix<value_t, DIM, 1>;
0027   /// Vertex array type corresponding to the vertex type
0028   using vertex_array_type = Eigen::Array<value_t, DIM, 1>;
0029   /// Associated transform type
0030   using transform_type = Eigen::Transform<value_t, DIM, Eigen::Affine>;
0031 
0032   /// Constructor from an origin point and a direction
0033   /// @param origin The origin of the ray
0034   /// @param dir The direction of the ray
0035   Ray(const VertexType& origin, const VertexType& dir);
0036 
0037   /// Getter for the origin
0038   /// @return The origin
0039   const VertexType& origin() const { return m_origin; }
0040 
0041   /// Getter for the direction
0042   /// @return The direction
0043   const VertexType& dir() const { return m_dir; }
0044 
0045   /// Getter for the element wise inverse of the direction.
0046   /// @return The element wise inverse.
0047   const vertex_array_type& idir() const { return m_idir; }
0048 
0049   /// Transforms this ray using a given transform and returns a new instance
0050   /// @param trf The transform to apply
0051   /// @return Copy of this ray with the transform applied
0052   Ray<value_t, DIM> transformed(const transform_type& trf) const;
0053 
0054   /// Write information on this instance to an outstream.
0055   /// @param os The out stream
0056   /// @return The out stream given as an argument
0057   std::ostream& toStream(std::ostream& os) const;
0058 
0059   /// Helper to draw this ray using a given visualization helper.
0060   /// @param helper The visualization helper
0061   /// @param far_distance The "length" of the drawn line representing the ray
0062   void draw(IVisualization3D& helper, value_type far_distance = 10) const
0063     requires(DIM == 3);
0064 
0065  private:
0066   VertexType m_origin;
0067   VertexType m_dir;
0068   vertex_array_type m_idir;
0069 };
0070 
0071 /// Overload of the outstream operator
0072 /// @param os The out stream
0073 /// @param ray The ray to write to @p os
0074 /// @return The outstream given in @p os
0075 template <typename T, std::size_t D>
0076 std::ostream& operator<<(std::ostream& os, const Ray<T, D>& ray) {
0077   ray.dump(os);
0078   return os;
0079 }
0080 
0081 using Ray3D = Ray<double, 3>;
0082 
0083 }  // namespace Acts
0084 
0085 #include "Acts/Utilities/Ray.ipp"