Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-05 08:22: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 #include "Acts/Surfaces/DiamondBounds.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/detail/VerticesHelper.hpp"
0013 #include "Acts/Utilities/detail/OstreamStateGuard.hpp"
0014 
0015 #include <iomanip>
0016 #include <iostream>
0017 #include <stdexcept>
0018 
0019 namespace Acts {
0020 
0021 std::vector<double> DiamondBounds::values() const {
0022   return {m_values.begin(), m_values.end()};
0023 }
0024 
0025 void DiamondBounds::checkConsistency() noexcept(false) {
0026   if (std::ranges::any_of(m_values, [](auto v) { return v <= 0.; })) {
0027     throw std::invalid_argument("DiamondBounds: negative half length.");
0028   }
0029   if (get(eHalfLengthXnegY) > get(eHalfLengthXzeroY) ||
0030       get(eHalfLengthXposY) > get(eHalfLengthXzeroY)) {
0031     throw std::invalid_argument("DiamondBounds: not a diamond shape.");
0032   }
0033 }
0034 
0035 bool DiamondBounds::inside(const Vector2& lposition) const {
0036   // Vertices starting at lower left (min rel. phi)
0037   // counter-clockwise
0038   double x1 = get(DiamondBounds::eHalfLengthXnegY);
0039   double y1 = get(DiamondBounds::eHalfLengthYneg);
0040   double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0041   double y2 = 0.;
0042   double x3 = get(DiamondBounds::eHalfLengthXposY);
0043   double y3 = get(DiamondBounds::eHalfLengthYpos);
0044   std::array<Vector2, 6> vertices{
0045       {{-x1, -y1}, {x1, -y1}, {x2, y2}, {x3, y3}, {-x3, y3}, {-x2, y2}}};
0046   return detail::VerticesHelper::isInsidePolygon(lposition, vertices);
0047 }
0048 
0049 Vector2 DiamondBounds::closestPoint(const Vector2& lposition,
0050                                     const SquareMatrix2& metric) const {
0051   // Vertices starting at lower left (min rel. phi)
0052   // counter-clockwise
0053   double x1 = get(DiamondBounds::eHalfLengthXnegY);
0054   double y1 = get(DiamondBounds::eHalfLengthYneg);
0055   double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0056   double y2 = 0.;
0057   double x3 = get(DiamondBounds::eHalfLengthXposY);
0058   double y3 = get(DiamondBounds::eHalfLengthYpos);
0059   Vector2 vertices[] = {{-x1, -y1}, {x1, -y1}, {x2, y2},
0060                         {x3, y3},   {-x3, y3}, {-x2, y2}};
0061   return detail::VerticesHelper::computeClosestPointOnPolygon(lposition,
0062                                                               vertices, metric);
0063 }
0064 
0065 std::vector<Vector2> DiamondBounds::vertices(
0066     unsigned int /*ignoredSegments*/) const {
0067   // Vertices starting at lower left (min rel. phi)
0068   // counter-clockwise
0069   double x1 = get(DiamondBounds::eHalfLengthXnegY);
0070   double y1 = get(DiamondBounds::eHalfLengthYneg);
0071   double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0072   double y2 = 0.;
0073   double x3 = get(DiamondBounds::eHalfLengthXposY);
0074   double y3 = get(DiamondBounds::eHalfLengthYpos);
0075   return {{-x1, -y1}, {x1, -y1}, {x2, y2}, {x3, y3}, {-x3, y3}, {-x2, y2}};
0076 }
0077 
0078 const RectangleBounds& DiamondBounds::boundingBox() const {
0079   return m_boundingBox;
0080 }
0081 
0082 Vector2 DiamondBounds::center() const {
0083   // The diamond is symmetric about both x and y axes,
0084   // so centroid is at origin
0085   return Vector2::Zero();
0086 }
0087 
0088 std::ostream& DiamondBounds::toStream(std::ostream& sl) const {
0089   detail::OstreamStateGuard guard{sl};
0090   sl << std::fixed << std::setprecision(7);
0091   sl << "Acts::DiamondBounds: (halfXatYneg, halfXatYzero, halfXatYpos, "
0092         "halfYneg, halfYpos) = ";
0093   sl << "(" << get(DiamondBounds::eHalfLengthXnegY) << ", "
0094      << get(DiamondBounds::eHalfLengthXzeroY) << ", "
0095      << get(DiamondBounds::eHalfLengthXposY) << ", "
0096      << get(DiamondBounds::eHalfLengthYneg) << ", "
0097      << get(DiamondBounds::eHalfLengthYpos) << ")";
0098   return sl;
0099 }
0100 
0101 }  // namespace Acts