DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
GlobalAlignment.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DD4hep/GlobalAlignment.h>
16 #include <DD4hep/MatrixHelpers.h>
17 #include <DD4hep/Printout.h>
18 
19 // ROOT include files
20 #include <TGeoManager.h>
21 
22 namespace {
23  struct CheckHandle {
24  CheckHandle(const dd4hep::align::GlobalAlignment& a) {
25  if ( a.isValid() ) return;
26  dd4hep::except("dd4hep:GlobalAlignment", "Attempt to access invalid alignment object. [Invalid Handle]");
27  }
28  ~CheckHandle() {}
29  };
30 }
31 
34  //cout << "GlobalAlignment: path=" << path << endl;
35  m_element = new TGeoPhysicalNode(path.c_str());
36 }
37 
40  CheckHandle verify_handle(*this);
41  return ptr()->GetLevel();
42 }
43 
46  CheckHandle verify_handle(*this);
47  return ptr()->GetNode(0);
48 }
49 
52  CheckHandle verify_handle(*this);
53  TGeoNode* n = ptr()->GetNode(level);
54  if ( n ) return n;
55  except("dd4hep:GlobalAlignment",
56  "The object chain of %s is too short. [Invalid index]", placement().name());
57  return {};
58 }
59 
62  CheckHandle verify_handle(*this);
63  Int_t ind = ptr()->GetLevel()-level_up;
64  if ( ind >= 0 ) {
65  return ptr()->GetMother(level_up);
66  }
67  except("dd4hep:GlobalAlignment",
68  "This object %s has not enough mothers. [Invalid index]", placement().name());
69  return {};
70 }
71 
74  CheckHandle verify_handle(*this);
75  return detail::matrix::_transform(ptr()->GetMatrix(level));
76 }
77 
80  CheckHandle verify_handle(*this);
81  Position result;
82  TGeoHMatrix* matrix = ptr()->GetMatrix(level);
83  matrix->LocalToMaster((Double_t*)&localPoint,(Double_t*)&result);
84  return result;
85 }
86 
89  CheckHandle verify_handle(*this);
90  Position result;
91  TGeoHMatrix* matrix = ptr()->GetMatrix(level);
92  matrix->MasterToLocal((Double_t*)&globalPoint,(Double_t*)&result);
93  return result;
94 }
95 
98  CheckHandle verify_handle(*this);
99  return detail::matrix::_transform(ptr()->GetNode(level)->GetMatrix());
100 }
101 
104  CheckHandle verify_handle(*this);
105  return detail::matrix::_transform(ptr()->GetOriginalMatrix());
106 }
107 
110  // It may be useful at some point to cache some of these matrices....
111  CheckHandle verify_handle(*this);
112  TGeoPhysicalNode* n = ptr();
113  // T = T_0 * Delta -> Delta = T_0^-1 * T
114  TGeoHMatrix matrix(n->GetOriginalMatrix()->Inverse());
115  matrix.Multiply(n->GetNode()->GetMatrix());
116  return detail::matrix::_transform(&matrix);
117 }
118 
121  // It may be useful at some point to cache some of these matrices....
122  CheckHandle verify_handle(*this);
123  TGeoPhysicalNode* n = ptr();
124  // T = T_0 * Delta -> Delta^-1 = T^-1 * T_0
125  TGeoHMatrix matrix(n->GetNode()->GetMatrix()->Inverse());
126  matrix.Multiply(n->GetOriginalMatrix());
127  return detail::matrix::_transform(&matrix);
128 }
dd4hep::align::GlobalAlignment::motherPlacement
PlacedVolume motherPlacement(int level_up=1) const
Access the placement of the mother of this node.
Definition: GlobalAlignment.cpp:61
dd4hep::align::GlobalAlignment::globalToLocal
Position globalToLocal(const Position &globalPoint, int level=-1) const
Transform a point from global coordinates to local coordinates of a given level.
Definition: GlobalAlignment.cpp:88
GlobalAlignment.h
dd4hep::align::GlobalAlignment
Main handle class to hold a TGeo alignment object of type TGeoPhysicalNode.
Definition: GlobalAlignment.h:38
MatrixHelpers.h
dd4hep::align::GlobalAlignment::nodePlacement
PlacedVolume nodePlacement(int level=-1) const
Access the placement of a node in the chain of placements for this branch.
Definition: GlobalAlignment.cpp:51
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::detail::matrix::_transform
TGeoHMatrix * _transform(const Transform3D &trans)
Convert a Transform3D object to a newly created TGeoHMatrix.
Definition: MatrixHelpers.cpp:140
dd4hep::align::GlobalAlignment::toGlobal
Transform3D toGlobal(int level=-1) const
Access the currently applied alignment/placement matrix with respect to the world.
Definition: GlobalAlignment.cpp:73
dd4hep::align::GlobalAlignment::nominal
Transform3D nominal() const
Access the currently applied alignment/placement matrix (mother to daughter)
Definition: GlobalAlignment.cpp:103
dd4hep::Handle< TGeoPhysicalNode >::m_element
TGeoPhysicalNode * m_element
Single and only data member: Reference to the actual element.
Definition: Handle.h:93
dd4hep::align::GlobalAlignment::numNodes
int numNodes() const
Number of nodes in this branch (=depth of the placement hierarchy from the top level volume)
Definition: GlobalAlignment.cpp:39
dd4hep::Transform3D
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:117
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::align::GlobalAlignment::GlobalAlignment
GlobalAlignment()=default
Default constructor.
dd4hep::align::GlobalAlignment::delta
Transform3D delta() const
Access the currently applied correction matrix (delta) (mother to daughter)
Definition: GlobalAlignment.cpp:109
dd4hep::align::GlobalAlignment::placement
PlacedVolume placement() const
Access the placement of this node.
Definition: GlobalAlignment.cpp:45
dd4hep::align::GlobalAlignment::toMother
Transform3D toMother(int level=-1) const
Access the currently applied alignment/placement matrix with respect to mother volume.
Definition: GlobalAlignment.cpp:97
Printout.h
dd4hep::align::GlobalAlignment::invDelta
Transform3D invDelta() const
Access the inverse of the currently applied correction matrix (delta) (mother to daughter)
Definition: GlobalAlignment.cpp:120