ATLAS Offline Software
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 
15 #include "InDetIdentifier/SCT_ID.h"
16 #include "Identifier/Identifier.h"
19 
20 #include <iostream>
21 #include <vector>
22 #include <string>
23 
24 using std::cout;
25 using std::endl;
26 
27 using 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 
42 TestSiAlignment::TestSiAlignment(const std::string& name, ISvcLocator* pSvcLocator) :
43  AthAlgorithm(name, pSvcLocator),
44  m_manager(nullptr),
45  m_managerName("")
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  }
70  return StatusCode::SUCCESS;
71 }
72 
73 
74 void
75 TestSiAlignment::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 {
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 
137 bool
138 TestSiAlignment::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 
159 void 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 
181  printAlignmentShifts(false);
182  return StatusCode::SUCCESS;
183 }
184 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
186 
188  return StatusCode::SUCCESS;
189 }
190 
191 
192 
193 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
TestSiAlignment::finalize
StatusCode finalize()
Definition: TestSiAlignment.cxx:187
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
SCT_ID.h
This is an Identifier helper class for the SCT subdetector. This class is a factory for creating comp...
TestSiAlignment::execute
StatusCode execute()
Definition: TestSiAlignment.cxx:180
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TestSiAlignment::extractAlphaBetaGamma
void extractAlphaBetaGamma(const Amg::Transform3D &trans, double &alpha, double &beta, double &gamma) const
Definition: TestSiAlignment.cxx:159
ALFA_EventTPCnv_Dict::t1
std::vector< ALFA_RawDataCollection_p1 > t1
Definition: ALFA_EventTPCnvDict.h:43
mc.diff
diff
Definition: mc.SFGenPy8_MuMu_DD.py:14
TestSiAlignment::m_errTrans
double m_errTrans
Definition: TestSiAlignment.h:43
InDetDD::SiDetectorManager::getDetectorElementCollection
virtual const SiDetectorElementCollection * getDetectorElementCollection() const =0
access to whole collectiom
TestSiAlignment.h
ReadCondHandle.h
SiIntersect.h
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
TestSiAlignment::TestSiAlignment
TestSiAlignment(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TestSiAlignment.cxx:42
TestSiAlignment::m_detEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_detEleCollKey
Definition: TestSiAlignment.h:44
TestSiAlignment::m_managerName
std::string m_managerName
Definition: TestSiAlignment.h:40
SG::ReadCondHandle::retrieve
const_pointer_type retrieve()
Definition: ReadCondHandle.h:161
TrigVtx::gamma
@ gamma
Definition: TrigParticleTable.h:26
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
TestSiAlignment::initialize
StatusCode initialize()
Definition: TestSiAlignment.cxx:56
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
TestSiAlignment::m_manager
const InDetDD::SiDetectorManager * m_manager
Definition: TestSiAlignment.h:39
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SiLocalPosition.h
AthAlgorithm
Definition: AthAlgorithm.h:47
CLHEPtoEigenConverter.h
TestSiAlignment::m_longPrintOut
bool m_longPrintOut
Definition: TestSiAlignment.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
SiDetectorElement.h
TestSiAlignment::testIdentity
bool testIdentity(const Amg::Transform3D &transform, double errRot=0, double errTrans=0)
Definition: TestSiAlignment.cxx:138
ALFA_EventTPCnv_Dict::t2
std::vector< ALFA_RawDataContainer_p1 > t2
Definition: ALFA_EventTPCnvDict.h:44
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
InDetDD
Message Stream Member.
Definition: FakeTrackBuilder.h:8
SiDetectorManager.h
TestSiAlignment::printAlignmentShifts
void printAlignmentShifts(const bool accessDuringInitialization)
Definition: TestSiAlignment.cxx:75
MuonParameters::beta
@ beta
Definition: MuonParamDefs.h:144
TestSiAlignment::m_errRot
double m_errRot
Definition: TestSiAlignment.h:42
SiCellId.h