ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_AlignDbSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
9
10#include "TRT_AlignDbSvc.h"
11
12
13
17
22
24
25// Amg
30#include <fstream>
31#include <iostream>
32#include <sstream>
33
34ATLAS_NO_CHECK_FILE_THREAD_SAFETY; // This class uses const_cast and regFcn (callback). Legacy code
35
36TRT_AlignDbSvc::TRT_AlignDbSvc( const std::string& name, ISvcLocator* pSvcLocator )
37 : base_class(name,pSvcLocator),
38 m_detStore("DetectorStore",name),
39 m_trtStrawAlignDbSvc("TRT_StrawAlignDbSvc",name),
40 m_trtid(nullptr),
41 m_trtman(nullptr),
42 m_alignroot("/TRT/Align"),
43 m_alignString("AL"),
45 m_streamer("AthenaOutputStreamTool/CondStream1"),
46 m_alignDBprefix("/TRT/Align/"),
47 m_dynamicDB(false),
49{
50 declareProperty("StreamTool",m_streamer);
51 declareProperty("alignroot",m_alignroot);
52 declareProperty("alignTextFile",m_par_alitextfile);
53 declareProperty("DetectorStore",m_detStore);
54 declareProperty("TrtStrawAlignDbSvc", m_trtStrawAlignDbSvc,"Service for interaction with the TRT straw alignment DB");
55 declareProperty("alignString",m_alignString);
56 declareProperty("alignDBprefix",m_alignDBprefix);
57 declareProperty("forceUserDBConfig",m_forceUserDBConfig, "Set to true to override any DB auto-configuration");
58}
59
60//-------------------------------------------------------------------------
61
64
65//
66//-----------------------------------------------------------------------------
68{
69 ATH_MSG_INFO( " in initialize " );
70
71 ATH_CHECK( m_detStore.retrieve() );
72 ATH_CHECK (m_trtStrawAlignDbSvc.retrieve() );
73 ATH_MSG_INFO ("retrieved " << m_trtStrawAlignDbSvc);
74
75 // Get the geometry.
77 ATH_CHECK (m_detStore->retrieve(m_trtman,"TRT") );
78
79 // Get TRT manager and ID helper
80 itermin=m_trtman->getDetectorElementBegin();
81 itermax=m_trtman->getDetectorElementEnd();
82 ATH_CHECK( m_detStore->retrieve(m_trtid,"TRT_ID") );
83 ATH_MSG_INFO( "found all TRT services " );
84
85 if (m_trtman->m_alignfoldertype == InDetDD::timedependent_run2 && !m_forceUserDBConfig){
86 m_dynamicDB = true;
87 m_alignroot = "/TRT/AlignL2";
88 m_alignDBprefix = "/TRT/AlignL2/";
89 }
90 if (m_trtman->m_alignfoldertype == InDetDD::static_run1 && !m_forceUserDBConfig){
91 m_dynamicDB = false;
92 m_alignroot = "/TRT/Align";
93 m_alignDBprefix = "/TRT/Align/";
94 }
95
96
97 // setup list of TDS objects from geometry description
98 m_alignobjs.clear();
99 m_alignchans.clear();
100
101 // Include a level 1 alignment
102 int ichan(0) ;
103 if (!m_dynamicDB){
104 m_alignobjs.emplace_back("/TRT/Align/TRT");
105 ATH_MSG_INFO( "Adding key: /TRT/Align/TRT --> We are using static DB folder scheme" );
106 m_alignchans.push_back(ichan++);
107 }
108
109 //Check all detector elements in the present geometry setup
110 for (iter=itermin;iter!=itermax;++iter) {
111 const InDetDD::TRT_BaseElement* element=*iter;
112 if (element!=nullptr) {
113 const Identifier ident=element->identify();
114 if (m_trtid->is_trt(ident)) { //OK this Element is included
115 std::string key = findkey(ident,m_alignString);
116 std::vector<std::string>::const_iterator ix = find(m_alignobjs.begin(),m_alignobjs.end(),key);
117 if (ix==m_alignobjs.end()) {
118 m_alignobjs.push_back(key);
119 ATH_MSG_INFO( "Adding key: " << key );
120 m_alignchans.push_back(ichan++);
121 }
122 }
123 }
124 }
125
129
133 bool alignFolderExists = m_detStore->contains<AlignableTransformContainer>(m_alignroot) ;
134 if (m_dynamicDB) alignFolderExists = ( alignFolderExists && m_detStore->contains<CondAttrListCollection>("/TRT/AlignL1/TRT"));
135
138 bool alignTextFileExists = !m_par_alitextfile.empty();
139
140 if( alignFolderExists ) {
141
143// ATH_CHECK( m_detStore->regFcn(&TRT_AlignDbSvc::IOVCallBack,this,m_aligncontainerhandle,m_alignroot) );
144
146 if( alignTextFileExists )
147 ATH_MSG_INFO( "AlignableTransformContainer with name " << m_alignroot
148 << " exists. Will read text file from callback function." );
149
150 } else if ( alignTextFileExists ) {
151
153 ATH_CHECK( this->createAlignObjects() );
154
157
158 } else {
159 ATH_MSG_ERROR( "AlignableTransformContainer not in IOV service and no textfile specified." );
160 }
161
162 ATH_MSG_DEBUG ("The TRT/Align keys and channels are:");
163 for (unsigned int i=0;i<m_alignobjs.size();++i)
164 ATH_MSG_DEBUG (" key " << m_alignobjs[i] << " chan " << m_alignchans[i]);
165
166 return StatusCode::SUCCESS;
167}
168//
169//-----------------------------------------------------------------------------
170
172{
173 ATH_MSG_INFO( "TRT_AlignDbSvc finalize method called" );
174 for(std::vector<Amg::Transform3D*>::iterator it = m_amgTransformCache.begin(); it != m_amgTransformCache.end(); ++it){
175 delete *it;
176 }
177 return StatusCode::SUCCESS;
178}
179
182{
183 ATH_MSG_DEBUG( "In IOVCallBack" );
184
193
196// for (std::list<std::string>::const_iterator itr=keys.begin(); itr!=keys.end(); ++itr)
197// ATH_MSG_INFO( "IOVCALLBACK for key " << *itr<< " number " << I );
198
199
200 if(!m_par_alitextfile.empty()){
202 }else{
203 ATH_MSG_INFO( "Text file " << m_par_alitextfile << " is empty" );
204 }
205
209
210 ATH_MSG_DEBUG( "Leaving IOVCallBack" );
211 return StatusCode::SUCCESS;
212}
213
215StatusCode TRT_AlignDbSvc::writeAlignTextFile(const std::string &file) const
216{
217 ATH_MSG_DEBUG(" in writeAlignTextFile ");
218 ATH_MSG_INFO( " Write AlignableTransforms to text file: "<< file );
219 std::ofstream outfile(file);
220
221 int ntrans=0;
222 int nobj=0;
223
225 std::vector<std::string>::const_iterator iobj=m_alignobjs.begin();
226 std::vector<std::string>::const_iterator iobjE=m_alignobjs.end();
227 for (;iobj!=iobjE; ++iobj) {
228 const AlignableTransform* pat=cgetTransPtr(*iobj);
229 std::string key=*iobj;
230
232 if(isOldKey(key) && m_alignString != "ALold")
233 continue;
234
236 if (!pat){
237 ATH_MSG_ERROR( "Cannot find AlignableTransform for key "<< key );
238 ATH_MSG_ERROR( "Skipping it. " );
239 outfile << key << std::endl;
240 continue;
241 }
242
243 // first record is the name
244 ATH_MSG_INFO( " Write folder: " << key );
245 outfile << key << std::endl;
246 ++nobj;
247
248 // loop over all transforms in the AlignableTransform object
251 for (;cit!=citE;++cit) {
252
253 int bec(0);
254 int layer(0);
255 int sector(0);
256 int strawLayer(0);
257
259 ++ntrans;
260
262 const Identifier& ident=cit->identify();
263 bec=m_trtid->barrel_ec(ident);
264 layer=m_trtid->layer_or_wheel(ident);
265 sector=m_trtid->phi_module(ident);
266 strawLayer=m_trtid->straw_layer(ident);
267
269 const Amg::Transform3D& trans = Amg::CLHEPTransformToEigen(cit->transform());
270
271 if(msgLvl(MSG::DEBUG)){
272 std::string thisMess = key+" for "+file;
273 printTransform(thisMess,trans);
274 }
275
276
277 HepGeom::Transform3D transCLHEP = Amg::EigenTransformToCLHEP(trans);
278 CLHEP::HepRotation rot=transCLHEP.getRotation();
279 Amg::Vector3D eulerangles;
280 eulerangles[0] = rot.getPhi();
281 eulerangles[1] = rot.getTheta();
282 eulerangles[2] = rot.getPsi();
283
284 Amg::Vector3D shift=trans.translation();
285 //Matthias: was initially 2,1,2 --> this should be equivalent to complicated method above
286 //Amg::Vector3D eulerangles = trans.rotation().eulerAngles(2,0,2) ;
287
288 if(key == (m_alignDBprefix+"L2A") || key == (m_alignDBprefix+"L2C") ){
289
290 ATH_MSG_INFO( " Write member: "
291 << ident << " " << bec << " " << layer << " " << strawLayer << " " << key );
292
293 outfile << bec << " " << layer << " " << strawLayer << " "
294 << std::setprecision(10) << " "
295 << shift.x() << " " << shift.y() << " " << shift.z() << " "
296 << eulerangles[0] << " " << eulerangles[1] << " " << eulerangles[2]
297 << std::endl;
298
299 ATH_MSG_DEBUG( "Writing transform to log file " );
300 ATH_MSG_DEBUG( bec << " " << layer << " " << strawLayer << " "
301 << std::setprecision(10) << " "
302 << shift.x() << " " << shift.y() << " " << shift.z() << " "
303 << eulerangles[0] << " " << eulerangles[1] << " " << eulerangles[2]
304 );
305
306 }else{
307 //Need to validate this for writing out L1 Endcap alignments
308 ATH_MSG_INFO( " Write member: "
309 << ident << " " << bec << " " << layer << " " << sector << " " << key );
310
311 outfile << bec << " " << layer << " " << sector << " "
312 << std::setprecision(10) << " "
313 << shift.x() << " " << shift.y() << " " << shift.z() << " "
314 << eulerangles[0] << " " << eulerangles[1] << " " << eulerangles[2]
315 << std::endl;
316
317 ATH_MSG_DEBUG( "Writing transform to log file " );
318 ATH_MSG_DEBUG( bec << " " << layer << " " << sector << " "
319 << std::setprecision(10) << " "
320 << shift.x() << " " << shift.y() << " " << shift.z() << " "
321 << eulerangles[0] << " " << eulerangles[1] << " " << eulerangles[2]
322 );
323 }
324
325 }
326 }
327
328 outfile.close();
329
330 ATH_MSG_INFO( "Written " << nobj << " AlignableTransform objects" << " with " << ntrans
331 << " transforms to text file" );
332
333 ATH_MSG_DEBUG( " leaving writeAlignTextFile " );
334 return StatusCode::SUCCESS;
335}
336
337StatusCode TRT_AlignDbSvc::writeStrawAlignTextFile(const std::string & file) const
338{
339 ATH_MSG_DEBUG( " in writeAlignTextFile " );
340
341 ATH_MSG_INFO( "Writing the straw alignments " );
342 if( m_trtStrawAlignDbSvc -> writeTextFile(file) != StatusCode::SUCCESS )
343 ATH_MSG_ERROR("Cannot write to file "<< file );
344
345 return StatusCode::SUCCESS;
346}
347
349StatusCode TRT_AlignDbSvc::readAlignTextFile(const std::string & file) {
350 ATH_MSG_DEBUG( " In readAlignTextFile " );
351 ATH_MSG_INFO( "Read alignment constants from text file: " << file );
352 std::ifstream infile;
353 infile.open(file.c_str());
354
359 if(container) {
361
364 for(;it!=itE;++it)
365 // there is no 'clear' function in alignable transform, so we do it with this hack
366 **it = AlignableTransform( (*it)->tag() ) ;
367 } else {
368 return StatusCode::FAILURE ;
369 }
370
371 // loop over file
372 int nobj=0;
373 int ntrans=0;
374 std::string atname;
375 AlignableTransform* pat(nullptr) ;
376 char line[512] ;
377
378 while( infile.getline(line,512) ) {
379 if(line[0] != '#') {
380
381 std::string linestring(line) ;
382 if( linestring.find('/') != std::string::npos) {
383 // this must be a line with a container name
384 atname = linestring ;
385 ATH_MSG_INFO( "now reading container: " << atname );
386 pat=getTransPtr(atname);
387 if (!pat) {
388 ATH_MSG_ERROR( "Cannot find AlignableTransform object for key " << atname );
389 return StatusCode::FAILURE;
390 } else {
391 nobj++;
392 }
393 } else if(pat!=nullptr) {
394 // this must be a line with constants
395 std::istringstream is(line) ;
396
397 int bec(0),layer(0),sector(0),strawLayer(0);
398 double dx,dy,dz,phi,theta,psi;
399
400 if(atname == (m_alignDBprefix+"L2A") || atname == (m_alignDBprefix+"L2C") ){
401 if( is >> bec >> layer >> strawLayer >> dx >> dy >> dz >> phi ) {
402 CLHEP::Hep3Vector translation(dx, dy, dz);
403 CLHEP::HepRotation rotation;
404 if (is >> theta >> psi) {
405 ATH_MSG_DEBUG ("read a line with euler angles!" << phi
406 << " " << theta << " " << psi);
407 rotation.set(phi, theta, psi);
408 }
409 //We have to give a phi sector, so we'll give 0.
410 Identifier ident=m_trtid->layer_id(bec,0,layer,strawLayer);
411 ATH_MSG_DEBUG( "The identifier is for bec " << bec
412 << " layer " << layer << " strawLayer " << strawLayer );
413 ATH_MSG_DEBUG( "The code is " << m_trtid->show_to_string(ident) );
414 if( pat->findIdent(ident)!=pat->end() ) {
415 ATH_MSG_WARNING ("WARNING: read module from file which was already in AlignableTransform. Will skip it."
416 << " bec,lay,sec,strawlay = " << bec << " " << layer << " " << sector << " " );
417 } else {
418 pat->add(ident,HepGeom::Transform3D(rotation, translation));
419 HepGeom::Transform3D testtrans = HepGeom::Transform3D(rotation, translation);
420 if(msgLvl(MSG::DEBUG)){
421 std::string thisMess = atname+" for "+file;
422 printTransform(thisMess,Amg::CLHEPTransformToEigen(testtrans));
423 }
424
425
426 ++ntrans;
427 ATH_MSG_DEBUG( "Set transform: "
428 << " [" << bec << "," << layer << "," << strawLayer
429 << "] key " << atname
430 << " rotation=(" << phi << "," << theta << "," << psi
431 << "), translation=(" << dx << "," << dy << "," << dz << "])"
432 );
433 }
434 } else if(!linestring.empty()) {
435 ATH_MSG_WARNING( "Read invalid line from textfile. Line=\'" << line << "\'" );
436 }
437 }//if endcap
438 else{
439 if( is >> bec >> layer >> sector >> dx >> dy >> dz >> phi ) {
440 CLHEP::Hep3Vector translation(dx,dy,dz) ;
441 CLHEP::HepRotation rotation;
442 if( is >> theta >> psi ) {
443 ATH_MSG_DEBUG( "read a line with euler angles!" << phi << " " << theta << " " << psi );
444 rotation.set(phi,theta,psi) ;
445
446 } else {
447 ATH_MSG_DEBUG( "read a line with angle in phi!" << phi );
448 rotation = CLHEP::HepRotationZ(phi) ;
449 }
450
451 Identifier ident=m_trtid->module_id(bec,sector,layer);
452 if( pat->findIdent(ident)!=pat->end() ) {
453 ATH_MSG_WARNING ("WARNING: read module from file which was already in AlignableTransform. Will skip it."
454 << " bec,lay,sec = " << bec << " " << layer << " " << sector);
455 } else {
456 pat->add(ident,HepGeom::Transform3D(rotation, translation));
457 ++ntrans ;
458 ATH_MSG_DEBUG( "Set transform: "
459 << " [" << bec << "," << layer << "," << sector
460 << "] key " << atname << " rotation=(" << phi << "," << theta << "," << psi
461 << "), translation=(" << dx << "," << dy << "," << dz << "])" );
462 }
463 } else if(!linestring.empty()) {
464 ATH_MSG_WARNING( "Read invalid line from textfile. Line=\'" << line << "\'" );
465 }
466 }//if not the endcap
467
468
469 }//if pat!=0
470 }//if line != "#"
471 }//while
472
473 infile.close() ;
474 ATH_MSG_INFO( "Read " << nobj << " objects from file with " << ntrans << " transforms."
475 << " Now forcing callback in detector manager." );
476
478 if((const_cast<InDetDD::TRT_DetectorManager*>(m_trtman))->align().isFailure()){
479 ATH_MSG_ERROR("Failed to force the alignment callback!" );
480 }
481
482 ATH_MSG_DEBUG( " Leaving readAlignTextFile " );
483 return StatusCode::SUCCESS;
484}
485
488 ATH_MSG_DEBUG( "In streamOutAlignObjects " );
489
490 // Get Output Stream tool for writing
491 ATH_CHECK( m_streamer.retrieve() );
492
493 IAthenaOutputStreamTool* streamer=const_cast<IAthenaOutputStreamTool*>(&(*m_streamer));
494
495 ATH_CHECK( streamer->connectOutput() );
496
498 IAthenaOutputStreamTool::TypeKeyPair arraypair("AlignableTransformContainer",m_alignroot);
499 typeKeys.push_back(arraypair);
501
502 ATH_CHECK( streamer->streamObjects(typeKeys) );
503 ATH_CHECK( streamer->commitOutput() );
504
505 ATH_MSG_INFO( " Streamed out and committed AlignableTransformContainer" );
507
508 ATH_MSG_DEBUG( "Leaving streamOutAlignObjects " );
509 return StatusCode::SUCCESS;
510}
511
513StatusCode TRT_AlignDbSvc::registerAlignObjects(const std::string & tag, int run1, int event1, int run2, int event2) const{
514
515 ATH_MSG_INFO( "registerAlignObjects with IOV " );
516 ATH_MSG_INFO( "Run/evt1 [" << run1 << "," << event1 << "]" );
517 ATH_MSG_INFO( "Run/evt2 [" << run2 << "," << event2 << "]" );
518
519 // get pointer to registration svc
520 SmartIF<IIOVRegistrationSvc> regsvc(service("IOVRegistrationSvc"));
521 ATH_CHECK( regsvc.isValid() );
522
523 if (StatusCode::SUCCESS==regsvc->registerIOV("AlignableTransformContainer",m_alignroot,tag,run1,run2,event1,event2)){
524 ATH_MSG_INFO( " Register AlignableTransformContainer object "
525 << m_alignroot );
526 } else {
527 ATH_MSG_ERROR( " Failed to register AlignableTranformContainer "
528 << m_alignroot );
529 return StatusCode::FAILURE;
530 }
531
532 return StatusCode::SUCCESS;
533}
534
536const Amg::Transform3D TRT_AlignDbSvc::getAlignmentTransform(const Identifier& ident, unsigned int level) const {
537 ATH_MSG_DEBUG( "In getAlignmentTransform" );
538
539 if(level != 1 && level != 2){
540 ATH_MSG_ERROR( "Call to trans wrong!" );
541 ATH_MSG_ERROR( "Level must be 1 or 2!" );
542 ATH_MSG_ERROR( "Returning NULL" );
543 return Amg::Transform3D();
544 }
545
546 return (level == 1) ? getAlignmentTransformL1(ident) : getAlignmentTransformL2(ident);
547}
548
551 ATH_MSG_DEBUG( "In getAlignmentTransformL1" );
552 // return level 1 AlignableTransform for the TRT subdetector bec (+-1,+-2)
553 // or return null transform.
554
555 std::string key="/TRT/Align/TRT";
556 const AlignableTransform* pat=cgetTransPtr(key);
557 if (!pat) return Amg::Transform3D();
558
559 // get Amg::Transform3d via AlignTransMember
560 AlignableTransform::AlignTransMem_citr itr = pat->findIdent(ident);
561 return ( itr!=pat->end() ? Amg::CLHEPTransformToEigen(itr->transform()) : Amg::Transform3D() );
562}
563
566 ATH_MSG_DEBUG( "In getAlignmentTransformL2" );
567 // return level 2 AlignableTransform for the module containing ident
568 // or return null transform.
569
570 std::string key=findkey(ident,m_alignString);
571 //does a key exist corresponding to this identifier?
572
573 const AlignableTransform* pat=cgetTransPtr(key);
574 if (!pat) return Amg::Transform3D();
575
576 // OK it exists
577 // get "module identifier" from identifier
578 int bec=m_trtid->barrel_ec(ident);
579 int layer=m_trtid->layer_or_wheel(ident);
580 int sector=m_trtid->phi_module(ident);
581 int strawLayer=m_trtid->straw_layer(ident);
582 int ring = getRingForStrawLayer(strawLayer);
583
584 Identifier mid;
585 if(key == (m_alignDBprefix+"L2A") || key == (m_alignDBprefix+"L2C") )
586 mid=m_trtid->layer_id(bec,0,layer,ring);
587 else
588 mid=m_trtid->module_id(bec,sector,layer);
589
590 // get Amg::Transform3d via AlignTransMember
591 AlignableTransform::AlignTransMem_citr itr = pat->findIdent(mid);
592 return ( itr!=pat->end() ? Amg::CLHEPTransformToEigen(itr->transform()) : Amg::Transform3D() );
593}
594
596const Amg::Transform3D* TRT_AlignDbSvc::getAlignmentTransformPtr(const Identifier& ident, unsigned int level) const {
597 ATH_MSG_DEBUG( "In getAlignmentTransformPtr" );
598
599 if(level != 1 && level != 2){
600 ATH_MSG_ERROR( "Call to trans wrong!" );
601 ATH_MSG_ERROR( "Level must be 1 or 2!" );
602 ATH_MSG_ERROR( "Returning NULL" );
603 return nullptr;
604 }
605
606 return (level == 1) ? getAlignmentTransformL1Ptr(ident) : getAlignmentTransformL2Ptr(ident);
607}
608
611 ATH_MSG_DEBUG( "In getAlignmentTransformL1Ptr" );
612 // get level 1 (despite name, will change soon) AlignableTransform for the subdetector containing ident
613 const Amg::Transform3D* rc(nullptr) ;
614 if( m_trtid->is_trt(ident) ) {
615 const AlignableTransform* pat = cgetTransPtr( "/TRT/Align/TRT" ) ;
616 if( pat ) {
617 int bec=m_trtid->barrel_ec(ident);
618 Identifier mid=m_trtid->module_id(bec,0,0);
619 AlignableTransform::AlignTransMem_citr iter = pat->findIdent(mid) ;
620 if(iter != pat->end() ) {
621 Amg::Transform3D* amgTransform = new Amg::Transform3D((Amg::CLHEPTransformToEigen(iter->transform())));
622 m_amgTransformCache.push_back(amgTransform);
623 rc = amgTransform;
624 }
625 }
626 }
627
628 ATH_MSG_DEBUG( "Leaving getAlignmentTransformL1Ptr" );
629 return rc ;
630}
631
634 ATH_MSG_DEBUG( "In getAlignmentTransformL2Ptr" );
635 // set level 2 (despite name, will change soon) AlignableTransform for the module containing ident
636 // or add a new one.
637 const Amg::Transform3D* rc(nullptr) ;
638 //does a folder exist corresponding to this identifier?
639 if( m_trtid->is_trt(ident) ) {
640 std::string key=findkey(ident,m_alignString);
641 const AlignableTransform* pat=cgetTransPtr(key);
642 if(pat) {
643 // make sure the identifier is a "module identifier"
644 int bec=m_trtid->barrel_ec(ident);
645 int layer=m_trtid->layer_or_wheel(ident);
646 int sector=m_trtid->phi_module(ident);
647 int strawLayer=m_trtid->straw_layer(ident);
648 int ring = getRingForStrawLayer(strawLayer);
649 Identifier mid;
650 if(key == (m_alignDBprefix+"L2A") || key == (m_alignDBprefix+"L2C") ){
651 mid =m_trtid->layer_id(bec,0,layer,ring);
652 }else
653 mid =m_trtid->module_id(bec,sector,layer);
654
655 AlignableTransform::AlignTransMem_citr iter = pat->findIdent(mid) ;
656 if(iter != pat->end() ){
657 AlignableTransform::AlignTransMem_citr iter = pat->findIdent(mid) ;
658 Amg::Transform3D* amgTransform = new Amg::Transform3D((Amg::CLHEPTransformToEigen(iter->transform())));
659 m_amgTransformCache.push_back(amgTransform);
660 rc = amgTransform;
661 }
662
663 else
664 ATH_MSG_WARNING( "Did not find the transform for " << m_trtid->show_to_string(mid) );
665 }
666 }
667
668 ATH_MSG_DEBUG( "Leaving getAlignmentTransformL2Ptr" );
669 return rc ;
670}
671
673StatusCode TRT_AlignDbSvc::setAlignTransform(Identifier ident, Amg::Transform3D trans, unsigned int level) {
674 ATH_MSG_DEBUG( "In getAlignmentTransform" );
675
676 if(level != 1 && level != 2 && level != 3){
677 ATH_MSG_FATAL( "Call to setAlignTransform wrong!" );
678 ATH_MSG_FATAL( "Level must be 1,2 or 3!" );
679 return StatusCode::FAILURE;
680 }
681
682 switch (level) {
683
684 case 1:
685 ATH_CHECK( setAlignTransformL1(ident,trans) );
686 break;
687 case 2:
688 ATH_CHECK( setAlignTransformL2(ident,trans) );
689 break;
690 case 3:
691 ATH_CHECK( setAlignTransformL3(ident,trans) );
692 break;
693 }
694
695 return StatusCode::SUCCESS;
696}
697
703 ATH_MSG_DEBUG( "In setAlignTransformL1" );
704 if(msgLvl(MSG::DEBUG)){
705 printTransform("Transform in setAlignTransformL1",trans);
706 }
707
708 // New additions for new global folder structure
709 // No ATs exist for levels 1 & 2 --> need alternative
710 if (m_dynamicDB){
711 if(!tweakGlobalFolder(ident, trans)) {
712 ATH_MSG_ERROR( "Attempt tweak GlobalDB folder failed" );
713 return StatusCode::FAILURE;
714 }
715 }
716 else {
717
718 //does a folder exist corresponding to this identifier?
719 AlignableTransform* pat=getTransPtr("/TRT/Align/TRT");
720 if (!pat){
721 ATH_MSG_FATAL( "The AlignableTransform for key " << "/TRT/Align/TRT" << " does not exist " );
722 ATH_MSG_FATAL( "Failing ... " );
723 return StatusCode::FAILURE;
724 }
725
726 // make sure the identifier is a "subdetector identifier"
727 if( !(m_trtid->is_trt(ident)) ){
728 ATH_MSG_FATAL( "The identifier " << ident << " is not from the TRT " );
729 ATH_MSG_FATAL( "Failing ... " );
730 return StatusCode::FAILURE;
731 }
732
733 int bec=m_trtid->barrel_ec(ident);
734 Identifier mid=m_trtid->module_id(bec,0,0);
735 // update or add (mid,trans) pair
736 HepGeom::Transform3D clhepTrans = Amg::EigenTransformToCLHEP(trans);
737 if( !(pat->update(mid,clhepTrans)) ) {
738 pat->add(mid,clhepTrans);
739 pat->sortv() ;
740 }
741 }
742
743 ATH_MSG_DEBUG( "Leaving setAlignTransformL1" );
744 return StatusCode::SUCCESS;
745}
746
749 ATH_MSG_DEBUG( "In setAlignTransformL2" );
753
754 //does a folder exist corresponding to this identifier?
755 std::string key=findkey(ident,m_alignString);
757 if (!pat) return StatusCode::FAILURE;
758
759 // make sure the identifier is a "module identifier"
760 if( !(m_trtid->is_trt(ident)) ) return StatusCode::FAILURE;
761 int bec=m_trtid->barrel_ec(ident);
762 int layer=m_trtid->layer_or_wheel(ident);
763 int sector=m_trtid->phi_module(ident);
764 int strawLayer=m_trtid->straw_layer(ident);
765 int ring = getRingForStrawLayer(strawLayer);
766 Identifier ident2;
767
768 ATH_MSG_DEBUG( "Setting the L2 Alignment for: "
769 << " Bec= " << bec << " layer= " << layer << " sector= " << sector
770 << " strawLayer= " << strawLayer );
771 ATH_MSG_DEBUG( "The translations are: x= " << trans(0,3) << " y= "<<trans(1,3) << " z= "<<trans(2,3) );
772
773 if(key == (m_alignDBprefix+"L2A") || key == (m_alignDBprefix+"L2C"))
774 ident2=m_trtid->layer_id(bec,0,layer,ring);
775 else
776 ident2=m_trtid->module_id(bec,sector,layer);
777
778 // make sure the identifier is a TRT identifier
779 if( !(m_trtid->is_trt(ident2)) ){
780 ATH_MSG_FATAL( "The identifier " << ident2 << " is not from the TRT " );
781 ATH_MSG_FATAL( "Failing ... " );
782 return StatusCode::FAILURE;
783 }
784
785 // update or add (mid,trans) pair
786 HepGeom::Transform3D clhepTrans = Amg::EigenTransformToCLHEP(trans);
787 if( !(pat->update(ident2,clhepTrans)) ) {
788 pat->add(ident2,clhepTrans);
789 pat->sortv() ;
790 }
791
792 ATH_MSG_DEBUG( "Leaving setAlignTransformL2 " );
793 return StatusCode::SUCCESS;
794}
795
798 ATH_MSG_DEBUG( "In setAlignTransformL3" );
799
800 // make sure the identifier is a "module identifier"
801 if( !(m_trtid->is_trt(ident)) ) return StatusCode::FAILURE;
802 int bec=m_trtid->barrel_ec(ident);
803
804 //Only L3 in the barrel is currently supported
805 if(abs(bec) == 1){
806
807 // Currently at L3 only displacements in the plane of the straw layer can be stored.
808 // For tracks coming from the interaction point this coorisponds to the sensitive coordinate
809 ATH_MSG_INFO("Storing L3 Barrel constants, Only dx and rotz will be written to DB");
810 float dx = trans.translation().x();
811 float rotz = std::atan2(trans.rotation()(0,1),trans.rotation()(0,0));
812
813 // Need the length of the wires to translate the rotation to a translation.
814 const InDetDD::TRT_BaseElement* strawElement = m_trtman->getElement( ident );
815 double strawLenthOver2 = 0.5* strawElement->strawLength();
816
817 // The alignment frames are the same for straws on side A and side C (verrify this!!)
818 // but variables stored in the db are not. We'll calculate the dispacement of each end
819 // in the alignment frame and in a second step, convert to the values in the DB.
820 double delta_dx_atLargerZ = dx + strawLenthOver2 * std::sin(rotz);
821 double delta_dx_atSmallerZ = dx - strawLenthOver2 * std::sin(rotz);
822
823 // For the definition of dx1 and dx2 see TRT_ConditionsData/StrawDx.h
824 // Now we need to know the real meaning of dx1 and dx2. Alas, we
825 // are in the frame of either of the two barrel sides, but not
826 // both, so we need to know which one.
827 bool sideA = m_trtid->barrel_ec(ident) == 1;
828
829 // Straw position closest to the electronics
830 double dx1_new = sideA ? delta_dx_atLargerZ : delta_dx_atSmallerZ;
831
832 // Straw position away from the electronics
833 double dx2_new = sideA ? delta_dx_atSmallerZ : delta_dx_atLargerZ;
834
835 // Uncertianty on straw positions (Arbitrary for now)
836 double dxErr = 0.001;
837
838 m_trtStrawAlignDbSvc->setDx(ident, dx1_new, dx2_new, dxErr);
839 }else{
840 // Currently at L3 only displacements in the plane of the straw layer can be stored.
841 // For tracks coming from the interaction point this coorisponds to the sensitive coordinate
842 ATH_MSG_INFO("Storing L3 Endcap constants, Only dy and rotz will be written to DB");
843
844 // The expected transformation is in the local frame of the Endcap Straws
845 // In the local straw frame:
846 // - the z-axis is along the straw and points toward the beampipe
847 // - the x-axis is along global-z and away from the interaction point
848 // (locX = globZ A-side / locX = -1 *gobZ C-side)
849 // - the y-axis is along global phi_hat direction determined by the other 2.
850 // (clockwise C-side, counter clockwise A-Side)
851 float dy = trans.translation().y();
852 float rotx = std::atan2(trans.rotation()(1,2),trans.rotation()(2,2));
853
854 // Need the length of the wires to translate the rotation to a translation.
855 const InDetDD::TRT_BaseElement* strawElement = m_trtman->getElement( ident );
856 double strawLenthOver2 = 0.5* strawElement->strawLength();
857
858 // In the global frame, 'dx1' corresponds to the readout side and 'dx2'
859 // to the side closest the beampipe.
860 double delta_dx_nearBeamPipe = dy + strawLenthOver2 * std::sin(rotx);
861 double delta_dx_nearReadOut = dy - strawLenthOver2 * std::sin(rotx);
862
863 // Uncertianty on straw positions (Arbitrary for now)
864 double dxErr = 0.001;
865
866 m_trtStrawAlignDbSvc->setDx(ident, delta_dx_nearReadOut, delta_dx_nearBeamPipe, dxErr);
867 }
868
869 ATH_MSG_DEBUG( "Leaving setAlignTransformL3 " );
870 return StatusCode::SUCCESS;
871}
872
874StatusCode TRT_AlignDbSvc::tweakAlignTransform(Identifier ident, Amg::Transform3D trans, unsigned int level) {
875
876 ATH_MSG_DEBUG( "In tweakAlignTransform" );
877
878 if(level != 1 && level != 2 && level != 3){
879 ATH_MSG_FATAL( "Incorrect call to tweakTrans" );
880 ATH_MSG_FATAL( "level must be 1,2 or 3" );
881 return StatusCode::FAILURE;
882 }
883
884 if(level == 1){
885 if(tweakAlignTransformL1(ident,trans).isFailure()){
886
887 ATH_MSG_WARNING( "tweak failed...just setting it." );
888
889 if(setAlignTransformL1(ident,trans).isFailure()){
890 ATH_MSG_FATAL( "Set also failed!" );
891 ATH_MSG_FATAL( "Fail for real." );
892 return StatusCode::FAILURE;
893 }
894 }
895 }
896
897 else if(level == 2){
898 if(tweakAlignTransformL2(ident,trans).isFailure()){
899
900 ATH_MSG_WARNING( "tweak failed...just setting it." );
901
902 if(setAlignTransformL2(ident,trans).isFailure()){
903 ATH_MSG_FATAL( "Set also failed!" );
904 ATH_MSG_FATAL( "Fail for real." );
905 return StatusCode::FAILURE;
906 }
907 }
908 }
909
910 else if(level == 3){
911 if(tweakAlignTransformL3(ident,trans).isFailure()){
912
913 ATH_MSG_WARNING( "tweak failed...just setting it." );
914
915 if(setAlignTransformL3(ident,trans).isFailure()){
916 ATH_MSG_FATAL( "Set also failed!" );
917 ATH_MSG_FATAL( "Fail for real." );
918 return StatusCode::FAILURE;
919 }
920 }
921 }
922
923 ATH_MSG_DEBUG( "Leaving tweakAlignTransform" );
924 return StatusCode::SUCCESS;
925}
926
932 ATH_MSG_DEBUG( "In tweakAlignTransformL1" );
933
934 // New additions for new global folder structure
935 // No ATs exist for levels 1 & 2 --> need alternative
936 if (m_dynamicDB){
937 if(!tweakGlobalFolder(ident, trans)) {
938 ATH_MSG_ERROR( "Attempt tweak GlobalDB folder failed" );
939 return StatusCode::FAILURE;
940 }
941 }
942 else {
943
945 AlignableTransform* pat=getTransPtr("/TRT/Align/TRT");
946 if (!pat){
947 ATH_MSG_WARNING( "The AlignableTransform for key " << "/TRT/Align/TRT" << " does not exist " );
948 ATH_MSG_WARNING( "Failing ... " );
949 return StatusCode::FAILURE;
950 }
951
955 if( !(m_trtid->is_trt(ident)) ){
956 ATH_MSG_WARNING( "The identifier " << ident << " is not from the TRT " );
957 ATH_MSG_WARNING( "Failing ... " );
958 return StatusCode::FAILURE;
959 }
960
961 int bec=m_trtid->barrel_ec(ident);
962 Identifier mid=m_trtid->module_id(bec,0,0);
963
965 if( !(pat->tweak(mid,Amg::EigenTransformToCLHEP(trans))) ){
966 ATH_MSG_WARNING( "The Alignable transfor tweek failed for " << mid );
967 ATH_MSG_WARNING( "Failing ... " );
968 return StatusCode::FAILURE;
969 }
970 }
971
972 ATH_MSG_DEBUG( "Leaving tweakAlignTransformL1" );
973 return StatusCode::SUCCESS;
974}
975
978 ATH_MSG_DEBUG( "In tweakAlignTransformL2" );
979 // multiply level 2 AlignableTransform for the module containing ident
980 // by an additional transform.
981
982 //does a folder exist corresponding to this identifier?
983 std::string key=findkey(ident,m_alignString);
985 if (!pat){
986 ATH_MSG_WARNING( "The transfor for key: " << key << "Does not exist" );
987 ATH_MSG_WARNING( " Failing ... " );
988 return StatusCode::FAILURE;
989 }
990
991 //OK the key exists
992 // make sure the identifier is a "module identifier"
993 if( !(m_trtid->is_trt(ident)) ) return StatusCode::FAILURE;
994 int bec=m_trtid->barrel_ec(ident);
995 int layer=m_trtid->layer_or_wheel(ident);
996 int sector=m_trtid->phi_module(ident);
997 int strawLayer=m_trtid->straw_layer(ident);
998 int ring = getRingForStrawLayer(strawLayer);
999 Identifier mid;
1000 if(key == (m_alignDBprefix+"L2A") || key == (m_alignDBprefix+"L2C"))
1001 mid = m_trtid->layer_id(bec,0,layer,ring);
1002 else
1003 mid = m_trtid->module_id(bec,sector,layer);
1004
1005 // multiply the additional transformation
1006 if( !(pat->tweak(mid,Amg::EigenTransformToCLHEP(trans))) ){
1007 ATH_MSG_WARNING( "Leaving tweakAlignTransformL2. TWEAK FAILED!!" );
1008 return StatusCode::FAILURE;
1009 }
1010
1011 ATH_MSG_DEBUG( "Leaving tweakAlignTransformL2" );
1012 return StatusCode::SUCCESS;
1013}
1014
1017 ATH_MSG_DEBUG( "In tweakAlignTransformL3" );
1018
1019 // make sure the identifier is a "module identifier"
1020 if( !(m_trtid->is_trt(ident)) ) return StatusCode::FAILURE;
1021 int bec=m_trtid->barrel_ec(ident);
1022
1023 //Only L3 in the barrel is currently supported
1024 if(abs(bec) == 1){
1025
1026 // Currently at L3 only displacements in the plane of the straw layer can be stored.
1027 // For tracks coming from the interaction point this coorisponds to the sensitive coordinate
1028 ATH_MSG_INFO("Storing L3 constants, Only dx and rotz will be written to DB");
1029 float dx = trans.translation().x();
1030
1031 ATH_MSG_DEBUG("xx: " << trans.rotation()(0,0));
1032 ATH_MSG_DEBUG("xy: " << trans.rotation()(0,1));
1033 ATH_MSG_DEBUG("xz: " << trans.rotation()(0,2));
1034 ATH_MSG_DEBUG("yx: " << trans.rotation()(1,0));
1035 ATH_MSG_DEBUG("yy: " << trans.rotation()(1,1));
1036 ATH_MSG_DEBUG("yz: " << trans.rotation()(1,2));
1037 ATH_MSG_DEBUG("zx: " << trans.rotation()(2,0));
1038 ATH_MSG_DEBUG("zy: " << trans.rotation()(2,1));
1039 ATH_MSG_DEBUG("zz: " << trans.rotation()(2,2));
1040
1041 // For the definition of dx1 and dx2 see TRT_ConditionsData/StrawDx.h
1042 // Now we need to know the real meaning of dx1 and dx2. Alas, we
1043 // are in the frame of either of the two barrel sides, but not
1044 // both, so we need to know which one.
1045 bool sideA = m_trtid->barrel_ec(ident) == 1;
1046
1047 float rotz = std::atan2(trans.rotation()(0,2),trans.rotation()(0,0));
1048
1049 // Need the length of the wires to translate the rotation to a translation.
1050 const InDetDD::TRT_BaseElement* strawElement = m_trtman->getElement( ident );
1051 double strawLenthOver2 = 0.5* strawElement->strawLength();
1052
1053 // Old way (buggy)
1054 //double delta_dx_atLargerZ = dx + strawLenthOver2 * std::sin(rotz);
1055 //double delta_dx_atSmallerZ = dx - strawLenthOver2 * std::sin(rotz);
1056
1057 // New way - The rotation is opposite for side A as compared to side C
1058 double delta_dx_atLargerZ;
1059 double delta_dx_atSmallerZ;
1060 if (sideA){
1061 delta_dx_atLargerZ = dx - strawLenthOver2 * std::sin(rotz);
1062 delta_dx_atSmallerZ = dx + strawLenthOver2 * std::sin(rotz);
1063 }
1064 else{
1065 delta_dx_atLargerZ = dx + strawLenthOver2 * std::sin(rotz);
1066 delta_dx_atSmallerZ = dx - strawLenthOver2 * std::sin(rotz);
1067 }
1068
1069 // Straw position closest to the electronics
1070 double delta_dx1 = sideA ? delta_dx_atLargerZ : delta_dx_atSmallerZ;
1071
1072 // Straw position away from the electronics
1073 double delta_dx2 = sideA ? delta_dx_atSmallerZ : delta_dx_atLargerZ;
1074
1075 // Uncertianty on straw positions
1076 double dxErr = 0.001;
1077
1078 // now we do some gymnastics: because the strawdisplacement is
1079 // binned, we would rather not just 'add' the current change,
1080 // but rather 'set' the total change. note that this goes
1081 // wrong if there were other straw corrections
1082 // applied. We might have to worry about that at
1083 // some point.
1084 double dx1_current = m_trtStrawAlignDbSvc->getDx1(ident);
1085 double dx2_current = m_trtStrawAlignDbSvc->getDx2(ident) ;
1086 ATH_MSG_DEBUG("Current dx1 is: " << dx1_current);
1087 ATH_MSG_DEBUG("Current dx2 is: " << dx2_current);
1088
1089 double dx1_new = dx1_current + delta_dx1;
1090 double dx2_new = dx2_current + delta_dx2;
1091
1092 //ATH_MSG_INFO("New dx1 is: " << dx1_new);
1093 //ATH_MSG_INFO("New dx2 is: " << dx2_new);
1094
1095 m_trtStrawAlignDbSvc->setDx(ident, dx1_new, dx2_new, dxErr);
1096 }else{
1097
1098 // Currently at L3 only displacements in the plane of the straw layer can be stored.
1099 // For tracks coming from the interaction point this coorisponds to the sensitive coordinate
1100 ATH_MSG_INFO("Storing L3 Endcap constants, Only dy and rotz will be written to DB");
1101
1102 // The expected transformation is in the local frame of the Endcap Straws
1103 // In the local straw frame:
1104 // - the z-axis is along the straw and points toward the beampipe
1105 // - the x-axis is along global-z and away from the interaction point
1106 // (locX = globZ A-side / locX = -1 *gobZ C-side)
1107 // - the y-axis is along global phi_hat direction determined by the other 2.
1108 // (clockwise C-side, counter clockwise A-Side)
1109 float dy = trans.translation().y();
1110 float rotx = std::atan2(trans.rotation()(1,2),trans.rotation()(2,2));
1111
1112 // Need the length of the wires to translate the rotation to a translation.
1113 const InDetDD::TRT_BaseElement* strawElement = m_trtman->getElement( ident );
1114 double strawLenthOver2 = 0.5* strawElement->strawLength();
1115
1116 // In the global frame, 'dx1' corresponds to the readout side and 'dx2'
1117 // to the side closest the beampipe.
1118 double delta_dx_nearBeamPipe = dy + strawLenthOver2 * std::sin(rotx);
1119 double delta_dx_nearReadOut = dy - strawLenthOver2 * std::sin(rotx);
1120
1121 // Uncertianty on straw positions
1122 double dxErr = 0.001;
1123
1124 // now we do some gymnastics: because the strawdisplacement is
1125 // binned, we would rather not just 'add' the current change,
1126 // but rather 'set' the total change. note that this goes
1127 // wrong if there were other straw corrections
1128 // applied. We might have to worry about that at
1129 // some point.
1130 double dx1_current = m_trtStrawAlignDbSvc->getDx1(ident);
1131 double dx2_current = m_trtStrawAlignDbSvc->getDx2(ident) ;
1132 ATH_MSG_DEBUG("Current dx1 is: " << dx1_current);
1133 ATH_MSG_DEBUG("Current dx2 is: " << dx2_current);
1134
1135 double dx1_new = dx1_current + delta_dx_nearReadOut;
1136 double dx2_new = dx2_current + delta_dx_nearBeamPipe;
1137
1138 m_trtStrawAlignDbSvc->setDx(ident, dx1_new, dx2_new, dxErr);
1139 }
1140
1141 ATH_MSG_DEBUG( "Leaving tweakAlignTransformL3 " );
1142 return StatusCode::SUCCESS;
1143}
1144
1146std::string TRT_AlignDbSvc::findkey(const Identifier& ident, const std::string& type) const {
1172 std::ostringstream result;
1173 if (!m_trtid->is_trt(ident)) return result.str();
1174
1175 if(type=="AL" || type=="ALold") {
1176 // result << "/TRT/Align/";
1178 } else if(type=="DF") {
1179 result << "/TRT/Calib/DF";
1180 } else return result.str();
1181
1182 int bec=m_trtid->barrel_ec(ident);
1183
1184 if(type!="AL" && type!="ALold") result << "_";
1185
1186 if(type=="AL"){
1187 if(bec==2) {
1188 result << "L2A";
1189 } else if(bec==-2) {
1190 result << "L2C";
1191 } else {
1192 result << "B";
1193 int layer = m_trtid->layer_or_wheel(ident);
1194 result << layer;
1195 }
1196 }else if(type=="ALold"){
1197 if(bec==2) {
1198 result << "A";
1199 } else if(bec==-2) {
1200 result << "C";
1201 } else {
1202 result << "B";
1203 }
1204 int layer = m_trtid->layer_or_wheel(ident);
1205 result << layer;
1206 }
1207
1212
1213 return result.str();
1214}
1215
1217std::string TRT_AlignDbSvc::prefixtag(const std::string& key) {
1230
1231 std::ostringstream result;
1232 std::string detector=key.substr(1,3);
1233
1234 std::string type,quantity;
1235 int ind,ind1;
1236 if(detector=="TRT") {
1237 type=key.substr(5,5);
1238 ind=11;
1239 ind1=11;
1240 quantity=key.substr(ind,2);
1241 } else if(detector=="Indet") {
1242 type=key.substr(7,5);
1243 ind=17;
1244 ind1=13;
1245 quantity="";
1246 if(type=="Align" && key.substr(ind1,2)!="ID") {
1247 if(key.substr(ind1+3,1)=="_") quantity="DF";
1248 }
1249 } else {
1250 return "";
1251 }
1252 if(type=="Calib") {
1253
1254 if(quantity=="DF") {
1255 result << "TrtDf";
1256 } else if (quantity=="RT") {
1257 result << "TrtRt";
1258 } else if (quantity=="T0") {
1259 result << "TrtT0";
1260 } else {
1261 return "TrtDe_";
1262 }
1263 std::string module=key.substr(ind+3,2);
1264 result << module;
1265 } else if(type=="Align") {
1266 std::string module=key.substr(ind1,2);
1267 if(module=="ID" || module=="TR") {
1268 return "TrtAl_";
1269 } else {
1270 result << "TrtAl";
1271 }
1272 module=key.substr(ind+3,2);
1273 result << module;
1274 } else {
1275 return "";
1276 }
1277 result << "_";
1278 return result.str();
1279}
1280
1283
1288 ATH_MSG_DEBUG( "createAlignObjects method called" );
1289
1292 ATH_MSG_WARNING( "createAlignObjects: AlignableTransformContainer with name " << m_alignroot
1293 << " already exists." );
1294 return StatusCode::FAILURE;
1295 }
1296
1298 auto patc = std::make_unique<AlignableTransformContainer>();
1299
1300 for (unsigned int i=0;i<m_alignobjs.size();++i) {
1301 patc->push_back(std::make_unique<AlignableTransform>(m_alignobjs[i]));
1302 patc->add(m_alignchans[i]);
1303 ATH_MSG_INFO( " added empty AlignableTransform for key " << m_alignobjs[i] );
1304 }
1305
1307 ATH_CHECK( m_detStore->record(std::move(patc),m_alignroot) );
1308
1309 ATH_MSG_DEBUG( "Leaving createAlignObjects" );
1310 return StatusCode::SUCCESS;
1311}
1312
1316
1319 ATH_MSG_DEBUG( "createAlignObjectsWhichDoNotAlreadyExist method called" );
1320
1323
1326
1328 AlignableTransformContainer* patc_NonConst = const_cast<AlignableTransformContainer*>(patc);
1329
1330 for (unsigned int i=0;i<m_alignobjs.size();++i) {
1331
1333 if(m_alignString != "Alold" && !isOldKey(m_alignobjs[i] )){
1334
1336 if(!cgetTransPtr(m_alignobjs[i])){
1337
1339 patc_NonConst->push_back(pat);
1340 patc_NonConst->add(m_alignchans[i]);
1341 ATH_MSG_INFO( " added empty AlignableTransform for key " << m_alignobjs[i] );
1342
1343 }
1344 }
1345 }
1346
1347 ATH_MSG_DEBUG( "Leaving createAlignObjectsWhichDoNotAlreadyExist" );
1348 return StatusCode::SUCCESS;
1349}
1350
1353 ATH_MSG_DEBUG( " In printCondObjects " );
1354 ATH_MSG_INFO( " TRT Conditions DB contains " << m_alignobjs.size() <<" AlignableTransforms: " );
1355
1356 const AlignableTransform *pat;
1357 std::vector<std::string>::const_iterator iobj=m_alignobjs.begin();
1358 std::vector<std::string>::const_iterator iobjE=m_alignobjs.end();
1359 for (;iobj!=iobjE;++iobj) {
1360 ATH_MSG_INFO( " " << *iobj );
1361 pat=cgetTransPtr(*iobj);
1362 if (pat) {
1363 pat->print2();
1364 } else {
1365 ATH_MSG_ERROR( " Could not find key: " << *iobj );
1366 }
1367 }
1368
1369 ATH_MSG_DEBUG( " Leaving printCondObjects" );
1370 return;
1371}
1372
1374AlignableTransform* TRT_AlignDbSvc::getTransPtr(const std::string& key) const {
1375 ATH_MSG_DEBUG( "In (and leaving) getTransPtr" );
1376 return const_cast<AlignableTransform*>(cgetTransPtr(key)) ;
1377}
1378
1380const AlignableTransform* TRT_AlignDbSvc::cgetTransPtr(const std::string& key) const {
1381 ATH_MSG_DEBUG( "In cgetTransPtr" );
1382 ATH_MSG_DEBUG( "Getting the poiter for key " << key );
1383
1384 // Retrieve AlignableTransform pointer for a given key - const version
1385 const AlignableTransform* pat=nullptr;
1387 // the retrieve is unnecessary. in fact, if patc==0, retrieve should
1388 // fail as well.
1389
1390 if( patc || StatusCode::SUCCESS==m_detStore->retrieve(patc,m_alignroot)) {
1391 for(DataVector<AlignableTransform>::const_iterator dva=patc->begin();dva!=patc->end();++dva) {
1392 if( (*dva)->tag()==key ) {
1393 pat = *dva;
1394 break;
1395 }
1396 }
1397 }
1398
1399 if(!pat){
1400 ATH_MSG_WARNING( "AlignableTransform poiter is NULL!!!!!" );
1401 ATH_MSG_WARNING( "Failed to get the AlignableTransform for key " << key );
1402 }
1403
1404 ATH_MSG_DEBUG( "leaving cgetTransPtr " );
1405 return pat;
1406}
1407
1411 return strawlayer / 4 * 4;
1412}
1413
1414
1417bool TRT_AlignDbSvc::isOldKey(const std::string& input) const{
1418
1419 for(unsigned int i=0; i<14; ++i){
1420 std::string testA = "A"+intToString(i);
1421 ATH_MSG_VERBOSE( " The testA is " << testA << " "
1422 << bool(input.find(testA)!=std::string::npos) );
1423 if(input.find(testA)!=std::string::npos){
1424 return true;
1425 }
1426
1427 std::string testC = "C"+intToString(i);
1428 ATH_MSG_VERBOSE( " The testC is " << testC << " "
1429 << bool(input.find(testC)!=std::string::npos) );
1430 if(input.find(testC)!=std::string::npos){
1431 return true;
1432 }
1433
1434 }
1435
1436 return false;
1437}
1438
1440std::string TRT_AlignDbSvc::intToString(int input) {
1441 std::ostringstream stm;
1442 stm << input;
1443 return stm.str();
1444}
1445
1447void TRT_AlignDbSvc::printTransform(const std::string& thisName, const Amg::Transform3D& transform) {
1448 std::cout << thisName << " " << transform(0,3) << " " << transform(1,3) << " " << transform(2,3) << std::endl;
1449 std::cout << thisName << " " << transform(0,0) << " " << transform(0,1) << " " << transform(0,2) << std::endl;
1450 std::cout << thisName << " " << transform(1,0) << " " << transform(1,1) << " " << transform(1,2) << std::endl;
1451 std::cout << thisName << " " << transform(2,1) << " " << transform(2,1) << " " << transform(2,2) << std::endl;
1452 return;
1453}
1454
1455// write global DB to file
1456StatusCode TRT_AlignDbSvc::writeGlobalFolderFile( const std::string &file)
1457 const {
1458
1459 if (m_dynamicDB){
1460 ATH_MSG_DEBUG( "writeFile: Write GlobalFolder DB in text file: " << file );
1461 std::ofstream outfile(file);
1462 std::vector<std::string> folder_list = {"/TRT/AlignL1/TRT"};
1463
1464 for (std::vector<std::string>::iterator it = folder_list.begin(); it != folder_list.end(); ++it){
1465
1466 outfile << *it << std::endl;
1467 const CondAttrListCollection* atrlistcol=nullptr;
1468 if (StatusCode::SUCCESS==m_detStore->retrieve(atrlistcol,*it)) {
1469 // loop over objects in collection
1470 for (CondAttrListCollection::const_iterator citr=atrlistcol->begin(); citr!=atrlistcol->end();++citr) {
1471
1472 const coral::AttributeList& atrlist=citr->second;
1473 outfile << atrlist["bec"].data<int>()
1474 << " " << atrlist["layer"].data<int>()
1475 << " " << atrlist["sector"].data<int>()
1476 << " " << atrlist["Tx"].data<float>()
1477 << " " << atrlist["Ty"].data<float>()
1478 << " " << atrlist["Tz"].data<float>()
1479 << " " << atrlist["phi"].data<float>()
1480 << " " << atrlist["theta"].data<float>()
1481 << " " << atrlist["psi"].data<float>() << std::endl;
1482 }
1483 }
1484 else {
1485 if (msgLvl(MSG::INFO)){
1486 ATH_MSG_INFO( "Cannot find " << *it << " Container - cannot write DB in text file " );
1487 return StatusCode::FAILURE;
1488 }
1489 }
1490 }
1491
1492 return StatusCode::SUCCESS;
1493 }
1494 else {
1495 ATH_MSG_DEBUG( "writeFile: No dynamic Run2 DB structure is present --> skipping writing file " << file );
1496 return StatusCode::SUCCESS;
1497 }
1498}
1499
1500
1501
1502
1503
1504
1506
1507 // find transform key, then set appropriate transform
1508 const CondAttrListCollection* atrlistcol1=nullptr;
1509 CondAttrListCollection* atrlistcol2=nullptr;
1510 bool result = false;
1511 std::string key="/TRT/AlignL1/TRT";
1512 ATH_MSG_DEBUG( " Identifier is valid: "<< ident.is_valid() );
1513 int bec=m_trtid->barrel_ec(ident);
1514 const unsigned int DBident=1000+bec*100;
1515 // so far not a very fancy DB identifier, but seems elaborate enough for this simple structure
1516
1517 if (StatusCode::SUCCESS==m_detStore->retrieve(atrlistcol1,key)) {
1518 // loop over objects in collection
1519 atrlistcol2 = const_cast<CondAttrListCollection*>(atrlistcol1);
1520 if (atrlistcol1!=nullptr){
1521 for (CondAttrListCollection::const_iterator citr=atrlistcol2->begin(); citr!=atrlistcol2->end();++citr) {
1522
1523 const coral::AttributeList& atrlist=citr->second;
1524 coral::AttributeList& atrlist2 = const_cast<coral::AttributeList&>(atrlist);
1525
1526 if(citr->first!=DBident){
1527 ATH_MSG_DEBUG( "tweakGlobalFolder fails due to identifier mismatch" );
1528 continue;
1529 }
1530 else {
1531 ATH_MSG_DEBUG( "Tweak Old global DB -- channel: " << citr->first
1532 << " ,bec: " << atrlist2["bec"].data<int>()
1533 << " ,layer: " << atrlist2["layer"].data<int>()
1534 << " ,sector: " << atrlist2["sector"].data<int>()
1535 << " ,Tx: " << atrlist2["Tx"].data<float>()
1536 << " ,Ty: " << atrlist2["Ty"].data<float>()
1537 << " ,Tz: " << atrlist2["Tz"].data<float>()
1538 << " ,phi: " << atrlist2["phi"].data<float>()
1539 << " ,theta: " << atrlist2["theta"].data<float>()
1540 << " ,psi: " << atrlist2["psi"].data<float>() );
1541
1542
1543 // Follow same definitions as in TRT_AlignDbSvc.cxx
1544 CLHEP::Hep3Vector oldtranslation(atrlist2["Tx"].data<float>(),atrlist2["Ty"].data<float>(),atrlist2["Tz"].data<float>());
1545 CLHEP::HepRotation oldrotation;
1546 oldrotation.set(atrlist["phi"].data<float>(),atrlist["theta"].data<float>(),atrlist["psi"].data<float>());
1547 HepGeom::Transform3D oldtransform(oldrotation, oldtranslation);
1548
1549 // get the new transform
1550 HepGeom::Transform3D newtrans = Amg::EigenTransformToCLHEP(trans)*oldtransform;
1551 Amg::Transform3D newtransAMG = trans*Amg::CLHEPTransformToEigen(oldtransform);
1552
1553 // Extract the values we need to write to DB
1554 Amg::Vector3D shift=newtransAMG.translation();
1555 CLHEP::HepRotation rot=newtrans.getRotation();
1556 Amg::Vector3D eulerangles;
1557 eulerangles[0] = rot.getPhi();
1558 eulerangles[1] = rot.getTheta();
1559 eulerangles[2] = rot.getPsi();
1560
1561 atrlist2["Tx"].data<float>() = shift.x();
1562 atrlist2["Ty"].data<float>() = shift.y();
1563 atrlist2["Tz"].data<float>() = shift.z();
1564 atrlist2["phi"].data<float>() = eulerangles[0] ;
1565 atrlist2["theta"].data<float>() = eulerangles[1] ;
1566 atrlist2["psi"].data<float>() = eulerangles[2] ;
1567
1568 result = true;
1569 ATH_MSG_DEBUG( "Tweak New global DB -- channel: " << citr->first
1570 << " ,bec: " << atrlist2["bec"].data<int>()
1571 << " ,layer: " << atrlist2["layer"].data<int>()
1572 << " ,sector: " << atrlist2["sector"].data<int>()
1573 << " ,Tx: " << atrlist2["Tx"].data<float>()
1574 << " ,Ty: " << atrlist2["Ty"].data<float>()
1575 << " ,Tz: " << atrlist2["Tz"].data<float>()
1576 << " ,phi: " << atrlist2["phi"].data<float>()
1577 << " ,theta: " << atrlist2["theta"].data<float>()
1578 << " ,psi: " << atrlist2["psi"].data<float>() );
1579
1580 }
1581 }
1582 }
1583 else {
1584 ATH_MSG_ERROR("tweakGlobalFolder: cast fails for DBident " << DBident );
1585 return StatusCode::FAILURE;
1586 }
1587 }
1588 else {
1589 ATH_MSG_ERROR("tweakGlobalFolder: cannot retrieve CondAttrListCollection for key " << key );
1590 return StatusCode::FAILURE;
1591 }
1592
1593 if (result) return StatusCode::SUCCESS;
1594 else return StatusCode::FAILURE;
1595}
1596
1597
1599{
1600 if (m_aligncontainerhandle.isValid())
1601 return m_aligncontainerhandle.cptr();
1602 const AlignableTransformContainer* ptr = nullptr;
1603 if (m_detStore->retrieve (ptr, m_alignroot).isFailure()) {
1604 ATH_MSG_ERROR ("Cannot retrieve " << m_alignroot << " from detStore ");
1605 }
1606 return ptr;
1607}
CondMultChanCollection< AlignableTransform > AlignableTransformContainer
Scalar phi() const
phi method
Scalar theta() const
theta method
#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_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
Interface to an output stream tool.
This is an interface to a tool used to register conditions objects in the Interval of Validity (IOV) ...
static Double_t rc
a Service to manage TRT alignment conditions
This is an Identifier helper class for the TRT subdetector.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
std::vector< AlignTransMember >::const_iterator AlignTransMem_citr
This class is a collection of AttributeLists where each one is associated with a channel number.
const_iterator end() const
const_iterator begin() const
Access to Chan/AttributeList pairs via iterators.
ChanAttrListMap::const_iterator const_iterator
void add(ChanNum chanNum)
Adding in channel numbers.
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
Standard iterator.
Definition DataVector.h:842
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
This is a tool that allows streaming out of DataObjects.
virtual StatusCode streamObjects(const TypeKeyPairs &typeKeys, const std::string &outputName="")=0
std::pair< std::string, std::string > TypeKeyPair
Stream out objects.
virtual StatusCode connectOutput(const std::string &outputName="")=0
Connect to the output stream Must connectOutput BEFORE streaming Only specify "outputName" if one wan...
std::vector< TypeKeyPair > TypeKeyPairs
virtual StatusCode commitOutput(bool doCommit=false)=0
Commit the output stream after having streamed out objects Must commitOutput AFTER streaming.
Virtual base class of TRT readout elements.
virtual const double & strawLength() const =0
Active straw length.
virtual Identifier identify() const override final
identifier of this detector element:
The Detector Manager for all TRT Detector elements, it acts as the interface to the detector elements...
std::vector< Amg::Transform3D * > m_amgTransformCache
StatusCode setAlignTransformL1(Identifier ident, const Amg::Transform3D &trans)
set Level 1 AlignableTransform for an identifier
virtual StatusCode initialize()
tool initialize
const TRT_ID * m_trtid
trt id helper
const Amg::Transform3D * getAlignmentTransformL2Ptr(Identifier const &ident) const
get Level L2 Transform for an identifier
ToolHandle< IAthenaOutputStreamTool > m_streamer
OutputStreamTool.
AlignableTransform * getTransPtr(const std::string &key) const
get AlignableTransform pointer for an object key
const Amg::Transform3D * getAlignmentTransformL1Ptr(Identifier const &ident) const
get Level L1 Transform for an identifier
virtual StatusCode finalize()
tool finalize
StatusCode writeGlobalFolderFile(const std::string &file) const
std::vector< std::string > m_alignobjs
folder names
StatusCode tweakAlignTransformL1(Identifier ident, const Amg::Transform3D &trans)
tweak Level 1 AlignableTransform for an identifier
static void printTransform(const std::string &thisName, const Amg::Transform3D &transform)
Output the transform to the cout, for debugging.
StatusCode registerAlignObjects(const std::string &tag, int run1, int event1, int run2, int event2) const
register alignment objects with the IoV service
const Amg::Transform3D getAlignmentTransformL2(Identifier const &ident) const
get Level 2 AlignableTransform for an identifier
StatusCode createAlignObjects() const
Create an empty set of AlignableTransforms for the GeoModel setup.
StatusCode writeStrawAlignTextFile(const std::string &file) const
void printCondObjects() const
Output the conditions objects currently in memory.
StatusCode tweakAlignTransformL3(Identifier ident, Amg::Transform3D trans)
tweak Level 3 AlignableTransform for an identifier
StatusCode writeAlignTextFile(const std::string &file) const
write AlignableTransforms to flat text file
StatusCode IOVCallBack()
Call back function for alignment folders.
StatusCode readAlignTextFile(const std::string &file)
read AlignableTransforms from text file into TDS
std::string m_alignString
alignment string searched for
ServiceHandle< ITRT_StrawAlignDbSvc > m_trtStrawAlignDbSvc
const Amg::Transform3D * getAlignmentTransformPtr(const Identifier &ident, unsigned int level) const
get Level L2 Transform for an identifier
std::string findkey(const Identifier &ident, const std::string &type) const
Return the object key for a given identifier and data type.
StatusCode tweakAlignTransformL2(Identifier ident, const Amg::Transform3D &trans)
tweak Level 2 AlignableTransform for an identifier
const Amg::Transform3D getAlignmentTransform(const Identifier &ident, unsigned int level) const
get AlignableTransform for an identifier
std::string m_par_alitextfile
input text file
const AlignableTransformContainer * getContainer() const
Return the container.
StatusCode setAlignTransformL3(Identifier ident, Amg::Transform3D trans)
set Level 3 AlignableTransform for an identifier
virtual ~TRT_AlignDbSvc()
destructor
const Amg::Transform3D getAlignmentTransformL1(Identifier const &ident) const
get Level 1 AlignableTransform for an identifier
StatusCode setAlignTransformL2(Identifier ident, Amg::Transform3D trans)
set Level 2 AlignableTransform for an identifier
StatusCode setAlignTransform(Identifier ident, Amg::Transform3D trans, unsigned int level)
set AlignableTransform for an identifier
static std::string intToString(int input)
Convert from an int to a string.
const InDetDD::TRT_DetectorManager * m_trtman
detector manager
static std::string prefixtag(const std::string &key)
Return the prefix tag for a given calibration folder.
static int getRingForStrawLayer(int strawlayer)
Returns the ring for a given strawLayer.
StatusCode streamOutAlignObjects() const
write the alignment objects to output
const AlignableTransform * cgetTransPtr(const std::string &key) const
get const AlignableTransform pointer for an object key
ServiceHandle< StoreGateSvc > m_detStore
std::vector< int > m_alignchans
channels
const DataHandle< AlignableTransformContainer > m_aligncontainerhandle
StatusCode tweakGlobalFolder(Identifier ident, const Amg::Transform3D &trans)
tweak L1 DB for global folders for an identifier
std::string m_alignDBprefix
TRT_AlignDbSvc(const std::string &name, ISvcLocator *pSvcLocator)
constructor
StatusCode tweakAlignTransform(Identifier ident, Amg::Transform3D trans, unsigned int level)
tweak AlignableTransform for an identifier
StatusCode createAlignObjectsWhichDoNotAlreadyExist()
Create an empty set of AlignableTransforms for the transforms which are not created by XXXXXXX from t...
bool isOldKey(const std::string &input) const
Returns the true if the input key is from the old endcap scheme.
std::string m_alignroot
root alignment folder
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
Amg::Transform3D CLHEPTransformToEigen(const HepGeom::Transform3D &CLHEPtransf)
Converts a CLHEP-based HepGeom::Transform3D into an Eigen Amg::Transform3D.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
@ timedependent_run2
TFile * file