20 #include <DD4hep/detail/Handle.inl>
24 #include <TGeoMatrix.h>
25 #include <TGeoManager.h>
27 #ifdef __GNUC__ // Disable some diagnostics.
28 #pragma GCC diagnostic ignored "-Wunused-function"
33 using dd4hep::printout;
70 static bool s_GlobalDetectorAlignment_debug =
true;
73 TGeoPhysicalNode* node = a.
ptr();
75 TGeoMatrix* mm = node->GetNode()->GetMatrix();
78 printout(INFO,
"Alignment",
"DELTA matrix of %s", node->GetName());
80 printout(INFO,
"Alignment",
"OLD matrix of %s", node->GetName());
83 std::vector<dd4hep::PlacedVolume> places;
84 for(
int i = 0; i < node->GetLevel(); ++i )
85 places.emplace_back(node->GetNode(i+1));
87 transform->MultiplyLeft(mm);
88 node->Align(transform, 0, check, overlap);
90 printout(INFO,
"Alignment",
"NEW matrix of %s", node->GetName());
91 node->GetNode()->GetMatrix()->Print();
94 for(
int i = 0; i < node->GetLevel(); ++i ) {
97 if (
nullptr == p->GetUserExtension() ) {
99 p->SetUserExtension(places[i]->GetUserExtension());
102 printout(INFO,
"Alignment",
"_align(places): %s Path[%d]: %-24s %p <-> %p %s",
103 tag, i, p.
name(), p.
ptr(), places[i].ptr(), places[i].name());
107 if (
nullptr ==
v->GetUserExtension() ) {
109 v->SetUserExtension(places[i].volume()->GetUserExtension());
112 printout(INFO,
"Alignment",
"_align(volumes): %s Path[%d]: %-24s %p <-> %p %s",
113 tag, i,
v.name(),
v.ptr(), places[i].volume().ptr(), places[i].volume().name());
117 places[i].volume().access();
135 dd4hep::except(
"GlobalDetectorAlignment",
"Cannot align non existing physical node. [Invalid Handle]");
146 if ( h.isValid() && h->global.isValid() ) {
149 dd4hep::except(
"GlobalDetectorAlignment",
"Cannot access global alignment data. [Invalid Handle]");
160 dd4hep::detail::tools::PlacementPath::const_reverse_iterator j=nodes.rbegin();
161 dd4hep::detail::tools::ElementPath::const_reverse_iterator k=det_nodes.rbegin();
162 for(; j!=nodes.rend(); ++j, ++level) {
165 if ( ::strcmp((*j).ptr()->GetName(), (*k).placement().ptr()->GetName()) ) {
167 elements.emplace_back(level, *k);
193 return s_GlobalDetectorAlignment_debug;
198 bool tmp = s_GlobalDetectorAlignment_debug;
199 s_GlobalDetectorAlignment_debug = value;
210 return _alignment(*
this);
247 return _align(_alignment(*
this), matrix, chk, overlap);
273 if ( elt_path.empty() )
274 return _align(_alignment(*
this), matrix, chk, overlap);
276 return _align(_alignment(*
this), matrix, chk, overlap);
277 else if ( elt_path[0] ==
'/' ) {
280 return _align(a, matrix, chk, overlap);
284 return _align(a, matrix, chk, overlap);