]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONGeometryMisAligner.cxx
Separating run-dependent mapping data from data, which are not
[u/mrichter/AliRoot.git] / MUON / AliMUONGeometryMisAligner.cxx
index 566ce38614cc4204409e06e2f3d1c657eb6cac5e..00189749e5d952d8c5649b2a54d7f3acb526f568 100644 (file)
 
 // $Id$
 //
-// Class AliMUONGeometryMisAligner 
-// ----------------------------
-// Class for misalignment of geometry transformations
-//
-// Author:Bruce Becker
-
-//__________________________________________________________________
-//
-/////////////////////////////////////////////////////////////////////
-//This performs the misalignment on an existing muon arm geometry
-//  based on the standard definition of the detector elements in 
-//  $ALICE_ROOT/MUON/data
-//
-//  --> User has to specify the magnitude of the alignments, in the Cartesian 
-//  co-ordiantes (which are used to apply translation misalignments) and in the
-//  spherical co-ordinates (which are used to apply angular displacements)
-//  --> If the constructor is used with no arguments, user has to set 
-//  misalignment ranges by hand using the methods : 
-//  SetApplyMisAlig, SetMaxCartMisAlig, SetMaxAngMisAlig, SetXYAngMisAligFactor
-//  (last method takes account of the fact that the misalingment is greatest in 
-//  the XY plane, since the detection elements are fixed to a support structure
-//  in this plane. Misalignments in the XZ and YZ plane will be very small 
-//  compared to those in the XY plane, which are small already - of the order 
-//  of microns)
-
-//  Note : If the detection elements are allowed to be misaligned in all
-//  directions, this has consequences for the alignment algorithm
-//  (AliMUONAlignment), which needs to know the number of free parameters. 
-//  Eric only allowed 3 :  x,y,theta_xy, but in principle z and the other 
-//  two angles are alignable as well.
+//-----------------------------------------------------------------------------
+/// \class AliMUONGeometryMisAligner
+///
+/// This performs the misalignment on an existing muon arm geometry
+/// based on the standard definition of the detector elements in 
+/// $ALICE_ROOT/MUON/data
+///
+/// --> User has to specify the magnitude of the alignments, in the Cartesian 
+/// co-ordiantes (which are used to apply translation misalignments) and in the
+/// spherical co-ordinates (which are used to apply angular displacements)
+///
+/// --> If the constructor is used with no arguments, user has to set 
+/// misalignment ranges by hand using the methods : 
+/// SetApplyMisAlig, SetMaxCartMisAlig, SetMaxAngMisAlig, SetXYAngMisAligFactor
+/// (last method takes account of the fact that the misalingment is greatest in 
+/// the XY plane, since the detection elements are fixed to a support structure
+/// in this plane. Misalignments in the XZ and YZ plane will be very small 
+/// compared to those in the XY plane, which are small already - of the order 
+/// of microns)
+///
+/// Note : If the detection elements are allowed to be misaligned in all
+/// directions, this has consequences for the alignment algorithm
+/// (AliMUONAlignment), which needs to know the number of free parameters. 
+/// Eric only allowed 3 :  x,y,theta_xy, but in principle z and the other 
+/// two angles are alignable as well.
+///
+/// \author Bruce Becker, Javier Castillo
+//-----------------------------------------------------------------------------
 
 #include "AliMUONGeometryMisAligner.h"
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONGeometryModuleTransformer.h"
 #include "AliMUONGeometryDetElement.h"
-#include "AliMUONGeometryStore.h"
 #include "AliMUONGeometryBuilder.h"
 
+#include "AliMpExMap.h"
+#include "AliMpExMapIterator.h"
+
 #include "AliLog.h"
 
-#include <TGeoManager.h>
-#include <Riostream.h>
-#include <TObjArray.h>
-#include <TSystem.h>
+#include <TGeoMatrix.h>
 #include <TMath.h>
 #include <TRandom.h>
+#include <Riostream.h>
 
-#include <sstream>
-
+/// \cond CLASSIMP
 ClassImp(AliMUONGeometryMisAligner)
+/// \endcond
+
 //______________________________________________________________________________
-AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
-:TObject(), fDisplacementGenerator(0)
+AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartXMisAligM, Double_t cartXMisAligW, Double_t cartYMisAligM, Double_t cartYMisAligW, Double_t angMisAligM, Double_t angMisAligW)
+  : TObject(),
+    fUseUni(kFALSE),
+    fUseGaus(kTRUE),
+    fXYAngMisAligFactor(0.0),
+    fZCartMisAligFactor(0.0),
+    fDisplacementGenerator(0)
 {
   /// Standard constructor
-  fMaxCartMisAlig = cartMisAlig;       // 0.5 mm. Perhaps this should go into AliMUONConstants.h ? 
-  fMaxAngMisAlig = angMisAlig;
-  fXYAngMisAligFactor = 1.0;
+  for (Int_t i=0; i<6; i++){
+    for (Int_t j=0; j<2; j++){
+      fDetElemMisAlig[i][j] = 0.0;
+      fModuleMisAlig[i][j] = 0.0;
+    }
+  }
+  fDetElemMisAlig[0][0] = cartXMisAligM; 
+  fDetElemMisAlig[0][1] = cartXMisAligW; 
+  fDetElemMisAlig[1][0] = cartYMisAligM; 
+  fDetElemMisAlig[1][1] = cartYMisAligW; 
+  fDetElemMisAlig[5][0] = angMisAligM; 
+  fDetElemMisAlig[5][1] = angMisAligW;
+
   fDisplacementGenerator = new TRandom(0);
 }
 
-//_____________________________________________________________________________
-AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
-:TObject(), fDisplacementGenerator(0)
+//______________________________________________________________________________
+AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAligM, Double_t cartMisAligW, Double_t angMisAligM, Double_t angMisAligW)
+  : TObject(), 
+    fUseUni(kFALSE),
+    fUseGaus(kTRUE),
+    fXYAngMisAligFactor(0.0),
+    fZCartMisAligFactor(0.0),
+    fDisplacementGenerator(0)
 {
-/// Default constructor
+  /// Standard constructor
+  for (Int_t i=0; i<6; i++){
+    for (Int_t j=0; j<2; j++){
+      fDetElemMisAlig[i][j] = 0.0;
+      fModuleMisAlig[i][j] = 0.0;
+    }
+  }
+  fDetElemMisAlig[0][0] = cartMisAligM; 
+  fDetElemMisAlig[0][1] = cartMisAligW; 
+  fDetElemMisAlig[1][0] = cartMisAligM; 
+  fDetElemMisAlig[1][1] = cartMisAligW; 
+  fDetElemMisAlig[5][0] = angMisAligM; 
+  fDetElemMisAlig[5][1] = angMisAligW;
+
+  fDisplacementGenerator = new TRandom(0);
 }
 
 //______________________________________________________________________________
-AliMUONGeometryMisAligner::
-AliMUONGeometryMisAligner(const AliMUONGeometryMisAligner & right):
-TObject(right)
+AliMUONGeometryMisAligner::AliMUONGeometryMisAligner(Double_t cartMisAlig, Double_t angMisAlig)
+  : TObject(), 
+    fUseUni(kTRUE),
+    fUseGaus(kFALSE),
+    fXYAngMisAligFactor(0.0),
+    fZCartMisAligFactor(0.0),
+    fDisplacementGenerator(0)
 {
-  /// Copy constructor (not implemented)
+  /// Standard constructor
+  for (Int_t i=0; i<6; i++){
+    for (Int_t j=0; j<2; j++){
+      fDetElemMisAlig[i][j] = 0.0;
+      fModuleMisAlig[i][j] = 0.0;
+    }
+  }
+  fDetElemMisAlig[0][1] = cartMisAlig; 
+  fDetElemMisAlig[1][1] = cartMisAlig; 
+  fDetElemMisAlig[5][1] = angMisAlig;
 
-  AliFatal("Copy constructor not provided.");
+  fDisplacementGenerator = new TRandom(0);
 }
 
-//______________________________________________________________________________
-AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
+//_____________________________________________________________________________
+AliMUONGeometryMisAligner::AliMUONGeometryMisAligner()
+  : TObject(), 
+    fUseUni(kTRUE),
+    fUseGaus(kFALSE),
+    fXYAngMisAligFactor(0.0),
+    fZCartMisAligFactor(0.0),
+    fDisplacementGenerator(0)
 {
-/// Destructor
-
-  delete fDisplacementGenerator;
+  /// Default constructor
+  for (Int_t i=0; i<6; i++){
+    for (Int_t j=0; j<2; j++){
+      fDetElemMisAlig[i][j] = 0.0;
+      fModuleMisAlig[i][j] = 0.0;
+    }
+  }
 }
 
 //______________________________________________________________________________
-AliMUONGeometryMisAligner & AliMUONGeometryMisAligner::
-operator=(const AliMUONGeometryMisAligner & right)
+AliMUONGeometryMisAligner::~AliMUONGeometryMisAligner()
 {
-  /// Assignement operator (not implemented)
-
-  // check assignement to self
-  if (this == &right)
-    return *this;
-
-  AliFatal("Assignement operator not provided.");
+/// Destructor
 
-  return *this;
+  if (fDisplacementGenerator) delete fDisplacementGenerator;
 }
 
+//_________________________________________________________________________
 void
 AliMUONGeometryMisAligner::SetXYAngMisAligFactor(Double_t factor)
 {
-  if (TMath::Abs(factor) > 1.0 && factor > 0.)
+  /// Set XY angular misalign factor 
+
+  if (TMath::Abs(factor) > 1.0 && factor > 0.){
     fXYAngMisAligFactor = factor;
+    fDetElemMisAlig[3][0] = fDetElemMisAlig[5][0]*factor; // These lines were 
+    fDetElemMisAlig[3][1] = fDetElemMisAlig[5][1]*factor; // added to keep
+    fDetElemMisAlig[4][0] = fDetElemMisAlig[5][0]*factor; // backward 
+    fDetElemMisAlig[4][1] = fDetElemMisAlig[5][1]*factor; // compatibility 
+  }
   else
-    AliError(Form("Invalid factor, %d", factor));
+    AliError(Form("Invalid XY angular misalign factor, %d", factor));
 }
 
 //_________________________________________________________________________
-TGeoCombiTrans AliMUONGeometryMisAligner::MisAlign(const TGeoCombiTrans & transform) const
+void AliMUONGeometryMisAligner::SetZCartMisAligFactor(Double_t factor) 
 {
-  /// Misalign given transformation and return the misaligned transformation
-  
-  Double_t cartMisAlig[3] = {0,0,0};
-  Double_t angMisAlig[3] = {0,0,0};
-  const Double_t *trans = transform.GetTranslation();
-  TGeoRotation *rot;
-  // check if the rotation we obtain is not NULL
-  if (transform.GetRotation())
-    {
-      rot = transform.GetRotation();
-    }
+  /// Set XY angular misalign factor 
+  if (TMath::Abs(factor)<1.0 && factor>0.) {
+    fZCartMisAligFactor = factor;
+    fDetElemMisAlig[2][0] = fDetElemMisAlig[0][0];        // These lines were added to 
+    fDetElemMisAlig[2][1] = fDetElemMisAlig[0][1]*factor; // keep backward compatibility
+  }
   else
-    {
-      rot = new TGeoRotation("rot");
-    }                  // default constructor.
-  
-  cartMisAlig[0] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
-  cartMisAlig[1] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
-  cartMisAlig[2] = fDisplacementGenerator->Uniform(-1. * fMaxCartMisAlig, fMaxCartMisAlig);
-  
-  TGeoTranslation newTrans(cartMisAlig[0] + trans[0], cartMisAlig[1] + trans[1], cartMisAlig[2] + trans[2]);
-  
-  /*
+    AliError(Form("Invalid Z cartesian misalign factor, %d", factor));
+}
+
+//_________________________________________________________________________
+void AliMUONGeometryMisAligner::GetUniMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
+{
+  /// Misalign using uniform distribution
+  /**
+    misalign the centre of the local transformation
+    rotation axes : 
+    fAngMisAlig[1,2,3] = [x,y,z]
+    Assume that misalignment about the x and y axes (misalignment of z plane)
+    is much smaller, since the entire detection plane has to be moved (the 
+    detection elements are on a support structure), while rotation of the x-y
+    plane is more free.
+  */
+  cartMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[0][1]+lParMisAlig[0][0], lParMisAlig[0][0]+lParMisAlig[0][1]);
+  cartMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[1][1]+lParMisAlig[1][0], lParMisAlig[1][0]+lParMisAlig[1][1]);
+  cartMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[2][1]+lParMisAlig[2][0], lParMisAlig[2][0]+lParMisAlig[2][1]);  
+  angMisAlig[0] = fDisplacementGenerator->Uniform(-lParMisAlig[3][1]+lParMisAlig[3][0], lParMisAlig[3][0]+lParMisAlig[3][1]);
+  angMisAlig[1] = fDisplacementGenerator->Uniform(-lParMisAlig[4][1]+lParMisAlig[4][0], lParMisAlig[4][0]+lParMisAlig[4][1]);
+  angMisAlig[2] = fDisplacementGenerator->Uniform(-lParMisAlig[5][1]+lParMisAlig[5][0], lParMisAlig[5][0]+lParMisAlig[5][1]);  // degrees
+}
+
+//_________________________________________________________________________
+void AliMUONGeometryMisAligner::GetGausMisAlign(Double_t cartMisAlig[3], Double_t angMisAlig[3], const Double_t lParMisAlig[6][2]) const
+{
+  /// Misalign using gaussian distribution
+  /**
     misalign the centre of the local transformation
     rotation axes : 
     fAngMisAlig[1,2,3] = [x,y,z]
@@ -159,42 +230,123 @@ TGeoCombiTrans AliMUONGeometryMisAligner::MisAlign(const TGeoCombiTrans & transf
     detection elements are on a support structure), while rotation of the x-y
     plane is more free.
   */
+  cartMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[0][0], lParMisAlig[0][1]);
+  cartMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[1][0], lParMisAlig[1][1]);
+  cartMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[2][0], lParMisAlig[2][1]);
+  angMisAlig[0] = fDisplacementGenerator->Gaus(lParMisAlig[3][0], lParMisAlig[3][1]);
+  angMisAlig[1] = fDisplacementGenerator->Gaus(lParMisAlig[4][0], lParMisAlig[4][1]);
+  angMisAlig[2] = fDisplacementGenerator->Gaus(lParMisAlig[5][0], lParMisAlig[5][1]);  // degrees
+}
+
+//_________________________________________________________________________
+TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignDetElem(const TGeoCombiTrans & transform) const
+{
+  /// Misalign given transformation and return the misaligned transformation. 
+  /// Use misalignment parameters for detection elements.
+  /// Note that applied misalignments are small deltas with respect to the detection 
+  /// element own ideal local reference frame. Thus deltaTransf represents 
+  /// the transformation to go from the misaligned d.e. local coordinates to the 
+  /// ideal d.e. local coordinates. 
+  /// Also note that this -is not- what is in the ALICE alignment framework known 
+  /// as local nor global (see AliMUONGeometryMisAligner::MisAlign) 
   
-  angMisAlig[0] = fDisplacementGenerator->Uniform(fXYAngMisAligFactor * fMaxAngMisAlig,  1.0 * fMaxAngMisAlig);
-  angMisAlig[1] =    fDisplacementGenerator->Uniform(fXYAngMisAligFactor * fMaxAngMisAlig, 1.0 * fMaxAngMisAlig);
-  angMisAlig[2] = fDisplacementGenerator->Uniform(-1. * fMaxAngMisAlig, fMaxAngMisAlig);       // degrees
-  AliInfo(Form("Rotated by %f about Z axis.", angMisAlig[2]));
-  rot->RotateX(angMisAlig[0]);
-  rot->RotateY(angMisAlig[1]);
-  rot->RotateZ(angMisAlig[2]);
-
-  return TGeoCombiTrans(newTrans, *rot);
+  Double_t cartMisAlig[3] = {0,0,0};
+  Double_t angMisAlig[3] = {0,0,0};
+
+  if (fUseUni) { 
+    GetUniMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
+  }
+  else { 
+    if (!fUseGaus) {
+      AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
+    } 
+    GetGausMisAlign(cartMisAlig,angMisAlig,fDetElemMisAlig);
+  }
+
+  TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
+  TGeoRotation deltaRot;
+  deltaRot.RotateX(angMisAlig[0]);
+  deltaRot.RotateY(angMisAlig[1]);
+  deltaRot.RotateZ(angMisAlig[2]);
+
+  TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
+  TGeoHMatrix newTransfMat = transform * deltaTransf;
+    
+  AliInfo(Form("Rotated DE by %f about Z axis.", angMisAlig[2]));
+
+  return TGeoCombiTrans(newTransfMat);
 }
 
+//_________________________________________________________________________
+TGeoCombiTrans AliMUONGeometryMisAligner::MisAlignModule(const TGeoCombiTrans & transform) const
+{
+  /// Misalign given transformation and return the misaligned transformation. 
+  /// Use misalignment parameters for modules.
+  /// Note that applied misalignments are small deltas with respect to the module 
+  /// own ideal local reference frame. Thus deltaTransf represents 
+  /// the transformation to go from the misaligned module local coordinates to the 
+  /// ideal module local coordinates. 
+  /// Also note that this -is not- what is in the ALICE alignment framework known 
+  /// as local nor global (see AliMUONGeometryMisAligner::MisAlign) 
+  
+  Double_t cartMisAlig[3] = {0,0,0};
+  Double_t angMisAlig[3] = {0,0,0};
+
+  if (fUseUni) { 
+    GetUniMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
+  }
+  else { 
+    if (!fUseGaus) {
+      AliWarning("Neither uniform nor gausian distribution is set! Will use gausian...");
+    } 
+    GetGausMisAlign(cartMisAlig,angMisAlig,fModuleMisAlig);
+  }
+
+  TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
+  TGeoRotation deltaRot;
+  deltaRot.RotateX(angMisAlig[0]);
+  deltaRot.RotateY(angMisAlig[1]);
+  deltaRot.RotateZ(angMisAlig[2]);
+
+  TGeoCombiTrans deltaTransf(deltaTrans,deltaRot);
+  TGeoHMatrix newTransfMat = transform * deltaTransf;
+
+  AliInfo(Form("Rotated Module by %f about Z axis.", angMisAlig[2]));
+
+  return TGeoCombiTrans(newTransfMat);
+}
 
 //______________________________________________________________________
 AliMUONGeometryTransformer *
 AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
-                                transformer, Bool_t verbose)
+                                   transformer, Bool_t verbose)
 {
-  /////////////////////////////////////////////////////////////////////
-  //   Takes the internal geometry module transformers, copies them
-  // and gets the Detection Elements from them.
-  // Calculates misalignment parameters and applies these
-  // to the local transform of the Detection Element
-  // Obtains the global transform by multiplying the module transformer
-  // transformation with the local transformation 
-  // Applies the global transform to a new detection element
-  // Adds the new detection element to a new module transformer
-  // Adds the new module transformer to a new geometry transformer
-  // Returns the new geometry transformer
+  /// Takes the internal geometry module transformers, copies them to
+  /// new geometry module transformers. 
+  /// Calculates  module misalignment parameters and applies these
+  /// to the new module transformer.
+  /// Calculates the module misalignment delta transformation in the 
+  /// Alice Alignment Framework newTransf = delta * oldTransf.
+  /// Add a module misalignment to the new geometry transformer.
+  /// Gets the Detection Elements from the module transformer. 
+  /// Calculates misalignment parameters and applies these
+  /// to the local transformation of the Detection Element.
+  /// Obtains the new global transformation by multiplying the new 
+  /// module transformer transformation with the new local transformation. 
+  /// Applies the new global transform to a new detection element.
+  /// Adds the new detection element to a new module transformer.
+  /// Calculates the d.e. misalignment delta transformation in the 
+  /// Alice Alignment Framework (newGlobalTransf = delta * oldGlobalTransf).
+  /// Add a d.e. misalignment to the new geometry transformer.
+  /// Adds the new module transformer to a new geometry transformer.
+  /// Returns the new geometry transformer.
 
 
   AliMUONGeometryTransformer *newGeometryTransformer =
-    new AliMUONGeometryTransformer(kTRUE);
+    new AliMUONGeometryTransformer();
   for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++)
     {                          // module transformers
-      
       const AliMUONGeometryModuleTransformer *kModuleTransformer =
        transformer->GetModuleTransformer(iMt, true);
       
@@ -204,26 +356,31 @@ AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
 
       TGeoCombiTrans moduleTransform =
        TGeoCombiTrans(*kModuleTransformer->GetTransformation());
-      TGeoCombiTrans *newModuleTransform = new TGeoCombiTrans(moduleTransform);        
-              // same module transform as the previous one 
-             // no mis align object created
-      newModuleTransformer->SetTransformation(moduleTransform);
+      // New module transformation
+      TGeoCombiTrans newModuleTransform = MisAlignModule(moduleTransform);
+      newModuleTransformer->SetTransformation(newModuleTransform);
 
-      AliMUONGeometryStore *detElements =
-       kModuleTransformer->GetDetElementStore();
+      // Get delta transformation: 
+      // Tdelta = Tnew * Told.inverse
+      TGeoHMatrix deltaModuleTransform = 
+       AliMUONGeometryBuilder::Multiply(
+         newModuleTransform, 
+         kModuleTransformer->GetTransformation()->Inverse());
 
-      if (verbose)
-       AliInfo(Form
-               ("%i DEs in old GeometryStore  %i",
-                detElements->GetNofEntries(), iMt));
+      // Create module mis alignment matrix
+      newGeometryTransformer
+       ->AddMisAlignModule(kModuleTransformer->GetModuleId(), deltaModuleTransform);
 
-      for (Int_t iDe = 0; iDe < detElements->GetNofEntries(); iDe++)
-       {                       // detection elements.
-         AliMUONGeometryDetElement *detElement =
-           (AliMUONGeometryDetElement *) detElements->GetEntry(iDe);
-         if (!detElement)
-           AliFatal("Detection element not found.");
+      AliMpExMap *detElements = kModuleTransformer->GetDetElementStore();
+
+      if (verbose)
+       AliInfo(Form("%i DEs in old GeometryStore  %i",detElements->GetSize(), iMt));
 
+      TIter next(detElements->CreateIterator());
+      AliMUONGeometryDetElement *detElement;
+      
+      while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
+      {
          /// make a new detection element
          AliMUONGeometryDetElement *newDetElement =
            new AliMUONGeometryDetElement(detElement->GetId(),
@@ -232,29 +389,37 @@ AliMUONGeometryMisAligner::MisAlign(const AliMUONGeometryTransformer *
          // local transformation of this detection element.
           TGeoCombiTrans localTransform
            = TGeoCombiTrans(*detElement->GetLocalTransformation());
-         TGeoCombiTrans newLocalTransform = MisAlign(localTransform);
-          newDetElement->SetLocalTransformation(newLocalTransform);                                      
+         TGeoCombiTrans newLocalTransform = MisAlignDetElem(localTransform);
+          newDetElement->SetLocalTransformation(newLocalTransform);
+
 
          // global transformation
          TGeoHMatrix newGlobalTransform =
-           AliMUONGeometryBuilder::Multiply(*newModuleTransform,
-                                             newLocalTransform);
+           AliMUONGeometryBuilder::Multiply(newModuleTransform,
+                                            newLocalTransform);
          newDetElement->SetGlobalTransformation(newGlobalTransform);
          
          // add this det element to module
          newModuleTransformer->GetDetElementStore()->Add(newDetElement->GetId(),
                                                          newDetElement);
-          // Get delta transformation: 
+
+         // In the Alice Alignment Framework misalignment objects store
+         // global delta transformation
+         // Get detection "intermediate" global transformation
+         TGeoHMatrix newOldGlobalTransform = newModuleTransform * localTransform;
+          // Get detection element global delta transformation: 
          // Tdelta = Tnew * Told.inverse
-         TGeoHMatrix  deltaTransform
+         TGeoHMatrix  deltaGlobalTransform
            = AliMUONGeometryBuilder::Multiply(
                newGlobalTransform, 
-               detElement->GetGlobalTransformation()->Inverse());
+               newOldGlobalTransform.Inverse());
          
          // Create mis alignment matrix
          newGeometryTransformer
-           ->AddMisAlignDetElement(detElement->GetId(), deltaTransform);
+           ->AddMisAlignDetElement(detElement->GetId(), deltaGlobalTransform);
        }
+
+      
       if (verbose)
        AliInfo(Form("Added module transformer %i to the transformer", iMt));
       newGeometryTransformer->AddModuleTransformer(newModuleTransformer);