ATLAS Offline Software
Loading...
Searching...
No Matches
ServiceVolumeMaker.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3 */
4
5#include <utility>
6
10
12
14#include "GaudiKernel/SystemOfUnits.h"
15
16namespace InDetDD {
20
21 void
23 m_rmin = "RIN";
24 m_rmax = "ROUT";
25 m_rmin2 = "RIN2";
26 m_rmax2 = "ROUT2";
27 m_zmin = "ZIN";
28 m_zmax = "ZOUT";
29 m_zsymm = "ZSYMM";
30 m_materialName = "MATERIALNAME";
31 m_repeat = "REPEAT";
32 m_phiStart = "PHI";
33 m_phiDelta = "WIDTH";
34 m_width = "WIDTH";
35 m_shapeType = "SHAPE";
36 m_volName = "VOLNAME";
37 m_radialDiv = "";
38 m_phiStep = "";
39 m_volId = "FRAMENUM";
40 m_shiftFlag = "SHIFT";
41 }
42
43 void
45 m_rmin = "RMIN";
46 m_rmax = "RMAX";
47 m_rmin2 = "RMIN2";
48 m_rmax2 = "RMAX2";
49 m_zmin = "ZMIN";
50 m_zmax = "ZMAX";
51 m_zsymm = "ZSYMM";
52 m_materialName = "MATERIAL";
53 m_repeat = "NREPEAT";
54 m_phiStart = "PHISTART";
55 m_phiDelta = "PHIDELTA";
56 m_width = "";
57 m_shapeType = "";
58 m_volName = "NAME";
59 m_radialDiv = "RADIAL";
60 m_phiStep = "PHISTEP";
61 m_volId = "";
62 m_shiftFlag = "SHIFT";
63 }
64
65 void
67 m_rmin = "RMIN";
68 m_rmax = "RMAX";
69 m_rmin2 = "";
70 m_rmax2 = "";
71 m_zmin = "ZMIN";
72 m_zmax = "ZMAX";
73 m_zsymm = "ZSYMM";
74 m_materialName = "MATERIAL";
75 m_repeat = "";
76 m_phiStart = "";
77 m_phiDelta = "";
78 m_width = "";
79 m_shapeType = "";
80 m_volName = "NAME";
81 m_radialDiv = "";
82 m_phiStep = "";
83 m_volId = "";
84 m_shiftFlag = "SHIFT";
85 }
86
93
94 double
96 return (*m_table)[index]->getDouble(m_schema.rmin()) * Gaudi::Units::mm;
97 }
98
99 double
101 return (*m_table)[index]->getDouble(m_schema.rmax()) * Gaudi::Units::mm;
102 }
103
104 double
106 return (*m_table)[index]->getDouble(m_schema.rmin2()) * Gaudi::Units::mm;
107 }
108
109 double
111 return (*m_table)[index]->getDouble(m_schema.rmax2()) * Gaudi::Units::mm;
112 }
113
114 double
116 return (*m_table)[index]->getDouble(m_schema.zmin()) * Gaudi::Units::mm;
117 }
118
119 double
121 return (*m_table)[index]->getDouble(m_schema.zmax()) * Gaudi::Units::mm;
122 }
123
124 double
126 return (*m_table)[index]->getDouble(m_schema.phiDelta()) * Gaudi::Units::deg;
127 }
128
129 double
131 if (m_schema.has_width()) {
132 return (*m_table)[index]->getDouble(m_schema.width()) * Gaudi::Units::mm;
133 }
134 return 0;
135 }
136
137 double
139 return (*m_table)[index]->getDouble(m_schema.phiStart()) * Gaudi::Units::deg;
140 }
141
142 double
144 if (m_schema.has_phiStep()) {
145 return (*m_table)[index]->getDouble(m_schema.phiStep()) * Gaudi::Units::deg;
146 }
147 return 0;
148 }
149
150 bool
152 return (*m_table)[index]->getInt(m_schema.zsymm());
153 }
154
155 int
157 return (*m_table)[index]->getInt(m_schema.repeat());
158 }
159
160 int
162 if (m_schema.has_radial()) {
163 return (*m_table)[index]->getInt(m_schema.radialDiv());
164 } else {
165 return 0;
166 }
167 }
168
169 std::string
171 if (m_schema.has_shapeType()) {
172 try {
173 if (!(*m_table)[index]->isFieldNull(m_schema.shapeType())) {
174 return (*m_table)[index]->getString(m_schema.shapeType());
175 }
176 }
177 catch(std::runtime_error&) {
178 }
179 return "TUBE";
180 }
181 return "UNKNOWN";
182 }
183
184 std::string
186 try {
187 if (!(*m_table)[index]->isFieldNull(m_schema.volName())) {
188 return (*m_table)[index]->getString(m_schema.volName());
189 }
190 }
191 catch(std::runtime_error&) {
192 }
193 return "";
194 }
195
196 std::string
198 return (*m_table)[index]->getString(m_schema.materialName());
199 }
200
201 unsigned int
203 return m_table->size();
204 }
205
206 int
208 if (m_schema.has_volId()) {
209 return (*m_table)[index]->getInt(m_schema.volId());
210 }
211 return 0;
212 }
213
214 int
216 if (m_schema.has_shiftFlag()) {
217 try {
218 if (!(*m_table)[index]->isFieldNull(m_schema.shiftFlag())) {
219 return (*m_table)[index]->getInt(m_schema.shiftFlag());
220 }
221 }
222 catch(std::runtime_error&) {
223 }
224 }
225 return 0;
226 }
227
228 std::vector<double>
230 std::vector<double> layerShift;
231
232 IRDBAccessSvc* rdbSvc = m_athenaComps->rdbAccessSvc();
233 const IGeoDbTagSvc* geoDbTag = m_athenaComps->geoDbTagSvc();
234
235 DecodeVersionKey versionKey(geoDbTag, "Pixel");
236 const std::string& detectorKey = versionKey.tag();
237 const std::string& detectorNode = versionKey.node();
238
239 IRDBRecordset_ptr PixelBarrelGeneral = rdbSvc->getRecordsetPtr("PixelBarrelGeneral", detectorKey, detectorNode);
240 IRDBRecordset_ptr PixelLayer = rdbSvc->getRecordsetPtr("PixelLayer", detectorKey, detectorNode);
241
242 int numLayers = (*PixelBarrelGeneral)[0]->getInt("NLAYER");
243 layerShift.reserve(numLayers);
244 for(const auto& rec : *PixelLayer) {
245 double shift = 0;
246 try {
247 if(!rec->isFieldNull("GBLSHIFT")) {
248 shift = rec->getDouble("GBLSHIFT");
249 }
250 }
251 catch(std::runtime_error&) {
252 }
253 layerShift.push_back(shift);
254 }
255
256 return layerShift;
257 }
258
260 IRDBRecordset_ptr table, const ServiceVolumeSchema& schema,
261 InDetDD::AthenaComps* athenaComps)
262 : m_label(label) {
263 m_mgr = new ServiceVolumeMakerMgr(std::move(table), schema, athenaComps);
264 m_layerShift = m_mgr->readLayerShift();
265 }
266
268 for (unsigned int i = 0; i < m_services.size(); i++) {
269 delete m_services[i];
270 }
271 delete m_mgr;
272 }
273
274 const std::vector<const ServiceVolume*>&
276 for (unsigned int ii = 0; ii < numElements(); ++ii) {
277 m_services.push_back(make(ii));
278 }
279 return m_services;
280 }
281
282 unsigned int
284 return m_mgr->numElements();
285 }
286
289 //
290 // Retrieve/calculate the parameters for the volume.
291 //
292 ServiceVolume* param = new ServiceVolume;
293
294 param->setMaterial(m_mgr->materialName(ii));
295 param->setRmin(m_mgr->rmin(ii));
296 param->setRmax(m_mgr->rmax(ii));
297 param->setZmin(m_mgr->zmin(ii));
298 param->setZmax(m_mgr->zmax(ii));
299 param->setZsymm(m_mgr->zsymm(ii));
300 param->setVolName(m_mgr->volName(ii));
301
302 double zShift = 0.; // the famous IBL Z shift
303 if (m_mgr->shiftFlag(ii) > 0) zShift = m_layerShift[m_mgr->shiftFlag(ii) - 100];
304 param->setZShift(zShift);
305
306 int volId = m_mgr->volId(ii);
307 if (volId == 0) volId = ii + 1;
308
309 bool needsRotation = false;
310
311 // For TUBE there is no need to read the rest
312 std::string shapeType = m_mgr->shapeType(ii);
313 if (!m_mgr->schema().simple() && !shapeType.empty() && shapeType != "TUBE") {
314 double rmin2 = m_mgr->rmin2(ii);
315 double rmax2 = m_mgr->rmax2(ii);
316
317 if (rmin2 <= 0) rmin2 = param->rmin();
318 if (rmax2 <= 0) rmax2 = param->rmax();
319
320 int radialDiv = m_mgr->radialDiv(ii);
321
322 double phiDelta = m_mgr->phiDelta(ii);
323
324 bool fullPhiSector = false;
325 if (phiDelta == 0 || phiDelta >= 359.9 * Gaudi::Units::degree) {
326 phiDelta = 360 * Gaudi::Units::degree;
327 fullPhiSector = true;
328 }
329 //else {
330 //phiDelta -= 2*phiepsilon;
331 //phiStart += phiepsilon;
332 // }
333
334 if (shapeType == "UNKNOWN") {
335 if (radialDiv > 0) {
336 shapeType = "RADIAL";
337 } else if (param->rmin() == rmin2 && param->rmax() == rmax2) {
338 if (fullPhiSector) {
339 shapeType = "TUBE";
340 } else {
341 shapeType = "TUBS";
342 }
343 } else {
344 shapeType = "CONS";
345 }
346 }
347
348
349 int repeat = m_mgr->repeat(ii);
350 if (repeat == 0) repeat = 1;
351
352 double phiStart = m_mgr->phiStart(ii);
353 double phiWidth = phiDelta;
354
355 if (shapeType == "CONS" || shapeType == "TUBS") {
356 const double phiepsilon = 0.001 * Gaudi::Units::degree;
357 phiWidth -= 2 * phiepsilon;
358 phiStart += phiepsilon;
359 }
360
361 // Can be in degree or mm. Usually it is deg expect for BOX, TRAP and ROD shape
362 // Geometry manager makes no assumptions about units. So we must interpret here.
363 if (shapeType == "BOX" || shapeType == "ROD" || shapeType == "ROD2" || shapeType == "TRAP") {
364 phiWidth = m_mgr->width(ii); // in mm
365 }
366
367 if (shapeType == "PGON" || shapeType == "PGON2" ||
368 shapeType == "CONE" || shapeType == "CONS" ||
369 shapeType == "PGON3" || shapeType == "PGON4") {
370 if ((rmin2 != param->rmin()) || (rmax2 != param->rmax())) {
371 needsRotation = true;
372 }
373 }
374
375 int sides = 0;
376 int nCopies = 1;
377 if (shapeType == "PGON" || shapeType == "PGON2" ||
378 shapeType == "PGON3" || shapeType == "PGON4") {
379 sides = repeat;
380 } else {
381 nCopies = repeat;
382 }
383
384 // Force nCopies to 1 for TUBE and CONE
385 if (shapeType.empty() || shapeType == "TUBE" || shapeType == "CONE") {
386 nCopies = 1;
387 }
388
389 param->setShapeType(shapeType);
390 param->setRmin2(rmin2);
391 param->setRmax2(rmax2);
392 param->setPhiLoc(phiStart);
393 param->setPhiWidth(phiWidth);
394 param->setSides(sides);
395 param->setNCopies(nCopies);
396 //param->setRadialDiv(radialDiv);
397 //param->setPhiStep(phiStep);
398 }
399
400 param->setNeedsRotation(needsRotation);
401
402
403 //
404 // If zin is 0... (within 10^-5) this is a volume symmetric around
405 // the origin
406 //
407 if (std::abs(param->zmin()) < 0.000001) {
408 param->setZmin(-param->zmax());
409 param->setZsymm(false);
410 }
411
412 param->setLabel(m_label, volId);
413
414 return param;
415 }
416} // end namespace
std::shared_ptr< IRDBRecordset > IRDBRecordset_ptr
Definition of the abstract IRDBRecordset interface.
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
const std::string & tag() const
Return version tag.
const std::string & node() const
Return the version node.
IRDBAccessSvc is an abstract interface to the athena service that provides the following functionalit...
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.
Class to hold various Athena components.
std::vector< double > readLayerShift()
const ServiceVolumeSchema & schema() const
ServiceVolumeMakerMgr(IRDBRecordset_ptr table, const ServiceVolumeSchema &schema, InDetDD::AthenaComps *athenaComps)
InDetDD::AthenaComps * m_athenaComps
std::string volName(int index) const
std::string shapeType(int index) const
std::string materialName(int index) const
std::vector< const ServiceVolume * > m_services
std::vector< double > m_layerShift
ServiceVolumeMakerMgr * m_mgr
ServiceVolumeMaker(const std::string &label, IRDBRecordset_ptr table, const ServiceVolumeSchema &schema, InDetDD::AthenaComps *)
const std::vector< const ServiceVolume * > & makeAll()
ServiceVolume * make(int index)
void setLabel(const std::string &name, int volId)
std::string label(const std::string &format, int i)
Definition label.h:19
Message Stream Member.
Definition index.py:1
STL namespace.