ATLAS Offline Software
Loading...
Searching...
No Matches
ReadTRT_DetectorElements.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
12#include "Identifier/Identifier.h"
16
17#include <iostream>
18#include <vector>
19
20
21using std::cout;
22using std::endl;
23using namespace InDetDD;
24
25namespace{
26 const Amg::Vector3D origin(0., 0., 0.);
27}
28
29// Prints out TRT DetectorElement positions.
30
32
33ReadTRT_DetectorElements::ReadTRT_DetectorElements(const std::string& name, ISvcLocator* pSvcLocator) :
34 AthAlgorithm(name, pSvcLocator),
35 m_managerName("TRT"),
36 m_manager(nullptr),
37 m_idHelper(nullptr),
38 m_maxdiff(0),
39 m_first(true)
40{
41 // Get parameter values from jobOptions file
42 declareProperty("ManagerName", m_managerName);
43 declareProperty("DoInitialize", m_doInit = true);
44 declareProperty("DoExecute", m_doExec = false);
45}
46
47// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
48
50 msg(MSG::INFO) << "initialize()" << endmsg;
51 // Get the manager
52 StatusCode sc=detStore()->retrieve(m_manager, m_managerName);
53 if (sc.isFailure() || !m_manager) {
54 msg(MSG::FATAL) << "Could not find the Manager: "<< m_managerName << " !" << endmsg;
55 return StatusCode::FAILURE;
56 } else {
57 msg(MSG::DEBUG) << "Manager found" << endmsg;
58 }
59 // Get ID helper
60 if (detStore()->retrieve(m_idHelper, "TRT_ID").isFailure()) {
61 msg(MSG::FATAL) << "Could not get TRT ID helper" << endmsg;
62 return StatusCode::FAILURE;
63 }
65 return StatusCode::SUCCESS;
66}
67
68// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
69
71 msg(MSG::INFO) << "execute()" << endmsg;
72 // Only print out on first event
73 if (m_first && m_doExec) {
74 m_first = false;
76 }
77 return StatusCode::SUCCESS;
78}
79
81 // Retrieve GeoModel Detector Elements
82 // Get the id helper
83 const TRT_ID * idHelper = m_idHelper;
84 // Examples are shown below for accessing via index for barrel, then endcap and
85 // then accessing via hash
86 //
87 // Access via indices.
88 //
89 //
90 //
91 cout << "======================================" <<endl;
92 cout << " BARREL ELEMENTS - access via index" << endl;
93 cout << "======================================" <<endl;
94 cout << endl;
95 //cache numerology
96 const TRT_Numerology * numerology=m_manager->getNumerology();
97 //avoid getting these inside loops
98 const unsigned int nBarrelRings(numerology->getNBarrelRings());
99 const unsigned int nBarrelPhi(numerology->getNBarrelPhi());
100
101 for (int iSide = 0; iSide < 2; iSide++) {
102 for (unsigned int iLayer = 0; iLayer != nBarrelRings; iLayer++) {
103 const unsigned int nBarrelLayers(numerology->getNBarrelLayers(iLayer));
104 for (unsigned int iPhiModule = 0; iPhiModule != nBarrelPhi; iPhiModule++) {
105 for (unsigned int iStrawLayer = 0; iStrawLayer !=nBarrelLayers; iStrawLayer++) {
106 cout << "Barrel element " << iSide << ", " << iLayer << ", " << iPhiModule << ", "<< iStrawLayer << endl;
107 const TRT_BarrelElement *element = m_manager->getBarrelElement(iSide, iLayer, iPhiModule, iStrawLayer);
108 // Make identifier.
109 Identifier newId = idHelper->layer_id((iSide ? 1:-1), iPhiModule, iLayer, iStrawLayer);
110 idHelper->show(newId);
111 IdentifierHash idHash = idHelper->straw_layer_hash(newId);
112 cout << "idHash = " << idHash << endl;
113 if (element) {
114 Amg::Vector3D center = element->transform() * origin;
115 cout << " center = " << center << endl;
116 //cout << " strawDir = " << element->strawDirection() << endl;
117 cout << " number of straws = " << element->nStraws() << endl;
118 // Print out straw details of some elements
119 if ((iPhiModule == 0) || (iPhiModule == 1) || (iPhiModule == 7) || (iPhiModule == 31)) {
120 for (unsigned int istraw = 0; istraw < 15; istraw++) {
121 printStraw(element, istraw);
122 //printBarrelStraw(element, istraw);
123 }
124 }
125 // Compare methods
126 for (unsigned int istraw = 0; istraw < element->nStraws(); istraw++) {
127 compareBarrelStraw(element, istraw);
128 }
129 } else {
130 cout << "No Element found " << endl;
131 }
132 }
133 }
134 }
135 }
136
137 //
138 //
139 cout << "======================================" <<endl;
140 cout << " ENDCAP ELEMENTS - access via index" << endl;
141 cout << "======================================" <<endl;
142 cout << endl;
143 const unsigned int nWheels(numerology->getNEndcapWheels());
144 const unsigned int nEndcapPhi(numerology->getNEndcapPhi());
145 for (int iSide = 0; iSide < 2; iSide++) {
146 for (unsigned int iWheel = 0; iWheel !=nWheels ; iWheel++) {
147 const unsigned int nEndcapLayers(numerology->getNEndcapLayers(iWheel));
148 for (unsigned int iStrawLayer = 0; iStrawLayer != nEndcapLayers; iStrawLayer++){
149 for(unsigned int iPhi = 0; iPhi != nEndcapPhi; iPhi++){
150 cout << "Endcap element " << iSide << ", "<< iWheel << ", "<< iStrawLayer << ", "<< iPhi << endl;
151 const TRT_EndcapElement * element = m_manager->getEndcapElement(iSide, iWheel, iStrawLayer, iPhi);
152
153 // Make identifier.
154 Identifier newId = idHelper->layer_id((iSide ? 2:-2), iPhi, iWheel, iStrawLayer);
155 idHelper->show(newId);
156 IdentifierHash idHash = idHelper->straw_layer_hash(newId);
157 cout << "idHash = " << idHash << endl;
158
159 if (element) {
160 Amg::Vector3D center = element->transform() * origin;
161 cout << " center = " << center << endl;
162 cout << " number of straws = " << element->nStraws() << endl;
163 // Print out straw details of some elements
164 int iPhiModule = iPhi;
165 if ((iPhiModule == 0) || (iPhiModule == 1) || (iPhiModule == 7) || (iPhiModule == 31)) {
166 for (unsigned int istraw = 0; istraw < 15; istraw++) {
167 printStraw(element, istraw);
168 //printEndcapStraw(element, istraw);
169 }
170 }
171 // Compare methods
172 for (unsigned int istraw = 0; istraw < element->nStraws(); istraw++) {
173 compareEndcapStraw(element, istraw);
174 }
175 } else {
176 cout << "No Element found " << endl;
177 }
178 }
179 }
180 }
181 }
182
183
184
185 unsigned int maxHash = idHelper->straw_layer_hash_max();
186
187 //
188 // Try and iterate over all elements.
189 // There is no iterator but we can get the elements via the idHash.
190 //
191
192 cout << "======================================" <<endl;
193 cout << " ALL ELEMENTS - access via hash" << endl;
194 cout << "======================================" <<endl;
195 cout << endl;
196
197 cout << " maxHash = " << maxHash << endl;
198
199 for (unsigned int index = 0; index < maxHash; index++) {
200
201 IdentifierHash idHash = index;
202
203 Identifier id = idHelper->layer_id(idHash);
204 idHelper->show(id);
205
206 const TRT_BaseElement * element;
207
208 element = m_manager->getElement(idHash);
209
210 if (element) {
211 Amg::Vector3D center = element->transform() * origin;
212 cout << " center = " << center << endl;
213 } else {
214 cout << "No Element with id hash = " << idHash << endl;
215 }
216 }
217
218
219 cout << "======================================" <<endl;
220 cout << " ALL ELEMENTS - access via index from hash" << endl;
221 cout << " (no printout) " << endl;
222 cout << "======================================" <<endl;
223 cout << endl; for (unsigned int index = 0; index < maxHash; index++) {
224
225 IdentifierHash idHash = index;
226
227 Identifier id = idHelper->layer_id(idHash);
228 //idHelper->show(id);
229
230
231 int idBarrelEndcap = idHelper->barrel_ec(id);
232 int idSide = (idBarrelEndcap > 0);
233 int idLayerWheel = idHelper->layer_or_wheel(id);
234 int idPhiModule = idHelper->phi_module(id);
235 int idStrawLayer = idHelper->straw_layer(id);
236
237 // Make identifier again,
238 // Identifier newId = idHelper->layer_id(idBarrelEndcap, idPhiModule, idLayerWheel, idStrawLayer);
239 // idHelper->show(newId);
240
241
242 const TRT_BaseElement * element;
243
244
245 if (idHelper->is_barrel(id)) {
246 element = m_manager->getBarrelElement(idSide, idLayerWheel, idPhiModule, idStrawLayer);
247 } else {
248 element = m_manager->getEndcapElement(idSide, idLayerWheel, idStrawLayer, idPhiModule);
249 }
250
251 if (element) {
252 //nop
253 //Amg::Vector3D center = element->transform() * origin;
254 //cout << " center = " << center << endl;
255 } else {
256 cout << "No Element with id hash = " << idHash << endl;
257 }
258 }
259
260 cout << endl;
261
262 cout << "Max diff = " << m_maxdiff << endl;
263
264}
265
266
267
268// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
269
271 msg(MSG::INFO) << "finalize()" << endmsg;
272 return StatusCode::SUCCESS;
273}
274
275
276void
277ReadTRT_DetectorElements::printBarrelStraw(const TRT_BarrelElement * element, unsigned int strawNum){
278 // It is recommended to use the methods in printStraw() rather than the ones here
279 if (strawNum >= element->nStraws()) {
280 cout << "Straw number out of range:" << strawNum << " >= " << element->nStraws() << endl;
281 return;
282 }
283
284 double x = element->strawXPos(strawNum);
285 double y = element->strawYPos(strawNum);
286 double z = element->strawZPos(strawNum);
287 double r = sqrt(x*x+y*y);
288 double phi = atan2(y,x);
289 cout << "strawNum = " << strawNum << ", "
290 << "x = " << x << ", "
291 << "y = " << y << ", "
292 << "z = " << z << ", "
293 << "r = " << r << ", "
294 << "phi = " << phi << ", "
295 << "length = " << element->strawLength()
296 << endl;
297
298
299}
300
301void
303{
304 // It is recommended to use the methods in printStraw() rather than the ones here
305
306 if (strawNum >= element->nStraws()) {
307 cout << "Straw number out of range:" << strawNum << " >= " << element->nStraws() << endl;
308 return;
309 }
310
311 double phiStart = element->getDescriptor()->startPhi();
312 double pitch = element->getDescriptor()->strawPitch();
313 double phi = phiStart + strawNum*pitch;
314 phi = atan2(sin(phi), cos(phi)); // Get phi b/n -pi and pi.
315 double z = (element->transform() * origin).z();
316 cout << "strawNum = " << strawNum << ", "
317 << "phiStart = " << phiStart << ", "
318 << "pitch = " << pitch << ", "
319 << "z = " << z << ", "
320 << "r = " << element->getDescriptor()->innerRadius() + 0.5 * element->getDescriptor()->strawLength() << ", "
321 << "phi = " << phi << ", "
322 << "length = " << element->getDescriptor()->strawLength()
323 << endl;
324
325}
326
327
328
329void
330ReadTRT_DetectorElements::printStraw(const TRT_BaseElement * element, unsigned int strawNum)
331{
332 if (strawNum >= element->nStraws()) {
333 cout << "Straw number out of range:" << strawNum << " >= " << element->nStraws() << endl;
334 return;
335 }
336
337 const Amg::Transform3D& transform = element->strawTransform(strawNum);
338 Amg::Vector3D strawCenter = transform * origin;
339 cout << "strawNum = " << strawNum << ", "
340 << "x = " << strawCenter.x() << ", "
341 << "y = " << strawCenter.y() << ", "
342 << "z = " << strawCenter.z() << ", "
343 << "r = " << strawCenter.perp() << ", "
344 << "phi = " << strawCenter.phi() << ", "
345 << "length = " << element->strawLength() << ", "
346 << "localAxis = " << transform * Amg::Vector3D(0,0,1)
347 << endl;
348}
349
350void
352 if (strawNum >= element->nStraws()) {
353 cout << "Straw number out of range:" << strawNum << " >= " << element->nStraws() << endl;
354 return;
355 }
356
357 double x = element->strawXPos(strawNum);
358 double y = element->strawYPos(strawNum);
359 double z = element->strawZPos(strawNum);
360
361 Amg::Transform3D transform = element->strawTransform(strawNum);
362 Amg::Vector3D strawPos = transform * origin;
363
364 if (!comparePos(strawPos, Amg::Vector3D(x,y,z), 1e-9)) {
365 cout << "Straw Positions DIFFER !!!!!" << endl;
366 printStraw(element, strawNum);
367 printBarrelStraw(element, strawNum);
368 }
369}
370
371void
373 if (strawNum >= element->getDescriptor()->nStraws()) {
374 cout << "Straw number out of range:" << strawNum << " >= " << element->getDescriptor()->nStraws() << endl;
375 return;
376 }
377 double phiStart = element->getDescriptor()->startPhi();
378 double pitch = element->getDescriptor()->strawPitch();
379 double phi = phiStart + strawNum*pitch;
380 double r = element->getDescriptor()->innerRadius() + 0.5 * element->getDescriptor()->strawLength();
381 double z = (element->transform() * origin).z();
382
383 Amg::Transform3D transform = element->strawTransform(strawNum);
384 Amg::Vector3D strawPos = transform * origin;
385
386 if (!comparePos(strawPos, Amg::Vector3D(r*cos(phi), r*sin(phi), z), 1e-5)) {
387 cout << "Straw Positions DIFFER !!!!!" << endl;
388 printStraw(element, strawNum);
389 printEndcapStraw(element, strawNum);
390 }
391}
392
393
394bool
396 for (int i = 0; i < 3; i++) {
397 double diff = std::abs(p1[i] - p2[i]);
398 m_maxdiff = std::max(diff,m_maxdiff);
399 if (diff > err) return false;
400 }
401 return true;
402}
Scalar phi() const
phi method
#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
This is an Identifier helper class for the TRT subdetector.
#define y
#define x
#define z
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
void show(Identifier id, const IdContext *context=0, char sep='.') const
Short print out of any identifier (optionally provide separation character - default is '.
This is a "hash" representation of an Identifier.
Extended TRT_BaseElement to describe a TRT readout element, this is a planar layer with n ( order of ...
double strawXPos(unsigned int i) const
Get X Position: DEPRECATED.
double strawZPos(unsigned int i) const
Get Z Position: (active center) DEPRECATED.
virtual const double & strawLength() const override final
Get the length of the straws (active length):
double strawYPos(unsigned int i) const
Get Y Position: DEPRECATED.
Virtual base class of TRT readout elements.
virtual const double & strawLength() const =0
Active straw length.
unsigned int nStraws() const
Number of straws in the element.
virtual const Amg::Transform3D & transform() const override final
Element Surface: Get Transform of element in Tracking frame: Amg.
const Amg::Transform3D & strawTransform(unsigned int straw) const
Straw transform - fast access in array, in Tracking frame: Amg.
double & strawPitch()
The straw pitch (angular!
double & startPhi()
The starting phi (angular!
unsigned int & nStraws()
The number of straws in a module:
double & innerRadius()
The inner radius:
Extended class of a TRT_BaseElement to describe a readout elment in the endcap.
const TRT_EndcapDescriptor * getDescriptor() const
Returns a pointer to a descriptor, giving common information on module construction.
Helper class to organize the straw elements on TRT readout elements.
unsigned int getNEndcapWheels() const
unsigned int getNEndcapPhi() const
unsigned int getNBarrelPhi() const
unsigned int getNBarrelRings() const
unsigned int getNBarrelLayers(unsigned int iMod) const
unsigned int getNEndcapLayers(unsigned int iWheel) const
void printStraw(const InDetDD::TRT_BaseElement *element, const unsigned int strawNum)
void printBarrelStraw(const InDetDD::TRT_BarrelElement *element, const unsigned int strawNum)
ReadTRT_DetectorElements(const std::string &name, ISvcLocator *pSvcLocator)
Default Algorithm constructor with parameters.
void compareEndcapStraw(const InDetDD::TRT_EndcapElement *element, const unsigned int strawNum)
const InDetDD::TRT_DetectorManager * m_manager
bool comparePos(const Amg::Vector3D &p1, const Amg::Vector3D &p2, const double err)
void compareBarrelStraw(const InDetDD::TRT_BarrelElement *element, const unsigned int strawNum)
void printEndcapStraw(const InDetDD::TRT_EndcapElement *element, const unsigned int strawNum)
This is an Identifier helper class for the TRT subdetector.
Definition TRT_ID.h:82
int phi_module(const Identifier &id) const
Definition TRT_ID.h:806
Identifier layer_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer) const
For an individual straw layer.
Definition TRT_ID.h:494
size_type straw_layer_hash_max() const
Definition TRT_ID.h:851
bool is_barrel(const Identifier &id) const
Test for barrel.
Definition TRT_ID.h:788
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition TRT_ID.h:797
IdentifierHash straw_layer_hash(Identifier straw_layer_id) const
straw_layer hash from id - optimized
Definition TRT_ID.h:687
int layer_or_wheel(const Identifier &id) const
Definition TRT_ID.h:815
int straw_layer(const Identifier &id) const
Definition TRT_ID.h:824
int r
Definition globals.cxx:22
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Message Stream Member.
Definition index.py:1