ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_DetectorManager.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
11
12#include "GeoModelKernel/GeoXF.h"
13#include "GeoModelKernel/GeoAlignableTransform.h"
14
16
18
21
22namespace InDetDD {
23
24 const int FIRST_HIGHER_LEVEL = 1;
25
27 :InDetDetectorManager(detStore, "TRT"),
29 m_idHelper(nullptr),
30 m_ownsIdHelper(false),
32 m_digvers(9999),
33 m_digversname("ERROR:DIGVERSNOTSET!")
34 {
35 m_elementContainer.setNumerology(m_numerology);
36
37 m_barrelXF[0]=m_barrelXF[1]=m_barrelXF[2]=nullptr;
38 m_endcapXF[0]=m_endcapXF[1]=m_endcapXF[2]=nullptr;
39 }
40
41
42
46
50
52 {
53 delete m_numerology;
54 if (m_ownsIdHelper) delete m_idHelper;
55 for (auto & i : m_barrelXF) delete i;
56 for (auto & i : m_endcapXF) delete i;
57
58
59 for (auto & m : m_alignableTransforms) {
60 for (auto & j : m) {
61 delete j.second;
62 }
63 }
64
65 for (const TRT_BarrelDescriptor* barrelDescriptor : m_barrelDescriptors) {
66 delete barrelDescriptor;
67 }
68 for (const TRT_EndcapDescriptor* endcapDescriptor : m_endcapDescriptors) {
69 delete endcapDescriptor;
70 }
71 }
72
73
75 {
76 return m_volume.size();
77 }
78
79 PVConstLink TRT_DetectorManager::getTreeTop(unsigned int i) const
80 {
81 return m_volume[i];
82 }
83
84 void TRT_DetectorManager::addTreeTop(const PVLink& vol) {
85 m_volume.push_back(vol);
86 }
87
88 // Manage the barrel elements:
93
94 // Manage the endcap elements:
96 {
97 m_elementContainer.manageEndcapElement(endcap,m_idHelper);
98 }
99
101 , unsigned int moduleIndex
102 , unsigned int phiIndex
103 , unsigned int strawLayerIndex) const
104 {
105 return m_elementContainer.getBarrelDetElement(positive,moduleIndex,phiIndex,strawLayerIndex);
106 }
107
109 , unsigned int moduleIndex
110 , unsigned int phiIndex
111 , unsigned int strawLayerIndex)
112 {
113 return m_elementContainer.getBarrelDetElement(positive,moduleIndex,phiIndex,strawLayerIndex);
114 }
115
117 , unsigned int wheelIndex
118 , unsigned int strawLayerIndex
119 , unsigned int phiIndex) const
120 {
121 return m_elementContainer.getEndcapDetElement(positive,wheelIndex,strawLayerIndex,phiIndex);
122 }
123
125 , unsigned int wheelIndex
126 , unsigned int strawLayerIndex
127 , unsigned int phiIndex)
128 {
129 return m_elementContainer.getEndcapDetElement(positive,wheelIndex,strawLayerIndex,phiIndex);
130 }
131
133 {
134 return m_idHelper;
135 }
136
137 void TRT_DetectorManager::setIdHelper(const TRT_ID *idHelper, bool owns)
138 {
139 m_idHelper=idHelper;
140 m_ownsIdHelper=owns;
141 }
142
143
144
146 {
147 // Make sure it is a straw_layer id
148 Identifier strawLayerId = m_idHelper->layer_id(id);
149 IdentifierHash hashId = m_idHelper->straw_layer_hash(strawLayerId);
150 const TRT_DetElementCollection* elements = m_elementContainer.getElements();
151 if (hashId>=elements->size()) return nullptr;
152 return (*elements)[hashId];
153 }
154
156 {
157 const TRT_DetElementCollection* elements = m_elementContainer.getElements();
158 if (id>=elements->size()) return nullptr;
159 return (*elements)[id];
160 }
161
166
171
176
181
186
191
192 void TRT_DetectorManager::setBarrelTransformField(size_t i, const GeoXF::Function * f){
193 if (m_barrelXF[i]!=f) delete m_barrelXF[i];
194 m_barrelXF[i] = f;
195 }
196
197 const GeoXF::Function * TRT_DetectorManager::barrelTransformField(size_t i) const {
198 return m_barrelXF[i];
199 }
200
201 void TRT_DetectorManager::setEndcapTransformField(size_t i, const GeoXF::Function *f) {
202 if (m_endcapXF[i]!=f) delete m_endcapXF[i];
203 m_endcapXF[i]=f;
204 }
205
206 const GeoXF::Function *TRT_DetectorManager::endcapTransformField(size_t i) const{
207 return m_endcapXF[i];
208 }
209
210
215
217 {
218 m_gasType = activeGasType;
219 }
220
222 const Identifier &id,
223 GeoAlignableTransform *transform,
224 const GeoVPhysVol * child,
225 const GeoVPhysVol * frameVol)
226 {
227 if (m_idHelper) {
228 // Check if child and frame are actually full physical volumes.
229 // if they are non zero.
230 const GeoVFullPhysVol * childFPV = nullptr;
231 if (child) {
232 childFPV = dynamic_cast<const GeoVFullPhysVol *>(child);
233 }
234 const GeoVFullPhysVol * frameFPV = nullptr;
235 if (frameVol) {
236 frameFPV = dynamic_cast<const GeoVFullPhysVol *>(frameVol);
237 }
238 if (child && !childFPV) {
239 msg(MSG::ERROR)
240 << "Child of alignable transform is not a full physical volume"
241 << endmsg;
242 } else if (frameVol && !frameFPV) {
243 msg(MSG::ERROR)
244 << "Frame for alignable transform is not a full physical volume"
245 << endmsg;
246 } else {
247 addAlignableTransform (level, id, transform, childFPV, frameFPV);
248 }
249 }
250 }
251
253 const Identifier &id,
254 GeoAlignableTransform *transform,
255 const GeoVFullPhysVol *child,
256 const GeoVFullPhysVol *frameVol)
257 {
258 if (m_idHelper) {
259 if (level == 0) {
260 // Nothing implemented. Reserved in case we want alignable straws.
261 } else {
262
263 ExtendedAlignableTransform * extAlignableTransform = new ExtendedAlignableTransform(transform, child, frameVol);
264 if(msgLvl(MSG::VERBOSE)) {
265 msg(MSG::VERBOSE) << "TRT: Adding alignment at level " << level << " " << m_idHelper->show_to_string(id);
266 if (child && !frameVol) {
267 msg(MSG::VERBOSE) << " using global frame";
268 } else if (!child || child == frameVol ) {
269 msg(MSG::VERBOSE) << " using local frame";
270 } else {
271 msg(MSG::VERBOSE) << " using other frame";
272 }
273 msg(MSG::VERBOSE) << endmsg;
274 }
275 // Save in map
276 int index = level - FIRST_HIGHER_LEVEL; // level 0 treated separately.
277 if (index >= static_cast<int>(m_alignableTransforms.size())) m_alignableTransforms.resize(index+1);
278 m_alignableTransforms[index][id] = extAlignableTransform;
279 }
280 }
281 }
282
284 const Identifier & id,
285 const Amg::Transform3D & delta,
286 FrameType frame,
287 GeoVAlignmentStore* alignStore) const
288 {
289 if (level == 0) {
290 // Nothing implemented. Reserved in case we want alignable straws
291 return false;
292 } else {
293
294 int index = level - FIRST_HIGHER_LEVEL; // level 0 treated separately.
295 if (index >= static_cast<int>(m_alignableTransforms.size())) return false;
296
297 // We retrieve it from a map.
298 AlignableTransformMap::const_iterator iter;
299 iter = m_alignableTransforms[index].find(id);
300 if (iter == m_alignableTransforms[index].end()) return false;
301
302 return setAlignableTransformAnyFrameDelta(iter->second, delta, frame, alignStore);
303
304 }
305 }
306
308 const Amg::Transform3D & delta,
309 FrameType frame,
310 GeoVAlignmentStore* alignStore) const
311 {
312 //---------------------
313 // For Local:
314 //---------------------
315 // The geomodel alignable transform delta is already a local delta so we just pass it directly
316
317 //---------------------
318 // For global frame
319 //---------------------
320 // Sets the alignable transform delta when the supplied delta is in the global frame.
321
322 // If the default transform down to the alignable transform is
323 // T = A*B*C
324 // and the alignable transform is C with delta c and the delta in the global frame is g, then
325 // A*B*C*c = g*A*B*C
326 // T*c = g*T
327 // c = T.inverse() * g * T
328
329 // To get default transform up and including the alignable transform,
330 // we assume the next volume down is a fullphys volume and so its
331 // transform is the transform we want (ie T=A*B*C in the above example).
332
333 //---------------------
334 // For Other frame
335 //---------------------
336 // Sets the alignable transform delta when the supplied delta is in the frame of the
337 // volume "frameVol".
338
339 // If the default transform down to the alignable transform is
340 // T = A*B*C
341 // and the alignable transform is C with delta c and the delta g is expressed in the frame A, then
342 // A*B*C*c = A*g*B*C
343 // c = (BC).inverse * g * (BC)
344 // BC = A.inverse() * T
345 // C = T.inverse() * A * g * A.inverse() * T
346
347 // To get default transform up and including the alignable transform,
348 // we assume the next volume down is a fullphys volume and so its
349 // transform is the transform we want (ie T=A*B*C in the above example).
350 // The Transform to the frame is T = A which we get from the fullphys volume frameVol.
351
352 if (!extXF) return false;
353 if (!extXF->alignableTransform()) return false;
354
355 const GeoVFullPhysVol * child = extXF->child();
356 const GeoVFullPhysVol * frameVol = extXF->frame();
357
358 FrameType newFrame = frame;
359 // If frame is other then check if "other" is actually local or global
360 if (frame == InDetDD::other) {
361 if (child && !frameVol) {
362 // frame = 0 indicates to use global frame
363 newFrame = InDetDD::global;
364 } else if (!child || child == frameVol){
365 // if child is 0 or the they are the same volumes then its local
366 newFrame = InDetDD::local;
367 } // else its "other" already.
368 }
369
370 if (newFrame == InDetDD::global) { // Global
371 if (!child) {
372 msg(MSG::ERROR) << "global frame specified, but child == 0" << endmsg;
373 } else {
374 const GeoTrf::Transform3D & childXF = child->getDefAbsoluteTransform(alignStore);
375 extXF->alignableTransform()->setDelta(childXF.inverse() * delta * childXF, alignStore);
376 }
377
378 } else if (frame == InDetDD::local) { // Local
379 // if its a local frame then no transform necessary. We set it directly.
380 extXF->alignableTransform()->setDelta(delta, alignStore);
381
382 } else { // Other frame
383 // if child or frame is zero it will have been set to local or global above
384 if (!child) { // CID 113112
385 // shouldn't be happening, if child is null then something is terribly wrong
386 ATH_MSG_ERROR("Child can't be null if frame is 'other'");
387 return false;
388 } else {
389 const GeoTrf::Transform3D & xfChild = child->getDefAbsoluteTransform(alignStore);
390 const GeoTrf::Transform3D & xfFrame = frameVol->getDefAbsoluteTransform(alignStore);
391 extXF->alignableTransform()->setDelta(xfChild.inverse() * xfFrame * delta * xfFrame.inverse() * xfChild, alignStore);
392 }
393 }
394
395 return true;
396 }
397
398
400 {
401 return align();
402 }
403
404
405 // We invalidate all the elements if at least one alignment changed.
407 {
409 element_iter != getDetectorElementEnd();
410 ++element_iter) {
411 if (*element_iter) {
412 (*element_iter)->invalidate();
413 }
414 }
415 }
416
418 {
420 element_iter != getDetectorElementEnd();
421 ++element_iter) {
422
423 if (*element_iter) {
424 (*element_iter)->updateAllCaches();
425 }
426 }
427 }
428
429
431 {
432 return getIdHelper()->is_trt(id);
433 }
434
435
437 {
438 if(msgLvl(MSG::DEBUG))
439 msg(MSG::DEBUG) << "Processing TRT fine alignment." << endmsg;
440
441 const TRTCond::StrawDxContainer* container = nullptr;
442 StatusCode sc = StatusCode::FAILURE;
443 if (m_detStore->contains<TRTCond::StrawDxContainer>(key)) {
444 sc = m_detStore->retrieve(container, key);
445 }
446
447 if (sc.isFailure()) {
448 if (msgLvl(MSG::INFO))
449 msg(MSG::INFO) << "Cannot find StrawDxContainer for key "
450 << key << " - no fine alignment " << endmsg;
451 throw std::runtime_error("Unable to apply TRT fine alignment. This is normal for simulation");
452 } else {
453 this->setDxContainer(container);
454 return true; //Elements will need to be invalidated via invalidateAll from the caller
455 }
456 }
457
458 bool TRT_DetectorManager::processSpecialAlignment(const std::string& /*key*/,
459 const CondAttrListCollection* /*obj*/,
460 GeoVAlignmentStore* /*alignStore*/) const {
461 return false;
462 }
463
464
466 {
467 return this;
468 }
469
470 // New global alignment filders
471 bool TRT_DetectorManager::processGlobalAlignment(const std::string & key, int level, FrameType frame,
472 const CondAttrListCollection* obj, GeoVAlignmentStore* alignStore) const
473 {
474
475 bool alignmentChange = false;
476
477 ATH_MSG_INFO("Processing new global alignment containers with key " << key << " in the " << frame << " frame at level " << level);
478
479 Identifier ident=Identifier();
480 const CondAttrListCollection* atrlistcol=obj;
481 //cppcheck-suppress nullPointerRedundantCheck
482 if (!atrlistcol) {
483 ATH_MSG_INFO("Read alignment from detector store with key " << key);
484 if (StatusCode::SUCCESS!=m_detStore->retrieve(atrlistcol,key)) {
485 ATH_MSG_WARNING("Cannot find new global align Container for key "
486 << key << " - no new global alignment");
487 return alignmentChange;
488 }
489 }
490 // Avoid cppcheck warning.
491 if (!atrlistcol) {
492 return alignmentChange;
493 }
494 {
495 // loop over objects in collection
496 //cppcheck-suppress nullPointerRedundantCheck
497 for (const auto & citr : *atrlistcol) {
498
499 const coral::AttributeList& atrlist=citr.second;
500 ident = getIdHelper()->module_id(atrlist["bec"].data<int>(),
501 atrlist["layer"].data<int>(),
502 atrlist["sector"].data<int>());
503
504 // Follow same definitions as in TRT_AlignDbSvc.cxx
505 CLHEP::Hep3Vector newtranslation(atrlist["Tx"].data<float>(),atrlist["Ty"].data<float>(),atrlist["Tz"].data<float>());
506 CLHEP::HepRotation newrotation;
507 newrotation.set(atrlist["phi"].data<float>(),atrlist["theta"].data<float>(),atrlist["psi"].data<float>());
508 HepGeom::Transform3D newtransform(newrotation, newtranslation);
509
510 msg(MSG::DEBUG) << "New global DB -- channel: " << citr.first
511 << " ,bec: " << atrlist["bec"].data<int>()
512 << " ,layer: " << atrlist["layer"].data<int>()
513 << " ,sector: " << atrlist["sector"].data<int>()
514 << " ,Tx: " << atrlist["Tx"].data<float>()
515 << " ,Ty: " << atrlist["Ty"].data<float>()
516 << " ,Tz: " << atrlist["Tz"].data<float>()
517 << " ,phi: " << atrlist["phi"].data<float>()
518 << " ,theta: " << atrlist["theta"].data<float>()
519 << " ,psi: " << atrlist["psi"].data<float>() << endmsg;
520
521 // Set the new transform; Will replace existing one with updated transform
522 bool status = setAlignableTransformDelta(level,
523 ident,
524 Amg::CLHEPTransformToEigen(newtransform),
525 frame,
526 alignStore);
527
528 if (!status) {
529 if (msgLvl(MSG::DEBUG)) {
530 msg(MSG::DEBUG) << "Cannot set AlignableTransform for identifier."
531 << getIdHelper()->show_to_string(ident)
532 << " at level " << level << " for new global DB " << endmsg;
533 }
534 }
535
536 alignmentChange = (alignmentChange || status);
537 }
538 }
539 return alignmentChange;
540 }
541
543 {
544 m_barrelDescriptors.insert(barrelDescriptor);
545 }
546
548 {
549 m_endcapDescriptors.insert(endcapDescriptor);
550 }
551
552} // namespace InDetDD
#define endmsg
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t sc
Class for storing/accessing trt endpoint corrections data.
MsgStream & msg() const
The standard message stream.
bool msgLvl(const MSG::Level lvl) const
Test the output level.
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
bool is_trt(Identifier id) const
This class is a collection of AttributeLists where each one is associated with a channel number.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
size_type size() const noexcept
Returns the number of elements in the collection.
This is a "hash" representation of an Identifier.
Class to hold alignable transform plus a pointer to the child volume and optionally a frame volume.
InDetDetectorManager(StoreGateSvc *detStore, const std::string &name)
Local Straw Positions (from the center of the module.)
Extended TRT_BaseElement to describe a TRT readout element, this is a planar layer with n ( order of ...
Virtual base class of TRT readout elements.
void setDxContainer(const TRTCond::StrawDxContainer *container)
Class to hold collection of TRT detector elements.
Class to hold different TRT detector elements structures.
virtual const TRT_ID * getIdHelper() const override
const GeoXF::Function * m_barrelXF[3]
const TRT_BaseElement * getElement(Identifier id) const
Access Elements Generically---------------------------------------------—.
virtual bool processGlobalAlignment(const std::string &, int level, FrameType frame, const CondAttrListCollection *obj, GeoVAlignmentStore *alignStore) const override
Process new global DB folders for L1 and L2.
void manageBarrelElement(TRT_BarrelElement *barrel)
const TRT_BarrelElement * getBarrelElement(unsigned int positive, unsigned int moduleIndex, unsigned int phiIndex, unsigned int strawLayerIndex) const
Access Barrel Elements:---------------—(Fast)-------------------------—.
void setBarrelTransformField(size_t i, const GeoXF::Function *field)
virtual void invalidateAll() override
Invalidate cache for all detector elements.
void setGasType(const ActiveGasType &)
TRT_Numerology * getNumerology()
Access Numerological information:---------------------------------------—.
const GeoXF::Function * endcapTransformField(size_t i) const
bool processSpecialAlignment(const std::string &key, InDetDD::AlignFolderType dummy) override
std::set< const TRT_BarrelDescriptor * > m_barrelDescriptors
void setBarrelDescriptor(const TRT_BarrelDescriptor *barrelDescriptor)
Set TRT_Barrel/EndcapDescriptor pointer to the internal sets to delete them in the destructor.
virtual bool identifierBelongs(const Identifier &id) const override
Check identifier is for this detector.
TRT_DetectorManager(StoreGateSvc *detStore)
virtual void updateAll() const override
Update all caches.
bool setAlignableTransformAnyFrameDelta(ExtendedAlignableTransform *extXF, const Amg::Transform3D &delta, FrameType frame, GeoVAlignmentStore *alignStore) const
Set alignable transforms: Amg based.
StatusCode alignmentCallback()
Call back for alignment updates, DEPRECATED.
virtual PVConstLink getTreeTop(unsigned int i) const override
TRT_DetElementCollection::const_iterator getDetectorElementBegin() const
void setEndcapTransformField(size_t i, const GeoXF::Function *field)
const TRT_Conditions * conditions() const
Conditions interface (mostly for internal use):-------------------------—.
std::vector< AlignableTransformMap > m_alignableTransforms
const TRT_DetElementContainer * getDetectorElementContainer() const
Access the element container -------------------------------------------—.
TRT_DetElementCollection::const_iterator getDetectorElementEnd() const
const GeoXF::Function * barrelTransformField(size_t i) const
void setEndcapDescriptor(const TRT_EndcapDescriptor *endcapDescriptor)
void manageEndcapElement(TRT_EndcapElement *endcap)
void addAlignableTransform(int level, const Identifier &id, GeoAlignableTransform *transform, const GeoVFullPhysVol *child=0, const GeoVFullPhysVol *frameVol=0)
Add alignable transforms: GeoModel/CLHEP based.
const TRT_EndcapElement * getEndcapElement(unsigned int positive, unsigned int wheelIndex, unsigned int strawLayerIndex, unsigned int phiIndex) const
Access Endcap Elements:---------------—(Fast)--------------------------—.
virtual bool setAlignableTransformDelta(int level, const Identifier &id, const Amg::Transform3D &delta, FrameType frame, GeoVAlignmentStore *alignStore) const override
Set alignable transforms: Amg based.
void setIdHelper(const TRT_ID *idHelper, bool owns=true)
Get the ID helper: -----------------------------------------------------—.
virtual unsigned int getNumTreeTops() const override
Access Raw Geometry:----------------------------------------------------—.
std::set< const TRT_EndcapDescriptor * > m_endcapDescriptors
TRT_DetElementContainer m_elementContainer
const TRT_DetElementCollection * getDetectorElementCollection() const
Access to Whole Collection of Elements ---------------------------------—.
const GeoXF::Function * m_endcapXF[3]
class TRT_EndcapDescriptor
Extended class of a TRT_BaseElement to describe a readout elment in the endcap.
Helper class to organize the straw elements on TRT readout elements.
The Athena Transient Store API.
specialise to detector level
This is an Identifier helper class for the TRT subdetector.
Definition TRT_ID.h:82
Identifier module_id(int barrel_ec, int phi_module, int layer_or_wheel) const
For an individual module phi sector.
Definition TRT_ID.h:442
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Eigen::Affine3d Transform3D
Message Stream Member.
const int FIRST_HIGHER_LEVEL
Definition index.py:1