ATLAS Offline Software
Loading...
Searching...
No Matches
TestSiAlignment.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include "CLHEP/Units/SystemOfUnits.h"
8
16#include "Identifier/Identifier.h"
19
20#include <iostream>
21#include <vector>
22#include <string>
23
24using std::cout;
25using std::endl;
26
27using namespace InDetDD;
28// or just the ones we need.
29// using InDetDD::SiDetectorManager;
30// using InDetDD::SiDetectorElement;
31// using InDetDD::SiDetectorElementCollection;
32// using InDetDD::SiLocalPosition;
33// using InDetDD::SiCellId;
34// using InDetDD::SiIntersect;
35
37//
38// Prints out SiDetectorElement positions and other info.
39
41
42TestSiAlignment::TestSiAlignment(const std::string& name, ISvcLocator* pSvcLocator) :
43 AthAlgorithm(name, pSvcLocator),
44 m_manager(nullptr),
46{
47 // Get parameter values from jobOptions file
48 declareProperty("ManagerName", m_managerName);
49 declareProperty("LongPrintOut", m_longPrintOut = false);
50 declareProperty("ErrorRotation",m_errRot = 1e-15); // For testing if alignment changed
51 declareProperty("ErrorTranslation",m_errTrans = 1e-12); // For testing if alignment changed
52}
53
54// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
55
57
58 ATH_MSG_INFO( "Algorithm Properties" );
59 ATH_MSG_INFO( " ManagerName: " << m_managerName );
60 ATH_MSG_INFO( " LongPrintOut: " << (m_longPrintOut ? "true" : "false") );
61 ATH_MSG_INFO( " ErrorRotation: " << m_errRot );
62 ATH_MSG_INFO( " ErrorTranslation: " << m_errTrans );
63 // Retrieve Detector Manager
65 if (m_managerName!="Pixel" && m_managerName!="SCT") {
66 ATH_MSG_FATAL("m_managerName " << m_managerName << " is not appropriate name");
67 }
68 ATH_CHECK(m_detEleCollKey.initialize(m_managerName=="SCT"));
70 return StatusCode::SUCCESS;
71}
72
73
74void
75TestSiAlignment::printAlignmentShifts(const bool accessDuringInitialization) {
76 const bool useConditionStore = (m_managerName == "SCT" and (not accessDuringInitialization));
77 static const Amg::Vector3D zeroPoint(0., 0., 0.);
78 static const Amg::Vector3D phiAxis(1, 0, 0);
79 static const Amg::Vector3D etaAxis(0, 1, 0);
80 static const Amg::Vector3D depAxis(0, 0, 1);
81 const SiDetectorElementCollection* elements = nullptr;
82 if (useConditionStore) {
83 // Get SiDetectorElementCollection from ConditionStore
85 elements = detEle.retrieve();
86 if (elements==nullptr) {
87 ATH_MSG_FATAL(m_detEleCollKey.fullKey() << " could not be retrieved");
88 return;
89 }
90 } else {
91 elements = m_manager->getDetectorElementCollection();
92 }
93 for (const SiDetectorElement * element: *elements) {
94 if (element) {
95 // The id helper is available either through the manager or the elements
96 cout << element->getIdHelper()->show_to_string(element->identify());
97 // Get the default transform
98 Amg::Transform3D elementDefXF = element->defTransform();
99 Amg::Transform3D elementXF = element->transform();
100 Amg::Transform3D localDelta = elementDefXF.inverse() * elementXF;
101 Amg::Transform3D globalDelta = elementXF * elementDefXF.inverse();
102 Amg::Vector3D globalShift = elementXF * zeroPoint - elementDefXF * zeroPoint;
103 double alphaL,betaL,gammaL;
104 extractAlphaBetaGamma(localDelta,alphaL,betaL,gammaL);
105 // test if it is the identity transform within some error
106 if (testIdentity(localDelta, m_errRot, m_errTrans)) {
107 cout << " NO SHIFT" << endl;
108 } else {
109 if (m_longPrintOut) {
110 double alphaG,betaG,gammaG;
111 extractAlphaBetaGamma(globalDelta,alphaG,betaG,gammaG);
112 cout << endl;
113 cout << " Local Shift" << endl;
114 cout << " delta trans " << localDelta * zeroPoint << " Rot: {" << alphaL << "," << betaL << "," << gammaL << "}" <<endl;
115 cout << " phiAxis " << phiAxis << " -> " << localDelta * phiAxis << endl;
116 cout << " etaAxis " << etaAxis << " -> " << localDelta * etaAxis << endl;
117 cout << " depAxis " << depAxis << " -> " << localDelta * depAxis << endl;
118 cout << " Global Shift" << endl;
119 cout << " shift " << globalShift << endl;
120 cout << " delta trans " << globalDelta * zeroPoint << " Rot: {" << alphaG << "," << betaG << "," << gammaG << "}" <<endl;
121 cout << " center " << elementDefXF * zeroPoint << " -> " << elementXF * zeroPoint << endl;
122 cout << " phiAxis " << elementDefXF * phiAxis << " -> " << elementXF * phiAxis << endl;
123 cout << " etaAxis " << elementDefXF * etaAxis << " -> " << elementXF * etaAxis << endl;
124 cout << " depAxis " << elementDefXF * depAxis << " -> " << elementXF * depAxis << endl;
125 } else {
126 cout << " Global shift: " << globalShift << " Local shift/Rot: " << localDelta * zeroPoint << " Rot: {"
127 << alphaL << "," << betaL << "," << gammaL << "}" <<endl;
128 }
129 }
130 } else {
131 cout << "Missing element!!!!!!!!!!!" << endl;
132 }
133 }
134 cout << endl;
135}
136
137bool
138TestSiAlignment::testIdentity(const Amg::Transform3D & transform, double errRot,double errTrans) {
139 using std::abs;
140 const Amg::Transform3D & t1 = transform;
142 t2.setIdentity();
143 // Rotation/Scale
144 for (int i=0; i < 3; i++){
145 for (int j=0; j < 3; j++){
146 double diff = abs(t1(i,j) - t2(i,j));
147 if (diff > errRot) return false;
148 }
149 }
150
151 // Translation
152 for (int ii = 0; ii < 3; ii++){
153 double diff = abs(t1(ii,3) - t2(ii,3));
154 if (diff > errTrans) return false;
155 }
156 return true;
157}
158
159void TestSiAlignment::extractAlphaBetaGamma(const Amg::Transform3D & trans, double& alpha, double& beta, double &gamma) const {
160 double siny = trans(0,2);
161 beta = asin(siny);
162 // Check if cosy = 0. This requires special treatment.
163 // can check either element (1,2),(2,2) both equal zero
164 // or (0,1) and (0,0)
165 if ((trans(1,2) == 0) && (trans(2,2) == 0)) {
166 // alpha and gamma are degenerate. We arbitrarily choose
167 // gamma = 0.
168 gamma = 0;
169 alpha = atan2(trans(1,1),trans(2,1));
170 } else {
171 alpha = atan2(-trans(1,2),trans(2,2));
172 gamma = atan2(-trans(0,1),trans(0,0));
173 if (alpha == 0) alpha = 0; // convert -0 to 0
174 if (gamma == 0) gamma = 0; // convert -0 to 0
175 }
176}
177
178// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
179
182 return StatusCode::SUCCESS;
183}
184
185// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
186
188 return StatusCode::SUCCESS;
189}
190
191
192
193
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
This is an Identifier helper class for the Pixel subdetector.
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
This is an Identifier helper class for the SCT subdetector.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Class to hold the SiDetectorElement objects to be put in the detector store.
Class to hold geometrical description of a silicon detector element.
const_pointer_type retrieve()
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_detEleCollKey
void extractAlphaBetaGamma(const Amg::Transform3D &trans, double &alpha, double &beta, double &gamma) const
const InDetDD::SiDetectorManager * m_manager
StatusCode initialize()
bool testIdentity(const Amg::Transform3D &transform, double errRot=0, double errTrans=0)
StatusCode finalize()
void printAlignmentShifts(const bool accessDuringInitialization)
std::string m_managerName
TestSiAlignment(const std::string &name, ISvcLocator *pSvcLocator)
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Message Stream Member.