Back to home page

EIC code displayed by LXR

 
 

    


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

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/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Surfaces/BoundaryCheck.hpp"
0014 #include "Acts/Surfaces/PlanarBounds.hpp"
0015 #include "Acts/Surfaces/RectangleBounds.hpp"
0016 #include "Acts/Surfaces/SurfaceBounds.hpp"
0017 
0018 #include <algorithm>
0019 #include <array>
0020 #include <cmath>
0021 #include <iosfwd>
0022 #include <stdexcept>
0023 #include <vector>
0024 
0025 namespace Acts {
0026 
0027 /// @class DiamondBounds
0028 ///
0029 /// @image html DiamondBounds.svg
0030 /// Bounds for a double trapezoidal ("diamond"), planar Surface.
0031 class DiamondBounds : public PlanarBounds {
0032  public:
0033   enum BoundValues {
0034     eHalfLengthXnegY = 0,
0035     eHalfLengthXzeroY = 1,
0036     eHalfLengthXposY = 2,
0037     eHalfLengthYneg = 3,
0038     eHalfLengthYpos = 4,
0039     eSize = 5
0040   };
0041 
0042   DiamondBounds() = delete;
0043 
0044   /// Constructor for convex hexagon symmetric about the y axis
0045   ///
0046   /// @param halfXnegY is the halflength in x at minimal y
0047   /// @param halfXzeroY is the halflength in x at y = 0
0048   /// @param halfXposY is the halflength in x at maximal y
0049   /// @param halfYneg is the halflength into y < 0
0050   /// @param halfYpos is the halflength into y > 0
0051   DiamondBounds(double halfXnegY, double halfXzeroY, double halfXposY,
0052                 double halfYneg, double halfYpos) noexcept(false)
0053       : m_values({halfXnegY, halfXzeroY, halfXposY, halfYneg, halfYpos}),
0054         m_boundingBox(
0055             Vector2{
0056                 -(*std::max_element(m_values.begin(), m_values.begin() + 2)),
0057                 -halfYneg},
0058             Vector2{*std::max_element(m_values.begin(), m_values.begin() + 2),
0059                     halfYpos}) {
0060     checkConsistency();
0061   }
0062 
0063   /// Constructor - from fixed size array
0064   ///
0065   /// @param values The parameter values
0066   DiamondBounds(const std::array<double, eSize>& values) noexcept(false)
0067       : m_values(values),
0068         m_boundingBox(
0069             Vector2{-(*std::max_element(values.begin(), values.begin() + 2)),
0070                     -values[eHalfLengthYneg]},
0071             Vector2{*std::max_element(values.begin(), values.begin() + 2),
0072                     values[eHalfLengthYpos]}) {}
0073 
0074   ~DiamondBounds() override = default;
0075 
0076   BoundsType type() const final;
0077 
0078   /// Return the bound values as dynamically sized vector
0079   ///
0080   /// @return this returns a copy of the internal values
0081   std::vector<double> values() const final;
0082 
0083   /// Inside check for the bounds object driven by the boundary check directive
0084   /// Each Bounds has a method inside, which checks if a LocalPosition is inside
0085   /// the bounds  Inside can be called without/with tolerances.
0086   ///
0087   /// @param lposition Local position (assumed to be in right surface frame)
0088   /// @param bcheck boundary check directive
0089   /// @return boolean indicator for the success of this operation
0090   bool inside(const Vector2& lposition,
0091               const BoundaryCheck& bcheck) const final;
0092 
0093   /// Return the vertices
0094   ///
0095   /// @param lseg the number of segments used to approximate
0096   /// and eventually curved line
0097   ///
0098   /// @note the number of segments is ignored for this representation
0099   ///
0100   /// @return vector for vertices in 2D
0101   std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
0102 
0103   // Bounding box representation
0104   const RectangleBounds& boundingBox() const final;
0105 
0106   /// Output Method for std::ostream
0107   ///
0108   /// @param sl is the ostream in which it is dumped
0109   std::ostream& toStream(std::ostream& sl) const final;
0110 
0111   /// Access to the bound values
0112   /// @param bValue the class nested enum for the array access
0113   double get(BoundValues bValue) const { return m_values[bValue]; }
0114 
0115  private:
0116   std::array<double, eSize> m_values;
0117   RectangleBounds m_boundingBox;  ///< internal bounding box cache
0118 
0119   /// Check the input values for consistency, will throw a logic_exception
0120   /// if consistency is not given
0121   void checkConsistency() noexcept(false);
0122 };
0123 
0124 inline std::vector<double> DiamondBounds::values() const {
0125   std::vector<double> valvector;
0126   valvector.insert(valvector.begin(), m_values.begin(), m_values.end());
0127   return valvector;
0128 }
0129 
0130 inline void DiamondBounds::checkConsistency() noexcept(false) {
0131   if (std::any_of(m_values.begin(), m_values.end(),
0132                   [](auto v) { return v <= 0.; })) {
0133     throw std::invalid_argument("DiamondBounds: negative half length.");
0134   }
0135   if (get(eHalfLengthXnegY) > get(eHalfLengthXzeroY) ||
0136       get(eHalfLengthXposY) > get(eHalfLengthXzeroY)) {
0137     throw std::invalid_argument("DiamondBounds: not a diamond shape.");
0138   }
0139 }
0140 
0141 }  // namespace Acts