EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairGeoRotation.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairGeoRotation.cxx
1 //*-- AUTHOR : Ilse Koenig
2 //*-- Modified : 16/06/99
3 
5 // FairGeoRotation
6 //
7 // This class defines a 3x3 rotation matrix.
8 // The data are stored in a linear array with 9 Double_t
9 // components.
10 //
11 // Inline functions:
12 //
13 // Constructors:
14 // FairGeoRotation()
15 // FairGeoRotation(const FairGeoRotation& r)
16 // FairGeoRotation(const Double_t* a)
17 //
18 // Access to components:
19 // Double_t operator () (Int_t) const
20 // void setElement(const Double_t,const Int_t)
21 //
22 // Check for equality/inequality
23 // Bool_t operator == (const FairGeoRotation&)
24 // Bool_t operator != (const FairGeoRotation&)
25 //
26 // FairGeoRotation& operator = (const FairGeoRotation&);
27 // assignment
28 //
29 // void setUnitMatrix()
30 // sets identity matrix
31 //
32 // void setZero()
33 // sets all components to 0.0
34 //
35 // Bool_t isUnitMatrix()
36 // checks unity
37 //
38 // FairGeoRotation& invert()
39 // inverts the matrix
40 //
41 // FairGeoRotation inverse()
42 // copies the matrix and returns the inverse of the copy
43 //
44 // Double_t determinant() const;
45 // returns determinate
46 //
47 // FairGeoRotation& operator *= (const FairGeoRotation&);
48 // multiplies with the given rotation matrix from the right
49 //
50 // FairGeoRotation& transform(const FairGeoRotation&);
51 // multiplies with the given rotation matrix from the left
52 //
53 // FairGeoVector operator * (const FairGeoVector&) const;
54 // rotates a vector
55 //
56 // FairGeoRotation operator * (const FairGeoRotation&) const;
57 // rotates the given rotation
58 //
59 // void print()
60 // shows the matrix
61 //
62 //
63 // Euler Angles:
64 // 1. angle: rotation around z-axis --> x1, y1, z1=z
65 // 2. angle: rotation around y1-axis --> x2, y2=y1, z2
66 // 3. angle: rotation around z2-axis --> x3, y3, z3=z2
68 
69 #include "FairGeoRotation.h"
70 
72 
73 
74 FairGeoRotation::FairGeoRotation(const Double_t a,const Double_t b,
75  const Double_t c)
76  :TObject()
77 {
78  // constructor taking three Euler angles
79  setEulerAngles(a,b,c);
80 }
81 
82 
83 void FairGeoRotation::setEulerAngles(const Double_t a,const Double_t b,
84  const Double_t c)
85 {
86  // sets the matrix calculating the values from the given Euler angles
87  const double deg2rad=0.01745329252;
88  Double_t s0=TMath::Sin(a*deg2rad);
89  Double_t c0=TMath::Cos(a*deg2rad);
90  Double_t s1=TMath::Sin(b*deg2rad);
91  Double_t c1=TMath::Cos(b*deg2rad);
92  Double_t s2=TMath::Sin(c*deg2rad);
93  Double_t c2=TMath::Cos(c*deg2rad);
94  rot[0]=c0*c1*c2 - s0*s2;
95  rot[1]=-c0*c1*s2 - s0*c2;
96  rot[2]=c0*s1;
97  rot[3]=s0*c1*c2 + c0*s2;
98  rot[4]=c0*c2 - s0*c1*s2;
99  rot[5]=s0*s1;
100  rot[6]=-s1*c2;
101  rot[7]=s1*s2;
102  rot[8]=c1;
103 }
104 
105 
106 Double_t FairGeoRotation::diff2(const FairGeoRotation& r) const
107 {
108  // calculates the square of the difference between 2 matrices
109  Double_t s=0;
110  for(Int_t i=0; i<9; i++) {
111  Double_t d=rot[i]-r(i);
112  s+=d*d;
113  }
114  return s;
115 }
116 
117 
118 TRotMatrix* FairGeoRotation::createTRotMatrix(const Text_t* name,const Text_t* title)
119 {
120  // creates a TRotMatrix
121  // (uses a new() operator and the user has to take care to free the memory)
122  TRotMatrix* t=0;
123  if (isUnitMatrix()==kTRUE) { return t; }
124  Double_t a[9];
125  for(Int_t i=0; i<3; i++) {
126  for(Int_t j=0; j<3; j++) { a[j+3*i]=rot[i+3*j]; }
127  }
128  t=new TRotMatrix(name,title,a);
129  return t;
130 }
131