Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 "TGeometry.h"
15#include "TMath.h"
16
17
18/** \class TRotMatrix
19\ingroup g3d
20Manages a detector rotation matrix. See class TGeometry.
21*/
22
23////////////////////////////////////////////////////////////////////////////////
24/// RotMatrix default constructor.
25
27{
28 for (int i=0;i<9;i++) fMatrix[i] = 0;
29 fNumber = 0;
30 fPhi = 0;
31 fPsi = 0;
32 fTheta = 0;
33 fType = 0;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37/// RotMatrix normal constructor.
38
39TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t *matrix)
40 :TNamed(name,title)
41{
42 fNumber = 0;
43 fPhi = 0;
44 fPsi = 0;
45 fTheta = 0;
46 fType = 0;
47
48 if (!matrix) { Error("ctor","No rotation is supplied"); return; }
49
51 if (!gGeometry) gGeometry = new TGeometry();
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// RotMatrix normal constructor.
58
59TRotMatrix::TRotMatrix(const char *name, const char *title, Double_t theta, Double_t phi, Double_t psi)
60 :TNamed(name,title)
61{
62 printf("ERROR: This form of TRotMatrix constructor not implemented yet\n");
63
64 Int_t i;
65 fTheta = theta;
66 fPhi = phi;
67 fPsi = psi;
68 fType = 2;
69 for (i=0;i<9;i++) fMatrix[i] = 0;
70 fMatrix[0] = 1; fMatrix[4] = 1; fMatrix[8] = 1;
71
72 if (!gGeometry) gGeometry = new TGeometry();
75}
76
77////////////////////////////////////////////////////////////////////////////////
78/// RotMatrix normal constructor defined a la GEANT.
79///
80/// The TRotMatrix constructor with six angles uses the GEANT convention:
81///
82/// theta1 is the polar angle of the x-prim axis in the main reference system
83/// (MRS), theta2 and theta3 have the same meaning for the y-prim and z-prim
84/// axis.
85///
86/// Phi1 is the azimuthal angle of the x-prim in the MRS and phi2 and phi3
87/// have the same meaning for y-prim and z-prim.
88///
89///
90/// for example, the unit matrix is defined in the following way.
91/// ~~~ {.cpp}
92/// x-prim || x, y-prim || y, z-prim || z
93///
94/// means: theta1=90, theta2=90, theta3=0, phi1=0, phi2=90, phi3=0
95/// ~~~
96
108
109////////////////////////////////////////////////////////////////////////////////
110/// RotMatrix default destructor.
111
116
117////////////////////////////////////////////////////////////////////////////////
118/// Returns the value of the determinant of this matrix
119
121{
122 return
123 fMatrix[0] * (fMatrix[4]*fMatrix[8] - fMatrix[7]*fMatrix[5])
124 - fMatrix[3] * (fMatrix[1]*fMatrix[8] - fMatrix[7]*fMatrix[2])
125 + fMatrix[6] * (fMatrix[1]*fMatrix[5] - fMatrix[4]*fMatrix[2]);
126}
127
128////////////////////////////////////////////////////////////////////////////////
129/// Convert this matrix to the OpenGL [4x4]
130///
131/// ~~~ {.cpp}
132/// [ fMatrix[0] fMatrix[1] fMatrix[2] 0 ]
133/// [ fMatrix[3] fMatrix[4] fMatrix[5] 0 ]
134/// [ fMatrix[6] fMatrix[7] fMatrix[8] 0 ]
135/// [ 0 0 0 1 ]
136/// ~~~
137///
138/// Input:
139///
140/// Double_t *rGLMatrix: pointer to Double_t 4x4 buffer array
141///
142/// Return:
143///
144/// Double_t*: pointer to the input buffer
145
147{
149 const Double_t *matrix = fMatrix;
150 if (rGLMatrix)
151 {
152 for (Int_t i=0;i<3;i++) {
153 for (Int_t j=0;j<3;j++) memcpy(glmatrix,matrix,3*sizeof(Double_t));
154 matrix += 3;
155 glmatrix += 3;
156 *glmatrix = 0.0;
157 glmatrix++;
158 }
159 for (Int_t j=0;j<3;j++) {
160 *glmatrix = 0.0;
161 glmatrix++;
162 }
163 *glmatrix = 1.0;
164 }
165 return rGLMatrix;
166}
167
168////////////////////////////////////////////////////////////////////////////////
169/// theta1 is the polar angle of the x-prim axis in the main reference system
170/// (MRS), theta2 and theta3 have the same meaning for the y-prim and z-prim
171/// axis.
172///
173/// Phi1 is the azimuthal angle of the x-prim in the MRS and phi2 and phi3
174/// have the same meaning for y-prim and z-prim.
175///
176///
177/// for example, the unit matrix is defined in the following way.
178///
179/// ~~~ {.cpp}
180/// x-prim || x, y-prim || y, z-prim || z
181///
182/// means: theta1=90, theta2=90, theta3=0, phi1=0, phi2=90, phi3=0
183/// ~~~
184
210
211////////////////////////////////////////////////////////////////////////////////
212/// copy predefined 3x3 matrix into TRotMatrix object
213
215{
216 fTheta = 0;
217 fPhi = 0;
218 fPsi = 0;
219 fType = 0;
220 if (!matrix) return;
221 fType = 2;
222 memcpy(fMatrix,matrix,9*sizeof(Double_t));
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Checks whether the determinant of this
228/// matrix defines the reflection transformation
229/// and set the "reflection" flag if any
230
236
237////////////////////////////////////////////////////////////////////////////////
238/// Stream an object of class TRotMatrix.
239
241{
242 if (R__b.IsReading()) {
244 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
245 if (R__v > 1) {
246 R__b.ReadClassBuffer(TRotMatrix::Class(), this, R__v, R__s, R__c);
247 return;
248 }
249 //====process old versions before automatic schema evolution
251 R__b >> fNumber;
252 R__b >> fType;
253 R__b >> fTheta;
254 R__b >> fPhi;
255 R__b >> fPsi;
256 R__b.ReadStaticArray(fMatrix);
257 R__b.CheckByteCount(R__s, R__c, TRotMatrix::IsA());
258 //====end of old versions
259
260 } else {
261 R__b.WriteClassBuffer(TRotMatrix::Class(),this);
262 }
263}
short Version_t
Class version identifier (short)
Definition RtypesCore.h:79
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char name[80]
Definition TGX11.cxx:110
R__EXTERN TGeometry * gGeometry
Definition TGeometry.h:158
Buffer base class used for serializing objects.
Definition TBuffer.h:43
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
TGeometry description.
Definition TGeometry.h:39
THashList * GetListOfMatrices() const
Definition TGeometry.h:78
TObject * Remove(TObject *obj) override
Remove object from the list.
void Add(TObject *obj) override
Definition TList.h:81
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
void Streamer(TBuffer &) override
Stream an object of class TObject.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:864
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
void ResetBit(UInt_t f)
Definition TObject.h:201
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...
TClass * IsA() const override
Definition TRotMatrix.h:66
Double_t fTheta
Definition TRotMatrix.h:35
Double_t fPsi
Definition TRotMatrix.h:37
static TClass * Class()
void Streamer(TBuffer &) override
Stream an object of class TRotMatrix.
Double_t fPhi
Definition TRotMatrix.h:36
~TRotMatrix() override
RotMatrix default destructor.
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...
virtual void SetMatrix(const Double_t *matrix)
copy predefined 3x3 matrix into TRotMatrix object
TRotMatrix()
RotMatrix default constructor.
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.
virtual Double_t * GetGLMatrix(Double_t *rGLMatrix) const
Convert this matrix to the OpenGL [4x4].
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Definition TMath.h:605
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Definition TMath.h:599