1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
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 //-----------------------------------------------------------------
24 #include "AliAlignObj.h"
29 //_____________________________________________________________________________
30 AliAlignObj::AliAlignObj():
36 //_____________________________________________________________________________
37 AliAlignObj::AliAlignObj(const AliAlignObj& theAlignObj) :
41 fVolPath = theAlignObj.GetVolPath();
42 fVolUID = theAlignObj.GetVolUID();
45 //_____________________________________________________________________________
46 AliAlignObj &AliAlignObj::operator =(const AliAlignObj& theAlignObj)
48 // assignment operator
49 if(this==&theAlignObj) return *this;
50 fVolPath = theAlignObj.GetVolPath();
51 fVolUID = theAlignObj.GetVolUID();
55 //_____________________________________________________________________________
56 AliAlignObj::~AliAlignObj()
61 //_____________________________________________________________________________
62 void AliAlignObj::AnglesToMatrix(const Double_t *angles, Double_t *rot) const
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]);
72 rot[0] = costhe*cosphi;
73 rot[1] = -costhe*sinphi;
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;
83 //_____________________________________________________________________________
84 Bool_t AliAlignObj::MatrixToAngles(const Double_t *rot, Double_t *angles) const
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]);
94 //_____________________________________________________________________________
95 void AliAlignObj::Print(Option_t *) const
97 // Print the contents of the
98 // alignment object in angles and
99 // matrix representations
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]);
115 //=============================================================================
117 ClassImp(AliAlignObjAngles)
119 //_____________________________________________________________________________
120 AliAlignObjAngles::AliAlignObjAngles() //: AliAlignObj()
122 // default constructor
123 fTranslation[0]=fTranslation[1]=fTranslation[2]=0.;
124 fRotation[0]=fRotation[1]=fRotation[2]=0.;
127 //_____________________________________________________________________________
128 AliAlignObjAngles::AliAlignObjAngles(const AliAlignObjAngles& theAlignObj) :
129 AliAlignObj(theAlignObj)
133 theAlignObj.GetTranslation(tr);
134 SetTranslation(tr[0],tr[1],tr[2]);
136 theAlignObj.GetAngles(rot);
137 SetRotation(rot[0],rot[1],rot[2]);
140 //_____________________________________________________________________________
141 AliAlignObjAngles &AliAlignObjAngles::operator =(const AliAlignObjAngles& theAlignObj)
143 // assignment operator
144 if(this==&theAlignObj) return *this;
145 ((AliAlignObj *)this)->operator=(theAlignObj);
148 theAlignObj.GetTranslation(tr);
149 SetTranslation(tr[0],tr[1],tr[2]);
151 theAlignObj.GetAngles(rot);
152 SetRotation(rot[0],rot[1],rot[2]);
156 //_____________________________________________________________________________
157 AliAlignObjAngles::~AliAlignObjAngles()
159 // default destructor
162 //_____________________________________________________________________________
163 void AliAlignObjAngles::SetTranslation(const TGeoMatrix& m)
165 if(m.IsTranslation()){
166 const Double_t* tr = m.GetTranslation();
167 fTranslation[0]=tr[0]; fTranslation[1]=tr[1]; fTranslation[2]=tr[2];
169 // AliWarning("Argument matrix is not a translation! Setting zero-translation.");
170 fTranslation[0] = fTranslation[1] = fTranslation[2] = 0.;
174 //_____________________________________________________________________________
175 Bool_t AliAlignObjAngles::SetRotation(const TGeoMatrix& m)
178 const Double_t* rot = m.GetRotationMatrix();
179 return MatrixToAngles(rot,fRotation);
181 // AliWarning("Argument matrix is not a rotation! Setting yaw-pitch-roll to zero.");
182 fRotation[0] = fRotation[1] = fRotation[2] = 0.;
187 //_____________________________________________________________________________
188 void AliAlignObjAngles::SetMatrix(const TGeoMatrix& m)
194 //_____________________________________________________________________________
195 void AliAlignObjAngles::GetPars(Double_t tr[], Double_t angles[]) const
201 //_____________________________________________________________________________
202 void AliAlignObjAngles::GetMatrix(TGeoHMatrix& m) const
204 m.SetTranslation(&fTranslation[0]);
206 AnglesToMatrix(fRotation,rot);
210 //=============================================================================
212 ClassImp(AliAlignObjMatrix)
214 //_____________________________________________________________________________
215 AliAlignObjMatrix::AliAlignObjMatrix() : AliAlignObj()
217 // Default constructor
220 AliAlignObjMatrix::AliAlignObjMatrix(const AliAlignObjMatrix& theAlignObj) :
221 AliAlignObj(theAlignObj)
226 theAlignObj.GetTranslation(tr);
227 SetTranslation(tr[0],tr[1],tr[2]);
229 theAlignObj.GetAngles(rot);
230 SetRotation(rot[0],rot[1],rot[2]);
233 AliAlignObjMatrix &AliAlignObjMatrix::operator =(const AliAlignObjMatrix& theAlignObj)
235 // assignment operator
237 if(this==&theAlignObj) return *this;
238 ((AliAlignObj *)this)->operator=(theAlignObj);
240 theAlignObj.GetTranslation(tr);
241 SetTranslation(tr[0],tr[1],tr[2]);
243 theAlignObj.GetAngles(rot);
244 SetRotation(rot[0],rot[1],rot[2]);
248 AliAlignObjMatrix::~AliAlignObjMatrix()
254 //_____________________________________________________________________________
255 void AliAlignObjMatrix::SetTranslation(Double_t x, Double_t y, Double_t z)
258 tr[0]=x; tr[1]=y; tr[2]=z;
259 fMatrix.SetTranslation(tr);
262 //_____________________________________________________________________________
263 void AliAlignObjMatrix::SetTranslation(const TGeoMatrix& m)
265 const Double_t *tr = m.GetTranslation();
266 fMatrix.SetTranslation(tr);
269 //_____________________________________________________________________________
270 void AliAlignObjMatrix::SetRotation(Double_t psi, Double_t theta, Double_t phi)
272 Double_t angles[3] = {psi, theta, phi};
274 AnglesToMatrix(angles,rot);
275 fMatrix.SetRotation(rot);
278 //_____________________________________________________________________________
279 Bool_t AliAlignObjMatrix::SetRotation(const TGeoMatrix& m)
281 const Double_t* rot = m.GetRotationMatrix();
282 fMatrix.SetRotation(rot);
286 //_____________________________________________________________________________
287 void AliAlignObjMatrix::SetMatrix(const TGeoMatrix& m)
289 // Set rotation matrix and translation
295 //_____________________________________________________________________________
296 void AliAlignObjMatrix::SetPars(Double_t x, Double_t y, Double_t z,
297 Double_t psi, Double_t theta, Double_t phi)
299 // Set rotation matrix and translation
300 // using 3 angles and 3 translations
301 SetTranslation(x,y,z);
302 SetRotation(psi,theta,phi);
305 //_____________________________________________________________________________
306 void AliAlignObjMatrix::GetTranslation(Double_t *tr) const
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];
315 //_____________________________________________________________________________
316 Bool_t AliAlignObjMatrix::GetAngles(Double_t *angles) const
318 // Get rotation angles from the TGeoHMatrix
319 const Double_t* rot = fMatrix.GetRotationMatrix();
320 return MatrixToAngles(rot,angles);
323 //_____________________________________________________________________________
324 void AliAlignObjMatrix::GetPars(Double_t tr[], Double_t angles[]) const
330 //_____________________________________________________________________________
331 void AliAlignObjMatrix::GetMatrix(TGeoHMatrix& m) const
335 const Double_t *tr = fMatrix.GetTranslation();
336 m.SetTranslation(tr);
337 const Double_t *rot = fMatrix.GetRotationMatrix();