ATLAS Offline Software
Loading...
Searching...
No Matches
TestTRT_Alignment.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 "CLHEP/Units/SystemOfUnits.h"
8
10#include "Identifier/Identifier.h"
13
14#include <iostream>
15#include <vector>
16#include <string>
17
18using std::cout;
19using std::endl;
20
21using namespace InDetDD;
22
23//anonymous namespace for utility functions at file scope
24namespace{
25 Amg::Transform3D zRotation(const double angle){
26 const Amg::Vector3D zAxis(0., 0., 1.);
28 }
29 Amg::Transform3D yTranslation(const double distance){
30 return Amg::Transform3D(Amg::Translation3D(0., distance, 0.));
31 }
32}
33
35//
36// Prints out SiDetectorElement positions and other info.
37
39
40TestTRT_Alignment::TestTRT_Alignment(const std::string& name, ISvcLocator* pSvcLocator) :
41 AthAlgorithm(name, pSvcLocator),
42 m_manager(nullptr),
43 m_idHelper(nullptr)
44{
45 // Get parameter values from jobOptions file
46 declareProperty("ManagerName", m_managerName = "TRT");
47 declareProperty("LongPrintOut", m_longPrintOut = false);
48 declareProperty("TestAllStraws", m_testAllStraws = false);
49 declareProperty("TestAllElements", m_testAllElements = 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 declareProperty("HardwiredShifts", m_hardwiredShifts = false);
53 declareProperty("Precision", m_precision = 6);
54}
55
56// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
57
59 msg(MSG::INFO) << "initialize()" << endmsg;
60 msg(MSG::INFO) << "Algorithm Properties" << endmsg;
61 msg(MSG::INFO) << " ManagerName: " << m_managerName << endmsg;
62 msg(MSG::INFO) << " LongPrintOut: " << (m_longPrintOut ? "true" : "false") << endmsg;
63 msg(MSG::INFO) << " TestAllElements: " << (m_testAllElements ? "true" : "false") << endmsg;
64 msg(MSG::INFO) << " TestAllStraws: " << (m_testAllStraws ? "true" : "false") << endmsg;
65 msg(MSG::INFO) << " ErrorRotation: " << m_errRot << endmsg;
66 msg(MSG::INFO) << " ErrorTranslation: " << m_errTrans << endmsg;
67 msg(MSG::INFO) << " Precision: " << m_precision << endmsg;
68 if (!m_testAllElements) {
69 msg(MSG::INFO) << endmsg;
70 msg(MSG::INFO) << " Modules only - the 4 corner straws of each module will be printed. " << endmsg;
71 if (m_testAllStraws) {
72 msg(MSG::INFO) << " NB. TestAllStraws flag is ignored" << endmsg;
73 }
74 }
75 // Retrieve GeoModel Detector Elements
76 // You can either get the SCT or pixel manager or the common base class
77 // manager. In this example I get the base class.
78 // const SiTrackerDetectorManager * manager;
79 // or
80 // const PixelDetectorManager * manager;
81 // const SCT_DetectorManager * manager;
82 // const SiDetectorManager * manager;
83 StatusCode sc = detStore()->retrieve(m_manager, m_managerName);
84 if (sc.isFailure() || !m_manager) {
85 msg(MSG::FATAL) << "Could not find the Manager: "<< m_managerName << " !" << endmsg;
86 return StatusCode::FAILURE;
87 } else {
88 msg(MSG::DEBUG) << "Manager found" << endmsg;
89 }
90 // Get ID helper
91 if (detStore()->retrieve(m_idHelper, "TRT_ID").isFailure()) {
92 msg(MSG::FATAL) << "Could not get TRT ID helper" << endmsg;
93 return StatusCode::FAILURE;
94 }
97 //translation/rotation are inverted to get the same result between Eigen and CLHEP
98 const unsigned int nTests(3);
99 const double distances[nTests]={0.2679 * CLHEP::mm, -0.4254 * CLHEP::mm, 0.0264 * CLHEP::mm};
100 const double angles[nTests]={atan(-0.0001639), atan(0.0003195), atan(0.0000053)};
101 const Amg::Translation3D translation(0., 11.93*CLHEP::mm, 0.);
102 const Amg::Vector3D zAxis(0., 0., 1.);
103 //this really needs checking!
104 Amg::Transform3D zRotations[nTests] = {zRotation(angles[0]), zRotation(angles[1]), zRotation(angles[2])};
105 Amg::Transform3D yTranslations[nTests]={yTranslation(distances[0]), yTranslation(distances[1]), yTranslation(distances[2])};
106 addShiftTop(Amg::Transform3D(translation));
107 addShiftModule(1,0,0, zRotations[0]*yTranslations[0]);
108 addShiftModule(1,0,1, zRotations[1]*yTranslations[1]);
109 addShiftModule(1,0,2, zRotations[2]*yTranslations[2]);
110 //
111 addShiftModule(1,1,0, Amg::Transform3D::Identity());
112 addShiftModule(1,1,1, Amg::Transform3D::Identity());
113 addShiftModule(1,1,2, Amg::Transform3D::Identity());
124 }
126 return StatusCode::SUCCESS;
127}
128
129
130void
132 Identifier id = m_idHelper->barrel_ec_id(1);
133 addShift(2, id, transform);
134}
135
136
137void
138TestTRT_Alignment::addShiftModule(int bec, int phiMod, int layer, const Amg::Transform3D & transform)
139{
140 Identifier id = m_idHelper->module_id(bec, phiMod, layer);
141 addShift(1, id, transform);
142}
143
144
145void
146TestTRT_Alignment::addShift(int level, const Identifier & id, const Amg::Transform3D & transform)
147{
148 m_manager->setAlignableTransformDelta(level, id, transform, InDetDD::other, nullptr);
149}
150
151
153 // Part 1: Get the messaging service, print where you are
154 msg(MSG::INFO) << "execute()" << endmsg;
156 return StatusCode::SUCCESS;
157}
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
160
162 // Part 1: Get the messaging service, print where you are
163 msg(MSG::INFO) << "finalize()" << endmsg;
164 return StatusCode::SUCCESS;
165}
166
167void
169 int oldPrec = cout.precision(m_precision);
170 if (m_testAllElements) {
171 unsigned int maxHash = m_idHelper->straw_layer_hash_max();
172 for (unsigned int index = 0; index < maxHash; index++) {
173 IdentifierHash idHash = index;
174 Identifier id = m_idHelper->layer_id(idHash);
175 m_idHelper->show(id);
176 const TRT_BaseElement * element;
177 element = m_manager->getElement(idHash);
178 if (element) {
179 // Test first and last straw
180 if (m_testAllStraws) {
181 for (unsigned int iStraw = 0; iStraw < element->nStraws(); iStraw++) {
182 compareStraw(element, iStraw);
183 }
184 } else {
185 compareStraw(element, 0);
186 compareStraw(element, element->nStraws() - 1);
187 }
188 } else {
189 cout << "No Element with id hash = " << idHash << endl;
190 }
191 } // loop over elements
192 } else { // Just modules
193 TRT_ID::const_id_iterator moduleIter;
194 for (moduleIter = m_idHelper->module_begin(); moduleIter != m_idHelper->module_end(); ++moduleIter) {
195 Identifier moduleId = *moduleIter;
196 cout << "Module " << m_idHelper->show_to_string(moduleId) << endl;
197 int numStrawLayers = m_idHelper->straw_layer_max(moduleId);
198 if (numStrawLayers) {
199 Identifier firstElementId = m_idHelper->layer_id(moduleId,0);
200 Identifier lastElementId = m_idHelper->layer_id(moduleId,numStrawLayers-1);
201 compareEndStraws(firstElementId);
202 compareEndStraws(lastElementId);
203 } else {
204 cout << "ERROR: No Elements in this module!" << endl;
205 }
206 }
207 }
208 cout.precision(oldPrec);
209}
210
211void
213 const TRT_BaseElement * element = m_manager->getElement(id);
214 cout << " " << m_idHelper->show_to_string(id) << endl;
215 if (element) {
216 compareStraw(element, 0);
217 compareStraw(element, element->nStraws() - 1);
218 } else {
219 cout << " No Element with id = " << m_idHelper->show_to_string(id) << endl;
220 }
221}
222
223
224void
226 static const Amg::Vector3D zeroPoint(0., 0., 0.);
227 static const Amg::Vector3D zAxis(0., 0., 1.);
228 const Amg::Transform3D& strawDefXF = element->strawTransform(straw);
229 const Amg::Transform3D& strawXF = element->strawTransform(straw);
230
231 Amg::Transform3D globalDelta = strawXF * strawDefXF.inverse();
232 // test if it is the identity transform within some error
233 if (testIdentity(globalDelta, m_errRot, m_errTrans)) {
234 cout << " Straw " << straw << ": NO SHIFT" << endl;
235 } else {
236 cout << " Straw " << straw << ": Global shift: " << globalDelta * zeroPoint << endl ;
237 if (m_longPrintOut) {
238 cout << " center " << strawDefXF * zeroPoint << " -> " << strawXF * zeroPoint << endl;
239 cout << " diff = " << strawXF * zeroPoint - strawDefXF * zeroPoint << endl;
240 cout << " strawAxis " << strawDefXF * zAxis << " -> " << strawXF * zAxis << endl;
241 }
242 }
243}
244
245
246bool
247TestTRT_Alignment::testIdentity(const Amg::Transform3D & transform, double errRot,double errTrans) {
248 using std::abs;
249 const Amg::Transform3D & t1 = transform;
250 const Amg::Transform3D t2 = Amg::Transform3D::Identity();
251 // Rotation/Scale
252 for (int i=0; i < 3; i++){
253 for (int j=0; j < 3; j++){
254 double diff = abs(t1(i,j) - t2(i,j));
255 if (diff > errRot) return false;
256 }
257 }
258 // Translation
259 for (int ii = 0; ii < 3; ii++){
260 double diff = abs(t1(ii,3) - t2(ii,3));
261 if (diff > errTrans) return false;
262 }
263 return true;
264}
#define endmsg
static Double_t sc
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
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
This is an Identifier helper class for the TRT 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
MsgStream & msg() const
This is a "hash" representation of an Identifier.
Virtual base class of TRT readout elements.
unsigned int nStraws() const
Number of straws in the element.
const Amg::Transform3D & strawTransform(unsigned int straw) const
Straw transform - fast access in array, in Tracking frame: Amg.
std::vector< Identifier >::const_iterator const_id_iterator
Definition TRT_ID.h:87
std::string m_managerName
void compareEndStraws(const Identifier &id)
bool testIdentity(const Amg::Transform3D &transform, double errRot=0, double errTrans=0)
const TRT_ID * m_idHelper
void addShiftModule(int bec, int phiMod, int layer, const Amg::Transform3D &transform)
void compareStraw(const InDetDD::TRT_BaseElement *element, int straw)
void addShiftTop(const Amg::Transform3D &transform)
TestTRT_Alignment(const std::string &name, ISvcLocator *pSvcLocator)
const InDetDD::TRT_DetectorManager * m_manager
void addShift(int level, const Identifier &id, const Amg::Transform3D &transform)
Eigen::AngleAxisd AngleAxis3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
Message Stream Member.
Definition index.py:1