]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAlignObj.cxx
bug
[u/mrichter/AliRoot.git] / STEER / AliAlignObj.cxx
index 117b430b36286727947f563189ff2aa93727265d..c98fa986c983f16bdd736fc8d7b06b1dc6deaafd 100644 (file)
 //  (AliAlignObjParams, AliAlignObjMatrix) are derived in separate files.
 //-----------------------------------------------------------------
 
-#include <TClass.h>
 #include <TGeoManager.h>
+#include <TGeoMatrix.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 +41,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 +53,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 +75,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 +86,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 +102,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;
 }
 
@@ -153,7 +155,7 @@ Int_t AliAlignObj::GetLevel() const
   // slashes in the corresponding volume path
   //
   if(!gGeoManager){
-    AliWarning("gGeoManager doesn't exist or it is still opened: unable to return meaningful level value.");
+    AliWarning("gGeoManager doesn't exist or it is still open: unable to return meaningful level value.");
     return (-1);
   }
   const char* symname = GetSymName();
@@ -165,9 +167,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('/');
 }
 
 //_____________________________________________________________________________
@@ -329,12 +331,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())); 
@@ -352,6 +354,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);
+  }
   
 }
 
@@ -506,7 +514,7 @@ Bool_t AliAlignObj::SetLocalMatrix(const TGeoMatrix& m)
   // returns false and the object parameters are not set.
   //
   if (!gGeoManager || !gGeoManager->IsClosed()) {
-    AliError("Can't set the alignment object parameters! gGeoManager doesn't exist or it is still opened!");
+    AliError("Can't set the local alignment object parameters! gGeoManager doesn't exist or it is still open!");
     return kFALSE;
   }
 
@@ -514,7 +522,11 @@ Bool_t AliAlignObj::SetLocalMatrix(const TGeoMatrix& m)
   TGeoPhysicalNode* node;
   TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
   if(pne){
-    node = gGeoManager->MakeAlignablePN(pne);
+    if(!pne->GetPhysicalNode()){
+      node = gGeoManager->MakeAlignablePN(pne);
+    }else{
+      node = pne->GetPhysicalNode();
+    }
   }else{
     AliWarning(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as volume path!",symname));
     node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(symname);
@@ -604,7 +616,7 @@ Bool_t AliAlignObj::GetLocalMatrix(TGeoHMatrix& m) const
   // returns false and the object parameters are not set.
   //
   if (!gGeoManager || !gGeoManager->IsClosed()) {
-    AliError("Can't set the alignment object parameters! gGeoManager doesn't exist or it is still opened!");
+    AliError("Can't get the local alignment object parameters! gGeoManager doesn't exist or it is still open!");
     return kFALSE;
   }
 
@@ -612,7 +624,11 @@ Bool_t AliAlignObj::GetLocalMatrix(TGeoHMatrix& m) const
   TGeoPhysicalNode* node;
   TGeoPNEntry* pne = gGeoManager->GetAlignableEntry(symname);
   if(pne){
-    node = gGeoManager->MakeAlignablePN(pne);
+    if(!pne->GetPhysicalNode()){
+      node = gGeoManager->MakeAlignablePN(pne);
+    }else{
+      node = pne->GetPhysicalNode();
+    }
   }else{
     AliWarning(Form("The symbolic volume name %s does not correspond to a physical entry. Using it as volume path!",symname));
     node = (TGeoPhysicalNode*) gGeoManager->MakePhysicalNode(symname);
@@ -636,17 +652,22 @@ 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
   // valid neither to get a TGeoPEntry nor as a volume path
   //
   if (!gGeoManager || !gGeoManager->IsClosed()) {
-    AliError("Can't apply the alignment object! gGeoManager doesn't exist or it is still opened!");
+    AliError("Can't apply the alignment object! gGeoManager doesn't exist or it is still open!");
     return kFALSE;
   }
   
+  if (gGeoManager->IsLocked()){
+    AliError("Can't apply the alignment object! Geometry is locked!");
+    return kFALSE;
+  }
+
   const char* symname = GetSymName();
   const char* path;
   TGeoPhysicalNode* node;
@@ -685,7 +706,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;
 }