ATLAS Offline Software
RadialStripDesign.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 #ifndef MUONREADOUTGEOMETRYR4_RADIALSTRIPDESIGN_ICC
5 #define MUONREADOUTGEOMETRYR4_RADIALSTRIPDESIGN_ICC
6 #include <GaudiKernel/SystemOfUnits.h>
7 /// Helper macro to shift the strip number and check that's valid
8 #define CHECK_STRIPRANGE(STRIP_NUM) \
9  const int stripCh = (STRIP_NUM - firstStripNumber()); \
10  if (stripCh < 0 || stripCh >= numStrips()) { \
11  ATH_MSG_WARNING(__func__<<"() -- Invalid strip number given " \
12  <<STRIP_NUM<<" allowed range [" \
13  <<firstStripNumber()<<";"<<(firstStripNumber() +numStrips())<<"]"); \
14  return Amg::Vector2D::Zero(); \
15  }
16 #define CHECK_STRIPRANGESCAL(STRIP_NUM) \
17  const int stripCh = (STRIP_NUM - firstStripNumber()); \
18  if (stripCh < 0 || stripCh >= numStrips()) { \
19  ATH_MSG_WARNING(__func__<<"() -- Invalid strip number given " \
20  <<STRIP_NUM<<" allowed range [" \
21  <<firstStripNumber()<<";"<<(firstStripNumber() +numStrips())<<"]"); \
22  return 0.; \
23  } \
24 
25 namespace MuonGMR4{
26  using CheckVector2D = RadialStripDesign::CheckVector2D;
27  inline int RadialStripDesign::numStrips() const { return m_strips.size() -1; }
28 
29  inline CheckVector2D RadialStripDesign::leftInterSect(int stripNum, bool /*uncapped*/) const {
30  /// Calculate the strip width center at the bottom edge
31  return std::make_optional<Amg::Vector2D>(0.5*(m_strips[stripNum].topMounting() +
32  m_strips[stripNum +1].topMounting()));
33  }
34 
35 
36  inline CheckVector2D RadialStripDesign::rightInterSect(int stripNum, bool /*uncapped*/) const {
37  /// Calculate the strip width center at the top edge
38  return std::make_optional<Amg::Vector2D>(0.5*(m_strips[stripNum].bottomMounting() +
39  m_strips[stripNum +1].bottomMounting()));
40  }
41 
42  inline double RadialStripDesign::stripLength(int stripNumb) const {
43  CHECK_STRIPRANGESCAL(stripNumb);
44  return m_strips[stripCh].fromBottomToTop().mag();
45  }
46  inline Amg::Vector2D RadialStripDesign::stripLeftEdge(int stripNumber) const{
47  CHECK_STRIPRANGE(stripNumber);
48  return m_strips[stripCh].fromBottomToTop().unit();
49  }
50  inline Amg::Vector2D RadialStripDesign::stripRightEdge(int stripNumber) const {
51  CHECK_STRIPRANGE(stripNumber);
52  return m_strips[stripCh + 1].fromBottomToTop().unit();
53  }
54  inline Amg::Vector2D RadialStripDesign::stripDir(int stripNumber) const {
55  CHECK_STRIPRANGE(stripNumber);
56  return (m_strips[stripCh].fromBottomToTop() + m_strips[stripCh+1].fromBottomToTop()).unit();
57  }
58  inline Amg::Vector2D RadialStripDesign::stripNormal(int stripNumber) const {
59  const Eigen::Rotation2D rotMat{(m_reversedStripOrder ? 90 : -90) * Gaudi::Units::deg};
60  return rotMat * stripDir(stripNumber);
61  }
62 
63  inline Amg::Vector2D RadialStripDesign::stripEdges::bottomMounting() const{
64  return parent.cornerBotLeft() + distOnBottom * parent.edgeDirBottom();
65  }
66  inline Amg::Vector2D RadialStripDesign::stripEdges::topMounting() const {
67  return parent.cornerTopLeft() + distOnTop * parent.edgeDirTop();
68  }
69  inline Amg::Vector2D RadialStripDesign::stripEdges::fromBottomToTop() const {
70  return topMounting() - bottomMounting();
71  }
72  inline Amg::Vector2D RadialStripDesign::stripEdges::center() const {
73  return 0.5*(topMounting() + bottomMounting());
74  }
75  inline Amg::Vector2D RadialStripDesign::stripLeftBottom(int stripNumber) const{
76  CHECK_STRIPRANGE(stripNumber);
77  return m_strips[stripCh].bottomMounting();
78  }
79  inline Amg::Vector2D RadialStripDesign::stripRightBottom(int stripNumber) const{
80  CHECK_STRIPRANGE(stripNumber);
81  return m_strips[stripCh+1].bottomMounting();
82  }
83  inline Amg::Vector2D RadialStripDesign::stripLeftTop(int stripNumber) const{
84  CHECK_STRIPRANGE(stripNumber);
85  return m_strips[stripCh].topMounting();
86  }
87  inline Amg::Vector2D RadialStripDesign::stripRightTop(int stripNumber) const{
88  CHECK_STRIPRANGE(stripNumber);
89  return m_strips[stripCh+1].topMounting();
90  }
91  inline double RadialStripDesign::stripPitch(int stripNumb) const {
92  CHECK_STRIPRANGESCAL(stripNumb);
93 
94  return 0.5*(m_strips[stripCh].center() - m_strips[stripCh+1].center()).mag();
95 
96  }
97  inline int RadialStripDesign::stripNumber(const Amg::Vector2D& extPos) const {
98  if (!insideTrapezoid(extPos)) {
99  ATH_MSG_VERBOSE("The point "<<Amg::toString(extPos)<<" is outside the active trapezoid area");
100  return -1;
101  }
102  const Eigen::Rotation2D normalRot{(m_reversedStripOrder ? 90 : -90)*Gaudi::Units::deg};
103  stripEdgeVecItr itr = std::lower_bound(m_strips.begin(), m_strips.end(), extPos,
104  [& normalRot](const stripEdges& stripPos, const Amg::Vector2D& pos) {
105  const Amg::Vector2D dir = stripPos.fromBottomToTop().unit();
106  const Amg::Vector2D normal = normalRot * dir;
107  std::optional<double> distFromBotEdge = Amg::intersect<2>(stripPos.bottomMounting(), dir, pos, normal);
108  return distFromBotEdge.value_or(1.) < 0;
109  });
110 
111  if (itr == m_strips.end() || m_strips.begin() == itr) {
112  return -1;
113  }
114  return std::distance(m_strips.begin(), itr) -1 + firstStripNumber();
115  }
116 }
117 #undef CHECK_STRIPRANGE
118 #undef CHECK_STRIPRANGESCAL
119 #endif