]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONSt1GeometryBuilderV2.cxx
Updated for changing mm->cm in mapping
[u/mrichter/AliRoot.git] / MUON / AliMUONSt1GeometryBuilderV2.cxx
index e3baf1c8f3c389a13db787bf6f38c07bec5d5ee6..12b89b9ef4f6857aa1740a289f470e62000b9f91 100644 (file)
 #include <TVirtualMC.h>
 
 #include "AliMpFiles.h"
-#include "AliMpReader.h"
+#include "AliMpSectorReader.h"
 #include "AliMpSector.h"
 #include "AliMpRow.h"
 #include "AliMpVRowSegment.h"
 #include "AliMpMotifMap.h"
 #include "AliMpMotifPosition.h"
 
+#include "AliRun.h"
+#include "AliMagF.h"
+#include "AliLog.h"
+
 #include "AliMUONSt1GeometryBuilderV2.h"
 #include "AliMUONSt1SpecialMotif.h"
 #include "AliMUON.h"
 #include "AliMUONChamber.h"
-#include "AliMUONChamberGeometry.h"
-#include "AliRun.h"
-#include "AliMagF.h"
+#include "AliMUONGeometryModule.h"
+#include "AliMUONGeometryEnvelopeStore.h"
 
 ClassImp(AliMUONSt1GeometryBuilderV2)
 
@@ -66,7 +69,7 @@ const GReal_t AliMUONSt1GeometryBuilderV2::fgkHzKapton = 0.0122/2.;     //Kapton
 const GReal_t AliMUONSt1GeometryBuilderV2::fgkHzBergPlastic = 0.3062/2.;//Berg connector
 const GReal_t AliMUONSt1GeometryBuilderV2::fgkHzBergCopper = 0.1882/2.; //Berg connector
 const GReal_t AliMUONSt1GeometryBuilderV2::fgkHzDaughter = 0.0156/2.;   //Daughter board
-const GReal_t AliMUONSt1GeometryBuilderV2::fgkHzGas = 0.2/2.;           //Gas thickness
+const GReal_t AliMUONSt1GeometryBuilderV2::fgkHzGas = 0.42/2.;          //Gas thickness
 
 // Quadrant Mother volume - TUBS1 - Middle layer of model
 const GReal_t AliMUONSt1GeometryBuilderV2::fgkMotherIR1 = 18.3;
@@ -99,25 +102,34 @@ const GReal_t AliMUONSt1GeometryBuilderV2::fgkDeltaFilleEtamX=1.46;
 const GReal_t AliMUONSt1GeometryBuilderV2::fgkDeltaFilleEtamY=0.051;
 
 const GReal_t AliMUONSt1GeometryBuilderV2::fgkDeltaQuadLHC=2.6;  // LHC Origin wrt Quadrant Origin
-const GReal_t AliMUONSt1GeometryBuilderV2::fgkFrameOffset=5.0;  
+const GReal_t AliMUONSt1GeometryBuilderV2::fgkFrameOffset=5.2;
+              // Fix (1) of overlap SQN* layers with SQM* ones (was 5.0)
+             
+// Pad planes offsets
+const GReal_t AliMUONSt1GeometryBuilderV2::fgkPadXOffsetBP =  0.50 - 0.63/2; // = 0.185
+const GReal_t AliMUONSt1GeometryBuilderV2::fgkPadYOffsetBP = -0.31 - 0.42/2; // =-0.52
 
 const char* AliMUONSt1GeometryBuilderV2::fgkHoleName="MCHL";      
 const char* AliMUONSt1GeometryBuilderV2::fgkDaughterName="MCDB";  
 const char  AliMUONSt1GeometryBuilderV2::fgkFoamLayerSuffix='F';  // prefix for automatic volume naming
+const char* AliMUONSt1GeometryBuilderV2::fgkQuadrantEnvelopeName="SE";
 const char* AliMUONSt1GeometryBuilderV2::fgkQuadrantMLayerName="SQM";
 const char* AliMUONSt1GeometryBuilderV2::fgkQuadrantNLayerName="SQN";
 const char* AliMUONSt1GeometryBuilderV2::fgkQuadrantFLayerName="SQF";
+const Int_t AliMUONSt1GeometryBuilderV2::fgkDaughterCopyNoOffset=1000;
 
 //______________________________________________________________________________
 AliMUONSt1GeometryBuilderV2::AliMUONSt1GeometryBuilderV2(AliMUON* muon)
-  : AliMUONVGeometryBuilder(&muon->Chamber(0), &muon->Chamber(1)),
+  : AliMUONVGeometryBuilder("st1V2.dat",
+                            muon->Chamber(0).GetGeometry(), 
+                           muon->Chamber(1).GetGeometry()),
     fMUON(muon)
 {
    // set path to mapping data files
    if (! gSystem->Getenv("MINSTALL")) {    
      TString dirPath = gSystem->Getenv("ALICE_ROOT");
      dirPath += "/MUON/mapping"; 
-     AliMpFiles::Instance()->SetTopPath(dirPath);
+     AliMpFiles::SetTopPath(dirPath);
      gSystem->Setenv("MINSTALL", dirPath.Data());
      //cout << "AliMpFiles top path set to " << dirPath << endl;         
    }
@@ -140,8 +152,7 @@ AliMUONSt1GeometryBuilderV2::AliMUONSt1GeometryBuilderV2(const AliMUONSt1Geometr
 {
 // Dummy copy constructor
 
- Fatal("Copy constructor", 
-        "Copy constructor is not implemented.");
+ AliFatal("Copy constructor is not implemented.");
 }
 
 //______________________________________________________________________________
@@ -158,8 +169,7 @@ AliMUONSt1GeometryBuilderV2::operator = (const AliMUONSt1GeometryBuilderV2& rhs)
   // check assignement to self
   if (this == &rhs) return *this;
 
-  Fatal("operator=", 
-        "Assignment operator is not implemented.");
+  AliFatal("Assignment operator is not implemented.");
     
   return *this;  
 }
@@ -168,6 +178,16 @@ AliMUONSt1GeometryBuilderV2::operator = (const AliMUONSt1GeometryBuilderV2& rhs)
 //  Private methods
 //
 
+//______________________________________________________________________________
+TString 
+AliMUONSt1GeometryBuilderV2::QuadrantEnvelopeName(Int_t chamber, Int_t quadrant) const
+{ 
+// Generate unique envelope name from chamber Id and quadrant number
+// ---
+
+  return Form("%s%d", Form("%s%d",fgkQuadrantEnvelopeName,chamber), quadrant); 
+}
+
 //______________________________________________________________________________
 void AliMUONSt1GeometryBuilderV2::CreateHole()
 {
@@ -482,50 +502,64 @@ void AliMUONSt1GeometryBuilderV2::CreateQuadrant(Int_t chamber)
 
 #ifdef ST1_WITH_STL
   SpecialMap specialMap;
-  specialMap[1001] = AliMUONSt1SpecialMotif(TVector2( 0.1, 0.84), 90.);
-  specialMap[1002] = AliMUONSt1SpecialMotif(TVector2( 0.5, 0.36));
-  specialMap[1003] = AliMUONSt1SpecialMotif(TVector2(1.01, 0.36));
+  specialMap[76] = AliMUONSt1SpecialMotif(TVector2( 0.1, 0.84), 90.);
+  specialMap[75] = AliMUONSt1SpecialMotif(TVector2( 0.5, 0.36));
+  specialMap[47] = AliMUONSt1SpecialMotif(TVector2(1.01, 0.36));
 #endif
   
 #ifdef ST1_WITH_ROOT
   SpecialMap specialMap;
-  specialMap.Add(1001, (Long_t) new AliMUONSt1SpecialMotif(TVector2( 0.1, 0.84), 90.));
-  specialMap.Add(1002, (Long_t) new AliMUONSt1SpecialMotif(TVector2( 0.5, 0.36)));
-  specialMap.Add(1003, (Long_t) new AliMUONSt1SpecialMotif(TVector2(1.01, 0.36)));
+  specialMap.Add(76, (Long_t) new AliMUONSt1SpecialMotif(TVector2( 0.1, 0.84), 90.));
+  specialMap.Add(75, (Long_t) new AliMUONSt1SpecialMotif(TVector2( 0.5, 0.36)));
+  specialMap.Add(47, (Long_t) new AliMUONSt1SpecialMotif(TVector2(1.01, 0.36)));
 #endif
 
-  AliMpReader reader1(kStation1, kBendingPlane);
+  AliMpSectorReader reader1(kStation1, kBendingPlane);
   AliMpSector* sector1 = reader1.BuildSector();
 
-  Bool_t reflectZ = true;
-  TVector3 where = TVector3(2.5+0.1+0.56+0.001, 2.5+0.1+0.001, 0.);
+  //Bool_t reflectZ = true;
+  Bool_t reflectZ = false;
+  //TVector3 where = TVector3(2.5+0.1+0.56+0.001, 2.5+0.1+0.001, 0.);
+  TVector3 where = TVector3(fgkDeltaQuadLHC + fgkPadXOffsetBP, 
+                            fgkDeltaQuadLHC + fgkPadYOffsetBP, 0.);
   PlaceSector(sector1, specialMap, where, reflectZ, chamber);
   
 #ifdef ST1_WITH_STL
   specialMap.clear();
-  specialMap[4001] = AliMUONSt1SpecialMotif(TVector2(1.01,0.59),90.);
-  specialMap[4002] = AliMUONSt1SpecialMotif(TVector2(1.96, 0.17));
-  specialMap[4003] = AliMUONSt1SpecialMotif(TVector2(1.61,-1.18));
-  specialMap[4004] = AliMUONSt1SpecialMotif(TVector2(0.2 ,-0.08));
-  specialMap[4005] = AliMUONSt1SpecialMotif(TVector2(0.2 , 0.25));
-  specialMap[4006] = AliMUONSt1SpecialMotif(TVector2(0.28, 0.21));
+  specialMap[76] = AliMUONSt1SpecialMotif(TVector2(1.01,0.59),90.);
+  specialMap[75] = AliMUONSt1SpecialMotif(TVector2(1.96, 0.17));
+  specialMap[47] = AliMUONSt1SpecialMotif(TVector2(2.18,-0.98));
+  specialMap[20] = AliMUONSt1SpecialMotif(TVector2(0.2 ,-0.08));
+  specialMap[46] = AliMUONSt1SpecialMotif(TVector2(0.2 , 0.25));
+  specialMap[74] = AliMUONSt1SpecialMotif(TVector2(0.28, 0.21));
+      // Fix (7) - overlap of SQ42 with MCHL (after moving the whole sector
+      // in the true position)   
+      // Was: specialMap[47] = AliMUONSt1SpecialMotif(TVector2(1.61,-1.18));
 #endif
 
 #ifdef ST1_WITH_ROOT
   specialMap.Delete();
-  specialMap.Add(4001,(Long_t) new AliMUONSt1SpecialMotif(TVector2(1.01,0.59),90.));
-  specialMap.Add(4002,(Long_t) new AliMUONSt1SpecialMotif(TVector2(1.96, 0.17)));
-  specialMap.Add(4003,(Long_t) new AliMUONSt1SpecialMotif(TVector2(1.61,-1.18)));
-  specialMap.Add(4004,(Long_t) new AliMUONSt1SpecialMotif(TVector2(0.2 ,-0.08)));
-  specialMap.Add(4005,(Long_t) new AliMUONSt1SpecialMotif(TVector2(0.2 , 0.25)));
-  specialMap.Add(4006,(Long_t) new AliMUONSt1SpecialMotif(TVector2(0.28, 0.21)));
+  specialMap.Add(76,(Long_t) new AliMUONSt1SpecialMotif(TVector2(1.01,0.59),90.));
+  specialMap.Add(75,(Long_t) new AliMUONSt1SpecialMotif(TVector2(1.96, 0.17)));
+  specialMap.Add(47,(Long_t) new AliMUONSt1SpecialMotif(TVector2(2.18,-0.98)));
+  specialMap.Add(20,(Long_t) new AliMUONSt1SpecialMotif(TVector2(0.2 ,-0.08)));
+  specialMap.Add(46,(Long_t) new AliMUONSt1SpecialMotif(TVector2(0.2 , 0.25)));
+  specialMap.Add(74,(Long_t) new AliMUONSt1SpecialMotif(TVector2(0.28, 0.21)));  
+      // Fix (7) - overlap of SQ42 with MCHL (after moving the whole sector
+      // in the true position)   
+      // Was: specialMap.Add(47,(Long_t) new AliMUONSt1SpecialMotif(TVector2(1.61,-1.18)));
 #endif
 
-  AliMpReader reader2(kStation1, kNonBendingPlane);
+  AliMpSectorReader reader2(kStation1, kNonBendingPlane);
   AliMpSector* sector2 = reader2.BuildSector();
-
-  reflectZ = false;
-  where = TVector3(where.X()+0.63/2.,where.Y()+0.42/2., 0.); //add a half pad shift
+  
+  //reflectZ = false;
+  reflectZ = true;
+  TVector2 offset = sector2->Position();
+  where = TVector3(where.X()+offset.X(), where.Y()+offset.Y(), 0.); 
+      // Add the half-pad shift of the non-bending plane wrt bending plane
+      // (The shift is defined in the mapping as sector offset)
+      // Fix (4) - was TVector3(where.X()+0.63/2, ... - now it is -0.63/2
   PlaceSector(sector2, specialMap, where, reflectZ, chamber);
 
 #ifdef ST1_WITH_ROOT
@@ -875,13 +909,19 @@ void AliMUONSt1GeometryBuilderV2::CreateFrame(Int_t chamber)
   const Float_t kAlp2OETF2 = 2.94; 
  
 // Trapezoid 3
-  const Float_t kBl1OETF3 = 1.767/2.;
-  const Float_t kTl1OETF3 = 3.01/2.;
+  //const Float_t kBl1OETF3 = 1.767/2.;
+  //const Float_t kTl1OETF3 = 3.01/2.;
+  const Float_t kBl1OETF3 = 1.117/2.;
+  const Float_t kTl1OETF3 = 2.36/2.;
   const Float_t kAlp1OETF3 = 4.94;
+        // Fix (5) - overlap of SQ21 with 041M and 125M
       
-  const Float_t kBl2OETF3 = 1.767/2.;
-  const Float_t kTl2OETF3 = 3.01/2.; 
+  //const Float_t kBl2OETF3 = 1.767/2.;
+  //const Float_t kTl2OETF3 = 3.01/2.; 
+  const Float_t kBl2OETF3 = 1.117/2.;
+  const Float_t kTl2OETF3 = 2.36/2.;
   const Float_t kAlp2OETF3 = 4.94; 
+        // Fix (5) - overlap of SQ21 with 041M and 125M
   
 // Trapezoid 4
   const Float_t kBl1OETF4 = 0.;
@@ -1633,13 +1673,17 @@ void AliMUONSt1GeometryBuilderV2::CreateFrame(Int_t chamber)
     
     xCenter[0] = 73.201 + fgkDeltaQuadLHC;
     xCenter[1] = 78.124 + fgkDeltaQuadLHC; 
-    xCenter[2] = 82.862 + fgkDeltaQuadLHC;
+    //xCenter[2] = 82.862 + fgkDeltaQuadLHC;
+    xCenter[2] = 83.102 + fgkDeltaQuadLHC;
     xCenter[3] = 87.418 + fgkDeltaQuadLHC; 
+        // Fix (5) - overlap of SQ21 with 041M and 125M
     
     yCenter[0] = 68.122 + fgkDeltaQuadLHC;
     yCenter[1] = 62.860 + fgkDeltaQuadLHC;   
-    yCenter[2] = 57.420 + fgkDeltaQuadLHC;
+    //yCenter[2] = 57.420 + fgkDeltaQuadLHC;
+    yCenter[2] = 57.660 + fgkDeltaQuadLHC;
     yCenter[3] = 51.800 + fgkDeltaQuadLHC; 
+        // Fix (5) - overlap of SQ21 with 041M and 125M
       
     xCenter[4] = 68.122 + fgkDeltaQuadLHC;
     xCenter[5] = 62.860 + fgkDeltaQuadLHC; 
@@ -1785,10 +1829,11 @@ void AliMUONSt1GeometryBuilderV2::CreateFrame(Int_t chamber)
     posZ = 0.;              
     gMC->Gspos("SQ36",2,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");
 
-    posX = 98.31-kNearFarLHC;
+    posX = 98.05-kNearFarLHC;
     posY = 12.77-kNearFarLHC;        
-
     posZ = 2.0*kHzLateralSightAl+kHzVerticalCradleAl-fgkMotherThick2;         
+           // Fix (2) of extrusion SQ36 from SQN1, SQN2, SQF1, SQF2 
+          // (was posX = 98.31 ...)
     gMC->Gspos("SQ36",1,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY");       
     posZ = -1.0*posZ;
     gMC->Gspos("SQ36",3,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY");  
@@ -1805,9 +1850,11 @@ void AliMUONSt1GeometryBuilderV2::CreateFrame(Int_t chamber)
     gMC->Gspos("SQ37",3,QuadrantMLayerName(chamber),posX, posY, posZ, 0, "ONLY");          
              
 // LateralSightSupport - 2 copies
-    posX = 98.53-kNearFarLHC;
+    posX = 98.33-kNearFarLHC;
     posY = 10.00-kNearFarLHC;    
     posZ = kHzLateralSightAl-fgkMotherThick2;
+           // Fix (3) of extrusion SQ38 from SQN1, SQN2, SQF1, SQF2 
+           // (was posX = 98.53 ...)
     gMC->Gspos("SQ38",1,QuadrantNLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
     posZ = -1.0*posZ;             
     gMC->Gspos("SQ38",2,QuadrantFLayerName(chamber),posX, posY, posZ, 0, "ONLY"); 
@@ -2124,23 +2171,29 @@ void AliMUONSt1GeometryBuilderV2::PlaceSector(AliMpSector* sector,SpecialMap spe
       
         // create the cathode part
         sprintf(segName,"%.3dM", segNum);
-        CreatePlaneSegment(segName, seg->Dimensions()/10., seg->GetNofMotifs());
+        CreatePlaneSegment(segName, seg->Dimensions(), seg->GetNofMotifs());
   
-        posX = where.X() + seg->Position().X()/10.;
-        posY = where.Y() + seg->Position().Y()/10.;
+        posX = where.X() + seg->Position().X();
+        posY = where.Y() + seg->Position().Y();
         posZ = where.Z() + sgn * (TotalHzPlane() + fgkHzGas + 2.*fgkHzPadPlane);
         gMC->Gspos(segName, 1, QuadrantMLayerName(chamber), posX, posY, posZ, reflZ, "ONLY");
 
         // and place all the daughter boards of this segment
         for (Int_t motifNum=0;motifNum<seg->GetNofMotifs();motifNum++) {
+
+         // Copy number
           Int_t motifPosId = seg->GetMotifPositionId(motifNum);
           AliMpMotifPosition* motifPos = 
             sector->GetMotifMap()->FindMotifPosition(motifPosId);
+         Int_t copyNo = motifPosId;
+         if ( sector->GetDirection() == kX) copyNo += fgkDaughterCopyNoOffset;
   
-          posX = where.X() + motifPos->Position().X()/10.+fgkOffsetX;
-          posY = where.Y() + motifPos->Position().Y()/10.+fgkOffsetY;
+          // Position
+          posX = where.X() + motifPos->Position().X() + fgkOffsetX;
+          posY = where.Y() + motifPos->Position().Y() + fgkOffsetY;
          posZ = where.Z() + sgn * (fgkMotherThick1 - TotalHzDaughter()); 
-          gMC->Gspos(fgkDaughterName, motifPosId, QuadrantMLayerName(chamber), posX, posY, posZ, reflZ, "ONLY");
+
+          gMC->Gspos(fgkDaughterName, copyNo, QuadrantMLayerName(chamber), posX, posY, posZ, reflZ, "ONLY");
         }  
         segNum++;
        
@@ -2173,19 +2226,23 @@ void AliMUONSt1GeometryBuilderV2::PlaceSector(AliMpSector* sector,SpecialMap spe
 
           AliMpMotifPosition* motifPos = sector->GetMotifMap()->FindMotifPosition(motifPosId);
 
+          // Copy number
+         Int_t copyNo = motifPosId;
+         if ( sector->GetDirection() == kX) copyNo += fgkDaughterCopyNoOffset;
+
           // place the hole for the motif, wrt the requested rotation angle
           Int_t rot = ( spMot.GetRotAngle()<0.1 ) ? reflZ:rotMat;
 
-          posX = where.X() + motifPos->Position().X()/10.+spMot.GetDelta().X();
-          posY = where.Y() + motifPos->Position().Y()/10.+spMot.GetDelta().Y();
+          posX = where.X() + motifPos->Position().X() + spMot.GetDelta().X();
+          posY = where.Y() + motifPos->Position().Y() + spMot.GetDelta().Y();
           posZ = where.Z() + sgn * (TotalHzPlane() + fgkHzGas + 2.*fgkHzPadPlane);
-          gMC->Gspos(fgkHoleName, motifPosId, QuadrantMLayerName(chamber), posX, posY, posZ, rot, "ONLY");
+          gMC->Gspos(fgkHoleName, copyNo, QuadrantMLayerName(chamber), posX, posY, posZ, rot, "ONLY");
 
           // then place the daughter board for the motif, wrt the requested rotation angle
           posX = posX+fgkDeltaFilleEtamX;
           posY = posY+fgkDeltaFilleEtamY;
          posZ = where.Z() + sgn * (fgkMotherThick1 - TotalHzDaughter()); 
-          gMC->Gspos(fgkDaughterName, motifPosId, QuadrantMLayerName(chamber), posX, posY, posZ, rot, "ONLY");
+          gMC->Gspos(fgkDaughterName, copyNo, QuadrantMLayerName(chamber), posX, posY, posZ, rot, "ONLY");
 
 #ifdef ST1_WITH_STL
           alreadyDone.push_back(motifPosId);// mark this motif as done
@@ -2299,18 +2356,6 @@ void AliMUONSt1GeometryBuilderV2::CreateMaterials()
        // was id: 9
        // from PDG and "The Particle Detector BriefBook", Bock and Vasilescu, P.18  
         // ??? same but the last but one argument < 0 
-  
-  fMUON->AliMaterial(42, "Copper$", 63.546,29.,8.96,-1.43,9.6);
-       // was id: 30
-
-  fMUON->AliMaterial(43, "FR4$", 17.749, 8.875, 1.7, -19.4, 999.);    // from DPG
-       // was id: 31
-
-  fMUON->AliMaterial(44, "FrameEpoxy",12.24,6.0,1.85,-19.14,999);// use 16.75cm
-        // was id: 36
-        // Density of FrameEpoxy only from manufacturer's specifications
-        // Frame composite epoxy , X0 in g/cm**2 (guestimation!)
-  
   //
   // --- Define mixtures for GEANT ---
   //
@@ -2352,7 +2397,6 @@ void AliMUONSt1GeometryBuilderV2::CreateMaterials()
  
   // Not used, to be removed
   //
-  fMUON->AliMaterial(49, "Kapton$", 12.01,6,1.42,-28.6,999);          // from DPG
        // was id: 34
 
   // Inox/Stainless Steel (18%Cr, 9%Ni)
@@ -2384,12 +2428,7 @@ void AliMUONSt1GeometryBuilderV2::CreateMaterials()
 
   fMUON->AliMedium(21, "ALU_II$",    41, 0, iSXFLD, sXMGMX, 
                    tmaxfd, maxStepAlu, maxDestepAlu, epsil, stmin);
-                  // was med: 4  mat: 9
-  fMUON->AliMedium(22, "COPPER_II$", 42, 0, iSXFLD, sXMGMX, 
-                   tmaxfd, maxStepAlu, maxDestepAlu, epsil, stmin);
-                  // was med: 10  mat: 30
-  fMUON->AliMedium(23, "FR4_CH$",    43, 0, iSXFLD, sXMGMX, 
-                   10.0, 0.01, 0.1, 0.003, 0.003);
+
                   // was med: 15  mat: 31 
   fMUON->AliMedium(24, "FrameCH$",   44, 1, iSXFLD, sXMGMX, 
                    10.0, 0.001, 0.001, 0.001, 0.001);
@@ -2409,9 +2448,7 @@ void AliMUONSt1GeometryBuilderV2::CreateMaterials()
 
   // Not used, to be romoved
   //
-  fMUON->AliMedium(29, "Kapton$",    49, 0, iSXFLD, sXMGMX,  
-                   10.0, 0.01, 1.0, 0.003, 0.003);
-                  // was med: 18  mat: 34 
+
   fMUON->AliMedium(30, "InoxBolts$", 50, 1, iSXFLD, sXMGMX, 
                    10.0, 0.01, 1.0, 0.003, 0.003);
                   // was med: 21  mat: 37
@@ -2424,8 +2461,7 @@ void AliMUONSt1GeometryBuilderV2::CreateGeometry()
 {
 // Create the detailed GEANT geometry for the dimuon arm station1
 // --
-  cout << "AliMUONSt1GeometryBuilderV2::CreateGeometry()" << endl;
-  cout << "_________________________________________" << endl;
+  AliDebug(1,"Called");
 
   // Create basic volumes
   // 
@@ -2442,11 +2478,15 @@ void AliMUONSt1GeometryBuilderV2::CreateGeometry()
   fMUON->AliMatrix(reflXY,  90., 180., 90., 270., 0., 0.);
 */
   // Define transformations for each quadrant
+  // In old coordinate system:        In new coordinate system:
   // 
-  //     II. |  I.
-  //   _____ | ____
-  //         |
-  //    III. |  IV.
+  // 
+  //     II. |  I.                   I. |  II. 
+  //         |                    (101) | (100)
+  //   _____ | ____               _____ | ____                         
+  //         |                          |
+  //    III. |  IV.                 IV. | III.
+  //                              (102) | (103) 
   // 
 /*
   Int_t rotm[4];
@@ -2467,11 +2507,17 @@ void AliMUONSt1GeometryBuilderV2::CreateGeometry()
   scale[2] = TVector3(-1, -1,  1);  // quadrant III
   scale[3] = TVector3( 1, -1, -1);  // quadrant IV
   
+  Int_t  detElemId[4];  
+  detElemId[0] =  1;  // quadrant I
+  detElemId[1] =  0;  // quadrant II
+  detElemId[2] =  3;  // quadrant III
+  detElemId[3] =  2;  // quadrant IV
+  
   // Shift in Z of the middle layer
-  Double_t deltaZ = 6.5/2.;         
+  Double_t deltaZ = 7.5/2.;         
 
   // Position of quadrant I wrt to the chamber position
-  TVector3 pos0(-fgkDeltaQuadLHC, -fgkDeltaQuadLHC, deltaZ);
+  // TVector3 pos0(-fgkDeltaQuadLHC, -fgkDeltaQuadLHC, deltaZ);
 
   // Shift for near/far layers
   GReal_t  shiftXY = fgkFrameOffset;
@@ -2490,27 +2536,38 @@ void AliMUONSt1GeometryBuilderV2::CreateGeometry()
     // Place the quadrant
     for (Int_t i=0; i<4; i++) {
 
+      // DE envelope
+      GReal_t posx0, posy0, posz0;
+      posx0 = fgkPadXOffsetBP * scale[i].X();
+      posy0 = fgkPadYOffsetBP * scale[i].Y();;
+      posz0 = deltaZ * scale[i].Z();
+      GetEnvelopes(ich-1)
+        ->AddEnvelope(QuadrantEnvelopeName(ich,i), detElemId[i] + ich*100, true,
+                     TGeoTranslation(posx0, posy0, posz0), rotm[i]);
+
       // Middle layer
-      GReal_t posx = pos0.X() * scale[i].X();
-      GReal_t posy = pos0.Y() * scale[i].Y();
-      //GReal_t posz = pos0.Z() * scale[i].Z() + AliMUONConstants::DefaultChamberZ(ich-1);
-      //gMC->Gspos(QuadrantMLayerName(ich), i+1, "ALIC", posx, posy, posz, rotm[i], "ONLY");
-      GReal_t posz = pos0.Z() * scale[i].Z();
-      GetChamber(ich-1)->GetGeometry()
-        ->AddEnvelope(QuadrantMLayerName(ich), i+1, TGeoTranslation(posx, posy, posz), rotm[i]); 
+      GReal_t posx, posy, posz;
+      posx = -fgkDeltaQuadLHC - fgkPadXOffsetBP;
+      posy = -fgkDeltaQuadLHC - fgkPadYOffsetBP;
+      posz = 0.;
+      GetEnvelopes(ich-1)
+        ->AddEnvelopeConstituent(QuadrantMLayerName(ich), QuadrantEnvelopeName(ich,i),
+                    i+1, TGeoTranslation(posx, posy, posz));
 
       // Near/far layers
-      Real_t  posx2 = posx + shiftXY * scale[i].X();
-      Real_t  posy2 = posy + shiftXY * scale[i].Y();
-      Real_t  posz2 = posz - scale[i].Z()*shiftZ;
+      GReal_t  posx2 = posx + shiftXY;;
+      GReal_t  posy2 = posy + shiftXY;;
+      GReal_t  posz2 = posz - shiftZ;;
       //gMC->Gspos(QuadrantNLayerName(ich), i+1, "ALIC", posx2, posy2, posz2, rotm[i],"ONLY");
-      GetChamber(ich-1)->GetGeometry()
-        ->AddEnvelope(QuadrantNLayerName(ich), i+1, TGeoTranslation(posx2, posy2, posz2), rotm[i]); 
+      GetEnvelopes(ich-1)
+        ->AddEnvelopeConstituent(QuadrantNLayerName(ich), QuadrantEnvelopeName(ich,i),
+                    i+1, TGeoTranslation(posx2, posy2, posz2)); 
     
-      posz2 = posz + scale[i].Z()*shiftZ;      
+      posz2 = posz + shiftZ;      
       //gMC->Gspos(QuadrantFLayerName(ich), i+1, "ALIC", posx2, posy2, posz2, rotm[i],"ONLY");
-      GetChamber(ich-1)->GetGeometry()
-        ->AddEnvelope(QuadrantFLayerName(ich), i+1, TGeoTranslation(posx2, posy2, posz2), rotm[i]); 
+      GetEnvelopes(ich-1)
+        ->AddEnvelopeConstituent(QuadrantFLayerName(ich), QuadrantEnvelopeName(ich,i), 
+                    i+1, TGeoTranslation(posx2, posy2, posz2)); 
    }
  }     
 }
@@ -2521,12 +2578,12 @@ void AliMUONSt1GeometryBuilderV2::SetTransformations()
 // Defines the transformations for the station2 chambers.
 // ---
 
-  AliMUONChamber* iChamber1 = GetChamber(0);
+  AliMUONChamber* iChamber1 = &fMUON->Chamber(0);
   Double_t zpos1 = - iChamber1->Z(); 
   iChamber1->GetGeometry()
     ->SetTranslation(TGeoTranslation(0., 0., zpos1));
 
-  AliMUONChamber* iChamber2 = GetChamber(1);
+  AliMUONChamber* iChamber2 = &fMUON->Chamber(1);
   Double_t zpos2 = - iChamber2->Z(); 
   iChamber2->GetGeometry()
     ->SetTranslation(TGeoTranslation(0., 0., zpos2));
@@ -2538,28 +2595,28 @@ void AliMUONSt1GeometryBuilderV2::SetSensitiveVolumes()
 // Defines the sensitive volumes for station2 chambers.
 // ---
 
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SA1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SB1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SC1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SD1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SE1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SF1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SG1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SH1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SI1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SJ1G");
-  GetChamber(0)->GetGeometry()->SetSensitiveVolume("SK1G");
+  GetGeometry(0)->SetSensitiveVolume("SA1G");
+  GetGeometry(0)->SetSensitiveVolume("SB1G");
+  GetGeometry(0)->SetSensitiveVolume("SC1G");
+  GetGeometry(0)->SetSensitiveVolume("SD1G");
+  GetGeometry(0)->SetSensitiveVolume("SE1G");
+  GetGeometry(0)->SetSensitiveVolume("SF1G");
+  GetGeometry(0)->SetSensitiveVolume("SG1G");
+  GetGeometry(0)->SetSensitiveVolume("SH1G");
+  GetGeometry(0)->SetSensitiveVolume("SI1G");
+  GetGeometry(0)->SetSensitiveVolume("SJ1G");
+  GetGeometry(0)->SetSensitiveVolume("SK1G");
     
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SA2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SB2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SC2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SD2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SE2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SF2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SG2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SH2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SI2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SJ2G");
-  GetChamber(1)->GetGeometry()->SetSensitiveVolume("SK2G");
+  GetGeometry(1)->SetSensitiveVolume("SA2G");
+  GetGeometry(1)->SetSensitiveVolume("SB2G");
+  GetGeometry(1)->SetSensitiveVolume("SC2G");
+  GetGeometry(1)->SetSensitiveVolume("SD2G");
+  GetGeometry(1)->SetSensitiveVolume("SE2G");
+  GetGeometry(1)->SetSensitiveVolume("SF2G");
+  GetGeometry(1)->SetSensitiveVolume("SG2G");
+  GetGeometry(1)->SetSensitiveVolume("SH2G");
+  GetGeometry(1)->SetSensitiveVolume("SI2G");
+  GetGeometry(1)->SetSensitiveVolume("SJ2G");
+  GetGeometry(1)->SetSensitiveVolume("SK2G");
 }