HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hgeomrotation.h
Go to the documentation of this file.
1 #ifndef HGEOMROTATION_H
2 #define HGEOMROTATION_H
3 using namespace std;
4 #include "TObject.h"
5 #include "hgeomvector.h"
6 #include "TRotMatrix.h"
7 #include <iostream>
8 #include <iomanip>
9 
10 class HGeomRotation : public TObject {
11 protected:
12  Double_t rot[9];
13 public:
14  inline HGeomRotation();
15  inline HGeomRotation(const Double_t*);
16  HGeomRotation(const Double_t,const Double_t,const Double_t);
18  inline void setMatrix(const Double_t*);
19  inline void setMatrix(const Float_t*);
20  void setEulerAngles(const Double_t,const Double_t,const Double_t);
21  inline void setElement(const Double_t,const Int_t);
22  inline Double_t operator () (Int_t) const;
23  inline HGeomRotation& operator = (const HGeomRotation&);
24  inline Bool_t operator == (const HGeomRotation&);
25  inline Bool_t operator != (const HGeomRotation&);
26  inline HGeomVector operator * (const HGeomVector&) const;
27  inline HGeomRotation operator * (const HGeomRotation&) const;
28  inline HGeomRotation& operator *= (const HGeomRotation&);
29  inline HGeomRotation& transform(const HGeomRotation&);
30  inline Bool_t isUnitMatrix();
31  inline HGeomRotation inverse() const;
32  inline HGeomRotation& invert();
33  inline Double_t determinant() const;
34  Double_t diff2(const HGeomRotation&) const;
35  inline Double_t getElement(Int_t i,Int_t j) const;
36  inline void setUnitMatrix();
37  inline void setZero();
38  inline void print() const;
39  TRotMatrix* createTRotMatrix(const Text_t* name="",const Text_t* title="");
40 
41  ClassDef(HGeomRotation,1) // rotation matrix
42 };
43 
44 // -------------------- inlines ---------------------------
45 
47  rot[0]=rot[4]=rot[8]=1.;
48  rot[1]=rot[2]=rot[3]=rot[5]=rot[6]=rot[7]=0.;
49 }
50 
51 inline Double_t HGeomRotation::operator () (Int_t i) const {
52  if (i>=0 && i<9) return rot[i];
53  Error("operator()","bad index");
54  return 0;
55 }
56 
57 inline HGeomRotation::HGeomRotation(const Double_t* a) {
58  for(Int_t i=0;i<9;i++) rot[i]=a[i];
59 }
60 
61 inline void HGeomRotation::setMatrix(const Double_t* a) {
62  for(Int_t i=0;i<9;i++) rot[i]=a[i];
63 }
64 
65 inline void HGeomRotation::setMatrix(const Float_t* a) {
66  for(Int_t i=0;i<9;i++) rot[i]=a[i];
67 }
68 
69 inline void HGeomRotation::setElement(const Double_t a, const Int_t i) {
70  if (i<9) rot[i]=a;
71 }
72 
73 inline Double_t HGeomRotation::getElement(Int_t i,Int_t j) const {
74  return rot[i*3+j];
75 }
76 
78  for(Int_t i=0;i<9;i++) rot[i]=r(i);
79  return *this;
80 }
81 
82 inline Bool_t HGeomRotation::operator == (const HGeomRotation& r) {
83  Int_t i=0;
84  while (i<9) {
85  if (rot[i]!=r(i)) return kFALSE;
86  i++;
87  }
88  return kTRUE;
89 }
90 
91 inline Bool_t HGeomRotation::operator != (const HGeomRotation& r) {
92  Int_t i=0;
93  while (i<9) {
94  if (rot[i]!=r(i)) return kTRUE;
95  i++;
96  }
97  return kFALSE;
98 }
99 
101  return HGeomVector(rot[0]*v(0)+rot[1]*v(1)+rot[2]*v(2),
102  rot[3]*v(0)+rot[4]*v(1)+rot[5]*v(2),
103  rot[6]*v(0)+rot[7]*v(1)+rot[8]*v(2));
104 }
105 
107  Double_t a[9];
108  for(Int_t i=0;i<9;i++) a[i]=0;
109  for(Int_t i=0;i<3;i++) {
110  for(Int_t j=0;j<3;j++) {
111  Int_t n=3*i+j;
112  for(Int_t k=0;k<3;k++) a[n]+=rot[3*i+k]*r(3*k+j);
113  }
114  }
115  return HGeomRotation(&a[0]);
116 }
117 
119  return *this=operator * (r);
120 }
121 
123  return *this=r*(*this);
124 }
125 
127  return (rot[0]==1. && rot[1]==0. && rot[2]==0. &&
128  rot[3]==0. && rot[4]==1. && rot[5]==0. &&
129  rot[6]==0. && rot[7]==0. && rot[8]==1.) ? kTRUE : kFALSE;
130 }
131 
133  Double_t a[9];
134  for(Int_t i=0;i<3;i++) {
135  for(Int_t j=0;j<3;j++) a[j+3*i]=rot[i+3*j];
136  }
137  return HGeomRotation(a);
138 }
139 
141  return *this=inverse();
142 }
143 
144 inline Double_t HGeomRotation::determinant() const {
145  return rot[0]*(rot[4]*rot[8]-rot[7]*rot[5])
146  -rot[3]*(rot[1]*rot[8]-rot[7]*rot[2])
147  +rot[6]*(rot[1]*rot[5]-rot[4]*rot[2]);
148 }
149 
151  rot[0]=rot[4]=rot[8]=1.;
152  rot[1]=rot[2]=rot[3]=rot[5]=rot[6]=rot[7]=0.;
153 }
154 
156  for(Int_t i=0;i<9;i++) rot[i]=0.;
157 }
158 
159 inline void HGeomRotation::print() const {
160  for(Int_t i=0;i<9;i++) cout<<rot[i]<<" ";
161  cout<<'\n';
162 }
163 
164 #endif /* !HGEOMROTATION_H */
Double_t getElement(Int_t i, Int_t j) const
Definition: hgeomrotation.h:73
Double_t determinant() const
HGeomRotation & invert()
Double_t operator()(Int_t) const
Definition: hgeomrotation.h:51
void setUnitMatrix()
Int_t n
void print() const
HGeomVector operator*(const HGeomVector &) const
Bool_t operator!=(const HGeomRotation &)
Definition: hgeomrotation.h:91
void setMatrix(const Double_t *)
Definition: hgeomrotation.h:61
HGeomRotation & transform(const HGeomRotation &)
Bool_t isUnitMatrix()
HGeomRotation inverse() const
Bool_t operator==(const HGeomRotation &)
Definition: hgeomrotation.h:82
void setElement(const Double_t, const Int_t)
Definition: hgeomrotation.h:69
HGeomRotation & operator*=(const HGeomRotation &)
HGeomRotation & operator=(const HGeomRotation &)
Definition: hgeomrotation.h:77