]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAlignObj.cxx
Memory leak (Sacha)
[u/mrichter/AliRoot.git] / STEER / AliAlignObj.cxx
CommitLineData
c18195b9 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16//-----------------------------------------------------------------
17// Implementation of the alignment object class through
18// 1) the abstract class AliAlignObj
19// 2) two derived concrete representation of alignment object class:
20// - AliAlignObjAngles
21// - AliAlignObjMatrix
22//-----------------------------------------------------------------
fdf65bb5 23/*****************************************************************************
24 * AliAlignObjAngles: derived alignment class storing alignment information *
25 * for a single volume in form of three doubles for the translation *
26 * and three doubles for the rotation expressed with the euler angles *
27 * in the xyz-convention (http://mathworld.wolfram.com/EulerAngles.html), *
28 * also known as roll, pitch, yaw. PLEASE NOTE THE ANGLES SIGNS ARE *
29 * INVERSE WITH RESPECT TO THIS REFERENCE!!! In this way the representation*
30 * is fully consistent with the TGeo Rotation methods. *
31 *****************************************************************************/
c18195b9 32
33#include "AliAlignObj.h"
34//#include "AliLog.h"
35
36ClassImp(AliAlignObj)
37
38//_____________________________________________________________________________
39AliAlignObj::AliAlignObj():
40 fVolUID(0)
41{
42 // dummy constructor
43}
44
45//_____________________________________________________________________________
46AliAlignObj::AliAlignObj(const AliAlignObj& theAlignObj) :
47 TObject(theAlignObj)
48{
49 //copy constructor
50 fVolPath = theAlignObj.GetVolPath();
51 fVolUID = theAlignObj.GetVolUID();
52}
53
54//_____________________________________________________________________________
55AliAlignObj &AliAlignObj::operator =(const AliAlignObj& theAlignObj)
56{
57 // assignment operator
58 if(this==&theAlignObj) return *this;
59 fVolPath = theAlignObj.GetVolPath();
60 fVolUID = theAlignObj.GetVolUID();
61 return *this;
62}
63
64//_____________________________________________________________________________
65AliAlignObj::~AliAlignObj()
66{
67 // dummy destructor
68}
69
70//_____________________________________________________________________________
71void AliAlignObj::AnglesToMatrix(const Double_t *angles, Double_t *rot) const
72{
fdf65bb5 73 // Calculates the rotation matrix using the
74 // Euler angles in "x y z" notation
c18195b9 75 Double_t degrad = TMath::DegToRad();
76 Double_t sinpsi = TMath::Sin(degrad*angles[0]);
77 Double_t cospsi = TMath::Cos(degrad*angles[0]);
78 Double_t sinthe = TMath::Sin(degrad*angles[1]);
79 Double_t costhe = TMath::Cos(degrad*angles[1]);
80 Double_t sinphi = TMath::Sin(degrad*angles[2]);
81 Double_t cosphi = TMath::Cos(degrad*angles[2]);
82
83 rot[0] = costhe*cosphi;
84 rot[1] = -costhe*sinphi;
85 rot[2] = sinthe;
86 rot[3] = sinpsi*sinthe*cosphi + cospsi*sinphi;
87 rot[4] = -sinpsi*sinthe*sinphi + cospsi*cosphi;
88 rot[5] = -costhe*sinpsi;
89 rot[6] = -cospsi*sinthe*cosphi + sinpsi*sinphi;
90 rot[7] = cospsi*sinthe*sinphi + sinpsi*cosphi;
91 rot[8] = costhe*cospsi;
92}
93
94//_____________________________________________________________________________
95Bool_t AliAlignObj::MatrixToAngles(const Double_t *rot, Double_t *angles) const
96{
fdf65bb5 97 // Calculates the Euler angles in "x y z" notation
98 // using the rotation matrix
c18195b9 99 if(rot[0]<1e-7 || rot[8]<1e-7) return kFALSE;
100 Double_t raddeg = TMath::RadToDeg();
101 angles[0]=raddeg*TMath::ATan2(-rot[5],rot[8]);
102 angles[1]=raddeg*TMath::ASin(rot[2]);
103 angles[2]=raddeg*TMath::ATan2(-rot[1],rot[0]);
104 return kTRUE;
105}
106
107//_____________________________________________________________________________
108void AliAlignObj::Print(Option_t *) const
109{
110 // Print the contents of the
111 // alignment object in angles and
112 // matrix representations
113 Double_t tr[3];
114 GetTranslation(tr);
115 Double_t angles[3];
116 GetAngles(angles);
117 TGeoHMatrix m;
118 GetMatrix(m);
119 const Double_t *rot = m.GetRotationMatrix();
120 printf("Volume=%s ID=%u\n", GetVolPath(),GetVolUID());
121 printf("%12.6f%12.6f%12.6f Tx = %12.6f Psi = %12.6f\n", rot[0], rot[1], rot[2], tr[0], angles[0]);
122 printf("%12.6f%12.6f%12.6f Ty = %12.6f Theta = %12.6f\n", rot[3], rot[4], rot[5], tr[1], angles[1]);
123 printf("%12.6f%12.6f%12.6f Tz = %12.6f Phi = %12.6f\n", rot[6], rot[7], rot[8], tr[2], angles[2]);
124
125}
126
127
128//=============================================================================
129
130ClassImp(AliAlignObjAngles)
131
132//_____________________________________________________________________________
133AliAlignObjAngles::AliAlignObjAngles() //: AliAlignObj()
134{
135 // default constructor
136 fTranslation[0]=fTranslation[1]=fTranslation[2]=0.;
137 fRotation[0]=fRotation[1]=fRotation[2]=0.;
138}
139
140//_____________________________________________________________________________
141AliAlignObjAngles::AliAlignObjAngles(const AliAlignObjAngles& theAlignObj) :
142 AliAlignObj(theAlignObj)
143{
144 // copy constructor
145 Double_t tr[3];
146 theAlignObj.GetTranslation(tr);
147 SetTranslation(tr[0],tr[1],tr[2]);
148 Double_t rot[3];
149 theAlignObj.GetAngles(rot);
150 SetRotation(rot[0],rot[1],rot[2]);
151}
152
153//_____________________________________________________________________________
154AliAlignObjAngles &AliAlignObjAngles::operator =(const AliAlignObjAngles& theAlignObj)
155{
156 // assignment operator
157 if(this==&theAlignObj) return *this;
158 ((AliAlignObj *)this)->operator=(theAlignObj);
159
160 Double_t tr[3];
161 theAlignObj.GetTranslation(tr);
162 SetTranslation(tr[0],tr[1],tr[2]);
163 Double_t rot[3];
164 theAlignObj.GetAngles(rot);
165 SetRotation(rot[0],rot[1],rot[2]);
166 return *this;
167}
168
169//_____________________________________________________________________________
170AliAlignObjAngles::~AliAlignObjAngles()
171{
172 // default destructor
173}
174
175//_____________________________________________________________________________
176void AliAlignObjAngles::SetTranslation(const TGeoMatrix& m)
177{
fdf65bb5 178 // Sets the translation parameters from an existing TGeoMatrix
c18195b9 179 if(m.IsTranslation()){
180 const Double_t* tr = m.GetTranslation();
181 fTranslation[0]=tr[0]; fTranslation[1]=tr[1]; fTranslation[2]=tr[2];
182 }else{
183// AliWarning("Argument matrix is not a translation! Setting zero-translation.");
184 fTranslation[0] = fTranslation[1] = fTranslation[2] = 0.;
185 }
186}
187
188//_____________________________________________________________________________
189Bool_t AliAlignObjAngles::SetRotation(const TGeoMatrix& m)
190{
fdf65bb5 191 // Sets the rotation components from an existing TGeoMatrix
c18195b9 192 if(m.IsRotation()){
193 const Double_t* rot = m.GetRotationMatrix();
194 return MatrixToAngles(rot,fRotation);
195 }else{
196// AliWarning("Argument matrix is not a rotation! Setting yaw-pitch-roll to zero.");
197 fRotation[0] = fRotation[1] = fRotation[2] = 0.;
198 return kTRUE;
199 }
200}
201
202//_____________________________________________________________________________
203void AliAlignObjAngles::SetMatrix(const TGeoMatrix& m)
204{
fdf65bb5 205 // Sets both the rotation and translation components from an
206 // existing TGeoMatrix
c18195b9 207 SetTranslation(m);
208 SetRotation(m);
209}
210
211//_____________________________________________________________________________
212void AliAlignObjAngles::GetPars(Double_t tr[], Double_t angles[]) const
213{
fdf65bb5 214 // Returns the translations and the rotation angles
c18195b9 215 GetTranslation(tr);
216 GetAngles(angles);
217}
218
219//_____________________________________________________________________________
220void AliAlignObjAngles::GetMatrix(TGeoHMatrix& m) const
221{
fdf65bb5 222 // Extracts the information in an existing TGeoHMatrix using the translations
223 // and the rotation parameters
c18195b9 224 m.SetTranslation(&fTranslation[0]);
225 Double_t rot[9];
226 AnglesToMatrix(fRotation,rot);
227 m.SetRotation(rot);
228}
229
230//=============================================================================
231
232ClassImp(AliAlignObjMatrix)
233
234//_____________________________________________________________________________
235AliAlignObjMatrix::AliAlignObjMatrix() : AliAlignObj()
236{
237 // Default constructor
238}
239
240AliAlignObjMatrix::AliAlignObjMatrix(const AliAlignObjMatrix& theAlignObj) :
241 AliAlignObj(theAlignObj)
242{
243 //copy constructor
244 //
245 Double_t tr[3];
246 theAlignObj.GetTranslation(tr);
247 SetTranslation(tr[0],tr[1],tr[2]);
248 Double_t rot[3];
249 theAlignObj.GetAngles(rot);
250 SetRotation(rot[0],rot[1],rot[2]);
251}
252
253AliAlignObjMatrix &AliAlignObjMatrix::operator =(const AliAlignObjMatrix& theAlignObj)
254{
255 // assignment operator
256 //
257 if(this==&theAlignObj) return *this;
258 ((AliAlignObj *)this)->operator=(theAlignObj);
259 Double_t tr[3];
260 theAlignObj.GetTranslation(tr);
261 SetTranslation(tr[0],tr[1],tr[2]);
262 Double_t rot[3];
263 theAlignObj.GetAngles(rot);
264 SetRotation(rot[0],rot[1],rot[2]);
265 return *this;
266}
267
268AliAlignObjMatrix::~AliAlignObjMatrix()
269{
270 // Destructor
271 //
272}
273
274//_____________________________________________________________________________
275void AliAlignObjMatrix::SetTranslation(Double_t x, Double_t y, Double_t z)
276{
fdf65bb5 277 // Sets the translation parameters
c18195b9 278 Double_t tr[3];
279 tr[0]=x; tr[1]=y; tr[2]=z;
280 fMatrix.SetTranslation(tr);
281}
282
283//_____________________________________________________________________________
284void AliAlignObjMatrix::SetTranslation(const TGeoMatrix& m)
285{
fdf65bb5 286 // Sets the translation parameters from an existing TGeoMatrix
c18195b9 287 const Double_t *tr = m.GetTranslation();
288 fMatrix.SetTranslation(tr);
289}
290
291//_____________________________________________________________________________
292void AliAlignObjMatrix::SetRotation(Double_t psi, Double_t theta, Double_t phi)
293{
fdf65bb5 294 // Sets the rotation parameters
c18195b9 295 Double_t angles[3] = {psi, theta, phi};
296 Double_t rot[9];
297 AnglesToMatrix(angles,rot);
298 fMatrix.SetRotation(rot);
299}
300
301//_____________________________________________________________________________
302Bool_t AliAlignObjMatrix::SetRotation(const TGeoMatrix& m)
303{
fdf65bb5 304 // Sets the rotation parameters from an existing TGeoMatrix
c18195b9 305 const Double_t* rot = m.GetRotationMatrix();
306 fMatrix.SetRotation(rot);
307 return kTRUE;
308}
309
310//_____________________________________________________________________________
311void AliAlignObjMatrix::SetMatrix(const TGeoMatrix& m)
312{
313 // Set rotation matrix and translation
314 // using TGeoMatrix
315 SetTranslation(m);
316 SetRotation(m);
317}
318
319//_____________________________________________________________________________
320void AliAlignObjMatrix::SetPars(Double_t x, Double_t y, Double_t z,
321 Double_t psi, Double_t theta, Double_t phi)
322{
323 // Set rotation matrix and translation
324 // using 3 angles and 3 translations
325 SetTranslation(x,y,z);
326 SetRotation(psi,theta,phi);
327}
328
329//_____________________________________________________________________________
330void AliAlignObjMatrix::GetTranslation(Double_t *tr) const
331{
332 // Get Translation from TGeoMatrix
333 const Double_t* translation = fMatrix.GetTranslation();
334 tr[0] = translation[0];
335 tr[1] = translation[1];
336 tr[2] = translation[2];
337}
338
339//_____________________________________________________________________________
340Bool_t AliAlignObjMatrix::GetAngles(Double_t *angles) const
341{
342 // Get rotation angles from the TGeoHMatrix
343 const Double_t* rot = fMatrix.GetRotationMatrix();
344 return MatrixToAngles(rot,angles);
345}
346
347//_____________________________________________________________________________
348void AliAlignObjMatrix::GetPars(Double_t tr[], Double_t angles[]) const
349{
fdf65bb5 350 // Gets the translations and the rotation angles
c18195b9 351 GetTranslation(tr);
352 GetAngles(angles);
353}
354
355//_____________________________________________________________________________
356void AliAlignObjMatrix::GetMatrix(TGeoHMatrix& m) const
357{
fdf65bb5 358 // Extracts the translations and the rotation parameters
359 // in an existing TGeoHMatrix
c18195b9 360 const Double_t *tr = fMatrix.GetTranslation();
361 m.SetTranslation(tr);
362 const Double_t *rot = fMatrix.GetRotationMatrix();
363 m.SetRotation(rot);
364}
365