Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
TRTStrawAlign.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 //
11 #include <fstream>
12 #include <iostream>
13 #include <string>
14 #include "TRTStrawAlign.h"
15 
18 #include "InDetIdentifier/TRT_ID.h"
19 
21 
22 TRTStrawAlign::TRTStrawAlign(const std::string& name, ISvcLocator* pSvcLocator)
23  :AthAlgorithm (name, pSvcLocator),
24  m_inputModuleAlignmentTextFile(""),
25  m_inputStrawAlignmentTextFile(""),
26  m_outputModuleAlignmentTextFile(""),
27  m_outputStrawAlignmentTextFile(""),
28  m_outputPOOLFile(""),
29  m_moduleAlignTag("TRTAlign_00"),
30  m_stawAlignTag("TrtCalibDx_00"),
31  m_runRangeBegin(0),
32  m_runRangeEnd(9999999),
33  m_eventRangeBegin(0),
34  m_eventRangeEnd(9999999)
35 
36 {
38  declareProperty("RegisterIOV",m_doRegIOV);
40  declareProperty("InputStrawAlignmentFile",m_inputStrawAlignmentTextFile);
41  declareProperty("PoolOutputFile",m_outputPOOLFile);
43  declareProperty("StrawAlignmentTextOutputFile",m_outputStrawAlignmentTextFile);
44  declareProperty("VersionTag",m_moduleAlignTag);
45  declareProperty("VersionTagStrawAlign",m_stawAlignTag);
46  declareProperty("ValidRun1",m_runRangeBegin);
47  declareProperty("ValidRun2",m_runRangeEnd);
48  declareProperty("ValidEvent1",m_eventRangeBegin);
49  declareProperty("ValidEvent2",m_eventRangeEnd);
50  declareProperty("DoStrawAlign",m_doStrawAlign);
51  declareProperty("DoModuleAlign",m_doModuleAlign);
52 }
53 
54 
56 = default;
57 
59 
60  ATH_MSG_DEBUG(" in initialize() ");
61 
62  //
63  // Get TRT manager and ID helper
65  ATH_CHECK(detStore()->retrieve(m_trt,"TRT_ID"));
66  ATH_MSG_DEBUG("TRT manager and helper found ");
67 
68  //get Database manager tools
69  if (m_doStrawAlign) {
70  ATH_CHECK(p_caldbtool.retrieve());
71  ATH_MSG_DEBUG(" TRTStrawAlignDbTool found ");
72  if (m_doWriteToPOOL) {
73  ATH_MSG_INFO("Straw alignment will be written to POOL file " << m_outputPOOLFile);
74  }
75  if (m_doRegIOV) {
76  ATH_MSG_INFO("Straw alignment will be registered with IOV");
77  ATH_MSG_INFO(" run range: " << m_runRangeBegin << " to " << m_runRangeEnd);
78  ATH_MSG_INFO(" version tag: " << m_stawAlignTag);
79  }
80  if (!m_inputStrawAlignmentTextFile.empty()) {
81  ATH_MSG_INFO("Straw Alignment will read from text file " << m_inputStrawAlignmentTextFile);
82  }
83  if (!m_outputStrawAlignmentTextFile.empty()) {
84  ATH_MSG_INFO("Straw Alignment will be written on text file " << m_outputStrawAlignmentTextFile);
85  }
86  }
87 
88  if (m_doModuleAlign) {
89  ATH_CHECK(p_aligndbtool.retrieve());
90  ATH_MSG_DEBUG(" TRTAlignDbTool found ");
91 
92  if (m_doWriteToPOOL) {
93  ATH_MSG_INFO("Module alignment will be written to POOL file " << m_outputPOOLFile);
94  }
95  if (m_doRegIOV) {
96  ATH_MSG_INFO("Module alignment will be registered with IOV");
97  ATH_MSG_INFO(" run range: " << m_runRangeBegin << " to " << m_runRangeEnd);
98  ATH_MSG_INFO(" version tag: " << m_moduleAlignTag);
99  }
100  if (!m_inputModuleAlignmentTextFile.empty()) {
101  ATH_MSG_INFO("Module Alignment will read from text file " << m_inputModuleAlignmentTextFile);
102  }
103  if (!m_outputModuleAlignmentTextFile.empty()) {
104  ATH_MSG_INFO("Module Alignment will be written on text file " << m_outputModuleAlignmentTextFile);
105  }
106  }
107 
108  return StatusCode::SUCCESS;
109 }
110 
111 
113 
114  StatusCode sc=StatusCode::SUCCESS;
115  //
116  // at first event:
117  if (!m_setup) {
118  m_setup=true;
119 
120  if (m_doStrawAlign) {
121  // read alignment constants from text file
122  if (!m_inputStrawAlignmentTextFile.empty()) {
124  if(sc!=StatusCode::SUCCESS) {
125  ATH_MSG_ERROR(" Could not read input text file ");
126  return StatusCode::FAILURE;
127  }
128  }
129 
130  // write alignment constants to text file
131  if (!m_outputStrawAlignmentTextFile.empty()) {
133  if(sc!=StatusCode::SUCCESS) {
134  ATH_MSG_ERROR(" Could not write output text file ");
135  return StatusCode::FAILURE;
136  }
137  }
138 
139  if(m_doWriteToPOOL) {
140  if( StatusCode::SUCCESS != p_caldbtool->streamOutObjects()) {
141  ATH_MSG_ERROR(" Could not stream Straw Alignment objects to " << m_outputPOOLFile);
142  return StatusCode::FAILURE;
143  }
144  }
145  if(m_doRegIOV) {
146  if( StatusCode::SUCCESS != p_caldbtool->registerObjects(m_stawAlignTag,m_runRangeBegin,m_eventRangeBegin,m_runRangeEnd,m_eventRangeEnd) ) {
147  ATH_MSG_ERROR(" Could not register Straw Alignment objects ");
148  return StatusCode::FAILURE;
149  }
150  }
151  }
152 
153  if (m_doModuleAlign) {
154  // read alignment constants from text file
155  if (!m_inputModuleAlignmentTextFile.empty()) {
156  sc=p_aligndbtool->readAlignTextFile(m_inputModuleAlignmentTextFile);
157  if(sc!=StatusCode::SUCCESS) {
158  ATH_MSG_ERROR(" Could not read input text file ");
159  return StatusCode::FAILURE;
160  }
161  }
162 
163  // write alignment constants to text file
164  if (!m_outputModuleAlignmentTextFile.empty()) {
165  sc=p_aligndbtool->writeAlignTextFile(m_outputModuleAlignmentTextFile);
166  if(sc!=StatusCode::SUCCESS) {
167  ATH_MSG_ERROR( " Could not write output text file ");
168  return StatusCode::FAILURE;
169  }
170  }
171 
172  if(m_doWriteToPOOL) {
173  if( StatusCode::SUCCESS != p_aligndbtool->streamOutAlignObjects()) {
174  ATH_MSG_ERROR(" Could not stream Module Alignment objects to " << m_outputPOOLFile);
175  return StatusCode::FAILURE;
176  }
177  }
178  if(m_doRegIOV) {
179  if( StatusCode::SUCCESS != p_aligndbtool->registerAlignObjects(m_moduleAlignTag
183  ,m_eventRangeEnd) ) {
184 
185  ATH_MSG_ERROR(" Could not register Module Alignment objects ");
186  return StatusCode::FAILURE;
187  }
188  }
189  }
190 
191  }
192 
193  return StatusCode::SUCCESS;
194 }
195 
196 
198 
199  //
200  // check a few straw positions
201  // NB: alignment corrections will not be seen because elelemnts are taken from the Det Manager
202  for(int strlay=0;strlay<3;strlay++) {
203  for(int str=7;str<10;str++) {
204  Identifier id=m_trt->layer_id(-1,1,0,strlay);
205  const InDetDD::TRT_BaseElement* element = m_trtman->getElement(id);
206  float y = element->strawCenter(str).x();
207  float x = element->strawCenter(str).y();
208  float z = element->strawCenter(str).z();
210  << "bec -1 layer 0 sector 1 plane "
211  << strlay << " straw " << str << endmsg;
213  << " x " << x << " y " << y << " z " << z << endmsg;
214  id=m_trt->layer_id(1,1,0,strlay);
215  element = m_trtman->getElement(id);
216  y = element->strawCenter(str).x();
217  x = element->strawCenter(str).y();
218  z = element->strawCenter(str).z();
220  << "bec 1 layer 0 sector 1 plane "
221  << strlay << " straw " << str << endmsg;
223  << " x " << x << " y " << y << " z " << z << endmsg;
224  }
225  }
226 
227  return StatusCode::SUCCESS;
228 }
229 
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
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
TRTStrawAlign::m_inputModuleAlignmentTextFile
std::string m_inputModuleAlignmentTextFile
text file to read module alignment data
Definition: TRTStrawAlign.h:47
TRTStrawAlign::execute
virtual StatusCode execute(void) override
Definition: TRTStrawAlign.cxx:112
TRTStrawAlign::m_inputStrawAlignmentTextFile
std::string m_inputStrawAlignmentTextFile
text file to read straw alignment data
Definition: TRTStrawAlign.h:48
TRTStrawAlign::initialize
virtual StatusCode initialize(void) override
Definition: TRTStrawAlign.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TRTStrawAlign::m_trt
const TRT_ID * m_trt
trt id helper
Definition: TRTStrawAlign.h:41
TRT_DetectorManager.h
TRTStrawAlign::p_aligndbtool
ServiceHandle< ITRT_AlignDbSvc > p_aligndbtool
db tool
Definition: TRTStrawAlign.h:37
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
TRTStrawAlign::m_stawAlignTag
std::string m_stawAlignTag
IOV version tag for straw alignment.
Definition: TRTStrawAlign.h:53
TRTStrawAlign::m_outputModuleAlignmentTextFile
std::string m_outputModuleAlignmentTextFile
output module level text file
Definition: TRTStrawAlign.h:49
TRT_ID.h
This is an Identifier helper class for the TRT subdetector. This class is a factory for creating comp...
TRTStrawAlign::m_doStrawAlign
bool m_doStrawAlign
Definition: TRTStrawAlign.h:38
InDetDD::TRT_BaseElement::strawCenter
const Amg::Vector3D & strawCenter(int straw) const
Straw Surface: Local -> global transform of the straw via integer.
Definition: TRT_BaseElement.cxx:143
AthCommonMsg< Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
x
#define x
TRTStrawAlign::m_trtman
const InDetDD::TRT_DetectorManager * m_trtman
detector manager
Definition: TRTStrawAlign.h:40
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TRTStrawAlign::m_outputStrawAlignmentTextFile
std::string m_outputStrawAlignmentTextFile
output module level text file
Definition: TRTStrawAlign.h:50
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
z
#define z
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
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
TRTStrawAlign::m_eventRangeEnd
int m_eventRangeEnd
IOV range.
Definition: TRTStrawAlign.h:57
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
TRTStrawAlign::~TRTStrawAlign
~TRTStrawAlign(void)
TRT_BarrelElement.h
AthAlgorithm
Definition: AthAlgorithm.h:47
TRTStrawAlign::m_eventRangeBegin
int m_eventRangeBegin
IOV range.
Definition: TRTStrawAlign.h:56
TRTStrawAlign::m_doRegIOV
bool m_doRegIOV
register structures in the IOV service
Definition: TRTStrawAlign.h:46
TRTStrawAlign::m_doWriteToPOOL
bool m_doWriteToPOOL
stream structures to output
Definition: TRTStrawAlign.h:45
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
TRTStrawAlign::m_setup
bool m_setup
true for first event
Definition: TRTStrawAlign.h:42
InDetDD::TRT_DetectorManager::getElement
const TRT_BaseElement * getElement(Identifier id) const
Access Elements Generically---------------------------------------------—.
Definition: TRT_DetectorManager.cxx:148
TRTStrawAlign::m_doModuleAlign
bool m_doModuleAlign
Definition: TRTStrawAlign.h:39
TRTStrawAlign::TRTStrawAlign
TRTStrawAlign(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTStrawAlign.cxx:22
TRTStrawAlign::m_runRangeEnd
int m_runRangeEnd
IOV range.
Definition: TRTStrawAlign.h:55
y
#define y
DEBUG
#define DEBUG
Definition: page_access.h:11
TRTStrawAlign::p_caldbtool
ServiceHandle< ITRT_StrawAlignDbSvc > p_caldbtool
db tool
Definition: TRTStrawAlign.h:36
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
str
Definition: BTagTrackIpAccessor.cxx:11
TRTStrawAlign.h
Algorithm to make individual Straw Alignment.
TRTStrawAlign::m_moduleAlignTag
std::string m_moduleAlignTag
IOV version tag for module alignment.
Definition: TRTStrawAlign.h:52
TRTStrawAlign::m_outputPOOLFile
std::string m_outputPOOLFile
POOL file to write.
Definition: TRTStrawAlign.h:51
TRTStrawAlign::finalize
virtual StatusCode finalize(void) override
Definition: TRTStrawAlign.cxx:197
StrawDxContainer.h
Class for storing/accessing trt endpoint corrections data.
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:52
TRTStrawAlign::m_runRangeBegin
int m_runRangeBegin
IOV range.
Definition: TRTStrawAlign.h:54
Identifier
Definition: IdentifierFieldParser.cxx:14