ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
HighGranularityTimingDetector
HGTD_AlignAlgs
HGTD_AlignGenAlgs
src
HGTD_MisalignAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
HGTD_MisalignAlg.h
"
6
#include "GeoModelKernel/GeoAlignableTransform.h"
7
#include "
GeoPrimitives/GeoPrimitives.h
"
8
9
#include "
HGTD_AlignGenTools/IHGTD_AlignDBTool.h
"
10
#include "
GeoPrimitives/CLHEPtoEigenConverter.h
"
11
#include "
AthenaBaseComps/AthCheckMacros.h
"
12
#include "
AthenaKernel/IOVTime.h
"
13
14
#include <fstream>
15
16
StatusCode
HGTD_MisalignAlg::initialize
()
17
{
18
ATH_MSG_INFO
(
"=== HGTD_MisalignAlg initialize ==="
);
19
20
//------------------------------------------------------------
21
// Retrieve services
22
//------------------------------------------------------------
23
ATH_CHECK
(
m_rndmSvc
.retrieve());
24
ATH_CHECK
(
m_alignDBTool
.retrieve());
25
26
ATH_MSG_DEBUG
(
"Retrieved HGTD_AlignDBTool"
);
27
ATH_MSG_DEBUG
(
"AlignDBTool = "
<<
m_alignDBTool
.typeAndName());
28
ATH_MSG_DEBUG
(
"WriteToDB = "
<<
m_writeToDB
);
29
ATH_MSG_DEBUG
(
"SQLiteTag = "
<<
m_sqliteTag
);
30
ATH_MSG_DEBUG
(
"RandomStream = "
<<
m_randomStream
);
31
32
//------------------------------------------------------------
33
// Retrieve HGTD identifier helper
34
//------------------------------------------------------------
35
ATH_CHECK
(
detStore
()->retrieve(
m_hgtdIdHelper
,
"HGTD_ID"
));
36
37
//------------------------------------------------------------
38
// Retrieve HGTD detector manager
39
//------------------------------------------------------------
40
ATH_CHECK
(
detStore
()->retrieve(
m_hgtdManager
,
"HGTD"
));
41
ATH_MSG_DEBUG
(
"Retrieved HGTD_DetectorManager"
);
42
43
//------------------------------------------------------------
44
// Open output file
45
//------------------------------------------------------------
46
m_outfile
.open(
m_outputFile
.value());
47
48
if
(!
m_outfile
.is_open()) {
49
50
ATH_MSG_ERROR
(
51
"Cannot open output file "
52
<<
m_outputFile
.value());
53
54
return
StatusCode::FAILURE;
55
}
56
ATH_MSG_DEBUG
(
"Output file = "
<<
m_outputFile
.value());
57
58
//------------------------------------------------------------
59
// ASCII validation output
60
//------------------------------------------------------------
61
m_outfile
62
<<
"# hash "
63
<<
"endcap "
64
<<
"layer "
65
<<
"phi_module "
66
<<
"eta_module "
67
<<
"local_dx "
68
<<
"local_dy "
69
<<
"local_dz "
70
<<
"center_x "
71
<<
"center_y "
72
<<
"center_z "
73
<<
"misaligned_x "
74
<<
"misaligned_y "
75
<<
"misaligned_z\n"
;
76
77
SmartIF<ITHistSvc> histSvc{
78
Gaudi::svcLocator()->service(
"THistSvc"
)};
79
ATH_CHECK
(histSvc.isValid());
80
81
m_tree
=
new
TTree(
"HGTDMisalignment"
,
"HGTD alignment validation"
);
82
83
ATH_CHECK
(
84
histSvc->regTree(
"/CREATEMISALIGN/HGTDMisalignment"
,
m_tree
));
85
86
//------------------------------------------------------------
87
// Validation tree branches
88
// These quantities are used to validate the generated
89
// misalignment and compare the nominal and shifted geometry.
90
//------------------------------------------------------------
91
92
m_tree
->Branch(
"hash"
, &
m_hash
,
"hash/i"
);
93
94
// HGTD detector identifier
95
m_tree
->Branch(
"endcap"
, &
m_endcap
,
"endcap/I"
);
96
m_tree
->Branch(
"layer"
, &
m_layer
,
"layer/I"
);
97
m_tree
->Branch(
"phi_module"
, &
m_phiModule
,
"phi_module/I"
);
98
m_tree
->Branch(
"eta_module"
, &
m_etaModule
,
"eta_module/I"
);
99
100
// Applied local misalignment
101
m_tree
->Branch(
"local_dx"
, &
m_localDx
,
"local_dx/F"
);
102
m_tree
->Branch(
"local_dy"
, &
m_localDy
,
"local_dy/F"
);
103
m_tree
->Branch(
"local_dz"
, &
m_localDz
,
"local_dz/F"
);
104
105
// Nominal global center
106
m_tree
->Branch(
"center_x"
, &
m_centerX
,
"center_x/F"
);
107
m_tree
->Branch(
"center_y"
, &
m_centerY
,
"center_y/F"
);
108
m_tree
->Branch(
"center_z"
, &
m_centerZ
,
"center_z/F"
);
109
110
// Misaligned global center
111
m_tree
->Branch(
"misaligned_x"
, &
m_shiftedX
,
"misaligned_x/F"
);
112
m_tree
->Branch(
"misaligned_y"
, &
m_shiftedY
,
"misaligned_y/F"
);
113
m_tree
->Branch(
"misaligned_z"
, &
m_shiftedZ
,
"misaligned_z/F"
);
114
115
//------------------------------------------------------------
116
// Print configuration
117
//------------------------------------------------------------
118
ATH_MSG_DEBUG
(
"MisalignMode = "
<<
m_mode
.value());
119
ATH_MSG_DEBUG
(
"ShiftX = "
<<
m_shiftX
.value());
120
ATH_MSG_DEBUG
(
"ShiftY = "
<<
m_shiftY
.value());
121
ATH_MSG_DEBUG
(
"ShiftZ = "
<<
m_shiftZ
.value());
122
ATH_MSG_DEBUG
(
"SigmaX = "
<<
m_sigmaX
.value());
123
ATH_MSG_DEBUG
(
"SigmaY = "
<<
m_sigmaY
.value());
124
ATH_MSG_DEBUG
(
"SigmaZ = "
<<
m_sigmaZ
.value());
125
ATH_MSG_DEBUG
(
"ApplyTranslation = "
<<
m_applyTranslation
.value());
126
127
return
StatusCode::SUCCESS;
128
}
129
130
StatusCode
HGTD_MisalignAlg::execute
(
const
EventContext&)
131
{
132
ATH_MSG_DEBUG
(
"HGTD_MisalignAlg execute()"
);
133
134
++
m_nEvents
;
135
136
//------------------------------------------------------------
137
// Nothing to do if misalignment is disabled
138
//------------------------------------------------------------
139
if
(!
m_applyTranslation
.value()) {
140
ATH_MSG_DEBUG
(
"Translation disabled"
);
141
return
StatusCode::SUCCESS;
142
}
143
144
//------------------------------------------------------------
145
// Generate the alignment only once
146
//------------------------------------------------------------
147
if
(!
m_firstEvent
) {
148
return
StatusCode::SUCCESS;
149
}
150
151
ATH_MSG_DEBUG
(
"Generating HGTD misalignment"
);
152
153
//------------------------------------------------------------
154
// Create a fresh alignment database
155
//------------------------------------------------------------
156
if
(
m_createFreshDB
) {
157
158
ATH_MSG_DEBUG
(
"Creating HGTD alignment database"
);
159
160
ATH_CHECK
(
m_alignDBTool
->createDB());
161
162
m_createFreshDB
=
false
;
163
}
164
165
//------------------------------------------------------------
166
// Generate all module misalignments
167
//------------------------------------------------------------
168
ATH_CHECK
(
GenerateMisalignment
());
169
170
//------------------------------------------------------------
171
// Write AlignableTransforms
172
//------------------------------------------------------------
173
ATH_MSG_DEBUG
(
"Writing HGTD alignment constants"
);
174
175
if
(
m_writeToDB
) {
176
ATH_MSG_DEBUG
(
"Calling outputObjs()"
);
177
ATH_CHECK
(
m_alignDBTool
->outputObjs());
178
179
ATH_MSG_DEBUG
(
"Finished outputObjs()"
);
180
ATH_MSG_DEBUG
(
"Calling fillDB()"
);
181
182
//------------------------------------------------------------
183
// Write SQLite database
184
//------------------------------------------------------------
185
ATH_CHECK
(
186
m_alignDBTool
->fillDB(
187
m_sqliteTag
,
188
IOVTime::MINRUN
,
189
IOVTime::MINEVENT
,
190
IOVTime::MAXRUN
,
191
IOVTime::MAXEVENT
));
192
193
ATH_MSG_DEBUG
(
"Finished fillDB()"
);
194
}
195
else
{
196
ATH_MSG_DEBUG
(
"WriteToDB = FALSE, skipping database writing."
);
197
}
198
199
//------------------------------------------------------------
200
// Do not regenerate on later events
201
//------------------------------------------------------------
202
m_firstEvent
=
false
;
203
204
return
StatusCode::SUCCESS;
205
}
206
207
StatusCode
HGTD_MisalignAlg::GenerateMisalignment
()
208
{
209
const
auto
* elements =
m_hgtdManager
->getDetectorElementCollection();
210
211
if
(!elements) {
212
ATH_MSG_ERROR
(
"HGTD detector element collection is null"
);
213
return
StatusCode::FAILURE;
214
}
215
216
ATH_MSG_DEBUG
(
"Number of HGTD detector elements = "
217
<< elements->size());
218
219
ATH_MSG_DEBUG
(
"Misalignment mode = "
220
<<
m_mode
.value());
221
222
//------------------------------------------------------------
223
// Random generators
224
//------------------------------------------------------------
225
Rndm::Numbers gaussX(
226
m_rndmSvc
.operator->(),
227
Rndm::Gauss(0.,
m_sigmaX
.value()));
228
229
Rndm::Numbers gaussY(
230
m_rndmSvc
.operator->(),
231
Rndm::Gauss(0.,
m_sigmaY
.value()));
232
233
Rndm::Numbers gaussZ(
234
m_rndmSvc
.operator->(),
235
Rndm::Gauss(0.,
m_sigmaZ
.value()));
236
237
int
count
= 0;
238
239
//------------------------------------------------------------
240
// Loop over all HGTD detector elements
241
//------------------------------------------------------------
242
for
(
const
auto
* element : *elements) {
243
244
if
(!element)
245
continue
;
246
247
Identifier
id
= element->identify();
248
IdentifierHash
hash = element->identifyHash();
249
250
//--------------------------------------------------------
251
// Detector identifier information
252
//--------------------------------------------------------
253
m_hash
= hash.value();
254
m_endcap
=
m_hgtdIdHelper
->endcap(
id
);
255
m_layer
=
m_hgtdIdHelper
->layer(
id
);
256
m_phiModule
=
m_hgtdIdHelper
->phi_module(
id
);
257
m_etaModule
=
m_hgtdIdHelper
->eta_module(
id
);
258
259
//--------------------------------------------------------
260
// Misalignment parameters
261
//--------------------------------------------------------
262
double
dx = 0.0;
263
double
dy = 0.0;
264
double
dz = 0.0;
265
266
if
(
m_mode
.value() == 0) {
267
// no misalignment
268
}
269
else
if
(
m_mode
.value() == 1) {
270
// Constant translation
271
dx =
m_shiftX
.value();
272
dy =
m_shiftY
.value();
273
dz =
m_shiftZ
.value();
274
}
275
else
if
(
m_mode
.value() == 2) {
276
// Random Gaussian translation
277
dx = gaussX();
278
dy = gaussY();
279
dz = gaussZ();
280
}
281
else
{
282
ATH_MSG_WARNING
(
"Unknown MisalignMode = "
283
<<
m_mode
.value()
284
<<
". No misalignment applied."
);
285
continue
;
286
}
287
//--------------------------------------------------------
288
// Update alignment constants
289
//--------------------------------------------------------
290
bool
ok =
291
m_alignDBTool
->tweakTrans(
292
id
,
293
1,
294
Amg::Vector3D
(dx, dy, dz),
295
0.,
296
0.,
297
0.);
298
299
if
(!ok) {
300
301
ATH_MSG_WARNING
(
302
"Failed to update module "
303
<< hash);
304
305
continue
;
306
}
307
308
//--------------------------------------------------------
309
// Fill validation tree
310
// For the current implementation only translations are
311
// applied, therefore the shifted position is simply
312
// nominal position + translation.
313
//--------------------------------------------------------
314
315
m_localDx
= dx;
316
m_localDy
= dy;
317
m_localDz
= dz;
318
319
//--------------------------------------------------------
320
// Nominal module position
321
//--------------------------------------------------------
322
const
Amg::Vector3D
& center = element->center();
323
324
m_centerX
= center.x();
325
m_centerY
= center.y();
326
m_centerZ
= center.z();
327
328
m_shiftedX
=
m_centerX
+
m_localDx
;
329
m_shiftedY
=
m_centerY
+
m_localDy
;
330
m_shiftedZ
=
m_centerZ
+
m_localDz
;
331
332
//--------------------------------------------------------
333
// Print first few modules
334
//--------------------------------------------------------
335
if
(
count
< 10) {
336
337
ATH_MSG_DEBUG
(
338
"Module "
339
<< hash
340
<<
" -> shift ("
341
<< dx <<
", "
342
<< dy <<
", "
343
<< dz <<
")"
);
344
}
345
346
//--------------------------------------------------------
347
// Save to text file
348
//--------------------------------------------------------
349
m_outfile
350
<<
m_hash
<<
" "
351
<<
m_endcap
<<
" "
352
<<
m_layer
<<
" "
353
<<
m_phiModule
<<
" "
354
<<
m_etaModule
<<
" "
355
<<
m_localDx
<<
" "
356
<<
m_localDy
<<
" "
357
<<
m_localDz
<<
" "
358
<<
m_centerX
<<
" "
359
<<
m_centerY
<<
" "
360
<<
m_centerZ
<<
" "
361
<<
m_shiftedX
<<
" "
362
<<
m_shiftedY
<<
" "
363
<<
m_shiftedZ
364
<<
'\n'
;
365
366
m_tree
->Fill();
367
368
++
count
;
369
}
370
371
ATH_MSG_DEBUG
(
372
"Processed "
373
<<
count
374
<<
" HGTD modules"
);
375
376
return
StatusCode::SUCCESS;
377
}
378
379
StatusCode
HGTD_MisalignAlg::finalize
()
380
{
381
ATH_MSG_INFO
(
"HGTD_MisalignAlg finalize()"
);
382
383
//------------------------------------------------------------
384
// Close output file
385
//------------------------------------------------------------
386
if
(
m_outfile
.is_open()) {
387
m_outfile
.close();
388
}
389
390
ATH_CHECK
(
m_alignDBTool
->outputObjs());
391
392
ATH_CHECK
(
393
m_alignDBTool
->fillDB(
394
m_sqliteTag
,
395
IOVTime::MINRUN
,
396
IOVTime::MINEVENT
,
397
IOVTime::MAXRUN
,
398
IOVTime::MAXEVENT
399
)
400
);
401
402
ATH_MSG_INFO
(
"Processed "
<<
m_nEvents
<<
" event(s)"
);
403
404
return
StatusCode::SUCCESS;
405
}
AthCheckMacros.h
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
CLHEPtoEigenConverter.h
GeoPrimitives.h
HGTD_MisalignAlg.h
IHGTD_AlignDBTool.h
IOVTime.h
Basic time unit for IOVSvc.
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
HGTD_MisalignAlg::m_sigmaY
Gaudi::Property< double > m_sigmaY
Definition
HGTD_MisalignAlg.h:48
HGTD_MisalignAlg::m_shiftedZ
float m_shiftedZ
Definition
HGTD_MisalignAlg.h:145
HGTD_MisalignAlg::initialize
virtual StatusCode initialize() override
Definition
HGTD_MisalignAlg.cxx:16
HGTD_MisalignAlg::m_createFreshDB
Gaudi::Property< bool > m_createFreshDB
Definition
HGTD_MisalignAlg.h:94
HGTD_MisalignAlg::m_writeToDB
Gaudi::Property< bool > m_writeToDB
Definition
HGTD_MisalignAlg.h:108
HGTD_MisalignAlg::m_tree
TTree * m_tree
Definition
HGTD_MisalignAlg.h:130
HGTD_MisalignAlg::m_etaModule
int m_etaModule
Definition
HGTD_MisalignAlg.h:152
HGTD_MisalignAlg::m_hash
unsigned int m_hash
Definition
HGTD_MisalignAlg.h:148
HGTD_MisalignAlg::m_centerX
float m_centerX
Definition
HGTD_MisalignAlg.h:138
HGTD_MisalignAlg::m_outfile
std::ofstream m_outfile
Definition
HGTD_MisalignAlg.h:154
HGTD_MisalignAlg::m_outputFile
Gaudi::Property< std::string > m_outputFile
Definition
HGTD_MisalignAlg.h:71
HGTD_MisalignAlg::m_sigmaX
Gaudi::Property< double > m_sigmaX
Definition
HGTD_MisalignAlg.h:47
HGTD_MisalignAlg::m_localDz
float m_localDz
Definition
HGTD_MisalignAlg.h:135
HGTD_MisalignAlg::m_shiftZ
Gaudi::Property< double > m_shiftZ
Definition
HGTD_MisalignAlg.h:45
HGTD_MisalignAlg::m_shiftX
Gaudi::Property< double > m_shiftX
Definition
HGTD_MisalignAlg.h:43
HGTD_MisalignAlg::GenerateMisalignment
StatusCode GenerateMisalignment()
Definition
HGTD_MisalignAlg.cxx:207
HGTD_MisalignAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
HGTD_MisalignAlg.cxx:130
HGTD_MisalignAlg::m_shiftY
Gaudi::Property< double > m_shiftY
Definition
HGTD_MisalignAlg.h:44
HGTD_MisalignAlg::m_localDy
float m_localDy
Definition
HGTD_MisalignAlg.h:134
HGTD_MisalignAlg::m_hgtdManager
const HGTD_DetectorManager * m_hgtdManager
Definition
HGTD_MisalignAlg.h:78
HGTD_MisalignAlg::m_centerY
float m_centerY
Definition
HGTD_MisalignAlg.h:139
HGTD_MisalignAlg::m_sigmaZ
Gaudi::Property< double > m_sigmaZ
Definition
HGTD_MisalignAlg.h:49
HGTD_MisalignAlg::m_layer
int m_layer
Definition
HGTD_MisalignAlg.h:150
HGTD_MisalignAlg::m_shiftedY
float m_shiftedY
Definition
HGTD_MisalignAlg.h:144
HGTD_MisalignAlg::m_localDx
float m_localDx
Definition
HGTD_MisalignAlg.h:133
HGTD_MisalignAlg::finalize
virtual StatusCode finalize() override
Definition
HGTD_MisalignAlg.cxx:379
HGTD_MisalignAlg::m_randomStream
Gaudi::Property< std::string > m_randomStream
Definition
HGTD_MisalignAlg.h:62
HGTD_MisalignAlg::m_sqliteTag
Gaudi::Property< std::string > m_sqliteTag
Definition
HGTD_MisalignAlg.h:101
HGTD_MisalignAlg::m_firstEvent
bool m_firstEvent
Definition
HGTD_MisalignAlg.h:155
HGTD_MisalignAlg::m_mode
Gaudi::Property< int > m_mode
Definition
HGTD_MisalignAlg.h:42
HGTD_MisalignAlg::m_shiftedX
float m_shiftedX
Definition
HGTD_MisalignAlg.h:143
HGTD_MisalignAlg::m_phiModule
int m_phiModule
Definition
HGTD_MisalignAlg.h:151
HGTD_MisalignAlg::m_nEvents
unsigned int m_nEvents
Definition
HGTD_MisalignAlg.h:156
HGTD_MisalignAlg::m_centerZ
float m_centerZ
Definition
HGTD_MisalignAlg.h:140
HGTD_MisalignAlg::m_endcap
int m_endcap
Definition
HGTD_MisalignAlg.h:149
HGTD_MisalignAlg::m_rndmSvc
ServiceHandle< IRndmGenSvc > m_rndmSvc
Definition
HGTD_MisalignAlg.h:58
HGTD_MisalignAlg::m_hgtdIdHelper
const HGTD_ID * m_hgtdIdHelper
Definition
HGTD_MisalignAlg.h:122
HGTD_MisalignAlg::m_applyTranslation
Gaudi::Property< bool > m_applyTranslation
Definition
HGTD_MisalignAlg.h:52
HGTD_MisalignAlg::m_alignDBTool
ToolHandle< IHGTD_AlignDBTool > m_alignDBTool
Definition
HGTD_MisalignAlg.h:115
IOVTime::MAXRUN
static constexpr uint32_t MAXRUN
Definition
IOVTime.h:48
IOVTime::MINEVENT
static constexpr uint32_t MINEVENT
Definition
IOVTime.h:50
IOVTime::MAXEVENT
static constexpr uint32_t MAXEVENT
Definition
IOVTime.h:51
IOVTime::MINRUN
static constexpr uint32_t MINRUN
Definition
IOVTime.h:44
IdentifierHash
This is a "hash" representation of an Identifier.
Definition
IdentifierHash.h:25
count
int count(std::string s, const std::string ®x)
count how many occurances of a regx are in a string
Definition
hcg.cxx:148
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition
GeoPrimitives.h:47
Identifier
Definition
IdentifierFieldParser.cxx:14
Generated on
for ATLAS Offline Software by
1.17.0