12 #ifndef ROOT_TGeoMatrix
13 #define ROOT_TGeoMatrix
24 const Double_t kNullVector[3] = {0.0, 0.0, 0.0};
26 const Double_t kIdentityMatrix[3*3] = {1.0, 0.0, 0.0,
30 const Double_t kUnitScale[3] = {1.0, 1.0, 1.0};
40 class TGeoMatrix :
public TNamed
43 enum EGeoTransfTypes {
46 kGeoTranslation = BIT(17),
47 kGeoRotation = BIT(18),
49 kGeoReflection = BIT(20),
50 kGeoRegistered = BIT(21),
51 kGeoSavePrimitive = BIT(22),
52 kGeoMatrixOwned = BIT(23),
53 kGeoCombiTrans = kGeoTranslation | kGeoRotation,
54 kGeoGenTrans = kGeoTranslation | kGeoRotation | kGeoScale,
55 kGeoMatrixBits = kGeoShared | kGeoGenTrans | kGeoReflection | kGeoRegistered | kGeoSavePrimitive | kGeoMatrixOwned
59 TGeoMatrix(
const TGeoMatrix &other);
63 TGeoMatrix(
const char *name);
64 virtual ~TGeoMatrix();
66 Bool_t IsIdentity()
const {
return !TestBit(kGeoGenTrans);}
67 Bool_t IsTranslation()
const {
return TestBit(kGeoTranslation);}
68 Bool_t IsRotation()
const {
return TestBit(kGeoRotation);}
69 Bool_t IsReflection()
const {
return TestBit(kGeoReflection);}
70 Bool_t IsScale()
const {
return TestBit(kGeoScale);}
71 Bool_t IsShared()
const {
return TestBit(kGeoShared);}
72 Bool_t IsOwned()
const {
return TestBit(kGeoMatrixOwned);}
73 Bool_t IsCombi()
const {
return (TestBit(kGeoTranslation)
74 && TestBit(kGeoRotation));}
75 Bool_t IsGeneral()
const {
return (TestBit(kGeoTranslation)
76 && TestBit(kGeoRotation) && TestBit(kGeoScale));}
77 Bool_t IsRegistered()
const {
return TestBit(kGeoRegistered);}
78 Bool_t IsRotAboutZ()
const;
79 void GetHomogenousMatrix(Double_t *hmat)
const;
80 char *GetPointerName()
const;
82 virtual Int_t GetByteCount()
const;
83 virtual const Double_t *GetTranslation()
const = 0;
84 virtual const Double_t *GetRotationMatrix()
const = 0;
85 virtual const Double_t *GetScale()
const = 0;
86 virtual TGeoHMatrix Inverse()
const = 0;
87 virtual void LocalToMaster(
const Double_t *local, Double_t *master)
const;
88 virtual void LocalToMasterVect(
const Double_t *local, Double_t *master)
const;
89 virtual void LocalToMasterBomb(
const Double_t *local, Double_t *master)
const;
90 virtual TGeoMatrix *MakeClone()
const = 0;
91 virtual void MasterToLocal(
const Double_t *master, Double_t *local)
const;
92 virtual void MasterToLocalVect(
const Double_t *master, Double_t *local)
const;
93 virtual void MasterToLocalBomb(
const Double_t *master, Double_t *local)
const;
94 static void Normalize(Double_t *vect);
95 void Print(Option_t *option=
"")
const;
96 virtual void RotateX(Double_t) {}
97 virtual void RotateY(Double_t) {}
98 virtual void RotateZ(Double_t) {}
99 virtual void ReflectX(Bool_t leftside,Bool_t rotonly=kFALSE);
100 virtual void ReflectY(Bool_t leftside,Bool_t rotonly=kFALSE);
101 virtual void ReflectZ(Bool_t leftside,Bool_t rotonly=kFALSE);
102 virtual void RegisterYourself();
103 void SetDefaultName();
104 virtual void SetDx(Double_t) {}
105 virtual void SetDy(Double_t) {}
106 virtual void SetDz(Double_t) {}
107 void SetShared(Bool_t flag=kTRUE) {SetBit(kGeoShared, flag);}
109 ClassDef(TGeoMatrix, 1)
121 class TGeoTranslation :
public TGeoMatrix
124 Double_t fTranslation[3];
127 TGeoTranslation(
const TGeoTranslation &other);
128 TGeoTranslation(
const TGeoMatrix &other);
129 TGeoTranslation(Double_t dx, Double_t dy, Double_t dz);
130 TGeoTranslation(
const char *name, Double_t dx, Double_t dy, Double_t dz);
131 virtual ~TGeoTranslation() {}
133 TGeoTranslation &operator =(
const TGeoTranslation &other) {
return TGeoTranslation::operator=((TGeoMatrix&)other);}
134 TGeoTranslation &operator =(
const TGeoMatrix &matrix);
135 TGeoTranslation &operator *=(
const TGeoTranslation &other);
136 TGeoTranslation operator *(
const TGeoTranslation &right)
const;
137 TGeoHMatrix operator *(
const TGeoMatrix &right)
const;
138 Bool_t operator ==(
const TGeoTranslation &other)
const;
140 void Add(
const TGeoTranslation *other);
141 TGeoHMatrix Inverse()
const;
142 virtual void LocalToMaster(
const Double_t *local, Double_t *master)
const;
143 virtual void LocalToMasterVect(
const Double_t *local, Double_t *master)
const;
144 virtual void LocalToMasterBomb(
const Double_t *local, Double_t *master)
const;
145 virtual TGeoMatrix *MakeClone()
const;
146 virtual void MasterToLocal(
const Double_t *master, Double_t *local)
const;
147 virtual void MasterToLocalVect(
const Double_t *master, Double_t *local)
const;
148 virtual void MasterToLocalBomb(
const Double_t *master, Double_t *local)
const;
149 virtual void RotateX(Double_t angle);
150 virtual void RotateY(Double_t angle);
151 virtual void RotateZ(Double_t angle);
152 virtual void SavePrimitive(std::ostream &out, Option_t *option =
"");
153 void Subtract(
const TGeoTranslation *other);
154 void SetTranslation(Double_t dx, Double_t dy, Double_t dz);
155 void SetTranslation(
const TGeoMatrix &other);
156 virtual void SetDx(Double_t dx) {SetTranslation(dx, fTranslation[1], fTranslation[2]);}
157 virtual void SetDy(Double_t dy) {SetTranslation(fTranslation[0], dy, fTranslation[2]);}
158 virtual void SetDz(Double_t dz) {SetTranslation(fTranslation[0], fTranslation[1], dz);}
160 virtual const Double_t *GetTranslation()
const {
return &fTranslation[0];}
161 virtual const Double_t *GetRotationMatrix()
const {
return &kIdentityMatrix[0];}
162 virtual const Double_t *GetScale()
const {
return &kUnitScale[0];}
164 ClassDef(TGeoTranslation, 1)
174 class TGeoRotation :
public TGeoMatrix
177 Double_t fRotationMatrix[3*3];
182 TGeoRotation(
const TGeoRotation &other);
183 TGeoRotation(
const TGeoMatrix &other);
184 TGeoRotation(
const char *name);
186 TGeoRotation(
const char *name, Double_t phi, Double_t theta, Double_t psi);
187 TGeoRotation(
const char *name, Double_t theta1, Double_t phi1, Double_t theta2, Double_t phi2,
188 Double_t theta3, Double_t phi3);
189 virtual ~TGeoRotation() {}
191 TGeoRotation &operator =(
const TGeoRotation &other) {
return TGeoRotation::operator=((TGeoMatrix&)other);}
192 TGeoRotation &operator =(
const TGeoMatrix &other);
193 TGeoRotation &operator *=(
const TGeoRotation &other);
194 TGeoRotation operator *(
const TGeoRotation &other)
const;
195 TGeoHMatrix operator *(
const TGeoMatrix &right)
const;
196 Bool_t operator ==(
const TGeoRotation &other)
const;
198 Bool_t IsValid()
const;
199 TGeoHMatrix Inverse()
const;
200 void Clear(Option_t *option =
"");
201 Double_t Determinant()
const;
202 void FastRotZ(
const Double_t *sincos);
203 void GetAngles(Double_t &theta1, Double_t &phi1, Double_t &theta2, Double_t &phi2,
204 Double_t &theta3, Double_t &phi3)
const;
205 void GetAngles(Double_t &phi, Double_t &theta, Double_t &psi)
const;
206 Double_t GetPhiRotation(Bool_t fixX=kFALSE)
const;
207 virtual void LocalToMaster(
const Double_t *local, Double_t *master)
const;
208 virtual void LocalToMasterVect(
const Double_t *local, Double_t *master)
const {TGeoRotation::LocalToMaster(local, master);}
209 virtual void LocalToMasterBomb(
const Double_t *local, Double_t *master)
const {TGeoRotation::LocalToMaster(local, master);}
210 virtual TGeoMatrix *MakeClone()
const;
211 virtual void MasterToLocal(
const Double_t *master, Double_t *local)
const;
212 virtual void MasterToLocalVect(
const Double_t *master, Double_t *local)
const {TGeoRotation::MasterToLocal(master, local);}
213 virtual void MasterToLocalBomb(
const Double_t *master, Double_t *local)
const {TGeoRotation::MasterToLocal(master, local);}
214 void MultiplyBy(
const TGeoRotation *rot, Bool_t after=kTRUE);
215 virtual void RotateX(Double_t angle);
216 virtual void RotateY(Double_t angle);
217 virtual void RotateZ(Double_t angle);
218 virtual void SavePrimitive(std::ostream &out, Option_t *option =
"");
219 virtual void ReflectX(Bool_t leftside, Bool_t rotonly=kFALSE);
220 virtual void ReflectY(Bool_t leftside, Bool_t rotonly=kFALSE);
221 virtual void ReflectZ(Bool_t leftside, Bool_t rotonly=kFALSE);
222 void SetAngles(Double_t phi, Double_t theta, Double_t psi);
223 void SetAngles(Double_t theta1, Double_t phi1, Double_t theta2, Double_t phi2,
224 Double_t theta3, Double_t phi3);
225 void SetMatrix(
const Double_t *rot) {memcpy(&fRotationMatrix[0], rot, 9*
sizeof(Double_t));CheckMatrix();}
226 void SetRotation(
const TGeoMatrix &other);
227 void GetInverse(Double_t *invmat)
const;
229 virtual const Double_t *GetTranslation()
const {
return &kNullVector[0];}
230 virtual const Double_t *GetRotationMatrix()
const {
return &fRotationMatrix[0];}
231 virtual const Double_t *GetScale()
const {
return &kUnitScale[0];}
233 ClassDef(TGeoRotation, 1)
244 class TGeoScale :
public TGeoMatrix
250 TGeoScale(
const TGeoScale &other);
251 TGeoScale(
const TGeoMatrix &other);
252 TGeoScale(Double_t sx, Double_t sy, Double_t sz);
253 TGeoScale(
const char *name, Double_t sx, Double_t sy, Double_t sz);
254 virtual ~TGeoScale();
256 TGeoScale &operator =(
const TGeoScale &other) {
return TGeoScale::operator=((TGeoMatrix&)other);}
257 TGeoScale &operator =(
const TGeoMatrix &other);
258 TGeoScale &operator *=(
const TGeoScale &other);
259 TGeoScale operator *(
const TGeoScale &other)
const;
260 TGeoHMatrix operator *(
const TGeoMatrix &right)
const;
261 Bool_t operator ==(
const TGeoScale &other)
const;
263 TGeoHMatrix Inverse()
const;
264 void SetScale(Double_t sx, Double_t sy, Double_t sz);
265 void SetScale(
const TGeoMatrix &other);
266 virtual void LocalToMaster(
const Double_t *local, Double_t *master)
const;
267 Double_t LocalToMaster(Double_t dist,
const Double_t *dir=0)
const;
268 virtual void LocalToMasterVect(
const Double_t *local, Double_t *master)
const {TGeoScale::LocalToMaster(local, master);}
269 virtual TGeoMatrix *MakeClone()
const;
270 virtual void MasterToLocal(
const Double_t *master, Double_t *local)
const;
271 Double_t MasterToLocal(Double_t dist,
const Double_t *dir=0)
const;
272 virtual void MasterToLocalVect(
const Double_t *master, Double_t *local)
const {TGeoScale::MasterToLocal(master, local);}
273 virtual void ReflectX(Bool_t, Bool_t) {fScale[0]=-fScale[0]; SetBit(kGeoReflection, !IsReflection());}
274 virtual void ReflectY(Bool_t, Bool_t) {fScale[1]=-fScale[1]; SetBit(kGeoReflection, !IsReflection());}
275 virtual void ReflectZ(Bool_t, Bool_t) {fScale[2]=-fScale[2]; SetBit(kGeoReflection, !IsReflection());}
277 virtual const Double_t *GetTranslation()
const {
return &kNullVector[0];}
278 virtual const Double_t *GetRotationMatrix()
const {
return &kIdentityMatrix[0];}
279 virtual const Double_t *GetScale()
const {
return &fScale[0];}
281 ClassDef(TGeoScale, 1)
291 class TGeoCombiTrans :
public TGeoMatrix
294 Double_t fTranslation[3];
295 TGeoRotation *fRotation;
298 TGeoCombiTrans(
const TGeoCombiTrans &other) : TGeoCombiTrans((TGeoMatrix&)other) {}
299 TGeoCombiTrans(
const TGeoMatrix &other);
300 TGeoCombiTrans(
const TGeoTranslation &tr,
const TGeoRotation &rot);
301 TGeoCombiTrans(
const char *name);
302 TGeoCombiTrans(Double_t dx, Double_t dy, Double_t dz, TGeoRotation *rot);
303 TGeoCombiTrans(
const char *name, Double_t dx, Double_t dy, Double_t dz, TGeoRotation *rot);
305 TGeoCombiTrans& operator =(
const TGeoCombiTrans &other) {
return TGeoCombiTrans::operator=((TGeoMatrix&)other);}
306 TGeoCombiTrans& operator =(
const TGeoMatrix &matrix);
307 TGeoCombiTrans &operator *=(
const TGeoMatrix &other);
308 TGeoCombiTrans operator *(
const TGeoMatrix &other)
const;
309 Bool_t operator ==(
const TGeoMatrix &other)
const;
311 virtual ~TGeoCombiTrans();
313 void Clear(Option_t *option =
"");
314 TGeoHMatrix Inverse()
const;
315 virtual TGeoMatrix *MakeClone()
const;
316 void Multiply(
const TGeoMatrix *right);
317 virtual void RegisterYourself();
318 virtual void RotateX(Double_t angle);
319 virtual void RotateY(Double_t angle);
320 virtual void RotateZ(Double_t angle);
321 virtual void ReflectX(Bool_t leftside, Bool_t rotonly=kFALSE);
322 virtual void ReflectY(Bool_t leftside, Bool_t rotonly=kFALSE);
323 virtual void ReflectZ(Bool_t leftside, Bool_t rotonly=kFALSE);
324 virtual void SavePrimitive(std::ostream &out, Option_t *option =
"");
325 virtual void SetDx(Double_t dx) {SetTranslation(dx, fTranslation[1], fTranslation[2]);}
326 virtual void SetDy(Double_t dy) {SetTranslation(fTranslation[0], dy, fTranslation[2]);}
327 virtual void SetDz(Double_t dz) {SetTranslation(fTranslation[0], fTranslation[1], dz);}
328 void SetTranslation(
const TGeoTranslation &tr);
329 void SetTranslation(Double_t dx, Double_t dy, Double_t dz);
330 void SetTranslation(Double_t *vect);
331 void SetRotation(
const TGeoRotation &other);
332 void SetRotation(
const TGeoRotation *rot);
334 TGeoRotation *GetRotation()
const {
return fRotation;}
336 virtual const Double_t *GetTranslation()
const {
return &fTranslation[0];}
337 virtual const Double_t *GetRotationMatrix()
const;
338 virtual const Double_t *GetScale()
const {
return &kUnitScale[0];}
340 ClassDef(TGeoCombiTrans, 1)
350 class TGeoGenTrans :
public TGeoCombiTrans
356 TGeoGenTrans(
const char *name);
357 TGeoGenTrans(Double_t dx, Double_t dy, Double_t dz,
358 Double_t sx, Double_t sy, Double_t sz, TGeoRotation *rot);
359 TGeoGenTrans(
const char *name, Double_t dx, Double_t dy, Double_t dz,
360 Double_t sx, Double_t sy, Double_t sz, TGeoRotation *rot);
361 virtual ~TGeoGenTrans();
363 void Clear(Option_t *option =
"");
364 TGeoHMatrix Inverse()
const;
365 void SetScale(Double_t sx, Double_t sy, Double_t sz);
366 void SetScale(Double_t *scale) {memcpy(&fScale[0], scale, 3*
sizeof(Double_t));}
367 virtual TGeoMatrix *MakeClone()
const {
return NULL;}
370 virtual const Double_t *GetScale()
const {
return &fScale[0];}
372 ClassDef(TGeoGenTrans, 1)
383 class TGeoIdentity :
public TGeoMatrix
389 TGeoIdentity(
const char *name);
390 virtual ~TGeoIdentity() {}
392 TGeoHMatrix Inverse()
const;
393 virtual void LocalToMaster(
const Double_t *local, Double_t *master)
const {memcpy(master, local, 3*
sizeof(Double_t));}
394 virtual void LocalToMasterVect(
const Double_t *local, Double_t *master)
const {memcpy(master, local, 3*
sizeof(Double_t));}
395 virtual void LocalToMasterBomb(
const Double_t *local, Double_t *master)
const {TGeoIdentity::LocalToMaster(local, master);}
396 virtual TGeoMatrix *MakeClone()
const {
return NULL;}
397 virtual void MasterToLocal(
const Double_t *master, Double_t *local)
const {memcpy(local, master, 3*
sizeof(Double_t));}
398 virtual void MasterToLocalVect(
const Double_t *master, Double_t *local)
const {memcpy(local, master, 3*
sizeof(Double_t));}
399 virtual void MasterToLocalBomb(
const Double_t *master, Double_t *local)
const {TGeoIdentity::MasterToLocal(master, local);}
401 virtual const Double_t *GetTranslation()
const {
return &kNullVector[0];}
402 virtual const Double_t *GetRotationMatrix()
const {
return &kIdentityMatrix[0];}
403 virtual const Double_t *GetScale()
const {
return &kUnitScale[0];}
404 virtual void SavePrimitive(std::ostream &, Option_t * =
"") {;}
406 ClassDef(TGeoIdentity, 1)
420 class TGeoHMatrix :
public TGeoMatrix
423 Double_t fTranslation[3];
424 Double_t fRotationMatrix[9];
429 TGeoHMatrix(
const TGeoHMatrix &other) : TGeoHMatrix((TGeoMatrix&)other) {}
430 TGeoHMatrix(
const TGeoMatrix &matrix);
431 TGeoHMatrix(
const char *name);
432 virtual ~TGeoHMatrix();
434 TGeoHMatrix& operator =(
const TGeoHMatrix &other) {
return TGeoHMatrix::operator=((TGeoMatrix&)other);}
435 TGeoHMatrix& operator =(
const TGeoMatrix *other);
436 TGeoHMatrix& operator =(
const TGeoMatrix &other);
437 TGeoHMatrix& operator *=(
const TGeoMatrix &other);
438 TGeoHMatrix operator *(
const TGeoMatrix &other)
const;
439 Bool_t operator ==(
const TGeoMatrix &other)
const;
441 void Clear(Option_t *option =
"");
442 void CopyFrom(
const TGeoMatrix *other);
443 Double_t Determinant()
const;
444 void FastRotZ(
const Double_t *sincos);
445 TGeoHMatrix Inverse()
const;
446 virtual TGeoMatrix *MakeClone()
const;
447 void Multiply(
const TGeoMatrix *right);
448 void Multiply(
const TGeoMatrix &right) {Multiply(&right);}
449 void MultiplyLeft(
const TGeoMatrix *left);
450 void MultiplyLeft(
const TGeoMatrix &left) {MultiplyLeft(&left);}
452 virtual void RotateX(Double_t angle);
453 virtual void RotateY(Double_t angle);
454 virtual void RotateZ(Double_t angle);
455 virtual void ReflectX(Bool_t leftside, Bool_t rotonly=kFALSE);
456 virtual void ReflectY(Bool_t leftside, Bool_t rotonly=kFALSE);
457 virtual void ReflectZ(Bool_t leftside, Bool_t rotonly=kFALSE);
458 virtual void SavePrimitive(std::ostream &out, Option_t *option =
"");
459 virtual void SetDx(Double_t dx) {fTranslation[0] = dx; SetBit(kGeoTranslation);}
460 virtual void SetDy(Double_t dy) {fTranslation[1] = dy; SetBit(kGeoTranslation);}
461 virtual void SetDz(Double_t dz) {fTranslation[2] = dz; SetBit(kGeoTranslation);}
462 void SetTranslation(
const Double_t *vect) {SetBit(kGeoTranslation); memcpy(&fTranslation[0], vect, 3*
sizeof(Double_t));}
463 void SetRotation(
const Double_t *matrix) {SetBit(kGeoRotation); memcpy(&fRotationMatrix[0], matrix, 9*
sizeof(Double_t));}
464 void SetScale(
const Double_t *scale) {SetBit(kGeoScale); memcpy(&fScale[0], scale, 3*
sizeof(Double_t));}
467 virtual const Double_t *GetTranslation()
const {
return &fTranslation[0];}
468 virtual const Double_t *GetRotationMatrix()
const {
return &fRotationMatrix[0];}
469 virtual const Double_t *GetScale()
const {
return &fScale[0];}
471 virtual Double_t *GetTranslation() {
return &fTranslation[0];}
472 virtual Double_t *GetRotationMatrix() {
return &fRotationMatrix[0];}
473 virtual Double_t *GetScale() {
return &fScale[0];}
474 ClassDef(TGeoHMatrix, 1)
478 R__EXTERN TGeoIdentity *gGeoIdentity;