ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_DetectorManager.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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
221 // Register the call back for this key and the corresponding level in
222 // in the hierarchy.
223 // DEPRECATED
224 void TRT_DetectorManager::addKey ATLAS_NOT_THREAD_SAFE (const std::string & key, int level) // Thread unsafe m_detStore->regFcn (callback) is used.
225 {
226 if(msgLvl(MSG::DEBUG))
227 msg(MSG::DEBUG) << "Registering alignmentCallback with key " << key << ", at level " << level
228 << endmsg;
229
230 const DataHandle<AlignableTransform> transformCollection;
231 if (m_detStore->regFcn(&TRT_DetectorManager::alignmentCallback, this, transformCollection, key).isFailure()) {
232 ATH_MSG_ERROR("Cannot register callback with DetectorStore");
233 }
234 addKey(key, level, InDetDD::other);
235 }
236
237 void TRT_DetectorManager::addKey(const std::string & key, int level, FrameType frame)
238 {
239 addChannel(key, level, frame);
240 }
241
243 const Identifier &id,
244 GeoAlignableTransform *transform,
245 const GeoVPhysVol * child,
246 const GeoVPhysVol * frameVol)
247 {
248 if (m_idHelper) {
249 // Check if child and frame are actually full physical volumes.
250 // if they are non zero.
251 const GeoVFullPhysVol * childFPV = nullptr;
252 if (child) {
253 childFPV = dynamic_cast<const GeoVFullPhysVol *>(child);
254 }
255 const GeoVFullPhysVol * frameFPV = nullptr;
256 if (frameVol) {
257 frameFPV = dynamic_cast<const GeoVFullPhysVol *>(frameVol);
258 }
259 if (child && !childFPV) {
260 msg(MSG::ERROR)
261 << "Child of alignable transform is not a full physical volume"
262 << endmsg;
263 } else if (frameVol && !frameFPV) {
264 msg(MSG::ERROR)
265 << "Frame for alignable transform is not a full physical volume"
266 << endmsg;
267 } else {
268 addAlignableTransform (level, id, transform, childFPV, frameFPV);
269 }
270 }
271 }
272
274 const Identifier &id,
275 GeoAlignableTransform *transform,
276 const GeoVFullPhysVol *child,
277 const GeoVFullPhysVol *frameVol)
278 {
279 if (m_idHelper) {
280 if (level == 0) {
281 // Nothing implemented. Reserved in case we want alignable straws.
282 } else {
283
284 ExtendedAlignableTransform * extAlignableTransform = new ExtendedAlignableTransform(transform, child, frameVol);
285 if(msgLvl(MSG::VERBOSE)) {
286 msg(MSG::VERBOSE) << "TRT: Adding alignment at level " << level << " " << m_idHelper->show_to_string(id);
287 if (child && !frameVol) {
288 msg(MSG::VERBOSE) << " using global frame";
289 } else if (!child || child == frameVol ) {
290 msg(MSG::VERBOSE) << " using local frame";
291 } else {
292 msg(MSG::VERBOSE) << " using other frame";
293 }
294 msg(MSG::VERBOSE) << endmsg;
295 }
296 // Save in map
297 int index = level - FIRST_HIGHER_LEVEL; // level 0 treated separately.
298 if (index >= static_cast<int>(m_alignableTransforms.size())) m_alignableTransforms.resize(index+1);
299 m_alignableTransforms[index][id] = extAlignableTransform;
300 }
301 }
302 }
303
305 const Identifier & id,
306 const Amg::Transform3D & delta,
307 FrameType frame,
308 GeoVAlignmentStore* alignStore) const
309 {
310 if (level == 0) {
311 // Nothing implemented. Reserved in case we want alignable straws
312 return false;
313 } else {
314
315 int index = level - FIRST_HIGHER_LEVEL; // level 0 treated separately.
316 if (index >= static_cast<int>(m_alignableTransforms.size())) return false;
317
318 // We retrieve it from a map.
319 AlignableTransformMap::const_iterator iter;
320 iter = m_alignableTransforms[index].find(id);
321 if (iter == m_alignableTransforms[index].end()) return false;
322
323 return setAlignableTransformAnyFrameDelta(iter->second, delta, frame, alignStore);
324
325 }
326 }
327
329 const Amg::Transform3D & delta,
330 FrameType frame,
331 GeoVAlignmentStore* alignStore) const
332 {
333 //---------------------
334 // For Local:
335 //---------------------
336 // The geomodel alignable transform delta is already a local delta so we just pass it directly
337
338 //---------------------
339 // For global frame
340 //---------------------
341 // Sets the alignable transform delta when the supplied delta is in the global frame.
342
343 // If the default transform down to the alignable transform is
344 // T = A*B*C
345 // and the alignable transform is C with delta c and the delta in the global frame is g, then
346 // A*B*C*c = g*A*B*C
347 // T*c = g*T
348 // c = T.inverse() * g * T
349
350 // To get default transform up and including the alignable transform,
351 // we assume the next volume down is a fullphys volume and so its
352 // transform is the transform we want (ie T=A*B*C in the above example).
353
354 //---------------------
355 // For Other frame
356 //---------------------
357 // Sets the alignable transform delta when the supplied delta is in the frame of the
358 // volume "frameVol".
359
360 // If the default transform down to the alignable transform is
361 // T = A*B*C
362 // and the alignable transform is C with delta c and the delta g is expressed in the frame A, then
363 // A*B*C*c = A*g*B*C
364 // c = (BC).inverse * g * (BC)
365 // BC = A.inverse() * T
366 // C = T.inverse() * A * g * A.inverse() * T
367
368 // To get default transform up and including the alignable transform,
369 // we assume the next volume down is a fullphys volume and so its
370 // transform is the transform we want (ie T=A*B*C in the above example).
371 // The Transform to the frame is T = A which we get from the fullphys volume frameVol.
372
373 if (!extXF) return false;
374 if (!extXF->alignableTransform()) return false;
375
376 const GeoVFullPhysVol * child = extXF->child();
377 const GeoVFullPhysVol * frameVol = extXF->frame();
378
379 FrameType newFrame = frame;
380 // If frame is other then check if "other" is actually local or global
381 if (frame == InDetDD::other) {
382 if (child && !frameVol) {
383 // frame = 0 indicates to use global frame
384 newFrame = InDetDD::global;
385 } else if (!child || child == frameVol){
386 // if child is 0 or the they are the same volumes then its local
387 newFrame = InDetDD::local;
388 } // else its "other" already.
389 }
390
391 if (newFrame == InDetDD::global) { // Global
392 if (!child) {
393 msg(MSG::ERROR) << "global frame specified, but child == 0" << endmsg;
394 } else {
395 const GeoTrf::Transform3D & childXF = child->getDefAbsoluteTransform(alignStore);
396 extXF->alignableTransform()->setDelta(childXF.inverse() * delta * childXF, alignStore);
397 }
398
399 } else if (frame == InDetDD::local) { // Local
400 // if its a local frame then no transform necessary. We set it directly.
401 extXF->alignableTransform()->setDelta(delta, alignStore);
402
403 } else { // Other frame
404 // if child or frame is zero it will have been set to local or global above
405 if (!child) { // CID 113112
406 // shouldn't be happening, if child is null then something is terribly wrong
407 ATH_MSG_ERROR("Child can't be null if frame is 'other'");
408 return false;
409 } else {
410 const GeoTrf::Transform3D & xfChild = child->getDefAbsoluteTransform(alignStore);
411 const GeoTrf::Transform3D & xfFrame = frameVol->getDefAbsoluteTransform(alignStore);
412 extXF->alignableTransform()->setDelta(xfChild.inverse() * xfFrame * delta * xfFrame.inverse() * xfChild, alignStore);
413 }
414 }
415
416 return true;
417 }
418
419
421 {
422 return align(I, keys);
423 }
424
425
426 // We invalidate all the elements if at least one alignment changed.
428 {
430 element_iter != getDetectorElementEnd();
431 ++element_iter) {
432 if (*element_iter) {
433 (*element_iter)->invalidate();
434 }
435 }
436 }
437
439 {
441 element_iter != getDetectorElementEnd();
442 ++element_iter) {
443
444 if (*element_iter) {
445 (*element_iter)->updateAllCaches();
446 }
447 }
448 }
449
450
452 {
453 return getIdHelper()->is_trt(id);
454 }
455
456
458 {
459 if(msgLvl(MSG::DEBUG))
460 msg(MSG::DEBUG) << "Processing TRT fine alignment." << endmsg;
461
462 const TRTCond::StrawDxContainer* container = nullptr;
463 StatusCode sc = StatusCode::FAILURE;
464 if (m_detStore->contains<TRTCond::StrawDxContainer>(key)) {
465 sc = m_detStore->retrieve(container, key);
466 }
467
468 if (sc.isFailure()) {
469 if (msgLvl(MSG::INFO))
470 msg(MSG::INFO) << "Cannot find StrawDxContainer for key "
471 << key << " - no fine alignment " << endmsg;
472 throw std::runtime_error("Unable to apply TRT fine alignment. This is normal for simulation");
473 } else {
474 this->setDxContainer(container);
475 return true; //Elements will need to be invalidated via invalidateAll from the caller
476 }
477 }
478
479 bool TRT_DetectorManager::processSpecialAlignment(const std::string& /*key*/,
480 const CondAttrListCollection* /*obj*/,
481 GeoVAlignmentStore* /*alignStore*/) const {
482 return false;
483 }
484
485
487 {
488 return this;
489 }
490
491 // New global alignment filders
492 bool TRT_DetectorManager::processGlobalAlignment(const std::string & key, int level, FrameType frame,
493 const CondAttrListCollection* obj, GeoVAlignmentStore* alignStore) const
494 {
495
496 bool alignmentChange = false;
497
498 ATH_MSG_INFO("Processing new global alignment containers with key " << key << " in the " << frame << " frame at level " << level);
499
500 Identifier ident=Identifier();
501 const CondAttrListCollection* atrlistcol=obj;
502 //cppcheck-suppress nullPointerRedundantCheck
503 if (!atrlistcol) {
504 ATH_MSG_INFO("Read alignment from detector store with key " << key);
505 if (StatusCode::SUCCESS!=m_detStore->retrieve(atrlistcol,key)) {
506 ATH_MSG_WARNING("Cannot find new global align Container for key "
507 << key << " - no new global alignment");
508 return alignmentChange;
509 }
510 }
511 // Avoid cppcheck warning.
512 if (!atrlistcol) {
513 return alignmentChange;
514 }
515 {
516 // loop over objects in collection
517 //cppcheck-suppress nullPointerRedundantCheck
518 for (const auto & citr : *atrlistcol) {
519
520 const coral::AttributeList& atrlist=citr.second;
521 ident = getIdHelper()->module_id(atrlist["bec"].data<int>(),
522 atrlist["layer"].data<int>(),
523 atrlist["sector"].data<int>());
524
525 // Follow same definitions as in TRT_AlignDbSvc.cxx
526 CLHEP::Hep3Vector newtranslation(atrlist["Tx"].data<float>(),atrlist["Ty"].data<float>(),atrlist["Tz"].data<float>());
527 CLHEP::HepRotation newrotation;
528 newrotation.set(atrlist["phi"].data<float>(),atrlist["theta"].data<float>(),atrlist["psi"].data<float>());
529 HepGeom::Transform3D newtransform(newrotation, newtranslation);
530
531 msg(MSG::DEBUG) << "New global DB -- channel: " << citr.first
532 << " ,bec: " << atrlist["bec"].data<int>()
533 << " ,layer: " << atrlist["layer"].data<int>()
534 << " ,sector: " << atrlist["sector"].data<int>()
535 << " ,Tx: " << atrlist["Tx"].data<float>()
536 << " ,Ty: " << atrlist["Ty"].data<float>()
537 << " ,Tz: " << atrlist["Tz"].data<float>()
538 << " ,phi: " << atrlist["phi"].data<float>()
539 << " ,theta: " << atrlist["theta"].data<float>()
540 << " ,psi: " << atrlist["psi"].data<float>() << endmsg;
541
542 // Set the new transform; Will replace existing one with updated transform
543 bool status = setAlignableTransformDelta(level,
544 ident,
545 Amg::CLHEPTransformToEigen(newtransform),
546 frame,
547 alignStore);
548
549 if (!status) {
550 if (msgLvl(MSG::DEBUG)) {
551 msg(MSG::DEBUG) << "Cannot set AlignableTransform for identifier."
552 << getIdHelper()->show_to_string(ident)
553 << " at level " << level << " for new global DB " << endmsg;
554 }
555 }
556
557 alignmentChange = (alignmentChange || status);
558 }
559 }
560 return alignmentChange;
561 }
562
564 {
565 m_barrelDescriptors.insert(barrelDescriptor);
566 }
567
569 {
570 m_endcapDescriptors.insert(endcapDescriptor);
571 }
572
573} // 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
#define IOVSVC_CALLBACK_ARGS_P(I, K)
short hand for IOVSvc call back argument list, to be used when access to formal arguments is needed,...
Definition IOVSvcDefs.h:42
static Double_t sc
#define I(x, y, z)
Definition MD5.cxx:116
Class for storing/accessing trt endpoint corrections data.
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
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.
an iterator over instances of a given type in StoreGateSvc.
Definition DataHandle.h:43
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)
void addChannel(const std::string &key, int level, FrameType frame)
Alignment access.
StatusCode align(IOVSVC_CALLBACK_ARGS)
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.
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)
StatusCode alignmentCallback(IOVSVC_CALLBACK_ARGS)
Call back for alignment updates, DEPRECATED.
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: -----------------------------------------------------—.
void addKey(const std::string &key, int level, FrameType frame)
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
MsgStream & msg
Definition testRead.cxx:32