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