ATLAS Offline Software
Loading...
Searching...
No Matches
ExpandedSector.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
7
8
9#include "GeoModelKernel/throwExcept.h"
10
11#include "Acts/Utilities/Helpers.hpp"
12#include "Acts/Utilities/UnitVectors.hpp"
13#include "Acts/Definitions/Units.hpp"
14
15#include <cassert>
16using namespace Acts::UnitLiterals;
17using namespace Muon::MuonStationIndex;
18
19namespace{
20 static const Muon::MuonSectorMapping sectorMap{};
21 using SectorProjector = MuonR4::ExpandedSector::SectorProjector;
22 constexpr std::int8_t nExpanded = 2*numberOfSectors();
23
24 inline std::tuple<unsigned, SectorProjector> msSectorAndProj(const std::int8_t expandSector) {
25 assert (expandSector >= 0 && expandSector <= nExpanded);
26 if (expandSector == 0) {
27 return std::make_tuple(numberOfSectors(), SectorProjector::center);
28 } else if (expandSector == 1) {
29 return std::make_tuple(numberOfSectors(), SectorProjector::rightOverlap);
30 }
31 const int regSector = expandSector / 2;
32 const int backConv = expandSector - 2*regSector;
33 switch (backConv) {
34 case 1: return std::make_tuple(regSector, SectorProjector::rightOverlap);
35 case 0: return std::make_tuple(regSector, SectorProjector::center);
36 case -1: return std::make_tuple(regSector, SectorProjector::leftOverlap);
37 default:
38 THROW_EXCEPTION("Cannot deduce the sector overlap "<<expandSector);
39 }
40 //all cases have been addressed
41 }
42
43}
44namespace MuonR4 {
45
46 ExpandedSector::ExpandedSector(const std::int8_t expSector):
47 m_sector{expSector}{}
49 const SectorProjector proj) {
50 m_sector = (2*msSector + Acts::toUnderlying(proj)) % nExpanded;
51 }
52
54 std::vector<int> sectors{};
55 sectorMap.getSectors(phi, sectors);
56 assert(!sectors.empty());
57 if (sectors.size() == 1) {
58 (*this) = ExpandedSector{static_cast<unsigned>(sectors[0]), SectorProjector::center};
59 } else {
60 const int dS = (sectors[1] - sectors[0]) % numberOfSectors();
61 assert(std::abs(dS) == 1);
62 (*this) = ExpandedSector{static_cast<unsigned>(sectors[0]),
63 static_cast<SectorProjector>(dS)};
64 }
65 }
66
68 return std::get<1>(msSectorAndProj(sector()));
69 }
70 unsigned ExpandedSector::msSector() const {
71 return std::get<0>(msSectorAndProj(sector()));
72 }
73 std::int8_t ExpandedSector::sector() const {
74 return m_sector;
75 }
77 const auto [msSec, proj] = msSectorAndProj(sector());
78 if (msSec == 1 && proj == SectorProjector::leftOverlap){
79 return numberOfSectors();
80 } else if (msSec == numberOfSectors() && proj == SectorProjector::rightOverlap) {
81 return 1;
82 }
83 return msSec + Acts::toUnderlying(proj);
84
85 }
87 unsigned sector1 {msSector()};
88 unsigned sector2 {adjacentMsSector()};
89
90 if (sector1 == sector2) {
91 return sectorMap.sectorSize(sector1);
92 }
94 return sectorMap.sectorWidth(sector1) - sectorMap.sectorSize(sector1);
95 }
96 bool ExpandedSector::operator<(const ExpandedSector& other) const {
97 return sector() < other.sector();
98 }
99 bool ExpandedSector::operator==(const ExpandedSector& other) const {
100 return sector() == other.sector();
101 }
103 return sector() != other.sector();
104 }
105 double ExpandedSector::phi() const {
106 return sectorMap.sectorOverlapPhi(msSector(), adjacentMsSector());
107 }
109 return Acts::makeDirectionFromPhiTheta(phi(), 90._degree);
110 }
112 return Acts::makeDirectionFromPhiTheta(phi() + 90._degree, 90._degree);
113 }
115 const int dS = std::abs(other.sector() - sector());
116 return std::min(dS, nExpanded - dS) <= 1;
117 }
118
120 switch (proj){
121 using enum SectorProjector;
122 case leftOverlap: return "leftOverlap";
123 case center: return "center";
124 case rightOverlap: return "rightOverlap";
125 }
126 return "";
127 }
128 std::ostream& ExpandedSector::toString(std::ostream& ostr)const {
129 ostr<<"Expanded sector: "<<static_cast<int>(sector()) <<" -> "
130 <<projector()<<" of sector "<<msSector();
131 return ostr;
132 }
133}
double phi() const
Returns the phi angle of the expanded sector.
Amg::Vector3D normalDir() const
Returns the vector that is normal to the plane spanned by the expanded sector.
std::int8_t m_sector
the sector number stored
bool operator==(const ExpandedSector &other) const
Define the equal operator.
SectorProjector
Enumeration to select the sector projection of the regular MS sector.
@ rightOverlap
Project the segment onto the sector centre.
@ center
Project the segment onto the overlap with the previous sector.
ExpandedSector(const unsigned msSector, const SectorProjector proj)
Constructor of the expanded sector taking the regular MS sector number and the projector.
double sectorSize() const
Return the expanded sector (half) size.
unsigned msSector() const
Returns the ms sector corresponding to the expanded sector.
std::int8_t sector() const
Returns the expanded sector number.
SectorProjector projector() const
Returns the projector in the corresponding MS sector.
bool isNeighbour(const ExpandedSector &other) const
Returns true if the expanded sector is a neighbour of the other.
bool operator!=(const ExpandedSector &other) const
Define the unequal operator.
unsigned adjacentMsSector() const
Returns the neighbouring msSector number constructed from the primary sector and the sector overlap p...
Amg::Vector3D radialDir() const
Returns the vector pointing radially along the sector plane.
static std::string toString(const SectorProjector proj)
Return the projector as a string.
bool operator<(const ExpandedSector &other) const
Define the ordering operator.
double sectorOverlapPhi(int sector1, int sector2) const
returns the phi position of the overlap between the two sectors (which have to be neighboring) in rad...
double sectorWidth(int sector) const
sector width (with overlap) in radians
void getSectors(double phi, std::vector< int > &sectors) const
returns the main sector plus neighboring if the phi position is in an overlap region
double sectorSize(int sector) const
sector size (exclusive) in radians
Eigen::Matrix< double, 3, 1 > Vector3D
This header ties the generic definitions in this package.
constexpr unsigned numberOfSectors()
return total number of sectors
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10