Back to home page

EIC code displayed by LXR

 
 

    


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

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/BoundaryTolerance.hpp"
0013 #include "Acts/Surfaces/detail/BoundaryCheckHelper.hpp"
0014 
0015 #include <iomanip>
0016 #include <iostream>
0017 #include <optional>
0018 #include <stdexcept>
0019 
0020 namespace Acts {
0021 
0022 std::vector<double> DiamondBounds::values() const {
0023   return {m_values.begin(), m_values.end()};
0024 }
0025 
0026 void DiamondBounds::checkConsistency() noexcept(false) {
0027   if (std::ranges::any_of(m_values, [](auto v) { return v <= 0.; })) {
0028     throw std::invalid_argument("DiamondBounds: negative half length.");
0029   }
0030   if (get(eHalfLengthXnegY) > get(eHalfLengthXzeroY) ||
0031       get(eHalfLengthXposY) > get(eHalfLengthXzeroY)) {
0032     throw std::invalid_argument("DiamondBounds: not a diamond shape.");
0033   }
0034 }
0035 
0036 bool DiamondBounds::inside(const Vector2& lposition,
0037                            const BoundaryTolerance& boundaryTolerance) const {
0038   // Vertices starting at lower left (min rel. phi)
0039   // counter-clockwise
0040   double x1 = get(DiamondBounds::eHalfLengthXnegY);
0041   double y1 = get(DiamondBounds::eHalfLengthYneg);
0042   double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0043   double y2 = 0.;
0044   double x3 = get(DiamondBounds::eHalfLengthXposY);
0045   double y3 = get(DiamondBounds::eHalfLengthYpos);
0046   Vector2 vertices[] = {{-x1, -y1}, {x1, -y1}, {x2, y2},
0047                         {x3, y3},   {-x3, y3}, {-x2, y2}};
0048   return detail::insidePolygon(vertices, boundaryTolerance, lposition,
0049                                std::nullopt);
0050 }
0051 
0052 std::vector<Vector2> DiamondBounds::vertices(
0053     unsigned int /*ignoredSegments*/) const {
0054   // Vertices starting at lower left (min rel. phi)
0055   // counter-clockwise
0056   double x1 = get(DiamondBounds::eHalfLengthXnegY);
0057   double y1 = get(DiamondBounds::eHalfLengthYneg);
0058   double x2 = get(DiamondBounds::eHalfLengthXzeroY);
0059   double y2 = 0.;
0060   double x3 = get(DiamondBounds::eHalfLengthXposY);
0061   double y3 = get(DiamondBounds::eHalfLengthYpos);
0062   return {{-x1, -y1}, {x1, -y1}, {x2, y2}, {x3, y3}, {-x3, y3}, {-x2, y2}};
0063 }
0064 
0065 const RectangleBounds& DiamondBounds::boundingBox() const {
0066   return m_boundingBox;
0067 }
0068 
0069 std::ostream& DiamondBounds::toStream(std::ostream& sl) const {
0070   sl << std::setiosflags(std::ios::fixed);
0071   sl << std::setprecision(7);
0072   sl << "Acts::DiamondBounds: (halfXatYneg, halfXatYzero, halfXatYpos, "
0073         "halfYneg, halfYpos) = ";
0074   sl << "(" << get(DiamondBounds::eHalfLengthXnegY) << ", "
0075      << get(DiamondBounds::eHalfLengthXzeroY) << ", "
0076      << get(DiamondBounds::eHalfLengthXposY) << ", "
0077      << get(DiamondBounds::eHalfLengthYneg) << ", "
0078      << get(DiamondBounds::eHalfLengthYpos) << ")";
0079   sl << std::setprecision(-1);
0080   return sl;
0081 }
0082 
0083 }  // namespace Acts