]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAlignObj.cxx
AliESDMuonTrack:
[u/mrichter/AliRoot.git] / STEER / AliAlignObj.cxx
index f805fb58ea60f5b391b7a448e63c6a3474277847..cee2c2bd86c9c8c54f949ec25188799524c37e9f 100644 (file)
 //  (AliAlignObjParams, AliAlignObjMatrix) are derived in separate files.
 //-----------------------------------------------------------------
 
-#include <TClass.h>
 #include <TGeoManager.h>
 #include <TGeoPhysicalNode.h>
 #include <TMath.h>
-#include "TObjString.h"
+#include <TMatrixDSym.h>
 
 #include "AliAlignObj.h"
 #include "AliTrackPointArray.h"
 #include "AliLog.h"
-#include "AliAlignObjParams.h"
  
 ClassImp(AliAlignObj)
 
@@ -42,7 +40,7 @@ AliAlignObj::AliAlignObj():
 {
   // default constructor
   for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
-  for(Int_t i=0; i<21; i++) fODia[i]=-999.;
+  for(Int_t i=0; i<15; i++) fODia[i]=-999.;
 }
 
 //_____________________________________________________________________________
@@ -54,7 +52,7 @@ AliAlignObj::AliAlignObj(const char* symname, UShort_t voluid) :
   // standard constructor
   //
   for(Int_t i=0; i<6; i++) fDiag[i]=-999.;
-  for(Int_t i=0; i<21; i++) fODia[i]=-999.;
+  for(Int_t i=0; i<15; i++) fODia[i]=-999.;
 }
 
 //_____________________________________________________________________________
@@ -76,7 +74,7 @@ AliAlignObj::AliAlignObj(const AliAlignObj& theAlignObj) :
 {
   //copy constructor
   for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
-  for(Int_t i=0; i<21; i++) fODia[i]=theAlignObj.fODia[i];
+  for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
 }
 
 //_____________________________________________________________________________
@@ -87,7 +85,7 @@ AliAlignObj &AliAlignObj::operator =(const AliAlignObj& theAlignObj)
   fVolPath = theAlignObj.GetSymName();
   fVolUID = theAlignObj.GetVolUID();
   for(Int_t i=0; i<6; i++) fDiag[i]=theAlignObj.fDiag[i];
-  for(Int_t i=0; i<21; i++) fODia[i]=theAlignObj.fODia[i];
+  for(Int_t i=0; i<15; i++) fODia[i]=theAlignObj.fODia[i];
   return *this;
 }
 
@@ -103,8 +101,11 @@ AliAlignObj &AliAlignObj::operator*=(const AliAlignObj& theAlignObj)
   theAlignObj.GetMatrix(m2);
   m1.MultiplyLeft(&m2);
   SetMatrix(m1);
-  // temporary solution: consider parameters indipendent 
-  for(Int_t i=0; i<6; i++)  fDiag[i] = TMath::Sqrt((fDiag[i]*fDiag[i])+(theAlignObj.fDiag[i]*theAlignObj.fDiag[i]));
+  // temporary solution: the covariance matrix of the resulting combined object
+  // is set equal to the covariance matrix of the right operand
+  // (not to be used for combining alignment objects for different levels)
+  for(Int_t i=0; i<6; i++)  fDiag[i] = theAlignObj.fDiag[i];
+  for(Int_t i=0; i<15; i++)  fODia[i] = theAlignObj.fODia[i];  
   return *this;
 }
 
@@ -165,9 +166,9 @@ Int_t AliAlignObj::GetLevel() const
     path = symname;
   }
 
-  TString path_str = path;
-  if(path_str[0]!='/') path_str.Prepend('/');
-  return path_str.CountChar('/');
+  TString pathStr = path;
+  if(pathStr[0]!='/') pathStr.Prepend('/');
+  return pathStr.CountChar('/');
 }
 
 //_____________________________________________________________________________
@@ -203,6 +204,27 @@ void AliAlignObj::GetCovMatrix(Double_t *cmat) const
     // Diagonal elements
     cmat[i*(i+1)/2+i] = (fDiag[i] >= 0.) ? fDiag[i]*fDiag[i] : -999.;
   }
+
+  return;
+}
+
+//______________________________________________________________________________
+void AliAlignObj::GetCovMatrix(TMatrixDSym& mcov) const
+{
+  // Fills the matrix m passed as argument as the covariance matrix calculated
+  // from the coefficients of the reduced covariance matrix data members
+  //
+
+  for(Int_t i=0; i<6; ++i) {
+    // Off diagonal elements
+    for(Int_t j=0; j<i; ++j) {
+      mcov(j,i) = mcov(i,j) = (fDiag[j] >= 0. && fDiag[i] >= 0.) ? fODia[(i-1)*i/2+j]*fDiag[j]*fDiag[i]: -999.;
+    }
+
+    // Diagonal elements
+    mcov(i,i) = (fDiag[i] >= 0.) ? fDiag[i]*fDiag[i] : -999.;
+  }
+
 }
 
 //______________________________________________________________________________
@@ -234,6 +256,35 @@ void AliAlignObj::SetCorrMatrix(Double_t *cmat)
   return;
 }
 
+//______________________________________________________________________________
+void AliAlignObj::SetCorrMatrix(TMatrixDSym& mcov)
+{
+  // Sets the correlation matrix data member from the covariance matrix mcov passed
+  // passed as argument. 
+  //
+  if(mcov.IsValid()) {
+
+    // Diagonal elements first
+    for(Int_t i=0; i<6; ++i) {
+      fDiag[i] = (mcov(i,i) >= 0.) ? TMath::Sqrt(mcov(i,i)) : -999.;
+    }
+
+    // ... then the ones off diagonal
+    for(Int_t i=0; i<6; ++i)
+      // Off diagonal elements
+      for(Int_t j=0; j<i; ++j) {
+       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).
+       if (fODia[(i-1)*i/2+j]>1.)  fODia[(i-1)*i/2+j] =  1.; // check upper boundary
+       if (fODia[(i-1)*i/2+j]<-1.) fODia[(i-1)*i/2+j] = -1.; // check lower boundary
+      }
+  } else {
+    for(Int_t i=0; i< 6; ++i) fDiag[i]=-999.;
+    for(Int_t i=0; i< 6*(6-1)/2; ++i) fODia[i]=0.;
+  }
+
+  return;
+}
+
 //_____________________________________________________________________________
 void AliAlignObj::AnglesToMatrix(const Double_t *angles, Double_t *rot) const
 {
@@ -279,12 +330,12 @@ Bool_t AliAlignObj::MatrixToAngles(const Double_t *rot, Double_t *angles) const
 }
 
 //______________________________________________________________________________
-void AliAlignObj::Transform(AliTrackPoint &p) const
+void AliAlignObj::Transform(AliTrackPoint &p, Bool_t copycov) const
 {
   // The method transforms the space-point coordinates using the
   // transformation matrix provided by the AliAlignObj
-  // The covariance matrix is not affected since we assume
-  // that the transformations are sufficiently small
+  // In case the copycov flag is set to kTRUE, the covariance matrix 
+  // of the alignment object is copied into the space-point
   //
   if (fVolUID != p.GetVolumeID())
     AliWarning(Form("Alignment object ID is not equal to the space-point ID (%d != %d)",fVolUID,p.GetVolumeID())); 
@@ -302,6 +353,12 @@ void AliAlignObj::Transform(AliTrackPoint &p) const
                 xyzin[1]*rot[3*i+1]+
                 xyzin[2]*rot[3*i+2];
   p.SetXYZ(xyzout);
+
+  if(copycov){
+    TMatrixDSym covmat(6);
+    GetCovMatrix(covmat); 
+    p.SetAlignCovMatrix(covmat);
+  }
   
 }
 
@@ -586,7 +643,7 @@ Bool_t AliAlignObj::GetLocalMatrix(TGeoHMatrix& m) const
 }
 
 //_____________________________________________________________________________
-Bool_t AliAlignObj::ApplyToGeometry()
+Bool_t AliAlignObj::ApplyToGeometry(Bool_t ovlpcheck)
 {
   // Apply the current alignment object to the TGeo geometry
   // This method returns FALSE if the symname of the object was not
@@ -635,7 +692,16 @@ Bool_t AliAlignObj::ApplyToGeometry()
   Int_t modId; // unique identity for volume inside layer in the alobj
   GetVolUID(layerId, modId);
   AliDebug(2,Form("Aligning volume %s of detector layer %d with local ID %d",symname,layerId,modId));
-  node->Align(ginv);
+  node->Align(ginv,0,ovlpcheck);
+  if(ovlpcheck){
+    Int_t novex=((TObjArray*)gGeoManager->GetListOfOverlaps())->GetEntriesFast();
+    if(novex){
+      TString error(Form("The alignment of volume %s introduced %d new overlap",GetSymName(),novex));
+      if(novex>1) error+="s";
+      AliError(error.Data());
+      return kFALSE;
+    }
+  }
 
   return kTRUE;
 }