DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GlobalAlignment.cpp
Go to the documentation of this file.
1 // $Id$
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DD4hep/GlobalAlignment.h"
17 #include "DD4hep/InstanceCount.h"
18 #include "DD4hep/MatrixHelpers.h"
19 #include "DD4hep/Printout.h"
20 
21 // ROOT include files
22 #include "TGeoMatrix.h"
23 #include "TGeoManager.h"
24 
25 
26 using namespace std;
27 using namespace DD4hep;
28 using namespace DD4hep::Alignments;
29 
30 namespace {
31  struct CheckHandle {
32  CheckHandle(const GlobalAlignment& a) {
33  if ( a.isValid() ) return;
34  throw runtime_error("DD4hep: Attempt to access invalid alignment object. [Invalid Handle]");
35  }
36  ~CheckHandle() {}
37  };
38 }
39 
41 GlobalAlignment::GlobalAlignment() : Handle<TGeoPhysicalNode>() {
42 }
43 
45 GlobalAlignment::GlobalAlignment(const GlobalAlignment& c) : Handle<TGeoPhysicalNode>(c) {
46 }
47 
49 GlobalAlignment::GlobalAlignment(const string& path) {
50  //cout << "GlobalAlignment: path=" << path << endl;
51  //m_element = gGeoManager->MakePhysicalNode(path.c_str());
52  m_element = new TGeoPhysicalNode(path.c_str());
53 }
54 
57  if ( &c != this ) {
58  m_element = c.ptr();
59  }
60  return *this;
61 }
62 
65  CheckHandle verify_handle(*this);
66  return ptr()->GetLevel();
67 }
68 
70 PlacedVolume GlobalAlignment::placement() const {
71  CheckHandle verify_handle(*this);
72  return PlacedVolume(ptr()->GetNode(0));
73 }
74 
76 PlacedVolume GlobalAlignment::nodePlacement(int level) const {
77  CheckHandle verify_handle(*this);
78  PlacedVolume pv = PlacedVolume(ptr()->GetNode(level));
79  if ( pv.isValid() ) return pv;
80  throw runtime_error("DD4hep: The object chain of "+string(placement().name())+
81  " is too short. [Invalid index]");
82 }
83 
85 PlacedVolume GlobalAlignment::motherPlacement(int level_up) const {
86  CheckHandle verify_handle(*this);
87  Int_t ind = ptr()->GetLevel()-level_up;
88  if ( ind >= 0 ) {
89  return PlacedVolume(ptr()->GetMother(level_up));
90  }
91  throw runtime_error("DD4hep: This object "+string(placement().name())+" has not enough mothers. [Invalid index]");
92 }
93 
96  CheckHandle verify_handle(*this);
97  return Geometry::_transform(ptr()->GetMatrix(level));
98 }
99 
101 GlobalAlignment::Position GlobalAlignment::toGlobal(const Position& localPoint, int level) const {
102  CheckHandle verify_handle(*this);
103  Position result;
104  TGeoHMatrix* m = ptr()->GetMatrix(level);
105  m->LocalToMaster((Double_t*)&localPoint,(Double_t*)&result);
106  return result;
107 }
108 
111  CheckHandle verify_handle(*this);
112  Position result;
113  TGeoHMatrix* m = ptr()->GetMatrix(level);
114  m->MasterToLocal((Double_t*)&globalPoint,(Double_t*)&result);
115  return result;
116 }
117 
120  CheckHandle verify_handle(*this);
121  return Geometry::_transform(ptr()->GetNode(level)->GetMatrix());
122 }
123 
126  CheckHandle verify_handle(*this);
127  return Geometry::_transform(ptr()->GetOriginalMatrix());
128 }
129 
132  // It may be useful at some point to cache some of these matrices....
133  CheckHandle verify_handle(*this);
134  TGeoPhysicalNode* n = ptr();
135  // T = T_0 * Delta -> Delta = T_0^-1 * T
136  TGeoHMatrix mat(n->GetOriginalMatrix()->Inverse());
137  mat.Multiply(n->GetNode()->GetMatrix());
138  return Geometry::_transform(&mat);
139 }
140 
143  // It may be useful at some point to cache some of these matrices....
144  CheckHandle verify_handle(*this);
145  TGeoPhysicalNode* n = ptr();
146  // T = T_0 * Delta -> Delta^-1 = T^-1 * T_0
147  TGeoHMatrix mat(n->GetNode()->GetMatrix()->Inverse());
148  mat.Multiply(n->GetOriginalMatrix());
149  return Geometry::_transform(&mat);
150 }
Transform3D toMother(int level=-1) const
Access the currently applied alignment/placement matrix with respect to mother volume.
Transform3D delta() const
Access the currently applied correction matrix (delta) (mother to daughter)
const char * name() const
Access the object name (or "" if not supported by the object)
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
Transform3D toGlobal(int level=-1) const
Access the currently applied alignment/placement matrix with respect to the world.
Transform3D nominal() const
Access the currently applied alignment/placement matrix (mother to daughter)
Main handle class to hold a TGeo alignment object of type TGeoPhysicalNode.
int numNodes() const
Number of nodes in this branch (=depth of the placement hierarchy from the top level volume) ...
PlacedVolume motherPlacement(int level_up=1) const
Access the placement of the mother of this node.
T * ptr() const
Access to the held object.
Definition: Handle.h:149
Transform3D invDelta() const
Access the inverse of the currently applied correction matrix (delta) (mother to daughter) ...
TGeoHMatrix * _transform(const Geometry::Transform3D &trans)
Convert a Transform3D object to a TGeoHMatrix
GlobalAlignment()
Default constructor.
PlacedVolume placement() const
Access the placement of this node.
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:87
GlobalAlignment & operator=(const GlobalAlignment &c)
Assignment operator.
Position globalToLocal(const Position &globalPoint, int level=-1) const
Transform a point from global coordinates to local coordinates of a given level.
PlacedVolume nodePlacement(int level=-1) const
Access the placement of a node in the chain of placements for this branch.
TGeoPhysicalNode * m_element
Single and only data member: Reference to the actual element.
Definition: Handle.h:96
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294