]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONAlignment.cxx
Adding MUONChamberMaterialBudget.C:
[u/mrichter/AliRoot.git] / MUON / AliMUONAlignment.cxx
index ffb5596286c4c31a54315f1a2fd1cd76cb0f5ba8..23c4336764eb55410c52f1368c2d6c82dfcecf1a 100644 (file)
 /* $Id$ */
 
 //-----------------------------------------------------------------------------
-/// \class AliMUONAlignmentV5
-/// Alignment class fro the ALICE DiMuon spectrometer 
+/// \class AliMUONAlignment
+/// Alignment class for the ALICE DiMuon spectrometer 
 ///
 /// MUON specific alignment class which interface to AliMillepede.   
 /// For each track ProcessTrack calculates the local and global derivatives
-/// at each hit and fill the corresponding local equations. Provide methods for
-/// fixing or constraining detection elements for best results. 
+/// at each cluster and fill the corresponding local equations. Provide methods
+/// for fixing or constraining detection elements for best results. 
 ///
 /// \author Bruce Becker, Javier Castillo
 //-----------------------------------------------------------------------------
 
 #include "AliMUONAlignment.h"
 #include "AliMUONTrack.h"
-#include "AliMUONRawCluster.h"
 #include "AliMUONTrackParam.h"
-#include "AliMUONHitForRec.h"
+#include "AliMUONVCluster.h"
 #include "AliMUONGeometryTransformer.h"
 #include "AliMUONGeometryModuleTransformer.h"
 #include "AliMUONGeometryDetElement.h"
 #include "AliMillepede.h"
 
 #include "AliMpExMap.h"
+#include "AliMpExMapIterator.h"
 
+#include "AliAlignObjMatrix.h"
 #include "AliLog.h"
 
+#include "TMath.h"
+#include "TMatrixDSym.h"
 #include "TSystem.h"
 
 /// \cond CLASSIMP
@@ -52,7 +55,7 @@ ClassImp(AliMUONAlignment)
   Int_t AliMUONAlignment::fgNDetElem = 4*2+4*2+18*2+26*2+26*2;
   Int_t AliMUONAlignment::fgNDetElemCh[10] = {4,4,4,4,18,18,26,26,26,26};
   Int_t AliMUONAlignment::fgSNDetElemCh[10] = {4,8,12,16,34,52,78,104,130,156};
-  Int_t AliMUONAlignment::fgNParCh = 3;
+  Int_t AliMUONAlignment::fgNParCh = 4;
   Int_t AliMUONAlignment::fgNTrkMod = 16;
   Int_t AliMUONAlignment::fgNCh = 10;
   Int_t AliMUONAlignment::fgNSt = 5;
@@ -60,14 +63,13 @@ ClassImp(AliMUONAlignment)
 AliMUONAlignment::AliMUONAlignment() 
   : TObject(),
     fBFieldOn(kTRUE),
-    fStartFac(16.), 
+    fStartFac(256.), 
     fResCutInitial(100.), 
     fResCut(100.),
     fMillepede(0),
-    fTrackParamAtHit(0),
-    fHitForRecAtHit(0),
+    fTrackParamAtCluster(0),
     fTrack(0),
-    fRecHit(0),
+    fCluster(0),
     fTrackParam(0),
     fNGlobal(fgNDetElem*fgNParCh),
     fNLocal(4),
@@ -83,8 +85,8 @@ AliMUONAlignment::AliMUONAlignment()
   fSigma[0] = 1.0e-1;
   fSigma[1] = 1.0e-2;
 
-  fDoF[0] = kTRUE;  fDoF[1] = kTRUE;  fDoF[2] = kTRUE;
-  fAllowVar[0] = 0.05;  fAllowVar[1] = 0.05;  fAllowVar[2] = 0.001;
+  fDoF[0] = kTRUE;  fDoF[1] = kTRUE;  fDoF[2] = kTRUE;  fDoF[3] = kTRUE;
+  fAllowVar[0] = 0.05;  fAllowVar[1] = 0.05;  fAllowVar[2] = 0.001;  fAllowVar[3] = 0.5;
   
   AliInfo(Form("fAllowVar[0]: %f\t fAllowVar[1]: %f\t fPhi: %f\t fgNDetElem: %i\t fNGlobal: %i\t fNLocal: %i",fAllowVar[0],fAllowVar[1],fPhi,fgNDetElem,fNGlobal,fNLocal));
 
@@ -108,16 +110,19 @@ void AliMUONAlignment::Init(Int_t nGlobal,  /* number of global paramers */
   /// Initialization of AliMillepede. Fix parameters, define constraints ...
   fMillepede->InitMille(nGlobal,nLocal,nStdDev,fResCut,fResCutInitial);
 
-  Bool_t bStOnOff[5] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
-  Bool_t bSpecLROnOff[2] = {kTRUE,kTRUE};
+//  Bool_t bStOnOff[5] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
+//  Bool_t bChOnOff[10] = {kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE,kTRUE};
+//  Bool_t bSpecLROnOff[2] = {kTRUE,kTRUE};
 
-  AllowVariations(bStOnOff);
+//   AllowVariations(bChOnOff);
 
   // Fix parameters or add constraints here
-  for (Int_t iSt=0; iSt<5; iSt++)
-    if (!bStOnOff[iSt]) FixStation(iSt+1);
+//   for (Int_t iSt=0; iSt<5; iSt++)
+//     if (!bStOnOff[iSt]) FixStation(iSt+1);
+//   for (Int_t iCh=0; iCh<10; iCh++)
+//     if (!bChOnOff[iCh]) FixChamber(iCh+1);
 
-  FixHalfSpectrometer(bStOnOff,bSpecLROnOff);
+//   FixHalfSpectrometer(bChOnOff,bSpecLROnOff);
 
   ResetConstraints();
   
@@ -147,29 +152,63 @@ void AliMUONAlignment::FixStation(Int_t iSt){
     FixParameter(i*fgNParCh+0, 0.0);
     FixParameter(i*fgNParCh+1, 0.0);
     FixParameter(i*fgNParCh+2, 0.0);
+    FixParameter(i*fgNParCh+3, 0.0);
   }
 }
 
-void AliMUONAlignment::FixHalfSpectrometer(Bool_t *lStOnOff, Bool_t *lSpecLROnOff){
+void AliMUONAlignment::FixChamber(Int_t iCh){
+  /// Fix all detection elements of chamber iCh
+  Int_t iDetElemFirst = (iCh>1) ? fgSNDetElemCh[iCh-2] : 0; 
+  Int_t iDetElemLast = fgSNDetElemCh[iCh-1]; 
+  for (Int_t i = iDetElemFirst; i < iDetElemLast; i++){    
+    FixParameter(i*fgNParCh+0, 0.0);
+    FixParameter(i*fgNParCh+1, 0.0);
+    FixParameter(i*fgNParCh+2, 0.0);
+    FixParameter(i*fgNParCh+3, 0.0);
+  }
+}
+
+void AliMUONAlignment::FixDetElem(Int_t iDetElemId, TString sVarXYT){
+  /// Fix a given detection element
+  Int_t iDetElemNumber = iDetElemId%100;
+  for (int iCh=0; iCh<iDetElemId/100-1; iCh++){
+    iDetElemNumber += fgNDetElemCh[iCh];
+  }
+  if (sVarXYT.Contains("X")) { // X constraint
+    FixParameter(iDetElemNumber*fgNParCh+0, 0.0);
+  }
+  if (sVarXYT.Contains("Y")) { // Y constraint
+    FixParameter(iDetElemNumber*fgNParCh+1, 0.0);
+  }
+  if (sVarXYT.Contains("T")) { // T constraint
+    FixParameter(iDetElemNumber*fgNParCh+2, 0.0);
+  }
+  if (sVarXYT.Contains("Z")) { // T constraint
+    FixParameter(iDetElemNumber*fgNParCh+3, 0.0);
+  }
+}
+
+void AliMUONAlignment::FixHalfSpectrometer(Bool_t *lChOnOff, Bool_t *lSpecLROnOff){
   /// Fix left or right detector
   for (Int_t i = 0; i < fgNDetElem; i++){    
     Int_t iCh=0;
     for (iCh=1; iCh<=fgNCh; iCh++){
       if (i<fgSNDetElemCh[iCh-1]) break;
     }
-    Int_t iSt = lStOnOff[(iCh-1)/2] ? (iCh+1)/2 : 0; 
-    if (iSt){
+    if (lChOnOff[iCh-1]){
       Int_t lDetElemNumber = (iCh==1) ? i : i-fgSNDetElemCh[iCh-2];
       if (iCh>=1 && iCh<=4){
        if ((lDetElemNumber==1 || lDetElemNumber==2) && !lSpecLROnOff[0]){ // From track crossings
          FixParameter(i*fgNParCh+0, 0.0);
          FixParameter(i*fgNParCh+1, 0.0);
          FixParameter(i*fgNParCh+2, 0.0);
+         FixParameter(i*fgNParCh+3, 0.0);
        }
        if ((lDetElemNumber==0 || lDetElemNumber==3) && !lSpecLROnOff[1]){ // From track crossings
          FixParameter(i*fgNParCh+0, 0.0);
          FixParameter(i*fgNParCh+1, 0.0);
          FixParameter(i*fgNParCh+2, 0.0);
+         FixParameter(i*fgNParCh+3, 0.0);
        }
       }
       if (iCh>=5 && iCh<=6){
@@ -177,12 +216,14 @@ void AliMUONAlignment::FixHalfSpectrometer(Bool_t *lStOnOff, Bool_t *lSpecLROnOf
          FixParameter(i*fgNParCh+0, 0.0);
          FixParameter(i*fgNParCh+1, 0.0);
          FixParameter(i*fgNParCh+2, 0.0);
+         FixParameter(i*fgNParCh+3, 0.0);
        }
        if (((lDetElemNumber>=0&&lDetElemNumber<=4) || 
             (lDetElemNumber>=14&&lDetElemNumber<=17)) && !lSpecLROnOff[1]){
          FixParameter(i*fgNParCh+0, 0.0);
          FixParameter(i*fgNParCh+1, 0.0);
          FixParameter(i*fgNParCh+2, 0.0);
+         FixParameter(i*fgNParCh+3, 0.0);
        }
       }
       if (iCh>=7 && iCh<=10){
@@ -190,27 +231,28 @@ void AliMUONAlignment::FixHalfSpectrometer(Bool_t *lStOnOff, Bool_t *lSpecLROnOf
          FixParameter(i*fgNParCh+0, 0.0);
          FixParameter(i*fgNParCh+1, 0.0);
          FixParameter(i*fgNParCh+2, 0.0);
+         FixParameter(i*fgNParCh+3, 0.0);
        }
        if (((lDetElemNumber>=0&&lDetElemNumber<=6) || 
             (lDetElemNumber>=20&&lDetElemNumber<=25)) && !lSpecLROnOff[1]){
          FixParameter(i*fgNParCh+0, 0.0);
          FixParameter(i*fgNParCh+1, 0.0);
          FixParameter(i*fgNParCh+2, 0.0);
+         FixParameter(i*fgNParCh+3, 0.0);
        }
       }
     }
   }
 }
 
-void AliMUONAlignment::SetNonLinear(Bool_t *lStOnOff,Bool_t *lVarXYT){
-  /// Set non linear parameter flag selected stations and degrees of freedom
+void AliMUONAlignment::SetNonLinear(Bool_t *lChOnOff,Bool_t *lVarXYT){
+  /// Set non linear parameter flag selected chambers and degrees of freedom
   for (Int_t i = 0; i < fgNDetElem; i++){    
     Int_t iCh=0;
     for (iCh=1; iCh<=fgNCh; iCh++){
       if (i<fgSNDetElemCh[iCh-1]) break;
     }
-    Int_t iSt = lStOnOff[(iCh-1)/2] ? (iCh+1)/2 : 0; 
-    if (iSt){
+    if (lChOnOff[iCh-1]){
       if (lVarXYT[0]) { // X constraint
        SetNonLinear(i*fgNParCh+0);
       }
@@ -220,19 +262,21 @@ void AliMUONAlignment::SetNonLinear(Bool_t *lStOnOff,Bool_t *lVarXYT){
       if (lVarXYT[2]) { // T constraint
        SetNonLinear(i*fgNParCh+2);
       }
+      if (lVarXYT[3]) { // Z constraint
+       SetNonLinear(i*fgNParCh+3);
+      }
     }
   }
 }
 
-void AliMUONAlignment::AddConstraints(Bool_t *lStOnOff,Bool_t *lVarXYT){
-  /// Add constraint equations for selected stations and degrees of freedom 
+void AliMUONAlignment::AddConstraints(Bool_t *lChOnOff,Bool_t *lVarXYT){
+  /// Add constraint equations for selected chambers and degrees of freedom 
   for (Int_t i = 0; i < fgNDetElem; i++){    
     Int_t iCh=0;
     for (iCh=1; iCh<=fgNCh; iCh++){
       if (i<fgSNDetElemCh[iCh-1]) break;
     }
-    Int_t iSt = lStOnOff[(iCh-1)/2] ? (iCh+1)/2 : 0; 
-    if (iSt){
+    if (lChOnOff[iCh-1]){
       if (lVarXYT[0]) { // X constraint
        fConstraintX[i*fgNParCh+0]=1.0;
       }
@@ -242,6 +286,9 @@ void AliMUONAlignment::AddConstraints(Bool_t *lStOnOff,Bool_t *lVarXYT){
       if (lVarXYT[2]) { // T constraint
        fConstraintP[i*fgNParCh+2]=1.0;
       }
+//       if (lVarXYT[3]) { // Z constraint
+//     fConstraintP[i*fgNParCh+3]=1.0;
+//       }
     }
   }
   if (lVarXYT[0]) { // X constraint
@@ -253,10 +300,13 @@ void AliMUONAlignment::AddConstraints(Bool_t *lStOnOff,Bool_t *lVarXYT){
   if (lVarXYT[2]) { // T constraint
     AddConstraint(fConstraintP,0.0);
   }
+//   if (lVarXYT[3]) { // Z constraint
+//     AddConstraint(fConstraintP,0.0);
+//   }
 }
 
-void AliMUONAlignment::AddConstraints(Bool_t *lStOnOff,Bool_t *lVarXYT, Bool_t *lDetTLBR, Bool_t *lSpecLROnOff){
-  /// Add constraint equations for selected stations, degrees of freedom and detector half 
+void AliMUONAlignment::AddConstraints(Bool_t *lChOnOff,Bool_t *lVarXYT, Bool_t *lDetTLBR, Bool_t *lSpecLROnOff){
+  /// Add constraint equations for selected chambers, degrees of freedom and detector half 
   Double_t lDetElemLocX = 0.;
   Double_t lDetElemLocY = 0.;
   Double_t lDetElemLocZ = 0.;
@@ -273,8 +323,7 @@ void AliMUONAlignment::AddConstraints(Bool_t *lStOnOff,Bool_t *lVarXYT, Bool_t *
     for (iCh=1; iCh<=fgNCh; iCh++){
       if (i<fgSNDetElemCh[iCh-1]) break;
     }
-    Int_t iSt = lStOnOff[(iCh-1)/2] ? (iCh+1)/2 : 0; 
-    if (iSt){
+    if (lChOnOff[iCh-1]){ 
       Int_t lDetElemNumber = (iCh==1) ? i : i-fgSNDetElemCh[iCh-2];
       Int_t lDetElemId = iCh*100+lDetElemNumber;
       fTransform->Local2Global(lDetElemId,lDetElemLocX,lDetElemLocY,lDetElemLocZ,
@@ -344,8 +393,7 @@ void AliMUONAlignment::AddConstraints(Bool_t *lStOnOff,Bool_t *lVarXYT, Bool_t *
     for (iCh=1; iCh<=fgNCh; iCh++){
       if (i<fgSNDetElemCh[iCh-1]) break;
     }
-    Int_t iSt = lStOnOff[(iCh-1)/2] ? (iCh+1)/2 : 0; 
-    if (iSt){
+    if (lChOnOff[iCh-1]){
       Int_t lDetElemNumber = (iCh==1) ? i : i-fgSNDetElemCh[iCh-2];
       Int_t lDetElemId = iCh*100+lDetElemNumber;
       fTransform->Local2Global(lDetElemId,lDetElemLocX,lDetElemLocY,lDetElemLocZ,
@@ -702,12 +750,12 @@ void AliMUONAlignment::ResetLocalEquation()
   }
 }
 
-void AliMUONAlignment::AllowVariations(Bool_t *bStOnOff) {
-  /// Set allowed variation for selected stations based on fDoF and fAllowVar
-  for (Int_t iSt=1; iSt<=5; iSt++) {
-    if (bStOnOff[iSt-1]) {
-      Int_t iDetElemFirst = (iSt>1) ? fgSNDetElemCh[2*(iSt-1)-1] : 0; 
-      Int_t iDetElemLast = fgSNDetElemCh[2*(iSt)-1]; 
+void AliMUONAlignment::AllowVariations(Bool_t *bChOnOff) {
+  /// Set allowed variation for selected chambers based on fDoF and fAllowVar
+  for (Int_t iCh=1; iCh<=10; iCh++) {
+    if (bChOnOff[iCh-1]) {
+      Int_t iDetElemFirst = (iCh>1) ? fgSNDetElemCh[iCh-2] : 0; 
+      Int_t iDetElemLast = fgSNDetElemCh[iCh-1]; 
       for (int i=0; i<fgNParCh; i++) {
        AliDebug(1,Form("fDoF[%d]= %d",i,fDoF[i]));    
        if (fDoF[i]) {
@@ -727,7 +775,7 @@ void AliMUONAlignment::SetNonLinear(Int_t iPar  /* set non linear flag */ ) {
 }
 
 void AliMUONAlignment::LocalEquationX() {
-  /// Define local equation for current track and hit in x coor. measurement
+  /// Define local equation for current track and cluster in x coor. measurement
   // set local derivatives
   SetLocalDerivative(0, fCosPhi);
   SetLocalDerivative(1, fCosPhi * (fTrackPos[2] - fTrackPos0[2]));
@@ -749,12 +797,14 @@ void AliMUONAlignment::LocalEquationX() {
                        +fCosPhi*(fTrackPos0[1]+fTrackSlope0[1]*
                                  (fTrackPos[2]-fTrackPos0[2])-fDetElemPos[1]));
   }
+  SetGlobalDerivative(fDetElemNumber*fgNParCh+3, 
+                     fCosPhi*fTrackSlope0[0]+fSinPhi*fTrackSlope0[1]);
 
   fMillepede->SetLocalEquation(fGlobalDerivatives, fLocalDerivatives, fMeas[0], fSigma[0]);
 }
 
 void AliMUONAlignment::LocalEquationY() {
-  /// Define local equation for current track and hit in y coor. measurement
+  /// Define local equation for current track and cluster in y coor. measurement
   // set local derivatives
   SetLocalDerivative(0,-fSinPhi);
   SetLocalDerivative(1,-fSinPhi * (fTrackPos[2] - fTrackPos0[2]));
@@ -776,21 +826,23 @@ void AliMUONAlignment::LocalEquationY() {
                        -fSinPhi*(fTrackPos0[1]+fTrackSlope0[1]*
                                  (fTrackPos[2]-fTrackPos0[2])-fDetElemPos[1]));
   }
+  SetGlobalDerivative(fDetElemNumber*fgNParCh+3,
+                     -fSinPhi*fTrackSlope0[0]+fCosPhi*fTrackSlope0[1]);
 
   fMillepede->SetLocalEquation(fGlobalDerivatives, fLocalDerivatives, fMeas[1], fSigma[1]);
 }
 
 void AliMUONAlignment::FillRecPointData() {
-  /// Get information of current hit
-  fClustPos[0] = fRecHit->GetNonBendingCoor();
-  fClustPos[1] = fRecHit->GetBendingCoor();
-  fClustPos[2] = fRecHit->GetZ();
+  /// Get information of current cluster
+  fClustPos[0] = fCluster->GetX();
+  fClustPos[1] = fCluster->GetY();
+  fClustPos[2] = fCluster->GetZ();
   fTransform->Global2Local(fDetElemId,fClustPos[0],fClustPos[1],fClustPos[2],
                            fClustPosLoc[0],fClustPosLoc[1],fClustPosLoc[2]);
 }
 
 void AliMUONAlignment::FillTrackParamData() {
-  /// Get information of current track at current hit
+  /// Get information of current track at current cluster
   fTrackPos[0] = fTrackParam->GetNonBendingCoor();
   fTrackPos[1] = fTrackParam->GetBendingCoor();
   fTrackPos[2] = fTrackParam->GetZ();
@@ -805,7 +857,7 @@ void AliMUONAlignment::FillDetElemData() {
   Double_t lDetElemLocX = 0.;
   Double_t lDetElemLocY = 0.;
   Double_t lDetElemLocZ = 0.;
-  fDetElemId = fRecHit->GetDetElemId();
+  fDetElemId = fCluster->GetDetElemId();
   fDetElemNumber = fDetElemId%100;
   for (int iCh=0; iCh<fDetElemId/100-1; iCh++){
     fDetElemNumber += fgNDetElemCh[iCh];
@@ -815,22 +867,19 @@ void AliMUONAlignment::FillDetElemData() {
 }
 
 void AliMUONAlignment::ProcessTrack(AliMUONTrack * track) {
-  /// Process track; Loop over hits and set local equations
+  /// Process track; Loop over clusters and set local equations
   fTrack = track;
   // get tclones arrays.
-  fTrackParamAtHit = fTrack->GetTrackParamAtHit();
-  fHitForRecAtHit = fTrack->GetHitForRecAtHit();
+  fTrackParamAtCluster = fTrack->GetTrackParamAtCluster();
   
   // get size of arrays
-  Int_t nTrackParam = fTrackParamAtHit->GetEntries();
-  Int_t nHitForRec = fHitForRecAtHit->GetEntries();
+  Int_t nTrackParam = fTrackParamAtCluster->GetEntries();
   AliDebug(1,Form("Number of track param entries : %i ", nTrackParam));
-  AliDebug(1,Form("Number of hit for rec entries : %i ", nHitForRec));
 
-  for(Int_t iHit=0; iHit<nHitForRec; iHit++) {
-    fRecHit = (AliMUONHitForRec *) fHitForRecAtHit->At(iHit);
-    fTrackParam = (AliMUONTrackParam *) fTrack->GetTrackParamAtHit()->At(iHit);
-    if (!fRecHit || !fTrackParam) continue;
+  for(Int_t iCluster=0; iCluster<nTrackParam; iCluster++) {
+    fTrackParam = (AliMUONTrackParam *) fTrack->GetTrackParamAtCluster()->At(iCluster);
+    fCluster = fTrackParam->GetClusterPtr();
+    if (!fCluster || !fTrackParam) continue;
     // fill local variables for this position --> one measurement
     FillDetElemData();
     FillRecPointData();
@@ -844,21 +893,21 @@ void AliMUONAlignment::ProcessTrack(AliMUONTrack * track) {
     break;
   }
 
-  for(Int_t iHit=0; iHit<nHitForRec; iHit++) {
+  for(Int_t iCluster=0; iCluster<nTrackParam; iCluster++) {
     // and get new pointers
-    fRecHit = (AliMUONHitForRec *) fHitForRecAtHit->At(iHit);
-    fTrackParam = (AliMUONTrackParam *) fTrack->GetTrackParamAtHit()->At(iHit);
-    if (!fRecHit || !fTrackParam) continue;
+    fTrackParam = (AliMUONTrackParam *) fTrack->GetTrackParamAtCluster()->At(iCluster);
+    fCluster = fTrackParam->GetClusterPtr();
+    if (!fCluster || !fTrackParam) continue;
     // fill local variables for this position --> one measurement
     FillDetElemData();        
     FillRecPointData();
     FillTrackParamData();
 //     if (fDetElemId<500) continue;
-    AliDebug(1,Form("cluster: %i", iHit));
+    AliDebug(1,Form("cluster: %i", iCluster));
     AliDebug(1,Form("x: %f\t y: %f\t z: %f\t DetElemID: %i\t ", fClustPos[0], fClustPos[1], fClustPos[2], fDetElemId));
     AliDebug(1,Form("fDetElemPos[0]: %f\t fDetElemPos[1]: %f\t fDetElemPos[2]: %f\t DetElemID: %i\t ", fDetElemPos[0],fDetElemPos[1],fDetElemPos[2], fDetElemId));
 
-    AliDebug(1,Form("Track Parameter: %i", iHit));
+    AliDebug(1,Form("Track Parameter: %i", iCluster));
     AliDebug(1,Form("x: %f\t y: %f\t z: %f\t slopex: %f\t slopey: %f", fTrackPos[0], fTrackPos[1], fTrackPos[2], fTrackSlope[0], fTrackSlope[1]));
     AliDebug(1,Form("x0: %f\t y0: %f\t z0: %f\t slopex0: %f\t slopey0: %f", fTrackPos0[0], fTrackPos0[1], fTrackPos0[2], fTrackSlope0[0], fTrackSlope0[1]));
     
@@ -925,9 +974,10 @@ TGeoCombiTrans AliMUONAlignment::ReAlign(const TGeoCombiTrans & transform, doubl
 //     rot = new TGeoRotation("rot");
 //   }                 // default constructor.
 
-  cartMisAlig[0] = -lMisAlignment[0];
-  cartMisAlig[1] = -lMisAlignment[1];
-  angMisAlig[2] = -lMisAlignment[2]*180./TMath::Pi();
+  cartMisAlig[0] = -TMath::Sign(1.0,transform.GetRotationMatrix()[0])*lMisAlignment[0];
+  cartMisAlig[1] = -TMath::Sign(1.0,transform.GetRotationMatrix()[4])*lMisAlignment[1];
+  cartMisAlig[2] = -TMath::Sign(1.0,transform.GetRotationMatrix()[8])*lMisAlignment[3];
+  angMisAlig[2] = -TMath::Sign(1.0,transform.GetRotationMatrix()[0]*transform.GetRotationMatrix()[4])*lMisAlignment[2]*180./TMath::Pi();
 
   TGeoTranslation deltaTrans(cartMisAlig[0], cartMisAlig[1], cartMisAlig[2]);
   TGeoRotation deltaRot;
@@ -947,8 +997,10 @@ AliMUONAlignment::ReAlign(const AliMUONGeometryTransformer * transformer,
                            double *misAlignments, Bool_t verbose)
                            
 {
-  /////////////////////////////////////////////////////////////////////
-  //   Takes the internal geometry module transformers, copies them
+  /// Returns a new AliMUONGeometryTransformer with the found misalignments
+  /// applied. 
+
+  // Takes the internal geometry module transformers, copies them
   // and gets the Detection Elements from them.
   // Takes misalignment parameters and applies these
   // to the local transform of the Detection Element
@@ -960,12 +1012,12 @@ AliMUONAlignment::ReAlign(const AliMUONGeometryTransformer * transformer,
   // Returns the new geometry transformer
 
   Double_t lModuleMisAlignment[3] = {0.,0.,0.};
-  Double_t lDetElemMisAlignment[3] = {0.,0.,0.};
+  Double_t lDetElemMisAlignment[4] = {0.,0.,0.,0.};
   Int_t iDetElemId = 0;
   Int_t iDetElemNumber = 0;
 
   AliMUONGeometryTransformer *newGeometryTransformer =
-    new AliMUONGeometryTransformer(kTRUE);
+    new AliMUONGeometryTransformer();
   for (Int_t iMt = 0; iMt < transformer->GetNofModuleTransformers(); iMt++) {
     // module transformers    
     const AliMUONGeometryModuleTransformer *kModuleTransformer =
@@ -995,14 +1047,13 @@ AliMUONAlignment::ReAlign(const AliMUONGeometryTransformer * transformer,
     if (verbose)
       AliInfo(Form("%i DEs in old GeometryStore  %i",detElements->GetSize(), iMt));
 
-    for (Int_t iDe = 0; iDe < detElements->GetSize(); iDe++) {
-      // detection elements.
-      AliMUONGeometryDetElement *detElement =
-       (AliMUONGeometryDetElement *) detElements->GetObject(iDe);
-      if (!detElement)
-       AliFatal("Detection element not found.");
-
-      /// make a new detection element
+    TIter next(detElements->CreateIterator());
+    AliMUONGeometryDetElement* detElement;
+    Int_t iDe(-1);
+    while ( ( detElement = static_cast<AliMUONGeometryDetElement*>(next()) ) )
+    {
+      ++iDe;
+      // make a new detection element
       AliMUONGeometryDetElement *newDetElement =
        new AliMUONGeometryDetElement(detElement->GetId(),
                                      detElement->GetVolumePath());
@@ -1058,3 +1109,57 @@ AliMUONAlignment::ReAlign(const AliMUONGeometryTransformer * transformer,
   return newGeometryTransformer;
 }
 
+//______________________________________________________________________
+void AliMUONAlignment::SetAlignmentResolution(const TClonesArray* misAlignArray, Int_t rChId, Double_t rChResX, Double_t rChResY, Double_t rDeResX, Double_t rDeResY){
+  /// Set alignment resolution to misalign objects to be stored in CDB
+  Int_t chIdMin = (rChId<0)? 0 : rChId;
+  Int_t chIdMax = (rChId<0)? 9 : rChId;
+  Double_t chResX = rChResX;
+  Double_t chResY = rChResY;
+  Double_t deResX = rDeResX;
+  Double_t deResY = rDeResY;
+
+  TMatrixDSym mChCorrMatrix(6);
+  mChCorrMatrix[0][0]=chResX*chResX;
+  mChCorrMatrix[1][1]=chResY*chResY;
+  //  mChCorrMatrix.Print();
+
+  TMatrixDSym mDECorrMatrix(6);
+  mDECorrMatrix[0][0]=deResX*deResX;
+  mDECorrMatrix[1][1]=deResY*deResY;
+  //  mDECorrMatrix.Print();
+
+  AliAlignObjMatrix *alignMat = 0x0;
+
+  for(Int_t chId=chIdMin; chId<=chIdMax; chId++) {
+    TString chName1;
+    TString chName2;
+    if (chId<4){
+      chName1 = Form("GM%d",chId);
+      chName2 = Form("GM%d",chId);
+    } else {
+      chName1 = Form("GM%d",4+(chId-4)*2);
+      chName2 = Form("GM%d",4+(chId-4)*2+1);
+    }
+    
+    for (int i=0; i<misAlignArray->GetEntries(); i++) {
+      alignMat = (AliAlignObjMatrix*)misAlignArray->At(i);
+      TString volName(alignMat->GetSymName());
+      if((volName.Contains(chName1)&&
+         ((volName.Last('/')==volName.Index(chName1)+chName1.Length())||
+          (volName.Length()==volName.Index(chName1)+chName1.Length())))||
+        (volName.Contains(chName2)&&
+         ((volName.Last('/')==volName.Index(chName2)+chName2.Length())||
+          (volName.Length()==volName.Index(chName2)+chName2.Length())))){
+       volName.Remove(0,volName.Last('/')+1);
+       if (volName.Contains("GM")) {
+         //    alignMat->Print("NULL");
+         alignMat->SetCorrMatrix(mChCorrMatrix);
+       } else if (volName.Contains("DE")) {
+         //    alignMat->Print("NULL");
+         alignMat->SetCorrMatrix(mDECorrMatrix);
+       }
+      }
+    }
+  }
+}