ATLAS Offline Software
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 
18 using std::cout;
19 using std::endl;
20 
21 using namespace InDetDD;
22 
23 //anonymous namespace for utility functions at file scope
24 namespace{
25  Amg::Transform3D zRotation(const double angle){
26  const Amg::Vector3D zAxis(0., 0., 1.);
28  }
29  Amg::Transform3D yTranslation(const double distance){
31  }
32 }
33 
35 //
36 // Prints out SiDetectorElement positions and other info.
37 
39 
40 TestTRT_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;
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  }
95  if (m_hardwiredShifts) {
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 
130 void
132  Identifier id = m_idHelper->barrel_ec_id(1);
133  addShift(2, id, transform);
134 }
135 
136 
137 void
139 {
140  Identifier id = m_idHelper->module_id(bec, phiMod, layer);
141  addShift(1, id, transform);
142 }
143 
144 
145 void
146 TestTRT_Alignment::addShift(int level, const Identifier & id, const Amg::Transform3D & transform)
147 {
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 
167 void
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 
211 void
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 
224 void
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 
246 bool
247 TestTRT_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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
TestTRT_Alignment::printAlignmentShifts
void printAlignmentShifts()
Definition: TestTRT_Alignment.cxx:168
TestTRT_Alignment::initialize
StatusCode initialize()
Definition: TestTRT_Alignment.cxx:58
TRT_ID::layer_id
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:500
TestTRT_Alignment::m_hardwiredShifts
bool m_hardwiredShifts
Definition: TestTRT_Alignment.h:56
TRT::Hit::straw
@ straw
Definition: HitInfo.h:82
TestTRT_Alignment::m_testAllElements
bool m_testAllElements
Definition: TestTRT_Alignment.h:53
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
PlotCalibFromCool.zAxis
zAxis
Definition: PlotCalibFromCool.py:76
TRT_DetectorManager.h
TestTRT_Alignment::finalize
StatusCode finalize()
Definition: TestTRT_Alignment.cxx:161
ParticleGun_SamplingFraction.bec
int bec
Definition: ParticleGun_SamplingFraction.py:89
index
Definition: index.py:1
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TRT_ID::straw_layer_hash_max
size_type straw_layer_hash_max(void) const
Definition: TRT_ID.h:920
InDetDD::TRT_BaseElement::nStraws
unsigned int nStraws() const
Number of straws in the element.
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
TestTRT_Alignment.h
InDetDD::TRT_DetectorManager::setAlignableTransformDelta
virtual bool setAlignableTransformDelta(int level, const Identifier &id, const Amg::Transform3D &delta, FrameType frame, GeoVAlignmentStore *alignStore) const override
Set alignable transforms: Amg based.
Definition: TRT_DetectorManager.cxx:323
TRT_ID::barrel_ec_id
Identifier barrel_ec_id(int barrel_ec) const
For +/-barrel or +/-endcap id.
Definition: TRT_ID.h:417
TRT_ID::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: TRT_ID.h:89
TRT_ID::module_begin
const_id_iterator module_begin(void) const
Iterators over full set of module ids. Module ids are sorted.
Definition: TRT_ID.h:937
drawFromPickle.atan
atan
Definition: drawFromPickle.py:36
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
TRT_ID::module_end
const_id_iterator module_end(void) const
Definition: TRT_ID.h:945
TestTRT_Alignment::m_longPrintOut
bool m_longPrintOut
Definition: TestTRT_Alignment.h:51
InDetDD_Defs.h
TestTRT_Alignment::m_testAllStraws
bool m_testAllStraws
Definition: TestTRT_Alignment.h:52
TestTRT_Alignment::m_precision
int m_precision
Definition: TestTRT_Alignment.h:57
lumiFormat.i
int i
Definition: lumiFormat.py:92
TestTRT_Alignment::m_managerName
std::string m_managerName
Definition: TestTRT_Alignment.h:50
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
angle
double angle(const GeoTrf::Vector2D &a, const GeoTrf::Vector2D &b)
Definition: TRTDetectorFactory_Full.cxx:73
TRT::Hit::layer
@ layer
Definition: HitInfo.h:79
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
TestTRT_Alignment::compareEndStraws
void compareEndStraws(const Identifier &id)
Definition: TestTRT_Alignment.cxx:212
TestTRT_Alignment::addShiftModule
void addShiftModule(int bec, int phiMod, int layer, const Amg::Transform3D &transform)
Definition: TestTRT_Alignment.cxx:138
TestTRT_Alignment::m_idHelper
const TRT_ID * m_idHelper
Definition: TestTRT_Alignment.h:48
AthAlgorithm
Definition: AthAlgorithm.h:47
TestTRT_Alignment::execute
StatusCode execute()
Definition: TestTRT_Alignment.cxx:152
TRT_ID::straw_layer_max
int straw_layer_max(const Identifier &id) const
Max values for each field (-999 == failure)
Definition: TRT_ID.cxx:980
TestTRT_Alignment::addShiftTop
void addShiftTop(const Amg::Transform3D &transform)
Definition: TestTRT_Alignment.cxx:131
TestTRT_Alignment::m_errRot
double m_errRot
Definition: TestTRT_Alignment.h:54
TestTRT_Alignment::compareStraw
void compareStraw(const InDetDD::TRT_BaseElement *element, int straw)
Definition: TestTRT_Alignment.cxx:225
TestTRT_Alignment::m_errTrans
double m_errTrans
Definition: TestTRT_Alignment.h:55
TestTRT_Alignment::m_manager
const InDetDD::TRT_DetectorManager * m_manager
Definition: TestTRT_Alignment.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDetDD::TRT_DetectorManager::getElement
const TRT_BaseElement * getElement(Identifier id) const
Access Elements Generically---------------------------------------------—.
Definition: TRT_DetectorManager.cxx:158
AtlasDetectorID::show
void show(Identifier id, const IdContext *context=0, char sep='.') const
Short print out of any identifier (optionally provide separation character - default is '.
Definition: AtlasDetectorID.cxx:565
TestTRT_Alignment::TestTRT_Alignment
TestTRT_Alignment(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TestTRT_Alignment.cxx:40
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
DeMoScan.index
string index
Definition: DeMoScan.py:362
InDetDD::TRT_BaseElement::strawTransform
const Amg::Transform3D & strawTransform(unsigned int straw) const
Straw transform - fast access in array, in Tracking frame: Amg.
Definition: TRT_BaseElement.cxx:89
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
TestTRT_Alignment::testIdentity
bool testIdentity(const Amg::Transform3D &transform, double errRot=0, double errTrans=0)
Definition: TestTRT_Alignment.cxx:247
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
DEBUG
#define DEBUG
Definition: page_access.h:11
Amg::Translation3D
Eigen::Translation< double, 3 > Translation3D
Definition: GeoPrimitives.h:44
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
Amg::AngleAxis3D
Eigen::AngleAxisd AngleAxis3D
Definition: GeoPrimitives.h:45
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
TRT_ID::module_id
Identifier module_id(int barrel_ec, int phi_module, int layer_or_wheel) const
For an individual module phi sector.
Definition: TRT_ID.h:448
TestTRT_Alignment::addShift
void addShift(int level, const Identifier &id, const Amg::Transform3D &transform)
Definition: TestTRT_Alignment.cxx:146