]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAlignObj.cxx
Coding conventions
[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//-----------------------------------------------------------------
23
24#include "AliAlignObj.h"
25//#include "AliLog.h"
26
27ClassImp(AliAlignObj)
28
29//_____________________________________________________________________________
30AliAlignObj::AliAlignObj():
31 fVolUID(0)
32{
33 // dummy constructor
34}
35
36//_____________________________________________________________________________
37AliAlignObj::AliAlignObj(const AliAlignObj& theAlignObj) :
38 TObject(theAlignObj)
39{
40 //copy constructor
41 fVolPath = theAlignObj.GetVolPath();
42 fVolUID = theAlignObj.GetVolUID();
43}
44
45//_____________________________________________________________________________
46AliAlignObj &AliAlignObj::operator =(const AliAlignObj& theAlignObj)
47{
48 // assignment operator
49 if(this==&theAlignObj) return *this;
50 fVolPath = theAlignObj.GetVolPath();
51 fVolUID = theAlignObj.GetVolUID();
52 return *this;
53}
54
55//_____________________________________________________________________________
56AliAlignObj::~AliAlignObj()
57{
58 // dummy destructor
59}
60
61//_____________________________________________________________________________
62void AliAlignObj::AnglesToMatrix(const Double_t *angles, Double_t *rot) const
63{
64 Double_t degrad = TMath::DegToRad();
65 Double_t sinpsi = TMath::Sin(degrad*angles[0]);
66 Double_t cospsi = TMath::Cos(degrad*angles[0]);
67 Double_t sinthe = TMath::Sin(degrad*angles[1]);
68 Double_t costhe = TMath::Cos(degrad*angles[1]);
69 Double_t sinphi = TMath::Sin(degrad*angles[2]);
70 Double_t cosphi = TMath::Cos(degrad*angles[2]);
71
72 rot[0] = costhe*cosphi;
73 rot[1] = -costhe*sinphi;
74 rot[2] = sinthe;
75 rot[3] = sinpsi*sinthe*cosphi + cospsi*sinphi;
76 rot[4] = -sinpsi*sinthe*sinphi + cospsi*cosphi;
77 rot[5] = -costhe*sinpsi;
78 rot[6] = -cospsi*sinthe*cosphi + sinpsi*sinphi;
79 rot[7] = cospsi*sinthe*sinphi + sinpsi*cosphi;
80 rot[8] = costhe*cospsi;
81}
82
83//_____________________________________________________________________________
84Bool_t AliAlignObj::MatrixToAngles(const Double_t *rot, Double_t *angles) const
85{
86 if(rot[0]<1e-7 || rot[8]<1e-7) return kFALSE;
87 Double_t raddeg = TMath::RadToDeg();
88 angles[0]=raddeg*TMath::ATan2(-rot[5],rot[8]);
89 angles[1]=raddeg*TMath::ASin(rot[2]);
90 angles[2]=raddeg*TMath::ATan2(-rot[1],rot[0]);
91 return kTRUE;
92}
93
94//_____________________________________________________________________________
95void AliAlignObj::Print(Option_t *) const
96{
97 // Print the contents of the
98 // alignment object in angles and
99 // matrix representations
100 Double_t tr[3];
101 GetTranslation(tr);
102 Double_t angles[3];
103 GetAngles(angles);
104 TGeoHMatrix m;
105 GetMatrix(m);
106 const Double_t *rot = m.GetRotationMatrix();
107 printf("Volume=%s ID=%u\n", GetVolPath(),GetVolUID());
108 printf("%12.6f%12.6f%12.6f Tx = %12.6f Psi = %12.6f\n", rot[0], rot[1], rot[2], tr[0], angles[0]);
109 printf("%12.6f%12.6f%12.6f Ty = %12.6f Theta = %12.6f\n", rot[3], rot[4], rot[5], tr[1], angles[1]);
110 printf("%12.6f%12.6f%12.6f Tz = %12.6f Phi = %12.6f\n", rot[6], rot[7], rot[8], tr[2], angles[2]);
111
112}
113
114
115//=============================================================================
116
117ClassImp(AliAlignObjAngles)
118
119//_____________________________________________________________________________
120AliAlignObjAngles::AliAlignObjAngles() //: AliAlignObj()
121{
122 // default constructor
123 fTranslation[0]=fTranslation[1]=fTranslation[2]=0.;
124 fRotation[0]=fRotation[1]=fRotation[2]=0.;
125}
126
127//_____________________________________________________________________________
128AliAlignObjAngles::AliAlignObjAngles(const AliAlignObjAngles& theAlignObj) :
129 AliAlignObj(theAlignObj)
130{
131 // copy constructor
132 Double_t tr[3];
133 theAlignObj.GetTranslation(tr);
134 SetTranslation(tr[0],tr[1],tr[2]);
135 Double_t rot[3];
136 theAlignObj.GetAngles(rot);
137 SetRotation(rot[0],rot[1],rot[2]);
138}
139
140//_____________________________________________________________________________
141AliAlignObjAngles &AliAlignObjAngles::operator =(const AliAlignObjAngles& theAlignObj)
142{
143 // assignment operator
144 if(this==&theAlignObj) return *this;
145 ((AliAlignObj *)this)->operator=(theAlignObj);
146
147 Double_t tr[3];
148 theAlignObj.GetTranslation(tr);
149 SetTranslation(tr[0],tr[1],tr[2]);
150 Double_t rot[3];
151 theAlignObj.GetAngles(rot);
152 SetRotation(rot[0],rot[1],rot[2]);
153 return *this;
154}
155
156//_____________________________________________________________________________
157AliAlignObjAngles::~AliAlignObjAngles()
158{
159 // default destructor
160}
161
162//_____________________________________________________________________________
163void AliAlignObjAngles::SetTranslation(const TGeoMatrix& m)
164{
165 if(m.IsTranslation()){
166 const Double_t* tr = m.GetTranslation();
167 fTranslation[0]=tr[0]; fTranslation[1]=tr[1]; fTranslation[2]=tr[2];
168 }else{
169// AliWarning("Argument matrix is not a translation! Setting zero-translation.");
170 fTranslation[0] = fTranslation[1] = fTranslation[2] = 0.;
171 }
172}
173
174//_____________________________________________________________________________
175Bool_t AliAlignObjAngles::SetRotation(const TGeoMatrix& m)
176{
177 if(m.IsRotation()){
178 const Double_t* rot = m.GetRotationMatrix();
179 return MatrixToAngles(rot,fRotation);
180 }else{
181// AliWarning("Argument matrix is not a rotation! Setting yaw-pitch-roll to zero.");
182 fRotation[0] = fRotation[1] = fRotation[2] = 0.;
183 return kTRUE;
184 }
185}
186
187//_____________________________________________________________________________
188void AliAlignObjAngles::SetMatrix(const TGeoMatrix& m)
189{
190 SetTranslation(m);
191 SetRotation(m);
192}
193
194//_____________________________________________________________________________
195void AliAlignObjAngles::GetPars(Double_t tr[], Double_t angles[]) const
196{
197 GetTranslation(tr);
198 GetAngles(angles);
199}
200
201//_____________________________________________________________________________
202void AliAlignObjAngles::GetMatrix(TGeoHMatrix& m) const
203{
204 m.SetTranslation(&fTranslation[0]);
205 Double_t rot[9];
206 AnglesToMatrix(fRotation,rot);
207 m.SetRotation(rot);
208}
209
210//=============================================================================
211
212ClassImp(AliAlignObjMatrix)
213
214//_____________________________________________________________________________
215AliAlignObjMatrix::AliAlignObjMatrix() : AliAlignObj()
216{
217 // Default constructor
218}
219
220AliAlignObjMatrix::AliAlignObjMatrix(const AliAlignObjMatrix& theAlignObj) :
221 AliAlignObj(theAlignObj)
222{
223 //copy constructor
224 //
225 Double_t tr[3];
226 theAlignObj.GetTranslation(tr);
227 SetTranslation(tr[0],tr[1],tr[2]);
228 Double_t rot[3];
229 theAlignObj.GetAngles(rot);
230 SetRotation(rot[0],rot[1],rot[2]);
231}
232
233AliAlignObjMatrix &AliAlignObjMatrix::operator =(const AliAlignObjMatrix& theAlignObj)
234{
235 // assignment operator
236 //
237 if(this==&theAlignObj) return *this;
238 ((AliAlignObj *)this)->operator=(theAlignObj);
239 Double_t tr[3];
240 theAlignObj.GetTranslation(tr);
241 SetTranslation(tr[0],tr[1],tr[2]);
242 Double_t rot[3];
243 theAlignObj.GetAngles(rot);
244 SetRotation(rot[0],rot[1],rot[2]);
245 return *this;
246}
247
248AliAlignObjMatrix::~AliAlignObjMatrix()
249{
250 // Destructor
251 //
252}
253
254//_____________________________________________________________________________
255void AliAlignObjMatrix::SetTranslation(Double_t x, Double_t y, Double_t z)
256{
257 Double_t tr[3];
258 tr[0]=x; tr[1]=y; tr[2]=z;
259 fMatrix.SetTranslation(tr);
260}
261
262//_____________________________________________________________________________
263void AliAlignObjMatrix::SetTranslation(const TGeoMatrix& m)
264{
265 const Double_t *tr = m.GetTranslation();
266 fMatrix.SetTranslation(tr);
267}
268
269//_____________________________________________________________________________
270void AliAlignObjMatrix::SetRotation(Double_t psi, Double_t theta, Double_t phi)
271{
272 Double_t angles[3] = {psi, theta, phi};
273 Double_t rot[9];
274 AnglesToMatrix(angles,rot);
275 fMatrix.SetRotation(rot);
276}
277
278//_____________________________________________________________________________
279Bool_t AliAlignObjMatrix::SetRotation(const TGeoMatrix& m)
280{
281 const Double_t* rot = m.GetRotationMatrix();
282 fMatrix.SetRotation(rot);
283 return kTRUE;
284}
285
286//_____________________________________________________________________________
287void AliAlignObjMatrix::SetMatrix(const TGeoMatrix& m)
288{
289 // Set rotation matrix and translation
290 // using TGeoMatrix
291 SetTranslation(m);
292 SetRotation(m);
293}
294
295//_____________________________________________________________________________
296void AliAlignObjMatrix::SetPars(Double_t x, Double_t y, Double_t z,
297 Double_t psi, Double_t theta, Double_t phi)
298{
299 // Set rotation matrix and translation
300 // using 3 angles and 3 translations
301 SetTranslation(x,y,z);
302 SetRotation(psi,theta,phi);
303}
304
305//_____________________________________________________________________________
306void AliAlignObjMatrix::GetTranslation(Double_t *tr) const
307{
308 // Get Translation from TGeoMatrix
309 const Double_t* translation = fMatrix.GetTranslation();
310 tr[0] = translation[0];
311 tr[1] = translation[1];
312 tr[2] = translation[2];
313}
314
315//_____________________________________________________________________________
316Bool_t AliAlignObjMatrix::GetAngles(Double_t *angles) const
317{
318 // Get rotation angles from the TGeoHMatrix
319 const Double_t* rot = fMatrix.GetRotationMatrix();
320 return MatrixToAngles(rot,angles);
321}
322
323//_____________________________________________________________________________
324void AliAlignObjMatrix::GetPars(Double_t tr[], Double_t angles[]) const
325{
326 GetTranslation(tr);
327 GetAngles(angles);
328}
329
330//_____________________________________________________________________________
331void AliAlignObjMatrix::GetMatrix(TGeoHMatrix& m) const
332{
333 // Get TGeoHMatrix
334 //
335 const Double_t *tr = fMatrix.GetTranslation();
336 m.SetTranslation(tr);
337 const Double_t *rot = fMatrix.GetRotationMatrix();
338 m.SetRotation(rot);
339}
340