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/DiscTrapezoidBounds.hpp"
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0013 #include "Acts/Surfaces/detail/BoundaryCheckHelper.hpp"
0014 #include "Acts/Utilities/detail/periodic.hpp"
0015 
0016 #include <cmath>
0017 #include <iomanip>
0018 #include <iostream>
0019 #include <stdexcept>
0020 
0021 namespace Acts {
0022 
0023 DiscTrapezoidBounds::DiscTrapezoidBounds(double halfXminR, double halfXmaxR,
0024                                          double minR, double maxR,
0025                                          double avgPhi,
0026                                          double stereo) noexcept(false)
0027     : m_values({halfXminR, halfXmaxR, minR, maxR, avgPhi, stereo}) {
0028   checkConsistency();
0029   m_ymax = std::sqrt(get(eMaxR) * get(eMaxR) -
0030                      get(eHalfLengthXmaxR) * get(eHalfLengthXmaxR));
0031 }
0032 
0033 std::vector<double> DiscTrapezoidBounds::values() const {
0034   return {m_values.begin(), m_values.end()};
0035 }
0036 
0037 void DiscTrapezoidBounds::checkConsistency() noexcept(false) {
0038   if (get(eMinR) < 0. || get(eMaxR) <= 0. || get(eMinR) > get(eMaxR)) {
0039     throw std::invalid_argument("DiscTrapezoidBounds: invalid radial setup.");
0040   }
0041   if (get(eHalfLengthXminR) < 0. || get(eHalfLengthXmaxR) <= 0.) {
0042     throw std::invalid_argument("DiscTrapezoidBounds: negative length given.");
0043   }
0044   if (get(eAveragePhi) != detail::radian_sym(get(eAveragePhi))) {
0045     throw std::invalid_argument(
0046         "DiscTrapezoidBounds: invalid phi positioning.");
0047   }
0048 }
0049 
0050 Vector2 DiscTrapezoidBounds::toLocalCartesian(const Vector2& lposition) const {
0051   return {lposition[0] * std::sin(lposition[1] - get(eAveragePhi)),
0052           lposition[0] * std::cos(lposition[1] - get(eAveragePhi))};
0053 }
0054 
0055 SquareMatrix2 DiscTrapezoidBounds::jacobianToLocalCartesian(
0056     const Vector2& lposition) const {
0057   SquareMatrix2 jacobian;
0058   jacobian(0, 0) = std::sin(lposition[1] - get(eAveragePhi));
0059   jacobian(1, 0) = std::cos(lposition[1] - get(eAveragePhi));
0060   jacobian(0, 1) = lposition[0] * std::cos(lposition[1]);
0061   jacobian(1, 1) = lposition[0] * -std::sin(lposition[1]);
0062   return jacobian;
0063 }
0064 
0065 bool DiscTrapezoidBounds::inside(
0066     const Vector2& lposition,
0067     const BoundaryTolerance& boundaryTolerance) const {
0068   Vector2 vertices[] = {{get(eHalfLengthXminR), get(eMinR)},
0069                         {get(eHalfLengthXmaxR), m_ymax},
0070                         {-get(eHalfLengthXmaxR), m_ymax},
0071                         {-get(eHalfLengthXminR), get(eMinR)}};
0072   auto jacobian = jacobianToLocalCartesian(lposition);
0073   return detail::insidePolygon(vertices, boundaryTolerance,
0074                                toLocalCartesian(lposition), jacobian);
0075 }
0076 
0077 std::vector<Vector2> DiscTrapezoidBounds::vertices(
0078     unsigned int /*ignoredSegments*/) const {
0079   Vector2 cAxis(std::cos(get(eAveragePhi)), std::sin(get(eAveragePhi)));
0080   Vector2 nAxis(cAxis.y(), -cAxis.x());
0081   auto ymin = std::sqrt(get(eMinR) * get(eMinR) -
0082                         get(eHalfLengthXminR) * get(eHalfLengthXminR));
0083   auto halfY = (m_ymax - ymin) / 2;
0084   return {-halfY * cAxis - get(eHalfLengthXminR) * nAxis,
0085           -halfY * cAxis + get(eHalfLengthXminR) * nAxis,
0086           halfY * cAxis + get(eHalfLengthXmaxR) * nAxis,
0087           halfY * cAxis - get(eHalfLengthXmaxR) * nAxis};
0088 }
0089 
0090 std::ostream& DiscTrapezoidBounds::toStream(std::ostream& sl) const {
0091   sl << std::setiosflags(std::ios::fixed);
0092   sl << std::setprecision(7);
0093   sl << "Acts::DiscTrapezoidBounds: (innerRadius, outerRadius, "
0094         "halfLengthXminR, "
0095         "halfLengthXmaxR, halfLengthY, halfPhiSector, averagePhi, rCenter, "
0096         "stereo) = ";
0097   sl << "(" << get(eMinR) << ", " << get(eMaxR) << ", " << get(eHalfLengthXminR)
0098      << ", " << get(eHalfLengthXmaxR) << ", " << halfLengthY() << ", "
0099      << halfPhiSector() << ", " << get(eAveragePhi) << ", " << rCenter() << ", "
0100      << stereo() << ")";
0101   sl << std::setprecision(-1);
0102   return sl;
0103 }
0104 
0105 }  // namespace Acts