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
MatrixHelpers.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/MatrixHelpers.h"
17 
18 // ROOT includes
19 #include "TGeoMatrix.h"
20 
21 using namespace DD4hep::Geometry;
22 
24  return gGeoIdentity;
25 }
26 
27 TGeoTranslation* DD4hep::Geometry::_translation(const Position& pos) {
28  return new TGeoTranslation("", pos.X(), pos.Y(), pos.Z());
29 }
30 
31 TGeoRotation* DD4hep::Geometry::_rotationZYX(const RotationZYX& rot) {
32  return new TGeoRotation("", rot.Phi() * RAD_2_DEGREE, rot.Theta() * RAD_2_DEGREE, rot.Psi() * RAD_2_DEGREE);
33 }
34 
35 TGeoRotation* DD4hep::Geometry::_rotation3D(const Rotation3D& rot3D) {
36  EulerAngles rot(rot3D);
37  return new TGeoRotation("", rot.Phi() * RAD_2_DEGREE, rot.Theta() * RAD_2_DEGREE, rot.Psi() * RAD_2_DEGREE);
38 }
39 
41 TGeoHMatrix& DD4hep::Geometry::_transform(TGeoHMatrix& tr, const RotationZYX& rot) {
42  tr.RotateZ(rot.Phi() * RAD_2_DEGREE);
43  tr.RotateY(rot.Theta() * RAD_2_DEGREE);
44  tr.RotateX(rot.Psi() * RAD_2_DEGREE);
45  return tr;
46 }
47 
49 TGeoHMatrix& DD4hep::Geometry::_transform(TGeoHMatrix& tr, const Position& pos) {
50  double t[3];
51  pos.GetCoordinates(t);
52  tr.SetDx(t[0]);
53  tr.SetDy(t[1]);
54  tr.SetDz(t[2]);
55  return tr;
56 }
57 
59 TGeoHMatrix& DD4hep::Geometry::_transform(TGeoHMatrix& tr, const Rotation3D& rot) {
60  Double_t* r = tr.GetRotationMatrix();
61  rot.GetComponents(r);
62  return tr;
63 }
64 
66 TGeoHMatrix& DD4hep::Geometry::_transform(TGeoHMatrix& tr, const Transform3D& trans) {
67  Position pos;
68  RotationZYX rot;
69  trans.GetDecomposition(rot, pos);
70  return _transform(tr, pos, rot);
71 }
72 
74 TGeoHMatrix& DD4hep::Geometry::_transform(TGeoHMatrix& tr, const Position& pos, const RotationZYX& rot) {
75  return _transform(_transform(tr, rot), pos);
76 }
77 
79 TGeoHMatrix* DD4hep::Geometry::_transform(const Position& pos) {
80  return &_transform(*(new TGeoHMatrix()), pos);
81 }
82 
84 TGeoHMatrix* DD4hep::Geometry::_transform(const RotationZYX& rot) {
85  return &_transform(*(new TGeoHMatrix()), rot);
86 }
87 
89 TGeoHMatrix* DD4hep::Geometry::_transform(const Rotation3D& rot) {
90  return &_transform(*(new TGeoHMatrix()), rot);
91 }
92 
94 TGeoHMatrix* DD4hep::Geometry::_transform(const Transform3D& trans) {
95  return &_transform(*(new TGeoHMatrix()), trans);
96 }
97 
99 TGeoHMatrix* DD4hep::Geometry::_transform(const Position& pos, const RotationZYX& rot) {
100  return &_transform(*(new TGeoHMatrix()), pos, rot);
101 }
102 
104 Transform3D DD4hep::Geometry::_transform(const TGeoMatrix* matrix) {
105  const Double_t* t = matrix->GetTranslation();
106  if ( matrix->IsRotation() ) {
107  const Double_t* r = matrix->GetRotationMatrix();
108  return Transform3D(r[0],r[1],r[2],t[0]*MM_2_CM,
109  r[3],r[4],r[5],t[1]*MM_2_CM,
110  r[6],r[7],r[8],t[2]*MM_2_CM);
111  }
112  return Transform3D(0e0,0e0,0e0,t[0]*MM_2_CM,
113  0e0,0e0,0e0,t[1]*MM_2_CM,
114  0e0,0e0,0e0,t[2]*MM_2_CM);
115 }
116 
118  return m->IsRotation() ? _XYZangles(m->GetRotationMatrix()) : XYZAngles(0,0,0);
119 }
120 
122  Double_t cosb = std::sqrt(r[0]*r[0] + r[1]*r[1]);
123  if (cosb > 0.00001) {
124  return XYZAngles(atan2(r[5], r[8]), atan2(-r[2], cosb), atan2(r[1], r[0]));
125  }
126  return XYZAngles(atan2(-r[7], r[4]),atan2(-r[2], cosb),0);
127 }
128 
130  trafo.GetDecomposition(rot,pos);
131 }
132 
134  EulerAngles r;
135  trafo.GetDecomposition(r,pos);
136  rot.SetXYZ(r.Psi(),r.Theta(),r.Phi());
137 }
138 
140  trafo.GetDecomposition(rot,pos);
141 }
142 
144  EulerAngles r;
145  trafo.GetDecomposition(r,pos);
146  rot.SetXYZ(r.Psi(),r.Theta(),r.Phi());
147 }
Position XYZAngles
Definition: MatrixHelpers.h:31
TGeoTranslation * _translation(const Geometry::Position &pos)
Convert a Position object to a TGeoTranslation
TGeoRotation * _rotationZYX(const Geometry::RotationZYX &rot)
Convert a RotationZYX object to a TGeoRotation
XYZAngles _XYZangles(const double *matrix)
Convert a 3x3 rotation matrix to XYZAngles
void _decompose(const Geometry::Transform3D &trafo, Geometry::Position &pos, Geometry::RotationZYX &rot)
Decompose a generic Transform3D into a translation (Position) and a RotationZYX
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:98
TGeoIdentity * identityTransform()
Access the TGeo identity transformation
ROOT::Math::Rotation3D Rotation3D
Definition: Objects.h:106
TGeoRotation * _rotation3D(const Geometry::Rotation3D &rot)
Convert a Rotation3D object to a TGeoRotation
TGeoHMatrix * _transform(const Geometry::Transform3D &trans)
Convert a Transform3D object to a TGeoHMatrix
#define MM_2_CM
Definition: Handle.h:35
ROOT::Math::XYZVector Position
Definition: Objects.h:75
ROOT::Math::Translation3D Translation3D
Definition: Objects.h:112
ROOT::Math::EulerAngles EulerAngles
Definition: Objects.h:108
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:110
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294
#define RAD_2_DEGREE
Definition: Handle.h:26