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