ATLAS Offline Software
Loading...
Searching...
No Matches
SiTrkAlignDBTool.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
6#include "CLHEP/Geometry/Transform3D.h"
8
12
14
16
19
23
25
27#include "TFile.h"
28
29#include <vector>
30
31namespace InDet
32{
33
34//________________________________________________________________________
35SiTrkAlignDBTool::SiTrkAlignDBTool(const std::string & type, const std::string & name, const IInterface * parent)
36 : AthAlgTool(type,name,parent)
37 , m_pixHelper(nullptr)
38 , m_sctHelper(nullptr)
39 , m_idHelper(nullptr)
40 , m_writeSQLFile(true)
41 , m_SQLiteTag("test_tag")
42 , m_outputAlignFile("OutputSiAlignment.txt")
43 , m_outIBLDistFile("OutputIBLDist.txt")
44 , m_outGlobalFolderFile("OutputSiGlobalFolder.txt")
45 , m_writeTextFile(true)
46 , m_writeOldConstants(false)
47 , m_oldIBLDistFile("OldIBLDist.txt")
48 , m_oldAlignFile("OldSiAlignment.txt")
49 , m_oldGlobalFolderFile("OldSiGlobalFolder.txt")
50 , m_updateConstants(true)
51 , m_IDAlignDBTool("InDetAlignDBTool")
52 , m_alignModuleTool("Trk::AlignModuleTool/AlignModuleTool")
54 , m_sctGeoManager("")
55 , m_siGeoManager("")
56 , m_ntuple{}
60 , m_pixelaAlignDBM(false)
61 , m_sctAlignLevel(-1)
64 , m_siAlignLevel(-1)
65 , m_doSi(false)
66 , m_doPixel(false)
67 , m_doSCT(false)
68 , m_writeAsL3(false)
69 , m_writeAsL2(false)
70 , m_writeAsL16(false)
71{
72 declareInterface<ITrkAlignDBTool>(this);
73
74 declareProperty("WriteSQLFile", m_writeSQLFile);
75 declareProperty("SQLiteTag", m_SQLiteTag);
76 declareProperty("OutputTextFile", m_outputAlignFile);
77 declareProperty("OutputIBLDistFile", m_outIBLDistFile, "File to write out IBL distortions - set empy to suppress writing this folder");
78 declareProperty("OutputGlobalFolderFile",m_outGlobalFolderFile);
79 declareProperty("WriteTextFile", m_writeTextFile);
80 declareProperty("WriteOldConstants", m_writeOldConstants);
81 declareProperty("OldAlignFile", m_oldAlignFile);
82 declareProperty("OldIBLDistFile", m_oldIBLDistFile,"File to write out (old-style) IBL distortions - set empy to suppress writing this folder");
83 declareProperty("OldGlobalFolderFile",m_oldGlobalFolderFile);
84 declareProperty("UpdateConstants", m_updateConstants);
85 declareProperty("WriteAsL3", m_writeAsL3);
86
87 declareProperty("IDAlignDBTool", m_IDAlignDBTool);
88 declareProperty("AlignModuleTool", m_alignModuleTool, "Tool for handling of align module collections");
89 declareProperty("AlignmentDBM", m_pixelaAlignDBM);
90
91 declareProperty("PixelGeometryManager", m_pixelGeoManager, "Tool for handling the Pixel alignment geometry");
92 declareProperty("SCTGeometryManager", m_sctGeoManager, "Tool for handling the SCT alignment geometry");
93 declareProperty("SiGeometryManager", m_siGeoManager, "Tool for handling the Silicon alignment geometry");
94}
95
96//________________________________________________________________________
99
100//________________________________________________________________________
102
103 ATH_MSG_DEBUG("initialize() of SiTrkAlignDBTool");
104
105 if(!m_updateConstants) {
106 ATH_MSG_WARNING("Not updating Silicon constants!");
107 return StatusCode::SUCCESS;
108 }
109
110 // Si alignment database tool
111 ATH_CHECK( m_IDAlignDBTool.retrieve() );
112 // get AlignModuleTool
113 ATH_CHECK( m_alignModuleTool.retrieve() );
114 // retrieve Pixel helper
115 ATH_CHECK( detStore()->retrieve(m_pixHelper) );
116 // retrieve SCT helper
117 ATH_CHECK( detStore()->retrieve(m_sctHelper) );
118 ATH_CHECK(detStore()->retrieve(m_idHelper, "AtlasID"));
119
120 // check which geometry managers are loaded and which are to be used
121
122 // get SiGeometryManagerTool
123 if( !m_siGeoManager.empty() ) {
124 ATH_CHECK( m_siGeoManager.retrieve());
125
126 ATH_MSG_DEBUG("retrieved " << m_siGeoManager);
127 m_siAlignLevel = m_siGeoManager->alignLevel();
128 ATH_MSG_INFO(" Requested update of Level "<<m_siAlignLevel<<" alignment constants for Silicon");
129
130 // check alignment level but don't stop on error
131 // if unknown level given, set to -1
132 if(!checkSiLevel()) {
133 ATH_MSG_WARNING(" Storing of alignment constants for level "<<m_siAlignLevel<<" for Silicon is not implemented.");
135 }
136 }
137
138 // for anything else then level 0 we need the other two geometry managers
139 if(m_siAlignLevel!=0) {
140
141 // get PixelGeometryManagerTool
142 if( !m_pixelGeoManager.empty() ) {
143 ATH_CHECK( m_pixelGeoManager.retrieve());
144 ATH_MSG_DEBUG("retrieved " << m_pixelGeoManager);
145 m_pixelAlignLevel = m_pixelGeoManager->alignLevel();
146 m_pixelAlignLevelBarrel = m_pixelGeoManager->alignLevelBarrel();
147 m_pixelAlignLevelEndcaps = m_pixelGeoManager->alignLevelEndcaps();
148// m_pixelaAlignDBM = m_pixelGeoManager->alignDBM();
149 ATH_MSG_DEBUG("Retrieved Pixel Global alignment level: "<<m_pixelAlignLevel);
150 ATH_MSG_DEBUG("Retrieved Pixel Barrel alignment level: "<<m_pixelAlignLevelBarrel);
151 ATH_MSG_DEBUG("Retrieved Pixel Endcap alignment level: "<<m_pixelAlignLevelEndcaps);
152 ATH_MSG_DEBUG("Retrieved DBM alignment configuration: "<<m_pixelaAlignDBM);
153
154 if(m_pixelAlignLevel == 1)
155 ATH_MSG_INFO(" Requested update of Level "<<m_pixelAlignLevel<<" alignment constants for Pixel");
156 else {
157 ATH_MSG_INFO(" Requested update of Level "<<m_pixelAlignLevelBarrel<<" alignment constants for Pixel Barrel");
158 ATH_MSG_INFO(" Requested update of Level "<<m_pixelAlignLevelEndcaps<<" alignment constants for Pixel Endcaps");
159 }
160
161 // check alignment level but don't stop on error
162 if(!checkPixelLevel()) {
163 ATH_MSG_FATAL(" Pixel alignment level not given.");
164// return StatusCode::FAILURE;
165 }
166 }
167
168 // get SCTGeometryManagerTool
169 if( !m_sctGeoManager.empty() ) {
170 ATH_CHECK( m_sctGeoManager.retrieve());
171 ATH_MSG_DEBUG("retrieved " << m_sctGeoManager);
172 m_sctAlignLevel = m_sctGeoManager->alignLevel();
173 m_sctAlignLevelBarrel = m_sctGeoManager->alignLevelBarrel();
174 m_sctAlignLevelEndcaps = m_sctGeoManager->alignLevelEndcaps();
175 ATH_MSG_DEBUG("Retrieved SCT Global alignment level: "<<m_sctAlignLevel);
176 ATH_MSG_DEBUG("Retrieved SCT Barrel alignment level: "<<m_sctAlignLevelBarrel);
177 ATH_MSG_DEBUG("Retrieved SCT Endcap alignment level: "<<m_sctAlignLevelEndcaps);
178
179 if(m_sctAlignLevel == 0)
180 ATH_MSG_INFO(" Requested update of Level "<<m_sctAlignLevel<<" alignment constants for SCT");
181 else {
182 ATH_MSG_INFO(" Requested update of Level "<<m_sctAlignLevelBarrel<<" alignment constants for SCT Barrel");
183 ATH_MSG_INFO(" Requested update of Level "<<m_sctAlignLevelEndcaps<<" alignment constants for SCT Endcaps");
184 }
185
186 // check alignment level but don't stop on error
187 if(!checkSCTLevel()) {
188 ATH_MSG_FATAL(" SCT alignment level not given.");
189// return StatusCode::FAILURE;
190 }
191 }
192
193 // if we're here it means that we need at least one the two managers
196 ATH_MSG_FATAL( " No geometry manager available or alignment level not given. " );
197 // we don't want to stop if there's errors
198 // so we comment out the return statement
199// return StatusCode::FAILURE;
200 }
201 }
202
203 m_doSi = (m_siAlignLevel==0);
205 m_doSCT = (checkSCTLevel() && !m_doSi);
206
207 if (m_writeAsL3)
208 ATH_MSG_INFO(" Storing as level 3 constants.");
209
210 if (m_writeAsL16)
211 ATH_MSG_INFO(" Storing IBLDist as level 16 constants in separate DB");
212
213 if(!m_doPixel && !m_doSCT && !m_doSi) {
214 ATH_MSG_FATAL(" No geometry manager available or alignment level not given.");
215 ATH_MSG_FATAL(" DB not updated.");
216// return;
217 }
218 ATH_MSG_DEBUG("Made it till here..... "<<m_doSi<<" "<<m_doPixel<<" "<<m_doSCT);
219 ATH_MSG_DEBUG("update constants..... "<<m_updateConstants);
220 return StatusCode::SUCCESS;
221}
222
223//________________________________________________________________________
225{
226 ATH_MSG_DEBUG("finalize() of SiTrkAlignDBTool");
227
228 return StatusCode::SUCCESS;
229}
230
231//________________________________________________________________________
233{
235 return true;
236
237 if(!m_pixelaAlignDBM && m_pixelAlignLevel==11){// the new one with IBL (seems simplest solution)
238 m_writeAsL2 = true;
239 return true;
240 }
241
242 if(m_pixelaAlignDBM && (m_pixelAlignLevel==1 || m_pixelAlignLevel==2 )){// the new one with DBM (seems simplest solution)
243 m_writeAsL2 = true;
244 return true;
245 }
246
247 if(m_pixelaAlignDBM && m_pixelAlignLevel==3 ){// the new one with DBM (seems simplest solution)
248 return true;
249 }
250
251 if(!m_pixelaAlignDBM && m_pixelAlignLevel==16){// the new IBL bowing level
252 m_writeAsL16 = true;
253 // We need some fix here with respect to current CL implementation! There bowing is updated at L3!! (this would currently do both..)
254 return true;
255 }
256
257 if (m_writeAsL3)
258 return true;
259
261
262 bool ok = false;
263
265 case 11: case 12: case 15: case 16: case 2: case 22: case 26: case 27: case 3:
266 ok = true;
267 break;
268 default:
269 ATH_MSG_ERROR(" Storing of alignment constants for level "<<m_pixelAlignLevelBarrel<<" for Pixel Barrel is not implemented.");
271 ok = false;
272 break;
273 }
274
276 case 11: case 16: case 2: case 3: case 12:
277 ok = ok && true;
278 break;
279 default:
280 ATH_MSG_ERROR(" Storing of alignment constants for level "<<m_pixelAlignLevelEndcaps<<" for Pixel Endcaps is not implemented.");
282 ok = false;
283 break;
284 }
285
286 return ok;
287}
288
289//________________________________________________________________________
291{
292 if(m_sctAlignLevel==0)
293 return true;
294
295 if (m_writeAsL3)
296 return true;
297
298 m_sctAlignLevel = -1;
299
300 bool ok = false;
301
302 switch(m_sctAlignLevelBarrel) {
303 case 1: case 2: case 27: case 3:
304 ok = true;
305 break;
306 default:
307 ATH_MSG_ERROR(" Storing of alignment constants for level "<<m_sctAlignLevelBarrel<<" for SCT Barrel is not implemented.");
309 ok = false;
310 break;
311 }
312
313 switch(m_sctAlignLevelEndcaps) {
314 case 1: case 2: case 25: case 3:
315 ok = ok && true;
316 break;
317 default:
318 ATH_MSG_ERROR(" Storing of alignment constants for level "<<m_sctAlignLevelEndcaps<<" for SCT Endcaps is not implemented.");
320 ok = false;
321 break;
322 }
323
324 return ok;
325}
326
327//________________________________________________________________________
329{
330 if (m_writeAsL3)
331 return true;
332
333 switch(m_siAlignLevel) {
334 case 0:
335 case 1:
336 case 2:
337 case 3:
338 return true;
339
340 default:
341 return false;
342 }
343}
344
345//________________________________________________________________________
347{
348 ATH_MSG_DEBUG("in SiTrkAlignDBTool::writeAlignPar()");
349
350 // do we want to update the DB?
351 if(!m_updateConstants) {
352 ATH_MSG_INFO("Update of Silicon constants not requested!");
353 return;
354 }
355
356 // write initial alignment constants
358 ATH_MSG_INFO("Writing old Silicon alignment constants to file "<<m_oldAlignFile);
359 m_IDAlignDBTool->writeFile(false, m_oldAlignFile);
360 if(m_oldIBLDistFile!="") m_IDAlignDBTool->writeIBLDistFile(m_oldIBLDistFile);
361 m_IDAlignDBTool->writeGlobalFolderFile(m_oldGlobalFolderFile);
362 }
363
364 // now update the DB
365 updateDB();
366
367 // and write the final alignment constants
368 if(m_writeTextFile) {
369 ATH_MSG_INFO("Writing Silicon alignment constants to file "<<m_outputAlignFile);
370 m_IDAlignDBTool->writeFile(false, m_outputAlignFile);
371 if(m_outIBLDistFile!="") m_IDAlignDBTool->writeIBLDistFile(m_outIBLDistFile);
372 m_IDAlignDBTool->writeGlobalFolderFile(m_outGlobalFolderFile);
373 }
374
375 return;
376}
377
378//________________________________________________________________________
380{
381 ATH_MSG_DEBUG(" in SiTrkAlignDBTool::updateDB()");
382
383 Amg::Transform3D dbtransform;
384
385 ATH_MSG_INFO("-------------------------------------------------");
386 // updating level 1, level 2 or level 3 constants in the DB
387 if(m_doSi)
388 ATH_MSG_INFO("Updating Level "<<m_siAlignLevel<<" alignment constants for Silicon");
389
390 if(m_doPixel) {
391 if(m_pixelAlignLevel==1)
392 ATH_MSG_INFO("Updating Level "<<m_pixelAlignLevel<<" alignment constants for Pixel");
393 else {
394 ATH_MSG_INFO("Updating Level "<<m_pixelAlignLevelBarrel<<" alignment constants for Pixel Barrel");
395 ATH_MSG_INFO("Updating Level "<<m_pixelAlignLevelEndcaps<<" alignment constants for Pixel Endcaps");
396 }
397 }
398
399 if(m_doSCT) {
400 if(m_sctAlignLevel==0)
401 ATH_MSG_INFO("Updating Level "<<m_sctAlignLevel<<" alignment constants for SCT");
402 else {
403 ATH_MSG_INFO("Updating Level "<<m_sctAlignLevelBarrel<<" alignment constants for SCT Barrel");
404 ATH_MSG_INFO("Updating Level "<<m_sctAlignLevelEndcaps<<" alignment constants for SCT Endcaps");
405 }
406 }
407
408 if (m_writeAsL3)
409 ATH_MSG_INFO("Updating Level 3 constants.");
410
411 // loop over all AlignModules
412 std::vector<Trk::AlignModule *>::const_iterator imod = m_alignModuleTool->getAlignModuleCollection()->begin();
413 std::vector<Trk::AlignModule *>::const_iterator imod_end = m_alignModuleTool->getAlignModuleCollection()->end();
414 for( ; imod != imod_end; ++imod ) {
415
416 Trk::AlignModule * module = *imod;
417
418 ATH_MSG_DEBUG("-------------------------------------------------------");
419 ATH_MSG_DEBUG("Alignment corrections for module: "<<module->name());
420
421 // the the identifier of the module for the DB
422 Identifier modID = module->identify();
423
424 // The Si AlignModules of levels 0, 1, 2 and 3 use the Silicon Identifier.
425 if(!m_idHelper->is_pixel(modID) && !m_idHelper->is_sct(modID)) {
426 ATH_MSG_DEBUG("Module with ID: "<<modID<<" is not a Silicon module. Skipping.");
427 continue;
428 }
429
430 // get active alignment parameters for the module
431 DataVector<Trk::AlignPar> * alignPars = m_alignModuleTool->getAlignPars(module);
432 if(alignPars->size() == 0) {
433 ATH_MSG_INFO("Alignment constants for module "<<module->name()<<" not available.");
434 continue;
435 }
436
437 ATH_MSG_DEBUG("Retrieved alignment constants for module "<<module->name());
438 ATH_MSG_DEBUG("Module ID : "<<modID);
439 ATH_MSG_DEBUG("Expanded module ID : "<<m_idHelper->show_to_string(modID,nullptr,'/'));
440
441 // get final alignment parameters
442 DataVector<Trk::AlignPar> * fullAlignPars = m_alignModuleTool->getFullAlignPars(module);
443 double apTraX = fullAlignPars->at(Trk::AlignModule::TransX)->par();
444 double apTraY = fullAlignPars->at(Trk::AlignModule::TransY)->par();
445 double apTraZ = fullAlignPars->at(Trk::AlignModule::TransZ)->par();
446 double apRotX = fullAlignPars->at(Trk::AlignModule::RotX)->par();
447 double apRotY = fullAlignPars->at(Trk::AlignModule::RotY)->par();
448 double apRotZ = fullAlignPars->at(Trk::AlignModule::RotZ)->par();
449
450 // Need to make sure not to call SCT modules - only defined for PIX
451 double apBowX = 0;
452 // This should be sufficient as bowing-DoF is only enabled for IBL
453 if(m_idHelper->is_pixel(modID) && m_pixHelper->is_barrel(modID) ){
454 apBowX = fullAlignPars->at(Trk::AlignModule::BowX)->par();
455
456 // The last check ensures that it also updates for L11 in case bowing DoF is enables.
457 if(m_pixelAlignLevelBarrel==16 || m_writeAsL16 || apBowX!=0){
458 updateAsL16(module,apBowX);
459 // Can we get a baseline as well? include here in case it is possible!
460 // Allow other DoF to be updated as well!
461 // Initial CL (Oct. 2016) update at L3 --> commented for now
462 }
463 }
464
465 Amg::Translation3D translation( apTraX, apTraY, apTraZ );
466 Amg::Transform3D transform = translation * Amg::RotationMatrix3D::Identity();
467 transform *= Amg::AngleAxis3D(apRotZ, Amg::Vector3D(0.,0.,1.));
468 transform *= Amg::AngleAxis3D(apRotY, Amg::Vector3D(0.,1.,0.));
469 transform *= Amg::AngleAxis3D(apRotX, Amg::Vector3D(1.,0.,0.));
470
471
472 ATH_MSG_DEBUG(" - translation X = "<<apTraX);
473 ATH_MSG_DEBUG(" - translation Y = "<<apTraY);
474 ATH_MSG_DEBUG(" - translation Z = "<<apTraZ);
475 ATH_MSG_DEBUG(" - rotation X = "<<apRotX);
476 ATH_MSG_DEBUG(" - rotation Y = "<<apRotY);
477 ATH_MSG_DEBUG(" - rotation Z = "<<apRotZ);
478
479 int level=-1;
480
481 // this is really ugly and quite confusing !!!
482 // but will do for now...
483 if(m_idHelper->is_pixel(modID)) {
484 if(!m_doPixel && !m_doSi) {
485 ATH_MSG_INFO("--> Pixel module - NOT storing");
486 continue;
487 }
488 if(m_doPixel) {
490 level = m_pixelAlignLevel;
491 else if(m_pixHelper->is_barrel(modID))
493 else
495 }
496 else // this makes sure that Si L0 is handled since pixel identifier is used for it
497 level = m_siAlignLevel;
498 }
499 else if(m_idHelper->is_sct(modID)) {
500 if(!m_doSCT) {
501 ATH_MSG_INFO("--> SCT module - NOT storing");
502 continue;
503 }
504 if(m_sctAlignLevel==0)
505 level = m_sctAlignLevel;
506 else if(m_sctHelper->is_barrel(modID))
507 level = m_sctAlignLevelBarrel;
508 else
510 }
511 // to better understand what is going on
512 ATH_MSG_DEBUG("We are having level: "<<level);
513
514 if (m_writeAsL3) {
515 updateAsL3(module,transform,apBowX);
516 continue;
517 }
518
519 if (m_idHelper->is_pixel(modID) && m_writeAsL2) {
520 level=2;
521 updateAsL2(module,transform,level);
522 continue;
523 }
524
525 // calculate the DB transform
526 switch(level) {
527
528 case -1:
529 // level not recognized, do nothing
530 continue;
531
532 case 0:
533 updateSiL0asL1(modID,transform);
534 continue;
535
536 case 1: case 2: {
537 // for levels 1 and 2 the DB frame equals to the global frame but the align
538 // frame doesnot, so we have to apply an additional transform
539 Amg::Transform3D dbFrameToAlignFrame = module->globalFrameToAlignFrame();
540
541 ATH_MSG_DEBUG("DB to align");
542 printTransform(dbFrameToAlignFrame);
543
544 dbtransform = dbFrameToAlignFrame.inverse() * transform * dbFrameToAlignFrame;
545
546 ATH_MSG_DEBUG("DB transform");
547 printTransform(dbtransform);
548 break;
549 }
550
551 case 3:
552 // for level 3 alignment the DB frame and the align frame equals to the local frame
553 // so we don't apply any additional transform
554 dbtransform = transform;
555
556 ATH_MSG_DEBUG("DB transform");
557 printTransform(dbtransform);
558 break;
559
560 default:
561 // otherwise we split the AlignModule into level 3 modules
562 ATH_MSG_DEBUG("We are doing this one");
563 updateAsL3(module,transform,apBowX);
564 continue;
565 }
566
567 // tweak applies the transform onto already existing transform in the DB
568 if( m_IDAlignDBTool->tweakTrans(modID, level, dbtransform) )
569 ATH_MSG_INFO("Module \'"<<module->name()<<"\': Level "<<level<<" constants updated.");
570 else {
571 // set replaces the transform in the DB
572 ATH_MSG_DEBUG("Module \'"<<module->name()<<"\': Call to tweak failed. Constants probably don't exist yet. Use set instead.");
573 if( m_IDAlignDBTool->setTrans(modID, level, dbtransform) )
574 ATH_MSG_INFO("Module \'"<<module->name()<<"\': Level "<<level<<" constants updated.");
575 else
576 ATH_MSG_ERROR("Error setting level "<<level<<" constants for module "<<module->name());
577 }
578
579 }
580 ATH_MSG_INFO("-------------------------------------------------");
581
582}
583
584//________________________________________________________________________
586{
587 // splitting the whole Silicon into Pixel, SCT barrel and 2 SCT endcaps
588 // the id has to be equal to L1 Pixel ID for Silicon level 0 update
589 // or to SCT barrel L1 ID for SCT level 0 update
590 if( idL0 != m_pixHelper->wafer_id(0,0,0,0) && idL0 != m_sctHelper->wafer_id(0,0,0,0,0) ) {
591 ATH_MSG_ERROR("wrong identifier for L0 Silicon in updateSiL0asL1()");
592 return;
593 }
594
595 // for both L0 and L1 the global frame is equal to the DB frame
596 // for L0 it is also equal to align frame so no additional transform is needed
597
598 if(idL0 == m_pixHelper->wafer_id(0,0,0,0)) {
599 ATH_MSG_INFO("Splitting Silicon into L1 modules and updating in the DB");
600
601 // Pixel
602 Identifier idPixel = m_pixHelper->wafer_id(0,0,0,0);
603 ATH_MSG_INFO("Updating L1 constants for Pixel");
604 // tweak applies the transform onto already existing transform in the DB
605 if( m_IDAlignDBTool->tweakTrans(idPixel, 1, transform) )
606 ATH_MSG_INFO("Call to tweak OK. Constants updated.");
607 else {
608 // set replaces the transform in the DB
609 ATH_MSG_INFO("Call to tweak failed. Constants probably don't exist yet. Use set instead.");
610 if( !m_IDAlignDBTool->setTrans(idPixel, 1, transform) )
611 ATH_MSG_ERROR("Error setting constants.");
612 }
613 }
614 else
615 ATH_MSG_INFO("Splitting SCT into L1 modules and updating in the DB");
616
617 // SCT
618 std::vector<Identifier> ids;
619 ids.push_back(m_sctHelper->wafer_id(0,0,0,0,0)); // SCT barrel
620 ids.push_back(m_sctHelper->wafer_id(-2,0,0,0,0)); // SCT endcap A
621 ids.push_back(m_sctHelper->wafer_id(2,0,0,0,0)); // SCT endcap C
622
623 ATH_MSG_INFO("Updating L1 constants for SCT");
624 for(unsigned int i=0; i<ids.size(); ++i) {
625 // tweak applies the transform onto already existing transform in the DB
626 if( m_IDAlignDBTool->tweakTrans(ids[i], 1, transform) )
627 ATH_MSG_INFO("Module "<<i<<". - id "<<ids[i]<<": Call to tweak OK. Constants updated.");
628 else {
629 // set replaces the transform in the DB
630 ATH_MSG_INFO("Module "<<i<<". - id "<<ids[i]<<": Call to tweak failed. Constants probably don't exist yet. Use set instead.");
631 if( !m_IDAlignDBTool->setTrans(ids[i], 1, transform) )
632 ATH_MSG_ERROR("Error setting constants.");
633 }
634 }
635}
636
637//_________________________________________________________________________________________
638void SiTrkAlignDBTool::updateAsL3(const Trk::AlignModule * module, const Amg::Transform3D & transform, double /*apBowX*/)
639{
640 ATH_MSG_INFO("Updating constants for module "<<module->name()<<" as level 3 constants");
641
642 // store as level 3 constants
643 const int level = 3;
644
645 // transform from global frame to align frame
646 const Amg::Transform3D& globaltoalign = module->globalFrameToAlignFrame();
647
648 // same code pplies to both Pixel and SCT
649 for (unsigned int idet=0; idet<2; idet++) {
650
652
653 ATH_MSG_DEBUG("getting elements of type "<<det<<" from the module");
654
655 const std::vector<const Trk::TrkDetElementBase *> * elements = module->detElementCollection(det);
656
657 if( !elements ) {
658 ATH_MSG_DEBUG("no elements of type "<<det);
659 continue;
660 }
661
662 ATH_MSG_DEBUG("looping over "<<elements->size()<<" elements");
663
664 std::vector<const Trk::TrkDetElementBase*>::const_iterator ielem = elements->begin();
665 std::vector<const Trk::TrkDetElementBase*>::const_iterator ielem_end = elements->end();
666 for ( ; ielem != ielem_end; ++ielem) {
667 const InDetDD::SiDetectorElement * sielem = dynamic_cast<const InDetDD::SiDetectorElement *>(*ielem);
668 if (!sielem) {
669 ATH_MSG_WARNING("Should be Silicon detector element but is not. Skipping.");
670 continue;
671 }
672
673 Identifier elemID = sielem->identify();
674
675 // for the SCT the 0 side Identifier is used in the DB
676 if (m_idHelper->is_sct(elemID)) {
677 if (m_sctHelper->side(elemID) > 0)
678 continue;
679 }
680
681 ATH_MSG_DEBUG("-----------------------------------------------------");
682
683 ATH_MSG_DEBUG("ModuleID value: "<<elemID);
684 ATH_MSG_DEBUG("ModuleID: "<<m_idHelper->show_to_string(elemID,nullptr,'/'));
685
686 // this should work for both Pixel and SCT
687 // module transform is the transform between the db frame and global frame
688 Amg::Transform3D dbtoglobal = sielem->moduleTransform();
689 // ATH_MSG_DEBUG("DB to Global");
690 // printTransform(dbtoglobal);
691
692 // ATH_MSG_DEBUG("Global to Align");
693 // printTransform(globaltoalign);
694
695 // from DB frame to alignment frame transform
696 Amg::Transform3D dbtoalign = globaltoalign * dbtoglobal;
697 // ATH_MSG_DEBUG("DB to Align");
698 // printTransform(dbtoalign);
699
700 ATH_MSG_DEBUG("Alignment transform");
701 printTransform(transform);
702
703 // alignment transform in DB frame
704 Amg::Transform3D dbtransform = dbtoalign.inverse() * transform * dbtoalign;
705
706 // This should work as Bowing is in DB frame, i.e. local module frame
707 // This implementation is need in the CL as of Oct2015;
708 // For now, just comment for offline
720 ATH_MSG_DEBUG("DB transform");
721 printTransform(dbtransform);
722
723 // tweak applies the transform onto already existing transform in the DB
724 if( !(m_IDAlignDBTool->tweakTrans(elemID, level, dbtransform)) ) {
725 // set replaces the transform in the DB
726 if( !(m_IDAlignDBTool->setTrans(elemID, level, dbtransform)) )
727 ATH_MSG_ERROR("Error setting level "<<level<<" constants for element "<<elemID<<" in module "<<module->name());
728 }
729 } // end loop over detElements
730 ATH_MSG_DEBUG("-----------------------------------------------------");
731 } // end loop over Pixel and SCT
732}
733
734 //_________________________________________________________________________________________
735void SiTrkAlignDBTool::updateAsL2(const Trk::AlignModule * module, const Amg::Transform3D & transform, const int level)
736{
737 ATH_MSG_INFO("Updating constants for module "<<module->name()<<" as level 2 constants (new)");
738
739 // check the level we store in
740 ATH_MSG_INFO("DB aligning at level: "<<level);
741
743 const std::vector<const Trk::TrkDetElementBase *> * elements = module->detElementCollection(det);
744
745 if( !elements ) {
746 ATH_MSG_FATAL("no elements of type "<<det);
747 return;
748 }
749
750 ATH_MSG_DEBUG("looping over "<<elements->size()<<" elements");
751 std::vector<std::string> level_mods; // where we store the unique identifiers we want to update
752
753 std::vector<const Trk::TrkDetElementBase*>::const_iterator ielem = elements->begin();
754 std::vector<const Trk::TrkDetElementBase*>::const_iterator ielem_end = elements->end();
755 for ( ; ielem != ielem_end; ++ielem) {
756 const InDetDD::SiDetectorElement * sielem = dynamic_cast<const InDetDD::SiDetectorElement *>(*ielem);
757 if (!sielem) {
758 ATH_MSG_WARNING("Should be Silicon detector element but is not. Skipping.");
759 continue;
760 }
761
762 Identifier elemID = sielem->identify();
763 Identifier level_mod = GetL1L2fromL3Identifier(elemID,level);
764 std::string key = m_IDAlignDBTool->dirkey(level_mod,level+1);
765
766 ATH_MSG_DEBUG("TESTING value: "<<level_mod);
767 ATH_MSG_DEBUG("TESTING ID: "<<m_idHelper->show_to_string(level_mod,nullptr,'/'));
768 ATH_MSG_DEBUG("TESTING retrieved key: "<<key);
769 std::vector<std::string>::const_iterator ix = find(level_mods.begin(),level_mods.end(),key); // check whether it is unique
770 if (ix==level_mods.end()) {
771 level_mods.push_back(key);
772
773 ATH_MSG_DEBUG("-----------------------------------------------------");
774
775 ATH_MSG_DEBUG("ModuleID value: "<<level_mod);
776 ATH_MSG_DEBUG("ModuleID: "<<m_idHelper->show_to_string(level_mod,nullptr,'/'));
777
778 // for levels 1 and 2 the DB frame equals to the global frame but the align
779 // frame doesnot, so we have to apply an additional transform
780 const Amg::Transform3D& dbFrameToAlignFrame = module->globalFrameToAlignFrame();
781
782 ATH_MSG_DEBUG("DB to align");
783 printTransform(dbFrameToAlignFrame);
784
785 Amg::Transform3D dbtransform = dbFrameToAlignFrame.inverse() * transform * dbFrameToAlignFrame;
786
787 ATH_MSG_DEBUG("DB transform");
788 printTransform(dbtransform);
789
790
791 // tweak applies the transform onto already existing transform in the DB
792 if( !(m_IDAlignDBTool->tweakTrans(level_mod, level, dbtransform)) ) {
793 // set replaces the transform in the DB
794 if( !(m_IDAlignDBTool->setTrans(level_mod, level, dbtransform)) )
795 ATH_MSG_ERROR("Error setting level "<<level<<" constants for element "<<level_mod<<" in module "<<module->name());
796 }
797 }
798 else {
799 ATH_MSG_DEBUG("Skipping ModuleID: "<<m_idHelper->show_to_string(elemID,nullptr,'/')<<" --> not unique");
800 }
801 } // end loop over detElements
802}
803
804
805//_________________________________________________________________________________________
806void SiTrkAlignDBTool::updateAsL16(const Trk::AlignModule * module, double bowx)
807{
808 ATH_MSG_INFO("Updating constants for module "<<module->name()<<" as level 16 IBLDist constants (new)");
809
811 const std::vector<const Trk::TrkDetElementBase *> * elements = module->detElementCollection(det);
812
813 if( !elements ) {
814 ATH_MSG_FATAL("no elements of type "<<det);
815 return;
816 }
817
818 ATH_MSG_DEBUG("looping over "<<elements->size()<<" elements");
819 std::vector<int> stave_phis; // where we store the unique identifiers we want to update
820 std::vector<const Trk::TrkDetElementBase*>::const_iterator ielem = elements->begin();
821 std::vector<const Trk::TrkDetElementBase*>::const_iterator ielem_end = elements->end();
822 for ( ; ielem != ielem_end; ++ielem) {
823 const InDetDD::SiDetectorElement * sielem = dynamic_cast<const InDetDD::SiDetectorElement *>(*ielem);
824 if (!sielem) {
825 ATH_MSG_WARNING("Should be Silicon detector element but is not. Skipping.");
826 continue;
827 }
828
829 Identifier elemID = sielem->identify();
830 const int this_stave_phi = m_pixHelper->phi_module( elemID );
831
832 ATH_MSG_DEBUG("module ID: "<<m_idHelper->show_to_string(elemID,nullptr,'/'));
833 ATH_MSG_DEBUG("phi identifier: "<<m_pixHelper->phi_module( elemID )) ;
834
835 std::vector<int>::const_iterator ix = find(stave_phis.begin(),stave_phis.end(),this_stave_phi); // check whether it is unique
836 if (ix==stave_phis.end()) {
837 stave_phis.push_back(this_stave_phi);
838
839 // tweak applies the transform onto already existing transform in the DB
840 if( !(m_IDAlignDBTool->tweakIBLDist(this_stave_phi,bowx)) ) {
841 ATH_MSG_ERROR("Error tweaking IBLDist DB for stave "<<this_stave_phi);
842 }
843 }
844 else {
845 ATH_MSG_DEBUG("Skipping ModuleID: "<<m_idHelper->show_to_string(elemID,nullptr,'/')<<" --> not unique");
846 }
847
848 } // end loop over detElements
849}
850
851
852//_________________________________________________________________________________________
854 {
855 ATH_MSG_DEBUG(" - translation: "<<tr.translation().x()<<" "<<tr.translation().y()<<" "<<tr.translation().z());
856 ATH_MSG_DEBUG(" - rotation:");
857 ATH_MSG_DEBUG(" "<<tr(0,0)<<" "<<tr(0,1)<<" "<<tr(0,2));
858 ATH_MSG_DEBUG(" "<<tr(1,0)<<" "<<tr(1,1)<<" "<<tr(1,2));
859 ATH_MSG_DEBUG(" "<<tr(2,0)<<" "<<tr(2,1)<<" "<<tr(2,2));
860 return;
861 }
862
863//_________________________________________________________________________________________
866 if( level == 3 ) return ident ;
868 if( m_pixHelper->is_pixel(ident) ) {
869 if( level == 1 ) {
870 return m_pixHelper->wafer_id( 0, 0, 0, 0 ) ;
871 }
872 if( level == 2 ) {
873 int barrel_ec = m_pixHelper->barrel_ec( ident ) ;
874 int layer_disk = m_pixHelper->layer_disk( ident ) ;
875 int phi_sector = m_pixHelper->phi_module( ident ) ;
876 if (abs(barrel_ec)==4) return m_pixHelper->wafer_id( barrel_ec, layer_disk, phi_sector, 0 ) ;
877 else return m_pixHelper->wafer_id( barrel_ec, layer_disk, 0, 0 ) ;
878 }
879 }
881 if( m_sctHelper->is_sct(ident) ) {
882 if( level == 1 ) {
883 int barrel_ec = m_sctHelper->barrel_ec( ident ) ;
884 return m_sctHelper->wafer_id( barrel_ec, 0, 0, 0, 0 ) ;
885 }
886 if( level == 2 ) {
887 int barrel_ec = m_sctHelper->barrel_ec( ident ) ;
888 int layer_disk = m_sctHelper->layer_disk( ident ) ;
889 return m_sctHelper->wafer_id( barrel_ec, layer_disk, 0, 0, 0 ) ;
890 }
891 }
892 return ident ;
893}
894
895
896
897
898} // end namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
An STL vector of pointers that by default owns its pointed-to elements.
Basic time unit for IOVSvc.
This is an Identifier helper class for the Pixel subdetector.
This is an Identifier helper class for the SCT subdetector.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Derived DataVector<T>.
Definition DataVector.h:795
const T * at(size_type n) const
Access an element, as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
Class to hold geometrical description of a silicon detector element.
const Amg::Transform3D & moduleTransform() const
Module to global frame transform.
virtual Identifier identify() const override final
identifier of this detector element (inline)
const PixelID * m_pixHelper
pointer to PIX detector manager
std::string m_oldGlobalFolderFile
filename for the textfile with initial GlobalFolder constants
ToolHandle< Trk::IGeometryManagerTool > m_pixelGeoManager
ToolHandle< Trk::IAlignModuleTool > m_alignModuleTool
void updateAsL16(const Trk::AlignModule *module, double)
ToolHandle< Trk::IGeometryManagerTool > m_sctGeoManager
std::string m_outGlobalFolderFile
filename for the textfile with final GlobalFolder constants
virtual ~SiTrkAlignDBTool()
destructor
std::string m_outIBLDistFile
filename for the textfile with final IBLDist params
std::string m_SQLiteTag
tag name for the ConditionsDB
const AtlasDetectorID * m_idHelper
bool m_writeTextFile
flag whether to write out the final constants into text file
virtual StatusCode initialize()
initialize method
bool m_writeSQLFile
flag wether to write out .db file or not (file is not needed in parallel jobs)
void printTransform(const Amg::Transform3D &tr) const
virtual Identifier GetL1L2fromL3Identifier(const Identifier &ident, const int &level) const
convert L3 module identifier to L1 or L2
void updateDB()
updates alignment constants in the DB
const SCT_ID * m_sctHelper
pointer to SCT detector manager
bool m_updateConstants
flag whether to update the constants
void updateAsL3(const Trk::AlignModule *module, const Amg::Transform3D &transform, double)
ToolHandle< IInDetAlignDBTool > m_IDAlignDBTool
void updateAsL2(const Trk::AlignModule *module, const Amg::Transform3D &transform, const int)
virtual StatusCode finalize()
finalize method
ToolHandle< Trk::IGeometryManagerTool > m_siGeoManager
bool m_writeOldConstants
flag whether to write out the initial constants into text file
void writeAlignPar()
Writes alignment parameters.
std::string m_oldIBLDistFile
filename for the textfile with initial IBLDist params
void updateSiL0asL1(Identifier idL0, const Amg::Transform3D &transform)
std::string m_outputAlignFile
filename for the textfile with final alignment constants
std::string m_oldAlignFile
filename for the textfile with initial alignment constants
SiTrkAlignDBTool(const std::string &type, const std::string &name, const IInterface *parent)
constructor
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
Eigen::AngleAxisd AngleAxis3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
Primary Vertex Finder.