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 **************************************************************************/
18 //-----------------------------------------------------------------
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
22 // (AliAlignObjParams, AliAlignObjMatrix) are derived in separate files.
23 //-----------------------------------------------------------------
25 #include <TGeoManager.h>
26 #include <TGeoMatrix.h>
27 #include <TGeoPhysicalNode.h>
28 #include <TGeoOverlap.h>
31 #include "AliAlignObj.h"
32 #include "AliTrackPointArray.h"
37 //_____________________________________________________________________________
38 AliAlignObj::AliAlignObj():
43 // default constructor
44 for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
45 for(Int_t i=0; i<15; i++) fODia[i]=-999.;
48 //_____________________________________________________________________________
49 AliAlignObj::AliAlignObj(const char* symname, UShort_t voluid) :
54 // standard constructor
56 for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
57 for(Int_t i=0; i<15; i++) fODia[i]=-999.;
60 //_____________________________________________________________________________
61 AliAlignObj::AliAlignObj(const char* symname, UShort_t voluid, Double_t* cmat) :
66 // standard constructor
71 //_____________________________________________________________________________
72 AliAlignObj::AliAlignObj(const AliAlignObj& theAlignObj) :
74 fVolPath(theAlignObj.GetSymName()),
75 fVolUID(theAlignObj.GetVolUID())
78 for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
79 for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
82 //_____________________________________________________________________________
83 AliAlignObj &AliAlignObj::operator =(const AliAlignObj& theAlignObj)
85 // assignment operator
86 if(this==&theAlignObj) return *this;
87 fVolPath = theAlignObj.GetSymName();
88 fVolUID = theAlignObj.GetVolUID();
89 for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
90 for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
94 //_____________________________________________________________________________
95 AliAlignObj &AliAlignObj::operator*=(const AliAlignObj& theAlignObj)
97 // multiplication operator
98 // The operator can be used to 'combine'
99 // two alignment objects
103 theAlignObj.GetMatrix(m2);
104 m1.MultiplyLeft(&m2);
106 // temporary solution: the covariance matrix of the resulting combined object
107 // is set equal to the covariance matrix of the right operand
108 // (not to be used for combining alignment objects for different levels)
109 for(Int_t i=0; i<6; i++) fDiag[i] = theAlignObj.fDiag[i];
110 for(Int_t i=0; i<15; i++) fODia[i] = theAlignObj.fODia[i];
114 //_____________________________________________________________________________
115 AliAlignObj::~AliAlignObj()
120 //_____________________________________________________________________________
121 void AliAlignObj::SetVolUID(AliGeomManager::ELayerID detId, Int_t modId)
123 // From detector name and module number (according to detector numbering)
124 // build fVolUID, unique numerical identity of that volume inside ALICE
125 // fVolUID is 16 bits, first 5 reserved for detID (32 possible values),
126 // remaining 11 for module ID inside det (2048 possible values).
128 fVolUID = AliGeomManager::LayerToVolUID(detId,modId);
131 //_____________________________________________________________________________
132 void AliAlignObj::GetVolUID(AliGeomManager::ELayerID &layerId, Int_t &modId) const
134 // From the fVolUID, unique numerical identity of that volume inside ALICE,
135 // (voluid is 16 bits, first 5 reserved for layerID (32 possible values),
136 // remaining 11 for module ID inside det (2048 possible values)), sets
137 // the argument layerId to the identity of the layer to which that volume
138 // belongs and sets the argument modId to the identity of that volume
139 // internally to the layer.
141 layerId = AliGeomManager::VolUIDToLayer(fVolUID,modId);
144 //_____________________________________________________________________________
145 Bool_t AliAlignObj::GetPars(Double_t tr[], Double_t angles[]) const
148 return GetAngles(angles);
151 //_____________________________________________________________________________
152 Int_t AliAlignObj::GetLevel() const
154 // Return the geometry level of the alignable volume to which
155 // the alignment object is associated; this is the number of
156 // slashes in the corresponding volume path
159 AliWarning("gGeoManager doesn't exist or it is still open: unable to return meaningful level value.");
162 const char* symname = GetSymName();
164 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
166 path = pne->GetTitle();
171 TString pathStr = path;
172 if(pathStr[0]!='/') pathStr.Prepend('/');
173 return pathStr.CountChar('/');
176 //_____________________________________________________________________________
177 Int_t AliAlignObj::Compare(const TObject *obj) const
179 // Compare the levels of two
181 // Used in the sorting during
182 // the application of alignment
183 // objects to the geometry
185 Int_t level = GetLevel();
186 Int_t level2 = ((AliAlignObj *)obj)->GetLevel();
190 return ((level > level2) ? 1 : -1);
193 //______________________________________________________________________________
194 void AliAlignObj::GetCovMatrix(Double_t *cmat) const
196 // Fills the cmat argument with the coefficients of the external cov matrix (21 elements)
197 // calculating them from the correlation matrix data member
200 for(Int_t i=0; i<6; ++i) {
201 // Off diagonal elements
202 for(Int_t j=0; j<i; ++j) {
203 cmat[i*(i+1)/2+j] = (fDiag[j] >= 0. && fDiag[i] >= 0.) ? fODia[(i-1)*i/2+j]*fDiag[j]*fDiag[i]: -999.;
207 cmat[i*(i+1)/2+i] = (fDiag[i] >= 0.) ? fDiag[i]*fDiag[i] : -999.;
213 //______________________________________________________________________________
214 void AliAlignObj::GetCovMatrix(TMatrixDSym& mcov) const
216 // Fills the matrix m passed as argument as the covariance matrix calculated
217 // from the coefficients of the reduced covariance matrix data members
220 for(Int_t i=0; i<6; ++i) {
221 // Off diagonal elements
222 for(Int_t j=0; j<i; ++j) {
223 mcov(j,i) = mcov(i,j) = (fDiag[j] >= 0. && fDiag[i] >= 0.) ? fODia[(i-1)*i/2+j]*fDiag[j]*fDiag[i]: -999.;
227 mcov(i,i) = (fDiag[i] >= 0.) ? fDiag[i]*fDiag[i] : -999.;
232 //______________________________________________________________________________
233 Bool_t AliAlignObj::GetLocalCovMatrix(TMatrixDSym& lCov) const
235 // Calculates the covariance matrix (6x6) associated to the six parameters
236 // defining the current alignment in the global coordinates system (and sets
237 // in the internal data members) from the covariance matrix (6x6) for the six
238 // parameters defining the alignment transformation in the local coordinates
239 // system, passed as an argument.
241 TMatrixD mJ(6,6);// the jacobian of the transformation from local to global parameters
242 if(!GetJacobian(mJ)) return kFALSE;
247 // Compute the local covariance matrix lcov = mJ^T gcov mJ
248 TMatrixD gcovJ(gCov,TMatrixD::kMult,mJ);
249 TMatrixD lCovM(mJ,TMatrixD::kTransposeMult,gcovJ);
250 // To be done: somehow check that lCovM is close enough to be symmetric
251 for(Int_t i=0; i<6; i++)
253 lCov(i,i) = lCovM(i,i);
254 for(Int_t j=i+1; j<6; j++)
256 lCov(i,j)=lCovM(i,j);
257 lCov(j,i)=lCovM(i,j);
265 //______________________________________________________________________________
266 Bool_t AliAlignObj::GetLocalCovMatrix(Double_t *lCov) const
268 // Calculates the covariance matrix (6x6) associated to the six parameters
269 // defining the current alignment in the global coordinates system (and sets
270 // in the internal data members) from the covariance matrix (6x6) for the six
271 // parameters defining the alignment transformation in the local coordinates
272 // system, passed as an argument.
274 TMatrixDSym lCovMatrix(6);
275 GetLocalCovMatrix(lCovMatrix);
278 for(Int_t i=0; i<6; i++)
279 for(Int_t j=i; j<6; j++)
281 lCov[k++] = lCovMatrix(i,j);
287 //______________________________________________________________________________
288 Bool_t AliAlignObj::GetJacobian(TMatrixD& mJ) const
290 // Compute the jacobian J of the transformation of the six local to the six global delta parameters
292 // R00 R01 R02 | (R01Rk2 - R02Rk1)Tk (R02Rk0 - R00Rk2)Tk (R00Rk1 - R01Rk0)Tk
293 // R00 R01 R02 | (R11Rk2 - R12Rk1)Tk (R12Rk0 - R10Rk2)Tk (R10Rk1 - R11Rk0)Tk
294 // R00 R01 R02 | (R21Rk2 - R22Rk1)Tk (R22Rk0 - R20Rk2)Tk (R20Rk1 - R21Rk0)Tk
295 // - - - - - - - - - - - - - - - - - - - - - - -
296 // 0 0 0 | R11R22 - R12R21 R12R20 - R10R22 R10R21 - R11R20
297 // 0 0 0 | R21R02 - R22R01 R22R00 - R20R02 R20R01 - R21R00
298 // 0 0 0 | R01R12 - R02R11 R02R10 - R00R12 R00R11 - R01R10
300 if (!gGeoManager || !gGeoManager->IsClosed()) {
301 AliError("Can't compute the global covariance matrix from the local one without an open geometry!");
305 const char* symname = GetSymName();
306 TGeoPhysicalNode* node;
307 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
309 if(!pne->GetPhysicalNode()){
310 node = gGeoManager->MakeAlignablePN(pne);
312 node = pne->GetPhysicalNode();
315 AliWarning(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as volume path!",symname));
316 node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(symname);
320 AliError(Form("Volume name or path %s not valid!",symname));
324 TGeoHMatrix gm; //global matrix
325 gm = *node->GetMatrix();
326 Double_t *tr = gm.GetTranslation();
327 Double_t *rot = gm.GetRotationMatrix();
329 TGeoHMatrix m; // global delta transformation matrix
331 // We should probably check that it's sufficinetly close to identity
332 // if it's not return because the "small angles" approximation cannot hold
334 // 3x3 upper left part (global shifts derived w.r.t. local shifts)
335 for(Int_t i=0; i<3; i++)
337 for(Int_t j=0; j<3; j++)
339 mJ(i,j) = rot[i+3*j];
343 // 3x3 lower left part (global angles derived w.r.t. local shifts)
344 for(Int_t i=0; i<3; i++)
346 for(Int_t j=0; j<3; j++)
352 // 3x3 upper right part (global shifts derived w.r.t. local angles)
353 for(Int_t i=0; i<3; i++)
355 for(Int_t j=0; j<3; j++)
360 for(Int_t k=0; k<3; k++)
362 mEl += (rot[3*i+b]*rot[3*k+d])*tr[k]-(rot[3*i+d]*rot[3*k+b])*tr[k];
368 // 3x3 lower right part (global angles derived w.r.t. local angles)
369 for(Int_t i=0; i<3; i++)
370 for(Int_t j=0; j<3; j++)
376 mJ(i+3,j+3) = rot[3*a+b]*rot[3*c+d]-rot[3*a+d]*rot[3*c+b];
383 //______________________________________________________________________________
384 Bool_t AliAlignObj::SetFromLocalCov(TMatrixDSym& lCov)
386 // Calculates the covariance matrix (6x6) associated to the six parameters
387 // defining the current alignment in the global coordinates system (and sets
388 // in the internal data members) from the covariance matrix (6x6) for the six
389 // parameters defining the alignment transformation in the local coordinates
390 // system, passed as an argument.
392 TMatrixD mJ(6,6);// the jacobian of the transformation from local to global parameters
393 if(!GetJacobian(mJ)) return kFALSE;
395 // Compute the global covariance matrix gcov = mJ lcov mJ'
396 TMatrixD trJ(TMatrixD::kTransposed, mJ);
397 TMatrixD lcovTrJ(lCov,TMatrixD::kMult,trJ);
398 TMatrixD gCovM(mJ,TMatrixD::kMult,lcovTrJ);
399 // To be done: somehow check that gCovM is close enough to be symmetric
401 for(Int_t i=0; i<6; i++)
403 gCov(i,i) = gCovM(i,i);
404 for(Int_t j=i+1; j<6; j++)
406 gCov(i,j)=gCovM(i,j);
407 gCov(j,i)=gCovM(i,j);
416 //______________________________________________________________________________
417 Bool_t AliAlignObj::SetFromLocalCov(Double_t *lCov)
419 // Calculates the covariance matrix (6x6) associated to the six parameters
420 // defining the current alignment in the global coordinates system, and sets
421 // in the internal data members, from the 21 coefficients, passed as argument,
422 // of the covariance matrix (6x6) for the six parameters defining the
423 // alignment transformation in the local coordinates system.
425 TMatrixDSym lCovMatrix(6);
428 for(Int_t i=0; i<6; i++)
429 for(Int_t j=i; j<6; j++)
431 lCovMatrix(i,j) = lCov[k++];
432 if(j!=i) lCovMatrix(j,i) = lCovMatrix(i,j);
435 return SetFromLocalCov(lCovMatrix);
440 //______________________________________________________________________________
441 void AliAlignObj::SetCorrMatrix(Double_t *cmat)
443 // Sets the correlation matrix data member from the coefficients of the external covariance
444 // matrix (21 elements passed as argument).
448 // Diagonal elements first
449 for(Int_t i=0; i<6; ++i) {
450 fDiag[i] = (cmat[i*(i+1)/2+i] >= 0.) ? TMath::Sqrt(cmat[i*(i+1)/2+i]) : -999.;
453 // ... then the ones off diagonal
454 for(Int_t i=0; i<6; ++i)
455 // Off diagonal elements
456 for(Int_t j=0; j<i; ++j) {
457 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).
458 if (fODia[(i-1)*i/2+j]>1.) fODia[(i-1)*i/2+j] = 1.; // check upper boundary
459 if (fODia[(i-1)*i/2+j]<-1.) fODia[(i-1)*i/2+j] = -1.; // check lower boundary
462 for(Int_t i=0; i< 6; ++i) fDiag[i]=-999.;
463 for(Int_t i=0; i< 6*(6-1)/2; ++i) fODia[i]=0.;
469 //______________________________________________________________________________
470 void AliAlignObj::SetCorrMatrix(TMatrixDSym& mcov)
472 // Sets the correlation matrix data member from the covariance matrix mcov passed
473 // passed as argument.
477 // Diagonal elements first
478 for(Int_t i=0; i<6; ++i) {
479 fDiag[i] = (mcov(i,i) >= 0.) ? TMath::Sqrt(mcov(i,i)) : -999.;
482 // ... then the ones off diagonal
483 for(Int_t i=0; i<6; ++i)
484 // Off diagonal elements
485 for(Int_t j=0; j<i; ++j) {
486 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).
487 if (fODia[(i-1)*i/2+j]>1.) fODia[(i-1)*i/2+j] = 1.; // check upper boundary
488 if (fODia[(i-1)*i/2+j]<-1.) fODia[(i-1)*i/2+j] = -1.; // check lower boundary
491 for(Int_t i=0; i< 6; ++i) fDiag[i]=-999.;
492 for(Int_t i=0; i< 6*(6-1)/2; ++i) fODia[i]=0.;
498 //_____________________________________________________________________________
499 void AliAlignObj::AnglesToMatrix(const Double_t *angles, Double_t *rot) const
501 // Calculates the rotation matrix using the
502 // Euler angles in "x y z" notation
504 Double_t degrad = TMath::DegToRad();
505 Double_t sinpsi = TMath::Sin(degrad*angles[0]);
506 Double_t cospsi = TMath::Cos(degrad*angles[0]);
507 Double_t sinthe = TMath::Sin(degrad*angles[1]);
508 Double_t costhe = TMath::Cos(degrad*angles[1]);
509 Double_t sinphi = TMath::Sin(degrad*angles[2]);
510 Double_t cosphi = TMath::Cos(degrad*angles[2]);
512 rot[0] = costhe*cosphi;
513 rot[1] = -costhe*sinphi;
515 rot[3] = sinpsi*sinthe*cosphi + cospsi*sinphi;
516 rot[4] = -sinpsi*sinthe*sinphi + cospsi*cosphi;
517 rot[5] = -costhe*sinpsi;
518 rot[6] = -cospsi*sinthe*cosphi + sinpsi*sinphi;
519 rot[7] = cospsi*sinthe*sinphi + sinpsi*cosphi;
520 rot[8] = costhe*cospsi;
523 //_____________________________________________________________________________
524 Bool_t AliAlignObj::MatrixToAngles(const Double_t *rot, Double_t *angles) const
526 // Calculates the Euler angles in "x y z" notation
527 // using the rotation matrix
528 // Returns false in case the rotation angles can not be
529 // extracted from the matrix
531 if(TMath::Abs(rot[0])<1e-7 || TMath::Abs(rot[8])<1e-7) {
532 AliError("Failed to extract roll-pitch-yall angles!");
535 Double_t raddeg = TMath::RadToDeg();
536 angles[0]=raddeg*TMath::ATan2(-rot[5],rot[8]);
537 angles[1]=raddeg*TMath::ASin(rot[2]);
538 angles[2]=raddeg*TMath::ATan2(-rot[1],rot[0]);
542 //______________________________________________________________________________
543 void AliAlignObj::Transform(AliTrackPoint &p, Bool_t copycov) const
545 // The method transforms the space-point coordinates using the
546 // transformation matrix provided by the AliAlignObj
547 // In case the copycov flag is set to kTRUE, the covariance matrix
548 // of the alignment object is copied into the space-point
550 if (fVolUID != p.GetVolumeID())
551 AliWarning(Form("Alignment object ID is not equal to the space-point ID (%d != %d)",fVolUID,p.GetVolumeID()));
555 Double_t *rot = m.GetRotationMatrix();
556 Double_t *tr = m.GetTranslation();
558 Float_t xyzin[3],xyzout[3];
560 for (Int_t i = 0; i < 3; i++)
568 TMatrixDSym covmat(6);
569 GetCovMatrix(covmat);
570 p.SetAlignCovMatrix(covmat);
575 //_____________________________________________________________________________
576 void AliAlignObj::Transform(AliTrackPointArray &array) const
578 // This method is used to transform all the track points
579 // from the input AliTrackPointArray
582 for (Int_t i = 0; i < array.GetNPoints(); i++) {
585 array.AddPoint(i,&p);
589 //_____________________________________________________________________________
590 void AliAlignObj::Print(Option_t *) const
592 // Print the contents of the
593 // alignment object in angles and
594 // matrix representations
602 const Double_t *rot = m.GetRotationMatrix();
604 printf("Volume=%s\n",GetSymName());
605 if (GetVolUID() != 0) {
606 AliGeomManager::ELayerID layerId;
608 GetVolUID(layerId,modId);
609 printf("VolumeID=%d LayerID=%d ( %s ) ModuleID=%d\n", GetVolUID(),layerId,AliGeomManager::LayerName(layerId),modId);
611 printf("%12.8f%12.8f%12.8f Tx = %12.8f Psi = %12.8f\n", rot[0], rot[1], rot[2], tr[0], angles[0]);
612 printf("%12.8f%12.8f%12.8f Ty = %12.8f Theta = %12.8f\n", rot[3], rot[4], rot[5], tr[1], angles[1]);
613 printf("%12.8f%12.8f%12.8f Tz = %12.8f Phi = %12.8f\n", rot[6], rot[7], rot[8], tr[2], angles[2]);
617 //_____________________________________________________________________________
618 void AliAlignObj::SetPars(Double_t x, Double_t y, Double_t z,
619 Double_t psi, Double_t theta, Double_t phi)
621 // Set the global delta transformation by passing 3 angles (expressed in
622 // degrees) and 3 shifts (in centimeters)
624 SetTranslation(x,y,z);
625 SetRotation(psi,theta,phi);
628 //_____________________________________________________________________________
629 Bool_t AliAlignObj::SetLocalPars(Double_t x, Double_t y, Double_t z,
630 Double_t psi, Double_t theta, Double_t phi)
632 // Set the global delta transformation by passing the parameters
633 // for the local delta transformation (3 shifts and 3 angles).
634 // In case that the TGeo was not initialized or not closed,
635 // returns false and the object parameters are not set.
638 Double_t tr[3] = {x, y, z};
639 m.SetTranslation(tr);
640 Double_t angles[3] = {psi, theta, phi};
642 AnglesToMatrix(angles,rot);
645 return SetLocalMatrix(m);
649 //_____________________________________________________________________________
650 Bool_t AliAlignObj::SetLocalTranslation(Double_t x, Double_t y, Double_t z)
652 // Set the global delta transformation by passing the three shifts giving
653 // the translation in the local reference system of the alignable
654 // volume (known by TGeo geometry).
655 // In case that the TGeo was not initialized or not closed,
656 // returns false and the object parameters are not set.
659 Double_t tr[3] = {x, y, z};
660 m.SetTranslation(tr);
662 return SetLocalMatrix(m);
666 //_____________________________________________________________________________
667 Bool_t AliAlignObj::SetLocalTranslation(const TGeoMatrix& m)
669 // Set the global delta transformation by passing the matrix of
670 // the local delta transformation and taking its translational part
671 // In case that the TGeo was not initialized or not closed,
672 // returns false and the object parameters are not set.
674 const Double_t* tr = m.GetTranslation();
676 mtr.SetTranslation(tr);
678 return SetLocalMatrix(mtr);
682 //_____________________________________________________________________________
683 Bool_t AliAlignObj::SetLocalRotation(Double_t psi, Double_t theta, Double_t phi)
685 // Set the global delta transformation by passing the three angles giving
686 // the rotation in the local reference system of the alignable
687 // volume (known by TGeo geometry).
688 // In case that the TGeo was not initialized or not closed,
689 // returns false and the object parameters are not set.
692 Double_t angles[3] = {psi, theta, phi};
694 AnglesToMatrix(angles,rot);
697 return SetLocalMatrix(m);
701 //_____________________________________________________________________________
702 Bool_t AliAlignObj::SetLocalRotation(const TGeoMatrix& m)
704 // Set the global delta transformation by passing the matrix of
705 // the local delta transformation and taking its rotational part
706 // In case that the TGeo was not initialized or not closed,
707 // returns false and the object parameters are not set.
710 const Double_t* rot = m.GetRotationMatrix();
711 rotm.SetRotation(rot);
713 return SetLocalMatrix(rotm);
717 //_____________________________________________________________________________
718 Bool_t AliAlignObj::SetLocalMatrix(const TGeoMatrix& m)
720 // Set the global delta transformation by passing the TGeo matrix
721 // for the local delta transformation.
722 // In case that the TGeo was not initialized or not closed,
723 // returns false and the object parameters are not set.
725 if (!gGeoManager || !gGeoManager->IsClosed()) {
726 AliError("Can't set the local alignment object parameters! gGeoManager doesn't exist or it is still open!");
730 const char* symname = GetSymName();
731 TGeoHMatrix gprime,gprimeinv;
732 TGeoPhysicalNode* pn = 0;
733 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
736 pn = pne->GetPhysicalNode();
739 AliWarning(Form("Volume %s has been misaligned already!",symname));
740 gprime = *pn->GetMatrix();
742 gprime = pne->GetGlobalOrig();
745 AliWarning(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as volume path!",symname));
746 if(!gGeoManager->cd(symname)) {
747 AliError(Form("Volume name or path %s not valid!",symname));
750 gprime = *gGeoManager->GetCurrentMatrix();
753 TGeoHMatrix m1; // the TGeoHMatrix copy of the local delta "m"
754 const Double_t *tr = m.GetTranslation();
755 m1.SetTranslation(tr);
756 const Double_t* rot = m.GetRotationMatrix();
759 gprimeinv = gprime.Inverse();
760 m1.Multiply(&gprimeinv);
761 m1.MultiplyLeft(&gprime);
763 return SetMatrix(m1);
766 //_____________________________________________________________________________
767 Bool_t AliAlignObj::SetMatrix(const TGeoMatrix& m)
769 // Set the global delta transformation by passing the TGeoMatrix
773 return SetRotation(m);
776 //_____________________________________________________________________________
777 Bool_t AliAlignObj::GetLocalPars(Double_t transl[], Double_t angles[]) const
779 // Get the translations and angles (in degrees) expressing the
780 // local delta transformation.
781 // In case that the TGeo was not initialized or not closed,
782 // returns false and the object parameters are not set.
784 if(!GetLocalTranslation(transl)) return kFALSE;
785 return GetLocalAngles(angles);
788 //_____________________________________________________________________________
789 Bool_t AliAlignObj::GetLocalTranslation(Double_t* tr) const
791 // Get the 3 shifts giving the translational part of the local
792 // delta transformation.
793 // In case that the TGeo was not initialized or not closed,
794 // returns false and the object parameters are not set.
797 if(!GetLocalMatrix(ml)) return kFALSE;
798 const Double_t* transl;
799 transl = ml.GetTranslation();
806 //_____________________________________________________________________________
807 Bool_t AliAlignObj::GetLocalAngles(Double_t* angles) const
809 // Get the 3 angles giving the rotational part of the local
810 // delta transformation.
811 // In case that the TGeo was not initialized or not closed,
812 // returns false and the object parameters are not set.
815 if(!GetLocalMatrix(ml)) return kFALSE;
816 const Double_t *rot = ml.GetRotationMatrix();
817 return MatrixToAngles(rot,angles);
820 //_____________________________________________________________________________
821 Bool_t AliAlignObj::GetLocalMatrix(TGeoHMatrix& m) const
823 // Get the matrix for the local delta transformation.
824 // In case that the TGeo was not initialized or not closed,
825 // returns false and the object parameters are not set.
827 if (!gGeoManager || !gGeoManager->IsClosed()) {
828 AliError("Can't get the local alignment object parameters! gGeoManager doesn't exist or it is still open!");
832 const char* symname = GetSymName();
833 TGeoPhysicalNode* node;
834 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
836 if(!pne->GetPhysicalNode()){
837 node = gGeoManager->MakeAlignablePN(pne);
839 node = pne->GetPhysicalNode();
842 AliWarning(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as volume path!",symname));
843 node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(symname);
847 AliError(Form("Volume name or path %s not valid!",symname));
850 // if (node->IsAligned())
851 // AliWarning(Form("Volume %s has been misaligned already!",symname));
854 TGeoHMatrix gprime,gprimeinv;
855 gprime = *node->GetMatrix();
856 gprimeinv = gprime.Inverse();
858 m.MultiplyLeft(&gprimeinv);
863 //_____________________________________________________________________________
864 Bool_t AliAlignObj::ApplyToGeometry(Bool_t ovlpcheck)
866 // Apply the current alignment object to the TGeo geometry
867 // This method returns FALSE if the symname of the object was not
868 // valid neither to get a TGeoPEntry nor as a volume path
870 if (!gGeoManager || !gGeoManager->IsClosed()) {
871 AliError("Can't apply the alignment object! gGeoManager doesn't exist or it is still open!");
875 if (gGeoManager->IsLocked()){
876 AliError("Can't apply the alignment object! Geometry is locked!");
880 const char* symname = GetSymName();
882 TGeoPhysicalNode* node;
883 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
885 path = pne->GetTitle();
886 node = gGeoManager->MakeAlignablePN(pne);
888 AliDebug(1,Form("The symbolic volume name %s does not correspond to a physical entry. Using it as a volume path!",symname));
890 if (!gGeoManager->CheckPath(path)) {
891 AliDebug(1,Form("Volume path %s not valid!",path));
894 if (gGeoManager->GetListOfPhysicalNodes()->FindObject(path)) {
895 AliError(Form("Volume %s has been misaligned already!",path));
898 node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(path);
902 AliError(Form("Volume path %s not valid!",path));
906 // Double_t threshold = 0.001;
908 TGeoHMatrix align,gprime;
909 gprime = *node->GetMatrix();
911 gprime.MultiplyLeft(&align);
912 TGeoHMatrix *ginv = new TGeoHMatrix;
913 TGeoHMatrix *g = node->GetMatrix(node->GetLevel()-1);
914 *ginv = g->Inverse();
916 AliGeomManager::ELayerID layerId; // unique identity for layer in the alobj
917 Int_t modId; // unique identity for volume inside layer in the alobj
918 GetVolUID(layerId, modId);
919 AliDebug(2,Form("Aligning volume %s of detector layer %d with local ID %d",symname,layerId,modId));
921 node->Align(ginv,0,kTRUE); //(trunk of root takes threshold as additional argument)
923 node->Align(ginv,0,kFALSE);
927 TObjArray* ovlpArray = gGeoManager->GetListOfOverlaps();
928 Int_t nOvlp = ovlpArray->GetEntriesFast();
931 AliInfo(Form("Misalignment of node %s generated the following overlaps/extrusions:",node->GetName()));
932 for(Int_t i=0; i<nOvlp; i++)
933 ((TGeoOverlap*)ovlpArray->UncheckedAt(i))->PrintInfo();