ATLAS Offline Software
HGTD_GmxInterface.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "HGTD_GmxInterface.h"
6 
10 
13 
17 #include <GeoModelRead/ReadGeoModel.h>
18 #include <GeoModelKernel/GeoFullPhysVol.h>
19 
20 namespace
21 {
22 constexpr int HGTD_HitIndex{2};
23 }
24 
26  InDetDD::SiCommonItems *commonItems)
27  : AthMessaging("HGTD_GmxInterface"),
28  m_detectorManager(detectorManager),
29  m_commonItems(commonItems)
30 {
31 }
32 
33 
34 int HGTD_GmxInterface::sensorId(std::map<std::string, int> &index) const
35 {
36  const HGTD_ID* hgtdIdHelper = dynamic_cast<const HGTD_ID *> (m_commonItems->getIdHelper());
37  bool newIdenSche = hgtdIdHelper->get_useNewIdentifierScheme(); // to choise which identification scheme will be used
38 
39  // Return the Simulation HitID (nothing to do with "ATLAS Identifiers" aka "Offline Identifiers"
40  int hitIdOfWafer;
41 
42  if(newIdenSche){
43  hitIdOfWafer = SiHitIdHelper::GetHelper()->buildHitId(HGTD_HitIndex,
44  index["endcap"],
45  index["layer"],
46  0,
47  index["moduleInLayer"],
48  0); // side is just 0 for HGTD
49 
50  ATH_MSG_DEBUG("Index list: " << index["endcap"] << " " << index["layer"] << " "
51  << index["moduleInLayer"] );
52  ATH_MSG_DEBUG("hitIdOfWafer = " << std::hex << hitIdOfWafer << std::dec);
53  ATH_MSG_DEBUG(" endcap = " << SiHitIdHelper::GetHelper()->getBarrelEndcap(hitIdOfWafer)
54  << " layer = " << SiHitIdHelper::GetHelper()->getLayerDisk(hitIdOfWafer)
55  << " moduleInLayer = " << SiHitIdHelper::GetHelper()->getPhiModule(hitIdOfWafer));
56  } else {
57  hitIdOfWafer = SiHitIdHelper::GetHelper()->buildHitId(HGTD_HitIndex,
58  index["endcap"],
59  index["layer"],
60  index["moduleNumberInRow"],
61  index["rowNumber"],
62  0); // side is just 0 for HGTD
63 
64  ATH_MSG_DEBUG("Index list: " << index["endcap"] << " " << index["layer"] << " "
65  << index["moduleNumberInRow"] << " " << index["rowNumber"]);
66  ATH_MSG_DEBUG("hitIdOfWafer = " << std::hex << hitIdOfWafer << std::dec);
67  ATH_MSG_DEBUG(" endcap = " << SiHitIdHelper::GetHelper()->getBarrelEndcap(hitIdOfWafer)
68  << " layer = " << SiHitIdHelper::GetHelper()->getLayerDisk(hitIdOfWafer)
69  << " moduleNumberInRow = " << SiHitIdHelper::GetHelper()->getEtaModule(hitIdOfWafer)
70  << " rowNumber = " << SiHitIdHelper::GetHelper()->getPhiModule(hitIdOfWafer));
71 
72  }
73  return hitIdOfWafer;
74 
75 }
76 
77 
78 void HGTD_GmxInterface::addSensorType(const std::string &clas,
79  const std::string &typeName,
80  const std::map<std::string, std::string> &parameters)
81 {
82  ATH_MSG_DEBUG("addSensorType called for class " << clas << ", typeName " << typeName);
83 
84  if (clas == "LGAD_module") {
85  // TODO: implement method to actually add the sensor type (also to the detector manager)
87  } else {
88  ATH_MSG_ERROR("addSensorType: unrecognised sensor class: " << clas);
89  ATH_MSG_ERROR("No sensor design created");
90  }
91 }
92 
93 
95  const std::map<std::string, std::string> &parameters)
96 {
97  double thickness{};
98  double xPitch{};
99  double yPitch{};
100  int circuitsPerColumn{};
101  int circuitsPerRow{};
102  int padColumns{};
103  int padRows{};
104 
105  // read parameters
106  // TO DO : checking for unlogical values
107  getParameter(typeName, parameters, "thickness", thickness);
108  getParameter(typeName, parameters, "xPitch", xPitch);
109  getParameter(typeName, parameters, "yPitch", yPitch);
110  getParameter(typeName, parameters, "circuitsPerColumn", circuitsPerColumn);
111  getParameter(typeName, parameters, "circuitsPerRow", circuitsPerRow);
112  getParameter(typeName, parameters, "padColumns", padColumns);
113  getParameter(typeName, parameters, "padRows", padRows);
114 
115  std::shared_ptr<const InDetDD::PixelDiodeMatrix> normalCell = InDetDD::PixelDiodeMatrix::construct(xPitch, yPitch);
116  std::shared_ptr<const InDetDD::PixelDiodeMatrix> singleRow = InDetDD::PixelDiodeMatrix::construct(InDetDD::PixelDiodeMatrix::phiDir, 0,
117  std::move(normalCell), padColumns, 0);
118  std::shared_ptr<const InDetDD::PixelDiodeMatrix> fullMatrix = InDetDD::PixelDiodeMatrix::construct(InDetDD::PixelDiodeMatrix::etaDir, 0,
119  std::move(singleRow), padRows, 0);
120 
121 
123 
125  circuitsPerColumn, circuitsPerRow,
126  padColumns, padRows/2,
127  padColumns, padRows/2,
128  std::move(fullMatrix),
129  InDetDD::CarrierType::electrons, 1, yDirection );
130 
131 
132  m_geometryMap[typeName] = design;
133 }
134 
135 
136 void HGTD_GmxInterface::addSensor(const std::string &typeName,
137  std::map<std::string, int> &index,
138  int /* sensitiveId */,
139  GeoVFullPhysVol *fpv)
140 {
141  //
142  // Get the ATLAS "Offline" wafer identifier
143  //
144  const HGTD_ID* hgtdIdHelper = dynamic_cast<const HGTD_ID *> (m_commonItems->getIdHelper());
145 
146  Identifier id;
147 
148  bool useNewIdentifierScheme = hgtdIdHelper->get_useNewIdentifierScheme(); // to find which identification scheme is configured
149  if(useNewIdentifierScheme){
150  id = hgtdIdHelper->wafer_id(index["endcap"],
151  index["layer"],
152  index["moduleInLayer"],
153  0);
154  ATH_MSG_DEBUG("HGTD New ID scheme");
155  } else {
156  id = hgtdIdHelper->wafer_id(index["endcap"],
157  index["layer"],
158  index["rowNumber"],
159  index["moduleNumberInRow"]);
160  ATH_MSG_DEBUG("HGTD Old ID scheme");
161  }
162  IdentifierHash hashId = hgtdIdHelper->wafer_hash(id);
163 
164  //
165  // Now do our best to check if this is a valid id. If either the gmx file is wrong, or the xml file
166  // defining the allowed id's is wrong, you can get disallowed id's. These cause a crash later
167  // if allowed through. To do the check, we ask for the hash-id of this id. Invalid ids give a
168  // special invalid hash-id (0xFFFFFFFF). But we don't exit the run, to help debug things quicker.
169  // //
170  if (hashId.is_valid()) {
171  ATH_MSG_DEBUG("valid id");
172  for (const auto& [key, value] : index) {
173  ATH_MSG_DEBUG(key << " = " << value << "; ");
174  }
175  } else {
176  ATH_MSG_ERROR("Invalid id for sensitive module " << typeName << " volume with indices");
177  for (const auto& [key, value] : index) {
178  ATH_MSG_ERROR(key << " = " << value << "; ");
179  }
180  ATH_MSG_ERROR("Refusing to make it into a sensitive element. Incompatible gmx and identifier-xml files.");
181  return;
182  }
183 
184  //
185  // Create the detector element and add to the DetectorManager
186  //
188  if (design == nullptr) {
189  ATH_MSG_ERROR("addSensor: Error: Readout sensor type " << typeName << " not found.");
190  throw std::runtime_error("readout sensor type " + typeName + " not found.");
191  }
193 
194  return;
195 }
196 
197 void HGTD_GmxInterface::buildReadoutGeometryFromSqlite(IRDBAccessSvc * rdbAccessSvc,GeoModelIO::ReadGeoModel* sqlreader)
198 {
199  IRDBRecordset_ptr LGAD_module = rdbAccessSvc->getRecordsetPtr("LGAD_module","");
200  const std::array<std::string,7> LGAD_moduleParamNames({"thickness","xPitch","yPitch","circuitsPerColumn","circuitsPerRow","padColumns","padRows"});
201 
202  if(LGAD_module->size() !=0){
203  for (const IRDBRecord_ptr& typeParams:*LGAD_module){
204  std::map<std::string,std::string> LGAD_moduleMap;
205  for(const std::string& paramName:LGAD_moduleParamNames){
206  std::string paramValue = typeParams->getString(paramName);
207  LGAD_moduleMap[paramName] = paramValue;
208  }
209  std::string LGAD_moduleName = typeParams->getString("SensorType");
210  makeLgadModule(LGAD_moduleName,LGAD_moduleMap);
211  }
212  }
213  else ATH_MSG_WARNING("Could not retrieve LGAD_module table");
214 
215  //Now, loop over the FullPhysVols and create the HGTD_DetectorElements (including splitting where needed)
216  //lots of string parsing...
217  std::vector<std::string> fields({"endcap","layer","moduleInLayer"});
218  //The map below is a map of string keys which contains all the Identifier/DetElement relevant info, and the associated FullPhysVol
219  std::map<std::string, GeoFullPhysVol*> mapFPV = sqlreader->getPublishedNodes<std::string, GeoFullPhysVol*>("GeoModelXML");
220  for (const auto&[fullPhysVolInfoString, fullPhysVolPointer] : mapFPV){
221  //find the name of the corresponding detector design type
222  size_t startLGAD = fullPhysVolInfoString.find("lgad");
223  if(startLGAD==std::string::npos){
224  ATH_MSG_DEBUG("GeoFullPhysVol "<<fullPhysVolInfoString<<" does not have the expected format. Skipping");
225  continue;
226  }
227  std::string typeName = fullPhysVolInfoString.substr(startLGAD);
228  std::map<std::string, int> index;
229  for (const std::string& field:fields){
230  size_t first = fullPhysVolInfoString.find(field+"_");
231  size_t last = fullPhysVolInfoString.find('_',first+field.size()+1);//start looking only after end of first delimiter (plus 1 for the "_" appended) ends
232  if(first==std::string::npos || last==std::string::npos){
233  ATH_MSG_DEBUG("Could not extract "<<field<<" from "<<fullPhysVolInfoString<<". Skipping");
234  continue;
235  }
236  std::string strNew = fullPhysVolInfoString.substr(first+field.size()+1,last-(first+field.size()+1));
237  index[field] = std::stoi(strNew);
238  }
239 
240  addSensor(typeName,index,0,fullPhysVolPointer);
241  }
242 }
HGTD_GmxInterface::addSensorType
virtual void addSensorType(const std::string &clas, const std::string &typeName, const std::map< std::string, std::string > &parameters) override final
Definition: HGTD_GmxInterface.cxx:78
HGTD_GmxInterface::HGTD_GmxInterface
HGTD_GmxInterface(HGTD_DetectorManager *detectorManager, InDetDD::SiCommonItems *commonItems)
Definition: HGTD_GmxInterface.cxx:25
IRDBAccessSvc::getRecordsetPtr
virtual IRDBRecordset_ptr getRecordsetPtr(const std::string &node, const std::string &tag, const std::string &tag2node="", const std::string &connName="ATLASDD")=0
Provides access to the Recordset object containing HVS-tagged data.
HGTD_ID::wafer_hash
IdentifierHash wafer_hash(Identifier wafer_id) const
wafer hash from id
Definition: HGTD_ID.h:404
InDetDD::SiCommonItems::getIdHelper
const AtlasDetectorID * getIdHelper() const
Definition: SiCommonItems.h:83
index
Definition: index.py:1
InDetDD::DetectorDesign::yAxis
@ yAxis
Definition: DetectorDesign.h:60
HGTD_ID::get_useNewIdentifierScheme
bool get_useNewIdentifierScheme() const
Definition: HGTD_ID.cxx:596
InDetDD::HGTD_DetectorElement
Definition: HGTD_DetectorElement.h:40
InDetDD::PixelDiodeMatrix::construct
static std::shared_ptr< const PixelDiodeMatrix > construct(double phiWidth, double etaWidth)
Construct method for just a single cell.
Definition: PixelDiodeMatrix.cxx:14
athena.value
value
Definition: athena.py:124
InDetDD::DetectorDesign::Axis
Axis
Definition: DetectorDesign.h:59
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
HGTD_ID::wafer_id
Identifier wafer_id(int endcap, int layer, int phi_module, int eta_module) const
For a single crystal.
Definition: HGTD_ID.h:287
InDetDD::PixelDiodeMatrix::phiDir
@ phiDir
Definition: PixelDiodeMatrix.h:97
PixelConditionsData::getParameter
std::vector< T > getParameter(const std::string &varName, const std::vector< std::string > &buffer)
Definition: PixelConditionsDataStringUtils.h:51
SiHitIdHelper.h
HGTD_GmxInterface::m_geometryMap
std::map< std::string, const InDetDD::HGTD_ModuleDesign * > m_geometryMap
Definition: HGTD_GmxInterface.h:49
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
IRDBAccessSvc
IRDBAccessSvc is an abstract interface to the athena service that provides the following functionalit...
Definition: IRDBAccessSvc.h:42
SiCommonItems.h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HGTD_DetectorElement.h
HGTD_GmxInterface::sensorId
virtual int sensorId(std::map< std::string, int > &index) const override final
Definition: HGTD_GmxInterface.cxx:34
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
HGTD_ID
Definition: HGTD_ID.h:47
IRDBRecordset_ptr
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition: IRDBAccessSvc.h:25
IdentifierHash::is_valid
bool is_valid() const
Check if id is in a valid state.
HGTD_GmxInterface::makeLgadModule
void makeLgadModule(const std::string &typeName, const std::map< std::string, std::string > &parameters)
Definition: HGTD_GmxInterface.cxx:94
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
HGTD_GmxInterface::m_commonItems
InDetDD::SiCommonItems * m_commonItems
Definition: HGTD_GmxInterface.h:51
InDetDD::SiCommonItems
Definition: SiCommonItems.h:45
HGTD_DetectorManager::addDetectorElement
void addDetectorElement(InDetDD::HGTD_DetectorElement *element)
Add elememts.
Definition: HGTD_DetectorManager.cxx:94
HGTD_ID.h
DeMoScan.index
string index
Definition: DeMoScan.py:364
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
HGTD_ModuleDesign.h
DeMoScan.first
bool first
Definition: DeMoScan.py:536
IRDBRecord_ptr
std::unique_ptr< IRDBRecord > IRDBRecord_ptr
Definition: IRDBRecordset.h:23
SiHitIdHelper::GetHelper
static const SiHitIdHelper * GetHelper()
Definition: SiHitIdHelper.cxx:19
HGTD_DetectorManager
Definition: HGTD_DetectorManager.h:33
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
InDetDD::HGTD_ModuleDesign
Definition: HGTD_ModuleDesign.h:43
HGTD_GmxInterface::m_detectorManager
HGTD_DetectorManager * m_detectorManager
Definition: HGTD_GmxInterface.h:50
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
SiHitIdHelper::buildHitId
int buildHitId(const int, const int, const int, const int, const int, const int) const
Definition: SiHitIdHelper.cxx:118
HGTD_GmxInterface::addSensor
void addSensor(const std::string &typeName, std::map< std::string, int > &index, int sequentialId, GeoVFullPhysVol *fpv) override final
Definition: HGTD_GmxInterface.cxx:136
HGTD_GmxInterface.h
InDetDD::electrons
@ electrons
Definition: InDetDD_Defs.h:17
InDetDD::PixelDiodeMatrix::etaDir
@ etaDir
Definition: PixelDiodeMatrix.h:97
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Identifier
Definition: IdentifierFieldParser.cxx:14
HGTD_GmxInterface::buildReadoutGeometryFromSqlite
void buildReadoutGeometryFromSqlite(IRDBAccessSvc *rdbAccessSvc, GeoModelIO::ReadGeoModel *sqlreader)
Definition: HGTD_GmxInterface.cxx:197