ATLAS Offline Software
MuonLayerHashProviderTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 
10 
12 
13 namespace Muon {
14 
15  MuonLayerHashProviderTool::MuonLayerHashProviderTool(const std::string& type, const std::string& name, const IInterface* parent):
17  m_ntechnologies(4)
18  {
19  declareInterface<MuonLayerHashProviderTool>(this);
20 
21  }
22 
24 
25  ATH_CHECK(m_idHelperSvc.retrieve());
26 
27  if( !initializeSectorMapping() ){
28  ATH_MSG_ERROR("Failed to initialize sector mapping");
29  return StatusCode::FAILURE;
30  }
31 
32  return StatusCode::SUCCESS;
33  }
34 
35 
37  insertHash(m_idHelperSvc->sector(id),hash,id);
38  }
39 
40  void MuonLayerHashProviderTool::insertHash( int sector, const IdentifierHash& hash, const Identifier& id ) {
41  MuonStationIndex::TechnologyIndex techIndex = m_idHelperSvc->technologyIndex(id);
42  int sectorLayerHash = MuonStationIndex::sectorLayerHash(m_idHelperSvc->regionIndex(id),m_idHelperSvc->layerIndex(id));
43  m_regionHashesPerSector[sector-1].technologyRegionHashVecs[techIndex][sectorLayerHash].push_back(hash);
44  }
45 
47 
48  // loop over all available STGC collection identifiers and order them per sector
50  MuonIdHelper::const_id_iterator it_end = idHelper.module_end();
51  for( ;it!=it_end; ++it ){
53  idHelper.get_module_hash(*it,hash);
54  insertHash(hash,*it);
55  }
56 
57  }
58 
60 
61  // the tgc's can be in multiple sectors so we need to do something special here
62  const MuonGM::MuonDetectorManager* detMgr = nullptr;
63  if( detStore()->retrieve( detMgr ).isFailure() || !detMgr ){
64  ATH_MSG_ERROR("Failed to initialize detector manager" );
65  return false;
66  }
67 
68  MuonSectorMapping sectorMapping;
69 
70  // loop over all available TGC collection identifiers and order them per sector
71  MuonIdHelper::const_id_iterator it = m_idHelperSvc->tgcIdHelper().module_begin();
72  MuonIdHelper::const_id_iterator it_end = m_idHelperSvc->tgcIdHelper().module_end();
73  for( ;it!=it_end; ++it ){
74  const MuonGM::TgcReadoutElement* detEl = detMgr->getTgcReadoutElement(*it);
75  if( !detEl ) {
76  ATH_MSG_DEBUG(" No detector element found for " << m_idHelperSvc->toString(*it) );
77  continue;
78  }
79  const IdentifierHash hash = m_idHelperSvc->moduleHash(*it);
80  int nstrips = detEl->nStrips(1);
81  Amg::Vector3D p1 = detEl->channelPos(1,1,1);
82  Amg::Vector3D p2 = detEl->channelPos(1,1,nstrips);
83  std::vector<int> sectors1;
84  sectorMapping.getSectors(p1.phi(),sectors1);
85  std::set<int> added;
86  std::vector<int>::iterator sit = sectors1.begin();
87  std::vector<int>::iterator sit_end = sectors1.end();
88  for( ;sit!=sit_end; ++sit ){
89  insertHash(*sit,hash,*it);
90  added.insert(*sit);
91  }
92 
93  std::vector<int> sectors2;
94  sectorMapping.getSectors(p2.phi(),sectors2);
95  sit = sectors2.begin();
96  sit_end = sectors2.end();
97  for( ;sit!=sit_end; ++sit ){
98  if( added.count(*sit) ) continue;
99  added.insert(*sit);
100  insertHash(*sit,hash,*it);
101  }
102  }
103 
104  return true;
105  }
106 
107  // all chambers are mapped onto a layer and sector map
109 
110  m_ntechnologies = m_idHelperSvc->mdtIdHelper().technologyNameIndexMax()+1;
112  // set sector numbers
113  unsigned int nsectorHashMax = MuonStationIndex::sectorLayerHashMax();
114  for( unsigned int i=0;i<m_regionHashesPerSector.size();++i ) {
115  m_regionHashesPerSector[i].sector=i+1;
116  m_regionHashesPerSector[i].technologyRegionHashVecs.resize(MuonStationIndex::TechnologyIndexMax);
117  for( auto it = m_regionHashesPerSector[i].technologyRegionHashVecs.begin();it!=m_regionHashesPerSector[i].technologyRegionHashVecs.end(); ++it ) {
118  it->resize(nsectorHashMax);
119  }
120  }
121  ATH_MSG_DEBUG("Initializing hashes: number of sectors " << MuonStationIndex::numberOfSectors()
122  << " technologies " << m_ntechnologies << " sectorLayers " << MuonStationIndex::sectorLayerHashMax() );
123 
124  // add technologies
125  if (m_idHelperSvc->hasMDT()) insertTechnology(m_idHelperSvc->mdtIdHelper());
126  if (m_idHelperSvc->hasRPC()) insertTechnology(m_idHelperSvc->rpcIdHelper());
127  if (m_idHelperSvc->hasCSC()) insertTechnology(m_idHelperSvc->cscIdHelper());
128  if (m_idHelperSvc->hasMM()) insertTechnology(m_idHelperSvc->mmIdHelper());
129  if (m_idHelperSvc->hasSTGC()) insertTechnology(m_idHelperSvc->stgcIdHelper());
130 
131  if( !insertTgcs() ) return false;
132 
133  if( msgLvl(MSG::DEBUG) ) msg(MSG::DEBUG) << " Printing collections per sector, number of technologies " << m_ntechnologies;
134  for( int sector = 1; sector<=16; ++sector ){
136  if( msgLvl(MSG::DEBUG) ) msg(MSG::DEBUG) << " sector " << sector;
137  TechnologyRegionHashVec& vec = m_regionHashesPerSector[sector-1].technologyRegionHashVecs;
138  for( unsigned int hash = 0; hash < nsectorHashMax; ++hash ){
139  std::pair<MuonStationIndex::DetectorRegionIndex,MuonStationIndex::LayerIndex> regionLayer = MuonStationIndex::decomposeSectorLayerHash(hash);
140  if( msgLvl(MSG::DEBUG) ) if( regionLayer.first != currentRegion ) msg(MSG::DEBUG) << std::endl << " " << MuonStationIndex::regionName(regionLayer.first);
141  bool first = true;
142  currentRegion = regionLayer.first;
143  for( unsigned int tech=0; tech<m_ntechnologies;++tech ){
144  std::stable_sort(vec[tech][hash].begin(),vec[tech][hash].end());
145  if( !vec[tech][hash].empty() ) {
146  if( msgLvl(MSG::DEBUG) ) {
147  if( first ) {
148  msg(MSG::DEBUG) << " " << std::setw(7) << MuonStationIndex::layerName(regionLayer.second);
149  first = false;
150  }
151  msg(MSG::DEBUG) << " " << std::setw(4) << MuonStationIndex::technologyName(static_cast<MuonStationIndex::TechnologyIndex>(tech))
152  << " " << std::setw(4) << vec[tech][hash].size();
153  }
154  }
155  }
156  }
157  if( msgLvl(MSG::DEBUG) ) msg(MSG::DEBUG) << std::endl;
158  }
160 
161  return true;
162  }
163 
164 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
Muon::MuonLayerHashProviderTool::MuonLayerHashProviderTool
MuonLayerHashProviderTool(const std::string &type, const std::string &name, const IInterface *parent)
Default AlgTool functions.
Definition: MuonLayerHashProviderTool.cxx:15
Muon::MuonLayerHashProviderTool::m_ntechnologies
unsigned int m_ntechnologies
number of technologies
Definition: MuonLayerHashProviderTool.h:75
Muon::MuonSectorMapping::getSectors
void getSectors(double phi, std::vector< int > &sectors) const
returns the main sector plus neighboring if the phi position is in an overlap region
Definition: MuonSectorMapping.h:93
Muon::MuonLayerHashProviderTool::m_regionHashesPerSector
RegionHashesPerSectorVec m_regionHashesPerSector
cachaed hash data structure
Definition: MuonLayerHashProviderTool.h:78
Muon::MuonLayerHashProviderTool::insertTgcs
bool insertTgcs()
insert hashes for the tgcs
Definition: MuonLayerHashProviderTool.cxx:59
Muon::MuonStationIndex::sectorLayerHashMax
static unsigned int sectorLayerHashMax()
maximum create a hash out of region and layer
Definition: MuonStationIndex.cxx:231
Muon::MuonStationIndex::sectorLayerHash
static unsigned int sectorLayerHash(DetectorRegionIndex detectorRegionIndex, LayerIndex layerIndex)
create a hash out of region and layer
Definition: MuonStationIndex.cxx:226
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:423
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
MuonIdHelper::module_end
const_id_iterator module_end() const
Definition: MuonIdHelper.cxx:760
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
Muon::MuonLayerHashProviderTool::insertTechnology
void insertTechnology(const MuonIdHelper &idHelper)
insert hashes of a given technology
Definition: MuonLayerHashProviderTool.cxx:46
Muon
This class provides conversion from CSC RDO data to CSC Digits.
Definition: TrackSystemController.h:49
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
MuonGM::TgcReadoutElement::channelPos
Amg::Vector3D channelPos(const Identifier &id) const
Returns the position of the active channel (wireGang or strip)
AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
Muon::MuonStationIndex::numberOfSectors
static unsigned int numberOfSectors()
return total number of sectors
Definition: MuonStationIndex.h:106
MuonGM::MuonDetectorManager::getTgcReadoutElement
const TgcReadoutElement * getTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:247
Muon::MuonStationIndex::decomposeSectorLayerHash
static std::pair< DetectorRegionIndex, LayerIndex > decomposeSectorLayerHash(unsigned int hash)
decompose the hash into Region and Layer
Definition: MuonStationIndex.cxx:237
Muon::MuonStationIndex::regionName
static const std::string & regionName(DetectorRegionIndex index)
convert DetectorRegionIndex into a string
Definition: MuonStationIndex.cxx:176
Muon::MuonLayerHashProviderTool::m_idHelperSvc
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
Definition: MuonLayerHashProviderTool.h:80
MuonIdHelper
Definition: MuonIdHelper.h:80
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MuonIdHelper::get_module_hash
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const
Definition: MuonIdHelper.cxx:98
Muon::MuonStationIndex::DetectorRegionUnknown
@ DetectorRegionUnknown
Definition: MuonStationIndex.h:48
MuonGM::TgcReadoutElement
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/TgcReadoutElement.h:42
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Muon::MuonLayerHashProviderTool::initializeSectorMapping
bool initializeSectorMapping()
initialize the mapping structure
Definition: MuonLayerHashProviderTool.cxx:108
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::MuonStationIndex::layerName
static const std::string & layerName(LayerIndex index)
convert LayerIndex into a string
Definition: MuonStationIndex.cxx:192
MuonGM::TgcReadoutElement::nStrips
int nStrips(int gasGap) const
Returns the number of strips in a given gas gap.
Muon::MuonStationIndex::DetectorRegionIndex
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
MuonDetectorManager.h
MuonLayerHashProviderTool.h
MuonSectorMapping.h
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:49
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< AlgTool >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Muon::MuonStationIndex::TechnologyIndexMax
@ TechnologyIndexMax
Definition: MuonStationIndex.h:57
MuonIdHelper::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: MuonIdHelper.h:143
Muon::MuonSectorMapping
Definition: MuonSectorMapping.h:20
TgcReadoutElement.h
Muon::MuonLayerHashProviderTool::TechnologyRegionHashVec
std::vector< RegionHashVec > TechnologyRegionHashVec
Definition: MuonLayerHashProviderTool.h:29
Muon::MuonLayerHashProviderTool::initialize
StatusCode initialize()
Definition: MuonLayerHashProviderTool.cxx:23
AthAlgTool
Definition: AthAlgTool.h:26
MuonIdHelper::module_begin
const_id_iterator module_begin() const
Iterators over full set of ids.
Definition: MuonIdHelper.cxx:758
IdentifierHash
Definition: IdentifierHash.h:38
Muon::MuonStationIndex::TechnologyIndex
TechnologyIndex
enum to classify the different layers in the muon spectrometer
Definition: MuonStationIndex.h:54
Muon::MuonLayerHashProviderTool::insertHash
void insertHash(const IdentifierHash &hash, const Identifier &id)
insert a single hash for a given identifier
Definition: MuonLayerHashProviderTool.cxx:36
Muon::MuonStationIndex::technologyName
static const std::string & technologyName(TechnologyIndex index)
convert LayerIndex into a string
Definition: MuonStationIndex.cxx:209