ATLAS Offline Software
TRTStrawAlign.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
10 //
11 #include <fstream>
12 #include <iostream>
13 #include <string>
15 
18 #include "InDetIdentifier/TRT_ID.h"
19 
21 
24 
25 TRTStrawAlign::TRTStrawAlign(const std::string& name, ISvcLocator* pSvcLocator)
26  :AthAlgorithm (name, pSvcLocator),
27  p_caldbtool("TRT_StrawAlignDbSvc",name),
28  p_aligndbtool("TRT_AlignDbSvc",name),
29  m_trtman(nullptr),
30  m_trt(nullptr),
31  m_setup(false),
32  m_doWriteToPOOL(false),
33  m_doRegIOV(false),
34  m_inputModuleAlignmentTextFile(""),
35  m_inputStrawAlignmentTextFile(""),
36  m_outputModuleAlignmentTextFile(""),
37  m_outputStrawAlignmentTextFile(""),
38  m_outputPOOLFile(""),
39  m_moduleAlignTag("TRTAlign_00"),
40  m_stawAlignTag("TrtCalibDx_00"),
41  m_runRangeBegin(0),
42  m_runRangeEnd(9999999),
43  m_eventRangeBegin(0),
44  m_eventRangeEnd(9999999)
45 
46 {
48  declareProperty("RegisterIOV",m_doRegIOV);
50  declareProperty("InputStrawAlignmentFile",m_inputStrawAlignmentTextFile);
51  declareProperty("PoolOutputFile",m_outputPOOLFile);
53  declareProperty("StrawAlignmentTextOutputFile",m_outputStrawAlignmentTextFile);
54  declareProperty("VersionTag",m_moduleAlignTag);
55  declareProperty("VersionTagStrawAlign",m_stawAlignTag);
56  declareProperty("ValidRun1",m_runRangeBegin);
57  declareProperty("ValidRun2",m_runRangeEnd);
58  declareProperty("ValidEvent1",m_eventRangeBegin);
59  declareProperty("ValidEvent2",m_eventRangeEnd);
60  declareProperty("DbTool",p_caldbtool);
61  declareProperty("AlignDbTool",p_aligndbtool);
62  declareProperty("DoStrawAlign",m_doStrawAlign);
63  declareProperty("DoModuleAlign",m_doModuleAlign);
64 }
65 
66 
68 = default;
69 
71 
72  ATH_MSG_DEBUG(" in initialize() ");
73 
74  //
75  // Get TRT manager and ID helper
76  StatusCode sc = AthAlgorithm::detStore()->retrieve(m_trtman,"TRT");
77  if(sc.isFailure() || m_trtman==nullptr)
78  {
79  msg(MSG::FATAL) << "Could not find TRT manager " << endmsg;
80  return StatusCode::FAILURE;
81  }
82 
83  sc = detStore()->retrieve(m_trt,"TRT_ID");
84  if ( sc.isFailure() ) {
85  ATH_MSG_FATAL( "Couldn't retrieve TRT ID helper." );
86  return sc;
87  }
88  if(m_trt) ATH_MSG_DEBUG("TRT manager and helper found ");
89 
90  //get Database manager tools
91  if (m_doStrawAlign) {
92  if (StatusCode::SUCCESS!=p_caldbtool.retrieve()) {
93  msg(MSG::FATAL) << "TRTStrawAlignDbTool not found" << endmsg;
94  return StatusCode::FAILURE;
95  }
96 
97  ATH_MSG_DEBUG(" TRTStrawAlignDbTool found ");
98  if (m_doWriteToPOOL && msgLvl(MSG::INFO)) msg(MSG::INFO)
99  << "Straw alignment will be written to POOL file "
100  << m_outputPOOLFile << endmsg;
101  if (m_doRegIOV) {
102  ATH_MSG_INFO("Straw alignment will be registered with IOV");
103  if (msgLvl(MSG::INFO)) {
104  msg(MSG::INFO) << " run range: "
105  << m_runRangeBegin << " to " << m_runRangeEnd << endmsg;
106  msg(MSG::INFO) << " version tag: " << m_stawAlignTag << endmsg;
107  }
108  }
109  if (!m_inputStrawAlignmentTextFile.empty() && msgLvl(MSG::INFO)) msg(MSG::INFO)
110  << "Straw Alignment will read from text file "
112  if (!m_outputStrawAlignmentTextFile.empty() && msgLvl(MSG::INFO)) msg(MSG::INFO)
113  << "Straw Alignment will be written on text file "
115 
116  }
117  if (m_doModuleAlign) {
118 
119  if (StatusCode::SUCCESS!=p_aligndbtool.retrieve()) {
120  msg(MSG::FATAL) << "TRTAlignDbTool not found" << endmsg;
121  return StatusCode::FAILURE;
122  }
123 
124  ATH_MSG_DEBUG(" TRTAlignDbTool found ");
125  if (m_doWriteToPOOL && msgLvl(MSG::INFO)) msg(MSG::INFO)
126  << "Module alignment will be written to POOL file "
127  << m_outputPOOLFile << endmsg;
128  if (m_doRegIOV) {
129  ATH_MSG_INFO("Module alignment will be registered with IOV");
130  if ( msgLvl(MSG::INFO) ) {
131  msg(MSG::INFO) << " run range: " << m_runRangeBegin << " to " << m_runRangeEnd
132  << endmsg;
133  msg(MSG::INFO) << " version tag: " << m_moduleAlignTag << endmsg;
134  }
135  }
136  if (!m_inputModuleAlignmentTextFile.empty() && msgLvl(MSG::INFO)) msg(MSG::INFO)
137  << "Module Alignment will read from text file "
139  if (!m_outputModuleAlignmentTextFile.empty() && msgLvl(MSG::INFO)) msg(MSG::INFO)
140  << "Module Alignment will be written on text file "
142  }
143 
144  return StatusCode::SUCCESS;
145 }
146 
147 
149 
150  StatusCode sc=StatusCode::SUCCESS;
151  //
152  // at first event:
153  if (!m_setup) {
154  m_setup=true;
155 
156  if (m_doStrawAlign) {
157  // read alignment constants from text file
158  if (!m_inputStrawAlignmentTextFile.empty()) {
160  if(sc!=StatusCode::SUCCESS) {
161  msg(MSG::ERROR) << " Could not read input text file "
162  << endmsg;
163  return StatusCode::FAILURE;
164  }
165  }
166 
167  // write alignment constants to text file
168  if (!m_outputStrawAlignmentTextFile.empty()) {
170  if(sc!=StatusCode::SUCCESS) {
171  msg(MSG::ERROR) << " Could not write output text file "
172  << endmsg;
173  return StatusCode::FAILURE;
174  }
175  }
176 
177  if(m_doWriteToPOOL) {
178  if( StatusCode::SUCCESS != p_caldbtool->streamOutObjects()) {
179  msg(MSG::ERROR) << " Could not stream Straw Alignment objects to "
180  << m_outputPOOLFile << endmsg;
181  return StatusCode::FAILURE;
182  }
183  }
184  if(m_doRegIOV) {
185  if( StatusCode::SUCCESS != p_caldbtool->registerObjects(m_stawAlignTag,m_runRangeBegin,m_eventRangeBegin,m_runRangeEnd,m_eventRangeEnd) ) {
186  msg(MSG::ERROR) << " Could not register Straw Alignment objects "
187  << endmsg;
188  return StatusCode::FAILURE;
189  }
190  }
191  }
192 
193  if (m_doModuleAlign) {
194  // read alignment constants from text file
195  if (!m_inputModuleAlignmentTextFile.empty()) {
196  sc=p_aligndbtool->readAlignTextFile(m_inputModuleAlignmentTextFile);
197  if(sc!=StatusCode::SUCCESS) {
198  msg(MSG::ERROR) << " Could not read input text file "
199  << endmsg;
200  return StatusCode::FAILURE;
201  }
202  }
203 
204  // write alignment constants to text file
205  if (!m_outputModuleAlignmentTextFile.empty()) {
206  sc=p_aligndbtool->writeAlignTextFile(m_outputModuleAlignmentTextFile);
207  if(sc!=StatusCode::SUCCESS) {
208  msg(MSG::ERROR) << " Could not write output text file " << endmsg;
209  return StatusCode::FAILURE;
210  }
211  }
212 
213  if(m_doWriteToPOOL) {
214  if( StatusCode::SUCCESS != p_aligndbtool->streamOutAlignObjects()) {
215  msg(MSG::ERROR) << " Could not stream Module Alignment objects to " << m_outputPOOLFile << endmsg;
216  return StatusCode::FAILURE;
217  }
218  }
219  if(m_doRegIOV) {
220  if( StatusCode::SUCCESS != p_aligndbtool->registerAlignObjects(m_moduleAlignTag
224  ,m_eventRangeEnd) ) {
225 
226  msg(MSG::ERROR) << " Could not register Module Alignment objects " << endmsg;
227  return StatusCode::FAILURE;
228  }
229  }
230  }
231 
232  }
233 
234  return StatusCode::SUCCESS;
235 }
236 
237 
239 
240  //
241  // check a few straw positions
242  for(int strlay=0;strlay<3;strlay++) {
243  for(int str=7;str<10;str++) {
244  Identifier id=m_trt->layer_id(-1,1,0,strlay);
245  const InDetDD::TRT_BaseElement* element = m_trtman->getElement(id);
246  float y = element->strawCenter(str).x();
247  float x = element->strawCenter(str).y();
248  float z = element->strawCenter(str).z();
250  << "bec -1 layer 0 sector 1 plane "
251  << strlay << " straw " << str << endmsg;
253  << " x " << x << " y " << y << " z " << z << endmsg;
254  id=m_trt->layer_id(1,1,0,strlay);
255  element = m_trtman->getElement(id);
256  y = element->strawCenter(str).x();
257  x = element->strawCenter(str).y();
258  z = element->strawCenter(str).z();
260  << "bec 1 layer 0 sector 1 plane "
261  << strlay << " straw " << str << endmsg;
263  << " x " << x << " y " << y << " z " << z << endmsg;
264  }
265  }
266 
267  return StatusCode::SUCCESS;
268 }
269 
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:48
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
TRTStrawAlign::m_inputStrawAlignmentTextFile
std::string m_inputStrawAlignmentTextFile
text file to read straw alignment data
Definition: TRTStrawAlign.h:49
python.Constants.FATAL
int FATAL
Definition: Control/AthenaCommon/python/Constants.py:19
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:42
TRT_DetectorManager.h
TRTStrawAlign::p_aligndbtool
ServiceHandle< ITRT_AlignDbSvc > p_aligndbtool
db tool
Definition: TRTStrawAlign.h:38
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:54
TRTStrawAlign::m_outputModuleAlignmentTextFile
std::string m_outputModuleAlignmentTextFile
output module level text file
Definition: TRTStrawAlign.h:50
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:39
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:41
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
TRTStrawAlign::m_outputStrawAlignmentTextFile
std::string m_outputStrawAlignmentTextFile
output module level text file
Definition: TRTStrawAlign.h:51
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
TRTStrawAlign::initialize
StatusCode initialize(void)
Definition: TRTStrawAlign.cxx:70
ITRT_StrawAlignDbSvc.h
abstract interface to TRT straw alignment constants
TRTStrawAlign::execute
StatusCode execute(void)
Definition: TRTStrawAlign.cxx:148
z
#define z
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
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:58
TRTStrawAlign::~TRTStrawAlign
~TRTStrawAlign(void)
TRT_BarrelElement.h
AthAlgorithm
Definition: AthAlgorithm.h:47
TRTStrawAlign::m_eventRangeBegin
int m_eventRangeBegin
IOV range.
Definition: TRTStrawAlign.h:57
TRTStrawAlign::m_doRegIOV
bool m_doRegIOV
register structures in the IOV service
Definition: TRTStrawAlign.h:47
TRTStrawAlign::m_doWriteToPOOL
bool m_doWriteToPOOL
stream structures to output
Definition: TRTStrawAlign.h:46
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
TRTStrawAlign::m_setup
bool m_setup
true for first event
Definition: TRTStrawAlign.h:43
InDetDD::TRT_DetectorManager::getElement
const TRT_BaseElement * getElement(Identifier id) const
Access Elements Generically---------------------------------------------—.
Definition: TRT_DetectorManager.cxx:158
TRTStrawAlign::m_doModuleAlign
bool m_doModuleAlign
Definition: TRTStrawAlign.h:40
TRTStrawAlign::TRTStrawAlign
TRTStrawAlign(const std::string &name, ISvcLocator *pSvcLocator)
Definition: TRTStrawAlign.cxx:25
TRTStrawAlign::m_runRangeEnd
int m_runRangeEnd
IOV range.
Definition: TRTStrawAlign.h:56
y
#define y
TRTStrawAlign::finalize
StatusCode finalize(void)
Definition: TRTStrawAlign.cxx:238
DEBUG
#define DEBUG
Definition: page_access.h:11
TRTStrawAlign::p_caldbtool
ServiceHandle< ITRT_StrawAlignDbSvc > p_caldbtool
db tool
Definition: TRTStrawAlign.h:37
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
str
Definition: BTagTrackIpAccessor.cxx:11
TRTStrawAlign.h
Algorithm to make individual Straw Alignment.
ITRT_AlignDbSvc.h
abstract interface to Service to manage TRT alignment conditions
TRTStrawAlign::m_moduleAlignTag
std::string m_moduleAlignTag
IOV version tag for module alignment.
Definition: TRTStrawAlign.h:53
TRTStrawAlign::m_outputPOOLFile
std::string m_outputPOOLFile
POOL file to write.
Definition: TRTStrawAlign.h:52
StrawDxContainer.h
Class for storing/accessing trt endpoint corrections data.
InDetDD::TRT_BaseElement
Definition: TRT_BaseElement.h:57
TRTStrawAlign::m_runRangeBegin
int m_runRangeBegin
IOV range.
Definition: TRTStrawAlign.h:55