]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSInitGeometry.cxx
Correct treatment of tracks with pT<pTmin
[u/mrichter/AliRoot.git] / ITS / AliITSInitGeometry.cxx
index e02ba52152b92f157cbeea35c1640e4d55a60e5d..effa21f99715bfb3887151beda6a8eaf4d588f46 100644 (file)
 /*
 $Id$
 */
+////////////////////////////////////////////////////////////////
+//  This class initializes the class AliITSgeom
+//  The initialization is done starting from 
+//  a geometry coded by means of the ROOT geometrical modeler
+//  This initialization can be used both for simulation and reconstruction
+///////////////////////////////////////////////////////////////
+
 #include <TArrayD.h>
 #include <TArrayF.h>
 #include <TStopwatch.h>
-#include <AliITSgeomSPD.h>
-#include <AliITSgeomSDD.h>
-#include <AliITSgeomSSD.h>
-#include <AliITSsegmentationSPD.h>
-#include <AliITSsegmentationSDD.h>
-#include <AliITSsegmentationSSD.h>
 #include <TGeoManager.h>
+#include <TGeoMatrix.h>
 #include <TGeoVolume.h>
 #include <TGeoShape.h>
 #include <TGeoBBox.h>
@@ -40,22 +42,28 @@ $Id$
 #include <TGeoPcon.h>
 #include <TGeoEltu.h>
 #include <TGeoHype.h>
-#include <TClass.h>
+#include <TMath.h>
 
-#include <AliLog.h>
-#include "AliITSgeom.h"
+#include "AliLog.h"
+#include "AliITSsegmentationSPD.h"
+#include "AliITSsegmentationSDD.h"
+#include "AliITSsegmentationSSD.h"
 #include "AliITSInitGeometry.h"
+#include <TDatime.h>
 
 ClassImp(AliITSInitGeometry)
+
 //______________________________________________________________________
 AliITSInitGeometry::AliITSInitGeometry():
-TObject(),
-fName(),
-fMinorVersion(0),
-fMajorVersion(0),
-fTiming(kFALSE),
-fSegGeom(kFALSE),
-fDecode(kFALSE){
+TObject(),                   // Base Class
+fName(0),                    // Geometry name
+fMajorVersion(kvDefault),    // Major versin number
+fTiming(kFALSE),             // Flag to start inilization timing
+fSegGeom(kFALSE),            // Flag to switch between the old use of
+                             // AliITSgeomS?D class, or AliITSsegmentation
+                             // class in fShape of AliITSgeom class.
+fDecode(kFALSE),             // Flag for new/old decoding
+fDebug(0){                   // Debug flag
     // Default Creator
     // Inputs:
     //   none.
@@ -63,16 +71,20 @@ fDecode(kFALSE){
     //   none.
     // Return:
     //   A default inilized AliITSInitGeometry object
+
+    fName = "Undefined";
 }
 //______________________________________________________________________
-AliITSInitGeometry::AliITSInitGeometry(const Char_t *name,Int_t minorversion):
-TObject(),
-fName(name),
-fMinorVersion(minorversion),
-fMajorVersion(0),
-fTiming(kFALSE),
-fSegGeom(kFALSE),
-fDecode(kFALSE){
+AliITSInitGeometry::AliITSInitGeometry(AliITSVersion_t version):
+TObject(),                   // Base Class
+fName(0),                    // Geometry name
+fMajorVersion(version),      // Major version number
+fTiming(kFALSE),             // Flag to start inilization timing
+fSegGeom(kFALSE),            // Flag to switch between the old use of
+                             // AliITSgeomS?D class, or AliITSsegmentation
+                             // class in fShape of AliITSgeom class.
+fDecode(kFALSE),             // Flag for new/old decoding
+fDebug(0){                   // Debug flag
     // Default Creator
     // Inputs:
     //   none.
@@ -81,17 +93,16 @@ fDecode(kFALSE){
     // Return:
     //   A default inilized AliITSInitGeometry object
 
-    if(fName.CompareTo("AliITSvPPRasymmFMD")==0)if(fMinorVersion==1||
-                                                  fMinorVersion==2){
-       fMajorVersion=10;
-       return;
-    } // end if
-    // if not defined geometry error
-    Error("AliITSInitGeometry(name,version)"," Name must be AliITSvPPRasymmFMD"
-       " and version must be 1 or 2 for now.");
-    fMinorVersion = 0;
-    fName = "";
-    return;
+  switch (version) {
+    case kv11:
+        fName="AliITSv11";
+       break;
+    case kvDefault:
+    default:
+        AliFatal(Form("Undefined geometry: fMajorVersion=%d, ",(Int_t)fMajorVersion));
+        fName = "Undefined";
+       break;
+    } // switch
 }
 //______________________________________________________________________
 AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(){
@@ -107,249 +118,202 @@ AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(){
     //   A pointer to a new properly inilized AliITSgeom class. If
     //   pointer = 0 then failed to init.
 
-    AliITSgeom *geom = new AliITSgeom();
-    if(!InitAliITSgeom(geom)){ // Error initilization failed
-       delete geom;
-       geom = 0;
-    } // end if
-    return geom;
+
+  AliITSVersion_t version = kvDefault;
+  TDatime datetime;
+  TGeoVolume *itsV = gGeoManager->GetVolume("ITSV");
+  if(!itsV){
+    AliError("Can't find ITS volume ITSV, exiting - nothing done!");
+    return 0;
+  }// end if
+  const Char_t *title = itsV->GetTitle();
+  if(!ReadVersionString(title,version))
+    Warning("UpdateInternalGeometry","Can't read title=%s\n",title);
+  SetTiming(kFALSE);
+  SetSegGeom(kFALSE);
+  SetDecoding(kFALSE);
+  AliITSgeom *geom = CreateAliITSgeom(version);
+  AliDebug(1,"AliITSgeom object has been initialized from TGeo\n");
+  return geom;
 }
 //______________________________________________________________________
-Bool_t AliITSInitGeometry::InitAliITSgeom(AliITSgeom *geom){
-    // Initilizes the geometry transformation class AliITSgeom
+AliITSgeom* AliITSInitGeometry::CreateAliITSgeom(Int_t major){
+    // Creates and Initilizes the geometry transformation class AliITSgeom
     // to values appropreate to this specific geometry. Now that
     // the segmentation is part of AliITSgeom, the detector
     // segmentations are also defined here.
     // Inputs:
-    //   AliITSgeom *geom  A pointer to the AliITSgeom class
+    //   Int_t major   major version, see AliITSVersion_t
+    //   
     // Outputs:
-    //   AliITSgeom *geom  This pointer recreated and properly inilized.
-    // Return:
     //   none.
+    // Return:
+    //   A pointer to a new properly inilized AliITSgeom class. If
+    //   pointer = 0 then failed to init.
 
-    switch(fMajorVersion){
-    case 10:{ // only case defined so far
-       return InitAliITSgeomPPRasymmFMD(geom);
-    }break; // end case
-    default:{
-       Error("InitAliITSgeom","Undefine geomtery");
-       return kFALSE;
-    } break; // end case
+    switch(major){
+    case kv11:
+        SetGeometryName("AliITSv11");
+        SetVersion(kv11);
+        break;
+    case kvDefault:
+    default:
+        SetGeometryName("Undefined");
+        SetVersion(kvDefault);
+        break;
     } // end switch
-    return kFALSE;
-}
-//______________________________________________________________________
-Bool_t AliITSInitGeometry::InitAliITSgeomPPRasymmFMD(AliITSgeom *geom){
-    // Initilizes the geometry transformation class AliITSgeom
-    // to values appropreate to this specific geometry. Now that
-    // the segmentation is part of AliITSgeom, the detector
-    // segmentations are also defined here.
-    // Inputs:
-    //   AliITSgeom *geom  A pointer to the AliITSgeom class
-    // Outputs:
-    //   AliITSgeom *geom  This pointer recreated and properly inilized.
-    // Return:
-    //   none.
-  //    const Double_t kcm2micron = 1.0E4;
-    const Int_t kItype=0; // Type of transormation defined 0=> Geant
-    const Int_t klayers = 6; // number of layers in the ITS
-    const Int_t kladders[klayers]   = {20,40,14,22,34,38}; // Number of ladders
-    const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
-    const AliITSDetector idet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
-    const TString pathbase = "/ALIC_1/ITSV_1/ITSD_1/";
-    const TString names[2][klayers] = {
-       {"%sIT12_1/I12A_%d/I10A_%d/I103_%d/I101_1/ITS1_1", // lay=1
-        "%sIT12_1/I12A_%d/I20A_%d/I1D3_%d/I1D1_1/ITS2_1", // lay=2
-        "%sIT34_1/I004_%d/I302_%d/ITS3_%d/", // lay=3
-        "%sIT34_1/I005_%d/I402_%d/ITS4_%d/", // lay=4
-        "%sIT56_1/I565_%d/I562_%d/ITS5_%d/", // lay=5
-        "%sIT56_1/I569_%d/I566_%d/ITS6_%d/"},// lay=6
-       {"%sIT12_1/I12B_%d/I10B_%d/I107_%d/I101_1/ITS1_1", // lay=1
-        "%sIT12_1/I12B_%d/I20B_%d/I1D7_%d/I1D1_1/ITS2_1", // lay=2
-        "%sIT34_1/I004_%d/I302_%d/ITS3_%d", // lay=3
-        "%sIT34_1/I005_%d/I402_%d/ITS4_%d", // lay=4
-        "%sIT56_1/I565_%d/I562_%d/ITS5_%d", // lay=5
-        "%sIT56_1/I569_%d/I566_%d/ITS6_%d"}};// Lay=6
-    /*
-      Int_t itsGeomTreeCopys[knlayers][3]= {{10, 2, 4},// lay=1
-      {10, 4, 4},// lay=2
-      {14, 6, 1},// lay=3
-      {22, 8, 1},// lay=4
-      {34,22, 1},// lay=5
-      {38,25, 1}};//lay=6
-    */
-    Int_t mod,nmods=0,lay,lad,det,cpn0,cpn1,cpn2;
-    Double_t tran[3]={0.0,0.0,0.0},rot[10]={9*0.0,1.0};
-    TArrayD shapePar;
-    TString path,shapeName;
-    TGeoHMatrix materix;
-    Bool_t initSeg[3]={kFALSE,kFALSE,kFALSE};
-    TStopwatch *time = 0x0;if(fTiming) time=new TStopwatch();
-
-    if(fTiming) time->Start();
-    for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
-    geom->Init(kItype,klayers,kladders,kdetectors,nmods);
-    for(mod=0;mod<nmods;mod++){
-        DecodeDetectorLayers(mod,lay,lad,det); // Write
-        geom->CreateMatrix(mod,lay,lad,det,idet[lay-1],tran,rot);
-        RecodeDetector(mod,cpn0,cpn1,cpn2); // Write reusing lay,lad,det.
-        path.Form(names[fMinorVersion-1][lay-1].Data(),
-                  pathbase.Data(),cpn0,cpn1,cpn2);
-        geom->GetGeomMatrix(mod)->SetPath(path);
-        GetTransformation(path.Data(),materix);
-        geom->SetTrans(mod,materix.GetTranslation());
-        geom->SetRotMatrix(mod,materix.GetRotationMatrix());
-        if(initSeg[idet[lay-1]]) continue;
-        GetShape(path,shapeName,shapePar);
-        if(shapeName.CompareTo("BOX")){
-            Error("InitITSgeom","Geometry changed without proper code update"
-                  "or error in reading geometry. Shape is not BOX.");
-            return kFALSE;
-        } // end if
-       InitGeomShapePPRasymmFMD(idet[lay-1],initSeg,shapePar,geom);
-    } // end for module
-    if(fTiming){
-        time->Stop();
-        time->Print();
-        delete time;
+    AliITSgeom *geom = new AliITSgeom();
+    if(!InitAliITSgeom(geom)){ // Error initilization failed
+       delete geom;
+       geom = 0;
     } // end if
-    return kTRUE;
+    return geom;
 }
 //______________________________________________________________________
-Bool_t AliITSInitGeometry::InitGeomShapePPRasymmFMD(AliITSDetector idet,
-                                                      Bool_t *initSeg,
-                                                      TArrayD &shapePar,
-                                                      AliITSgeom *geom){
-    // Initilizes the geometry segmentation class AliITSgeomS?D, or
-    // AliITSsegmentationS?D depending on the vaule of fSegGeom,
-    // to values appropreate to this specific geometry. Now that
-    // the segmentation is part of AliITSgeom, the detector
-    // segmentations are also defined here.
-    // Inputs:
-    //   Int_t      lay    The layer number/name.
-    //   AliITSgeom *geom  A pointer to the AliITSgeom class
-    // Outputs:
-    //   AliITSgeom *geom  This pointer recreated and properly inilized.
-    // Return:
-    //   none.
-  //   const Double_t kcm2micron = 1.0E4;
-    const Double_t kmicron2cm = 1.0E-4;
-    Int_t i;
-    TArrayF shapeParF;
-
-    shapeParF.Set(shapePar.GetSize());
-    for(i=0;i<shapePar.GetSize();i++) shapeParF[i]=shapePar[i];
-    switch (idet){
-    case kSPD:{
-       initSeg[idet] = kTRUE;
-       AliITSgeomSPD *geomSPD = new AliITSgeomSPD425Short();
-       Float_t bx[256],bz[280];
-       for(i=000;i<256;i++) bx[i] =  50.0*kmicron2cm; // in x all are 50 microns.
-       for(i=000;i<160;i++) bz[i] = 425.0*kmicron2cm; // most are 425 microns
-       // except below
-       for(i=160;i<280;i++) bz[i] =   0.0*kmicron2cm; // Outside of detector.
-       bz[ 31] = bz[ 32] = 625.0*kmicron2cm; // first chip boundry
-       bz[ 63] = bz[ 64] = 625.0*kmicron2cm; // first chip boundry
-       bz[ 95] = bz[ 96] = 625.0*kmicron2cm; // first chip boundry
-       bz[127] = bz[128] = 625.0*kmicron2cm; // first chip boundry
-       bz[160] = 425.0*kmicron2cm;// Set so that there is no zero pixel size for fNz.
-       geomSPD->ReSetBins(shapeParF[1],256,bx,160,bz);
-       geom->ReSetShape(idet,geomSPD);
-    }break;
-    case kSDD:{
-       initSeg[idet] = kTRUE;
-       AliITSgeomSDD *geomSDD = new AliITSgeomSDD256(shapeParF.GetSize(),
-                                                     shapeParF.GetArray());
-       geom->ReSetShape(idet,geomSDD);
-    }break;
-    case kSSD:{
-       initSeg[idet] = kTRUE;
-       AliITSgeomSSD *geomSSD = new AliITSgeomSSD275and75(
-           shapeParF.GetSize(),shapeParF.GetArray());
-       geom->ReSetShape(idet,geomSSD);
-    }break;
-    default:{// Others, Note no kSDDp or kSSDp in this geometry.
-       geom->ReSetShape(idet,0);
-       Info("InitGeomShapePPRasymmFMD",
-            "default Dx=%f Dy=%f Dz=%f default=%d",
-            shapePar[0],shapePar[1],shapePar[2],idet);
-    }break;
+Bool_t AliITSInitGeometry::InitAliITSgeom(AliITSgeom *geom){
+  // Initilizes the geometry transformation class AliITSgeom
+  // to values appropreate to this specific geometry. Now that
+  // the segmentation is part of AliITSgeom, the detector
+  // segmentations are also defined here.
+  // Inputs:
+  //   AliITSgeom *geom  A pointer to the AliITSgeom class
+  // Outputs:
+  //   AliITSgeom *geom  This pointer recreated and properly inilized.
+  // Return:
+  //   none.
+
+    if(!gGeoManager){
+        AliFatal("The geometry manager has not been initialized (e.g. "
+                 "TGeoManager::Import(\"geometry.root\")should be "
+                 "called in advance) - exit forced");
+        return kFALSE;
+    } // end if
+    switch(fMajorVersion) {
+    case kv11: {
+        return InitAliITSgeomV11(geom);
+    } break; // end case
+    case kvDefault: default: {
+        AliFatal("Undefined geometry");
+        return kFALSE;
+    } break; // end case
     } // end switch
-    return kTRUE;
+    return kFALSE;
 }
 //______________________________________________________________________
-Bool_t AliITSInitGeometry::InitSegmentationPPRasymmFMD(AliITSDetector idet,
-                                                      Bool_t *initSeg,
-                                                      TArrayD &shapePar,
-                                                      AliITSgeom *geom){
-    // Initilizes the geometry segmentation class AliITSgeomS?D, or
-    // AliITSsegmentationS?D depending on the vaule of fSegGeom,
-    // to values appropreate to this specific geometry. Now that
-    // the segmentation is part of AliITSgeom, the detector
-    // segmentations are also defined here.
+void AliITSInitGeometry::TransposeTGeoHMatrix(TGeoHMatrix *m)const{
+    // Transpose the rotation matrix part of a TGeoHMatrix. This
+    // is needed because TGeo stores the transpose of the rotation
+    // matrix as compared to what AliITSgeomMatrix uses (and Geant3).
     // Inputs:
-    //   Int_t      lay    The layer number/name.
-    //   AliITSgeom *geom  A pointer to the AliITSgeom class
+    //    TGeoHMatrix *m  The matrix to be transposed
     // Outputs:
-    //   AliITSgeom *geom  This pointer recreated and properly inilized.
+    //    TGEoHMatrix *m  The transposed matrix
     // Return:
-    //   none.
-    const Double_t kcm2micron = 1.0E4;
+    //    none.
     Int_t i;
+    Double_t r[9];
 
-    switch (idet){
-    case kSPD:{
-       initSeg[idet] = kTRUE;
-       AliITSsegmentationSPD *segSPD = new AliITSsegmentationSPD();
-       segSPD->SetDetSize(2.*shapePar[0]*kcm2micron, // X
-                          2.*shapePar[2]*kcm2micron, // Z
-                          2.*shapePar[1]*kcm2micron);// Y  Microns
-       segSPD->SetNPads(256,160);// Number of Bins in x and z
-       Float_t bx[256],bz[280];
-       for(i=000;i<256;i++) bx[i] =  50.0; // in x all are 50 microns.
-       for(i=000;i<160;i++) bz[i] = 425.0; // most are 425 microns
-       // except below
-       for(i=160;i<280;i++) bz[i] =   0.0; // Outside of detector.
-       bz[ 31] = bz[ 32] = 625.0; // first chip boundry
-       bz[ 63] = bz[ 64] = 625.0; // first chip boundry
-       bz[ 95] = bz[ 96] = 625.0; // first chip boundry
-       bz[127] = bz[128] = 625.0; // first chip boundry
-       bz[160] = 425.0;// Set so that there is no zero pixel size for fNz.
-       segSPD->SetBinSize(bx,bz); // Based on AliITSgeomSPD for now.
-       geom->ReSetShape(idet,segSPD);
-    }break;
-    case kSDD:{
-       initSeg[idet] = kTRUE;
-       AliITSsegmentationSDD *segSDD = new AliITSsegmentationSDD();
-       segSDD->SetDetSize(shapePar[0]*kcm2micron, // X
-                          2.*shapePar[2]*kcm2micron, // Z
-                          2.*shapePar[1]*kcm2micron);// Y  Microns
-       segSDD->SetNPads(256,256);// Anodes, Samples
-       geom->ReSetShape(idet,segSDD);
-    }break;
-    case kSSD:{
-       initSeg[idet] = kTRUE;
-       AliITSsegmentationSSD *segSSD = new AliITSsegmentationSSD();
-       segSSD->SetDetSize(2.*shapePar[0]*kcm2micron, // X
-                          2.*shapePar[2]*kcm2micron, // Z
-                          2.*shapePar[1]*kcm2micron);// Y  Microns.
-       segSSD->SetPadSize(95.,0.); // strip x pitch in microns
-       segSSD->SetNPads(768,2); // number of strips on each side, sides.
-       segSSD->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
-       segSSD->SetAnglesLay5(0.0075,0.0275);//strip angels rad P and N
-       segSSD->SetAnglesLay6(0.0275,0.0075);//strip angels rad P and N
-       geom->ReSetShape(idet,segSSD);
-    }break;
-    default:{// Others, Note no kSDDp or kSSDp in this geometry.
-       geom->ReSetShape(idet,0);
-       Info("InitSegmentationPPRasymmFMD",
-            "default segmentation Dx=%f Dy=%f Dz=%f default=%d",
-            shapePar[0],shapePar[1],shapePar[2],idet);
-    }break;
-    } // end switch
-    return kTRUE;
+    if(m==0) return; // no matrix to transpose.
+    for(i=0;i<9;i += 4) r[i] = m->GetRotationMatrix()[i]; // diagonals
+    r[1] = m->GetRotationMatrix()[3];
+    r[2] = m->GetRotationMatrix()[6];
+    r[3] = m->GetRotationMatrix()[1];
+    r[5] = m->GetRotationMatrix()[7];
+    r[6] = m->GetRotationMatrix()[2];
+    r[7] = m->GetRotationMatrix()[5];
+    m->SetRotation(r);
+    return;
 }
+
+
 //______________________________________________________________________
+Bool_t AliITSInitGeometry::InitAliITSgeomV11(AliITSgeom *geom){
+  // Initilizes the geometry transformation class AliITSgeom
+  // Now that the segmentation is part of AliITSgeom, the detector
+  // segmentations are also defined here.
+  //
+  // Inputs:
+  //   AliITSgeom *geom  A pointer to the AliITSgeom class
+  // Outputs:
+  //   AliITSgeom *geom  This pointer recreated and properly inilized.
+  // LG
+
+  const Int_t kItype  = 0; // Type of transformation defined 0=> Geant
+  const Int_t klayers = 6; // number of layers in the ITS
+  const Int_t kladders[klayers]   = {20,40,14,22,34,38}; // Number of ladders
+  const Int_t kdetectors[klayers] = {4,4,6,8,22,25};// number of detector/lad
+  const AliITSDetector kIdet[6]   = {kSPD,kSPD,kSDD,kSDD,kSSD,kSSD};
+  const TString kPathbase = "/ALIC_1/ITSV_1/";
+
+  const char *pathSPDsens1, *pathSPDsens2;
+  pathSPDsens1="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay1-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay1-Ladder_%d/ITSSPDlay1-sensor_1";
+  pathSPDsens2="%sITSSPD_1/ITSSPDCarbonFiberSectorV_%d/ITSSPDSensitiveVirtualvolumeM0_1/ITSSPDlay2-Stave_%d/ITSSPDhalf-Stave%d_1/ITSSPDlay2-Ladder_%d/ITSSPDlay2-sensor_1";
+
+  const char *pathSDDsens1, *pathSDDsens2;
+  pathSDDsens1 = "%sITSsddLayer3_1/ITSsddLadd_%d/ITSsddSensor3_%d/ITSsddWafer3_%d/ITSsddSensitivL3_1";
+  pathSDDsens2 = "%sITSsddLayer4_1/ITSsddLadd_%d/ITSsddSensor4_%d/ITSsddWafer4_%d/ITSsddSensitivL4_1";
+
+  const char *pathSSDsens1, *pathSSDsens2;
+  pathSSDsens1 = "%sITSssdLayer5_1/ITSssdLay5Ladd_%d/ITSssdSensor5_%d/ITSssdSensitivL5_1";
+  pathSSDsens2 = "%sITSssdLayer6_1/ITSssdLay6Ladd_%d/ITSssdSensor6_%d/ITSssdSensitivL6_1";
+
+  const TString kNames[klayers] = {
+    pathSPDsens1, // lay=1
+    pathSPDsens2, // lay=2
+    pathSDDsens1, // lay=3
+    pathSDDsens2, // lay=4
+    pathSSDsens1, // lay=5
+    pathSSDsens2};// Lay=6
+  
+  Int_t mod,nmods=0, lay, lad, det, cpn0, cpn1, cpn2, cpnHS=1;
+  Double_t tran[3]={0.,0.,0.}, rot[10]={9*0.0,1.0};
+  TArrayD shapePar;
+  TString path, shapeName;
+  TGeoHMatrix matrix;
+  Bool_t initSeg[3]={kFALSE, kFALSE, kFALSE};
+  TStopwatch *time = 0x0;
+  if(fTiming) time = new TStopwatch();
+
+  if(fTiming) time->Start();
+  for(mod=0;mod<klayers;mod++) nmods += kladders[mod]*kdetectors[mod];
+  geom->Init(kItype,klayers,kladders,kdetectors,nmods);
+
+  for(mod=0; mod<nmods; mod++) {
+
+    DecodeDetectorLayers(mod,lay,lad,det);
+    geom->CreateMatrix(mod,lay,lad,det,kIdet[lay-1],tran,rot);
+    RecodeDetector(mod,cpn0,cpn1,cpn2);
+
+    if (kIdet[lay-1]==kSPD) { // we need 1 more copy number because of the half-stave
+      if (det<3) cpnHS = 0; else cpnHS = 1;
+      path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpnHS,cpn2);
+    } else {
+      path.Form(kNames[lay-1].Data(),kPathbase.Data(),cpn0,cpn1,cpn2);
+    };
+
+    geom->GetGeomMatrix(mod)->SetPath(path);
+    GetTransformation(path.Data(),matrix);
+    geom->SetTrans(mod,matrix.GetTranslation());
+    TransposeTGeoHMatrix(&matrix); //Transpose TGeo's rotation matrixes
+    geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
+    if(initSeg[kIdet[lay-1]]) continue;
+    GetShape(path,shapeName,shapePar);
+    if(shapeName.CompareTo("BOX")){
+      Error("InitITSgeom","Geometry changed without proper code update"
+           "or error in reading geometry. Shape is not BOX.");
+      return kFALSE;
+    } // end if
+  } // end for module
+
+  if(fTiming){
+    time->Stop();
+    time->Print();
+    delete time;
+  } // end if
+  return kTRUE;
+}
+
+//_______________________________________________________________________
 Bool_t AliITSInitGeometry::GetTransformation(const TString &volumePath,
                                             TGeoHMatrix &mat){
     // Returns the Transformation matrix between the volume specified
@@ -376,9 +340,9 @@ Bool_t AliITSInitGeometry::GetTransformation(const TString &volumePath,
     // Preserve the modeler state.
     gGeoManager->PushPath();
     if (!gGeoManager->cd(volumePath.Data())) {
-       gGeoManager->PopPath();
-       Error("GetTransformation","Error in cd-ing to ",volumePath.Data());
-       return kFALSE;
+      gGeoManager->PopPath();
+      Error("GetTransformation","Error in cd-ing to %s",volumePath.Data());
+      return kFALSE;
     } // end if !gGeoManager
     mat = *gGeoManager->GetCurrentMatrix();
     // Retstore the modeler state.
@@ -409,8 +373,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
     gGeoManager->PopPath();
     if (!vol) return kFALSE;
     TGeoShape *shape = vol->GetShape();
-    TClass *class_type = shape->IsA();
-    if (class_type==TGeoBBox::Class()) {
+    TClass *classType = shape->IsA();
+    if (classType==TGeoBBox::Class()) {
        shapeType = "BOX";
        npar = 3;
        par.Set(npar);
@@ -419,8 +383,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(box->GetDY(),1);
        par.AddAt(box->GetDZ(),2);
        return kTRUE;
-    }
-    if (class_type==TGeoTrd1::Class()) {
+    } // end if
+    if (classType==TGeoTrd1::Class()) {
        shapeType = "TRD1";
        npar = 4;
        par.Set(npar);
@@ -430,8 +394,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(trd1->GetDy(), 2);
        par.AddAt(trd1->GetDz(), 3);
        return kTRUE;
-    }
-    if (class_type==TGeoTrd2::Class()) {
+    } // end if
+    if (classType==TGeoTrd2::Class()) {
        shapeType = "TRD2";
        npar = 5;
        par.Set(npar);
@@ -442,8 +406,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(trd2->GetDy2(),3);
        par.AddAt(trd2->GetDz(), 4);
        return kTRUE;
-    }
-    if (class_type==TGeoTrap::Class()) {
+    } // end if
+    if (classType==TGeoTrap::Class()) {
        shapeType = "TRAP";
        npar = 11;
        par.Set(npar);
@@ -461,8 +425,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(trap->GetTl2(),9);
        par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
        return kTRUE;
-    }
-    if (class_type==TGeoTube::Class()) {
+    } // end if
+    if (classType==TGeoTube::Class()) {
        shapeType = "TUBE";
        npar = 3;
        par.Set(npar);
@@ -471,8 +435,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(tube->GetRmax(),1);
        par.AddAt(tube->GetDz(),2);
        return kTRUE;
-    }
-    if (class_type==TGeoTubeSeg::Class()) {
+    } // end if
+    if (classType==TGeoTubeSeg::Class()) {
        shapeType = "TUBS";
        npar = 5;
        par.Set(npar);
@@ -483,8 +447,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(tubs->GetPhi1(),3);
        par.AddAt(tubs->GetPhi2(),4);
        return kTRUE;
-    }
-    if (class_type==TGeoCone::Class()) {
+    } // end if
+    if (classType==TGeoCone::Class()) {
        shapeType = "CONE";
        npar = 5;
        par.Set(npar);
@@ -495,8 +459,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(cone->GetRmin2(),3);
        par.AddAt(cone->GetRmax2(),4);
        return kTRUE;
-    }
-    if (class_type==TGeoConeSeg::Class()) {
+    } // end if
+    if (classType==TGeoConeSeg::Class()) {
        shapeType = "CONS";
        npar = 7;
        par.Set(npar);
@@ -509,8 +473,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(cons->GetPhi1(),5);
        par.AddAt(cons->GetPhi2(),6);
        return kTRUE;
-    }
-    if (class_type==TGeoSphere::Class()) {
+    } // end if
+    if (classType==TGeoSphere::Class()) {
        shapeType = "SPHE";
        npar = 6;
        par.Set(npar);
@@ -523,8 +487,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(sphe->GetPhi1(),4);
        par.AddAt(sphe->GetPhi2(),5);
        return kTRUE;
-    }
-    if (class_type==TGeoPara::Class()) {
+    } // end if
+    if (classType==TGeoPara::Class()) {
        shapeType = "PARA";
        npar = 6;
        par.Set(npar);
@@ -536,8 +500,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(para->GetTxz(),4);
        par.AddAt(para->GetTyz(),5);
        return kTRUE;
-    }
-    if (class_type==TGeoPgon::Class()) {
+    } // end if
+    if (classType==TGeoPgon::Class()) {
        shapeType = "PGON";
        TGeoPgon *pgon = (TGeoPgon*)shape;
        Int_t nz = pgon->GetNz();
@@ -556,8 +520,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
            par.AddAt(rmax[i], 4+3*i+2);
        }
        return kTRUE;
-    }
-    if (class_type==TGeoPcon::Class()) {
+    } // end if
+    if (classType==TGeoPcon::Class()) {
        shapeType = "PCON";
        TGeoPcon *pcon = (TGeoPcon*)shape;
        Int_t nz = pcon->GetNz();
@@ -576,8 +540,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
            par.AddAt(rmax[i], 3+3*i+2);
        }
        return kTRUE;
-    }
-    if (class_type==TGeoEltu::Class()) {
+    } // end if
+    if (classType==TGeoEltu::Class()) {
        shapeType = "ELTU";
        npar = 3;
        par.Set(npar);
@@ -586,8 +550,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(eltu->GetB(),1);
        par.AddAt(eltu->GetDz(),2);
        return kTRUE;
-    }
-    if (class_type==TGeoHype::Class()) {
+    } // end if
+    if (classType==TGeoHype::Class()) {
        shapeType = "HYPE";
        npar = 5;
        par.Set(npar);
@@ -598,8 +562,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(hype->GetStIn(),3);
        par.AddAt(hype->GetStOut(),4);
        return kTRUE;
-    }
-    if (class_type==TGeoGtra::Class()) {
+    } // end if
+    if (classType==TGeoGtra::Class()) {
        shapeType = "GTRA";
        npar = 12;
        par.Set(npar);
@@ -618,8 +582,8 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(TMath::Tan(trap->GetAlpha2()*TMath::DegToRad()),10);
        par.AddAt(trap->GetTwistAngle(),11);
        return kTRUE;
-    }
-    if (class_type==TGeoCtub::Class()) {
+    } // end if
+    if (classType==TGeoCtub::Class()) {
        shapeType = "CTUB";
        npar = 11;
        par.Set(npar);
@@ -638,14 +602,15 @@ Bool_t AliITSInitGeometry::GetShape(const TString &volumePath,
        par.AddAt(tx[1],9);
        par.AddAt(tx[2],10);
        return kTRUE;
-    }
+    } // end if
     Error("GetShape","Getting shape parameters for shape %s not implemented",
          shape->ClassName());
+    shapeType = "Unknown";
     return kFALSE;
 }
 //______________________________________________________________________
-void AliITSInitGeometry::DecodeDetector(Int_t &mod,Int_t layer,Int_t cpn0,
-                                        Int_t cpn1,Int_t cpn2){
+void AliITSInitGeometry::DecodeDetector(
+    Int_t &mod,Int_t layer,Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
     // decode geometry into detector module number. There are two decoding
     // Scheams. Old which does not follow the ALICE coordinate system
     // requirements, and New which dose.
@@ -659,87 +624,22 @@ void AliITSInitGeometry::DecodeDetector(Int_t &mod,Int_t layer,Int_t cpn0,
     //                   of copy numbers.
     // Return:
     //    none.
-    const Int_t detPerLadderSPD[2]={2,4};
-    const Int_t detPerLadder[6]={4,4,6,8,22,25};
-    const Int_t ladPerLayer[6]={20,40,14,22,34,38};
-    Int_t lay=-1,lad=-1,det=-1,i;
-
-    if(fDecode){ // New decoding scheam
-        switch (layer){
-        case 1:{
-            lay = layer;
-            det = 5-cpn2;
-            if(cpn0==4&&cpn1==1) lad=1;
-            else if(cpn0==4&&cpn1==2) lad=20;
-            else if(cpn0<4){
-                lad = 8-cpn1-detPerLadderSPD[layer-1]*(cpn0-1);
-            }else{ // cpn0>4
-                lad = 28-cpn1-detPerLadderSPD[layer-1]*(cpn0-1);
-            } // end if
-        } break;
-        case 2:{
-            lay = layer;
-            det = 5-cpn2;
-            if(cpn0==4&&cpn1==1) lad=1;
-            else if(cpn0<4){
-                lad = 14-cpn1-detPerLadderSPD[layer-1]*(cpn0-1);
-            }else{ // cpn0>4
-                lad = 54-cpn1-detPerLadderSPD[layer-1]*(cpn0-1);
-            } // end if
-        } break;
-        case 3:{
-            lay = layer;
-            if(cpn0<5) lad = 5-cpn0;
-            else lad = 19-cpn0;
-            det = 7-cpn1;
-        } break;
-        case 4:{
-            lay = layer;
-            if(cpn0<7) lad = 7-cpn0;
-            else lad = 29-cpn0;
-            det = 9-cpn1;
-        } break;
-        case 5:{
-            lay = layer;
-            if(cpn0<10) lad = 10-cpn0;
-            else lad = 44-cpn0;
-            det = 23-cpn1;
-        } break;
-        case 6:{
-            lay = layer;
-            if(cpn0<9) lad = 9-cpn0;
-            else lad = 47-cpn0;
-            det = 26-cpn1;
-        } break;
-        } // end switch
-        mod = 0;
-        for(i=0;i<layer-1;i++) mod += ladPerLayer[i]*detPerLadder[i];
-        mod += detPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
-        return;
-    } // end if
-    // Old decoding scheam
-    switch(layer){
-    case 1: case 2:{
-        lay = layer;
-        lad = cpn1+detPerLadderSPD[layer-1]*(cpn0-1);
-        det = cpn2;
-        }break;
-    case 3: case 4:{
-        lay = layer;
-        lad = cpn0;
-        det = cpn1;
-        }break;
-    case 5: case 6:{
-        lay = layer;
-        lad = cpn0;
-        det = cpn1;
-        }break;
+
+    // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
+    // like them but I see not better way for the moment.
+    switch (fMajorVersion){
+    case kvDefault:{
+        Error("DecodeDetector","Major version = kvDefault, not supported");
+    }break;
+    case kv11:{
+        return DecodeDetectorv11(mod,layer,cpn0,cpn1,cpn2);
+    }break;
     default:{
-        }break;
+        Error("DecodeDetector","Major version = %d, not supported",
+              (Int_t)fMajorVersion);
+        return;
+    }break;
     } // end switch
-    mod = 0;
-    for(i=0;i<layer-1;i++) mod += ladPerLayer[i]*detPerLadder[i];
-    mod += detPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
     return;
 }
 //______________________________________________________________________
@@ -757,100 +657,27 @@ void AliITSInitGeometry::RecodeDetector(Int_t mod,Int_t &cpn0,
     //    Int_t cpn2     the highest copy number
     // Return:
     //    none.
-    const Int_t itsGeomTreeCopys[6][3]= {{10, 2, 4},// lay=1
-                                         {10, 4, 4},// lay=2
-                                         {14, 6, 1},// lay=3
-                                         {22, 8, 1},// lay=4
-                                         {34,22, 1},// lay=5
-                                         {38,25, 1}};//lay=6
-    const Int_t detPerLadderSPD[2]={2,4};
-    //    const Int_t detPerLadder[6]={4,4,6,8,22,25};
-    //    const Int_t ladPerLayer[6]={20,40,14,22,34,38};
-    Int_t lay,lad,det;
 
-    cpn0 = cpn1 = cpn2 = 0;
-    DecodeDetectorLayers(mod,lay,lad,det);
-    if(fDecode){ // New decoding scheam
-        switch (lay){
-        case 1:{
-            cpn2 = 5-det;     // Detector 1-4
-            cpn1 = 1+(lad-1)%detPerLadderSPD[lay-1];
-            cpn0 = 5-(lad+detPerLadderSPD[lay-1])/detPerLadderSPD[lay-1];
-            if(mod>27) cpn0 = 15-(lad+detPerLadderSPD[lay-1])/
-                          detPerLadderSPD[lay-1];
-        } break;
-        case 2:{
-            cpn2 = 5-det;     // Detector 1-4
-            cpn1 = 4-(lad+2)%detPerLadderSPD[lay-1];
-            cpn0 = 1+(14-cpn1-lad)/detPerLadderSPD[lay-1];
-            if(mod>131) cpn0 = 1+(54-lad-cpn1)/detPerLadderSPD[lay-1];
-        } break;
-        case 3:{
-            cpn2 = 1;
-            if(lad<5) cpn0 = 5-lad;
-            else cpn0 = 19-lad;
-            cpn1 = 7-det;
-        } break;
-        case 4:{
-            cpn2 = 1;
-            if(lad<7) cpn0 = 7-lad;
-            else cpn0 = 29-lad;
-            cpn1 = 9-det;
-        } break;
-        case 5:{
-            cpn2 = 1;
-            if(lad<10) cpn0 = 10-lad;
-            else cpn0 = 44-lad;
-            cpn1 = 23-det;
-        } break;
-        case 6:{
-            cpn2 = 1;
-            if(lad<9) cpn0 = 9-lad;
-            else cpn0 = 47-lad;
-            cpn1 = 26-det;
-        } break;
-        default:{
-            Error("RecodeDetector","New: mod=%d lay=%d not 1-6.");
-            return;
-        } break;
-        } // end switch
-        if(cpn0<1||cpn1<1||cpn2<1||
-           cpn0>itsGeomTreeCopys[lay-1][0]||
-           cpn1>itsGeomTreeCopys[lay-1][1]||
-           cpn2>itsGeomTreeCopys[lay-1][2])
-            Error("RecodeDetector",
-                  "cpn0=%d cpn1=%d cpn2=%d mod=%d lay=%d lad=%d det=%d",
-                  cpn0,cpn1,cpn2,mod,lay,lad,det);
+    // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
+    // like them but I see not better way for the moment.
+    switch (fMajorVersion){
+    case kvDefault:{
+        Error("RecodeDetector","Major version = kvDefault, not supported");
         return;
-    } // end if
-    // Old encoding
-    switch (lay){
-    case 1: case 2:{
-        cpn2 = det;     // Detector 1-4
-        cpn0 = (lad+detPerLadderSPD[lay-1]-1)/detPerLadderSPD[lay-1];
-        cpn1 = (lad+detPerLadderSPD[lay-1]-1)%detPerLadderSPD[lay-1] + 1;
-    } break;
-    case 3: case 4: case 5 : case 6:{
-        cpn2 = 1;
-        cpn1 = det;
-        cpn0 = lad;
-    } break;
+    }
+    case kv11:{
+        return RecodeDetectorv11(mod,cpn0,cpn1,cpn2);
+    }break;
     default:{
-        Error("RecodeDetector","Old: mod=%d lay=%d not 1-6.");
+        Error("RecodeDetector","Major version = %d, not supported",
+              (Int_t)fMajorVersion);
         return;
-    } break;
+    }break;
     } // end switch
-    if(cpn0<1||cpn1<1||cpn2<1||
-       cpn0>itsGeomTreeCopys[lay-1][0]||
-       cpn1>itsGeomTreeCopys[lay-1][1]||
-       cpn2>itsGeomTreeCopys[lay-1][2])
-        Error("RecodeDetector",
-              "cpn0=%d cpn1=%d cpn2=%d mod=%d lay=%d lad=%d det=%d",
-              cpn0,cpn1,cpn2,mod,lay,lad,det);
     return;
 }
 //______________________________________________________________________
-void AliITSInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &lay,
+void AliITSInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &layer,
                                               Int_t &lad,Int_t &det){
     // decode geometry into detector module number. There are two decoding
     // Scheams. Old which does not follow the ALICE coordinate system
@@ -867,33 +694,188 @@ void AliITSInitGeometry::DecodeDetectorLayers(Int_t mod,Int_t &lay,
     //    Int_t det     the dettector number
     // Return:
     //    none.
-  //    const Int_t detPerLadderSPD[2]={2,4};
-    const Int_t detPerLadder[6]={4,4,6,8,22,25};
-    const Int_t ladPerLayer[6]={20,40,14,22,34,38};
-    Int_t mod2;
-
-    det  = 0;
-    lad  = 0;
-    lay  = 0;
-    mod2 = 0;
-    do{
-        mod2 += ladPerLayer[lay]*detPerLadder[lay];
-        lay++;
-    }while(mod2<=mod); // end while
-    if(lay>6||lay<1) Error("DecodeDetectorLayers","0<lay=%d>6",lay);
-    mod2 -= ladPerLayer[lay-1]*detPerLadder[lay-1];
-    do{
-        lad++;
-        mod2 += detPerLadder[lay-1];
-    }while(mod2<=mod); // end while
-    if(lad>ladPerLayer[lay-1]||lad<1) Error("DecodeDetectorLayera",
-            "lad=%d>ladPerLayer[lay-1=%d]=%d mod=%d mod2=%d",lad,lay-1,
-                                            ladPerLayer[lay-1],mod,mod2);
-    mod2 -= detPerLadder[lay-1];
-    det = mod-mod2+1;
-    if(det>detPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
-           "det=%d>detPerLayer[lay-1=%d]=%d mod=%d mod2=%d lad=%d",det,
-                                  lay-1,detPerLadder[lay-1],mod,mod2,lad);
+
+    // This is a FIXED switch yard function. I (Bjorn Nilsen) Don't 
+    // like them but I see not better way for the moment.
+    switch (fMajorVersion) {
+    case kvDefault:{
+        Error("DecodeDetectorLayers",
+              "Major version = kvDefault, not supported");
+        return;
+    }break;
+    case kv11:{
+        return DecodeDetectorLayersv11(mod,layer,lad,det);
+    }break;
+    default:{
+        Error("DecodeDetectorLayers","Major version = %d, not supported",
+              (Int_t)fMajorVersion);
+        return;
+    }break;
+    } // end switch
     return;
 }
 
+//______________________________________________________________________
+void AliITSInitGeometry::DecodeDetectorv11(Int_t &mod,Int_t layer,
+                                 Int_t cpn0,Int_t cpn1,Int_t cpn2) const {
+    // decode geometry into detector module number
+    // Inputs:
+    //    Int_t layer    The ITS layer
+    //    Int_t cpn0     The lowest copy number
+    //    Int_t cpn1     The middle copy number
+    //    Int_t cpn2     the highest copy number
+    // Output:
+    //    Int_t &mod     The module number assoicated with this set
+    //                   of copy numbers.
+    // Return:
+    //    none.
+  const Int_t kDetPerLadderSPD[2]={2,4};
+  const Int_t kDetPerLadder[6]={4,4,6,8,22,25};
+  const Int_t kLadPerLayer[6]={20,40,14,22,34,38};
+  Int_t lad=-1,det=-1;
+  
+  switch(layer) {
+  case 1: case 2:{
+    lad = cpn1+kDetPerLadderSPD[layer-1]*(cpn0-1);
+    det = cpn2;
+  } break;
+  case 3: case 4:{
+    lad = cpn0+1;
+    det = cpn1+1;
+  } break;
+  case 5: case 6:{
+    lad = cpn0+1;
+    det = cpn1+1;
+  } break;
+  default:{
+  } break;
+  } // end switch
+  mod = 0;
+  for(Int_t i=0;i<layer-1;i++) mod += kLadPerLayer[i]*kDetPerLadder[i];
+  mod += kDetPerLadder[layer-1]*(lad-1)+det-1;// module start at zero.
+  return;
+}
+
+
+//______________________________________________________________________
+void AliITSInitGeometry::RecodeDetectorv11(Int_t mod,Int_t &cpn0,
+                                          Int_t &cpn1,Int_t &cpn2) {
+    // decode geometry into detector module number using the new decoding
+    // Scheme.
+    // Inputs:
+    //    Int_t mod      The module number assoicated with this set
+    //                   of copy numbers.
+    // Output:
+    //    Int_t cpn0     The lowest copy number  (SPD sector or SDD/SSD ladder)
+    //    Int_t cpn1     The middle copy number  (SPD stave or SDD/SSD module)
+    //    Int_t cpn2     the highest copy number (SPD ladder or 1 for SDD/SSD)
+    // Return:
+    //    none.
+    const Int_t kDetPerLadderSPD[2]={2,4};
+    Int_t lay,lad,det;
+
+    DecodeDetectorLayersv11(mod,lay,lad,det);
+    if (lay<3) { // SPD
+        cpn2 = det;     // Detector 1-4
+        cpn0 = (lad+kDetPerLadderSPD[lay-1]-1)/kDetPerLadderSPD[lay-1];
+        cpn1 = (lad+kDetPerLadderSPD[lay-1]-1)%kDetPerLadderSPD[lay-1] + 1;
+    } else { // SDD and SSD
+        cpn2 = 1;
+        cpn1 = det;
+        cpn0 = lad;
+        if (lay<5) { // SDD
+         cpn1--;
+         cpn0--;
+        } else { //SSD
+         cpn1--;
+         cpn0--;
+        } // end if Lay<5/else
+    } // end if lay<3/else
+
+}
+
+
+//______________________________________________________________________
+void AliITSInitGeometry::DecodeDetectorLayersv11(Int_t mod,Int_t &lay,
+                                                Int_t &lad,Int_t &det) {
+
+  // decode module number into detector indices for v11
+  // mod starts from 0
+  // lay, lad, det start from 1
+
+  // Inputs:
+  //    Int_t mod      The module number associated with this set
+  //                   of copy numbers.
+  // Output:
+  //    Int_t lay     The layer number
+  //    Int_t lad     The ladder number
+  //    Int_t det     the dettector number
+
+  const Int_t kDetPerLadder[6] = {4,4,6,8,22,25};
+  const Int_t kLadPerLayer[6]  = {20,40,14,22,34,38};
+  
+  Int_t mod2 = 0;
+  lay  = 0;
+  
+  do {
+    mod2 += kLadPerLayer[lay]*kDetPerLadder[lay];
+    lay++;
+  } while(mod2<=mod); // end while
+  if(lay>6) Error("DecodeDetectorLayers","lay=%d>6",lay);
+
+  mod2 = kLadPerLayer[lay-1]*kDetPerLadder[lay-1] - mod2+mod;
+  lad = mod2/kDetPerLadder[lay-1];
+
+  if(lad>=kLadPerLayer[lay-1]||lad<0) Error("DecodeDetectorLayers",
+                                     "lad=%d not in the correct range",lad);
+  det = (mod2 - lad*kDetPerLadder[lay-1])+1;
+  if(det>kDetPerLadder[lay-1]||det<1) Error("DecodeDetectorLayers",
+                                     "det=%d not in the correct range",det);
+  lad++;
+}
+
+//______________________________________________________________________
+Bool_t AliITSInitGeometry::WriteVersionString(Char_t *str,Int_t length,AliITSVersion_t maj)const{
+    // fills the string str with the major version number
+    // Inputs:
+    //   Char_t *str          The character string to hold the major version number
+    //   Int_t  length        The maximum number of characters which 
+    //                        can be accommodated by this string. 
+    //                        str[length-1] must exist
+    //   AliITSVersion_t maj  The major number
+
+
+    Int_t i = (Int_t)maj;
+    snprintf(str,length-1,"Major Version= %d",i);
+    return kTRUE;
+}
+//______________________________________________________________________
+Bool_t AliITSInitGeometry::ReadVersionString(const Char_t *str,AliITSVersion_t &maj)const{
+    // fills the string str with the major and minor version number
+    // Inputs:
+    //   Char_t *str   The character string to holding the major version number
+    //   Int_t  length The maximum number of characters which can be
+    //                 accommodated by this string. str[length-1] must exist
+    // Outputs:
+    //   AliITSVersion_t maj  The major number
+
+    // Return:
+    //   kTRUE if no errors
+
+  Bool_t retcode=kFALSE;
+  Int_t n=strlen(str);
+  if(n<15) return retcode; // not enough space for numbers
+  Int_t m,i;
+  m = sscanf(str,"Major Version= %2d",&i);
+  maj = kvDefault;
+  if(m>0){
+    retcode = kTRUE;
+    if(i==11){
+      maj = kv11;
+    }
+  }
+  return retcode;
+}
+
+