Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:23:35

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2016-2020 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/BoundaryCheck.hpp"
0013 #include "Acts/Surfaces/PlanarBounds.hpp"
0014 #include "Acts/Surfaces/SurfaceBounds.hpp"
0015 
0016 #include <array>
0017 #include <cassert>
0018 #include <iosfwd>
0019 #include <limits>
0020 #include <stdexcept>
0021 #include <vector>
0022 
0023 namespace Acts {
0024 
0025 /// @class RectangleBounds
0026 ///
0027 /// @image html RectangleBounds.gif
0028 ///
0029 /// Bounds for a rectangular, planar surface - it can be used to for
0030 /// rectangles that are symmetrically centered around (0./0.) and for
0031 /// generic shifted rectangles
0032 class RectangleBounds : public PlanarBounds {
0033  public:
0034   enum BoundValues : int {
0035     eMinX = 0,
0036     eMinY = 1,
0037     eMaxX = 2,
0038     eMaxY = 3,
0039     eSize = 4
0040   };
0041 
0042   RectangleBounds() = delete;
0043 
0044   /// Constructor with halflength in x and y - symmetric
0045   ///
0046   /// @param halfX halflength in X
0047   /// @param halfY halflength in Y
0048   RectangleBounds(double halfX, double halfY) noexcept(false)
0049       : m_min({-halfX, -halfY}), m_max({halfX, halfY}) {
0050     checkConsistency();
0051   }
0052 
0053   /// Constructor - from fixed size array - generic
0054   ///
0055   /// @param values The parameter values
0056   RectangleBounds(const std::array<double, eSize>& values) noexcept(false)
0057       : m_min({values[eMinX], values[eMinY]}),
0058         m_max({values[eMaxX], values[eMaxY]}) {
0059     checkConsistency();
0060   }
0061 
0062   /// Constructor - from min/max - generic
0063   ///
0064   /// @param min The left bottom corner
0065   /// @param max The right top corning
0066   RectangleBounds(const Vector2& min, const Vector2& max) noexcept(false)
0067       : m_min(min), m_max(max) {
0068     checkConsistency();
0069   }
0070 
0071   ~RectangleBounds() override = default;
0072 
0073   BoundsType type() const final;
0074 
0075   std::vector<double> values() const final;
0076 
0077   /// Inside check for the bounds object driven by the boundary check directive
0078   /// Each Bounds has a method inside, which checks if a LocalPosition is inside
0079   /// the bounds  Inside can be called without/with tolerances.
0080   ///
0081   /// @param lposition Local position (assumed to be in right surface frame)
0082   /// @param bcheck boundary check directive
0083   /// @return boolean indicator for the success of this operation
0084   bool inside(const Vector2& lposition,
0085               const BoundaryCheck& bcheck) const final;
0086 
0087   /// Return the vertices
0088   ///
0089   /// @param lseg the number of segments used to approximate
0090   /// and eventually curved line
0091   ///
0092   /// @note the number of segments is ignored in this representation
0093   ///
0094   /// @return vector for vertices in 2D
0095   std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
0096 
0097   // Bounding box representation
0098   const RectangleBounds& boundingBox() const final;
0099 
0100   /// Output Method for std::ostream
0101   ///
0102   /// @param sl is the ostream for the dump
0103   std::ostream& toStream(std::ostream& sl) const final;
0104 
0105   /// Access to the bound values
0106   /// @param bValue the class nested enum for the array access
0107   double get(BoundValues bValue) const;
0108 
0109   /// Access to the half length in X
0110   double halfLengthX() const;
0111 
0112   /// Access to the half length in Y
0113   double halfLengthY() const;
0114 
0115   /// Get the min vertex defining the bounds
0116   /// @return The min vertex
0117   const Vector2& min() const;
0118 
0119   /// Get the max vertex defining the bounds
0120   /// @return The max vertex
0121   const Vector2& max() const;
0122 
0123  private:
0124   Vector2 m_min;
0125   Vector2 m_max;
0126 
0127   /// Check the input values for consistency, will throw a logic_exception
0128   /// if consistency is not given
0129   void checkConsistency() noexcept(false);
0130 };
0131 
0132 inline SurfaceBounds::BoundsType RectangleBounds::type() const {
0133   return SurfaceBounds::eRectangle;
0134 }
0135 
0136 inline const Vector2& RectangleBounds::min() const {
0137   return m_min;
0138 }
0139 
0140 inline const Vector2& RectangleBounds::max() const {
0141   return m_max;
0142 }
0143 
0144 inline double RectangleBounds::halfLengthX() const {
0145   return 0.5 * (m_max.x() - m_min.x());
0146 }
0147 
0148 inline double RectangleBounds::halfLengthY() const {
0149   return 0.5 * (m_max.y() - m_min.y());
0150 }
0151 
0152 inline std::vector<double> RectangleBounds::values() const {
0153   return {m_min.x(), m_min.y(), m_max.x(), m_max.y()};
0154 }
0155 
0156 inline double RectangleBounds::get(BoundValues bValue) const {
0157   switch (bValue) {
0158     case eMinX:
0159       return m_min.x();
0160     case eMinY:
0161       return m_min.y();
0162     case eMaxX:
0163       return m_max.x();
0164     case eMaxY:
0165       return m_max.y();
0166     default:
0167       assert(false && "Invalid BoundValue enum value");
0168       return std::numeric_limits<double>::quiet_NaN();
0169   }
0170 }
0171 
0172 inline void RectangleBounds::checkConsistency() noexcept(false) {
0173   if (get(eMinX) > get(eMaxX)) {
0174     throw std::invalid_argument("RectangleBounds: invalid local x setup");
0175   }
0176   if (get(eMinY) > get(eMaxY)) {
0177     throw std::invalid_argument("RectangleBounds: invalid local y setup");
0178   }
0179 }
0180 
0181 }  // namespace Acts