ATLAS Offline Software
MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
5 
13 #include <limits>
14 
15 namespace {
16  using ChIndex = Muon::MuonStationIndex::ChIndex;
17  template <class T>
21  template <class ReadOutEleStoreType,
22  class ReadoutEleReturnType> void insert(const ElementStorage_t<ReadOutEleStoreType>& eleStore,
23  std::vector<ReadoutEleReturnType>& returnVec) {
24  returnVec.reserve(returnVec.capacity() + eleStore.size());
25  for (const auto& ele : eleStore) {
26  if (ele) returnVec.push_back(ele.get());
27  }
28  }
29  template <class ReadOutEleType,
30  class ReadOutEleReturnType> void insert(std::vector<ReadOutEleType*>&& eleStore,
31  std::vector<ReadOutEleReturnType*>& returnVec) {
32  returnVec.insert(returnVec.end(),
33  std::make_move_iterator(eleStore.begin()),
34  std::make_move_iterator(eleStore.end()));
35  }
36 #ifndef SIMULATIONBASE
37  inline unsigned msSectorIdHash(const ChIndex chIndex, const int sector, const int side) {
38  constexpr unsigned chIdxMax = static_cast<unsigned>(ChIndex::ChIndexMax);
39  const unsigned secMax = Muon::MuonStationIndex::numberOfSectors()/2;
40  const unsigned stationPhi = (sector + sector%2) / 2 - 1;
41  return stationPhi + static_cast<unsigned>(chIndex)* secMax + (side <0) * chIdxMax * secMax;
42  }
43 #endif
44 }
45 
46 #define WRITE_SETTER(ELE_TYPE, SETTER, STORAGE_VEC) \
47  StatusCode MuonDetectorManager::SETTER(ElementPtr_t<ELE_TYPE> element) { \
48  if (!element) { \
49  ATH_MSG_FATAL(__func__ << " -- nullptr is given."); \
50  return StatusCode::FAILURE; \
51  } \
52  ATH_CHECK(element->initElement()); \
53  element->releaseUnAlignedTrfs(); \
54  size_t idx = static_cast<size_t>(element->identHash()); \
55  if (idx >= STORAGE_VEC.size()) { \
56  STORAGE_VEC.resize(idx + 1); \
57  } \
58  std::unique_ptr<ELE_TYPE>& new_element = STORAGE_VEC[idx]; \
59  if (new_element) { \
60  ATH_MSG_FATAL("The detector element " \
61  << m_idHelperSvc->toStringDetEl(element->identify()) \
62  << " has already been added before " \
63  <<m_idHelperSvc->toStringDetEl(new_element->identify())); \
64  return StatusCode::FAILURE; \
65  } \
66  linkElements(STORAGE_VEC, element.get()); \
67  new_element = std::move(element); \
68  return StatusCode::SUCCESS; \
69  }
70 #define ADD_DETECTOR(ELE_TYPE, STORAGE_VEC) \
71  WRITE_SETTER(ELE_TYPE, add##ELE_TYPE, STORAGE_VEC) \
72  \
73  std::vector<const ELE_TYPE*> MuonDetectorManager::getAll##ELE_TYPE##s() const { \
74  std::vector<const ELE_TYPE*> allElements{}; \
75  insert(STORAGE_VEC, allElements); \
76  return allElements; \
77  } \
78  \
79  std::vector<ELE_TYPE*> MuonDetectorManager::getAll##ELE_TYPE##s() { \
80  std::vector<ELE_TYPE*> allElements{}; \
81  insert(STORAGE_VEC, allElements); \
82  return allElements; \
83  }
84 #define WRITE_ALLGETTER(TYPE) \
85  std::vector<TYPE MuonReadoutElement*> MuonDetectorManager::getAllReadoutElements() TYPE { \
86  std::vector<TYPE MuonReadoutElement*> allEles{}; \
87  insert(getAllMdtReadoutElements(), allEles); \
88  insert(getAllRpcReadoutElements(), allEles); \
89  insert(getAllTgcReadoutElements(), allEles); \
90  insert(getAllMmReadoutElements(), allEles); \
91  insert(getAllsTgcReadoutElements(), allEles); \
92  return allEles; \
93  } \
94  TYPE MuonReadoutElement* MuonDetectorManager::getReadoutElement(const Identifier& id) TYPE { \
95  switch(m_idHelperSvc->technologyIndex(id)) { \
96  using enum Muon::MuonStationIndex::TechnologyIndex; \
97  case MDT: \
98  return getMdtReadoutElement(id); \
99  case RPC: \
100  return getRpcReadoutElement(id); \
101  case TGC: \
102  return getTgcReadoutElement(id); \
103  case STGC: \
104  return getsTgcReadoutElement(id); \
105  case MM: \
106  return getMmReadoutElement(id); \
107  default: \
108  ATH_MSG_WARNING(__FILE__<<":"<<__LINE__<<" Not a muon detector element " \
109  <<m_idHelperSvc->toString(id)); \
110  } \
111  return nullptr; \
112  }
113 
114 
115 namespace MuonGMR4 {
116 
117 #ifndef SIMULATIONBASE
120 
122  return (*a) < (*b);
123  }
125  return (*a) < (*b);
126  }
127 #endif
129 #ifndef SIMULATIONBASE
130  m_secEnvelopes.clear();
131 #endif
132 }
134  : AthMessaging{"MuonDetectorManagerR4"} {
135  if (!m_idHelperSvc.retrieve().isSuccess()) {
136  THROW_EXCEPTION(__func__<< "() -- Failed to retrieve the Identifier service");
137  }
138  setName("MuonR4");
139 }
140 
141 WRITE_ALLGETTER(const)
148 
149 unsigned int MuonDetectorManager::getNumTreeTops() const {
150  return m_treeTopVector.size();
151 }
152 PVConstLink MuonDetectorManager::getTreeTop(unsigned int i) const {
153  return m_treeTopVector[i];
154 }
155 
157  m_treeTopVector.push_back(pv);
158 }
160  return m_idHelperSvc.get();
161 }
162 std::vector<ActsTrk::DetectorType> MuonDetectorManager::getDetectorTypes() const {
163  std::vector<ActsTrk::DetectorType> types{};
164  if (!m_mdtEles.empty()) types.push_back(ActsTrk::DetectorType::Mdt);
165  if (!m_tgcEles.empty()) types.push_back(ActsTrk::DetectorType::Tgc);
166  if (!m_rpcEles.empty()) types.push_back(ActsTrk::DetectorType::Rpc);
167  if (!m_sTgcEles.empty()) types.push_back(ActsTrk::DetectorType::sTgc);
168  if (!m_mmEles.empty()) types.push_back(ActsTrk::DetectorType::Mm);
169  return types;
170 }
171 
172 #ifndef SIMULATIONBASE
174  const unsigned hash = msSectorIdHash(chSector->chamberIndex(), chSector->sector(), chSector->side());
175  ATH_MSG_DEBUG("Add new sector "<<(*chSector)<<", hash: "<<hash);
176  const auto [element, isNew] = m_envelopesById.insert(std::make_pair(hash, chSector.get()));
177  if (!isNew) {
178  ATH_MSG_DEBUG("Conflicting hash: "<<hash<<", inserted: "<<element->second->chambers().size()
179  <<", "<<chSector->chambers().size());
180  if (element->second->chambers().size() < chSector->chambers().size()) {
181  element->second = chSector.get();
182  }
183  }
184  m_secEnvelopes.push_back(std::move(chSector));
185  }
187  const unsigned sector,
188  const int side) const {
189  const unsigned hash = msSectorIdHash(chIdx, sector, side);
190  EnvelopeMap_t::const_iterator itr = m_envelopesById.find(hash);
191  if (itr != m_envelopesById.end()) {
192  return itr->second;
193  }
194  ATH_MSG_WARNING("Failed to fetch valid envelope for "<<Muon::MuonStationIndex::chName(chIdx)
195  <<", sector: "<<sector<<", side: "<<side);
196  return nullptr;
197  }
200  }
205  }
208  MuonSectorSet sectors{};
209  std::ranges::for_each(m_secEnvelopes,
210  [&sectors](const ElementPtr_t<SpectrometerSector>& ms){
211  sectors.insert(ms.get());
212  });
213  return sectors;
214  }
216  MuonChamberSet chambers{};
217  std::ranges::for_each(m_secEnvelopes,
218  [&chambers](const ElementPtr_t<SpectrometerSector>& ms){
219  std::ranges::for_each(ms->chambers(),
220  [&chambers](const SpectrometerSector::ChamberPtr& ch){
221  chambers.insert(ch.get());
222  });
223  });
224  return chambers;
225  }
226 #endif
227 
229  MuonDetectorType* reEle) {
230  ATH_MSG_VERBOSE("No inter-linking for "<<ActsTrk::to_string(reEle->detectorType())<<" "<<detStore.size());
231 }
233  MdtReadoutElement* refEle) {
234  const MdtIdHelper& idHelper{m_idHelperSvc->mdtIdHelper()};
235  const int complMl = refEle->multilayer() == 2 ? 1 : idHelper.multilayerMax(refEle->identify());
236  const Identifier complMlId = idHelper.multilayerID(refEle->identify(), complMl);
237  const unsigned mlHash =static_cast<unsigned>(m_idHelperSvc->detElementHash(complMlId));
239  if (mlHash >= detStore.size() || !detStore[mlHash]) {
240  return;
241  }
242  detStore[mlHash]->setComplementaryReadoutEle(refEle);
243  refEle->setComplementaryReadoutEle(detStore[mlHash].get());
244 
245 }
246 
247 
248 } // namespace MuonGMR4
249 #undef WRITE_SETTER
250 #undef ADD_DETECTOR
251 #undef WRITE_ALLGETTER
Muon::MuonStationIndex::chName
static const std::string & chName(ChIndex index)
convert ChIndex into a string
Definition: MuonStationIndex.cxx:157
Muon::nsw::STGTPSegments::moduleIDBits::stationPhi
constexpr uint8_t stationPhi
station Phi 1 to 8
Definition: NSWSTGTPDecodeBitmaps.h:161
GeoModel::TransientConstSharedPtr
The TransientConstSharedPtr allows non-const access if the pointer itself is non-const but in the con...
Definition: TransientConstSharedPtr.h:13
MuonGMR4::MmReadoutElement
Definition: MmReadoutElement.h:19
MuonGMR4::MuonDetectorManager::getDetectorTypes
std::vector< ActsTrk::DetectorType > getDetectorTypes() const
Returns a list of all detector types.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:162
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
MuonGMR4::MuonSectorSet
MuonDetectorManager::MuonSectorSet MuonSectorSet
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:118
MuonGMR4::MuonReadoutElement::chamber
const Chamber * chamber() const
Returns the pointer to the chamber enclosing this readout element.
MuonGMR4::MuonDetectorManager::m_sTgcEles
ElementStorage_t< sTgcReadoutElement > m_sTgcEles
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:152
MuonGMR4::MuonReadoutElement::msSector
const SpectrometerSector * msSector() const
Returns the pointer to the envelope volume enclosing all chambers in the sector.
MuonGMR4::SpectrometerSector
A spectrometer sector forms the envelope of all chambers that are placed in the same MS sector & laye...
Definition: SpectrometerSector.h:41
MuonGMR4::MuonDetectorManager::MuonSectorSet
std::set< const SpectrometerSector *, MSEnvelopeSorter > MuonSectorSet
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:123
AthCheckMacros.h
MuonGMR4::MuonDetectorManager::linkElements
void linkElements(ElementStorage_t< MuonDetectorType > &allStore, MuonDetectorType *readOutEle)
Method that connects the same elements from the station with the parsed readout Element and vice vers...
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:228
MuonGMR4::MuonDetectorManager
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:62
ActsTrk::DetectorType::Tgc
@ Tgc
Resitive Plate Chambers.
MuonGMR4::MuonDetectorManager::MuonDetectorManager
MuonDetectorManager()
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:133
MuonGMR4::MuonDetectorManager::ElementPtr_t
std::unique_ptr< MuonDetectorType > ElementPtr_t
: Abrivation of the smart pointer holding the readout element
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:70
MuonGMR4::MuonDetectorManager::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:141
MuonGMR4::MuonDetectorManager::m_envelopesById
EnvelopeMap_t m_envelopesById
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:147
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ActsTrk::DetectorType::sTgc
@ sTgc
Micromegas (NSW)
SpectrometerSector.h
python.SystemOfUnits.ms
int ms
Definition: SystemOfUnits.py:132
MuonGMR4::RpcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/RpcReadoutElement.h:17
Muon::MuonStationIndex::numberOfSectors
static unsigned int numberOfSectors()
return total number of sectors
Definition: MuonStationIndex.h:106
TRT::Hit::side
@ side
Definition: HitInfo.h:83
MuonGMR4::MdtReadoutElement::multilayer
unsigned int multilayer() const
Returns the multi layer of the MdtReadoutElement.
MuonGMR4::Chamber
Definition: Chamber.h:22
sTgcReadoutElement.h
MuonGMR4::MuonDetectorManager::getChamber
const Chamber * getChamber(const Identifier &channelId) const
Retrieves the chamber enclosing the channel's readout element.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:203
MuonGMR4
The ReadoutGeomCnvAlg converts the Run4 Readout geometry build from the GeoModelXML into the legacy M...
Definition: MdtCalibInput.h:19
ActsTrk::DetectorType::Mm
@ Mm
Maybe not needed in the migration.
lumiFormat.i
int i
Definition: lumiFormat.py:85
MuonGMR4::MuonDetectorManager::ElementStorage_t
std::vector< ElementPtr_t< MuonDetectorType > > ElementStorage_t
: Abbrivation of the container holding all readout elements of a technology.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:73
WRITE_ALLGETTER
#define WRITE_ALLGETTER(TYPE)
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:84
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonGMR4::MuonDetectorManager::MuonChamberSet
std::set< const Chamber *, MSEnvelopeSorter > MuonChamberSet
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:124
MuonDetectorManager.h
MdtIdHelper
Definition: MdtIdHelper.h:61
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
MuonGMR4::ADD_DETECTOR
ADD_DETECTOR(MdtReadoutElement, m_mdtEles)
MuonGMR4::MuonDetectorManager::~MuonDetectorManager
~MuonDetectorManager()
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:128
CaloCondBlobAlgs_fillNoiseFromASCII.channelId
channelId
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:122
MuonGMR4::MuonChamberSet
MuonDetectorManager::MuonChamberSet MuonChamberSet
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:119
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
MuonGMR4::MuonDetectorManager::getTreeTop
PVConstLink getTreeTop(unsigned int i) const override final
Returns the i-the tree top GeoModel volume.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:152
MuonGMR4::MuonDetectorManager::m_treeTopVector
std::vector< PVConstLink > m_treeTopVector
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:155
ActsTrk::DetectorType::Mdt
@ Mdt
MuonSpectrometer.
MuonGMR4::MuonDetectorManager::m_secEnvelopes
ElementStorage_t< SpectrometerSector > m_secEnvelopes
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:144
MuonGMR4::MdtReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MdtReadoutElement.h:22
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
MuonGMR4::MuonDetectorManager::addTreeTop
void addTreeTop(PVConstLink pv)
Adds a new GeoModelVolume with its children as a new top node of the muon system.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:156
MuonGMR4::MuonReadoutElement::identify
Identifier identify() const override final
Return the athena identifier.
THROW_EXCEPTION
#define THROW_EXCEPTION(MESSAGE)
Definition: throwExcept.h:10
MuonGMR4::sTgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/sTgcReadoutElement.h:21
RpcReadoutElement.h
MuonGMR4::MuonDetectorManager::getAllSectors
MuonSectorSet getAllSectors() const
: Returns all MuonChambers associated with the readout geometry
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:207
a
TList * a
Definition: liststreamerinfos.cxx:10
MuonGMR4::MuonDetectorManager::m_mmEles
ElementStorage_t< MmReadoutElement > m_mmEles
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:153
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
MdtReadoutElement.h
MuonGMR4::MdtReadoutElement::setComplementaryReadoutEle
void setComplementaryReadoutEle(const MdtReadoutElement *other)
Set the link to the second readout element inside the muon station.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MdtReadoutElement.cxx:207
MuonGMR4::MuonDetectorManager::idHelperSvc
const Muon::IMuonIdHelperSvc * idHelperSvc() const
Returns a pointer to the central MuonIdHelperSvc.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:159
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
python.changerun.pv
pv
Definition: changerun.py:81
ActsTrk::DetectorType::Rpc
@ Rpc
Monitored Drift Tubes.
Muon::IMuonIdHelperSvc
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
Definition: IMuonIdHelperSvc.h:27
MuonGMR4::MuonDetectorManager::m_mdtEles
ElementStorage_t< MdtReadoutElement > m_mdtEles
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:149
Muon::MuonStationIndex::ChIndex
ChIndex
enum to classify the different chamber layers in the muon spectrometer
Definition: MuonStationIndex.h:15
MuonGMR4::MuonDetectorManager::addSpectrometerSector
void addSpectrometerSector(ElementPtr_t< SpectrometerSector > &&chSector)
Add a spectrometer enevelope object to the manager.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:173
MuonGMR4::MuonDetectorManager::MSEnvelopeSorter::operator()
bool operator()(const SpectrometerSector *a, const SpectrometerSector *b) const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:121
MuonGMR4::MuonDetectorManager::getAllChambers
MuonChamberSet getAllChambers() const
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:215
MuonGMR4::MuonDetectorManager::m_rpcEles
ElementStorage_t< RpcReadoutElement > m_rpcEles
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:151
TgcReadoutElement.h
MuonGMR4::TgcReadoutElement
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/TgcReadoutElement.h:19
MuonGMR4::MuonDetectorManager::m_tgcEles
ElementStorage_t< TgcReadoutElement > m_tgcEles
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/MuonReadoutGeometryR4/MuonDetectorManager.h:150
MmReadoutElement.h
MuonGMR4::MuonDetectorManager::getSectorEnvelope
const SpectrometerSector * getSectorEnvelope(const Identifier &channelId) const
Retrieves the spectrometer envelope enclosing the channel's readout element.
Definition: MuonPhaseII/MuonDetDescr/MuonReadoutGeometryR4/src/MuonDetectorManager.cxx:198
MuonGMR4::MuonDetectorManager::getReadoutElement
const MuonReadoutElement * getReadoutElement(const Identifier &id) const
Returns a generic Muon readout element.
Muon::chIdxMax
constexpr int chIdxMax
Definition: MuonSegmentPlots.cxx:14
Identifier
Definition: IdentifierFieldParser.cxx:14