]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAlignObj.cxx
bug fix when grid connection is down
[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
090026bf 16/* $Id$ */
17
c18195b9 18//-----------------------------------------------------------------
7e154d52 19// Implementation of the alignment object class, holding the alignment
20// constants for a single volume, through the abstract class AliAlignObj.
21// From it two derived concrete representation of alignment object class
90dbf5fb 22// (AliAlignObjParams, AliAlignObjMatrix) are derived in separate files.
c18195b9 23//-----------------------------------------------------------------
a1e17193 24
995ad051 25#include <TGeoManager.h>
268f57b1 26#include <TGeoMatrix.h>
995ad051 27#include <TGeoPhysicalNode.h>
090026bf 28#include <TMath.h>
2499b21b 29#include <TMatrixDSym.h>
995ad051 30
c18195b9 31#include "AliAlignObj.h"
03b18860 32#include "AliTrackPointArray.h"
33#include "AliLog.h"
98937d93 34
c18195b9 35ClassImp(AliAlignObj)
36
37//_____________________________________________________________________________
38AliAlignObj::AliAlignObj():
fe12e09c 39 fVolPath(),
c18195b9 40 fVolUID(0)
41{
03b18860 42 // default constructor
90dbf5fb 43 for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
6b1b1a3b 44 for(Int_t i=0; i<15; i++) fODia[i]=-999.;
c18195b9 45}
46
47//_____________________________________________________________________________
b760c02e 48AliAlignObj::AliAlignObj(const char* symname, UShort_t voluid) :
fe12e09c 49 TObject(),
b760c02e 50 fVolPath(symname),
fe12e09c 51 fVolUID(voluid)
d9cc42ed 52{
53 // standard constructor
54 //
90dbf5fb 55 for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
6b1b1a3b 56 for(Int_t i=0; i<15; i++) fODia[i]=-999.;
90dbf5fb 57}
58
59//_____________________________________________________________________________
60AliAlignObj::AliAlignObj(const char* symname, UShort_t voluid, Double_t* cmat) :
61 TObject(),
62 fVolPath(symname),
63 fVolUID(voluid)
64{
65 // standard constructor
66 //
67 SetCorrMatrix(cmat);
d9cc42ed 68}
69
d9cc42ed 70//_____________________________________________________________________________
c18195b9 71AliAlignObj::AliAlignObj(const AliAlignObj& theAlignObj) :
fe12e09c 72 TObject(theAlignObj),
b760c02e 73 fVolPath(theAlignObj.GetSymName()),
fe12e09c 74 fVolUID(theAlignObj.GetVolUID())
c18195b9 75{
76 //copy constructor
90dbf5fb 77 for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
6b1b1a3b 78 for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
c18195b9 79}
80
81//_____________________________________________________________________________
82AliAlignObj &AliAlignObj::operator =(const AliAlignObj& theAlignObj)
83{
84 // assignment operator
85 if(this==&theAlignObj) return *this;
b760c02e 86 fVolPath = theAlignObj.GetSymName();
c18195b9 87 fVolUID = theAlignObj.GetVolUID();
90dbf5fb 88 for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
6b1b1a3b 89 for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
c18195b9 90 return *this;
91}
92
38b3a170 93//_____________________________________________________________________________
94AliAlignObj &AliAlignObj::operator*=(const AliAlignObj& theAlignObj)
95{
96 // multiplication operator
97 // The operator can be used to 'combine'
98 // two alignment objects
99 TGeoHMatrix m1;
100 GetMatrix(m1);
101 TGeoHMatrix m2;
102 theAlignObj.GetMatrix(m2);
103 m1.MultiplyLeft(&m2);
104 SetMatrix(m1);
6b1b1a3b 105 // temporary solution: the covariance matrix of the resulting combined object
106 // is set equal to the covariance matrix of the right operand
107 // (not to be used for combining alignment objects for different levels)
108 for(Int_t i=0; i<6; i++) fDiag[i] = theAlignObj.fDiag[i];
109 for(Int_t i=0; i<15; i++) fODia[i] = theAlignObj.fODia[i];
38b3a170 110 return *this;
111}
112
c18195b9 113//_____________________________________________________________________________
114AliAlignObj::~AliAlignObj()
115{
116 // dummy destructor
117}
118
befe2c08 119//_____________________________________________________________________________
25be1e5c 120void AliAlignObj::SetVolUID(AliGeomManager::ELayerID detId, Int_t modId)
befe2c08 121{
122 // From detector name and module number (according to detector numbering)
123 // build fVolUID, unique numerical identity of that volume inside ALICE
124 // fVolUID is 16 bits, first 5 reserved for detID (32 possible values),
125 // remaining 11 for module ID inside det (2048 possible values).
126 //
25be1e5c 127 fVolUID = AliGeomManager::LayerToVolUID(detId,modId);
befe2c08 128}
129
130//_____________________________________________________________________________
25be1e5c 131void AliAlignObj::GetVolUID(AliGeomManager::ELayerID &layerId, Int_t &modId) const
befe2c08 132{
7e154d52 133 // From the fVolUID, unique numerical identity of that volume inside ALICE,
134 // (voluid is 16 bits, first 5 reserved for layerID (32 possible values),
135 // remaining 11 for module ID inside det (2048 possible values)), sets
136 // the argument layerId to the identity of the layer to which that volume
137 // belongs and sets the argument modId to the identity of that volume
138 // internally to the layer.
befe2c08 139 //
25be1e5c 140 layerId = AliGeomManager::VolUIDToLayer(fVolUID,modId);
befe2c08 141}
142
b760c02e 143//_____________________________________________________________________________
144Bool_t AliAlignObj::GetPars(Double_t tr[], Double_t angles[]) const
145{
146 GetTranslation(tr);
147 return GetAngles(angles);
148}
149
4b94e753 150//_____________________________________________________________________________
151Int_t AliAlignObj::GetLevel() const
152{
85fbf070 153 // Return the geometry level of the alignable volume to which
154 // the alignment object is associated; this is the number of
155 // slashes in the corresponding volume path
156 //
157 if(!gGeoManager){
158 AliWarning("gGeoManager doesn't exist or it is still opened: unable to return meaningful level value.");
159 return (-1);
160 }
161 const char* symname = GetSymName();
162 const char* path;
163 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
164 if(pne){
165 path = pne->GetTitle();
166 }else{
167 path = symname;
168 }
169
2499b21b 170 TString pathStr = path;
171 if(pathStr[0]!='/') pathStr.Prepend('/');
172 return pathStr.CountChar('/');
4b94e753 173}
174
175//_____________________________________________________________________________
176Int_t AliAlignObj::Compare(const TObject *obj) const
177{
178 // Compare the levels of two
179 // alignment objects
180 // Used in the sorting during
181 // the application of alignment
182 // objects to the geometry
7e154d52 183 //
4b94e753 184 Int_t level = GetLevel();
185 Int_t level2 = ((AliAlignObj *)obj)->GetLevel();
186 if (level == level2)
187 return 0;
188 else
189 return ((level > level2) ? 1 : -1);
190}
191
90dbf5fb 192//______________________________________________________________________________
193void AliAlignObj::GetCovMatrix(Double_t *cmat) const
194{
195 // Fills the cmat argument with the coefficients of the external cov matrix (21 elements)
196 // calculating them from the correlation matrix data member
197 //
198
199 for(Int_t i=0; i<6; ++i) {
200 // Off diagonal elements
201 for(Int_t j=0; j<i; ++j) {
202 cmat[i*(i+1)/2+j] = (fDiag[j] >= 0. && fDiag[i] >= 0.) ? fODia[(i-1)*i/2+j]*fDiag[j]*fDiag[i]: -999.;
203 }
204
205 // Diagonal elements
206 cmat[i*(i+1)/2+i] = (fDiag[i] >= 0.) ? fDiag[i]*fDiag[i] : -999.;
207 }
e9304cb8 208
209 return;
210}
211
212//______________________________________________________________________________
213void AliAlignObj::GetCovMatrix(TMatrixDSym& mcov) const
214{
215 // Fills the matrix m passed as argument as the covariance matrix calculated
216 // from the coefficients of the reduced covariance matrix data members
217 //
218
219 for(Int_t i=0; i<6; ++i) {
220 // Off diagonal elements
221 for(Int_t j=0; j<i; ++j) {
222 mcov(j,i) = mcov(i,j) = (fDiag[j] >= 0. && fDiag[i] >= 0.) ? fODia[(i-1)*i/2+j]*fDiag[j]*fDiag[i]: -999.;
223 }
224
225 // Diagonal elements
226 mcov(i,i) = (fDiag[i] >= 0.) ? fDiag[i]*fDiag[i] : -999.;
227 }
228
90dbf5fb 229}
230
231//______________________________________________________________________________
232void AliAlignObj::SetCorrMatrix(Double_t *cmat)
233{
234 // Sets the correlation matrix data member from the coefficients of the external covariance
235 // matrix (21 elements passed as argument).
236 //
237 if(cmat) {
238
239 // Diagonal elements first
240 for(Int_t i=0; i<6; ++i) {
241 fDiag[i] = (cmat[i*(i+1)/2+i] >= 0.) ? TMath::Sqrt(cmat[i*(i+1)/2+i]) : -999.;
242 }
243
244 // ... then the ones off diagonal
245 for(Int_t i=0; i<6; ++i)
246 // Off diagonal elements
247 for(Int_t j=0; j<i; ++j) {
248 fODia[(i-1)*i/2+j] = (fDiag[i] > 0. && fDiag[j] > 0.) ? cmat[i*(i+1)/2+j]/(fDiag[j]*fDiag[i]) : 0.; // check for division by zero (due to diagonal element of 0) and for fDiag != -999. (due to negative input diagonal element).
249 if (fODia[(i-1)*i/2+j]>1.) fODia[(i-1)*i/2+j] = 1.; // check upper boundary
250 if (fODia[(i-1)*i/2+j]<-1.) fODia[(i-1)*i/2+j] = -1.; // check lower boundary
251 }
252 } else {
253 for(Int_t i=0; i< 6; ++i) fDiag[i]=-999.;
254 for(Int_t i=0; i< 6*(6-1)/2; ++i) fODia[i]=0.;
255 }
256
257 return;
258}
259
e9304cb8 260//______________________________________________________________________________
261void AliAlignObj::SetCorrMatrix(TMatrixDSym& mcov)
262{
263 // Sets the correlation matrix data member from the covariance matrix mcov passed
264 // passed as argument.
265 //
266 if(mcov.IsValid()) {
267
268 // Diagonal elements first
269 for(Int_t i=0; i<6; ++i) {
270 fDiag[i] = (mcov(i,i) >= 0.) ? TMath::Sqrt(mcov(i,i)) : -999.;
271 }
272
273 // ... then the ones off diagonal
274 for(Int_t i=0; i<6; ++i)
275 // Off diagonal elements
276 for(Int_t j=0; j<i; ++j) {
277 fODia[(i-1)*i/2+j] = (fDiag[i] > 0. && fDiag[j] > 0.) ? mcov(i,j)/(fDiag[j]*fDiag[i]) : 0.; // check for division by zero (due to diagonal element of 0) and for fDiag != -999. (due to negative input diagonal element).
278 if (fODia[(i-1)*i/2+j]>1.) fODia[(i-1)*i/2+j] = 1.; // check upper boundary
279 if (fODia[(i-1)*i/2+j]<-1.) fODia[(i-1)*i/2+j] = -1.; // check lower boundary
280 }
281 } else {
282 for(Int_t i=0; i< 6; ++i) fDiag[i]=-999.;
283 for(Int_t i=0; i< 6*(6-1)/2; ++i) fODia[i]=0.;
284 }
285
286 return;
287}
288
c18195b9 289//_____________________________________________________________________________
290void AliAlignObj::AnglesToMatrix(const Double_t *angles, Double_t *rot) const
291{
fdf65bb5 292 // Calculates the rotation matrix using the
293 // Euler angles in "x y z" notation
7e154d52 294 //
c18195b9 295 Double_t degrad = TMath::DegToRad();
296 Double_t sinpsi = TMath::Sin(degrad*angles[0]);
297 Double_t cospsi = TMath::Cos(degrad*angles[0]);
298 Double_t sinthe = TMath::Sin(degrad*angles[1]);
299 Double_t costhe = TMath::Cos(degrad*angles[1]);
300 Double_t sinphi = TMath::Sin(degrad*angles[2]);
301 Double_t cosphi = TMath::Cos(degrad*angles[2]);
302
303 rot[0] = costhe*cosphi;
304 rot[1] = -costhe*sinphi;
305 rot[2] = sinthe;
306 rot[3] = sinpsi*sinthe*cosphi + cospsi*sinphi;
307 rot[4] = -sinpsi*sinthe*sinphi + cospsi*cosphi;
308 rot[5] = -costhe*sinpsi;
309 rot[6] = -cospsi*sinthe*cosphi + sinpsi*sinphi;
310 rot[7] = cospsi*sinthe*sinphi + sinpsi*cosphi;
311 rot[8] = costhe*cospsi;
312}
313
314//_____________________________________________________________________________
315Bool_t AliAlignObj::MatrixToAngles(const Double_t *rot, Double_t *angles) const
316{
fdf65bb5 317 // Calculates the Euler angles in "x y z" notation
318 // using the rotation matrix
b760c02e 319 // Returns false in case the rotation angles can not be
320 // extracted from the matrix
7e154d52 321 //
b760c02e 322 if(TMath::Abs(rot[0])<1e-7 || TMath::Abs(rot[8])<1e-7) {
323 AliError("Failed to extract roll-pitch-yall angles!");
324 return kFALSE;
325 }
c18195b9 326 Double_t raddeg = TMath::RadToDeg();
327 angles[0]=raddeg*TMath::ATan2(-rot[5],rot[8]);
328 angles[1]=raddeg*TMath::ASin(rot[2]);
329 angles[2]=raddeg*TMath::ATan2(-rot[1],rot[0]);
330 return kTRUE;
331}
332
03b18860 333//______________________________________________________________________________
6b1b1a3b 334void AliAlignObj::Transform(AliTrackPoint &p, Bool_t copycov) const
03b18860 335{
336 // The method transforms the space-point coordinates using the
337 // transformation matrix provided by the AliAlignObj
6b1b1a3b 338 // In case the copycov flag is set to kTRUE, the covariance matrix
339 // of the alignment object is copied into the space-point
7e154d52 340 //
03b18860 341 if (fVolUID != p.GetVolumeID())
342 AliWarning(Form("Alignment object ID is not equal to the space-point ID (%d != %d)",fVolUID,p.GetVolumeID()));
343
344 TGeoHMatrix m;
345 GetMatrix(m);
346 Double_t *rot = m.GetRotationMatrix();
347 Double_t *tr = m.GetTranslation();
348
349 Float_t xyzin[3],xyzout[3];
350 p.GetXYZ(xyzin);
351 for (Int_t i = 0; i < 3; i++)
352 xyzout[i] = tr[i]+
353 xyzin[0]*rot[3*i]+
354 xyzin[1]*rot[3*i+1]+
355 xyzin[2]*rot[3*i+2];
356 p.SetXYZ(xyzout);
6b1b1a3b 357
358 if(copycov){
359 TMatrixDSym covmat(6);
360 GetCovMatrix(covmat);
361 p.SetAlignCovMatrix(covmat);
362 }
03b18860 363
364}
365
79e21da6 366//_____________________________________________________________________________
03b18860 367void AliAlignObj::Transform(AliTrackPointArray &array) const
368{
e1e6896f 369 // This method is used to transform all the track points
370 // from the input AliTrackPointArray
7e154d52 371 //
03b18860 372 AliTrackPoint p;
373 for (Int_t i = 0; i < array.GetNPoints(); i++) {
374 array.GetPoint(p,i);
375 Transform(p);
376 array.AddPoint(i,&p);
377 }
378}
379
c18195b9 380//_____________________________________________________________________________
381void AliAlignObj::Print(Option_t *) const
382{
383 // Print the contents of the
384 // alignment object in angles and
385 // matrix representations
7e154d52 386 //
c18195b9 387 Double_t tr[3];
388 GetTranslation(tr);
389 Double_t angles[3];
390 GetAngles(angles);
391 TGeoHMatrix m;
392 GetMatrix(m);
393 const Double_t *rot = m.GetRotationMatrix();
c18195b9 394
b760c02e 395 printf("Volume=%s\n",GetSymName());
c041444f 396 if (GetVolUID() != 0) {
25be1e5c 397 AliGeomManager::ELayerID layerId;
c041444f 398 Int_t modId;
399 GetVolUID(layerId,modId);
25be1e5c 400 printf("VolumeID=%d LayerID=%d ( %s ) ModuleID=%d\n", GetVolUID(),layerId,AliGeomManager::LayerName(layerId),modId);
c041444f 401 }
402 printf("%12.8f%12.8f%12.8f Tx = %12.8f Psi = %12.8f\n", rot[0], rot[1], rot[2], tr[0], angles[0]);
403 printf("%12.8f%12.8f%12.8f Ty = %12.8f Theta = %12.8f\n", rot[3], rot[4], rot[5], tr[1], angles[1]);
404 printf("%12.8f%12.8f%12.8f Tz = %12.8f Phi = %12.8f\n", rot[6], rot[7], rot[8], tr[2], angles[2]);
405
406}
407
b760c02e 408//_____________________________________________________________________________
409void AliAlignObj::SetPars(Double_t x, Double_t y, Double_t z,
410 Double_t psi, Double_t theta, Double_t phi)
411{
32898fe7 412 // Set the global delta transformation by passing 3 angles (expressed in
413 // degrees) and 3 shifts (in centimeters)
7e154d52 414 //
b760c02e 415 SetTranslation(x,y,z);
416 SetRotation(psi,theta,phi);
417}
418
1bfe7ffc 419//_____________________________________________________________________________
420Bool_t AliAlignObj::SetLocalPars(Double_t x, Double_t y, Double_t z,
421 Double_t psi, Double_t theta, Double_t phi)
422{
32898fe7 423 // Set the global delta transformation by passing the parameters
424 // for the local delta transformation (3 shifts and 3 angles).
7e154d52 425 // In case that the TGeo was not initialized or not closed,
426 // returns false and the object parameters are not set.
427 //
b760c02e 428 TGeoHMatrix m;
429 Double_t tr[3] = {x, y, z};
430 m.SetTranslation(tr);
431 Double_t angles[3] = {psi, theta, phi};
432 Double_t rot[9];
433 AnglesToMatrix(angles,rot);
434 m.SetRotation(rot);
435
436 return SetLocalMatrix(m);
437
438}
439
32898fe7 440//_____________________________________________________________________________
441Bool_t AliAlignObj::SetLocalTranslation(Double_t x, Double_t y, Double_t z)
442{
443 // Set the global delta transformation by passing the three shifts giving
444 // the translation in the local reference system of the alignable
445 // volume (known by TGeo geometry).
446 // In case that the TGeo was not initialized or not closed,
447 // returns false and the object parameters are not set.
448 //
449 TGeoHMatrix m;
450 Double_t tr[3] = {x, y, z};
451 m.SetTranslation(tr);
452
453 return SetLocalMatrix(m);
454
455}
456
457//_____________________________________________________________________________
458Bool_t AliAlignObj::SetLocalTranslation(const TGeoMatrix& m)
459{
460 // Set the global delta transformation by passing the matrix of
461 // the local delta transformation and taking its translational part
462 // In case that the TGeo was not initialized or not closed,
463 // returns false and the object parameters are not set.
464 //
465 const Double_t* tr = m.GetTranslation();
466 TGeoHMatrix mtr;
467 mtr.SetTranslation(tr);
468
469 return SetLocalMatrix(mtr);
470
471}
472
473//_____________________________________________________________________________
474Bool_t AliAlignObj::SetLocalRotation(Double_t psi, Double_t theta, Double_t phi)
475{
476 // Set the global delta transformation by passing the three angles giving
477 // the rotation in the local reference system of the alignable
478 // volume (known by TGeo geometry).
479 // In case that the TGeo was not initialized or not closed,
480 // returns false and the object parameters are not set.
481 //
482 TGeoHMatrix m;
483 Double_t angles[3] = {psi, theta, phi};
484 Double_t rot[9];
485 AnglesToMatrix(angles,rot);
486 m.SetRotation(rot);
487
488 return SetLocalMatrix(m);
489
490}
491
492//_____________________________________________________________________________
493Bool_t AliAlignObj::SetLocalRotation(const TGeoMatrix& m)
494{
495 // Set the global delta transformation by passing the matrix of
496 // the local delta transformation and taking its rotational part
497 // In case that the TGeo was not initialized or not closed,
498 // returns false and the object parameters are not set.
499 //
500 TGeoHMatrix rotm;
501 const Double_t* rot = m.GetRotationMatrix();
502 rotm.SetRotation(rot);
503
504 return SetLocalMatrix(rotm);
505
506}
507
b760c02e 508//_____________________________________________________________________________
509Bool_t AliAlignObj::SetLocalMatrix(const TGeoMatrix& m)
510{
32898fe7 511 // Set the global delta transformation by passing the TGeo matrix
512 // for the local delta transformation.
7e154d52 513 // In case that the TGeo was not initialized or not closed,
514 // returns false and the object parameters are not set.
515 //
1bfe7ffc 516 if (!gGeoManager || !gGeoManager->IsClosed()) {
517 AliError("Can't set the alignment object parameters! gGeoManager doesn't exist or it is still opened!");
518 return kFALSE;
519 }
520
b760c02e 521 const char* symname = GetSymName();
522 TGeoPhysicalNode* node;
523 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
524 if(pne){
525 node = gGeoManager->MakeAlignablePN(pne);
526 }else{
527 AliWarning(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as volume path!",symname));
528 node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(symname);
529 }
530
1bfe7ffc 531 if (!node) {
b760c02e 532 AliError(Form("Volume name or path %s not valid!",symname));
1bfe7ffc 533 return kFALSE;
534 }
535 if (node->IsAligned())
b760c02e 536 AliWarning(Form("Volume %s has been already misaligned!",symname));
1bfe7ffc 537
b760c02e 538 TGeoHMatrix m1;
539 const Double_t *tr = m.GetTranslation();
540 m1.SetTranslation(tr);
541 const Double_t* rot = m.GetRotationMatrix();
542 m1.SetRotation(rot);
1bfe7ffc 543
544 TGeoHMatrix align,gprime,gprimeinv;
545 gprime = *node->GetMatrix();
546 gprimeinv = gprime.Inverse();
b760c02e 547 m1.Multiply(&gprimeinv);
548 m1.MultiplyLeft(&gprime);
1bfe7ffc 549
b760c02e 550 return SetMatrix(m1);
551}
1bfe7ffc 552
b760c02e 553//_____________________________________________________________________________
554Bool_t AliAlignObj::SetMatrix(const TGeoMatrix& m)
555{
32898fe7 556 // Set the global delta transformation by passing the TGeoMatrix
557 // for it
7e154d52 558 //
b760c02e 559 SetTranslation(m);
560 return SetRotation(m);
1bfe7ffc 561}
562
32898fe7 563//_____________________________________________________________________________
564Bool_t AliAlignObj::GetLocalPars(Double_t transl[], Double_t angles[]) const
565{
566 // Get the translations and angles (in degrees) expressing the
567 // local delta transformation.
568 // In case that the TGeo was not initialized or not closed,
569 // returns false and the object parameters are not set.
570 //
571 if(!GetLocalTranslation(transl)) return kFALSE;
572 return GetLocalAngles(angles);
573}
574
575//_____________________________________________________________________________
576Bool_t AliAlignObj::GetLocalTranslation(Double_t* tr) const
577{
578 // Get the 3 shifts giving the translational part of the local
579 // delta transformation.
580 // In case that the TGeo was not initialized or not closed,
581 // returns false and the object parameters are not set.
582 //
583 TGeoHMatrix ml;
584 if(!GetLocalMatrix(ml)) return kFALSE;
585 const Double_t* transl;
586 transl = ml.GetTranslation();
587 tr[0]=transl[0];
588 tr[1]=transl[1];
589 tr[2]=transl[2];
590 return kTRUE;
591}
592
593//_____________________________________________________________________________
594Bool_t AliAlignObj::GetLocalAngles(Double_t* angles) const
595{
596 // Get the 3 angles giving the rotational part of the local
597 // delta transformation.
598 // In case that the TGeo was not initialized or not closed,
599 // returns false and the object parameters are not set.
600 //
601 TGeoHMatrix ml;
602 if(!GetLocalMatrix(ml)) return kFALSE;
603 const Double_t *rot = ml.GetRotationMatrix();
604 return MatrixToAngles(rot,angles);
605}
606
607//_____________________________________________________________________________
608Bool_t AliAlignObj::GetLocalMatrix(TGeoHMatrix& m) const
609{
610 // Get the matrix for the local delta transformation.
611 // In case that the TGeo was not initialized or not closed,
612 // returns false and the object parameters are not set.
613 //
614 if (!gGeoManager || !gGeoManager->IsClosed()) {
615 AliError("Can't set the alignment object parameters! gGeoManager doesn't exist or it is still opened!");
616 return kFALSE;
617 }
618
619 const char* symname = GetSymName();
620 TGeoPhysicalNode* node;
621 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
622 if(pne){
623 node = gGeoManager->MakeAlignablePN(pne);
624 }else{
625 AliWarning(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as volume path!",symname));
626 node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(symname);
627 }
628
629 if (!node) {
630 AliError(Form("Volume name or path %s not valid!",symname));
631 return kFALSE;
632 }
633 if (node->IsAligned())
634 AliWarning(Form("Volume %s has been already misaligned!",symname));
635
636 GetMatrix(m);
637 TGeoHMatrix gprime,gprimeinv;
638 gprime = *node->GetMatrix();
639 gprimeinv = gprime.Inverse();
640 m.Multiply(&gprime);
641 m.MultiplyLeft(&gprimeinv);
642
643 return kTRUE;
644}
645
995ad051 646//_____________________________________________________________________________
5590c6c3 647Bool_t AliAlignObj::ApplyToGeometry(Bool_t ovlpcheck)
995ad051 648{
7e154d52 649 // Apply the current alignment object to the TGeo geometry
650 // This method returns FALSE if the symname of the object was not
651 // valid neither to get a TGeoPEntry nor as a volume path
652 //
995ad051 653 if (!gGeoManager || !gGeoManager->IsClosed()) {
654 AliError("Can't apply the alignment object! gGeoManager doesn't exist or it is still opened!");
655 return kFALSE;
656 }
657
b760c02e 658 const char* symname = GetSymName();
659 const char* path;
660 TGeoPhysicalNode* node;
661 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
662 if(pne){
b760c02e 663 path = pne->GetTitle();
7e154d52 664 node = gGeoManager->MakeAlignablePN(pne);
b760c02e 665 }else{
5bd470e1 666 AliDebug(1,Form("The symbolic volume name %s does not correspond to a physical entry. Using it as a volume path!",symname));
b760c02e 667 path=symname;
7e154d52 668 if (!gGeoManager->CheckPath(path)) {
5bd470e1 669 AliDebug(1,Form("Volume path %s not valid!",path));
b760c02e 670 return kFALSE;
671 }
7e154d52 672 if (gGeoManager->GetListOfPhysicalNodes()->FindObject(path)) {
673 AliError(Form("Volume %s has already been misaligned!",path));
b760c02e 674 return kFALSE;
675 }
676 node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(path);
995ad051 677 }
48cac49d 678
48cac49d 679 if (!node) {
b760c02e 680 AliError(Form("Volume path %s not valid!",path));
995ad051 681 return kFALSE;
682 }
683
684 TGeoHMatrix align,gprime;
685 gprime = *node->GetMatrix();
686 GetMatrix(align);
687 gprime.MultiplyLeft(&align);
688 TGeoHMatrix *ginv = new TGeoHMatrix;
689 TGeoHMatrix *g = node->GetMatrix(node->GetLevel()-1);
690 *ginv = g->Inverse();
691 *ginv *= gprime;
25be1e5c 692 AliGeomManager::ELayerID layerId; // unique identity for layer in the alobj
b760c02e 693 Int_t modId; // unique identity for volume inside layer in the alobj
995ad051 694 GetVolUID(layerId, modId);
b760c02e 695 AliDebug(2,Form("Aligning volume %s of detector layer %d with local ID %d",symname,layerId,modId));
5590c6c3 696 node->Align(ginv,0,ovlpcheck);
697 if(ovlpcheck){
698 Int_t novex=((TObjArray*)gGeoManager->GetListOfOverlaps())->GetEntriesFast();
699 if(novex){
700 TString error(Form("The alignment of volume %s introduced %d new overlap",GetSymName(),novex));
701 if(novex>1) error+="s";
702 AliError(error.Data());
703 return kFALSE;
704 }
705 }
995ad051 706
707 return kTRUE;
708}
709