2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
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(); \
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())<<"]"); \
26 using CheckVector2D = RadialStripDesign::CheckVector2D;
27 inline int RadialStripDesign::numStrips() const { return m_strips.size() -1; }
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()));
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()));
42 inline double RadialStripDesign::stripLength(int stripNumb) const {
43 CHECK_STRIPRANGESCAL(stripNumb);
44 return m_strips[stripCh].fromBottomToTop().mag();
46 inline Amg::Vector2D RadialStripDesign::stripLeftEdge(int stripNumber) const{
47 CHECK_STRIPRANGE(stripNumber);
48 return m_strips[stripCh].fromBottomToTop().unit();
50 inline Amg::Vector2D RadialStripDesign::stripRightEdge(int stripNumber) const {
51 CHECK_STRIPRANGE(stripNumber);
52 return m_strips[stripCh + 1].fromBottomToTop().unit();
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();
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);
63 inline Amg::Vector2D RadialStripDesign::stripEdges::bottomMounting() const{
64 return parent.cornerBotLeft() + distOnBottom * parent.edgeDirBottom();
66 inline Amg::Vector2D RadialStripDesign::stripEdges::topMounting() const {
67 return parent.cornerTopLeft() + distOnTop * parent.edgeDirTop();
69 inline Amg::Vector2D RadialStripDesign::stripEdges::fromBottomToTop() const {
70 return topMounting() - bottomMounting();
72 inline Amg::Vector2D RadialStripDesign::stripEdges::center() const {
73 return 0.5*(topMounting() + bottomMounting());
75 inline Amg::Vector2D RadialStripDesign::stripLeftBottom(int stripNumber) const{
76 CHECK_STRIPRANGE(stripNumber);
77 return m_strips[stripCh].bottomMounting();
79 inline Amg::Vector2D RadialStripDesign::stripRightBottom(int stripNumber) const{
80 CHECK_STRIPRANGE(stripNumber);
81 return m_strips[stripCh+1].bottomMounting();
83 inline Amg::Vector2D RadialStripDesign::stripLeftTop(int stripNumber) const{
84 CHECK_STRIPRANGE(stripNumber);
85 return m_strips[stripCh].topMounting();
87 inline Amg::Vector2D RadialStripDesign::stripRightTop(int stripNumber) const{
88 CHECK_STRIPRANGE(stripNumber);
89 return m_strips[stripCh+1].topMounting();
91 inline double RadialStripDesign::stripPitch(int stripNumb) const {
92 CHECK_STRIPRANGESCAL(stripNumb);
94 return 0.5*(m_strips[stripCh].center() - m_strips[stripCh+1].center()).mag();
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");
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;
111 if (itr == m_strips.end() || m_strips.begin() == itr) {
114 return std::distance(m_strips.begin(), itr) -1 + firstStripNumber();
117 #undef CHECK_STRIPRANGE
118 #undef CHECK_STRIPRANGESCAL