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