ATLAS Offline Software
MuonDetectorFactoryLite.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include "GaudiKernel/MsgStream.h"
8 #include "GaudiKernel/SystemOfUnits.h"
10 #include "GeoModelKernel/GeoFullPhysVol.h"
11 #include "GeoModelKernel/GeoPerfUtils.h"
12 #include "GeoModelKernel/GeoPhysVol.h"
13 #include "MuonGeoModel/MYSQL.h"
16 #include "MuonGeoModel/Station.h"
17 
21 #include "StoreGate/StoreGateSvc.h"
22 
23 namespace MuonGM {
24 
25  // Helper function to retrieve ID Helpers:
26  template <class T>
27  const T *getIdHelper (StoreGateSvc *pDetStore, const std::string & helperName) {
28  const T *helper;
29  StatusCode sc = pDetStore->retrieve(helper, helperName);
30  if (sc.isFailure()) {
31  return nullptr;
32  }
33  else {
34  return helper;
35  }
36  };
37 
38 
39 
40 
41  MuonDetectorFactoryLite::MuonDetectorFactoryLite(StoreGateSvc *pDetStore, GeoModelIO::ReadGeoModel *sqliteReader):
42  m_pDetStore{pDetStore},
43  m_sqliteReader(sqliteReader) {
44  }
45 
47 
50 
51  void MuonDetectorFactoryLite::create(GeoPhysVol *) {
52 
53  std::map<std::string, GeoAlignableTransform*> mapAXF = m_sqliteReader->getPublishedNodes<std::string, GeoAlignableTransform*>("MuonSys");
54  std::map<std::string, GeoFullPhysVol*> mapFPV = m_sqliteReader->getPublishedNodes<std::string, GeoFullPhysVol*>("MuonSys");
55 
56  MsgStream log(Athena::getMessageSvc(), "MuGM:MuonFactory");
57 
59 
60 
61 
62 
63 
64  // Iterate using iterator in for loop
65  for (const auto& [key, pV] : mapFPV) {
66  int /*index1=key[3]-'0',*/ eta=key[5]-'0', ml=key[7]-'0', phi=key[12]-'0';
67 
68  char AC=key[13];
69  int ec = AC=='C' ? -1 : 1;
70  std::string vName = pV->getLogVol()->getName();
71  if (key.substr(0,3)=="sMD") {
72  std::string sName = vName.substr(4,4);
73  std::unique_ptr<MuonGM::MMReadoutElement> re = std::make_unique<MuonGM::MMReadoutElement>(pV, sName, ec*eta,phi,ml,m_manager,nullptr);
74  re->initDesign();
75  re->fillCache();
76  m_manager->addMMReadoutElement(std::move(re));
77  }
78  else if (key.substr(0,3)=="sTG") {
79  std::string sName = vName.substr(7,4);
80  std::unique_ptr<sTgcReadoutElement> re = std::make_unique<sTgcReadoutElement>(pV, sName, ec*eta, phi, ml, m_manager);
81  re->initDesign(2.6);
82  re->fillCache();
83  m_manager->addsTgcReadoutElement(std::move(re));
84  }
85  }
86 
87 
88 
89  // here create the MYSQL singleton
91  mysql->set_amdb_from_RDB(true);
92 
93  std::unique_ptr<RDBReaderAtlas> dbr;
94  {
95  // We never alter these in the "Lite" workflow
96  std::string oracleTag="";
97  std::string oracleNode="";
98  std::map<std::string, std::string> ascii{};
99  dbr = std::make_unique<RDBReaderAtlas>(m_pDetStore, m_pRDBAccess, oracleTag, oracleNode, ascii);
100 
101 
102  }
103 
104 
105 
106  // set here the flag deciding whether to include cutouts:
107  // m_includeCutouts = 1 => include cutouts
108  // m_includeCutouts = 0 => no cutouts
109  m_manager->setCutoutsFlag(true);
111 
112 
113  StatusCode sc = StatusCode::SUCCESS;
114 
115  dbr->setManager(getDetectorManager());
116  sc = dbr->ProcessDB(*mysql);
117  if (sc != StatusCode::SUCCESS) {
118  log << MSG::ERROR << " FAILURE in DB access; Muon node will not be built" << endmsg;
119  return;
120  }
121 
122  GeoFullPhysVol *p4 = mapFPV["MuonTreeTop"];
123  m_manager->addTreeTop(p4); // This is the top!
124  log << MSG::INFO << " TreeTop added to the Manager" << endmsg;
125 
126  // Look through the map explicitly for Stations
127  std::set<std::string> mappedStations;
128  for (const auto& i: mapFPV) {
129  size_t pos=i.first.find("_Station");
130  if (pos!=std::string::npos) mappedStations.insert(i.first.substr(0,pos));
131  }
132 
133  // Boudreau Jan 2024 Keep track of instantiated readout geometries. This is
134  // needed because the muon geometry is rebuild multiple times in current
135  // implementation.
136  std::set<std::string> keyset;
137 
138  for (const auto& i: mappedStations) {
139  auto it= mysql->stationMap().find(i);
140  if (it==mysql->stationMap().end()) {
141  throw std::runtime_error("Raw/readout geometry mismatch");
142  }
143 
144  Station *station = (*it).second.get();
145  std::string stname(station->GetName(), 0, 3);
146 
147  bool isAssembly = false;
148  if (station->GetNrOfCutouts() > 0 && stname.substr(0, 1) != "T")
149  isAssembly = true;
150 
151  // BIR have multilayers of diff. length and overall station volume clashes with toroids
152  if (stname == "BIR")
153  isAssembly = true;
154 
155  MuonChamberLite l(*mysql, station,&mapFPV,&mapAXF); // here is where we start to create a MuonChamber with all readoutelements
156  l.setKeyset(&keyset);
157 
158  PositionIterator pit;
159  AlignPos ap;
160  for ( auto const& [key, position] : *station) {
161  int zi = position.zindex;
162  int fi = position.phiindex;
163 
164  // here build the physical volume (tree) associated to the chamber
165  if (stname == "CSL") isAssembly = true;
166 
167  // CSL because coffin shape of the station mother volume
168  l.addReadoutLayers(*mysql, getDetectorManager(), zi, fi, position.isMirrored, isAssembly);
169 
170  // here define the GeoAlignableTransform associated to the chamber
171  // nominal transform first
172  GeoAlignableTransform *xf = mapAXF[station->GetName()+"_Station_"+std::to_string(zi)+"_"+std::to_string(fi)];
173  // alignment issues and readout geometry for station
174  MuonStation *mst = m_manager->getMuonStation(station->GetName(), zi, fi + 1);
175  if (!mst) {
176  log << MSG::WARNING << "For Station with nameTag=<" << station->GetName() << "> at zi/fi = " << zi << "/" << fi
177  << " no MuonStation found => no possibility to align" << endmsg;
178  continue;
179  }
180 
181  mst->setTransform(xf);
182  GeoTrf::Transform3D tsz_to_szt = GeoTrf::RotateZ3D(-90 * Gaudi::Units::degree) * GeoTrf::RotateY3D(-90 * Gaudi::Units::degree);
183  mst->setNativeToAmdbLRS(tsz_to_szt * station->native_to_tsz_frame(*mysql, position));
184  mst->setNominalAmdbLRSToGlobal(station->tsz_to_global_frame(*mysql, position) * tsz_to_szt.inverse());
185 
186  int nAlines = station->CountAlignPos(zi, fi);
187  if (nAlines == 0) {
188  ap.tras = ap.traz = ap.trat = ap.rots = ap.rotz = ap.rott = 0.;
189  ap.jobindex = 0;
190  mst->setDelta_fromAline(ap.tras, ap.traz, ap.trat, ap.rots, ap.rotz, ap.rott);
191  } else if (nAlines > 0) {
192  AlignPosIterator alast;
193  AlignPosIterator afirst = station->getFirstAlignPosInRange(zi, fi, alast);
194 
195  for (AlignPosIterator acurrent = afirst; acurrent != alast; ++acurrent) {
196  ap = acurrent->second;
197  if (ap.phiindex != fi || ap.zindex != zi) {
198  log << MSG::ERROR << "Inconsistent AlignedPosition found in the static Geometry DB: aligPos.fi, zi = " << ap.phiindex << ", " << ap.zindex
199  << " for station " << station->GetName() << " at fi/zi = " << fi << "/" << zi << " AlignPos indices fi/zi " << fi << "/" << zi << endmsg;
200  }
201  if (ap.jobindex == 0) {
202  mst->setDelta_fromAline(ap.tras, ap.traz, ap.trat, ap.rots, ap.rotz, ap.rott);
203  } else {
204  mst->setDelta_fromAline_forComp(ap.jobindex, ap.tras, ap.traz, ap.trat, ap.rots, ap.rotz, ap.rott);
205  }
206  }
207  }
208  } // end loop on positions
209  } // for ( it = sel.begin(); it != sel.end(); it++ ) {
210  delete mysql.get();
211  } // MuonDetectorFactoryLite::create
212 
213 } // namespace MuonGM
MuonGM::MuonDetectorFactoryLite::~MuonDetectorFactoryLite
~MuonDetectorFactoryLite()
CxxUtils::LockedPointer::get
T * get()
Definition: LockedPointer.h:43
MuonGM::AlignPos
Definition: AlignPos.h:12
beamspotnt.ascii
ascii
Definition: bin/beamspotnt.py:1476
MuonGM
Ensure that the Athena extensions are properly loaded.
Definition: GeoMuonHits.h:27
MuonGM::MuonStation::setDelta_fromAline_forComp
void setDelta_fromAline_forComp(int, double, double, double, double, double, double)
Definition: MuonStation.cxx:190
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
CxxUtils::LockedPointer
A pointer together with a movable lock.
Definition: LockedPointer.h:35
MuonGM::MuonDetectorManager::addTreeTop
void addTreeTop(PVLink)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:117
sTgcReadoutElement.h
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
MuonGM::Station
Definition: Station.h:40
skel.it
it
Definition: skel.GENtoEVGEN.py:423
MuonGM::MuonDetectorFactoryLite::getDetectorManager
virtual const MuonDetectorManager * getDetectorManager() const override
Definition: MuonDetectorFactoryLite.cxx:48
TRT_PAI_gasdata::AC
const float AC
Definition: TRT_PAI_gasdata.h:27
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
MuonGM::MuonDetectorFactoryLite::m_pDetStore
StoreGateSvc * m_pDetStore
Definition: MuonDetectorFactoryLite.h:42
python.compareNtuple.vName
vName
Definition: compareNtuple.py:23
python.AtlRunQueryParser.ap
ap
Definition: AtlRunQueryParser.py:826
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
Station.h
MuonGM::MuonChamberLite
Definition: MuonChamberLite.h:31
StoreGateSvc::retrieve
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
RDBReaderAtlas.h
MMReadoutElement.h
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
MuonGM::MuonStation::setNativeToAmdbLRS
void setNativeToAmdbLRS(Amg::Transform3D xf)
Definition: MuonStation.cxx:54
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
MuonGM::MuonStation::setTransform
void setTransform(GeoAlignableTransform *xf)
Definition: MuonStation.cxx:50
MuonGM::PositionIterator
std::map< int, Position, std::less< int > >::const_iterator PositionIterator
Definition: Station.h:37
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
MuonGM::MuonStation
Definition: MuonStation.h:51
MuonGM::AlignPosIterator
std::multimap< int, AlignPos, std::less< int > >::const_iterator AlignPosIterator
Definition: Station.h:38
MuonGM::MuonDetectorManager::setCutoutsFlag
void setCutoutsFlag(int flag)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:684
MuonGM::MuonDetectorManager::setCutoutsBogFlag
void setCutoutsBogFlag(int flag)
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:685
MuonGM::Station::GetName
std::string GetName() const
Definition: Station.cxx:110
MuonGM::MuonDetectorFactoryLite::create
virtual void create(GeoPhysVol *world) override
Definition: MuonDetectorFactoryLite.cxx:51
MYSQL.h
MuonGM::MuonDetectorFactoryLite::m_pRDBAccess
IRDBAccessSvc * m_pRDBAccess
Definition: MuonDetectorFactoryLite.h:43
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
StoredMaterialManager.h
MuonGM::MuonDetectorFactoryLite::m_manager
MuonDetectorManager * m_manager
Definition: MuonDetectorFactoryLite.h:41
MuonGM::MuonStation::setDelta_fromAline
void setDelta_fromAline(double, double, double, double, double, double)
set the delta transform in the amdb frame and update the geoModel Delta
Definition: MuonStation.cxx:142
MuonGM::MYSQL::GetPointer
static LockedMYSQL GetPointer()
Definition: MYSQL.cxx:42
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
MuonGM::Station::GetNrOfCutouts
int GetNrOfCutouts() const
Definition: Station.cxx:324
MuonGM::MuonDetectorManager::getMuonStation
const MuonStation * getMuonStation(const std::string &stName, int eta, int phi) const
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:137
MuonChamberLite.h
MuonGM::MuonDetectorManager
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
Definition: MuonDetDescr/MuonReadoutGeometry/MuonReadoutGeometry/MuonDetectorManager.h:49
re
const boost::regex re(r_e)
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
checkFileSG.fi
fi
Definition: checkFileSG.py:65
WriteBchToCool.dbr
dbr
Definition: WriteBchToCool.py:164
MuonGM::MuonDetectorFactoryLite::MuonDetectorFactoryLite
MuonDetectorFactoryLite(StoreGateSvc *pDetStore, GeoModelIO::ReadGeoModel *sqliteReader)
Definition: MuonDetectorFactoryLite.cxx:41
MuonGM::MuonDetectorManager::addMMReadoutElement
void addMMReadoutElement(std::unique_ptr< MMReadoutElement > &&reEle)
store the MMReadoutElement using as "key" the identifier
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:173
MuonDetectorFactoryLite.h
MuonGM::MuonDetectorManager::addsTgcReadoutElement
void addsTgcReadoutElement(std::unique_ptr< sTgcReadoutElement > &&reEle)
store the sTGCReadoutElement using as "key" the identifier
Definition: MuonDetDescr/MuonReadoutGeometry/src/MuonDetectorManager.cxx:183
MuonStation.h
MuonGM::MuonDetectorFactoryLite::m_sqliteReader
GeoModelIO::ReadGeoModel * m_sqliteReader
Definition: MuonDetectorFactoryLite.h:44
StoreGateSvc.h
python.SystemOfUnits.degree
tuple degree
Definition: SystemOfUnits.py:106
MuonGM::MuonStation::setNominalAmdbLRSToGlobal
void setNominalAmdbLRSToGlobal(Amg::Transform3D xf)
Definition: MuonStation.cxx:60
MuonGM::getIdHelper
const T * getIdHelper(StoreGateSvc *pDetStore, const std::string &helperName)
Definition: MuonDetectorFactoryLite.cxx:27
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37