]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFv5T0.cxx
Changed AliRunLoader::GetRunLoader() into AliRunLoader::Instance()
[u/mrichter/AliRoot.git] / TOF / AliTOFv5T0.cxx
index 0a71de67dfcd64153b9f5de7456e78a37f613903..db6208e1de41147b47e877f54fe73e664229f04b 100644 (file)
 
 /*
 $Log$
+Revision 1.22  2007/10/07 19:40:46  decaro
+right handling of l2t matrices and alignable entries in case of TOF staging geometry
+
+Revision 1.21  2007/10/04 13:15:30  arcelli
+updates to comply with AliTOFGeometryV5 becoming AliTOFGeometry
+
+Revision 1.20  2007/10/03 18:07:22  arcelli
+right handling of l2t matrices and alignable entries in case of TOF holes (Annalisa)
+
+Revision 1.19  2007/10/03 10:41:12  arcelli
+adding tracking-to-local matrices for new AliTOFcluster
+
+Revision 1.18  2007/07/27 08:14:48  morsch
+Write all track references into the same branch.
+
+Revision 1.17  2007/05/14 14:41:13  decaro
+Fix a bug in FTOA volume positionig inside BTOF13,14,15,16,17 in case of holes in 11th and 12th sectors
+
+Revision 1.16  2007/05/04 12:59:26  arcelli
+Change the TOF SM paths for misalignment (one layer up)
+
+Revision 1.15  2007/02/19 15:41:55  decaro
+Coding convention: few corrections
+
+Revision 1.14  2006/10/17 15:33:14  arcelli
+Moving some printout from Info to Debug level
+
+Revision 1.13  2006/10/12 16:35:43  arcelli
+definition of the alignable volumes symbolic names added
+
+Revision 1.12  2006/08/22 13:34:46  arcelli
+removal of effective c++ warnings (C.Zampolli)
+
+Revision 1.11  2006/07/12 16:03:44  arcelli
+updates to match the new numbering of the TOF/TRD mother volumes in FRAME (ALICE convention)
+
+Revision 1.10  2006/05/10 18:40:17  hristov
+Larger strings for the names
+
+Revision 1.9  2006/05/04 19:41:42  hristov
+Possibility for partial TOF geometry (S.Arcelli)
+
+Revision 1.8  2006/04/20 22:30:50  hristov
+Coding conventions (Annalisa)
+
+Revision 1.7  2006/04/16 22:29:05  hristov
+Coding conventions (Annalisa)
+
+Revision 1.6  2006/03/20 08:20:35  decaro
+Al layer: positioning correction
+
+Revision 1.5  2006/03/20 07:54:20  decaro
+Correction of some layer thickness
+
+Revision 1.4  2006/03/13 12:35:44  decaro
+Suppression of fractional Z warning
+
+Revision 1.3  2006/02/28 10:38:00  decaro
+AliTOFGeometry::fAngles, AliTOFGeometry::fHeights,
+AliTOFGeometry::fDistances arrays: dimension definition in the right
+location
+
 Revision 1.2  2006/02/27 18:12:14  decaro
-Remove in StepManager the dependence of hit indexes from parametrized TOF position
+Remove in StepManager the dependence of hit indexes from parametrized
+TOF position
 
 Revision 1.1  2005/12/15 08:55:33  decaro
 New TOF geometry description (V5) -G. Cara Romeo and A. De Caro
@@ -49,31 +112,43 @@ Revision 0.1 2004 November G. Cara Romeo and A. De Caro
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include "Riostream.h"
-#include <stdlib.h>
-
-#include "TVirtualMC.h"
-#include <TBRIK.h>
-#include <TGeometry.h>
+#include <TDirectory.h>
+#include <TGeoGlobalMagField.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoPhysicalNode.h>
+#include <TGeoVolume.h>
 #include <TLorentzVector.h>
-#include <TNode.h>
-#include <TObject.h>
 #include <TVirtualMC.h>
 
-#include "AliLog.h"
 #include "AliConst.h"
-#include "AliRun.h"
-#include "AliMC.h"
+#include "AliGeomManager.h"
+#include "AliLog.h"
 #include "AliMagF.h"
+#include "AliMC.h"
+#include "AliRun.h"
+#include "AliTrackReference.h"
 
 #include "AliTOFGeometry.h"
-#include "AliTOFGeometryV5.h"
 #include "AliTOFv5T0.h"
 
+extern TDirectory *gDirectory;
+extern TVirtualMC *gMC;
+extern TGeoManager *gGeoManager;
+
+extern AliRun *gAlice;
+
 ClassImp(AliTOFv5T0)
 
 //_____________________________________________________________________________
-AliTOFv5T0::AliTOFv5T0()
+  AliTOFv5T0::AliTOFv5T0():
+  fIdFTOA(-1),
+  fIdFTOB(-1),
+  fIdFTOC(-1),
+  fIdFLTA(-1),
+  fIdFLTB(-1),
+  fIdFLTC(-1)//,
+  //fTOFHoles(kFALSE)
 {
   //
   // Default constructor
@@ -81,8 +156,15 @@ AliTOFv5T0::AliTOFv5T0()
 }
  
 //_____________________________________________________________________________
-AliTOFv5T0::AliTOFv5T0(const char *name, const char *title)
-        : AliTOF(name,title,"tzero")
+AliTOFv5T0::AliTOFv5T0(const char *name, const char *title):
+  AliTOF(name,title,"tzero"),
+  fIdFTOA(-1),
+  fIdFTOB(-1),
+  fIdFTOC(-1),
+  fIdFLTA(-1),
+  fIdFLTB(-1),
+  fIdFLTC(-1)//,
+  //fTOFHoles(kFALSE)
 {
   //
   // Standard constructor
@@ -91,116 +173,169 @@ AliTOFv5T0::AliTOFv5T0(const char *name, const char *title)
   // Check that FRAME is there otherwise we have no place where to
   // put TOF
 
-
-  AliModule* frame=gAlice->GetModule("FRAME");
+  /*
+  AliModule* frame = (AliModule*)gAlice->GetModule("FRAME");
   if(!frame) {
     AliFatal("TOF needs FRAME to be present");
   } else{
     
     if (fTOFGeometry) delete fTOFGeometry;
-    fTOFGeometry = new AliTOFGeometryV5();
+    fTOFGeometry = new AliTOFGeometry();
 
     if(frame->IsVersion()==1) {
-      AliInfo(Form("Frame version %d", frame->IsVersion())); 
-      AliInfo("Full Coverage for TOF");
+      AliDebug(1,Form("Frame version %d", frame->IsVersion())); 
+      AliDebug(1,"Full Coverage for TOF");
       fTOFHoles=false;}    
     else {
-      AliInfo(Form("Frame version %d", frame->IsVersion())); 
-      AliInfo("TOF with Holes for PHOS");
+      AliDebug(1,Form("Frame version %d", frame->IsVersion())); 
+      AliDebug(1,"TOF with Holes for PHOS");
       fTOFHoles=true;}      
   }
   fTOFGeometry->SetHoles(fTOFHoles);
+  */
+
+  if (fTOFGeometry) delete fTOFGeometry;
+  fTOFGeometry = new AliTOFGeometry();
+  fTOFGeometry->SetHoles(fTOFHoles);
 
   //AliTOF::fTOFGeometry = fTOFGeometry;
 
   // Save the geometry
   TDirectory* saveDir = gDirectory;
-  gAlice->GetRunLoader()->CdGAFile();
+  AliRunLoader::Instance()->CdGAFile();
   fTOFGeometry->Write("TOFgeometry");
   saveDir->cd();
 
 } 
 
-//____________________________________________________________________________
-void AliTOFv5T0::BuildGeometry()
+//_____________________________________________________________________________
+void AliTOFv5T0::AddAlignableVolumes() const
 {
   //
-  // Build TOF ROOT geometry for the ALICE event display
+  // Create entries for alignable volumes associating the symbolic volume
+  // name with the corresponding volume path. Needs to be syncronized with
+  // eventual changes in the geometry.
   //
-  TNode *node, *top;
-  const int kColorTOF  = 27;
-  
-  // Find top TNODE
-  top = gAlice->GetGeometry()->GetNode("alice");
-  
-  // Position the different copies
-  const Float_t krTof  =(fTOFGeometry->Rmax()+fTOFGeometry->Rmin())/2.;
-  const Float_t khTof  = fTOFGeometry->Rmax()-fTOFGeometry->Rmin();
-  const Int_t   kNTof  = fTOFGeometry->NSectors();
-  const Float_t kangle = k2PI/kNTof;
 
-  const Float_t kInterCentrModBorder1 = 49.5;
-  const Float_t kInterCentrModBorder2 = 57.5;
+  AliGeomManager::ELayerID idTOF = AliGeomManager::kTOF;
+  Int_t modUID, modnum=0;
 
-  Float_t ang;
-  
-  // define offset for nodes
-  Float_t zOffsetB = (fTOFGeometry->ZlenA()*0.5 + (kInterCentrModBorder1+kInterCentrModBorder2)*0.5)*0.5;
-  Float_t zOffsetA = 0.;
-  // Define TOF basic volume
-  
-  char nodeName0[7], nodeName1[7], nodeName2[7];
-  char nodeName3[7], nodeName4[7], rotMatNum[7];
+  TString volPath;
+  TString symName;
+
+  TString vpL0  = "ALIC_1/B077_1/BSEGMO";
+  TString vpL1 = "_1/BTOF";
+  TString vpL2 = "_1";
+  TString vpL3 = "/FTOA_0";
+  TString vpL4 = "/FLTA_0/FSTR_";
+
+  TString snSM  = "TOF/sm";
+  TString snSTRIP = "/strip";
+
+  Int_t nSectors=fTOFGeometry->NSectors();
+  Int_t nStrips =fTOFGeometry->NStripA()+
+                 2*fTOFGeometry->NStripB()+
+                 2*fTOFGeometry->NStripC();
+
+  //
+  // The TOF MRPC Strips
+  // The symbolic names are: TOF/sm00/strip01
+  //                           ...
+  //                         TOF/sm17/strip91
+  Int_t imod=0;
+
+  for (Int_t isect = 0; isect < nSectors; isect++) {
+    for (Int_t istr = 1; istr <= nStrips; istr++) {
+
+      modUID = AliGeomManager::LayerToVolUID(idTOF,modnum++);
+      if (fTOFSectors[isect]==-1) continue;
+
+      if (fTOFHoles && (isect==13 || isect==14 || isect==15)) {
+       if (istr<39) {
+         vpL3 = "/FTOB_0";
+         vpL4 = "/FLTB_0/FSTR_";
+       }
+       else if (istr>53) {
+         vpL3 = "/FTOC_0";
+         vpL4 = "/FLTC_0/FSTR_";
+       }
+       else continue;
+      }
+      else {
+       vpL3 = "/FTOA_0";
+       vpL4 = "/FLTA_0/FSTR_";
+      }
+
+      volPath  = vpL0;
+      volPath += isect;
+      volPath += vpL1;
+      volPath += isect;
+      volPath += vpL2;
+      volPath += vpL3;
+      volPath += vpL4;
+      volPath += istr;
 
-  if (fTOFHoles) {
-    new TBRIK("S_TOF_B","TOF box","void",
-             fTOFGeometry->StripLength()*0.5, khTof*0.5, fTOFGeometry->ZlenB()*0.5);
-    new TBRIK("S_TOF_C","TOF box","void",
-             fTOFGeometry->StripLength()*0.5, khTof*0.5, fTOFGeometry->ZlenB()*0.5);
-  }
-  new TBRIK("S_TOF_A","TOF box","void",
-            fTOFGeometry->StripLength()*0.5, khTof*0.5, fTOFGeometry->ZlenA()*0.5);
-  
-  for (Int_t nodeNum=1;nodeNum<19;nodeNum++){
-    
-    if (nodeNum<10) {
-      sprintf(rotMatNum,"rot50%i",nodeNum);
-      sprintf(nodeName0,"FTO00%i",nodeNum);
-      sprintf(nodeName1,"FTO10%i",nodeNum);
-      sprintf(nodeName2,"FTO20%i",nodeNum);
-      sprintf(nodeName3,"FTO30%i",nodeNum);
-      sprintf(nodeName4,"FTO40%i",nodeNum);
-    }
-    if (nodeNum>9) {
-      sprintf(rotMatNum,"rot5%i",nodeNum);
-      sprintf(nodeName0,"FTO0%i",nodeNum);
-      sprintf(nodeName1,"FTO1%i",nodeNum);
-      sprintf(nodeName2,"FTO2%i",nodeNum);
-      sprintf(nodeName3,"FTO3%i",nodeNum);
-      sprintf(nodeName4,"FTO4%i",nodeNum);
-    }
-    
-    new TRotMatrix(rotMatNum,rotMatNum,90,-20*nodeNum,90,90-20*nodeNum,0,0);
-    ang = (4.5-nodeNum) * kangle;
-
-    if (fTOFHoles) {   
-      top->cd();
-      node = new TNode(nodeName2,nodeName2,"S_TOF_B", krTof*TMath::Cos(ang), krTof*TMath::Sin(ang), zOffsetB,rotMatNum);
-      node->SetLineColor(kColorTOF);
-      fNodes->Add(node);
       
-      top->cd();
-      node = new TNode(nodeName3,nodeName3,"S_TOF_C", krTof*TMath::Cos(ang), krTof*TMath::Sin(ang),-zOffsetB,rotMatNum);
-      node->SetLineColor(kColorTOF);
-      fNodes->Add(node);
+      symName  = snSM;
+      symName += Form("%02d",isect);
+      symName += snSTRIP;
+      symName += Form("%02d",istr);
+            
+      AliDebug(2,"--------------------------------------------"); 
+      AliDebug(2,Form("Alignable object %d", imod)); 
+      AliDebug(2,Form("volPath=%s\n",volPath.Data()));
+      AliDebug(2,Form("symName=%s\n",symName.Data()));
+      AliDebug(2,"--------------------------------------------"); 
+             
+      if(!gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data(),modUID))
+       AliError(Form("Alignable entry %s not set",symName.Data()));
+
+      //T2L matrices for alignment
+      TGeoPNEntry *e = gGeoManager->GetAlignableEntryByUID(modUID);
+      if (e) {
+       TGeoHMatrix *globMatrix = e->GetGlobalOrig();
+       Double_t phi = 20.0 * (isect % 18) + 10.0;
+       TGeoHMatrix *t2l  = new TGeoHMatrix();
+       t2l->RotateZ(phi);
+       t2l->MultiplyLeft(&(globMatrix->Inverse()));
+       e->SetMatrix(t2l);
+      }
+      else {
+       AliError(Form("Alignable entry %s is not valid!",symName.Data()));
+      }
+      imod++;
     }
+  }
+
+
+  //
+  // The TOF supermodules
+  // The symbolic names are: TOF/sm00
+  //                           ...
+  //                         TOF/sm17
+  //
+  for (Int_t isect = 0; isect < nSectors; isect++) {
 
-    top->cd();
-    node = new TNode(nodeName4,nodeName4,"S_TOF_A", krTof*TMath::Cos(ang), krTof*TMath::Sin(ang), zOffsetA,rotMatNum);
-    node->SetLineColor(kColorTOF);
-    fNodes->Add(node);
-  } // end loop on nodeNum
+    volPath  = vpL0;
+    volPath += isect;
+    volPath += vpL1;
+    volPath += isect;
+    volPath += vpL2;
 
+    symName  = snSM;
+    symName += Form("%02d",isect);
+
+    AliDebug(2,"--------------------------------------------"); 
+    AliDebug(2,Form("Alignable object %d", isect+imod)); 
+    AliDebug(2,Form("volPath=%s\n",volPath.Data()));
+    AliDebug(2,Form("symName=%s\n",symName.Data()));
+    AliDebug(2,"--------------------------------------------"); 
+
+    gGeoManager->SetAlignableEntry(symName.Data(),volPath.Data());
+
+  }
+  
 }
 
 //_____________________________________________________________________________
@@ -225,6 +360,9 @@ void AliTOFv5T0::CreateGeometry()
 void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
                       Float_t zlenB)
 {
+  //
+  // Definition of the Time Of Fligh Resistive Plate Chambers
+  //
 
   const Float_t kPi = TMath::Pi();
 
@@ -236,12 +374,13 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   const Float_t kLengthExInModBorder  = 4.7;
   const Float_t kLengthInCeModBorder  = 7.0;
 
-  const Float_t khAlWall = 0.1;
+  // Al layers over all internal module walls (cm)
+  const Float_t khAlWall = 0.03;
 
-  // module wall thickness
+  // module wall thickness (cm)
   const Float_t kModuleWallThickness = 0.3;
 
-  //  1.5 cm Al honeycomb layer between strips and cards
+  // Al honeycomb layer between strips and cards (cm)
   const Float_t kHoneycombLayerThickness = 1.5;
 
   AliDebug(2,Form("zlenA*0.5 = %d", zlenA*0.5));
@@ -250,7 +389,7 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   // Definition of the Time Of Fligh Resistive Plate Chambers
   // xFLT, yFLT, zFLT - sizes of TOF modules (large)
   
-  Float_t  ycoor, zcoor;
+  Float_t  xcoor, ycoor, zcoor;
   Float_t  par[3];
   Int_t    *idtmed = fIdtmed->GetArray()-499;
   Int_t    idrotm[100];
@@ -261,30 +400,43 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   gMC->Gsvolu("FTOA", "BOX ", idtmed[503], par, 3);  // fibre glass
   
   if (fTOFHoles) {
+    par[0] =  xtof * 0.5;
+    par[1] =  ytof * 0.5;
     par[2] = (zlenA*0.5 - kInterCentrModBorder1)*0.5;
-    gMC->Gsvolu("FTOB", "BOX ", idtmed[503], par, 3);
-    gMC->Gsvolu("FTOC", "BOX ", idtmed[503], par, 3);
+    gMC->Gsvolu("FTOB", "BOX ", idtmed[503], par, 3);  // fibre glass
+    gMC->Gsvolu("FTOC", "BOX ", idtmed[503], par, 3);  // fibre glass
   }
 
-  // Positioning of modules
+  // Positioning of fibre glass modules (FTOA, FTOB and FTOC)
   
   //AliMatrix(idrotm[0], 90.,  0., 0., 0., 90.,-90.);
-  AliMatrix(idrotm[0], 90.,  0., 0., 0., 90.,270.); // adc
-
-  Float_t zcor3 = 0.;
+  AliMatrix(idrotm[0], 90.,  0., 0., 0., 90.,270.);
+
+  xcoor = 0.;
+  ycoor = 0.;
+  zcoor = 0.;
+  for(Int_t isec=0;isec<18;isec++){
+    if(fTOFSectors[isec]==-1)continue;
+    char name[16];
+    sprintf(name, "BTOF%d",isec);
+    if (fTOFHoles && (isec==13 || isec==14 || isec==15)) {
+    //    if (fTOFHoles && (isec==16||isec==17)) { \\Old 6h convention
+      xcoor = 0.;
+      ycoor = (zlenA*0.5 + kInterCentrModBorder1)*0.5;
+      zcoor = 0.;
+      gMC->Gspos("FTOB", 0, name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
+      gMC->Gspos("FTOC", 0, name, xcoor,-ycoor, zcoor, idrotm[0], "ONLY");
+    }
+    else {
+      xcoor = 0.;
+      ycoor = 0.;
+      zcoor = 0.;
+      gMC->Gspos("FTOA", 0,name, xcoor, ycoor, zcoor, idrotm[0], "ONLY");
+    }
 
-  gMC->Gspos("FTOA", 0, "BTO1", 0, zcor3,  0, idrotm[0], "ONLY");
-  gMC->Gspos("FTOA", 0, "BTO3", 0, zcor3,  0, idrotm[0], "ONLY");
-  
-  if (fTOFHoles) {
-    zcor3 = (zlenA*0.5 + kInterCentrModBorder1)*0.5;
-    gMC->Gspos("FTOB", 0, "BTO2", 0, zcor3,  0, idrotm[0], "ONLY");
-    gMC->Gspos("FTOC", 0, "BTO2", 0,-zcor3,  0, idrotm[0], "ONLY");
   }
-  else gMC->Gspos("FTOA", 0, "BTO2", 0, zcor3,  0, idrotm[0], "ONLY");
-
-  // Large not sensitive volumes with Insensitive Freon  (FLTA, FLTB and FLTC)
-
+  // Large not sensitive volumes with Insensitive Freon (FLTA, FLTB and FLTC)
+  
   Float_t xFLT, yFLT, zFLTA;
   
   xFLT  = xtof  - kModuleWallThickness*2.;
@@ -293,187 +445,265 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   
   par[0] = xFLT*0.5;
   par[1] = yFLT*0.5;
-
   par[2] = zFLTA*0.5;
-  gMC->Gsvolu("FLTA", "BOX ", idtmed[507], par, 3); //  Freon mix     ok
-  gMC->Gspos ("FLTA", 0, "FTOA", 0., 0., 0., 0, "ONLY");
+  gMC->Gsvolu("FLTA", "BOX ", idtmed[507], par, 3); //  Freon mix
+
+  xcoor = 0.;
+  ycoor = 0.;
+  zcoor = 0.;
+  gMC->Gspos ("FLTA", 0, "FTOA", xcoor, ycoor, zcoor, 0, "ONLY");
 
   if (fTOFHoles) {
+    par[0] = xFLT*0.5;
+    par[1] = yFLT*0.5;
     par[2] = (zlenA*0.5 - kInterCentrModBorder1-kModuleWallThickness)*0.5;
     gMC->Gsvolu("FLTB", "BOX ", idtmed[507], par, 3); // Freon mix
-    gMC->Gspos ("FLTB", 0, "FTOB", 0., 0.,  kModuleWallThickness*0.5, 0, "ONLY");
     gMC->Gsvolu("FLTC", "BOX ", idtmed[507], par, 3); // Freon mix
-    gMC->Gspos ("FLTC", 0, "FTOC", 0., 0., -kModuleWallThickness*0.5, 0, "ONLY");
+
+    xcoor = 0.;
+    ycoor = 0.;
+    zcoor = kModuleWallThickness*0.5;
+    gMC->Gspos ("FLTB", 0, "FTOB", xcoor, ycoor, zcoor, 0, "ONLY");
+    gMC->Gspos ("FLTC", 0, "FTOC", xcoor, ycoor,-zcoor, 0, "ONLY");
   }
 
-  // Layer of Aluminum after detector
-  //par[0] = xFLT*0.5;
+  // Layer of Aluminum before detector (FALA, FALB and FALC)
+
+  par[0] = xFLT*0.5;
   par[1] = khAlWall*0.5;
+  par[2] = kInterCentrModBorder1 - (kModuleWallThickness + khAlWall);
+  gMC->Gsvolu("FALA", "BOX ", idtmed[505], par, 3); // Alluminium
 
-  par[2] = zFLTA *0.5;
+  xcoor = 0.;
+  ycoor = (-yFLT + khAlWall)*0.5;
+  zcoor = 0.;
+  gMC->Gspos ("FALA", 0, "FLTA", xcoor, ycoor, zcoor, 0, "ONLY");
+
+  par[0] = xFLT*0.5;
+  par[1] = khAlWall*0.5;
+  par[2] = (kExterInterModBorder2 - kInterCentrModBorder1 - 2.*(kModuleWallThickness + khAlWall))*0.5;
+  gMC->Gsvolu("FALB", "BOX ", idtmed[505], par, 3); // Alluminium
+
+  xcoor = 0.;
   ycoor = (-yFLT + khAlWall)*0.5;
-  gMC->Gsvolu("FALA", "BOX ", idtmed[505], par, 3); // Alluminium     ok
-  gMC->Gspos ("FALA", 0, "FLTA", 0., -ycoor, 0., 0, "ONLY");
+  zcoor = (kExterInterModBorder2 + kInterCentrModBorder1)*0.5;
+  gMC->Gspos ("FALB", 1, "FLTA", xcoor, ycoor, zcoor, 0, "ONLY");
+  gMC->Gspos ("FALB", 2, "FLTA", xcoor, ycoor,-zcoor, 0, "ONLY");
+
+  par[0] = xFLT*0.5;
+  par[1] = khAlWall*0.5;
+  par[2] = (zlenA*0.5 - kExterInterModBorder2 - 2.*(kModuleWallThickness + khAlWall))*0.5;
+  gMC->Gsvolu("FALC", "BOX ", idtmed[505], par, 3); // Alluminium
+
+  xcoor = 0.;
+  ycoor = (-yFLT + khAlWall)*0.5;
+  zcoor = (kExterInterModBorder2+zlenA*0.5)*0.5;
+  gMC->Gspos ("FALC", 1, "FLTA", xcoor, ycoor, zcoor, 0, "ONLY");
+  gMC->Gspos ("FALC", 2, "FLTA", xcoor, ycoor,-zcoor, 0, "ONLY");
 
   if (fTOFHoles) {
-    par[2] = (zlenA*0.5 - kInterCentrModBorder2-kModuleWallThickness)*0.5;
-    gMC->Gsvolu("FALB", "BOX ", idtmed[505], par, 3); // Alluminium
-    gMC->Gspos ("FALB", 1, "FLTB", 0.,-ycoor, -(kInterCentrModBorder2-kInterCentrModBorder1)*0.5, 0, "ONLY");
-    gMC->Gspos ("FALB", 2, "FLTC", 0.,-ycoor,  (kInterCentrModBorder2-kInterCentrModBorder1)*0.5, 0, "ONLY");
+    xcoor = 0.;
+    ycoor = (-yFLT + khAlWall)*0.5;
+    zcoor = (zlenA*0.5 - kExterInterModBorder2)*0.5 - kModuleWallThickness*0.5;
+    gMC->Gspos ("FALB", 1, "FLTB", xcoor, ycoor, zcoor, 0, "ONLY");
+    gMC->Gspos ("FALB", 2, "FLTC", xcoor, ycoor,-zcoor, 0, "ONLY");
+
+    xcoor = 0.;
+    ycoor = (-yFLT + khAlWall)*0.5;
+    zcoor = (kExterInterModBorder2 - kInterCentrModBorder1)*0.5 + kModuleWallThickness*0.5;
+    gMC->Gspos ("FALC", 1, "FLTB", xcoor, ycoor,-zcoor, 0, "ONLY");
+    gMC->Gspos ("FALC", 2, "FLTC", xcoor, ycoor, zcoor, 0, "ONLY");
   }
 
-  Float_t y0, alpha, beta, tgbe, trpa[11], dy, zcoo;
-  dy  = yFLT*0.5;
+  Float_t y0, alpha, tgal, beta, tgbe, trpa[11];
 
-  // wall between central and intermediate modules
-  y0    = kLengthInCeModBorder;
-  zcoor = kInterCentrModBorder1;
-  zcoo  = kInterCentrModBorder2;
-  alpha = TMath::ATan((dy-2.*y0)/(zcoo-zcoor));
-  beta = (kPi*0.5-alpha)*0.5;
+  // Fibre glass walls between central and intermediate modules (FWZ1 and FWZ2; holes -> FZ1B, FZ1C, FZ2B)
+
+  tgal = (yFLT*0.5 - 2.*kLengthInCeModBorder)/(kInterCentrModBorder2 - kInterCentrModBorder1);
+  alpha = TMath::ATan(tgal);
+  beta = (kPi*0.5 - alpha)*0.5;
   tgbe = TMath::Tan(beta);
-  trpa[0]  = xFLT*0.5;//par[0];
+  trpa[0]  = xFLT*0.5;
   trpa[1]  = 0.;
   trpa[2]  = 0.;
   trpa[3]  = kModuleWallThickness;
-  trpa[4]  = (y0-kModuleWallThickness*tgbe)*0.5;
-  trpa[5]  = (y0+kModuleWallThickness*tgbe)*0.5;
-  trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg;
+  trpa[4]  = (kLengthInCeModBorder - kModuleWallThickness*tgbe)*0.5;
+  trpa[5]  = (kLengthInCeModBorder + kModuleWallThickness*tgbe)*0.5;
+  trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
   trpa[7]  = kModuleWallThickness;
-  trpa[8]  = (y0-kModuleWallThickness*tgbe)*0.5;
-  trpa[9]  = (y0+kModuleWallThickness*tgbe)*0.5;
-  trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg;
-
+  trpa[8]  = (kLengthInCeModBorder - kModuleWallThickness*tgbe)*0.5;
+  trpa[9]  = (kLengthInCeModBorder + kModuleWallThickness*tgbe)*0.5;
+  trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
   gMC->Gsvolu("FWZ1","TRAP", idtmed[503], trpa, 11);   // fibre glass
 
   AliMatrix (idrotm[1],90., 90.,180.,0.,90.,180.);
-  ycoor = -dy + y0*0.5;
-  gMC->Gspos("FWZ1", 1,"FLTA",0.,ycoor, zcoor,idrotm[1],"ONLY");
-
   AliMatrix (idrotm[4],90., 90.,  0.,0.,90.,  0.);
-  gMC->Gspos("FWZ1", 2,"FLTA",0.,ycoor,-zcoor,idrotm[4],"ONLY");
+
+  xcoor = 0.;
+  ycoor = -yFLT*0.5 + kLengthInCeModBorder*0.5;
+  zcoor = kInterCentrModBorder1;
+  gMC->Gspos("FWZ1", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[1],"ONLY");
+  gMC->Gspos("FWZ1", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[4],"ONLY");
 
   if (fTOFHoles) {
-    Float_t y0B = y0 - kModuleWallThickness*0.5*tgbe;
-    Float_t ycoorB = ycoor - kModuleWallThickness*0.25/tgbe;
-    trpa[0]  = xFLT*0.5;//par[0];
+    y0 = kLengthInCeModBorder - kModuleWallThickness*0.5*tgbe;
+    trpa[0]  = xFLT*0.5;
     trpa[1]  = 0.;
     trpa[2]  = 0.;
     trpa[3]  = kModuleWallThickness*0.5;
-    trpa[4]  = (y0B-kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[5]  = (y0B+kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg;
+    trpa[4]  = (y0 - kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[5]  = (y0 + kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
     trpa[7]  = kModuleWallThickness*0.5;
-    trpa[8]  = (y0B-kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[9]  = (y0B+kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg;
+    trpa[8]  = (y0 - kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[9]  = (y0 + kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
     gMC->Gsvolu("FZ1B","TRAP", idtmed[503], trpa, 11);   // fibre glass
-    gMC->Gspos("FZ1B", 5,"FLTB",0.,ycoorB,-zcoor+(zlenA*0.5+kInterCentrModBorder1)*0.5-kModuleWallThickness,idrotm[4],"ONLY");
-    gMC->Gspos("FZ1B", 6,"FLTC",0.,ycoorB,+zcoor-(zlenA*0.5+kInterCentrModBorder1)*0.5+kModuleWallThickness,idrotm[1],"ONLY");
+
+    xcoor = 0.;
+    ycoor = -yFLT*0.5 + kLengthInCeModBorder*0.5 - kModuleWallThickness*0.25*tgbe;
+    zcoor = -kInterCentrModBorder1 + (zlenA*0.5 + kInterCentrModBorder1)*0.5 - kModuleWallThickness;
+    gMC->Gspos("FZ1B", 1,"FLTB", xcoor, ycoor, zcoor,idrotm[4],"ONLY");
+    gMC->Gspos("FZ1B", 2,"FLTC", xcoor, ycoor,-zcoor,idrotm[1],"ONLY");
   }
 
   AliMatrix (idrotm[2],90.,270.,  0.,0.,90.,180.);
-  ycoor = -y0*0.5;
-  gMC->Gspos("FWZ1", 3,"FLTA",0.,ycoor, zcoo,idrotm[2],"ONLY");
   AliMatrix (idrotm[5],90.,270.,180.,0.,90.,  0.);
-  gMC->Gspos("FWZ1", 4,"FLTA",0.,ycoor,-zcoo,idrotm[5],"ONLY");
+
+  xcoor = 0.;
+  ycoor = -kLengthInCeModBorder*0.5;
+  zcoor = kInterCentrModBorder2;
+  gMC->Gspos("FWZ1", 3,"FLTA", xcoor, ycoor, zcoor,idrotm[2],"ONLY");
+  gMC->Gspos("FWZ1", 4,"FLTA", xcoor, ycoor,-zcoor,idrotm[5],"ONLY");
 
   if (fTOFHoles) {
-    Float_t y0B = y0 + kModuleWallThickness*0.5*tgbe;
-    Float_t ycoorB = ycoor - kModuleWallThickness*0.25/tgbe;
-    trpa[0]  = xFLT*0.5;//par[0];
+    y0 = kLengthInCeModBorder + kModuleWallThickness*0.5*tgbe;
+    trpa[0]  = xFLT*0.5;
     trpa[1]  = 0.;
     trpa[2]  = 0.;
     trpa[3]  = kModuleWallThickness*0.5;
-    trpa[4]  = (y0B-kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[5]  = (y0B+kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg;
+    trpa[4]  = (y0 - kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[5]  = (y0 + kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
     trpa[7]  = kModuleWallThickness*0.5;
-    trpa[8]  = (y0B-kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[9]  = (y0B+kModuleWallThickness*0.5*tgbe)*0.5;
-    trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg;
+    trpa[8]  = (y0 - kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[9]  = (y0 + kModuleWallThickness*0.5*tgbe)*0.5;
+    trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
     gMC->Gsvolu("FZ1C","TRAP", idtmed[503], trpa, 11);   // fibre glass
-    gMC->Gspos("FZ1C", 7,"FLTB",0.,ycoorB,-zcoo+(zlenA*0.5+kInterCentrModBorder1)*0.5-kModuleWallThickness,idrotm[5],"ONLY");
-    gMC->Gspos("FZ1C", 8,"FLTC",0.,ycoorB, zcoo-(zlenA*0.5+kInterCentrModBorder1)*0.5+kModuleWallThickness,idrotm[2],"ONLY");
+
+    xcoor = 0.;
+    ycoor = -kLengthInCeModBorder*0.5 - kModuleWallThickness*0.25*tgbe;
+    zcoor = -kInterCentrModBorder2 + (zlenA*0.5 + kInterCentrModBorder1)*0.5 - kModuleWallThickness;
+    gMC->Gspos("FZ1C", 1,"FLTB", xcoor, ycoor, zcoor,idrotm[5],"ONLY");
+    gMC->Gspos("FZ1C", 2,"FLTC", xcoor, ycoor,-zcoor,idrotm[2],"ONLY");
   }
 
-  trpa[0] = 0.5*(zcoo-zcoor)/TMath::Cos(alpha);
+  trpa[0] = 0.5*(kInterCentrModBorder2 - kInterCentrModBorder1)/TMath::Cos(alpha);
   trpa[1] = kModuleWallThickness;
-  trpa[2] = xFLT*0.5;//par[0];
+  trpa[2] = xFLT*0.5;
   trpa[3] = -beta*kRaddeg;
   trpa[4] = 0.;
   trpa[5] = 0.;
   gMC->Gsvolu("FWZ2","PARA", idtmed[503], trpa, 6);    // fibre glass
+
   AliMatrix (idrotm[3],     alpha*kRaddeg,90.,90.+alpha*kRaddeg,90.,90.,180.);
-  gMC->Gspos("FWZ2", 1,"FLTA",0.,-dy*0.5, (zcoo+zcoor)*0.5,idrotm[3],"ONLY");
   AliMatrix (idrotm[6],180.-alpha*kRaddeg,90.,90.-alpha*kRaddeg,90.,90.,  0.);
-  gMC->Gspos("FWZ2", 2,"FLTA",0.,-dy*0.5,-(zcoo+zcoor)*0.5,idrotm[6],"ONLY");
+
+  xcoor = 0.;
+  ycoor = -yFLT*0.25;
+  zcoor = (kInterCentrModBorder2 + kInterCentrModBorder1)*0.5;
+  gMC->Gspos("FWZ2", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[3],"ONLY");
+  gMC->Gspos("FWZ2", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[6],"ONLY");
 
   if (fTOFHoles) {
-    trpa[0] = 0.5*(zcoo-zcoor)/TMath::Cos(alpha);
+    trpa[0] = 0.5*(kInterCentrModBorder2 - kInterCentrModBorder1)/TMath::Cos(alpha);
     trpa[1] = kModuleWallThickness*0.5;
-    trpa[2] = xFLT*0.5;//par[0];
+    trpa[2] = xFLT*0.5;
     trpa[3] = -beta*kRaddeg;
     trpa[4] = 0.;
     trpa[5] = 0.;
     gMC->Gsvolu("FZ2B","PARA", idtmed[503], trpa, 6);    // fibre glass
-    gMC->Gspos("FZ2B", 3,"FLTB",0.,-dy*0.5-kModuleWallThickness*0.5/tgbe,-(zcoo+zcoor)*0.5+(zlenA*0.5+kInterCentrModBorder1)*0.5-kModuleWallThickness,idrotm[6],"ONLY");
-    gMC->Gspos("FZ2B", 4,"FLTC",0.,-dy*0.5-kModuleWallThickness*0.5/tgbe,+(zcoo+zcoor)*0.5-(zlenA*0.5+kInterCentrModBorder1)*0.5+kModuleWallThickness,idrotm[3],"ONLY");
+
+    xcoor = 0.;
+    ycoor = -yFLT*0.25 - kModuleWallThickness*0.5*tgbe;
+    zcoor = -(kInterCentrModBorder2 + kInterCentrModBorder1)*0.5 + (zlenA*0.5 + kInterCentrModBorder1)*0.5 - kModuleWallThickness;
+    gMC->Gspos("FZ2B", 1,"FLTB", xcoor, ycoor, zcoor,idrotm[6],"ONLY");
+    gMC->Gspos("FZ2B", 2,"FLTC", xcoor, ycoor,-zcoor,idrotm[3],"ONLY");
   }
 
-  // wall between intermediate and lateral modules
-  y0    = kLengthExInModBorder;//4.7;
-  zcoor = kExterInterModBorder1;//196.;
-  zcoo  = kExterInterModBorder2;//203.5;
-  alpha = TMath::ATan((dy-2.*y0)/(zcoo-zcoor));
-  beta = (kPi*0.5-alpha)*0.5;
+  // Fibre glass walls between intermediate and lateral modules (FWZ3 and FWZ4)
+
+  tgal = (yFLT*0.5 - 2.*kLengthExInModBorder)/(kExterInterModBorder2 - kExterInterModBorder1);
+  alpha = TMath::ATan(tgal);
+  beta = (kPi*0.5 - alpha)*0.5;
   tgbe = TMath::Tan(beta);
-  trpa[0]  = xFLT*0.5;//par[0];
+  trpa[0]  = xFLT*0.5;
   trpa[1]  = 0.;
   trpa[2]  = 0.;
   trpa[3]  = kModuleWallThickness;
-  trpa[4]  = (y0-kModuleWallThickness*tgbe)*0.5;
-  trpa[5]  = (y0+kModuleWallThickness*tgbe)*0.5;
-  trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg;
+  trpa[4]  = (kLengthExInModBorder - kModuleWallThickness*tgbe)*0.5;
+  trpa[5]  = (kLengthExInModBorder + kModuleWallThickness*tgbe)*0.5;
+  trpa[6]  = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
   trpa[7]  = kModuleWallThickness;
-  trpa[8]  = (y0-kModuleWallThickness*tgbe)*0.5;
-  trpa[9]  = (y0+kModuleWallThickness*tgbe)*0.5;
-  trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg;
+  trpa[8]  = (kLengthExInModBorder - kModuleWallThickness*tgbe)*0.5;
+  trpa[9]  = (kLengthExInModBorder + kModuleWallThickness*tgbe)*0.5;
+  trpa[10] = TMath::ATan(tgbe*0.5)*kRaddeg; //TMath::ATan((trpa[5] - trpa[4])/(2.*trpa[3]))*kRaddeg;
   gMC->Gsvolu("FWZ3","TRAP", idtmed[503], trpa, 11);    // fibre glass
-  ycoor = -y0*0.5;
-  gMC->Gspos("FWZ3", 1,"FLTA",0.,ycoor, zcoor,idrotm[5],"ONLY");
-  gMC->Gspos("FWZ3", 2,"FLTA",0.,ycoor,-zcoor,idrotm[2],"ONLY");
+
+  xcoor = 0.;
+  ycoor = -kLengthExInModBorder*0.5;
+  zcoor = kExterInterModBorder1;
+  gMC->Gspos("FWZ3", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[5],"ONLY");
+  gMC->Gspos("FWZ3", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[2],"ONLY");
 
   if (fTOFHoles) {
-    gMC->Gspos("FWZ3", 5,"FLTB",0.,ycoor,-zcoor+(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[2],"ONLY");
-    gMC->Gspos("FWZ3", 6,"FLTC",0.,ycoor, zcoor-(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[5],"ONLY");
+    xcoor = 0.;
+    ycoor = -kLengthExInModBorder*0.5;
+    zcoor = -kExterInterModBorder1 + (zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5;
+    gMC->Gspos("FWZ3", 5,"FLTB", xcoor, ycoor, zcoor,idrotm[2],"ONLY");
+    gMC->Gspos("FWZ3", 6,"FLTC", xcoor, ycoor,-zcoor,idrotm[5],"ONLY");
   }
-  ycoor = -dy+y0*0.5;
-  gMC->Gspos("FWZ3", 3,"FLTA",0.,ycoor, zcoo,idrotm[4],"ONLY");
-  gMC->Gspos("FWZ3", 4,"FLTA",0.,ycoor,-zcoo,idrotm[1],"ONLY");
+
+  xcoor = 0.;
+  ycoor = -yFLT*0.5 + kLengthExInModBorder*0.5;
+  zcoor = kExterInterModBorder2;
+  gMC->Gspos("FWZ3", 3,"FLTA", xcoor, ycoor, zcoor,idrotm[4],"ONLY");
+  gMC->Gspos("FWZ3", 4,"FLTA", xcoor, ycoor,-zcoor,idrotm[1],"ONLY");
 
   if (fTOFHoles) {
-    gMC->Gspos("FWZ3", 7,"FLTB",0.,ycoor,-zcoo+(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[1],"ONLY");
-    gMC->Gspos("FWZ3", 8,"FLTC",0.,ycoor, zcoo-(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[4],"ONLY");
+    xcoor = 0.;
+    ycoor = -yFLT*0.5 + kLengthExInModBorder*0.5;
+    zcoor = -kExterInterModBorder2 + (zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5;
+    gMC->Gspos("FWZ3", 7,"FLTB", xcoor, ycoor, zcoor,idrotm[1],"ONLY");
+    gMC->Gspos("FWZ3", 8,"FLTC", xcoor, ycoor,-zcoor,idrotm[4],"ONLY");
   }
 
-  trpa[0] = 0.5*(zcoo-zcoor)/TMath::Cos(alpha);
+  trpa[0] = 0.5*(kExterInterModBorder2 - kExterInterModBorder1)/TMath::Cos(alpha);
   trpa[1] = kModuleWallThickness;
-  trpa[2] = xFLT*0.5;//par[0];
+  trpa[2] = xFLT*0.5;
   trpa[3] = -beta*kRaddeg;
   trpa[4] = 0.;
   trpa[5] = 0.;
   gMC->Gsvolu("FWZ4","PARA", idtmed[503], trpa, 6);    // fibre glass
-  AliMatrix (idrotm[3],alpha*kRaddeg,90.,90.+alpha*kRaddeg,90.,90.,180.);
-  AliMatrix (idrotm[6],180.-alpha*kRaddeg,90.,90.-alpha*kRaddeg,90.,90.,0.);
-  gMC->Gspos("FWZ4", 1,"FLTA",0.,-dy*0.5, (zcoo+zcoor)*0.5,idrotm[6],"ONLY");
-  gMC->Gspos("FWZ4", 2,"FLTA",0.,-dy*0.5,-(zcoo+zcoor)*0.5,idrotm[3],"ONLY");
+
+  AliMatrix (idrotm[13],alpha*kRaddeg,90.,90.+alpha*kRaddeg,90.,90.,180.);
+  AliMatrix (idrotm[16],180.-alpha*kRaddeg,90.,90.-alpha*kRaddeg,90.,90.,0.);
+
+  xcoor = 0.;
+  ycoor = -yFLT*0.25;
+  zcoor = (kExterInterModBorder2 + kExterInterModBorder1)*0.5;
+  gMC->Gspos("FWZ4", 1,"FLTA", xcoor, ycoor, zcoor,idrotm[16],"ONLY");
+  gMC->Gspos("FWZ4", 2,"FLTA", xcoor, ycoor,-zcoor,idrotm[13],"ONLY");
 
   if (fTOFHoles) {
-    gMC->Gspos("FWZ4", 3,"FLTB",0.,-dy*0.5,-(zcoo+zcoor)*0.5+(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[3],"ONLY");
-    gMC->Gspos("FWZ4", 4,"FLTC",0.,-dy*0.5, (zcoo+zcoor)*0.5-(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[6],"ONLY");
+    xcoor = 0.;
+    ycoor = -yFLT*0.25;
+    zcoor = -(kExterInterModBorder2 + kExterInterModBorder1)*0.5 + (zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5;
+    gMC->Gspos("FWZ4", 3,"FLTB", xcoor, ycoor, zcoor,idrotm[13],"ONLY");
+    gMC->Gspos("FWZ4", 4,"FLTC", xcoor, ycoor,-zcoor,idrotm[16],"ONLY");
   }
 
+
   ///////////////// Detector itself //////////////////////
 
   const Int_t    knx   = fTOFGeometry->NpadX();  // number of pads along x
@@ -487,7 +717,11 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   const Float_t khhony   = 1.0    ;   // heigth of HONY  Layer
   const Float_t khpcby   = 0.08   ;   // heigth of PCB   Layer
   const Float_t khrgly   = 0.055  ;   // heigth of RED GLASS  Layer
-  const Float_t khglfy   = 0.285  ;   // heigth of GLASS+FISHLINE  Layer
+
+  const Float_t khfiliy  = 0.125  ;   // heigth of FISHLINE  Layer
+  const Float_t khglassy = 0.160*0.5; // heigth of GLASS  Layer
+  const Float_t khglfy   = khfiliy+2.*khglassy;// heigth of GLASS+FISHLINE  Layer
+
   const Float_t khcpcby  = 0.16   ;   // heigth of PCB  Central Layer
   const Float_t kwhonz   = 8.1    ;   // z dimension of HONEY  Layer
   const Float_t kwpcbz1  = 10.6   ;   // z dimension of PCB  Lower Layer
@@ -496,7 +730,7 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   const Float_t kwrglz   = 8.     ;   // z dimension of RED GLASS  Layer
   const Float_t kwglfz   = 7.     ;   // z dimension of GLASS+FISHLN Layer
   const Float_t klsensmx = knx*kPadX; // length of Sensitive Layer
-  const Float_t khsensmy = 0.05;//0.11;//0.16;// heigth of Sensitive Layer // ADC
+  const Float_t khsensmy = 0.05;//0.11;//0.16;// heigth of Sensitive Layer
   const Float_t kwsensmz = knz*kPadZ; // width of Sensitive Layer
   
   // heigth of the FSTR Volume (the strip volume)
@@ -505,7 +739,7 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   // width  of the FSTR Volume (the strip volume)
   const Float_t kwstripz = kwcpcbz;
   // length of the FSTR Volume (the strip volume)
-  const Float_t klstripx = fTOFGeometry->StripLength();//122.;
+  const Float_t klstripx = fTOFGeometry->StripLength();
   
   Float_t parfp[3]={klstripx*0.5,khstripy*0.5,kwstripz*0.5};
   // Coordinates of the strip center in the strip reference frame;
@@ -563,6 +797,29 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   gMC->Gspos("FRGL",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
   gMC->Gspos("FRGL",3,"FSTR",0., posfp[1],0.,0,"ONLY");
 
+  //-- GLASS Layer definition
+  parfp[1] = khglassy*0.5;
+  parfp[2] = kwglfz*0.5;
+  gMC->Gsvolu("FGLA","BOX",idtmed[509],parfp,3);     // glass
+
+  // positioning 4 GLASS Layers on FSTR volume
+  posfp[1] = -khstripy*0.5+khhony+khpcby+khrgly+parfp[1];
+  gMC->Gspos("FGLA",1,"FSTR",0.,-posfp[1],0.,0,"ONLY");
+  gMC->Gspos("FGLA",4,"FSTR",0., posfp[1],0.,0,"ONLY");
+  posfp[1] = khcpcby*0.5+khrgly+khglassy*0.5;
+  gMC->Gspos("FGLA",2,"FSTR",0.,-posfp[1],0.,0,"ONLY");
+  gMC->Gspos("FGLA",3,"FSTR",0., posfp[1],0.,0,"ONLY");
+
+  //-- FREON Layer definition
+  parfp[1] = khfiliy*0.5;
+  gMC->Gsvolu("FFIS","BOX",idtmed[507],parfp,3);     // freon
+
+  // positioning 2 FREON Layers on FSTR volume
+  posfp[1] = -khstripy*0.5+khhony+khpcby+khrgly+khglassy+parfp[1];
+  gMC->Gspos("FFIS",1,"FSTR",0.,-posfp[1],0.,0,"ONLY");
+  gMC->Gspos("FFIS",2,"FSTR",0., posfp[1],0.,0,"ONLY");
+
+  /*
   //-- GLASS+FISHLINE Layer definition
   parfp[1] = khglfy*0.5;
   parfp[2] = kwglfz*0.5;
@@ -572,7 +829,7 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   posfp[1] = (khcpcby+khglfy)*0.5+khrgly;
   gMC->Gspos("FGLF",1,"FSTR",0.,-posfp[1],0.,0,"ONLY");
   gMC->Gspos("FGLF",2,"FSTR",0., posfp[1],0.,0,"ONLY");
-
+  */
 
   //  Positioning the Strips  (FSTR) in the FLT volumes
   Int_t maxStripNumbers [5] ={fTOFGeometry->NStripC(),
@@ -582,7 +839,7 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
                              fTOFGeometry->NStripC()};
 
   Int_t totalStrip = 0;
-  Float_t zpos, ypos, ang;
+  Float_t xpos, zpos, ypos, ang;
   for(Int_t iplate =0; iplate < fTOFGeometry->NPlates(); iplate++){
     if (iplate>0) totalStrip += maxStripNumbers[iplate-1];
     for(Int_t istrip =0; istrip < maxStripNumbers[iplate]; istrip++){
@@ -594,15 +851,15 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
       else if (ang==0.) AliMatrix (idrotm[istrip+totalStrip+1],90.,0.,90.,90., 0., 0.);
       else if (ang<0.)  AliMatrix (idrotm[istrip+totalStrip+1],90.,0.,90.+ang,90.,-ang,270.);
 
-
+      xpos = 0.;
       zpos = fTOFGeometry->GetDistances(iplate,istrip);
       ypos = fTOFGeometry->GetHeights(iplate,istrip);
 
-      gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTA",0.,ypos,-zpos,idrotm[istrip+totalStrip+1],  "ONLY");
+      gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTA", xpos, ypos,-zpos,idrotm[istrip+totalStrip+1],  "ONLY");
 
       if (fTOFHoles) {
-       if (istrip+totalStrip+1>53) gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTC",0.,ypos,-zpos-(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[istrip+totalStrip+1],"ONLY");
-       if (istrip+totalStrip+1<39) gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTB",0.,ypos,-zpos+(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[istrip+totalStrip+1],"ONLY");
+       if (istrip+totalStrip+1>53) gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTC", xpos, ypos,-zpos-(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[istrip+totalStrip+1],"ONLY");
+       if (istrip+totalStrip+1<39) gMC->Gspos("FSTR",istrip+totalStrip+1,"FLTB", xpos, ypos,-zpos+(zlenA*0.5 + kInterCentrModBorder1 - kModuleWallThickness)*0.5,idrotm[istrip+totalStrip+1],"ONLY");
       }
     }
   }
@@ -611,33 +868,49 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   par[0] = xFLT*0.5;
   par[1] = kHoneycombLayerThickness*0.5;
   par[2] = zFLTA*0.5;
-  ycoor  = kHoneycombLayerThickness*0.5;
-  gMC->Gsvolu("FPEA", "BOX ", idtmed[506], par, 3);   // Al honeycomb ok giovanni cara romeo
-  gMC->Gspos ("FPEA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
+  gMC->Gsvolu("FPEA", "BOX ", idtmed[506], par, 3);   // Al honeycomb
+
+  xcoor = 0.;
+  ycoor = kHoneycombLayerThickness*0.5;
+  zcoor = 0.;
+  gMC->Gspos ("FPEA", 0, "FLTA", xcoor, ycoor, zcoor, 0, "ONLY");
 
   if (fTOFHoles) {
+    par[0] = xFLT*0.5;
+    par[1] = kHoneycombLayerThickness*0.5;
     par[2] = (zlenA*0.5 - kInterCentrModBorder2-kModuleWallThickness)*0.5;
+    gMC->Gsvolu("FPEB", "BOX ", idtmed[506], par, 3);   // Al honeycomb
+
+    xcoor = 0.;
     ycoor = kHoneycombLayerThickness*0.5;
-    gMC->Gsvolu("FPEB", "BOX ", idtmed[506], par, 3);   // Al honeycomb ok giovanni cara romeo
-    gMC->Gspos ("FPEB", 1, "FLTB", 0., ycoor, -(kInterCentrModBorder2-kInterCentrModBorder1)*0.5, 0, "ONLY");
-    gMC->Gspos ("FPEB", 2, "FLTC", 0., ycoor,  (kInterCentrModBorder2-kInterCentrModBorder1)*0.5, 0, "ONLY");
+    zcoor = (kInterCentrModBorder2-kInterCentrModBorder1)*0.5;
+    gMC->Gspos ("FPEB", 1, "FLTB", xcoor, ycoor,-zcoor, 0, "ONLY");
+    gMC->Gspos ("FPEB", 2, "FLTC", xcoor, ycoor, zcoor, 0, "ONLY");
   }
 
   // frame of Air
-  ycoor += kHoneycombLayerThickness*0.5;
-  //par[0] = xFLT*0.5;
-  par[1] = (yFLT*0.5-kHoneycombLayerThickness-khAlWall)*0.5;
+  par[0] = xFLT*0.5;
+  par[1] = (yFLT*0.5 - kHoneycombLayerThickness)*0.5;
   par[2] = zFLTA *0.5;
-  ycoor += (yFLT*0.5-kHoneycombLayerThickness-khAlWall)*0.5;
   gMC->Gsvolu("FAIA", "BOX ", idtmed[500], par, 3); // Air
-  gMC->Gspos ("FAIA", 0, "FLTA", 0., ycoor, 0., 0, "ONLY");
+
+  xcoor = 0.;
+  ycoor = kHoneycombLayerThickness + (yFLT*0.5 - kHoneycombLayerThickness)*0.5;
+  zcoor = 0.;
+  gMC->Gspos ("FAIA", 0, "FLTA", xcoor, ycoor, zcoor, 0, "ONLY");
 
   if (fTOFHoles) {
+    par[0] = xFLT*0.5;
+    par[1] = (yFLT*0.5 - kHoneycombLayerThickness)*0.5;
     par[2] = (zlenA*0.5 - kInterCentrModBorder2 - kModuleWallThickness)*0.5;
     gMC->Gsvolu("FAIB", "BOX ", idtmed[500], par, 3); // Air
-    gMC->Gspos ("FAIB", 0, "FLTB", 0., ycoor, -(kInterCentrModBorder2-kInterCentrModBorder1)*0.5, 0, "ONLY");
     gMC->Gsvolu("FAIC", "BOX ", idtmed[500], par, 3); // Air
-    gMC->Gspos ("FAIC", 0, "FLTC", 0., ycoor,  (kInterCentrModBorder2-kInterCentrModBorder1)*0.5, 0, "ONLY");
+
+    xcoor = 0.;
+    ycoor = kHoneycombLayerThickness + (yFLT*0.5 - kHoneycombLayerThickness)*0.5;
+    zcoor = (kInterCentrModBorder2-kInterCentrModBorder1)*0.5;
+    gMC->Gspos ("FAIB", 0, "FLTB", xcoor, ycoor,-zcoor, 0, "ONLY");
+    gMC->Gspos ("FAIC", 0, "FLTC", xcoor, ycoor, zcoor, 0, "ONLY");
   }
 
   // start with cards and cooling tubes
@@ -646,8 +919,6 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
   
   // see GEOM200 in GEANT manual
 
-  //AliMatrix(idrotm[98], 90., 0., 90., 90., 0., 0.); // 0 deg
-  
   Float_t cardpar[3];
 
   // card volume definition
@@ -680,8 +951,8 @@ void AliTOFv5T0::TOFpc(Float_t xtof,  Float_t ytof, Float_t zlenA,
 
   // central module positioning
   Float_t cardpos[3], aplpos2;
-  Float_t stepforcardA=6.625;
-  Float_t tdis=0.6;
+  Float_t stepforcardA = 6.625;
+  Float_t tdis = 0.6;
   Float_t aplpos1 = -2.;
 
   cardpos[0]= 0.;
@@ -841,7 +1112,7 @@ void AliTOFv5T0::DrawModule() const
   gMC->Gdopt("hide","off");
 }
 //_____________________________________________________________________________
-void AliTOFv5T0::DrawDetectorModules()
+void AliTOFv5T0::DrawDetectorModules() const
 {
   //
   // Draw a shaded view of the TOF detector version 4
@@ -907,7 +1178,7 @@ void AliTOFv5T0::DrawDetectorModules()
 }                                 
 
 //_____________________________________________________________________________
-void AliTOFv5T0::DrawDetectorStrips()
+void AliTOFv5T0::DrawDetectorStrips() const
 {
   //
   // Draw a shaded view of the TOF strips for version 4
@@ -1040,12 +1311,14 @@ void AliTOFv5T0::CreateMaterials()
 
   //AliTOF::CreateMaterials();
 
-  Int_t   isxfld = gAlice->Field()->Integ();
-  Float_t sxmgmx = gAlice->Field()->Max();
+  AliMagF *magneticField = (AliMagF*)((AliMagF*)TGeoGlobalMagField::Instance()->GetField());
+
+  Int_t   isxfld = magneticField->Integ();
+  Float_t sxmgmx = magneticField->Max();
+
   Float_t we[7], ae[7], na[7], fr[7], vl[7];
   Int_t i;
 
-  //
   //--- Quartz (SiO2) to simulate float glass
   //    density tuned to have correct float glass 
   //    radiation length
@@ -1123,9 +1396,9 @@ void AliTOFv5T0::CreateMaterials()
   Float_t densfre= 0.00375;
   Int_t nfre  = 4;
 
-  char namat[15] = "            ";
-  Float_t ama[2], zma[2], dma, radl, absl, buf[1];
-  Int_t nbuf;
+  //char namat[15] = "            ";
+  //Float_t ama[2], zma[2], dma, radl, absl, buf[1];
+  //Int_t nbuf;
 
   AliMixture ( 0, "Air$", aAir, zAir, dAir, 4, wAir);
   AliMixture ( 1, "Nomex$", anox, znox, dnox, nnox, wnox);
@@ -1135,7 +1408,7 @@ void AliTOFv5T0::CreateMaterials()
   AliMaterial( 5, "Al honeycomb$", 26.98, 13., 0.0496, 483., 2483.);
   AliMixture ( 6, "Freon$",  afre, zfre, densfre, nfre, wfre);
   AliMixture ( 7, "Glass$", aq, zq, dq, nq, wq);
-
+  /*
   // get freon and glass
   gMC->Gfmate((*fIdmate)[6],namat,ama[0],zma[0],dma,radl,absl,buf,nbuf);
   gMC->Gfmate((*fIdmate)[7],namat,ama[1],zma[1],dma,radl,absl,buf,nbuf);
@@ -1145,6 +1418,7 @@ void AliTOFv5T0::CreateMaterials()
   Float_t dgfr = 1.434;
   Int_t ngfr  = 2;
   AliMixture ( 8, "glass-freon$", ama, zma, dgfr, ngfr, wgfr);
+  */
   AliMixture ( 9, "Water$",  awa, zwa, dwa, nwa, wwa);
   AliMixture (10, "STAINLESS STEEL$", asteel, zsteel, 7.88, 4, wsteel);
 
@@ -1166,7 +1440,7 @@ void AliTOFv5T0::CreateMaterials()
   AliMedium( 2,"Nomex$",        1, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
   AliMedium( 3,"G10$",          2, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
   AliMedium( 4,"fibre glass$",  3, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
-  AliMedium( 5,"glass-freon$",  8, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
+  //AliMedium( 5,"glass-freon$",  8, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
   AliMedium( 6,"Al Frame$",     4, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
   AliMedium( 7,"Al honeycomb$", 5, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
   AliMedium( 8,"Fre$",          6, 0, isxfld, sxmgmx, 10., stemax, deemax, epsil, stmin);
@@ -1223,9 +1497,6 @@ void AliTOFv5T0::StepManager()
   Int_t   *idtmed = fIdtmed->GetArray()-499;
   Float_t incidenceAngle;
 
-  const char * path71 = "B071";
-  const char * path75 = "B075";
-  const char * path74 = "B074";
   const char* volpath;
 
   Int_t index = 0;
@@ -1239,7 +1510,10 @@ void AliTOFv5T0::StepManager()
      )
   {
 
-    AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
+    AliMC *mcApplication = (AliMC*)gAlice->GetMCApp();
+
+    AddTrackReference(mcApplication->GetCurrentTrackNumber(), AliTrackReference::kTOF);
+    //AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber());
 
     // getting information about hit volumes
     
@@ -1305,16 +1579,19 @@ void AliTOFv5T0::StepManager()
       strip = strip - fTOFGeometry->NStripC() - fTOFGeometry->NStripB() - fTOFGeometry->NStripA() - fTOFGeometry->NStripB();
     }
 
-    volpath=gMC->CurrentVolOffName(8);
-    index=gMC->CurrentVolOffID(8,copy);
-    index=copy;
-
+    volpath=gMC->CurrentVolOffName(7);
+    index=atoi(&volpath[4]);
     sector=-1;
-    if(strcmp(path71,volpath)==0 && index <6) sector=12+index;
-    if(strcmp(path71,volpath)==0 && index >=6) sector=index-3;
-    if(strcmp(path75,volpath)==0) sector=index-1;
-    if(strcmp(path74,volpath)==0) sector=10+index;
-
+    sector=index;
+
+    //Old 6h convention
+    // if(index<5){
+    //   sector=index+13;
+    // }
+    // else{
+    //   sector=index-5;
+    // } 
     for(i=0;i<3;++i) {
       hits[i]   = pos[i];
       hits[i+3] = pm[i];
@@ -1335,11 +1612,13 @@ void AliTOFv5T0::StepManager()
     vol[3]= padx;
     vol[4]= padz;    
 
-    AddT0Hit(gAlice->GetMCApp()->GetCurrentTrackNumber(),vol, hits);
+    AddT0Hit(mcApplication->GetCurrentTrackNumber(),vol, hits);
+    //AddT0Hit(gAlice->GetMCApp()->GetCurrentTrackNumber(),vol, hits);
   }
 }
 //-------------------------------------------------------------------
-void AliTOFv5T0::MaterialMixer(Float_t* p,Float_t* a,Float_t* m,Float_t* d,Float_t* s,Int_t n) {
+void AliTOFv5T0::MaterialMixer(Float_t* p,Float_t* a,Float_t* m,Float_t* d,Float_t* s,Int_t n) const
+{
   // a[] atomic weights vector  (in)
   //     (atoms present in more compound appear separately)
   // m[] number of corresponding atoms in the mixture  (in)