ATLAS Offline Software
GetDetectorLocalFrames.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
16 
17 #include "GaudiKernel/MsgStream.h"
18 
19 #include "Identifier/Identifier.h"
23 
24 #include "InDetIdentifier/TRT_ID.h"
26 
28 
30 
31 #include <cstdlib>
32 #include <cstring>
33 #include <vector>
34 
35 
37 GetDetectorLocalFrames::GetDetectorLocalFrames(std::string const& name, ISvcLocator* pSvcLocator) :
38  AthAlgorithm(name, pSvcLocator),
39  m_outputFileName("IDLocalFrames.txt"),
40 
46  m_trt_barrel_ec(0),
47  m_trt_layer_or_wheel(0),
48  m_trt_phi_module(0),
49  m_trt_straw_layer(0),
50  m_trt_straw(0),
51 
53  m_TRTHelper(nullptr),
54  m_TRTDetectorManager(nullptr)
55 
56 {
57  declareProperty("OutputTextFile",m_outputFileName);
58 }
59 
62  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "initialize()" << endmsg;
63 
65  if (detStore()->retrieve(m_TRTHelper, "TRT_ID").isFailure()) {
66  msg(MSG::FATAL) << "Could not get TRT ID helper" << endmsg;
67  return StatusCode::FAILURE;
68  }
69  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "got the TRT ID" << endmsg;
70 
71  if ((detStore()->retrieve(m_TRTDetectorManager)).isFailure()) {
72  if(msgLvl(MSG::FATAL)) msg(MSG::FATAL) << "Problem retrieving TRT_DetectorManager" << endmsg;
73  return StatusCode::FAILURE;
74  }
75 
78 
81 
83  m_outputFile.open((m_outputFileName).c_str());
84 
85  return StatusCode::SUCCESS;
86 }
87 
90 
91  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "execute() check global position" << endmsg;
92 
93  StatusCode sc = StatusCode::SUCCESS;
94  m_eventCount++;
95 
97  if (m_eventCount!=0)
98  return sc;
99 
100  std::cout << "========================================================================================" <<std::endl;
101  std::cout << "==================== Getting the Inner Detector Local Frames ===========================" <<std::endl;
102  std::cout << "========================================================================================" <<std::endl;
103 
104  //Write pixel positions
105  writePixelFames();
106 
107  //Write SCT positions
108  writeSCTFrames();
109 
110  //Write SCT positions
111  writeTRTFrames();
112 
113  return StatusCode::SUCCESS;
114 }
115 
118  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "finalize()" << endmsg;
119 
121  m_outputFile.close();
122 
123  return StatusCode::SUCCESS;
124 }
125 
128  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "In writePixelFames()" << endmsg;
129 
131  const InDetDD::SiDetectorElementCollection* elements{*pixelDetEleHandle};
132  if (not pixelDetEleHandle.isValid() or elements==nullptr) {
133  ATH_MSG_ERROR(m_pixelDetEleCollKey.fullKey() << " is not available.");
134  return;
135  }
136  //Loop over pixel elements
137  // for (const InDetDD::SiDetectorElement* element: *elements) {
138  // Get local Frame
139  // }
140 
141  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Leaving writePixelFames()" << endmsg;
142  return;
143 }
144 
147  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "In writeSCTFrames()" << endmsg;
148 
150  const InDetDD::SiDetectorElementCollection* elements{*sctDetEleHandle};
151  if (not sctDetEleHandle.isValid() or elements==nullptr) {
152  ATH_MSG_ERROR(m_SCTDetEleCollKey.fullKey() << " is not available.");
153  return;
154  }
155  //Loop over SCT elements
156  // for (const InDetDD::SiDetectorElement* element: *elements) {
157  // Get local Frame
158  // }
159 
160  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Leaving writeSCTFrames()" << endmsg;
161  return;
162 }
163 
166  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "In writeTRTFrames()" << endmsg;
167 
170 
171  for (; trtStrawIt != trtStrawItE; ++trtStrawIt) {
172  const ExpandedIdentifier& expId = (*trtStrawIt);
173 
174  Identifier trtId = m_TRTHelper->straw_id(expId[2],
175  expId[3],
176  expId[4],
177  expId[5],
178  expId[6]);
179 
184  m_trt_straw = m_TRTHelper->straw(trtId);
185 
186  m_outputFile << 3 << " "
187  << m_trt_barrel_ec << " "
188  << m_trt_layer_or_wheel << " "
189  << m_trt_phi_module << " "
190  << m_trt_straw_layer << " "
191  << m_trt_straw << " ";
192  m_outputFile << std::endl;
193 
194  //const HepGeom::Transform3D& localTransform = m_TRTDetectorManager->getElement( trtId )->transform(trtId);
195  Amg::Vector3D xaxis(1,0,0);
196  Amg::Vector3D yaxis(0,1,0);
197  Amg::Vector3D zaxis(0,0,1);
201 
202  const Amg::Vector3D strawXAxis_NoSign = m_TRTDetectorManager->getElement( trtId )->strawTransform(m_trt_straw) * xaxis;
203  const Amg::Vector3D strawYAxis_NoSign = m_TRTDetectorManager->getElement( trtId )->strawTransform(m_trt_straw) * yaxis;
204  const Amg::Vector3D strawZAxis_NoSign = m_TRTDetectorManager->getElement( trtId )->strawTransform(m_trt_straw) * zaxis;
205  //const HepGeom::Vector3D<double> theStrawAxis = m_TRTDetectorManager->getElement( trtId )->strawAxis(m_trt_straw);
206 
207  //writeTransForm(localTransform);
208  writeVector("straw x-axis",strawXAxis);
209  writeVector("straw y-axis",strawYAxis);
210  writeVector("straw z-axis",strawZAxis);
211  m_outputFile << std::endl;
212  writeVector("straw x-axis (No sign)",strawXAxis_NoSign);
213  writeVector("straw y-axis (No sign)",strawYAxis_NoSign);
214  writeVector("straw z-axis (No sign)",strawZAxis_NoSign);
215  m_outputFile << std::endl;
216  }
217 
218  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Leaving writeTRTFrames()" << endmsg;
219  return;
220 }
221 
223  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "In writeVector()" << endmsg;
224 
225  m_outputFile << name << " " << vector.x() << " " << vector.y() << " " << vector.z() << std::endl;
226 
227  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Leaving writeVector()" << endmsg;
228  return;
229 }
230 
232  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "In writeTransForm()" << endmsg;
233 
234  m_outputFile << " Trans(x,y,z): " << transform.dx() << " " << transform.dy() << " " << transform.dz() << std::endl;
235  m_outputFile << " Rotation Matrix " << std::endl;
236  m_outputFile << transform.xx() << " " << transform.xy() << " " << transform.xz() << std::endl;
237  m_outputFile << transform.yx() << " " << transform.yy() << " " << transform.yz() << std::endl;
238  m_outputFile << transform.zx() << " " << transform.zy() << " " << transform.zz() << std::endl;
239 
240  if (msgLvl(MSG::VERBOSE)) msg(MSG::VERBOSE) << "Leaving writeTransForm()" << endmsg;
241  return;
242 }
243 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
GetDetectorLocalFrames::execute
StatusCode execute()
execute
Definition: GetDetectorLocalFrames.cxx:89
InDetDD::TRT_BaseElement::strawDirection
virtual int strawDirection() const =0
StrawDirection.
InDetDD::SiDetectorElementCollection
Definition: SiDetectorElementCollection.h:30
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
TRT_DetectorManager.h
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
GetDetectorLocalFrames::m_pixelDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_pixelDetEleCollKey
Pixel Data.
Definition: GetDetectorLocalFrames.h:58
GetDetectorLocalFrames::finalize
StatusCode finalize()
Finalize.
Definition: GetDetectorLocalFrames.cxx:117
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:102
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
GetDetectorLocalFrames::writeSCTFrames
void writeSCTFrames()
Writing the SCT Positions.
Definition: GetDetectorLocalFrames.cxx:146
GetDetectorLocalFrames.h
GetDetectorLocalFrames.name
name
Definition: GetDetectorLocalFrames.py:11
ReadCondHandle.h
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
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
GetDetectorLocalFrames::m_trt_layer_or_wheel
int m_trt_layer_or_wheel
Definition: GetDetectorLocalFrames.h:65
GetDetectorLocalFrames::m_trt_phi_module
int m_trt_phi_module
Definition: GetDetectorLocalFrames.h:66
TRT_ID::straw
int straw(const Identifier &id) const
Definition: TRT_ID.h:902
GetDetectorLocalFrames::m_trt_straw
int m_trt_straw
Definition: GetDetectorLocalFrames.h:68
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
MultiRange::const_identifier_factory
Definition: MultiRange.h:52
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
vector
Definition: MultiHisto.h:13
GetDetectorLocalFrames::m_trt_barrel_ec
int m_trt_barrel_ec
TRT Data.
Definition: GetDetectorLocalFrames.h:64
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
GetDetectorLocalFrames::m_outputFileName
std::string m_outputFileName
Name of the Output file.
Definition: GetDetectorLocalFrames.h:54
GetDetectorLocalFrames::writeTransForm
void writeTransForm(const HepGeom::Transform3D &transform)
Definition: GetDetectorLocalFrames.cxx:231
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TRT_ID::barrel_ec
int barrel_ec(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: TRT_ID.h:866
TRT_ID::straw_layer
int straw_layer(const Identifier &id) const
Definition: TRT_ID.h:893
TRT_ID::layer_or_wheel
int layer_or_wheel(const Identifier &id) const
Definition: TRT_ID.h:884
GetDetectorLocalFrames::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
SCT Data.
Definition: GetDetectorLocalFrames.h:61
AthAlgorithm
Definition: AthAlgorithm.h:47
EventPrimitives.h
GetDetectorLocalFrames::m_TRTHelper
const TRT_ID * m_TRTHelper
Tools.
Definition: GetDetectorLocalFrames.h:71
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IdentifierHash.h
InDetDD::TRT_DetectorManager::getElement
const TRT_BaseElement * getElement(Identifier id) const
Access Elements Generically---------------------------------------------—.
Definition: TRT_DetectorManager.cxx:148
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TRT_ID::straw_end
const_expanded_id_iterator straw_end(void) const
Definition: TRT_ID.h:977
TRT_ID::phi_module
int phi_module(const Identifier &id) const
Definition: TRT_ID.h:875
SiDetectorElement.h
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
GetDetectorLocalFrames::writeVector
void writeVector(const std::string &name, const Amg::Vector3D &vector)
Definition: GetDetectorLocalFrames.cxx:222
GetDetectorLocalFrames::initialize
StatusCode initialize()
initialize
Definition: GetDetectorLocalFrames.cxx:61
GetDetectorLocalFrames::m_trt_straw_layer
int m_trt_straw_layer
Definition: GetDetectorLocalFrames.h:67
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
GetDetectorLocalFrames::GetDetectorLocalFrames
GetDetectorLocalFrames(const std::string &name, ISvcLocator *pSvcLocator)
Authors: John Alison johnda@hep.upenn.edu
Definition: GetDetectorLocalFrames.cxx:37
GetDetectorLocalFrames::writePixelFames
void writePixelFames()
Functions to write the data.
Definition: GetDetectorLocalFrames.cxx:127
TRT_Numerology.h
TRT_ID::straw_begin
const_expanded_id_iterator straw_begin(void) const
For straw ids, only expanded id iterators are available.
Definition: TRT_ID.h:969
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
GetDetectorLocalFrames::m_outputFile
std::ofstream m_outputFile
Definition: GetDetectorLocalFrames.h:55
GetDetectorLocalFrames::m_TRTDetectorManager
const InDetDD::TRT_DetectorManager * m_TRTDetectorManager
Definition: GetDetectorLocalFrames.h:72
TRT_ID::straw_id
Identifier straw_id(int barrel_ec, int phi_module, int layer_or_wheel, int straw_layer, int straw) const
Three ways of getting id for a single straw:
Definition: TRT_ID.h:581
GetDetectorLocalFrames::writeTRTFrames
void writeTRTFrames()
Writing the Detailed (all straws) TRT Positions.
Definition: GetDetectorLocalFrames.cxx:165
GetDetectorLocalFrames::m_eventCount
int m_eventCount
Counter.
Definition: GetDetectorLocalFrames.h:75
Identifier
Definition: IdentifierFieldParser.cxx:14