EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairGeoTransform.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairGeoTransform.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Modified : 16/06/1999
3 //*-- Modified : 21/06/2005 D.Bertini
4 
6 //
7 // FairGeoTransform
8 //
9 // Class to hold the orientation (rotation matrix) and the position
10 // (translation vector) of a coordinate system (system 2) relative to a
11 // reference coordinate system (system 1)
12 // It provides member functions to transform a vector or a point and an other
13 // coordinate system from its own coordinate system into the reference
14 // coordinate system and vice versa.
15 // Instances of this class can e.g. hold the lab or detector transformation of
16 // a geometry volume (see class FairGeoVolume)
17 //
18 // Inline functions:
19 //
20 // FairGeoTransform()
21 // The default constructor creates an identity transformation
22 // FairGeoTransform(FairGeoTransform& t)
23 // copy constructor
24 // void setTransform(const FairGeoTransform& t)
25 // copies the given transformation
26 // void setRotMatrix(const FairGeoRotation& r)
27 // copies the given rotation matrix
28 // void setRotMatrix(const Double_t* a)
29 // creates a rotation matrix taking an Double_t array with 9 components
30 // void setTransVector(const FairGeoVector& t)
31 // copies the given translation vector
32 // void setTransVector(const Double_t* a)
33 // creates a translation vector taking an Double_t array with 6 components
34 // const FairGeoRotation& getRotMatrix() const
35 // returns the rotation matrix
36 // const FairGeoVector& getTransVector() const
37 // returns the translation vector
38 //
40 
41 #include "FairGeoTransform.h"
42 
43 //#include <iostream>
44 //#include <iomanip>
45 //#include "math.h"
46 
49  : TObject(),
50  rot(FairGeoRotation(0,0,0)),
51  trans(FairGeoVector(0,0,0)),
52  trans_cm(FairGeoVector(0,0,0))
53 {
54 
55 }
57 {
58  rot=t.getRotMatrix();
60 
61  return *this;
62 }
63 
64 
66 {
67  // Transforms a vector (point) given in its own coordinate
68  // system (2) into the reference coordinate system (1)
69  // e.g. v2 is a vector (point) in the detector coordinate system;
70  // it can be transformed to a vector v2 the lab system with
71  // FairGeoVector v2=mo.transFrom(v1)
72  // where mo is the coordinate system of the mother
73  return rot*p+trans;
74 }
75 
77 {
78  // Transforms a vector (point) given in the reference system (1)
79  // into the local coordinate system (2)
80  // e.g. v1 is a vector (point) in the lab system; it can be transformed to
81  // a vector v2 the detector coordinate system with
82  // FairGeoVector v2=mo.transTo(v1)
83  // where mo is the coordinate system of the mother
84  return rot.inverse()*(p-trans);
85 }
86 
88 {
89  // Transforms the coordinate system into the coordinate system
90  // described by s. Both transformations must have the same reference
91  // system e.g. the lab system
92  // This function is e.g. used to transform a daughter coordinate system
93  // with a transformation relative to the lab into the detector coordinate
94  // system.
95  const FairGeoRotation& rm=s.getRotMatrix();
96  FairGeoRotation rt(rm.inverse());
97  if (rm.diff2(rot)<0.000001) { rot.setUnitMatrix(); }
98  else { rot.transform(rt); }
99  trans-=s.getTransVector();
100  trans=rt*trans;
101  // trans.round(3); // rounds to 3 digits (precision 1 micrometer)
102 }
103 
105 {
106  // Transforms the coordinate system described by s into the local
107  // coordinate system
108  // This function is e.g. used to transform a daughter coordinate system
109  // with a transformation relative to its mother into the lab system.
110  // e.g. daughterDetTransform.transFrom(motherLabTransform)
111  const FairGeoRotation& r=s.getRotMatrix();
112  rot.transform(r);
113  trans=r*trans;
114  trans+=s.getTransVector();
115 }
116 
118 {
119  trans.clear();
120  rot.setUnitMatrix();
121 }
122 
124 {
125  rot.print();
126  trans.print();
127 }
128 
130 {
131  rot.invert();
132  trans = rot*trans;
133  trans *= -1.;
134 }