File indexing completed on 2025-01-18 09:13:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/GlobalAlignment.h>
0016 #include <DD4hep/MatrixHelpers.h>
0017 #include <DD4hep/Printout.h>
0018
0019
0020 #include <TGeoManager.h>
0021
0022 namespace {
0023 struct CheckHandle {
0024 CheckHandle(const dd4hep::align::GlobalAlignment& a) {
0025 if ( a.isValid() ) return;
0026 dd4hep::except("dd4hep:GlobalAlignment", "Attempt to access invalid alignment object. [Invalid Handle]");
0027 }
0028 ~CheckHandle() {}
0029 };
0030 }
0031
0032
0033 dd4hep::align::GlobalAlignment::GlobalAlignment(const std::string& path) {
0034
0035 m_element = new TGeoPhysicalNode(path.c_str());
0036 }
0037
0038
0039 int dd4hep::align::GlobalAlignment::numNodes() const {
0040 CheckHandle verify_handle(*this);
0041 return ptr()->GetLevel();
0042 }
0043
0044
0045 dd4hep::PlacedVolume dd4hep::align::GlobalAlignment::placement() const {
0046 CheckHandle verify_handle(*this);
0047 return ptr()->GetNode(0);
0048 }
0049
0050
0051 dd4hep::PlacedVolume dd4hep::align::GlobalAlignment::nodePlacement(int level) const {
0052 CheckHandle verify_handle(*this);
0053 TGeoNode* n = ptr()->GetNode(level);
0054 if ( n ) return n;
0055 except("dd4hep:GlobalAlignment",
0056 "The object chain of %s is too short. [Invalid index]", placement().name());
0057 return {};
0058 }
0059
0060
0061 dd4hep::PlacedVolume dd4hep::align::GlobalAlignment::motherPlacement(int level_up) const {
0062 CheckHandle verify_handle(*this);
0063 Int_t ind = ptr()->GetLevel()-level_up;
0064 if ( ind >= 0 ) {
0065 return ptr()->GetMother(level_up);
0066 }
0067 except("dd4hep:GlobalAlignment",
0068 "This object %s has not enough mothers. [Invalid index]", placement().name());
0069 return {};
0070 }
0071
0072
0073 dd4hep::Transform3D dd4hep::align::GlobalAlignment::toGlobal(int level) const {
0074 CheckHandle verify_handle(*this);
0075 return detail::matrix::_transform(ptr()->GetMatrix(level));
0076 }
0077
0078
0079 dd4hep::Position dd4hep::align::GlobalAlignment::toGlobal(const Position& localPoint, int level) const {
0080 CheckHandle verify_handle(*this);
0081 Position result;
0082 TGeoHMatrix* matrix = ptr()->GetMatrix(level);
0083 matrix->LocalToMaster((Double_t*)&localPoint,(Double_t*)&result);
0084 return result;
0085 }
0086
0087
0088 dd4hep::Position dd4hep::align::GlobalAlignment::globalToLocal(const Position& globalPoint, int level) const {
0089 CheckHandle verify_handle(*this);
0090 Position result;
0091 TGeoHMatrix* matrix = ptr()->GetMatrix(level);
0092 matrix->MasterToLocal((Double_t*)&globalPoint,(Double_t*)&result);
0093 return result;
0094 }
0095
0096
0097 dd4hep::Transform3D dd4hep::align::GlobalAlignment::toMother(int level) const {
0098 CheckHandle verify_handle(*this);
0099 return detail::matrix::_transform(ptr()->GetNode(level)->GetMatrix());
0100 }
0101
0102
0103 dd4hep::Transform3D dd4hep::align::GlobalAlignment::nominal() const {
0104 CheckHandle verify_handle(*this);
0105 return detail::matrix::_transform(ptr()->GetOriginalMatrix());
0106 }
0107
0108
0109 dd4hep::Transform3D dd4hep::align::GlobalAlignment::delta() const {
0110
0111 CheckHandle verify_handle(*this);
0112 TGeoPhysicalNode* n = ptr();
0113
0114 TGeoHMatrix matrix(n->GetOriginalMatrix()->Inverse());
0115 matrix.Multiply(n->GetNode()->GetMatrix());
0116 return detail::matrix::_transform(&matrix);
0117 }
0118
0119
0120 dd4hep::Transform3D dd4hep::align::GlobalAlignment::invDelta() const {
0121
0122 CheckHandle verify_handle(*this);
0123 TGeoPhysicalNode* n = ptr();
0124
0125 TGeoHMatrix matrix(n->GetNode()->GetMatrix()->Inverse());
0126 matrix.Multiply(n->GetOriginalMatrix());
0127 return detail::matrix::_transform(&matrix);
0128 }