ATLAS Offline Software
Loading...
Searching...
No Matches
LArAlignHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "GeoModelKernel/GeoFullPhysVol.h"
8#include "GeoModelKernel/GeoAlignableTransform.h"
14
16 : AthMessaging("LArAlignHelper")
17{
18}
19
21 , const DetCondKeyTrans* detCondKeyTrans
22 , GeoAlignmentStore* alignmentStore) const
23{
24 ATH_MSG_DEBUG("Applying LAr Alignments to GeoModel");
25
26 // Special treatment for the HEC:
27 StoredAlignX *hec1AlxPos{nullptr};
28 StoredAlignX *hec2AlxPos{nullptr};
29 StoredAlignX *hec1AlxNeg{nullptr};
30 StoredAlignX *hec2AlxNeg{nullptr};
31 if (detStore->contains<StoredAlignX> ("HEC1_POS")) {
32 if (detStore->retrieve(hec1AlxPos,"HEC1_POS")!=StatusCode::SUCCESS) {
33 ATH_MSG_WARNING(" Unable to retrieve StoredAlignX for the key HEC1_POS");
34 }
35 }
36 if (detStore->contains<StoredAlignX> ("HEC1_NEG")) {
37 if (detStore->retrieve(hec1AlxNeg,"HEC1_NEG")!=StatusCode::SUCCESS) {
38 ATH_MSG_WARNING(" Unable to retrieve StoredAlignX for the key HEC1_NEG");
39 }
40 }
41 if (detStore->contains<StoredAlignX> ("HEC2_POS")) {
42 if (detStore->retrieve(hec2AlxPos,"HEC2_POS")!=StatusCode::SUCCESS) {
43 ATH_MSG_WARNING(" Unable to retrieve StoredAlignX for the key HEC2_POS");
44 }
45 }
46 if (detStore->contains<StoredAlignX> ("HEC2_NEG")) {
47 if (detStore->retrieve(hec2AlxNeg,"HEC2_NEG")!=StatusCode::SUCCESS) {
48 ATH_MSG_WARNING(" Unable to retrieve StoredAlignX for the key HEC2_NEG");
49 }
50 }
51 GeoAlignableTransform *hec1GatPos = hec1AlxPos ? hec1AlxPos->getAlignX(): nullptr;
52 GeoAlignableTransform *hec1GatNeg = hec1AlxPos ? hec1AlxNeg->getAlignX(): nullptr;
53 GeoAlignableTransform *hec2GatPos = hec2AlxPos ? hec2AlxPos->getAlignX(): nullptr;
54 GeoAlignableTransform *hec2GatNeg = hec2AlxPos ? hec2AlxNeg->getAlignX(): nullptr;
55
56 // Loop over align names and if a transform is present, then alter its delta
57 for(const std::string& alignName : m_alignNames) {
58 ATH_MSG_DEBUG("Working on align name " << alignName);
59 HepGeom::Transform3D newDelta;
60 // First try to retrieve StoredAlignX
61 if(detStore->contains<StoredAlignX>(alignName)) {
62 StoredAlignX* alignX{nullptr};
63 if(detStore->retrieve(alignX,alignName).isFailure()) {
64 ATH_MSG_ERROR(" Unable to retrieve StoredAlignX for the key " << alignName);
65 return StatusCode::FAILURE;
66 }
67
68 if(!alignX) {
69 ATH_MSG_ERROR("Null pointer to StoredAlignX for the key " << alignName);
70 return StatusCode::FAILURE;
71 }
72
73 GeoAlignableTransform* gat = alignX->getAlignX();
74 if(!gat) {
75 ATH_MSG_ERROR("Null pointer to GeoAlignableTransform for the key " << alignName);
76 return StatusCode::FAILURE;
77 }
78
79 // Check the existence of new delta in DetCondKeyTrans
80 if(detCondKeyTrans->getTransform(alignName,newDelta)) {
81 gat->setDelta(Amg::CLHEPTransformToEigen(newDelta),alignmentStore);
82 }
83 else {
84 gat->clearDelta(alignmentStore);
85 }
86 }
87 else if (alignName=="HEC_POS") {
88 if (hec1GatPos) {
89 if(detCondKeyTrans->getTransform(alignName,newDelta)) {
90 hec1GatPos->setDelta(Amg::CLHEPTransformToEigen(newDelta),alignmentStore);
91 }
92 else {
93 hec1GatPos->clearDelta(alignmentStore);
94 }
95 }
96 if (hec2GatPos) {
97 if(detCondKeyTrans->getTransform(alignName,newDelta)) {
98 hec2GatPos->setDelta(Amg::CLHEPTransformToEigen(newDelta),alignmentStore);
99 }
100 else {
101 hec2GatPos->clearDelta(alignmentStore);
102 }
103 }
104 }
105 else if (alignName=="HEC_NEG") {
106 if (hec1GatNeg) {
107 if(detCondKeyTrans->getTransform(alignName,newDelta)) {
108 hec1GatNeg->setDelta(Amg::CLHEPTransformToEigen(newDelta),alignmentStore);
109 }
110 else {
111 hec1GatNeg->clearDelta(alignmentStore);
112 }
113 }
114 if (hec2GatNeg) {
115 if(detCondKeyTrans->getTransform(alignName,newDelta)) {
116 hec2GatNeg->setDelta(Amg::CLHEPTransformToEigen(newDelta),alignmentStore);
117 }
118 else {
119 hec2GatNeg->clearDelta(alignmentStore);
120 }
121 }
122 }
123 else {
124 ATH_MSG_DEBUG(" No StoredAlignX for the key " << alignName);
125 }
126 } // Loop over Align Names
127
128 // Fill the caches of Full Physical Volumes
129 //
130 // !!! NB! The code assumes that StoredPhysVol-s are used only by LAr
131 // This has been true ever since the StorePhysVol-s were invented.
132 //
133 std::vector<std::string> keys;
134 detStore->keys<StoredPhysVol> (keys);
135 for(const std::string& key : keys) {
136 StoredPhysVol* storedPV = detStore->tryRetrieve<StoredPhysVol>(key);
137 ATH_MSG_DEBUG("Building position caches for StoredPhysVol :" << key);
138 if(storedPV) {
139 storedPV->getPhysVol()->getAbsoluteTransform(alignmentStore);
140 storedPV->getPhysVol()->getDefAbsoluteTransform(alignmentStore);
141 }
142 }
143
144 // Debug printout of global positions
145 if (msgLvl (MSG::DEBUG)) {
146 for(const std::string& alignName : m_alignNames) {
147 if(detStore->contains<StoredPhysVol>(alignName)) {
148 StoredPhysVol* storedPV{nullptr};
149 if(detStore->retrieve(storedPV,alignName).isSuccess()) {
150 const GeoIntrusivePtr<GeoFullPhysVol> fullPV = storedPV->getPhysVol();
151 const GeoTrf::Transform3D& xf = fullPV->getAbsoluteTransform(alignmentStore);
152 GeoTrf::Vector3D trans=xf.translation();
153 GeoTrf::RotationMatrix3D rot=xf.rotation();
154 ATH_MSG_DEBUG("Dump Absolute Transform: Key " << alignName
155 << " translation [" << trans.x() << "," << trans.y() << "," << trans.z()
156 << "] rotation (" << rot(0,0) << "," << rot(0,1) << "," << rot(0,2)
157 << "," << rot(1,0) << "," << rot(1,1) << "," << rot(1,2)
158 << "," << rot(2,0) << "," << rot(2,1) << "," << rot(2,2) << ")");
159 }
160 }
161 }
162 }
163
164 return StatusCode::SUCCESS;
165}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool msgLvl(const MSG::Level lvl) const
Test the output level.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
bool getTransform(const std::string &key, HepGeom::Transform3D &result) const
Ensure that the extensions for the Vector3D are properly loaded.
std::vector< std::string > m_alignNames
StatusCode applyAlignments(const ServiceHandle< StoreGateSvc > &detStore, const DetCondKeyTrans *detCondKeyTrans, GeoAlignmentStore *alignmentStore) const
GeoAlignableTransform * getAlignX()
GeoFullPhysVol * getPhysVol()
Destructor.
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.