ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
InnerDetector
InDetAlignAlgs
InDetAlignGenAlgs
src
AlignWrt.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// AlignWrt.cxx
6
// Richard Hawkings, started 15/4/04
7
// Algorithm to create ID Alignment database in TDS and optionally write
8
// it to conditions database
9
//
10
#include <fstream>
11
#include "
AthenaBaseComps/AthCheckMacros.h
"
12
#include "GaudiKernel/SmartDataPtr.h"
13
#include "
AthenaKernel/IOVTime.h
"
14
#include "
InDetAlignGenTools/IInDetAlignDBTool.h
"
15
#include "
DetDescrConditions/DetCondKeyTrans.h
"
16
#include "
RegistrationServices/IIOVRegistrationSvc.h
"
17
18
#include "
InDetAlignGenAlgs/InDetAlignWrt.h
"
19
#include "
GeoPrimitives/CLHEPtoEigenConverter.h
"
20
21
22
InDetAlignWrt::InDetAlignWrt
(
const
std::string& name, ISvcLocator* pSvcLocator)
23
:
AthAlgorithm
(name, pSvcLocator),
24
p_iddbtool
(
"InDetAlignDBTool"
),
25
p_migratetool
(
"InDetAlignDBTool/InDetAlignMigrate"
),
26
p_eventinfo
(nullptr),
27
m_setup
(false),
28
m_par_create
(true),
29
m_par_wrt
(false),
30
m_par_wrtiov
(true),
31
m_par_print
(false),
32
m_par_migrate
(false),
33
m_par_rfile
(
""
),
34
m_par_wfile
(
""
),
35
m_par_dispfile
(
""
),
36
m_par_ntuple
(false),
37
m_par_wrtrun
(-1),
38
m_par_wrtevent
(0),
39
m_par_run1
(
IOVTime
::MINRUN),
40
m_par_run2
(
IOVTime
::MAXRUN),
41
m_par_evt1
(
IOVTime
::MINEVENT),
42
m_par_evt2
(
IOVTime
::MAXEVENT),
43
m_par_iovtag
(
""
),
44
m_par_dbtoolinst
(
"InDetAlignDBTool"
),
45
m_par_dispmode
(0),
46
m_par_dettype
(-1),
47
m_par_bec
(-1),
48
m_par_layer
(-1),
49
m_par_ring
(-1),
50
m_par_sector
(-1),
51
m_par_rphidisp
(0.1),
52
m_par_rdisp
(0.2),
53
m_par_zdisp
(0.3),
54
m_par_systdisp
(1),
55
m_par_irskip
(0),
56
m_par_dispcsc
(0),
57
m_par_writetop
(false),
58
m_par_topname
(
""
)
59
{
60
61
// declare algorithm parameters
62
declareProperty
(
"Create"
,
m_par_create
);
63
declareProperty
(
"Write"
,
m_par_wrt
);
64
declareProperty
(
"WriteIOV"
,
m_par_wrtiov
);
65
declareProperty
(
"PrintDB"
,
m_par_print
);
66
declareProperty
(
"Migrate"
,
m_par_migrate
);
67
declareProperty
(
"RFile"
,
m_par_rfile
);
68
declareProperty
(
"WFile"
,
m_par_wfile
);
69
declareProperty
(
"RWNtuple"
,
m_par_ntuple
);
70
declareProperty
(
"WriteRun"
,
m_par_wrtrun
);
71
declareProperty
(
"WriteEvent"
,
m_par_wrtevent
);
72
declareProperty
(
"ValidRun1"
,
m_par_run1
);
73
declareProperty
(
"ValidRun2"
,
m_par_run2
);
74
declareProperty
(
"ValidEvent1"
,
m_par_evt1
);
75
declareProperty
(
"ValidEvent2"
,
m_par_evt2
);
76
declareProperty
(
"IOVTag"
,
m_par_iovtag
);
77
declareProperty
(
"DBToolInst"
,
m_par_dbtoolinst
);
78
declareProperty
(
"DispMode"
,
m_par_dispmode
);
79
declareProperty
(
"DispDet"
,
m_par_dettype
);
80
declareProperty
(
"DispBec"
,
m_par_bec
);
81
declareProperty
(
"DispLayer"
,
m_par_layer
);
82
declareProperty
(
"DispRing"
,
m_par_ring
);
83
declareProperty
(
"DispSector"
,
m_par_sector
);
84
declareProperty
(
"DispRphi"
,
m_par_rphidisp
);
85
declareProperty
(
"DispR"
,
m_par_rdisp
);
86
declareProperty
(
"DispZ"
,
m_par_zdisp
);
87
declareProperty
(
"DispSyst"
,
m_par_systdisp
);
88
declareProperty
(
"DispFile"
,
m_par_dispfile
);
89
declareProperty
(
"RndmSkip"
,
m_par_irskip
);
90
declareProperty
(
"DispCSC"
,
m_par_dispcsc
);
91
92
declareProperty
(
"WriteTopTrans"
,
m_par_writetop
);
93
declareProperty
(
"TopTransFile"
,
m_par_topname
);
94
95
declareProperty
(
"InDetAlignDBTool"
,
p_iddbtool
);
96
declareProperty
(
"InDetAlignMigrateTool"
,
p_migratetool
);
97
}
98
99
100
InDetAlignWrt::~InDetAlignWrt
(
void
)
101
{}
102
103
StatusCode
InDetAlignWrt::initialize
() {
104
ATH_MSG_DEBUG
(
"InDetAlignWrt::initialize() called"
);
105
// get storegate pointers
106
if
( (
evtStore
().retrieve().isFailure()) ||
107
(
detStore
().retrieve().isFailure())) {
108
ATH_MSG_VERBOSE
(
"StoreGate or DetStore services not found"
);
109
return
StatusCode::FAILURE;
110
}
111
112
113
ATH_CHECK
(
p_iddbtool
.retrieve() );
114
115
// get second InDetAlignDBTool for migration if needed
116
if
(
m_par_migrate
) {
117
ATH_CHECK
(
p_migratetool
.retrieve() );
118
}
119
120
if
(
msgLvl
(MSG::DEBUG)) {
121
if
(
m_par_create
)
msg
() <<
"ID Alignment database structures will be created"
<<
endmsg
;
122
if
(
m_par_rfile
!=
""
) {
123
if
(
m_par_ntuple
)
msg
() <<
"Alignment constants will be initialised from ntuple: "
<<
m_par_rfile
<<
endmsg
;
124
else
msg
() <<
"Alignment constants will be initialised from text file"
<<
m_par_rfile
<<
endmsg
;
125
}
126
if
(
m_par_dispfile
!=
""
)
127
msg
() <<
"Alignment constants will be set according to recipe in file "
<<
m_par_dispfile
<<
endmsg
;
128
if
(
m_par_wrt
)
129
msg
() <<
"ID Alignment database structures will be written on run "
130
<<
m_par_wrtrun
<<
" event "
<<
m_par_wrtevent
<<
endmsg
;
131
if
(
m_par_wfile
!=
""
)
132
msg
() <<
"Structures will be written on file "
<<
m_par_wfile
<<
endmsg
;
133
if
(
m_par_writetop
)
134
msg
() <<
"Toplevel transforms will be read from file "
<<
m_par_topname
135
<<
"and written on run "
<<
m_par_wrtrun
<<
" event "
<<
m_par_wrtevent
<<
endmsg
;
136
if
(!
m_par_wrtiov
)
137
msg
() <<
"IOV writing will be suppressed - only output stream"
<<
endmsg
;
138
}
139
140
return
StatusCode::SUCCESS;
141
}
142
143
StatusCode
InDetAlignWrt::execute
(
const
EventContext&
/*ctx*/
) {
144
145
if
(!
m_setup
) {
146
m_setup
=
true
;
147
if
(
m_par_create
) {
148
ATH_MSG_DEBUG
(
149
"Creating null alignment database from geometry information in GeoModel"
);
150
p_iddbtool
->createDB();
151
}
152
if
(
m_par_rfile
!=
""
) {
153
if
(
m_par_ntuple
) {
154
p_iddbtool
->readNtuple(
m_par_rfile
);
155
}
else
{
156
p_iddbtool
->readTextFile(
m_par_rfile
);
157
}
158
}
159
if
(
m_par_dispmode
>0 ||
m_par_dispcsc
>0)
DispDB
();
160
if
(
m_par_dispfile
!=
""
)
dispFile
();
161
if
(
m_par_print
)
p_iddbtool
->printDB(2);
162
}
163
// make a fall back solution in case event info not available to prevent crash
164
int
run
= -1;
165
int
event
= 0;
166
if
(
evtStore
()->
contains< xAOD::EventInfo >
(
"EventInfo"
) &&
167
StatusCode::SUCCESS==
evtStore
()->retrieve(
p_eventinfo
)) {
168
run
=
p_eventinfo
->runNumber();
169
event
=
p_eventinfo
->eventNumber();
170
}
171
172
ATH_MSG_DEBUG
(
"In AlignWrt::execute for run/event "
<<
run
<<
173
","
<< event );
174
// trigger database write by setting filter passed to false
175
if
((
m_par_wrt
||
m_par_writetop
) &&
176
m_par_wrtrun
==
run
&&
m_par_wrtevent
==event)
doOutput
();
177
178
return
StatusCode::SUCCESS;
179
}
180
181
182
StatusCode
InDetAlignWrt::finalize
() {
183
if
(
m_par_wrtrun
==-1)
doOutput
();
184
if
(
m_par_migrate
)
doMigration
();
185
return
StatusCode::SUCCESS;
186
}
187
188
void
InDetAlignWrt::DispDB
() {
189
// displace silicon modules according to recipe in DispMode
190
// or use DispCSC if appropriate parameter is set
191
//if (m_par_dispcsc!=0) {
192
// ATH_MSG_DEBUG("DispCSC called for mode " << m_par_dispcsc );
193
// p_iddbtool->dispCSC(m_par_dettype, m_par_bec, m_par_layer, m_par_ring,
194
// m_par_sector, m_par_dispcsc);
195
//} else {
196
ATH_MSG_DEBUG
(
"DispDB called for mode "
<<
m_par_dispmode
);
197
p_iddbtool
->dispGroup(
m_par_dettype
,
m_par_bec
,
m_par_layer
,
m_par_ring
,
m_par_sector
,
198
m_par_rphidisp
,
m_par_rdisp
,
m_par_zdisp
,
m_par_systdisp
,
m_par_dispmode
,
m_par_irskip
);
199
//}
200
}
201
202
void
InDetAlignWrt::dispFile
() {
203
ATH_MSG_DEBUG
(
204
"::dispFile() : Initialise AlignableTransforms from parameters file "
205
<<
m_par_dispfile
);
206
std::ifstream infile;
207
infile.open(
m_par_dispfile
.c_str());
208
// loop over lines in file
209
int
nline=0;
210
std::string cline;
211
int
level,isyst,dettype,bec,layer,ring,sector;
212
float
rpd,rd,zd;
213
while
(infile >> level >> isyst >> dettype >> bec >> layer >> ring >>
214
sector >> rpd >>
215
rd >> zd) {
216
++nline;
217
ATH_MSG_DEBUG
(
"Add displacement level "
<< level <<
" syst "
<<
218
isyst <<
" to [det,bec,layer] ["
<< dettype <<
","
<< bec <<
","
<<
219
layer <<
"] {rphi,r,z} {"
<< rpd <<
","
<< rd <<
","
<< zd <<
"}"
);
220
p_iddbtool
->dispGroup(dettype,bec,layer,ring,sector,
221
rpd,rd,zd,isyst,level,
m_par_irskip
);
222
}
// end of input loop
223
ATH_MSG_DEBUG
(
"Read "
<< nline <<
224
" displacement recipe lines"
);
225
}
226
227
void
InDetAlignWrt::doOutput
() {
228
// write all objects and fill IOV database
229
if
(
m_par_wrt
) {
230
// first sort, just in case
231
p_iddbtool
->sortTrans();
232
if
(
m_par_wfile
==
""
) {
233
ATH_MSG_DEBUG
(
"doOutput for AlignableTransforms"
);
234
if
(StatusCode::SUCCESS!=
p_iddbtool
->outputObjs())
235
msg
(MSG::ERROR) <<
"Write of AlignableTransforms fails"
<<
endmsg
;
236
if
(
m_par_wrtiov
)
237
p_iddbtool
->fillDB(
m_par_iovtag
,
m_par_run1
,
m_par_evt1
,
m_par_run2
,
m_par_evt2
);
238
}
else
{
239
p_iddbtool
->writeFile(
m_par_ntuple
,
m_par_wfile
);
240
}
241
}
242
if
(
m_par_writetop
) {
243
genTopTrans
();
244
}
245
}
246
247
void
InDetAlignWrt::genTopTrans
() {
248
// generate top level transforms into TDS
249
ATH_MSG_DEBUG
(
"Initialise TOPTRANS from parameters file: "
<<
250
m_par_topname
);
251
DetCondKeyTrans
* dkp=
new
DetCondKeyTrans
();
252
std::ifstream infile;
253
infile.open(
m_par_topname
.c_str());
254
// loop over all lines in file
255
int
nline=0;
256
std::string cline,key;
257
float
xd,yd,zd,
phi
,
theta
,psi;
258
while
(infile >> key >> xd >> yd >> zd >>
phi
>>
theta
>> psi) {
259
++nline;
260
ATH_MSG_DEBUG
(
"Add transform name: "
<< key <<
" x/y/z "
<< xd <<
","
<< yd <<
261
","
<< zd <<
" phi/theta/psi "
<<
phi
<<
","
<<
theta
<<
","
<< psi );
262
HepGeom::Transform3D newtrans=HepGeom::Transform3D(CLHEP::HepRotation(
phi
,
theta
,psi),
263
CLHEP::Hep3Vector(xd,yd,zd));
264
dkp->
setTransform
(key,newtrans);
265
}
266
ATH_MSG_DEBUG
(
"Read "
<< nline <<
" lines from recipe file"
);
267
// record object in TDS
268
if
(StatusCode::SUCCESS==
detStore
()->record(dkp,
"/GLOBAL/GEOM/TOPTRANS"
)) {
269
ATH_MSG_DEBUG
(
"Recorded TOPTRANS in TDS"
);
270
}
else
{
271
ATH_MSG_DEBUG
(
"Failed to record TOPTRANS in TDS"
);
272
}
273
}
274
275
void
InDetAlignWrt::doMigration
() {
276
ATH_MSG_DEBUG
(
"Convert Pixel/SCT alignment from old to new format"
);
277
// create new format database
278
p_migratetool
->createDB();
279
// copy data from old to new database via temporary file
280
p_iddbtool
->writeFile(
false
,
"migrate.dat"
);
281
p_migratetool
->readTextFile(
"migrate.dat"
);
282
p_migratetool
->writeFile(
false
,
"migrate.check"
);
283
// write data to POOL file and optionally IOV
284
if
(StatusCode::SUCCESS!=
p_migratetool
->outputObjs())
285
msg
(MSG::ERROR) <<
"Write of AlignableTransform fails"
<<
endmsg
;
286
if
(
m_par_wrtiov
)
287
p_migratetool
->fillDB(
m_par_iovtag
,
m_par_run1
,
m_par_evt1
,
m_par_run2
,
m_par_evt2
);
288
}
phi
Scalar phi() const
phi method
Definition
AmgMatrixBasePlugin.h:67
theta
Scalar theta() const
theta method
Definition
AmgMatrixBasePlugin.h:75
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
AthCheckMacros.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x,...)
Definition
AthMsgStreamMacros.h:42
CLHEPtoEigenConverter.h
DetCondKeyTrans.h
IIOVRegistrationSvc.h
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
IInDetAlignDBTool.h
IOVTime.h
Basic time unit for IOVSvc.
InDetAlignWrt.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
AthCommonAlgorithm< Gaudi::Algorithm >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition
AthCommonMsg.h:30
AthCommonAlgorithm< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
DetCondKeyTrans
Class to hold set of HepGeom::Transform3D keyed by string value for storage in the conditions DB typi...
Definition
DetCondKeyTrans.h:27
DetCondKeyTrans::setTransform
void setTransform(const std::string &key, const HepGeom::Transform3D &trans)
Definition
DetCondKeyTrans.h:64
IOVTime
Basic time unit for IOVSvc.
Definition
IOVTime.h:33
InDetAlignWrt::doOutput
void doOutput()
Definition
AlignWrt.cxx:227
InDetAlignWrt::DispDB
void DispDB()
Definition
AlignWrt.cxx:188
InDetAlignWrt::m_par_print
bool m_par_print
Definition
InDetAlignWrt.h:35
InDetAlignWrt::initialize
StatusCode initialize(void)
Definition
AlignWrt.cxx:103
InDetAlignWrt::m_par_iovtag
std::string m_par_iovtag
Definition
InDetAlignWrt.h:47
InDetAlignWrt::m_setup
bool m_setup
Definition
InDetAlignWrt.h:29
InDetAlignWrt::m_par_evt1
unsigned int m_par_evt1
Definition
InDetAlignWrt.h:45
InDetAlignWrt::m_par_dettype
int m_par_dettype
Definition
InDetAlignWrt.h:52
InDetAlignWrt::m_par_wrtevent
int m_par_wrtevent
Definition
InDetAlignWrt.h:42
InDetAlignWrt::p_iddbtool
ToolHandle< IInDetAlignDBTool > p_iddbtool
Definition
InDetAlignWrt.h:26
InDetAlignWrt::doMigration
void doMigration()
Definition
AlignWrt.cxx:275
InDetAlignWrt::m_par_rdisp
float m_par_rdisp
Definition
InDetAlignWrt.h:58
InDetAlignWrt::m_par_rfile
std::string m_par_rfile
Definition
InDetAlignWrt.h:37
InDetAlignWrt::m_par_dispcsc
int m_par_dispcsc
Definition
InDetAlignWrt.h:62
InDetAlignWrt::m_par_dispfile
std::string m_par_dispfile
Definition
InDetAlignWrt.h:39
InDetAlignWrt::m_par_wfile
std::string m_par_wfile
Definition
InDetAlignWrt.h:38
InDetAlignWrt::m_par_run2
unsigned int m_par_run2
Definition
InDetAlignWrt.h:44
InDetAlignWrt::finalize
StatusCode finalize(void)
Definition
AlignWrt.cxx:182
InDetAlignWrt::p_eventinfo
const xAOD::EventInfo * p_eventinfo
Definition
InDetAlignWrt.h:28
InDetAlignWrt::m_par_migrate
bool m_par_migrate
Definition
InDetAlignWrt.h:36
InDetAlignWrt::m_par_rphidisp
float m_par_rphidisp
Definition
InDetAlignWrt.h:57
InDetAlignWrt::m_par_ntuple
bool m_par_ntuple
Definition
InDetAlignWrt.h:40
InDetAlignWrt::m_par_sector
int m_par_sector
Definition
InDetAlignWrt.h:56
InDetAlignWrt::m_par_dbtoolinst
std::string m_par_dbtoolinst
Definition
InDetAlignWrt.h:48
InDetAlignWrt::execute
StatusCode execute(const EventContext &ctx)
Execute method.
Definition
AlignWrt.cxx:143
InDetAlignWrt::InDetAlignWrt
InDetAlignWrt(const std::string &name, ISvcLocator *pSvcLocator)
Definition
AlignWrt.cxx:22
InDetAlignWrt::m_par_writetop
bool m_par_writetop
Definition
InDetAlignWrt.h:63
InDetAlignWrt::m_par_topname
std::string m_par_topname
Definition
InDetAlignWrt.h:64
InDetAlignWrt::m_par_wrtrun
int m_par_wrtrun
Definition
InDetAlignWrt.h:41
InDetAlignWrt::m_par_systdisp
int m_par_systdisp
Definition
InDetAlignWrt.h:60
InDetAlignWrt::m_par_bec
int m_par_bec
Definition
InDetAlignWrt.h:53
InDetAlignWrt::genTopTrans
void genTopTrans()
Definition
AlignWrt.cxx:247
InDetAlignWrt::m_par_wrt
bool m_par_wrt
Definition
InDetAlignWrt.h:33
InDetAlignWrt::m_par_create
bool m_par_create
Definition
InDetAlignWrt.h:32
InDetAlignWrt::p_migratetool
ToolHandle< IInDetAlignDBTool > p_migratetool
Definition
InDetAlignWrt.h:27
InDetAlignWrt::m_par_ring
int m_par_ring
Definition
InDetAlignWrt.h:55
InDetAlignWrt::m_par_dispmode
int m_par_dispmode
Definition
InDetAlignWrt.h:51
InDetAlignWrt::m_par_evt2
unsigned int m_par_evt2
Definition
InDetAlignWrt.h:46
InDetAlignWrt::m_par_run1
unsigned int m_par_run1
Definition
InDetAlignWrt.h:43
InDetAlignWrt::~InDetAlignWrt
~InDetAlignWrt(void)
Definition
AlignWrt.cxx:100
InDetAlignWrt::m_par_zdisp
float m_par_zdisp
Definition
InDetAlignWrt.h:59
InDetAlignWrt::dispFile
void dispFile()
Definition
AlignWrt.cxx:202
InDetAlignWrt::m_par_layer
int m_par_layer
Definition
InDetAlignWrt.h:54
InDetAlignWrt::m_par_irskip
int m_par_irskip
Definition
InDetAlignWrt.h:61
InDetAlignWrt::m_par_wrtiov
bool m_par_wrtiov
Definition
InDetAlignWrt.h:34
contains
bool contains(const std::string &s, const std::string ®x)
does a string contain the substring
Definition
hcg.cxx:116
run
int run(int argc, char *argv[])
Definition
ttree2hdf5.cxx:28
Generated on
for ATLAS Offline Software by
1.17.0