]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliAlignObj.cxx
Define default values of cluster resolution per chamber in the
[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>
d555b92a 28#include <TGeoOverlap.h>
090026bf 29#include <TMath.h>
2499b21b 30#include <TMatrixDSym.h>
995ad051 31
c18195b9 32#include "AliAlignObj.h"
03b18860 33#include "AliTrackPointArray.h"
34#include "AliLog.h"
98937d93 35
c18195b9 36ClassImp(AliAlignObj)
37
38//_____________________________________________________________________________
39AliAlignObj::AliAlignObj():
fe12e09c 40 fVolPath(),
c18195b9 41 fVolUID(0)
42{
03b18860 43 // default constructor
90dbf5fb 44 for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
6b1b1a3b 45 for(Int_t i=0; i<15; i++) fODia[i]=-999.;
c18195b9 46}
47
48//_____________________________________________________________________________
b760c02e 49AliAlignObj::AliAlignObj(const char* symname, UShort_t voluid) :
fe12e09c 50 TObject(),
b760c02e 51 fVolPath(symname),
fe12e09c 52 fVolUID(voluid)
d9cc42ed 53{
54 // standard constructor
55 //
90dbf5fb 56 for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
6b1b1a3b 57 for(Int_t i=0; i<15; i++) fODia[i]=-999.;
90dbf5fb 58}
59
60//_____________________________________________________________________________
61AliAlignObj::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);
d9cc42ed 69}
70
d9cc42ed 71//_____________________________________________________________________________
c18195b9 72AliAlignObj::AliAlignObj(const AliAlignObj& theAlignObj) :
fe12e09c 73 TObject(theAlignObj),
b760c02e 74 fVolPath(theAlignObj.GetSymName()),
fe12e09c 75 fVolUID(theAlignObj.GetVolUID())
c18195b9 76{
77 //copy constructor
90dbf5fb 78 for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
6b1b1a3b 79 for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
c18195b9 80}
81
82//_____________________________________________________________________________
83AliAlignObj &AliAlignObj::operator =(const AliAlignObj& theAlignObj)
84{
85 // assignment operator
86 if(this==&theAlignObj) return *this;
b760c02e 87 fVolPath = theAlignObj.GetSymName();
c18195b9 88 fVolUID = theAlignObj.GetVolUID();
90dbf5fb 89 for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
6b1b1a3b 90 for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
c18195b9 91 return *this;
92}
93
38b3a170 94//_____________________________________________________________________________
95AliAlignObj &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);
6b1b1a3b 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];
38b3a170 111 return *this;
112}
113
c18195b9 114//_____________________________________________________________________________
115AliAlignObj::~AliAlignObj()
116{
117 // dummy destructor
118}
119
befe2c08 120//_____________________________________________________________________________
25be1e5c 121void AliAlignObj::SetVolUID(AliGeomManager::ELayerID detId, Int_t modId)
befe2c08 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 //
25be1e5c 128 fVolUID = AliGeomManager::LayerToVolUID(detId,modId);
befe2c08 129}
130
131//_____________________________________________________________________________
25be1e5c 132void AliAlignObj::GetVolUID(AliGeomManager::ELayerID &layerId, Int_t &modId) const
befe2c08 133{
7e154d52 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.
befe2c08 140 //
25be1e5c 141 layerId = AliGeomManager::VolUIDToLayer(fVolUID,modId);
befe2c08 142}
143
b760c02e 144//_____________________________________________________________________________
145Bool_t AliAlignObj::GetPars(Double_t tr[], Double_t angles[]) const
146{
147 GetTranslation(tr);
148 return GetAngles(angles);
149}
150
4b94e753 151//_____________________________________________________________________________
152Int_t AliAlignObj::GetLevel() const
153{
85fbf070 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){
44a3c417 159 AliWarning("gGeoManager doesn't exist or it is still open: unable to return meaningful level value.");
85fbf070 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
2499b21b 171 TString pathStr = path;
172 if(pathStr[0]!='/') pathStr.Prepend('/');
173 return pathStr.CountChar('/');
4b94e753 174}
175
176//_____________________________________________________________________________
177Int_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
7e154d52 184 //
4b94e753 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
90dbf5fb 193//______________________________________________________________________________
194void 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 }
e9304cb8 209
210 return;
211}
212
213//______________________________________________________________________________
214void 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
90dbf5fb 230}
231
232//______________________________________________________________________________
233void 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
e9304cb8 261//______________________________________________________________________________
262void 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
c18195b9 290//_____________________________________________________________________________
291void AliAlignObj::AnglesToMatrix(const Double_t *angles, Double_t *rot) const
292{
fdf65bb5 293 // Calculates the rotation matrix using the
294 // Euler angles in "x y z" notation
7e154d52 295 //
c18195b9 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//_____________________________________________________________________________
316Bool_t AliAlignObj::MatrixToAngles(const Double_t *rot, Double_t *angles) const
317{
fdf65bb5 318 // Calculates the Euler angles in "x y z" notation
319 // using the rotation matrix
b760c02e 320 // Returns false in case the rotation angles can not be
321 // extracted from the matrix
7e154d52 322 //
b760c02e 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 }
c18195b9 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
03b18860 334//______________________________________________________________________________
6b1b1a3b 335void AliAlignObj::Transform(AliTrackPoint &p, Bool_t copycov) const
03b18860 336{
337 // The method transforms the space-point coordinates using the
338 // transformation matrix provided by the AliAlignObj
6b1b1a3b 339 // In case the copycov flag is set to kTRUE, the covariance matrix
340 // of the alignment object is copied into the space-point
7e154d52 341 //
03b18860 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);
6b1b1a3b 358
359 if(copycov){
360 TMatrixDSym covmat(6);
361 GetCovMatrix(covmat);
362 p.SetAlignCovMatrix(covmat);
363 }
03b18860 364
365}
366
79e21da6 367//_____________________________________________________________________________
03b18860 368void AliAlignObj::Transform(AliTrackPointArray &array) const
369{
e1e6896f 370 // This method is used to transform all the track points
371 // from the input AliTrackPointArray
7e154d52 372 //
03b18860 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
c18195b9 381//_____________________________________________________________________________
382void AliAlignObj::Print(Option_t *) const
383{
384 // Print the contents of the
385 // alignment object in angles and
386 // matrix representations
7e154d52 387 //
c18195b9 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();
c18195b9 395
b760c02e 396 printf("Volume=%s\n",GetSymName());
c041444f 397 if (GetVolUID() != 0) {
25be1e5c 398 AliGeomManager::ELayerID layerId;
c041444f 399 Int_t modId;
400 GetVolUID(layerId,modId);
25be1e5c 401 printf("VolumeID=%d LayerID=%d ( %s ) ModuleID=%d\n", GetVolUID(),layerId,AliGeomManager::LayerName(layerId),modId);
c041444f 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
b760c02e 409//_____________________________________________________________________________
410void AliAlignObj::SetPars(Double_t x, Double_t y, Double_t z,
411 Double_t psi, Double_t theta, Double_t phi)
412{
32898fe7 413 // Set the global delta transformation by passing 3 angles (expressed in
414 // degrees) and 3 shifts (in centimeters)
7e154d52 415 //
b760c02e 416 SetTranslation(x,y,z);
417 SetRotation(psi,theta,phi);
418}
419
1bfe7ffc 420//_____________________________________________________________________________
421Bool_t AliAlignObj::SetLocalPars(Double_t x, Double_t y, Double_t z,
422 Double_t psi, Double_t theta, Double_t phi)
423{
32898fe7 424 // Set the global delta transformation by passing the parameters
425 // for the local delta transformation (3 shifts and 3 angles).
7e154d52 426 // In case that the TGeo was not initialized or not closed,
427 // returns false and the object parameters are not set.
428 //
b760c02e 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
32898fe7 441//_____________________________________________________________________________
442Bool_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//_____________________________________________________________________________
459Bool_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//_____________________________________________________________________________
475Bool_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//_____________________________________________________________________________
494Bool_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
b760c02e 509//_____________________________________________________________________________
510Bool_t AliAlignObj::SetLocalMatrix(const TGeoMatrix& m)
511{
32898fe7 512 // Set the global delta transformation by passing the TGeo matrix
513 // for the local delta transformation.
7e154d52 514 // In case that the TGeo was not initialized or not closed,
515 // returns false and the object parameters are not set.
516 //
1bfe7ffc 517 if (!gGeoManager || !gGeoManager->IsClosed()) {
44a3c417 518 AliError("Can't set the local alignment object parameters! gGeoManager doesn't exist or it is still open!");
1bfe7ffc 519 return kFALSE;
520 }
521
b760c02e 522 const char* symname = GetSymName();
523 TGeoPhysicalNode* node;
524 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
525 if(pne){
44a3c417 526 if(!pne->GetPhysicalNode()){
527 node = gGeoManager->MakeAlignablePN(pne);
528 }else{
529 node = pne->GetPhysicalNode();
530 }
b760c02e 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
1bfe7ffc 536 if (!node) {
b760c02e 537 AliError(Form("Volume name or path %s not valid!",symname));
1bfe7ffc 538 return kFALSE;
539 }
540 if (node->IsAligned())
b760c02e 541 AliWarning(Form("Volume %s has been already misaligned!",symname));
1bfe7ffc 542
b760c02e 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);
1bfe7ffc 548
549 TGeoHMatrix align,gprime,gprimeinv;
550 gprime = *node->GetMatrix();
551 gprimeinv = gprime.Inverse();
b760c02e 552 m1.Multiply(&gprimeinv);
553 m1.MultiplyLeft(&gprime);
1bfe7ffc 554
b760c02e 555 return SetMatrix(m1);
556}
1bfe7ffc 557
b760c02e 558//_____________________________________________________________________________
559Bool_t AliAlignObj::SetMatrix(const TGeoMatrix& m)
560{
32898fe7 561 // Set the global delta transformation by passing the TGeoMatrix
562 // for it
7e154d52 563 //
b760c02e 564 SetTranslation(m);
565 return SetRotation(m);
1bfe7ffc 566}
567
32898fe7 568//_____________________________________________________________________________
569Bool_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//_____________________________________________________________________________
581Bool_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//_____________________________________________________________________________
599Bool_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//_____________________________________________________________________________
613Bool_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()) {
44a3c417 620 AliError("Can't get the local alignment object parameters! gGeoManager doesn't exist or it is still open!");
32898fe7 621 return kFALSE;
622 }
623
624 const char* symname = GetSymName();
625 TGeoPhysicalNode* node;
626 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
627 if(pne){
44a3c417 628 if(!pne->GetPhysicalNode()){
629 node = gGeoManager->MakeAlignablePN(pne);
630 }else{
631 node = pne->GetPhysicalNode();
632 }
32898fe7 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
995ad051 655//_____________________________________________________________________________
5590c6c3 656Bool_t AliAlignObj::ApplyToGeometry(Bool_t ovlpcheck)
995ad051 657{
7e154d52 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 //
995ad051 662 if (!gGeoManager || !gGeoManager->IsClosed()) {
44a3c417 663 AliError("Can't apply the alignment object! gGeoManager doesn't exist or it is still open!");
995ad051 664 return kFALSE;
665 }
171c4ef9 666
44a3c417 667 if (gGeoManager->IsLocked()){
668 AliError("Can't apply the alignment object! Geometry is locked!");
669 return kFALSE;
670 }
671
b760c02e 672 const char* symname = GetSymName();
673 const char* path;
674 TGeoPhysicalNode* node;
675 TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
676 if(pne){
b760c02e 677 path = pne->GetTitle();
7e154d52 678 node = gGeoManager->MakeAlignablePN(pne);
b760c02e 679 }else{
5bd470e1 680 AliDebug(1,Form("The symbolic volume name %s does not correspond to a physical entry. Using it as a volume path!",symname));
b760c02e 681 path=symname;
7e154d52 682 if (!gGeoManager->CheckPath(path)) {
5bd470e1 683 AliDebug(1,Form("Volume path %s not valid!",path));
b760c02e 684 return kFALSE;
685 }
7e154d52 686 if (gGeoManager->GetListOfPhysicalNodes()->FindObject(path)) {
687 AliError(Form("Volume %s has already been misaligned!",path));
b760c02e 688 return kFALSE;
689 }
690 node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(path);
995ad051 691 }
48cac49d 692
48cac49d 693 if (!node) {
b760c02e 694 AliError(Form("Volume path %s not valid!",path));
995ad051 695 return kFALSE;
696 }
697
d555b92a 698 Double_t threshold = 0.001;
171c4ef9 699
995ad051 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;
25be1e5c 708 AliGeomManager::ELayerID layerId; // unique identity for layer in the alobj
b760c02e 709 Int_t modId; // unique identity for volume inside layer in the alobj
995ad051 710 GetVolUID(layerId, modId);
b760c02e 711 AliDebug(2,Form("Aligning volume %s of detector layer %d with local ID %d",symname,layerId,modId));
5590c6c3 712 if(ovlpcheck){
d555b92a 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();
5590c6c3 726 }
727 }
d555b92a 728
995ad051 729 return kTRUE;
730}
731
171c4ef9 732