Logo ROOT  
Reference Guide
TRotMatrix.cxx
Go to the documentation of this file.
1// @(#)root/g3d:$Id$
2// Author: Rene Brun 14/09/95
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TRotMatrix.h"
13#include "TBuffer.h"
14#include "TClass.h"
15#include "TGeometry.h"
16#include "TMath.h"
17
19
20/** \class TRotMatrix
21\ingroup g3d
22Manages a detector rotation matrix. See class TGeometry.
23*/
24
25////////////////////////////////////////////////////////////////////////////////
26/// RotMatrix default constructor.
27
29{
30 for (int i=0;i<9;i++) fMatrix[i] = 0;
31 fNumber = 0;
32 fPhi = 0;
33 fPsi = 0;
34 fTheta = 0;
35 fType = 0;
36}
37
38////////////////////////////////////////////////////////////////////////////////
39/// RotMatrix normal constructor.
40
41TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t *matrix)
42 :TNamed(name,title)
43{
44 fNumber = 0;
45 fPhi = 0;
46 fPsi = 0;
47 fTheta = 0;
48 fType = 0;
49
50 if (!matrix) { Error("ctor","No rotation is supplied"); return; }
51
52 SetMatrix(matrix);
53 if (!gGeometry) gGeometry = new TGeometry();
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// RotMatrix normal constructor.
60
61TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t theta, Double_t phi, Double_t psi)
62 :TNamed(name,title)
63{
64 printf("ERROR: This form of TRotMatrix constructor not implemented yet\n");
65
66 Int_t i;
67 fTheta = theta;
68 fPhi = phi;
69 fPsi = psi;
70 fType = 2;
71 for (i=0;i<9;i++) fMatrix[i] = 0;
72 fMatrix[0] = 1; fMatrix[4] = 1; fMatrix[8] = 1;
73
74 if (!gGeometry) gGeometry = new TGeometry();
77}
78
79////////////////////////////////////////////////////////////////////////////////
80/// RotMatrix normal constructor defined a la GEANT.
81///
82/// The TRotMatrix constructor with six angles uses the GEANT convention:
83///
84/// theta1 is the polar angle of the x-prim axis in the main reference system
85/// (MRS), theta2 and theta3 have the same meaning for the y-prim and z-prim
86/// axis.
87///
88/// Phi1 is the azimuthal angle of the x-prim in the MRS and phi2 and phi3
89/// have the same meaning for y-prim and z-prim.
90///
91///
92/// for example, the unit matrix is defined in the following way.
93/// ~~~ {.cpp}
94/// x-prim || x, y-prim || y, z-prim || z
95///
96/// means: theta1=90, theta2=90, theta3=0, phi1=0, phi2=90, phi3=0
97/// ~~~
98
99TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t theta1, Double_t phi1
100 , Double_t theta2, Double_t phi2
101 , Double_t theta3, Double_t phi3)
102 :TNamed(name,title)
103{
104 SetAngles(theta1,phi1,theta2,phi2,theta3,phi3);
105
106 if (!gGeometry) gGeometry = new TGeometry();
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// RotMatrix default destructor.
113
115{
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Returns the value of the determinant of this matrix
121
123{
124 return
125 fMatrix[0] * (fMatrix[4]*fMatrix[8] - fMatrix[7]*fMatrix[5])
126 - fMatrix[3] * (fMatrix[1]*fMatrix[8] - fMatrix[7]*fMatrix[2])
127 + fMatrix[6] * (fMatrix[1]*fMatrix[5] - fMatrix[4]*fMatrix[2]);
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Convert this matrix to the OpenGL [4x4]
132///
133/// ~~~ {.cpp}
134/// [ fMatrix[0] fMatrix[1] fMatrix[2] 0 ]
135/// [ fMatrix[3] fMatrix[4] fMatrix[5] 0 ]
136/// [ fMatrix[6] fMatrix[7] fMatrix[8] 0 ]
137/// [ 0 0 0 1 ]
138/// ~~~
139///
140/// Input:
141///
142/// Double_t *rGLMatrix: pointer to Double_t 4x4 buffer array
143///
144/// Return:
145///
146/// Double_t*: pointer to the input buffer
147
149{
150 Double_t *glmatrix = rGLMatrix;
151 const Double_t *matrix = fMatrix;
152 if (rGLMatrix)
153 {
154 for (Int_t i=0;i<3;i++) {
155 for (Int_t j=0;j<3;j++) memcpy(glmatrix,matrix,3*sizeof(Double_t));
156 matrix += 3;
157 glmatrix += 3;
158 *glmatrix = 0.0;
159 glmatrix++;
160 }
161 for (Int_t j=0;j<3;j++) {
162 *glmatrix = 0.0;
163 glmatrix++;
164 }
165 *glmatrix = 1.0;
166 }
167 return rGLMatrix;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171/// theta1 is the polar angle of the x-prim axis in the main reference system
172/// (MRS), theta2 and theta3 have the same meaning for the y-prim and z-prim
173/// axis.
174///
175/// Phi1 is the azimuthal angle of the x-prim in the MRS and phi2 and phi3
176/// have the same meaning for y-prim and z-prim.
177///
178///
179/// for example, the unit matrix is defined in the following way.
180///
181/// ~~~ {.cpp}
182/// x-prim || x, y-prim || y, z-prim || z
183///
184/// means: theta1=90, theta2=90, theta3=0, phi1=0, phi2=90, phi3=0
185/// ~~~
186
188 Double_t theta2, Double_t phi2,Double_t theta3, Double_t phi3)
189{
190 const Double_t degrad = 0.0174532925199432958;
191
192 fTheta = theta1;
193 fPhi = phi1;
194 fPsi = theta2;
195
196 fType = 2;
197 if (!strcmp(GetName(),"Identity")) fType = 0;
198
199 fMatrix[0] = TMath::Sin(theta1*degrad)*TMath::Cos(phi1*degrad);
200 fMatrix[1] = TMath::Sin(theta1*degrad)*TMath::Sin(phi1*degrad);
201 fMatrix[2] = TMath::Cos(theta1*degrad);
202 fMatrix[3] = TMath::Sin(theta2*degrad)*TMath::Cos(phi2*degrad);
203 fMatrix[4] = TMath::Sin(theta2*degrad)*TMath::Sin(phi2*degrad);
204 fMatrix[5] = TMath::Cos(theta2*degrad);
205 fMatrix[6] = TMath::Sin(theta3*degrad)*TMath::Cos(phi3*degrad);
206 fMatrix[7] = TMath::Sin(theta3*degrad)*TMath::Sin(phi3*degrad);
207 fMatrix[8] = TMath::Cos(theta3*degrad);
208
210 return fMatrix;
211}
212
213////////////////////////////////////////////////////////////////////////////////
214/// copy predefined 3x3 matrix into TRotMatrix object
215
217{
218 fTheta = 0;
219 fPhi = 0;
220 fPsi = 0;
221 fType = 0;
222 if (!matrix) return;
223 fType = 2;
224 memcpy(fMatrix,matrix,9*sizeof(Double_t));
226}
227
228////////////////////////////////////////////////////////////////////////////////
229/// Checks whether the determinant of this
230/// matrix defines the reflection transformation
231/// and set the "reflection" flag if any
232
234{
236 if (Determinant() < 0) { fType=1; SetBit(kReflection);}
237}
238
239////////////////////////////////////////////////////////////////////////////////
240/// Stream an object of class TRotMatrix.
241
242void TRotMatrix::Streamer(TBuffer &R__b)
243{
244 if (R__b.IsReading()) {
245 UInt_t R__s, R__c;
246 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
247 if (R__v > 1) {
248 R__b.ReadClassBuffer(TRotMatrix::Class(), this, R__v, R__s, R__c);
249 return;
250 }
251 //====process old versions before automatic schema evolution
252 TNamed::Streamer(R__b);
253 R__b >> fNumber;
254 R__b >> fType;
255 R__b >> fTheta;
256 R__b >> fPhi;
257 R__b >> fPsi;
259 R__b.CheckByteCount(R__s, R__c, TRotMatrix::IsA());
260 //====end of old versions
261
262 } else {
264 }
265}
void Class()
Definition: Class.C:29
short Version_t
Definition: RtypesCore.h:63
unsigned int UInt_t
Definition: RtypesCore.h:44
double Double_t
Definition: RtypesCore.h:57
#define ClassImp(name)
Definition: Rtypes.h:361
char name[80]
Definition: TGX11.cxx:109
R__EXTERN TGeometry * gGeometry
Definition: TGeometry.h:158
Buffer base class used for serializing objects.
Definition: TBuffer.h:42
virtual Int_t ReadClassBuffer(const TClass *cl, void *pointer, const TClass *onfile_class=0)=0
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
Bool_t IsReading() const
Definition: TBuffer.h:85
virtual Int_t ReadStaticArray(Bool_t *b)=0
virtual Int_t WriteClassBuffer(const TClass *cl, void *pointer)=0
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
Definition: TCollection.h:182
TGeometry description.
Definition: TGeometry.h:39
THashList * GetListOfMatrices() const
Definition: TGeometry.h:78
TObject * Remove(TObject *obj)
Remove object from the list.
Definition: THashList.cxx:378
virtual void Add(TObject *obj)
Definition: TList.h:87
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition: TObject.cxx:694
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:891
void ResetBit(UInt_t f)
Definition: TObject.h:186
Manages a detector rotation matrix.
Definition: TRotMatrix.h:28
virtual ~TRotMatrix()
RotMatrix default destructor.
Definition: TRotMatrix.cxx:114
virtual const Double_t * SetAngles(Double_t theta1, Double_t phi1, Double_t theta2, Double_t phi2, Double_t theta3, Double_t phi3)
theta1 is the polar angle of the x-prim axis in the main reference system (MRS), theta2 and theta3 ha...
Definition: TRotMatrix.cxx:187
Double_t fTheta
Definition: TRotMatrix.h:35
Double_t fPsi
Definition: TRotMatrix.h:37
Double_t fPhi
Definition: TRotMatrix.h:36
Int_t fNumber
Definition: TRotMatrix.h:33
virtual void SetReflection()
Checks whether the determinant of this matrix defines the reflection transformation and set the "refl...
Definition: TRotMatrix.cxx:233
virtual void SetMatrix(const Double_t *matrix)
copy predefined 3x3 matrix into TRotMatrix object
Definition: TRotMatrix.cxx:216
TRotMatrix()
RotMatrix default constructor.
Definition: TRotMatrix.cxx:28
Double_t fMatrix[9]
Definition: TRotMatrix.h:38
Int_t fType
Definition: TRotMatrix.h:34
virtual Double_t Determinant() const
Returns the value of the determinant of this matrix.
Definition: TRotMatrix.cxx:122
virtual Double_t * GetGLMatrix(Double_t *rGLMatrix) const
Convert this matrix to the OpenGL [4x4].
Definition: TRotMatrix.cxx:148
Double_t Cos(Double_t)
Definition: TMath.h:631
Double_t Sin(Double_t)
Definition: TMath.h:627