ATLAS Offline Software
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 }
GeoAlignmentStore
Ensure that the extensions for the Vector3D are properly loaded.
Definition: GeoAlignmentStore.h:24
LArAlignHelper.h
DetCondKeyTrans
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
Definition: DetCondKeyTrans.h:27
StoredAlignX
Definition: StoredAlignX.h:23
StoredAlignX.h
StoredPhysVol
Definition: StoredPhysVol.h:27
StoredPhysVol::getPhysVol
GeoFullPhysVol * getPhysVol()
Destructor.
Definition: StoredPhysVol.cxx:20
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthMessaging::msgLvl
bool msgLvl(const MSG::Level lvl) const
Test the output level.
Definition: AthMessaging.h:151
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
DetCondKeyTrans.h
CLHEPtoEigenConverter.h
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
GeoAlignmentStore.h
LArAlignHelper::applyAlignments
StatusCode applyAlignments(const ServiceHandle< StoreGateSvc > &detStore, const DetCondKeyTrans *detCondKeyTrans, GeoAlignmentStore *alignmentStore) const
Definition: LArAlignHelper.cxx:20
DetCondKeyTrans::getTransform
bool getTransform(const std::string &key, HepGeom::Transform3D &result) const
Definition: DetCondKeyTrans.cxx:14
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Amg::CLHEPTransformToEigen
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Definition: CLHEPtoEigenConverter.h:38
Amg::RotationMatrix3D
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Definition: GeoPrimitives.h:49
DEBUG
#define DEBUG
Definition: page_access.h:11
LArAlignHelper::m_alignNames
std::vector< std::string > m_alignNames
Definition: LArAlignHelper.h:34
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
LArAlignHelper::LArAlignHelper
LArAlignHelper()
Definition: LArAlignHelper.cxx:15
StoredPhysVol.h
ServiceHandle< StoreGateSvc >
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37