New geometry from Mario
authorbelikov <iouri.belikov@in2p3.fr>
Thu, 30 Jan 2014 15:11:35 +0000 (16:11 +0100)
committerbelikov <iouri.belikov@in2p3.fr>
Thu, 30 Jan 2014 15:11:35 +0000 (16:11 +0100)
ITS/UPGRADE/AliITSUv1.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSUv1.h [new file with mode: 0644]
ITS/UPGRADE/AliITSUv1Layer.cxx [new file with mode: 0644]
ITS/UPGRADE/AliITSUv1Layer.h [new file with mode: 0644]
ITS/UPGRADE/CMakelibITSUpgradeSim.pkg
ITS/UPGRADE/ITSUpgradeSimLinkDef.h
ITS/UPGRADE/testITSUv1/Config.C [new file with mode: 0644]
ITS/UPGRADE/testITSUv1/CreateITSUv0.C [new file with mode: 0644]
ITS/UPGRADE/testITSUv1/CreateITSUv1.C [new file with mode: 0644]
ITS/UPGRADE/testITSUv1/sim.C [new file with mode: 0644]

diff --git a/ITS/UPGRADE/AliITSUv1.cxx b/ITS/UPGRADE/AliITSUv1.cxx
new file mode 100644 (file)
index 0000000..95bc298
--- /dev/null
@@ -0,0 +1,770 @@
+/**************************************************************************
+ * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+
+/* $Id: AliITSUv1.cxx */
+
+
+//========================================================================
+//
+//        Geometry for the Upgrade of the Inner Tracking System
+//
+// Mario Sitta (sitta@to.infn.it)
+// Chinorat Kobdaj (kobdaj@g.sut.ac.th)
+//
+//========================================================================
+
+
+
+// $Log: AliITSUv1.cxx,v $
+
+#include <TClonesArray.h>
+#include <TGeoGlobalMagField.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
+#include <TGeoPhysicalNode.h>
+#include <TGeoVolume.h>
+#include <TGeoTube.h>
+#include <TGeoXtru.h>
+#include <TLorentzVector.h>
+#include <TString.h>
+#include <TVirtualMC.h>
+
+#include "AliITSU.h"
+#include "AliITSUHit.h"
+#include "AliLog.h"
+#include "AliMC.h"
+#include "AliMagF.h"
+#include "AliRun.h"
+#include "AliTrackReference.h"
+#include "AliITSv11Geometry.h"
+#include "AliITSUv1Layer.h"
+#include "AliITSUv1.h"
+#include "AliITSUGeomTGeo.h"
+#include "AliGeomManager.h"
+using namespace TMath;
+
+
+ClassImp(AliITSUv1)
+
+//______________________________________________________________________
+AliITSUv1::AliITSUv1()
+:  fNWrapVol(0)
+  ,fWrapRMin(0)
+  ,fWrapRMax(0)
+  ,fWrapZSpan(0)
+  ,fLayTurbo(0)
+  ,fLayPhi0(0)
+  ,fLayRadii(0)
+  ,fLayZLength(0)
+  ,fLaddPerLay(0)
+  ,fModPerLadd(0)
+  ,fLadThick(0)
+  ,fLadWidth(0)
+  ,fLadTilt(0)
+  ,fDetThick(0)
+  ,fDetTypeID(0)
+  ,fBuildLevel(0)
+  ,fUpGeom(0)
+  ,fStaveModelIB(kIBModel0)
+  ,fStaveModelOB(kOBModel0)
+{
+  //    Standard default constructor
+  // Inputs:
+  //   none.
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+}
+
+//______________________________________________________________________
+AliITSUv1::AliITSUv1(const char *title,const Int_t nlay)
+  :AliITSU(title,nlay)
+  ,fNWrapVol(0)
+  ,fWrapRMin(0)
+  ,fWrapRMax(0)
+  ,fWrapZSpan(0)
+  ,fLayTurbo(0)
+  ,fLayPhi0(0)
+  ,fLayRadii(0)
+  ,fLayZLength(0)
+  ,fLaddPerLay(0)
+  ,fModPerLadd(0)
+  ,fLadThick(0)
+  ,fLadWidth(0)
+  ,fLadTilt(0)
+  ,fDetThick(0)
+  ,fDetTypeID(0)
+  ,fBuildLevel(0)
+  ,fUpGeom(0)
+  ,fStaveModelIB(kIBModel0)
+  ,fStaveModelOB(kOBModel0)
+{
+  //    Standard constructor for the Upgrade geometry.
+  // Inputs:
+  //   const char * name   Ignored, set to "ITS"
+  //   const char * title  Arbitrary title
+  //   const Int_t nlay    Number of layers
+  //
+  fLayerName = new TString[fNLayers];
+  //
+  for (Int_t j=0; j<fNLayers; j++)
+    fLayerName[j].Form("%s%d",AliITSUGeomTGeo::GetITSSensorPattern(),j); // See AliITSUv1Layer
+  //
+  fLayTurbo   = new Bool_t[fNLayers];
+  fLayPhi0    = new Double_t[fNLayers];
+  fLayRadii   = new Double_t[fNLayers];
+  fLayZLength = new Double_t[fNLayers];
+  fLaddPerLay = new Int_t[fNLayers];
+  fModPerLadd = new Int_t[fNLayers];
+  fLadThick   = new Double_t[fNLayers];
+  fLadWidth   = new Double_t[fNLayers];
+  fLadTilt    = new Double_t[fNLayers];
+  fDetThick   = new Double_t[fNLayers];
+  fDetTypeID  = new UInt_t[fNLayers];
+  fBuildLevel = new Int_t[fNLayers];
+
+
+  fUpGeom = new AliITSUv1Layer*[fNLayers];
+  
+  if (fNLayers > 0) { // if not, we'll Fatal-ize in CreateGeometry
+    for (Int_t j=0; j<fNLayers; j++) {
+      fLayPhi0[j] = 0;
+      fLayRadii[j] = 0.;
+      fLayZLength[j] = 0.;
+      fLaddPerLay[j] = 0;
+      fModPerLadd[j] = 0;
+      fLadWidth[j] = 0.;
+      fDetThick[j] = 0.;
+      fDetTypeID[j] = 0;
+      fBuildLevel[j] = 0;
+      fUpGeom[j] = 0;     
+    }
+  }
+}
+
+//______________________________________________________________________
+AliITSUv1::~AliITSUv1() {
+  //    Standard destructor
+  // Inputs:
+  //   none.
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+  delete [] fLayTurbo;
+  delete [] fLayPhi0;
+  delete [] fLayRadii;
+  delete [] fLayZLength;
+  delete [] fLaddPerLay;
+  delete [] fModPerLadd;
+  delete [] fLadThick;
+  delete [] fLadWidth;
+  delete [] fLadTilt;
+  delete [] fDetThick;
+  delete [] fDetTypeID;
+  delete [] fBuildLevel;
+  delete [] fUpGeom;
+  delete [] fWrapRMin;
+  delete [] fWrapRMax;
+  delete [] fWrapZSpan;
+}
+
+//______________________________________________________________________
+void AliITSUv1::AddAlignableVolumes() const{
+  // Creates entries for alignable volumes associating the symbolic volume
+  // name with the corresponding volume path.
+  // 
+  // Records in the alignable entries the transformation matrices converting
+  // TGeo local coordinates (in the RS of alignable volumes) to the tracking
+  // system
+  // For this, this function has to run before the misalignment because we
+  // are using the ideal positions in the AliITSgeom object.
+  // Inputs:
+  //   none.
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+
+  AliInfo("Add ITS alignable volumes");
+
+  if (!gGeoManager) { AliFatal("TGeoManager doesn't exist !"); return;  }
+  TString pth;
+  //
+  pth = Form("ALIC_1/%s_2",AliITSUGeomTGeo::GetITSVolPattern());
+  // RS: to be checked with MS
+  if( !gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameITS(),pth.Data()) )
+    AliFatal(Form("Unable to set alignable entry ! %s :: %s","ITS",pth.Data()));    
+  //
+  int modNum = 0;
+  //
+  for (int lr=0; lr<fNLayers; lr++) {
+    //
+    pth = Form("ALIC_1/%s_2/%s%d_1",AliITSUGeomTGeo::GetITSVolPattern(),AliITSUGeomTGeo::GetITSLayerPattern(),lr);
+    //printf("SetAlignable: %s %s\n",snm.Data(),pth.Data());
+    gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameLayer(lr),pth.Data());
+    //
+    for (int ld=0; ld<fLaddPerLay[lr]; ld++) {
+      //
+      TString pthL = Form("%s/%s%d_%d",pth.Data(),AliITSUGeomTGeo::GetITSLadderPattern(),lr,ld);
+      //printf("SetAlignable: %s %s\n",snmL.Data(),pthL.Data());
+      gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameLadder(lr,ld),pthL.Data());
+      //
+      for (int md=0; md<fModPerLadd[lr]; md++) {
+       //
+       TString pthM = Form("%s/%s%d_%d",pthL.Data(),AliITSUGeomTGeo::GetITSModulePattern(),lr,md);
+       //
+       // RS: Attention, this is a hack: AliGeomManager cannot accomodate all ITSU modules w/o
+       // conflicts with TPC. For this reason we define the UID of the module to be simply its ID
+       //      int modUID = AliGeomManager::LayerToVolUID(lr+1,modNum++); // here modNum would be module within the layer
+       int modUID = AliITSUGeomTGeo::ModuleVolUID( modNum++ );
+       // 
+       gGeoManager->SetAlignableEntry(AliITSUGeomTGeo::ComposeSymNameModule(lr,ld,md),pthM.Data(),modUID);
+       //
+      }
+    }
+  }
+  //
+}
+
+//______________________________________________________________________
+void AliITSUv1::SetNWrapVolumes(Int_t n)
+{
+  // book arrays for wrapper volumes
+  if (fNWrapVol) AliFatal(Form("%d wrapper volumes already defined",fNWrapVol));
+  if (n<1) return;
+  fNWrapVol = n;
+  fWrapRMin = new Double_t[fNWrapVol];
+  fWrapRMax = new Double_t[fNWrapVol];
+  fWrapZSpan= new Double_t[fNWrapVol];
+  for (int i=fNWrapVol;i--;) fWrapRMin[i]=fWrapRMax[i]=fWrapZSpan[i]=-1;
+  //
+}
+
+//______________________________________________________________________
+void AliITSUv1::DefineWrapVolume(Int_t id, Double_t rmin,Double_t rmax, Double_t zspan)
+{
+  // set parameters of id-th wrapper volume
+  if (id>=fNWrapVol||id<0) AliFatal(Form("id=%d of wrapper volume is not in 0-%d range",id,fNWrapVol-1));
+  fWrapRMin[id] = rmin;
+  fWrapRMax[id] = rmax;
+  fWrapZSpan[id] = zspan;
+}
+
+//______________________________________________________________________
+void AliITSUv1::CreateGeometry() {
+
+  // Create the geometry and insert it in the mother volume ITSV
+  TGeoManager *geoManager = gGeoManager;
+
+  TGeoVolume *vALIC = geoManager->GetVolume("ALIC");
+
+  new TGeoVolumeAssembly(AliITSUGeomTGeo::GetITSVolPattern());
+  TGeoVolume *vITSV = geoManager->GetVolume(AliITSUGeomTGeo::GetITSVolPattern());
+  vITSV->SetUniqueID(AliITSUGeomTGeo::GetUIDShift()); // store modID -> midUUID bitshift
+  vALIC->AddNode(vITSV, 2, 0);  // Copy number is 2 to cheat AliGeoManager::CheckSymNamesLUT
+  //
+  const Int_t kLength=100;
+  Char_t vstrng[kLength] = "xxxRS"; //?
+  vITSV->SetTitle(vstrng);
+  //
+  // Check that we have all needed parameters
+  if (fNLayers <= 0) AliFatal(Form("Wrong number of layers (%d)",fNLayers));
+  //
+  for (Int_t j=0; j<fNLayers; j++) {
+    if (fLayRadii[j] <= 0)                 AliFatal(Form("Wrong layer radius for layer %d (%f)",j,fLayRadii[j]));
+    if (fLayZLength[j] <= 0)               AliFatal(Form("Wrong layer length for layer %d (%f)",j,fLayZLength[j]));
+    if (fLaddPerLay[j] <= 0)               AliFatal(Form("Wrong number of ladders for layer %d (%d)",j,fLaddPerLay[j]));
+    if (fModPerLadd[j] <= 0)               AliFatal(Form("Wrong number of modules for layer %d (%d)",j,fModPerLadd[j]));
+    if (fLadThick[j] < 0)                  AliFatal(Form("Wrong ladder thickness for layer %d (%f)",j,fLadThick[j]));
+    if (fLayTurbo[j] && fLadWidth[j] <= 0) AliFatal(Form("Wrong ladder width for layer %d (%f)",j,fLadWidth[j]));
+    if (fDetThick[j] < 0)                  AliFatal(Form("Wrong module thickness for layer %d (%f)",j,fDetThick[j]));
+    //
+    if (j > 0) {
+      if (fLayRadii[j]<=fLayRadii[j-1])    AliFatal(Form("Layer %d radius (%f) is smaller than layer %d radius (%f)",
+                                                        j,fLayRadii[j],j-1,fLayRadii[j-1]));
+    } // if (j > 0)
+
+    if (fLadThick[j] == 0) AliInfo(Form("Ladder thickness for layer %d not set, using default",j));
+    if (fDetThick[j] == 0) AliInfo(Form("Module thickness for layer %d not set, using default",j));
+
+  } // for (Int_t j=0; j<fNLayers; j++)
+
+  // Create the wrapper volumes
+  TGeoVolume **wrapVols = 0;
+  if (fNWrapVol) {
+    wrapVols = new TGeoVolume*[fNWrapVol];
+    for (int id=0;id<fNWrapVol;id++) {
+      wrapVols[id] = CreateWrapperVolume(id);
+      vITSV->AddNode(wrapVols[id], 1, 0);
+    }
+  }
+  //
+  // Now create the actual geometry
+  for (Int_t j=0; j<fNLayers; j++) {
+    TGeoVolume* dest = vITSV;
+    //
+    if (fLayTurbo[j]) {
+      fUpGeom[j] = new AliITSUv1Layer(j,kTRUE,kFALSE);
+      fUpGeom[j]->SetLadderWidth(fLadWidth[j]);
+      fUpGeom[j]->SetLadderTilt(fLadTilt[j]);
+    }
+    else fUpGeom[j] = new AliITSUv1Layer(j,kFALSE);
+    //
+    fUpGeom[j]->SetPhi0(fLayPhi0[j]);
+    fUpGeom[j]->SetRadius(fLayRadii[j]);
+    fUpGeom[j]->SetZLength(fLayZLength[j]);
+    fUpGeom[j]->SetNLadders(fLaddPerLay[j]);
+    fUpGeom[j]->SetNModules(fModPerLadd[j]);
+    fUpGeom[j]->SetDetType(fDetTypeID[j]);
+    fUpGeom[j]->SetBuildLevel(fBuildLevel[j]);
+    if (j < 3)
+      fUpGeom[j]->SetStaveModel(fStaveModelIB);
+    else
+      fUpGeom[j]->SetStaveModel(fStaveModelOB);
+    AliDebug(1,Form("fBuildLevel: %d\n",fBuildLevel[j]));
+    //
+    if (fLadThick[j] != 0) fUpGeom[j]->SetLadderThick(fLadThick[j]);
+    if (fDetThick[j] != 0) fUpGeom[j]->SetSensorThick(fDetThick[j]);
+    //
+    for (int iw=0;iw<fNWrapVol;iw++) {
+      if (fLayRadii[j]>fWrapRMin[iw] && fLayRadii[j]<fWrapRMax[iw]) {
+       AliInfo(Form("Will embed layer %d in wrapper volume %d",j,iw));
+       if (fLayZLength[j]>=fWrapZSpan[iw]) AliFatal(Form("ZSpan %.3f of wrapper volume %d is less than ZSpan %.3f of layer %d",
+                                                         fWrapZSpan[iw],iw,fLayZLength[j],j));
+       dest = wrapVols[iw];
+       break;
+      }
+    }
+    fUpGeom[j]->CreateLayer(dest);
+  }
+  delete wrapVols; // delete pointer only, not the volumes
+  //
+}
+
+//______________________________________________________________________
+void AliITSUv1::CreateMaterials() {
+  // Create ITS materials
+  //     This function defines the default materials used in the Geant
+  // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
+  // AliITSv11Hybrid.
+  // In general it is automatically replaced by
+  // the CreateMaterials routine defined in AliITSv?. Should the function
+  // CreateMaterials not exist for the geometry version you are using this
+  // one is used. See the definition found in AliITSv5 or the other routine
+  // for a complete definition.
+  // Inputs:
+  //   none.
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+
+  Int_t   ifield = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
+  Float_t fieldm = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
+
+  Float_t tmaxfd = 0.1; // 1.0; // Degree
+  Float_t stemax = 1.0; // cm
+  Float_t deemax = 0.1; // 30.0; // Fraction of particle's energy 0<deemax<=1
+  Float_t epsil  = 1.0E-4; // 1.0; // cm
+  Float_t stmin  = 0.0; // cm "Default value used"
+
+  Float_t tmaxfdSi = 0.1; // .10000E+01; // Degree
+  Float_t stemaxSi = 0.0075; //  .10000E+01; // cm
+  Float_t deemaxSi = 0.1; // 0.30000E-02; // Fraction of particle's energy 0<deemax<=1
+  Float_t epsilSi  = 1.0E-4;// .10000E+01;
+  Float_t stminSi  = 0.0; // cm "Default value used"
+
+  Float_t tmaxfdAir = 0.1; // .10000E+01; // Degree
+  Float_t stemaxAir = .10000E+01; // cm
+  Float_t deemaxAir = 0.1; // 0.30000E-02; // Fraction of particle's energy 0<deemax<=1
+  Float_t epsilAir  = 1.0E-4;// .10000E+01;
+  Float_t stminAir  = 0.0; // cm "Default value used"
+
+  // AIR
+  Float_t aAir[4]={12.0107,14.0067,15.9994,39.948};
+  Float_t zAir[4]={6.,7.,8.,18.};
+  Float_t wAir[4]={0.000124,0.755267,0.231781,0.012827};
+  Float_t dAir = 1.20479E-3;
+
+  // Water
+  Float_t aWater[2]={1.00794,15.9994};
+  Float_t zWater[2]={1.,8.};
+  Float_t wWater[2]={0.111894,0.888106};
+  Float_t dWater   = 1.0;
+
+
+  // Kapton
+  Float_t aKapton[4]={1.00794,12.0107, 14.010,15.9994};
+  Float_t zKapton[4]={1.,6.,7.,8.};
+  Float_t wKapton[4]={0.026362,0.69113,0.07327,0.209235};
+  Float_t dKapton   = 1.42;
+  AliMixture(1,"AIR$",aAir,zAir,dAir,4,wAir);
+  AliMedium(1, "AIR$",1,0,ifield,fieldm,tmaxfdAir,stemaxAir,deemaxAir,epsilAir,stminAir);
+
+  AliMixture(2,"WATER$",aWater,zWater,dWater,2,wWater);
+  AliMedium(2, "WATER$",2,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+  AliMaterial(3,"SI$",0.28086E+02,0.14000E+02,0.23300E+01,0.93600E+01,0.99900E+03);
+  AliMedium(3,  "SI$",3,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+  AliMaterial(4,"BERILLIUM$",9.01, 4., 1.848, 35.3, 36.7);// From AliPIPEv3
+  AliMedium(4,  "BERILLIUM$",4,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+  AliMaterial(5,"COPPER$",0.63546E+02,0.29000E+02,0.89600E+01,0.14300E+01,0.99900E+03);
+  AliMedium(5,  "COPPER$",5,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+    
+  // needed for STAVE , Carbon, kapton, Epoxy, flexcable
+
+  //AliMaterial(6,"CARBON$",12.0107,6,2.210,999,999);
+  AliMaterial(6,"CARBON$",12.0107,6,2.210/1.3,999,999);
+  AliMedium(6,  "CARBON$",6,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+  AliMixture(7,"KAPTON(POLYCH2)$", aKapton, zKapton, dKapton, 4, wKapton);
+  AliMedium(7, "KAPTON(POLYCH2)$",7,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+
+  // values below modified as compared to source AliITSv11 !
+
+  //AliMaterial(7,"GLUE$",0.12011E+02,0.60000E+01,0.1930E+01/2.015,999,999); // original
+  AliMaterial(15,"GLUE$",12.011,6,1.93/2.015,999,999);  // conform with ATLAS, Corrado, Stefan
+  AliMedium(15,  "GLUE$",15,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+  // All types of carbon
+  // Unidirectional prepreg
+ AliMaterial(8,"K13D2U2k$",12.0107,6,1.643,999,999);
+ AliMedium(8,  "K13D2U2k$",8,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+ //Impregnated thread
+ AliMaterial(9,"M60J3K$",12.0107,6,2.21,999,999);
+ AliMedium(9,  "M60J3K$",9,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+ //Impregnated thread
+ AliMaterial(10,"M55J6K$",12.0107,6,1.63,999,999);
+ AliMedium(10,  "M55J6K$",10,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+ // Fabric(0/90)
+ AliMaterial(11,"T300$",12.0107,6,1.725,999,999);
+ AliMedium(11,  "T300$",11,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+ //AMEC Thermasol
+ AliMaterial(12,"FGS003$",12.0107,6,1.6,999,999);
+ AliMedium(12,  "FGS003$",12,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+ // Carbon fleece
+ AliMaterial(13,"CarbonFleece$",12.0107,6,0.4,999,999);
+ AliMedium(13,  "CarbonFleece$",13,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,epsilSi,stminSi);
+
+  // Flex cable
+  Float_t aFCm[5]={12.0107,1.00794,14.0067,15.9994,26.981538};
+  Float_t zFCm[5]={6.,1.,7.,8.,13.};
+  Float_t wFCm[5]={0.520088819984,0.01983871336,0.0551367996,0.157399667056, 0.247536};
+  //Float_t dFCm = 1.6087;  // original
+  //Float_t dFCm = 2.55;   // conform with STAR
+   Float_t dFCm = 2.595;   // conform with Corrado
+
+  AliMixture(14,"FLEXCABLE$",aFCm,zFCm,dFCm,5,wFCm);
+  AliMedium(14, "FLEXCABLE$",14,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+  AliMaterial(16,"ALUMINUM$",0.26982E+02,0.13000E+02,0.26989E+01,0.89000E+01,0.99900E+03);
+  AliMedium(16,"ALUMINUM$",16,0,ifield,fieldm,tmaxfd,stemax,deemax,epsil,stmin);
+
+}
+
+//______________________________________________________________________
+void AliITSUv1::DefineLayer(const Int_t nlay, const double phi0, const Double_t r,
+                           const Double_t zlen, const Int_t nladd,
+                           const Int_t nmod, const Double_t lthick,
+                           const Double_t dthick, const UInt_t dettypeID,
+                           const Int_t buildLevel)
+{
+  //     Sets the layer parameters
+  // Inputs:
+  //          nlay    layer number
+  //          phi0    layer phi0
+  //          r       layer radius
+  //          zlen    layer length
+  //          nladd   number of ladders
+  //          nmod    number of modules per ladder
+  //          lthick  ladder thickness (if omitted, defaults to 0)
+  //          dthick  detector thickness (if omitted, defaults to 0)
+  //          buildLevel (if 0, all geometry is build, used for material budget studies)
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+  
+  if (nlay >= fNLayers || nlay < 0) {
+    AliError(Form("Wrong layer number (%d)",nlay));
+    return;
+  }
+  
+  fLayTurbo[nlay] = kFALSE;
+  fLayPhi0[nlay] = phi0;
+  fLayRadii[nlay] = r;
+  fLayZLength[nlay] = zlen;
+  fLaddPerLay[nlay] = nladd;
+  fModPerLadd[nlay] = nmod;
+  fLadThick[nlay] = lthick;
+  fDetThick[nlay] = dthick;
+  fDetTypeID[nlay] = dettypeID;
+  fBuildLevel[nlay] = buildLevel;
+    
+}
+
+//______________________________________________________________________
+void AliITSUv1::DefineLayerTurbo(Int_t nlay, Double_t phi0, Double_t r, Double_t zlen, Int_t nladd,
+                                Int_t nmod, Double_t width, Double_t tilt,
+                                Double_t lthick,Double_t dthick,
+                                UInt_t dettypeID, Int_t buildLevel)
+{
+  //     Sets the layer parameters for a "turbo" layer
+  //     (i.e. a layer whose ladders overlap in phi)
+  // Inputs:
+  //          nlay    layer number
+  //          phi0    phi of 1st ladder
+  //          r       layer radius
+  //          zlen    layer length
+  //          nladd   number of ladders
+  //          nmod    number of modules per ladder
+  //          width   ladder width
+  //          tilt    layer tilt angle (degrees)
+  //          lthick  ladder thickness (if omitted, defaults to 0)
+  //          dthick  detector thickness (if omitted, defaults to 0)
+  //          dettypeID  ??
+  //          buildLevel (if 0, all geometry is build, used for material budget studies)
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+
+  if (nlay >= fNLayers || nlay < 0) {
+    AliError(Form("Wrong layer number (%d)",nlay));
+    return;
+  }
+
+  fLayTurbo[nlay] = kTRUE;
+  fLayPhi0[nlay] = phi0;
+  fLayRadii[nlay] = r;
+  fLayZLength[nlay] = zlen;
+  fLaddPerLay[nlay] = nladd;
+  fModPerLadd[nlay] = nmod;
+  fLadThick[nlay] = lthick;
+  fLadWidth[nlay] = width;
+  fLadTilt[nlay] = tilt;
+  fDetThick[nlay] = dthick;
+  fDetTypeID[nlay] = dettypeID;
+  fBuildLevel[nlay] = buildLevel;
+
+}
+
+//______________________________________________________________________
+void AliITSUv1::GetLayerParameters(Int_t nlay, Double_t &phi0,
+                                  Double_t &r, Double_t &zlen,
+                                  Int_t &nladd, Int_t &nmod,
+                                  Double_t &width, Double_t &tilt,
+                                  Double_t &lthick, Double_t &dthick,
+                                  UInt_t &dettype) const
+{
+  //     Gets the layer parameters
+  // Inputs:
+  //          nlay    layer number
+  // Outputs:
+  //          phi0    phi of 1st ladder
+  //          r       layer radius
+  //          zlen    layer length
+  //          nladd   number of ladders
+  //          nmod    number of modules per ladder
+  //          width   ladder width
+  //          tilt    ladder tilt angle
+  //          lthick  ladder thickness
+  //          dthick  detector thickness
+  //          dettype detector type
+  // Return:
+  //   none.
+
+  if (nlay >= fNLayers || nlay < 0) {
+    AliError(Form("Wrong layer number (%d)",nlay));
+    return;
+  }
+  
+  phi0   = fLayPhi0[nlay];
+  r      = fLayRadii[nlay];
+  zlen   = fLayZLength[nlay];
+  nladd  = fLaddPerLay[nlay];
+  nmod   = fModPerLadd[nlay];
+  width  = fLadWidth[nlay];
+  tilt   = fLadTilt[nlay];
+  lthick = fLadThick[nlay];
+  dthick = fDetThick[nlay];
+  dettype= fDetTypeID[nlay];
+}
+
+//______________________________________________________________________
+TGeoVolume* AliITSUv1::CreateWrapperVolume(Int_t id)
+{
+  //     Creates an air-filled wrapper cylindrical volume 
+  // Inputs:
+  //          volume id
+  // Outputs:
+  //          the wrapper volume
+
+  if (fWrapRMin[id]<0 || fWrapRMax[id]<0 || fWrapZSpan[id]<0) AliFatal(Form("Wrapper volume %d was requested but not defined",id));
+  // Now create the actual shape and volume
+  //
+  TGeoTube *tube = new TGeoTube(fWrapRMin[id], fWrapRMax[id], fWrapZSpan[id]/2.);
+
+  TGeoMedium *medAir = gGeoManager->GetMedium("ITS_AIR$");
+
+  char volnam[30];
+  snprintf(volnam, 29, "%s%d", AliITSUGeomTGeo::GetITSWrapVolPattern(),id);
+
+  TGeoVolume *wrapper = new TGeoVolume(volnam, tube, medAir);
+
+  return wrapper;
+}
+
+//______________________________________________________________________
+void AliITSUv1::Init()
+{
+  //     Initialise the ITS after it has been created.
+  UpdateInternalGeometry();
+  AliITSU::Init();
+  //  
+}
+
+//______________________________________________________________________
+Bool_t AliITSUv1::IsLayerTurbo(Int_t nlay)
+{
+  //     Returns true if the layer is a "turbo" layer
+  if ( nlay < 0 || nlay > fNLayers ) {
+    AliError(Form("Wrong layer number %d",nlay));
+    return kFALSE;
+  } 
+  else return fUpGeom[nlay]->IsTurbo();
+}
+
+//______________________________________________________________________
+void AliITSUv1::SetDefaults()
+{
+  // sets the default segmentation, response, digit and raw cluster classes
+}
+
+//______________________________________________________________________
+void AliITSUv1::StepManager()
+{
+  //    Called for every step in the ITS, then calles the AliITSUHit class
+  // creator with the information to be recoreded about that hit.
+  //     The value of the macro ALIITSPRINTGEOM if set to 1 will allow the
+  // printing of information to a file which can be used to create a .det
+  // file read in by the routine CreateGeometry(). If set to 0 or any other
+  // value except 1, the default behavior, then no such file is created nor
+  // it the extra variables and the like used in the printing allocated.
+  // Inputs:
+  //   none.
+  // Outputs:
+  //   none.
+  // Return:
+  //   none.
+  if(!(this->IsActive())) return;
+  if(!(gMC->TrackCharge())) return;
+  //
+  Int_t copy, lay = 0;
+  Int_t id = gMC->CurrentVolID(copy);
+
+  Bool_t notSens = kFALSE;
+  while ((lay<fNLayers)  && (notSens = (id!=fIdSens[lay]))) ++lay;
+  //printf("R: %.1f | Lay: %d  NotSens: %d\n",positionRS.Pt(), lay, notSens);
+          
+  if (notSens) return;
+
+  if(gMC->IsTrackExiting()) {
+    AddTrackReference(gAlice->GetMCApp()->GetCurrentTrackNumber(), AliTrackReference::kITS);
+  } // if Outer ITS mother Volume
+
+  static TLorentzVector position, momentum; // Saves on calls to construtors
+  static AliITSUHit hit;// Saves on calls to constructors
+
+  TClonesArray &lhits = *(Hits());
+  Int_t   cpn0, cpn1, mod, status = 0;
+  //
+  // Track status
+  if(gMC->IsTrackInside())      status +=  1;
+  if(gMC->IsTrackEntering())    status +=  2;
+  if(gMC->IsTrackExiting())     status +=  4;
+  if(gMC->IsTrackOut())         status +=  8;
+  if(gMC->IsTrackDisappeared()) status += 16;
+  if(gMC->IsTrackStop())        status += 32;
+  if(gMC->IsTrackAlive())       status += 64;
+
+  //
+  // retrieve the indices with the volume path
+  //
+  if (lay < 0 || lay >= fNLayers) {
+    AliError(Form("Invalid value: lay=%d. Not an ITS sensitive volume",lay));
+    return; // not an ITS sensitive volume.
+  } else {
+    copy = 1;
+    gMC->CurrentVolOffID(1,cpn1);
+    gMC->CurrentVolOffID(2,cpn0);
+  } //
+
+  mod = fGeomTGeo->GetModuleIndex(lay,cpn0,cpn1);
+  //RS2DEL  fInitGeom.DecodeDetector(mod,lay+1,cpn0,cpn1,copy);
+  //
+  // Fill hit structure.
+  //
+  hit.SetModule(mod);
+  hit.SetTrack(gAlice->GetMCApp()->GetCurrentTrackNumber());
+  gMC->TrackPosition(position);
+  gMC->TrackMomentum(momentum);
+  hit.SetPosition(position);
+  hit.SetTime(gMC->TrackTime());
+  hit.SetMomentum(momentum);
+  hit.SetStatus(status);
+  hit.SetEdep(gMC->Edep());
+  hit.SetShunt(GetIshunt());
+  if(gMC->IsTrackEntering()){
+    hit.SetStartPosition(position);
+    hit.SetStartTime(gMC->TrackTime());
+    hit.SetStartStatus(status);
+    return; // don't save entering hit.
+  } // end if IsEntering
+    // Fill hit structure with this new hit.
+    //Info("StepManager","Calling Copy Constructor");
+  new(lhits[fNhits++]) AliITSUHit(hit); // Use Copy Construtor.
+  // Save old position... for next hit.
+  hit.SetStartPosition(position);
+  hit.SetStartTime(gMC->TrackTime());
+  hit.SetStartStatus(status);
+
+  return;
+}
+
+//______________________________________________________________________
+void AliITSUv1::SetLayerDetTypeID(Int_t lr, UInt_t id)
+{
+  // set det type
+  if (!fDetTypeID || fNLayers<=lr) AliFatal(Form("Number of layers %d, %d is manipulated",fNLayers,lr));
+  fDetTypeID[lr] = id;
+}
+
+//______________________________________________________________________
+Int_t AliITSUv1::GetLayerDetTypeID(Int_t lr)
+{
+  // set det type
+  if (!fDetTypeID || fNLayers<=lr) AliFatal(Form("Number of layers %d, %d is manipulated",fNLayers,lr));
+  return fDetTypeID[lr];
+}
diff --git a/ITS/UPGRADE/AliITSUv1.h b/ITS/UPGRADE/AliITSUv1.h
new file mode 100644 (file)
index 0000000..40336b2
--- /dev/null
@@ -0,0 +1,105 @@
+#ifndef ALIITSUV1_H
+#define ALIITSUV1_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+//========================================================================
+//
+//        Geometry for the Upgrade of the Inner Tracking System
+//
+// Mario Sitta (sitta@to.infn.it)
+//
+//========================================================================
+
+
+// $Id: AliITSUv1.h 
+
+#include "AliITSU.h"
+
+class  AliITSUv1Layer;
+//class  AliITSv11GeomBeamPipe;
+class  TGeoVolume;
+class  TGeoVolumeAssembly;
+
+class AliITSUv1 : public AliITSU {
+
+ public:
+
+
+  typedef enum {
+    kIBModelDummy=0,
+    kIBModel0=1,
+    kIBModel1=2, 
+    kIBModel21=3,
+    kIBModel22=4,
+    kIBModel3=5,
+    kOBModelDummy=6,
+    kOBModel0=7,
+    kOBModel1=8 
+  } AliITSUModel_t;
+  
+
+  AliITSUv1();
+  AliITSUv1(const char *title, const Int_t nlay);
+  virtual       ~AliITSUv1() ;
+  virtual void   SetNWrapVolumes(Int_t n);
+  virtual void   AddAlignableVolumes() const;
+  virtual void   CreateGeometry();
+  virtual void   CreateMaterials();
+  virtual void   DefineLayer(Int_t nlay,Double_t phi0,Double_t r,Double_t zlen,Int_t nladd,
+                            Int_t nmod, Double_t lthick=0.,Double_t dthick=0.,UInt_t detType=0, Int_t buildFlag=0);
+  virtual void   DefineLayerTurbo(Int_t nlay,Double_t phi0,Double_t r,Double_t zlen,Int_t nladd,
+                                 Int_t nmod,Double_t width,Double_t tilt,
+                                 Double_t lthick = 0.,Double_t dthick = 0.,UInt_t detType=0, Int_t buildFlag=0);
+  virtual void   GetLayerParameters(Int_t nlay, Double_t &phi0,Double_t &r, Double_t &zlen,
+                                   Int_t &nladd, Int_t &nmod,
+                                   Double_t &width, Double_t &tilt,
+                                   Double_t &lthick, Double_t &mthick,
+                                   UInt_t &dettype) const;
+  virtual void   DefineWrapVolume(Int_t id, Double_t rmin,Double_t rmax, Double_t zspan);
+  virtual void   Init(); 
+  virtual Bool_t IsLayerTurbo(Int_t nlay);
+  virtual Int_t  IsVersion()                 const { return 20;}  // vUpgrade ? do we need this
+  virtual void   SetDefaults();
+  virtual void   StepManager();
+  virtual void   SetLayerDetTypeID(Int_t lr, UInt_t id);
+  virtual Int_t  GetLayerDetTypeID(Int_t lr);
+  virtual void   SetStaveModelIB(AliITSUModel_t model) {fStaveModelIB=model;}
+  virtual void   SetStaveModelOB(AliITSUModel_t model) {fStaveModelOB=model;}
+  virtual AliITSUModel_t GetStaveModelIB() const {return fStaveModelIB;}
+  virtual AliITSUModel_t GetStaveModelOB() const {return fStaveModelOB;}
+  //
+ private:
+  AliITSUv1(const AliITSUv1 &source); // copy constructor
+  AliITSUv1& operator=(const AliITSUv1 &source); // assignment operator
+
+  TGeoVolume* CreateWrapperVolume(const Int_t nLay);
+
+  //
+  Int_t     fNWrapVol;       // number of wrapper volumes
+  Double_t* fWrapRMin;       // min radius of wrapper volume
+  Double_t* fWrapRMax;       // max radius of wrapper volume
+  Double_t* fWrapZSpan;      // Z span of wrapper volume
+  Bool_t   *fLayTurbo;       // True for "turbo" layers
+  Double_t *fLayPhi0;        // Vector of layer's 1st ladder phi in lab
+  Double_t *fLayRadii;       // Vector of layer radii
+  Double_t *fLayZLength;     // Vector of layer length along Z
+  Int_t    *fLaddPerLay;     // Vector of number of ladders per layer
+  Int_t    *fModPerLadd;     // Vector of number of modules per ladder
+  Double_t *fLadThick;       // Vector of ladder thicknesses
+  Double_t *fLadWidth;       // Vector of ladder width (only used for turbo)
+  Double_t *fLadTilt;        // Vector of ladder tilt (only used for turbo)
+  Double_t *fDetThick;       // Vector of detector thicknesses
+  UInt_t   *fDetTypeID;      // Vector of detector type id
+  Int_t    *fBuildLevel;     // Vector of Material Budget Studies
+  //  
+  AliITSUv1Layer **fUpGeom; //! Geometry
+  AliITSUModel_t fStaveModelIB; // The stave model for the Inner Barrel
+  AliITSUModel_t fStaveModelOB; // The stave model for the Outer Barrel
+  
+  // Parameters for the Upgrade geometry
+  
+  ClassDef(AliITSUv1,0)                          
+};
+#endif
diff --git a/ITS/UPGRADE/AliITSUv1Layer.cxx b/ITS/UPGRADE/AliITSUv1Layer.cxx
new file mode 100644 (file)
index 0000000..05153c8
--- /dev/null
@@ -0,0 +1,2646 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+//*************************************************************************
+// This class Defines the Geometry for the ITS Upgrade using TGeo
+// This is a work class used to study different configurations
+// during the development of the new ITS structure.
+//
+//  Mario Sitta <sitta@to.infn.it>
+//  Chinorat Kobdaj (kobdaj@g.sut.ac.th)
+//*************************************************************************
+
+
+/* $Id: AliITSUv1Layer.cxx  */
+// General Root includes
+#include <TMath.h>
+// Root Geometry includes
+//#include <AliLog.h>
+#include <TGeoManager.h>
+#include <TGeoVolume.h>
+#include <TGeoPcon.h>
+#include <TGeoCone.h>
+#include <TGeoTube.h> // contaings TGeoTubeSeg
+#include <TGeoArb8.h>
+#include <TGeoXtru.h>
+#include <TGeoCompositeShape.h>
+#include <TGeoMatrix.h>
+#include "AliITSUv1Layer.h"
+#include "AliITSUGeomTGeo.h"
+#include <TGeoBBox.h>
+#include <TGeoShape.h>
+#include <TGeoTrd1.h>
+using namespace TMath;
+
+const Double_t AliITSUv1Layer::fgkDefaultSensorThick = 300*fgkmicron;
+const Double_t AliITSUv1Layer::fgkDefaultLadderThick =   1*fgkcm;
+
+const Double_t AliITSUv1Layer::fgkOBHalfStaveWidth   =   3.01 *fgkcm;
+const Double_t AliITSUv1Layer::fgkOBModuleGap        =   0.01 *fgkcm;
+const Double_t AliITSUv1Layer::fgkOBFlexCable1Thick  =   0.005*fgkcm;
+const Double_t AliITSUv1Layer::fgkOBFlexCable2Thick  =   0.01 *fgkcm;
+const Double_t AliITSUv1Layer::fgkOBBusCable1Thick   =   0.02 *fgkcm;
+const Double_t AliITSUv1Layer::fgkOBBusCable2Thick   =   0.02 *fgkcm;
+const Double_t AliITSUv1Layer::fgkOBColdPlateThick   =   0.012*fgkcm;
+const Double_t AliITSUv1Layer::fgkOBCarbonPlateThick =   0.012*fgkcm;
+const Double_t AliITSUv1Layer::fgkOBGlueThick        =   0.03 *fgkcm;
+const Double_t AliITSUv1Layer::fgkOBModuleZLength    =  21.06 *fgkcm;
+
+
+ClassImp(AliITSUv1Layer)
+
+#define SQ(A) (A)*(A)
+
+//________________________________________________________________________
+AliITSUv1Layer::AliITSUv1Layer(): 
+  AliITSv11Geometry(),
+  fLayerNumber(0),
+  fPhi0(0),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fDetTypeID(0),
+  fIsTurbo(0),
+  fBuildLevel(0),
+  fStaveModel(AliITSUv1::kIBModelDummy)
+{
+  //
+  // Standard constructor
+  //
+}
+
+//________________________________________________________________________
+AliITSUv1Layer::AliITSUv1Layer(Int_t debug): 
+  AliITSv11Geometry(debug),
+  fLayerNumber(0),
+  fPhi0(0),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fDetTypeID(0),
+  fIsTurbo(0),
+  fBuildLevel(0),
+  fStaveModel(AliITSUv1::kIBModelDummy)
+{
+  //
+  // Constructor setting debugging level
+  //
+}
+
+//________________________________________________________________________
+AliITSUv1Layer::AliITSUv1Layer(Int_t lay, Int_t debug): 
+  AliITSv11Geometry(debug),
+  fLayerNumber(lay),
+  fPhi0(0),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fDetTypeID(0),
+  fIsTurbo(0),
+  fBuildLevel(0),
+  fStaveModel(AliITSUv1::kIBModelDummy)
+{
+  //
+  // Constructor setting layer number and debugging level
+  //
+}
+
+//________________________________________________________________________
+AliITSUv1Layer::AliITSUv1Layer(Int_t lay, Bool_t turbo, Int_t debug): 
+  AliITSv11Geometry(debug),
+  fLayerNumber(lay),
+  fPhi0(0),
+  fLayRadius(0),
+  fZLength(0),
+  fSensorThick(0),
+  fLadderThick(0),
+  fLadderWidth(0),
+  fLadderTilt(0),
+  fNLadders(0),
+  fNModules(0),
+  fDetTypeID(0),
+  fIsTurbo(turbo),
+  fBuildLevel(0),
+  fStaveModel(AliITSUv1::kIBModelDummy)
+{
+  //
+  // Constructor setting layer number and debugging level
+  // for a "turbo" layer (i.e. where ladders overlap in phi)
+  //
+}
+
+//________________________________________________________________________
+AliITSUv1Layer::AliITSUv1Layer(const AliITSUv1Layer &s):
+  AliITSv11Geometry(s.GetDebug()),
+  fLayerNumber(s.fLayerNumber),
+  fPhi0(s.fPhi0),
+  fLayRadius(s.fLayRadius),
+  fZLength(s.fZLength),
+  fSensorThick(s.fSensorThick),
+  fLadderThick(s.fLadderThick),
+  fLadderWidth(s.fLadderWidth),
+  fLadderTilt(s.fLadderTilt),
+  fNLadders(s.fNLadders),
+  fNModules(s.fNModules),
+  fDetTypeID(s.fDetTypeID),
+  fIsTurbo(s.fIsTurbo),
+  fBuildLevel(s.fBuildLevel),
+  fStaveModel(s.fStaveModel)
+{
+  //
+  // Copy constructor
+  //
+}
+
+//________________________________________________________________________
+AliITSUv1Layer& AliITSUv1Layer::operator=(const AliITSUv1Layer &s)
+{
+  //
+  // Assignment operator 
+  //
+  if(&s == this) return *this;
+
+  fLayerNumber = s.fLayerNumber;
+  fPhi0        = s.fPhi0;
+  fLayRadius   = s.fLayRadius;
+  fZLength     = s.fZLength;
+  fSensorThick = s.fSensorThick;
+  fLadderThick = s.fLadderThick;
+  fLadderWidth = s.fLadderWidth;
+  fLadderTilt  = s.fLadderTilt;
+  fNLadders    = s.fNLadders;
+  fNModules    = s.fNModules;
+  fIsTurbo     = s.fIsTurbo;
+  fDetTypeID   = s.fDetTypeID;
+  fBuildLevel  = s.fBuildLevel;
+  fStaveModel  = s.fStaveModel;
+
+  return *this;
+}
+
+//________________________________________________________________________
+AliITSUv1Layer::~AliITSUv1Layer() {
+  //
+  // Destructor
+  //
+}
+
+//________________________________________________________________________
+void AliITSUv1Layer::CreateLayer(TGeoVolume *moth){
+//
+// Creates the actual Layer and places inside its mother volume
+//
+// Input:
+//         moth : the TGeoVolume owing the volume structure
+//
+// Output:
+//
+// Return:
+//
+// Created:      17 Jun 2011  Mario Sitta
+// Updated:      08 Jul 2011  Mario Sitta
+// Updated:      20 May 2013  Mario Sitta  Layer is Assembly instead of Tube
+//
+  // Local variables
+  char volname[30];
+  Double_t xpos, ypos, zpos;
+  Double_t alpha;
+
+
+  // Check if the user set the proper parameters
+  if (fLayRadius <= 0) AliFatal(Form("Wrong layer radius (%f)",fLayRadius));
+  if (fZLength   <= 0) AliFatal(Form("Wrong layer length (%f)",fZLength));
+  if (fNLadders  <= 0) AliFatal(Form("Wrong number of ladders (%d)",fNLadders));
+  if (fNModules  <= 0) AliFatal(Form("Wrong number of modules (%d)",fNModules));
+
+  if (fLadderThick <= 0) {
+    AliInfo(Form("Ladder thickness wrong or not set (%f), using default (%f)",
+                fLadderThick,fgkDefaultLadderThick));
+    fLadderThick = fgkDefaultLadderThick;
+  }
+
+  if (fSensorThick <= 0) {
+    AliInfo(Form("Sensor thickness wrong or not set (%f), using default (%f)",
+                fSensorThick,fgkDefaultSensorThick));
+    fSensorThick = fgkDefaultSensorThick;
+  }
+
+  if (fSensorThick > fLadderThick) {
+    AliWarning(Form("Sensor thickness (%f) is greater than ladder thickness (%f), fixing",
+                fSensorThick,fLadderThick));
+    fSensorThick = fLadderThick;
+  }
+
+
+  // If a Turbo layer is requested, do it and exit
+  if (fIsTurbo) {
+    CreateLayerTurbo(moth);
+    return;
+  }
+
+
+  // First create the ladder container
+  alpha = (360./(2*fNLadders))*DegToRad();
+
+  //  fLadderWidth = fLayRadius*Tan(alpha);
+
+  snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(),fLayerNumber);
+  TGeoVolume *layVol = new TGeoVolumeAssembly(volname);
+  layVol->SetUniqueID(fDetTypeID);
+
+//  layVol->SetVisibility(kFALSE);
+  layVol->SetVisibility(kTRUE);
+  layVol->SetLineColor(1);
+
+  TGeoVolume *laddVol = CreateLadder();
+
+
+  // Now build up the layer
+  alpha = 360./fNLadders;
+  Double_t r = fLayRadius + ((TGeoBBox*)laddVol->GetShape())->GetDY();
+  for (Int_t j=0; j<fNLadders; j++) {
+    Double_t phi = j*alpha + fPhi0;
+    xpos = r*CosD(phi);// r*SinD(-phi);
+    ypos = r*SinD(phi);// r*CosD(-phi);
+    zpos = 0.;
+    phi += 90;
+    layVol->AddNode(laddVol, j, new TGeoCombiTrans( xpos, ypos, zpos,
+                                                   new TGeoRotation("",phi,0,0)));
+  }
+
+
+  // Finally put everything in the mother volume
+  moth->AddNode(layVol, 1, 0);
+
+
+  // Upgrade geometry is served
+  return;
+}
+
+//________________________________________________________________________
+void AliITSUv1Layer::CreateLayerTurbo(TGeoVolume *moth){
+//
+// Creates the actual Layer and places inside its mother volume
+// A so-called "turbo" layer is a layer where ladders overlap in phi
+// User can set width and tilt angle, no check is performed here
+// to avoid volume overlaps
+//
+// Input:
+//         moth : the TGeoVolume owing the volume structure
+//
+// Output:
+//
+// Return:
+//
+// Created:      08 Jul 2011  Mario Sitta
+// Updated:      08 Mar 2012  Mario Sitta  Correct way to compute container R
+// Updated:      20 May 2013  Mario Sitta  Layer is Assemgbly instead of Tube
+//
+
+
+  // Local variables
+  char volname[30];
+  Double_t xpos, ypos, zpos;
+  Double_t alpha;
+
+
+  // Check if the user set the proper (remaining) parameters
+  if (fLadderWidth <= 0)
+    AliFatal(Form("Wrong ladder width (%f)",fLadderWidth));
+  if (Abs(fLadderTilt) > 45)
+    AliWarning(Form("Ladder tilt angle (%f) greater than 45deg",fLadderTilt));
+
+
+  snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSLayerPattern(), fLayerNumber);
+  TGeoVolume *layVol = new TGeoVolumeAssembly(volname);
+  layVol->SetUniqueID(fDetTypeID);
+  layVol->SetVisibility(kTRUE);
+  layVol->SetLineColor(1);
+  TGeoVolume *laddVol = CreateLadder();
+
+
+  // Now build up the layer
+  alpha = 360./fNLadders;
+  Double_t r = fLayRadius /* +module thick ?! */;
+  for (Int_t j=0; j<fNLadders; j++) {
+    Double_t phi = j*alpha + fPhi0;
+    xpos = r*CosD(phi);// r*SinD(-phi);
+    ypos = r*SinD(phi);// r*CosD(-phi);
+    zpos = 0.;
+    phi += 90;
+    layVol->AddNode(laddVol, j, new TGeoCombiTrans( xpos, ypos, zpos,
+                                                   new TGeoRotation("", phi-fLadderTilt,0,0)));
+  }
+
+
+  // Finally put everything in the mother volume
+  moth->AddNode(layVol, 1, 0);
+
+  return;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateLadder(const TGeoManager * /*mgr*/){
+//
+// Creates the actual Ladder
+//
+// Input:
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Jun 2011  Mario Sitta
+// Updated:      18 Dec 2013  Mario Sitta  Handle IB and OB
+//
+
+  char volname[30];
+  Double_t xLenO = 5.79/2;
+  Double_t xlenI, ylen, zlen;
+  Double_t xpos, ypos, zpos, zmod;
+  Double_t alpha;
+
+
+  // First create all needed shapes
+  alpha = (360./(2*fNLadders))*DegToRad();
+
+  // The ladder
+  xlenI = fLayRadius*Tan(alpha);
+  if (fIsTurbo) xlenI = 0.5*fLadderWidth;
+  ylen = 0.5*fLadderThick;
+  zlen = 0.5*fZLength;
+
+  Double_t yplus = 0.46;
+  TGeoXtru *ladder = new TGeoXtru(2); //z sections
+  Double_t xv[5] = {xlenI,xlenI,0,-xlenI,-xlenI};
+  Double_t yv[5] = {ylen+0.09,-0.15,-yplus-fSensorThick,-0.15,ylen+0.09};    
+  ladder->DefinePolygon(5,xv,yv);
+  ladder->DefineSection(0,-zlen,0,0,1.);
+  ladder->DefineSection(1,+zlen,0,0,1.);
+
+  // We have all shapes: now create the real volumes
+
+  snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSLadderPattern(), fLayerNumber);
+//  TGeoVolume *laddVol = new TGeoVolume(volname, ladder, medAir);
+  TGeoVolume *laddVol = new TGeoVolumeAssembly(volname);
+
+  //  laddVol->SetVisibility(kFALSE);
+  laddVol->SetVisibility(kTRUE);
+  laddVol->SetLineColor(2);
+  TGeoVolume *modVol = 0;
+  TGeoVolume *mechLaddVol = 0;
+
+  // Now build up the ladder
+  if (fLayerNumber<3) {
+    modVol = CreateModuleInnerB(xlenI,ylen,zlen);
+    zmod = ((TGeoBBox*)modVol->GetShape())->GetDZ();
+    for (Int_t j=0; j<fNModules; j++) {
+      xpos = 0.;
+      ypos = 0.021;  // Remove small overlap - M.S: 21may13
+      zpos = -ladder->GetDZ() + j*2*zmod + zmod;
+      laddVol->AddNode(modVol, j, new TGeoTranslation(xpos, ypos, zpos));
+    }
+  // put mechanical stave structure, only inner barrel up to now
+    mechLaddVol = CreateStaveStructInnerB(xlenI,zlen); 
+    if (mechLaddVol)
+      laddVol->AddNode(mechLaddVol, fNModules, new TGeoCombiTrans(0, -0.15-ylen, 0, new TGeoRotation("",0, 0, 180)));
+  }
+
+  else{
+    if (fStaveModel == AliITSUv1::kOBModel0) { // Create simplified stave struct as in v0
+      modVol = CreateModuleInnerB(xlenI,ylen,zlen);
+  printf("?????? %f %f %f\n",xlenI,ylen,zlen);
+      zmod = ((TGeoBBox*)modVol->GetShape())->GetDZ();
+      for (Int_t j=0; j<fNModules; j++) {
+       xpos = 0.;
+       ypos = 0.021;  // Remove small overlap - M.S: 21may13
+       zpos = -ladder->GetDZ() + j*2*zmod + zmod;
+       laddVol->AddNode(modVol, j, new TGeoTranslation(xpos, ypos, zpos));
+      }
+    } else { // (if fStaveModel) Create new stave struct as in TDR
+      modVol = CreateStaveOuterB(xLenO);
+      laddVol->AddNode(modVol, 1, new TGeoTranslation(0, 2.5, 0));
+
+      mechLaddVol = CreateSpaceFrameOuterB(xLenO); 
+      if (mechLaddVol)
+       laddVol->AddNode(mechLaddVol, 1,
+                        new TGeoCombiTrans(0, 0, 0,
+                                           new TGeoRotation("", 180, 0, 0)));
+    } // if (fStaveModel)
+  }
+  
+
+  // Done, return the ladder
+  return laddVol;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveStructInnerB(const Double_t xlad,
+                                                   const Double_t zlad,
+                                                   const TGeoManager *mgr){
+//
+// Create the mechanical stave structure
+//
+// Input:
+//         xlad : X length
+//         zlad : Z length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Mar 2013  Chinorat Kobdaj
+// Updated:      26 Apr 2013  Mario Sitta
+//
+
+  TGeoVolume *mechLaddVol = 0;
+
+  switch (fStaveModel) {
+    case AliITSUv1::kIBModelDummy:
+      mechLaddVol = CreateStaveModelInnerBDummy(xlad,zlad,mgr);
+      break;
+    case AliITSUv1::kIBModel0:
+      mechLaddVol = CreateStaveModelInnerB0(xlad,zlad,mgr);
+      break;
+    case AliITSUv1::kIBModel1:
+      mechLaddVol = CreateStaveModelInnerB1(xlad,zlad,mgr);
+      break;
+    case AliITSUv1::kIBModel21:
+      mechLaddVol = CreateStaveModelInnerB21(xlad,zlad,mgr);
+      break;
+    case AliITSUv1::kIBModel22:
+      mechLaddVol = CreateStaveModelInnerB22(xlad,zlad,mgr);
+      break;
+    case AliITSUv1::kIBModel3:
+      mechLaddVol = CreateStaveModelInnerB3(xlad,zlad,mgr);
+      break;
+    default:
+      AliFatal(Form("Unknown stave model %d",fStaveModel));
+      break;
+  }
+
+  return mechLaddVol; 
+}
+
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerBDummy(const Double_t ,
+                                                       const Double_t ,
+                                                       const TGeoManager *) const {
+//
+// Create dummy stave
+//
+// Input:
+//         xlad : X length
+//         zlad : Z length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Mar 2013  Chinorat Kobdaj
+// Updated:      26 Apr 2013  Mario Sitta
+//
+
+  // Done, return the stave structur
+  return 0;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB0(const Double_t xlad,
+                                                   const Double_t zlad,
+                                                   const TGeoManager *mgr){
+//
+// Create the mechanical stave structure for Model 0 of TDR
+//
+// Input:
+//         xlad : X length
+//         zlad : Z length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Mar 2013  Chinorat Kobdaj
+// Updated:      26 Apr 2013  Mario Sitta
+//
+  
+  // Materials defined in AliITSUv1
+  TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
+  TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
+
+  TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
+  TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
+  TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
+  TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
+
+  // Local parameters
+  Double_t kConeOutRadius = 0.15/2;
+  Double_t kConeInRadius = 0.1430/2;
+  Double_t kStaveLength = zlad*2;
+  Double_t kStaveWidth = xlad*2-kConeOutRadius*2;
+  Double_t kWidth = kStaveWidth/4;//1/2 of kWidth
+  Double_t kStaveHeight = 0.3;
+  Double_t kHeight = kStaveHeight/2;
+  Double_t kAlpha = 90-67;//90-33.69;
+  Double_t kTheta = kAlpha*TMath::DegToRad();
+  Double_t kS1 = kWidth/TMath::Sin(kTheta);
+  Double_t kL1 = kWidth/TMath::Tan(kTheta);
+  Double_t kS2 = TMath::Sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(the2);
+  Double_t kThe2 = TMath::ATan(kHeight/kS1);
+  Double_t kBeta = kThe2*TMath::RadToDeg();
+  // Int_t  loop = kStaveLength/(kL1);
+  // Double_t s3 = kWidth/(2*TMath::Sin(kTheta));
+  // Double_t s4 = 3*kWidth/(2*TMath::Sin(kTheta));
+
+  AliDebug(1, Form("BuildLevel %d\n",fBuildLevel));
+
+  char volname[30];
+  snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSLadderPattern(), fLayerNumber);
+
+  Double_t z=0, y=-0.011+0.0150, x=0;
+
+   TGeoVolume *mechLaddVol = 0;
+
+  if (fBuildLevel < 5) {
+
+    // world (trapezoid)
+    TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
+    Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
+    Double_t yv[5] = {-kConeOutRadius*2-0.07,0,kStaveHeight,0,-kConeOutRadius*2-0.07};    
+    mechStruct->DefinePolygon(5,xv,yv);
+    mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
+    mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
+
+    mechLaddVol = new TGeoVolume(volname, mechStruct, medAir);
+    mechLaddVol->SetLineColor(12);
+    mechLaddVol->SetFillColor(12); 
+    mechLaddVol->SetVisibility(kTRUE);
+      
+    // detailed structure ++++++++++++++
+    //Pipe Kapton grey-35
+    TGeoTube *coolTube = new TGeoTube(kConeInRadius,kConeOutRadius,kStaveLength/2);
+    TGeoVolume *volCoolTube= new TGeoVolume("pipe", coolTube, medKapton);
+    volCoolTube->SetFillColor(35);
+    volCoolTube->SetLineColor(35);
+    mechLaddVol->AddNode(volCoolTube,0,new TGeoTranslation(x+(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
+    mechLaddVol->AddNode(volCoolTube,1,new TGeoTranslation(x-(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
+  }
+
+  if (fBuildLevel < 4) {
+    TGeoTube *coolTubeW = new TGeoTube(0.,kConeInRadius,kStaveLength/2);
+    TGeoVolume *volCoolTubeW= new TGeoVolume("pipeWater", coolTubeW, medWater);
+    volCoolTubeW->SetFillColor(4);
+    volCoolTubeW->SetLineColor(4);
+    mechLaddVol->AddNode(volCoolTubeW,0,new TGeoTranslation(x+(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
+    mechLaddVol->AddNode(volCoolTubeW,1,new TGeoTranslation(x-(kStaveWidth/2),y-(kHeight-kConeOutRadius),0));
+  }
+
+  //frequency of filament
+  //n = 4 means very dense(4 filaments per interval)
+  //n = 2 means dense(2 filaments per interval)
+  Int_t n =4;
+  Int_t loop = (Int_t)(kStaveLength/(4*kL1/n) + 2/n)-1;
+  if (fBuildLevel < 3) {
+    //Top CFRP Filament black-12 Carbon structure TGeoBBox (length,thickness,width)
+    TGeoBBox *t2=new TGeoBBox(kS2,0.007/2,0.15/2);//(kS2,0.002,0.02);
+    TGeoVolume *volT2=new TGeoVolume("TopFilament", t2, medM60J3K);
+    volT2->SetLineColor(12);
+    volT2->SetFillColor(12); 
+
+    for(int i=1;i<loop;i++){  //i<60;i++){
+      mechLaddVol->AddNode(volT2,4*i+0,
+                                 new TGeoCombiTrans(x+kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),
+                                                    new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
+      mechLaddVol->AddNode(volT2,4*i+1,
+                                 new TGeoCombiTrans(x-kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),
+                                                    new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
+      mechLaddVol->AddNode(volT2,4*i+2,
+                                 new TGeoCombiTrans(x+kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),
+                                                    new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
+      mechLaddVol->AddNode(volT2,4*i+3,
+                                 new TGeoCombiTrans(x-kWidth,y+(2*kConeOutRadius),z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2,//z-14.25+(i*2*kL1),  
+                                                    new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
+    }
+
+
+    //Bottom CFRP Filament black-12 Carbon structure  TGeoBBox (thickness,width,length)
+    TGeoBBox *t1=new TGeoBBox(0.007/2,0.15/2,kS1);//(0.002,0.02,kS1);
+    TGeoVolume *volT1=new TGeoVolume("CFRPBottom", t1, medM60J3K);
+    volT1->SetLineColor(12);
+    volT1->SetFillColor(12); 
+
+    for(int i=1;i<loop;i++){
+      mechLaddVol->AddNode(volT1,4*i+0,
+                                 new TGeoCombiTrans(x+kWidth,y-kHeight,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2, //z-14.25+(i*2*kL1),  
+                                                    new TGeoRotation("volT1",-90,kAlpha,0)));
+      mechLaddVol->AddNode(volT1,4*i+1,
+                                 new TGeoCombiTrans(x-kWidth,y-kHeight,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2,  //z-14.25+(i*2*kL1), 
+                                                    new TGeoRotation("volT1",90,kAlpha,0)));
+      mechLaddVol->AddNode(volT1,4*i+2,
+                                 new TGeoCombiTrans(x+kWidth,y-kHeight,z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
+                                                    new TGeoRotation("volT1",-90,-kAlpha,0)));
+      mechLaddVol->AddNode(volT1,4*i+3,
+                                 new TGeoCombiTrans(x-kWidth,y-kHeight,z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
+                                                    new TGeoRotation("volT1",-90,+kAlpha,0)));
+    }
+  }
+   
+  if (fBuildLevel < 2) {
+    // Glue CFRP-Silicon layers TGeoBBox(thickness,width,kS1);
+    TGeoBBox *tG=new TGeoBBox(0.0075/2,0.18/2,kS1);
+    TGeoVolume *volTG=new TGeoVolume("Glue1", tG, medGlue);
+    volTG->SetLineColor(5);
+    volTG->SetFillColor(5); 
+
+    for(int i=1;i<loop;i++){ //i<60;i++){
+      mechLaddVol->AddNode(volTG,4*i+0,
+                                 new TGeoCombiTrans(x+kWidth,y-0.16,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2, //z-14.25+(2*kL1*i), 
+                                                    new TGeoRotation("volTG",-90,kAlpha,0)));
+      mechLaddVol->AddNode(volTG,4*i+1,
+                                 new TGeoCombiTrans(x-kWidth,y-0.16,z-kStaveLength/2+((4/n)*kL1*i)+kS1/2, //z-14.25+(2*kL1*i), 
+                                                    new TGeoRotation("volTG",90,kAlpha,0)));
+      mechLaddVol->AddNode(volTG,4*i+2,
+                                 new TGeoCombiTrans(x+kWidth,y-0.16,z-kStaveLength/2+((4/n)*i*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
+                                                    new TGeoRotation("volTG",-90,-kAlpha,0)));
+      mechLaddVol->AddNode(volTG,4*i+3,
+                                 new TGeoCombiTrans(x-kWidth,y-0.16,z-kStaveLength/2+(i*(4/n)*kL1)+kS1/2, //z-14.25+(i*2*kL1), 
+                                                    new TGeoRotation("volTG",-90,+kAlpha,0)));
+    }
+
+    TGeoBBox *glue = new TGeoBBox(xlad, 0.005/2, zlad);
+    TGeoVolume *volGlue=new TGeoVolume("Glue2", glue, medGlue);
+    volGlue->SetLineColor(5);
+    volGlue->SetFillColor(5); 
+    //mechLaddVol->AddNode(volGlue, 0, new TGeoCombiTrans(x, y-0.16, z, new TGeoRotation("",0, 0, 0)));
+    mechLaddVol->AddNode(volGlue, 1, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005, z, new TGeoRotation("",0, 0, 0)));
+  }
+
+  if (fBuildLevel < 1) {
+    //Flex cable brown-28 TGeoBBox(width,thickness,length); 
+    TGeoBBox *kapCable = new TGeoBBox(xlad, 0.01/2, zlad);
+    TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
+    volCable->SetLineColor(28);
+    volCable->SetFillColor(28); 
+    mechLaddVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005-0.01, z, new TGeoRotation("",0, 0, 0)));
+ }
+
+  // Done, return the stave structur
+  return mechLaddVol;
+}
+
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB1(const Double_t xlad,
+                                                   const Double_t zlad,
+                                                   const TGeoManager *mgr){
+//
+// Create the mechanical stave structure for Model 1 of TDR
+//
+// Input:
+//         xlad : X length
+//         zlad : Z length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Mar 2013  Chinorat Kobdaj
+// Updated:      26 Apr 2013  Mario Sitta
+//
+  
+  // Materials defined in AliITSUv1
+  TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
+  TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
+
+  TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
+  TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
+  TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
+  TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
+
+  // Local parameters
+  Double_t kConeOutRadius = 0.15/2;
+  //    Double_t kConeInRadius = 0.1430/2;
+  Double_t kStaveLength = zlad*2;
+  //    Double_t kStaveWidth = xlad*2-kConeOutRadius*2;
+  Double_t kStaveWidth = xlad*2;
+  Double_t kWidth = kStaveWidth/4;//1/2 of kWidth
+  Double_t kStaveHeight = 0.3;
+  Double_t kHeight = kStaveHeight/2;
+  Double_t kAlpha = 90-33.;//90-30;
+  Double_t kTheta = kAlpha*TMath::DegToRad();
+  Double_t kS1 = kWidth/TMath::Sin(kTheta);
+  Double_t kL1 = kWidth/TMath::Tan(kTheta);
+  Double_t kS2 = TMath::Sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(the2);
+  Double_t kThe2 = TMath::ATan(kHeight/kS1);
+  Double_t kBeta = kThe2*TMath::RadToDeg();
+  Int_t  loop = (Int_t)((kStaveLength/(2*kL1))/2);
+  
+
+  TGeoVolume *mechLaddVol = 0;
+
+  char volname[30];
+  snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSLadderPattern(), fLayerNumber);
+    
+
+  // detailed structure ++++++++++++++
+  Double_t z=0, y=-0.011+0.0150, x=0;
+
+  // Polimide micro channels numbers
+  Double_t yMC = y-kHeight+0.01;
+  Int_t nb = (Int_t)(kStaveWidth/0.1)+1;
+  Double_t xladMC = (nb*0.1-0.08)/2;
+
+
+  if (fBuildLevel < 5) {
+    // world (trapezoid)
+    TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
+    Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
+    Double_t yv[5] = {-kConeOutRadius*2-0.07,0,kStaveHeight,0,-kConeOutRadius*2-0.07};    
+    mechStruct->DefinePolygon(5,xv,yv);
+    mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
+    mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
+
+    mechLaddVol = new TGeoVolume(volname, mechStruct, medAir);
+    mechLaddVol->SetLineColor(12);
+    mechLaddVol->SetFillColor(12); 
+    mechLaddVol->SetVisibility(kTRUE);
+      
+    // Polimide micro channels numbers
+    TGeoBBox *tM0=new TGeoBBox(xladMC, 0.005/2, zlad);
+    TGeoVolume *volTM0=new TGeoVolume("MicroChanCover", tM0, medKapton);
+    volTM0->SetLineColor(35);
+    volTM0->SetFillColor(35); 
+    mechLaddVol->AddNode(volTM0, 0, new TGeoCombiTrans(x,-0.0125+yMC, z, new TGeoRotation("",0, 0, 0)));
+    mechLaddVol->AddNode(volTM0, 1, new TGeoCombiTrans(x,+0.0125+yMC, z, new TGeoRotation("",0, 0, 0)));
+      
+    TGeoBBox *tM0b=new TGeoBBox(0.02/2, 0.02/2, zlad);
+    TGeoVolume *volTM0b=new TGeoVolume("MicroChanWalls", tM0b, medKapton);
+    volTM0b->SetLineColor(35);
+    volTM0b->SetFillColor(35); 
+    for (Int_t ib=0;ib<nb;ib++) {
+      mechLaddVol->AddNode(volTM0b, ib, new TGeoCombiTrans(x+ib*0.1-xladMC+0.01,yMC, z, new TGeoRotation("",0, 0, 0)));
+    }
+      
+  }
+    
+  if (fBuildLevel < 4) {
+    // Water in Polimide micro channels
+    TGeoBBox *water=new TGeoBBox(0.08/2, 0.02/2, zlad+0.1);
+    TGeoVolume *volWater=new TGeoVolume("Water", water, medWater);
+    volWater->SetLineColor(4);
+    volWater->SetFillColor(4); 
+    for (Int_t ib=0;ib<(nb-1);ib++) {
+      mechLaddVol->AddNode(volWater, ib, new TGeoCombiTrans(x+ib*0.1-xladMC+0.06,yMC, z, new TGeoRotation("",0, 0, 0)));
+    }
+  }
+    
+  if (fBuildLevel < 3) {
+    //Bottom filament CFRP black-12 Carbon structure TGeoBBox (thickness,width,length)
+    Double_t filWidth = 0.04;
+    Double_t filHeight= 0.02;
+    TGeoBBox *t1=new TGeoBBox(filHeight/2,filWidth/2,kS1);
+    TGeoVolume *volT1=new TGeoVolume("CFRPBottom", t1, medM60J3K);
+    volT1->SetLineColor(12);
+    volT1->SetFillColor(12); 
+    for(int i=0;i<loop;i++){//i<30;i++){
+      mechLaddVol->AddNode(volT1,4*i+0,
+                                 new TGeoCombiTrans(x+kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+(4*kL1)+kS1/2, 
+                                                    new TGeoRotation("volT1",-90,kAlpha,0)));
+      mechLaddVol->AddNode(volT1,4*i+1,
+                                 new TGeoCombiTrans(x-kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+(4*kL1*i)+kS1/2, 
+                                                    new TGeoRotation("volT1",90,kAlpha,0)));
+      mechLaddVol->AddNode(volT1,4*i+2,
+                                 new TGeoCombiTrans(x+kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
+                                                    new TGeoRotation("volT1",-90,-kAlpha,0)));
+      mechLaddVol->AddNode(volT1,4*i+3,
+                                 new TGeoCombiTrans(x-kWidth,y-kHeight+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
+                                                    new TGeoRotation("volT1",-90,+kAlpha,0)));
+    }
+
+      // Top filament CFRP black-12 Carbon structure TGeoBBox (length,thickness,width)
+    TGeoBBox *t2=new TGeoBBox(kS2,filHeight/2,filWidth/2);
+    TGeoVolume *volT2=new TGeoVolume("CFRPTop", t2, medM60J3K);
+    volT2->SetLineColor(12);
+    volT2->SetFillColor(12); 
+    for(int i=0;i<loop;i++){ //i<30;i++){
+      mechLaddVol->AddNode(volT2,4*i+0,
+                                 new TGeoCombiTrans(x+kWidth,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*kL1)+kS1/2,
+                                                    new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
+      mechLaddVol->AddNode(volT2,4*i+1,
+                                 new TGeoCombiTrans(x-kWidth,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*kL1)+kS1/2,
+                                                    new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
+      mechLaddVol->AddNode(volT2,4*i+2,
+                                 new TGeoCombiTrans(x+kWidth,y+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2,
+                                                    new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
+      mechLaddVol->AddNode(volT2,4*i+3,
+                                 new TGeoCombiTrans(x-kWidth,y+0.04+filHeight/2,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
+                                                    new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
+    }
+  }
+
+  if (fBuildLevel < 2) {
+    // Glue between filament and polimide micro channel
+    TGeoBBox *t3=new TGeoBBox(0.01/2,0.04,kS1);
+    TGeoVolume *volT3=new TGeoVolume("FilamentGlue", t3, medGlue);
+    volT3->SetLineColor(5);
+    volT3->SetFillColor(5); 
+    for(int i=0;i<loop;i++){//i<30;i++){
+      mechLaddVol->AddNode(volT3,4*i+0,
+                                 new TGeoCombiTrans(x+kWidth,y-kHeight+0.0325,z-kStaveLength/2+(4*kL1*i)+kS1/2, 
+                                                    new TGeoRotation("volT1",-90,kAlpha,0)));
+      mechLaddVol->AddNode(volT3,4*i+1,
+                                 new TGeoCombiTrans(x-kWidth,y-kHeight+0.0325,z-kStaveLength/2+(4*kL1*i)+kS1/2, 
+                                                    new TGeoRotation("volT1",90,kAlpha,0)));
+      mechLaddVol->AddNode(volT3,4*i+2,
+                                 new TGeoCombiTrans(x+kWidth,y-kHeight+0.0325,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
+                                                    new TGeoRotation("volT1",-90,-kAlpha,0)));
+      mechLaddVol->AddNode(volT3,4*i+3,
+                                 new TGeoCombiTrans(x-kWidth,y-kHeight+0.0325,z-kStaveLength/2+2*kL1+(i*4*kL1)+kS1/2, 
+                                                    new TGeoRotation("volT1",-90,+kAlpha,0)));
+    }
+      
+    // Glue microchannel and sensor
+    TGeoBBox *glueM = new TGeoBBox(xlad, 0.01/2, zlad);
+    TGeoVolume *volGlueM=new TGeoVolume("MicroChanGlue", glueM, medGlue);
+    volGlueM->SetLineColor(5);
+    volGlueM->SetFillColor(5); 
+    mechLaddVol->AddNode(volGlueM, 0, new TGeoCombiTrans(x, y-0.16, z, new TGeoRotation("",0, 0, 0)));
+
+    // Glue sensor and kapton
+    TGeoBBox *glue = new TGeoBBox(xlad, 0.005/2, zlad);
+    TGeoVolume *volGlue=new TGeoVolume("SensorGlue", glue, medGlue);
+    volGlue->SetLineColor(5);
+    volGlue->SetFillColor(5); 
+    mechLaddVol->AddNode(volGlue, 1, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005, z, new TGeoRotation("",0, 0, 0)));
+  }
+
+  if (fBuildLevel < 1) {
+    TGeoBBox *kapCable = new TGeoBBox(xlad, 0.01/2, zlad);
+    TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
+    volCable->SetLineColor(28);
+    volCable->SetFillColor(28); 
+    mechLaddVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-0.165-fSensorThick-0.005-0.01, z, new TGeoRotation("",0, 0, 0)));
+  }
+    
+  // Done, return the stave structur
+  return mechLaddVol;
+
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB21(const Double_t xlad,
+                                                    const Double_t zlad,
+                                                    const TGeoManager *mgr){
+//
+// Create the mechanical stave structure for Model 2.1 of TDR
+//
+// Input:
+//         xlad : X length
+//         zlad : Z length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Mar 2013  Chinorat Kobdaj
+// Updated:      26 Apr 2013  Mario Sitta
+//
+  
+  // Materials defined in AliITSUv1
+  TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
+  TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
+
+  TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
+  TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
+  TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
+  TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
+  TGeoMedium *medK13D2U2k  = mgr->GetMedium("ITS_K13D2U2k$");
+  TGeoMedium *medFGS003    = mgr->GetMedium("ITS_FGS003$"); 
+  TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
+
+  // Local parameters
+  Double_t kConeOutRadius =0.151384/2;
+  Double_t kConeInRadius = 0.145034/2;
+  Double_t kStaveLength = zlad;
+  Double_t kStaveWidth = xlad*2;
+  Double_t kWidth = (kStaveWidth+0.005)/4;
+  Double_t kStaveHeigth = 0.33;//0.33;
+  Double_t kHeight = (kStaveHeigth+0.025)/2;
+  Double_t kAlpha = 57; //56.31;
+  Double_t kTheta = kAlpha*TMath::DegToRad();
+  Double_t kS1 = (kStaveWidth/4)/TMath::Sin(kTheta);
+  Double_t kL1 = (kStaveWidth/4)/TMath::Tan(kTheta);
+  Double_t kS2 = sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(the2);
+  Double_t kThe2 = TMath::ATan(kHeight/kS1);
+  Double_t kBeta = kThe2*TMath::RadToDeg();
+  // Double_t lay1 = 0.003157;
+  Double_t kLay1 = 0.003;//Amec carbon
+  // Double_t lay2 = 0.0043215;//C Fleece carbon
+  Double_t kLay2 = 0.002;//C Fleece carbon
+  Double_t kLay3 = 0.007;//K13D2U carbon
+  Int_t  loop = (Int_t)(kStaveLength/(2*kL1));
+
+
+  char volname[30];
+  snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSLadderPattern(), fLayerNumber);
+
+  Double_t z=0, y=-(kConeOutRadius+0.03)+0.0385, x=0;
+
+  TGeoVolume *mechLaddVol = 0;
+
+  if (fBuildLevel < 5) {
+    // world (trapezoid)
+    TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
+    Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
+    Double_t yv[5] = {-kConeOutRadius*2-0.07,0,kStaveHeigth,0,-kConeOutRadius*2-0.07};    
+    mechStruct->DefinePolygon(5,xv,yv);
+    mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
+    mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
+
+    mechLaddVol = new TGeoVolume(volname, mechStruct, medAir);
+    mechLaddVol->SetLineColor(12);
+    mechLaddVol->SetFillColor(12); 
+    mechLaddVol->SetVisibility(kTRUE);  
+      
+    //Pipe Kapton grey-35 
+    TGeoCone *cone1 = new TGeoCone(kStaveLength,kConeInRadius,kConeOutRadius,kConeInRadius,kConeOutRadius);
+    TGeoVolume *volCone1= new TGeoVolume("PolyimidePipe", cone1, medKapton);
+    volCone1->SetFillColor(35);
+    volCone1->SetLineColor(35);
+    mechLaddVol->AddNode(volCone1,1,new TGeoTranslation(x+0.25,y,z));
+    mechLaddVol->AddNode(volCone1,2,new TGeoTranslation(x-0.25,y,z));
+  }
+
+  if (fBuildLevel < 4) {
+    
+    TGeoTube *coolTubeW = new TGeoTube(0.,kConeInRadius,kStaveLength);
+    TGeoVolume *volCoolTubeW= new TGeoVolume("Water", coolTubeW, medWater);
+    volCoolTubeW->SetFillColor(4);
+    volCoolTubeW->SetLineColor(4);
+    mechLaddVol->AddNode(volCoolTubeW,0,new TGeoTranslation(x-0.25,y,z));
+    mechLaddVol->AddNode(volCoolTubeW,1,new TGeoTranslation(x+0.25,y,z));
+  }
+
+  if (fBuildLevel < 3) {
+    //top fillament
+    // Top filament M60J black-12 Carbon structure TGeoBBox (length,thickness,width)
+    TGeoBBox *t2=new TGeoBBox(kS2,0.02/2,0.04/2); //TGeoBBox *t2=new TGeoBBox(kS2,0.01,0.02);
+    TGeoVolume *volT2=new TGeoVolume("TopFilament", t2, medM60J3K);
+    volT2->SetLineColor(12);
+    volT2->SetFillColor(12); 
+    for(int i=0;i<loop;i++){// i<28;i++){
+      mechLaddVol->AddNode(volT2,i*4+1,new TGeoCombiTrans(x+kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
+      mechLaddVol->AddNode(volT2,i*4+2,new TGeoCombiTrans(x-kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
+      mechLaddVol->AddNode(volT2,i*4+3,new TGeoCombiTrans(x+kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
+      mechLaddVol->AddNode(volT2,i*4+4,new TGeoCombiTrans(x-kWidth,y+kHeight+(0.12/2)-0.014+0.007,z-kStaveLength+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
+//    mechLaddVol->AddNode(volT2,i*4+1,new TGeoCombiTrans(x+kWidth+0.0036,y+kHeight-(0.12/2)+0.072,z+kStaveLength+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
+
+ }
+    //wall side structure out
+    TGeoBBox *box4 = new TGeoBBox(0.03/2,0.12/2,kStaveLength-0.50);
+    TGeoVolume *plate4 = new TGeoVolume("WallOut",box4,medM60J3K);
+    plate4->SetFillColor(35);
+    plate4->SetLineColor(35);
+    mechLaddVol->AddNode(plate4,1,new TGeoCombiTrans(x+(2*kStaveWidth/4)-(0.03/2),y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate4",0,0,0)));
+    mechLaddVol->AddNode(plate4,2,new TGeoCombiTrans(x-(2*kStaveWidth/4)+(0.03/2),y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate4",0,0,0)));
+    //wall side in
+    TGeoBBox *box5 = new TGeoBBox(0.015/2,0.12/2,kStaveLength-0.50);
+    TGeoVolume *plate5 = new TGeoVolume("WallIn",box5,medM60J3K);
+    plate5->SetFillColor(12);
+    plate5->SetLineColor(12);
+    mechLaddVol->AddNode(plate5,1,new TGeoCombiTrans(x+(2*kStaveWidth/4)-0.03-0.015/2,y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate5",0,0,0)));
+    mechLaddVol->AddNode(plate5,2,new TGeoCombiTrans(x-(2*kStaveWidth/4)+0.03+0.015/2,y-0.0022-kConeOutRadius+0.12/2+0.007,z,new TGeoRotation("plate5",0,0,0)));
+
+     //Amec Thermasol red-2 cover tube FGS300
+    TGeoConeSeg *cons1 = new TGeoConeSeg(kStaveLength-0.50,kConeOutRadius,kConeOutRadius+kLay1,kConeOutRadius,kConeOutRadius+kLay1,0,180);
+    TGeoVolume *cone11 = new TGeoVolume("ThermasolPipeCover",cons1,medFGS003);
+    cone11->SetFillColor(2);
+    cone11->SetLineColor(2);
+    mechLaddVol->AddNode(cone11,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("Cone11",0,0,0)));
+    mechLaddVol->AddNode(cone11,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("Cone11",0,0,0)));
+
+    TGeoBBox *box2 = new TGeoBBox((0.50-(2*kConeOutRadius))/2,kLay1/2,kStaveLength-0.50);
+    TGeoVolume *plate2 = new TGeoVolume("ThermasolMiddle",box2,medFGS003);
+    plate2->SetFillColor(2);
+    plate2->SetLineColor(2);
+    mechLaddVol->AddNode(plate2,1,new TGeoCombiTrans(x,y-kConeOutRadius+(kLay1/2),z,new TGeoRotation("plate2",0,0,0)));
+
+    TGeoBBox *box21 = new TGeoBBox((0.75-0.25-kConeOutRadius-kLay1)/2,kLay1/2,kStaveLength-0.50);
+    TGeoVolume *plate21 = new TGeoVolume("ThermasolLeftRight",box21,medFGS003);
+    plate21->SetFillColor(2);
+    plate21->SetLineColor(2);
+    mechLaddVol->AddNode(plate21,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(0.75-0.25-kConeOutRadius)/2-(kLay1/2),y-kConeOutRadius+(kLay1/2),z,new TGeoRotation("plate21",0,0,0)));
+    mechLaddVol->AddNode(plate21,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-(0.75-0.25-kConeOutRadius)/2+(kLay1/2),y-kConeOutRadius+(kLay1/2),z,new TGeoRotation("plate21",0,0,0)));
+
+    TGeoBBox *box22 = new TGeoBBox((kLay1/2),kConeOutRadius/2,kStaveLength-0.50);
+    TGeoVolume *plate22 = new TGeoVolume("ThermasolVertical",box22,medFGS003);
+    plate22->SetFillColor(2);
+    plate22->SetLineColor(2);
+    mechLaddVol->AddNode(plate22,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+    mechLaddVol->AddNode(plate22,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+    mechLaddVol->AddNode(plate22,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+    mechLaddVol->AddNode(plate22,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-(kLay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+
+    //C Fleece
+    TGeoConeSeg *cons2 = new TGeoConeSeg(kStaveLength-0.50,kConeOutRadius+kLay1,kConeOutRadius+kLay1+kLay2,kConeOutRadius+kLay1,kConeOutRadius+kLay1+kLay2,0,180); 
+    TGeoVolume *cone12 = new TGeoVolume("CFleecePipeCover",cons2,medCarbonFleece);
+    cone12->SetFillColor(28);
+    cone12->SetLineColor(28);
+    mechLaddVol->AddNode(cone12,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("Cone12",0,0,0)));
+    mechLaddVol->AddNode(cone12,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("Cone12",0,0,0)));
+
+    TGeoBBox *box3 = new TGeoBBox((0.50-(2*(kConeOutRadius+kLay1)))/2,kLay2/2,kStaveLength-0.50);
+    TGeoVolume *plate3 = new TGeoVolume("CFleeceMiddle",box3,medCarbonFleece);
+    plate3->SetFillColor(28);
+    plate3->SetLineColor(28);
+    mechLaddVol->AddNode(plate3,1,new TGeoCombiTrans(x,y-kConeOutRadius+kLay1+(kLay2/2),z,new TGeoRotation("plate3",0,0,0)));
+
+    TGeoBBox *box31 = new TGeoBBox((0.75-0.25-kConeOutRadius-kLay1)/2,kLay2/2,kStaveLength-0.50);
+    TGeoVolume *plate31 = new TGeoVolume("CFleeceLeftRight",box31,medCarbonFleece);
+    plate31->SetFillColor(28);
+    plate31->SetLineColor(28);
+    mechLaddVol->AddNode(plate31,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+kLay1+(0.75-0.25-kConeOutRadius-kLay1)/2,y-kConeOutRadius+kLay1+(kLay2/2),z,new TGeoRotation("plate31",0,0,0)));
+    mechLaddVol->AddNode(plate31,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-kLay1-(0.75-0.25-kConeOutRadius-kLay1)/2,y-kConeOutRadius+kLay1+(kLay2/2),z,new TGeoRotation("plate31",0,0,0)));
+
+    TGeoBBox *box32 = new TGeoBBox((kLay2/2),(kConeOutRadius-kLay1)/2,kStaveLength-0.50);
+    TGeoVolume *plate32 = new TGeoVolume("CFleeceVertical",box32,medCarbonFleece);
+    plate32->SetFillColor(28);
+    plate32->SetLineColor(28);
+    mechLaddVol->AddNode(plate32,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+kLay1+(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+    mechLaddVol->AddNode(plate32,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-kLay1-(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+    mechLaddVol->AddNode(plate32,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+kLay1+(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+    mechLaddVol->AddNode(plate32,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-kLay1-(kLay2/2),y+(kLay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+
+
+    //K13D2U carbon plate
+    TGeoBBox *box1 = new TGeoBBox(2*kWidth,kLay3/2,kStaveLength-0.50);
+    TGeoVolume *plate1 = new TGeoVolume("CarbonPlate",box1,medK13D2U2k);
+    plate1->SetFillColor(5);
+    plate1->SetLineColor(5);
+    mechLaddVol->AddNode(plate1,1,new TGeoCombiTrans(x,y-(kConeOutRadius+(kLay3/2)),z,new TGeoRotation("plate1",0,0,0)));
+
+    //C Fleece bottom plate 
+    TGeoBBox *box6 = new TGeoBBox(2*kWidth,kLay2/2,kStaveLength-0.50);
+    TGeoVolume *plate6 = new TGeoVolume("CFleeceBottom",box6,medCarbonFleece);
+    plate6->SetFillColor(2);
+    plate6->SetLineColor(2);
+    mechLaddVol->AddNode(plate6,1,new TGeoCombiTrans(x,y-(kConeOutRadius+kLay3+(kLay2/2)),z,new TGeoRotation("plate1",0,0,0)));
+      
+      
+  }
+
+  if (fBuildLevel < 2) {
+    //Glue layers and kapton
+    TGeoBBox *glue = new TGeoBBox(kStaveWidth/2, 0.005/2, zlad);
+    TGeoVolume *volGlue=new TGeoVolume("Glue", glue, medGlue);
+    volGlue->SetLineColor(5);
+    volGlue->SetFillColor(5); 
+    mechLaddVol->AddNode(volGlue, 0, new TGeoCombiTrans(x,y-(kConeOutRadius+kLay3+(kLay2/2)+(0.01/2)), z, new TGeoRotation("",0, 0, 0)));
+    mechLaddVol->AddNode(volGlue, 1, new TGeoCombiTrans(x,y-(kConeOutRadius+kLay3+(kLay2/2)+0.01+fSensorThick+(0.01/2)), z, new TGeoRotation("",0, 0, 0)));
+  }
+
+  if (fBuildLevel < 1) {
+    TGeoBBox *kapCable = new TGeoBBox(kStaveWidth/2, 0.01/2, zlad);
+    TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
+    volCable->SetLineColor(28);
+    volCable->SetFillColor(28); 
+    mechLaddVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-(kConeOutRadius+kLay3+(kLay2/2)+0.01+fSensorThick+0.01+(0.01/2)), z, new TGeoRotation("",0, 0, 0)));
+  }
+    
+
+  // Done, return the stave structure
+  return mechLaddVol;
+  
+}
+// new model22
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB22(const Double_t xlad,
+                                                    const Double_t zlad,
+                                                    const TGeoManager *mgr){
+//
+// Create the mechanical stave structure for Model 2.2 of TDR
+//
+// Input:
+//         xlad : X length
+//         zlad : Z length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Mar 2013  Chinorat Kobdaj
+// Updated:      26 Apr 2013  Mario Sitta
+// Updated:      30 Apr 2013  Wanchaloem Poonsawat 
+//
+  
+  // Materials defined in AliITSUv1
+  TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
+  TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
+
+  TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
+  TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
+  TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
+  TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
+  TGeoMedium *medK13D2U2k  = mgr->GetMedium("ITS_K13D2U2k$");
+  TGeoMedium *medFGS003    = mgr->GetMedium("ITS_FGS003$"); 
+  TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
+
+  // Local parameters
+  Double_t kConeOutRadius =0.107/2;//0.107/2;
+  Double_t kConeInRadius = 0.1015/2;//0.10105/2
+  Double_t kStaveLength = zlad;
+  Double_t kStaveWidth = xlad*2;
+  Double_t kWidth = (kStaveWidth)/4;
+  Double_t kStaveHeight = 0.283;//0.33;
+  Double_t kHeight = (kStaveHeight)/2;
+  Double_t kAlpha = 57;//56.31;
+  Double_t kTheta = kAlpha*TMath::DegToRad();
+  Double_t kS1 = ((kStaveWidth)/4)/TMath::Sin(kTheta);
+  Double_t kL1 = (kStaveWidth/4)/TMath::Tan(kTheta);
+  Double_t kS2 = sqrt(kHeight*kHeight + kS1*kS1);//TMath::Sin(kThe2);
+  Double_t kThe2 = TMath::ATan(kHeight/(0.375-0.036));
+  Double_t kBeta = kThe2*TMath::RadToDeg();
+  Double_t klay1 = 0.003;//Amec carbon
+  Double_t klay2 = 0.002;//C Fleece carbon
+  Double_t klay3 = 0.007;//CFplate K13D2U carbon
+  Double_t klay4 = 0.007;//GluekStaveLength/2
+  Double_t klay5 = 0.01;//Flex cable
+  Double_t kTopVertexMaxWidth = 0.072;
+  Double_t kTopVertexHeight = 0.04;
+  Double_t kSideVertexMWidth = 0.052;
+  Double_t kSideVertexHeight = 0.11; 
+
+  Int_t  loop = (Int_t)(kStaveLength/(2*kL1));
+
+  char volname[30];
+  snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSLadderPattern(), fLayerNumber);
+
+  Double_t z=0, y=-(2*kConeOutRadius)+klay1+klay2+fSensorThick/2-0.0004, x=0;
+
+  TGeoVolume *mechLaddVol = 0;
+
+  if (fBuildLevel < 5) {
+    // world (trapezoid)
+    TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
+    Double_t xv[6] = {kStaveWidth/2,kStaveWidth/2,0.012,-0.012,-kStaveWidth/2,-kStaveWidth/2}; 
+    /* Double_t yv[6] = {-2*(kConeOutRadius+klay1+1.5*klay2+klay3+klay4+fSensorThick+klay5),
+                        0-0.02,kStaveHeight+0.01,kStaveHeight+0.01,0-0.02,
+                       -2*(kConeOutRadius+klay1+1.5*klay2+klay3+klay4+fSensorThick+klay5)};  // (kConeOutRadius*2)-0.0635 */
+    Double_t yv[6] = {-(kConeOutRadius*2)-0.06395,0-0.02,kStaveHeight+0.01,kStaveHeight+0.01,0-0.02,-(kConeOutRadius*2)-0.06395};  // (kConeOutRadius*2)-0.064
+    mechStruct->DefinePolygon(6,xv,yv);
+    mechStruct->DefineSection(0,-kStaveLength,0,0,1.);
+    mechStruct->DefineSection(1,kStaveLength,0,0,1.);
+
+    mechLaddVol = new TGeoVolume(volname, mechStruct, medAir);
+    mechLaddVol->SetLineColor(12);
+    mechLaddVol->SetFillColor(12); 
+    mechLaddVol->SetVisibility(kTRUE);  
+      
+    //Polyimide Pipe Kapton grey-35 
+    TGeoCone *cone1 = new TGeoCone(kStaveLength,kConeInRadius,kConeOutRadius-0.0001,kConeInRadius,kConeOutRadius-0.0001);
+    TGeoVolume *volCone1= new TGeoVolume("PolyimidePipe", cone1, medKapton);
+    volCone1->SetFillColor(35);
+    volCone1->SetLineColor(35);
+    mechLaddVol->AddNode(volCone1,1,new TGeoTranslation(x+0.25,y,z));
+    mechLaddVol->AddNode(volCone1,2,new TGeoTranslation(x-0.25,y,z));
+    }
+
+  if (fBuildLevel < 4) {
+    TGeoTube *coolTubeW = new TGeoTube(0.,kConeInRadius-0.0001,kStaveLength);
+    TGeoVolume *volCoolTubeW= new TGeoVolume("Water", coolTubeW, medWater);
+    volCoolTubeW->SetFillColor(4);
+    volCoolTubeW->SetLineColor(4);
+    mechLaddVol->AddNode(volCoolTubeW,0,new TGeoTranslation(x-0.25,y,z));
+    mechLaddVol->AddNode(volCoolTubeW,1,new TGeoTranslation(x+0.25,y,z));
+  }
+
+  if (fBuildLevel < 3) {
+    //top fillament
+    // Top filament M60J black-12 Carbon structure TGeoBBox (length,thickness,width)
+    TGeoBBox *t2=new TGeoBBox(kS2-0.028,0.02/2,0.02/2); //0.04/2//TGeoBBox *t2=new TGeoBBox(kS2,0.01,0.02);//kS2-0.03 old Config.C
+    TGeoVolume *volT2=new TGeoVolume("TopFilament", t2, medM60J3K);
+    volT2->SetLineColor(12);
+    volT2->SetFillColor(12); 
+    for(int i=0;i<loop;i++){// i<28;i++){
+      // 1) Front Left Top Filament
+       mechLaddVol->AddNode(volT2,i*4+1,new TGeoCombiTrans(x+kWidth+0.0036,y+kHeight+0.01,z-kStaveLength+0.1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,90-kBeta)));
+      // 2) Front Right Top Filament
+      mechLaddVol->AddNode(volT2,i*4+2,new TGeoCombiTrans(x-kWidth-0.0036,y+kHeight+0.01,z-kStaveLength+0.1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,-90+kBeta)));
+      // 3) Back Left  Top Filament
+      mechLaddVol->AddNode(volT2,i*4+3,new TGeoCombiTrans(x+kWidth+0.0036,y+kHeight+0.01,z-kStaveLength+0.1+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,-90+kAlpha,90-kBeta)));
+      // 4) Back Right Top Filament
+      mechLaddVol->AddNode(volT2,i*4+4,new TGeoCombiTrans(x-kWidth-0.0036,y+kHeight+0.01,z-kStaveLength+0.1+2*kL1+(i*4*kL1)+kS1/2, new TGeoRotation("volT2",90,90-kAlpha,-90+kBeta)));
+   }
+     //Vertex  structure 
+
+      //top ver trd1
+      TGeoTrd1 *trd1 = new TGeoTrd1(0,kTopVertexMaxWidth/2,kStaveLength,kTopVertexHeight/2);
+      TGeoVolume *ibdv = new TGeoVolume("TopVertex",trd1,medM60J3K);
+      ibdv->SetFillColor(12);
+      ibdv->SetLineColor(12);
+      mechLaddVol->AddNode(ibdv,1,new TGeoCombiTrans(x,y+kStaveHeight+0.03,z,new TGeoRotation("ibdv",0.,-90,0)));//y+kStaveHeight+0.056
+
+      //left trd2
+      TGeoTrd1 *trd2 = new TGeoTrd1(0,kSideVertexMWidth/2,kStaveLength, kSideVertexHeight/2);
+      TGeoVolume *ibdv2 = new TGeoVolume("LeftVertex",trd2,medM60J3K);
+      ibdv2->SetFillColor(12);
+      ibdv2->SetLineColor(12);
+      mechLaddVol->AddNode(ibdv2,1,new TGeoCombiTrans(x+kStaveWidth/2-0.06,y-0.0355,z,new TGeoRotation("ibdv2",-103.3,90,0))); //x-kStaveWidth/2-0.09 old Config.C y-0.0355,
+
+      //right trd3
+      TGeoTrd1 *trd3 = new TGeoTrd1(0,kSideVertexMWidth/2,kStaveLength, kSideVertexHeight/2);
+      TGeoVolume *ibdv3 = new TGeoVolume("RightVertex",trd3,medM60J3K);
+      ibdv3->SetFillColor(12);
+      ibdv3->SetLineColor(12);
+      mechLaddVol->AddNode(ibdv3,1,new TGeoCombiTrans(x-kStaveWidth/2+0.06,y-0.0355,z,new TGeoRotation("ibdv3",103.3,90,0))); //x-kStaveWidth/2+0.09 old Config.C
+      
+     //Carbon Fleece
+      TGeoConeSeg *cons2 = new TGeoConeSeg(zlad,kConeOutRadius+klay1,kConeOutRadius+klay1+klay2,kConeOutRadius+klay1,kConeOutRadius+klay1+klay2,0,180); 
+      TGeoVolume *cone12 = new TGeoVolume("CarbonFleecePipeCover",cons2,medCarbonFleece);
+      cone12->SetFillColor(28);
+      cone12->SetLineColor(28);
+      mechLaddVol->AddNode(cone12,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("cone12",0,0,0)));
+      mechLaddVol->AddNode(cone12,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("cone12",0,0,0)));
+
+      TGeoBBox *box3 = new TGeoBBox((0.50-(2*(kConeOutRadius+klay1)))/2,klay2/2,zlad);//kStaveLength-0.50);
+      TGeoVolume *plate3 = new TGeoVolume("CarbonFleeceMiddle",box3,medCarbonFleece);
+      plate3->SetFillColor(28);
+      plate3->SetLineColor(28);
+      mechLaddVol->AddNode(plate3,1,new TGeoCombiTrans(x,y-kConeOutRadius+klay1+(klay2/2),z,new TGeoRotation("plate3",0,0,0)));
+
+      TGeoBBox *box31 = new TGeoBBox((0.75-0.25-kConeOutRadius-klay1)/2+0.0025,klay2/2,zlad);
+      TGeoVolume *plate31 = new TGeoVolume("CarbonFleeceLeftRight",box31,medCarbonFleece);
+      plate31->SetFillColor(28);
+      plate31->SetLineColor(28);
+      mechLaddVol->AddNode(plate31,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+klay1+(0.75-0.25-kConeOutRadius-klay1)/2,y-kConeOutRadius+klay1+(klay2/2),z,new TGeoRotation("plate31",0,0,0)));
+      mechLaddVol->AddNode(plate31,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-klay1-(0.75-0.25-kConeOutRadius-klay1)/2,y-kConeOutRadius+klay1+(klay2/2),z,new TGeoRotation("plate31",0,0,0)));
+
+      TGeoBBox *box32 = new TGeoBBox((klay2/2),(kConeOutRadius-klay1)/2,zlad);
+      TGeoVolume *plate32 = new TGeoVolume("CarbonFleeceVertical",box32,medCarbonFleece);
+      plate32->SetFillColor(28);
+      plate32->SetLineColor(28);
+      mechLaddVol->AddNode(plate32,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+klay1+(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+      mechLaddVol->AddNode(plate32,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-klay1-(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+      mechLaddVol->AddNode(plate32,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+klay1+(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+      mechLaddVol->AddNode(plate32,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-klay1-(klay2/2),y+(klay1-kConeOutRadius)/2,z,new TGeoRotation("plate32",0,0,0)));
+
+     //Amec Thermasol red-2 cover tube FGS300 or Carbon Paper
+      TGeoConeSeg *cons1 = new TGeoConeSeg(zlad,kConeOutRadius,kConeOutRadius+klay1-0.0001,kConeOutRadius,kConeOutRadius+klay1-0.0001,0,180);//kConeOutRadius+klay1-0.0001
+      TGeoVolume *cone11 = new TGeoVolume("ThermasolPipeCover",cons1,medFGS003);
+      cone11->SetFillColor(2);
+      cone11->SetLineColor(2);
+      mechLaddVol->AddNode(cone11,1,new TGeoCombiTrans(x+0.25,y,z,new TGeoRotation("cone11",0,0,0)));
+      mechLaddVol->AddNode(cone11,2,new TGeoCombiTrans(x-0.25,y,z,new TGeoRotation("cone11",0,0,0)));
+
+      TGeoBBox *box2 = new TGeoBBox((0.50-(2*kConeOutRadius))/2,(klay1/2),zlad);//kStaveLength-0.50);
+      TGeoVolume *plate2 = new TGeoVolume("ThermasolMiddle",box2,medFGS003);
+      plate2->SetFillColor(2);
+      plate2->SetLineColor(2);
+      mechLaddVol->AddNode(plate2,1,new TGeoCombiTrans(x,y-kConeOutRadius+(klay1/2),z,new TGeoRotation("plate2",0,0,0)));
+
+      TGeoBBox *box21 = new TGeoBBox((0.75-0.25-kConeOutRadius-klay1)/2+0.0025,(klay1/2),zlad);
+      TGeoVolume *plate21 = new TGeoVolume("ThermasolLeftRight",box21,medFGS003);
+      plate21->SetFillColor(2);
+      plate21->SetLineColor(2);
+      mechLaddVol->AddNode(plate21,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(0.75-0.25-kConeOutRadius)/2-(klay1/2)+0.0025,y-kConeOutRadius+(klay1/2),z,new TGeoRotation("plate21",0,0,0)));
+      mechLaddVol->AddNode(plate21,2,new TGeoCombiTrans(x-0.25-kConeOutRadius-(0.75-0.25-kConeOutRadius)/2+(klay1/2)-0.0025,y-kConeOutRadius+(klay1/2),z,new TGeoRotation("plate21",0,0,0)));
+
+      TGeoBBox *box22 = new TGeoBBox((klay1/2),kConeOutRadius/2,zlad);
+      TGeoVolume *plate22 = new TGeoVolume("ThermasolVertical",box22,medFGS003);
+      plate22->SetFillColor(2);
+      plate22->SetLineColor(2);
+      mechLaddVol->AddNode(plate22,1,new TGeoCombiTrans(x+0.25+kConeOutRadius+(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+      mechLaddVol->AddNode(plate22,2,new TGeoCombiTrans(x+0.25-kConeOutRadius-(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+      mechLaddVol->AddNode(plate22,3,new TGeoCombiTrans(x-0.25+kConeOutRadius+(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+      mechLaddVol->AddNode(plate22,4,new TGeoCombiTrans(x-0.25-kConeOutRadius-(klay1/2),y-kConeOutRadius/2,z,new TGeoRotation("plate22",0,0,0)));
+
+     //K13D2U CF plate
+      TGeoBBox *box1 = new TGeoBBox(2*kWidth,(klay3)/2,zlad);
+      TGeoVolume *plate1 = new TGeoVolume("CFPlate",box1,medK13D2U2k);
+      plate1->SetFillColor(5);
+      plate1->SetLineColor(5);
+      mechLaddVol->AddNode(plate1,1,new TGeoCombiTrans(x,y-(kConeOutRadius+(klay3/2)),z,new TGeoRotation("plate1",0,0,0)));
+
+     //C Fleece bottom plate 
+      TGeoBBox *box6 = new TGeoBBox(2*kWidth,(klay2)/2,zlad);
+      TGeoVolume *plate6 = new TGeoVolume("CarbonFleeceBottom",box6,medCarbonFleece);
+      plate6->SetFillColor(2);
+      plate6->SetLineColor(2);
+      mechLaddVol->AddNode(plate6,1,new TGeoCombiTrans(x,y-(kConeOutRadius+klay3+(klay2/2)),z,new TGeoRotation("plate6",0,0,0)));
+
+    }
+   if (fBuildLevel < 2) {
+      //Glue klayers and kapton
+     TGeoBBox *glue = new TGeoBBox(kStaveWidth/2, (klay4)/2, zlad);
+      TGeoVolume *volGlue=new TGeoVolume("Glue", glue, medGlue);
+      volGlue->SetLineColor(5);
+      volGlue->SetFillColor(5); 
+      // mechLaddVol->AddNode(volGlue, 0, new TGeoCombiTrans(x,y-(kConeOutRadius+klay3+klay2+(klay4/2)), z, new TGeoRotation("",0, 0, 0)));
+      mechLaddVol->AddNode(volGlue, 0, new TGeoCombiTrans(x,y-(kConeOutRadius+klay3+klay2+(klay4)/2)+0.00005, z, new TGeoRotation("",0, 0, 0)));
+    }
+
+     if (fBuildLevel < 1) {
+     //Flex Cable or Bus
+      TGeoBBox *kapCable = new TGeoBBox(kStaveWidth/2, klay5/2, zlad);//klay5/2
+      TGeoVolume *volCable=new TGeoVolume("FlexCable", kapCable, medFlexCable);
+      volCable->SetLineColor(28);
+      volCable->SetFillColor(28); 
+      //      mechLaddVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-(kConeOutRadius+klay3+klay2+klay4+fSensorThick+(klay5)/2)+0.0002, z, new TGeoRotation("",0, 0, 0)));
+      mechLaddVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-(kConeOutRadius+klay3+klay2+klay4+fSensorThick+(klay5)/2)+0.01185, z, new TGeoRotation("",0, 0, 0)));
+      }
+    // Done, return the stave structe
+    return mechLaddVol;
+}
+
+// model3
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelInnerB3(const Double_t xlad,
+                                                   const Double_t zlad,
+                                                   const TGeoManager *mgr){
+//
+// Create the mechanical stave structure for Model 3 of TDR
+//
+// Input:
+//         xlad : X length
+//         zlad : Z length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      28 May 2013  Chinorat Kobdaj
+// Updated:                   Mario Sitta
+// Updated:                   Wanchaloem Poonsawat 
+//
+  
+  // Materials defined in AliITSUv1
+  TGeoMedium *medAir    = mgr->GetMedium("ITS_AIR$");
+  TGeoMedium *medWater  = mgr->GetMedium("ITS_WATER$");
+
+  TGeoMedium *medM60J3K    = mgr->GetMedium("ITS_M60J3K$"); 
+  TGeoMedium *medKapton    = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
+  TGeoMedium *medGlue      = mgr->GetMedium("ITS_GLUE$");
+  TGeoMedium *medFlexCable = mgr->GetMedium("ITS_FLEXCABLE$");
+  //TGeoMedium *medK13D2U2k  = mgr->GetMedium("ITS_K13D2U2k$");
+  //TGeoMedium *medFGS003    = mgr->GetMedium("ITS_FGS003$"); 
+  //TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
+
+  // Local parameters
+    Double_t kConeOutRadius = 0.15/2;
+    Double_t kStaveLength = zlad*2;
+    Double_t kStaveWidth = xlad*2;
+    Double_t w = kStaveWidth/4;//1/2 of W
+    Double_t staveHeight = 0.3;
+    Double_t h = staveHeight/2;
+    Double_t alpha = 90-33.;//90-30;
+    Double_t the1 = alpha*TMath::DegToRad();
+    Double_t s1 = w/TMath::Sin(the1);
+    Double_t l = w/TMath::Tan(the1);
+    Double_t s2 = TMath::Sqrt(h*h + s1*s1);//TMath::Sin(the2);
+    Double_t the2 = TMath::ATan(h/s1);
+    Double_t beta = the2*TMath::RadToDeg();
+    Double_t klay4 = 0.007; //Glue
+    Double_t klay5 = 0.01; //Flexcable
+    Int_t  loop = (Int_t)((kStaveLength/(2*l))/2);
+    Double_t hh = 0.01;
+       Double_t ang1 = 0*TMath::DegToRad();
+       Double_t ang2 = 0*TMath::DegToRad();
+       Double_t ang3 = 0*TMath::DegToRad();
+       Int_t modules = 4;
+       Double_t headWidth=0.25;
+       Double_t smcLength=kStaveLength/modules-2*headWidth;//6.25;
+       Double_t smcWidth=kStaveWidth;
+       Double_t smcSide1Thick=0.03;
+       Double_t vaporThick=0.032;
+       Double_t liquidThick=0.028;
+       Double_t smcSide2Thick=0.01;
+       Double_t smcSide3Thick=0.0055;
+       Double_t smcSide4Thick=0.0095;
+       Double_t smcSide5Thick=0.0075;
+       Double_t smcSpace=0.01;
+
+
+    char volname[30];
+    snprintf(volname, 30, "%s%d_StaveStruct", AliITSUGeomTGeo::GetITSLadderPattern(), fLayerNumber);
+    
+    // detailed structure ++++++++++++++
+    Double_t z=0, y=0-0.007, x=0;
+
+    // Polimide micro channels numbers
+    Double_t yMC = y-h+0.01;
+    Int_t nb = (Int_t)(kStaveWidth/0.1)+1;
+    Double_t xladMC = (nb*0.1-0.08)/2;
+
+
+    TGeoVolume *mechLaddVol = 0;
+    if (fBuildLevel < 5) {
+      // world (trapezoid)
+      TGeoXtru *mechStruct = new TGeoXtru(2); //z sections
+      Double_t xv[5] = {kStaveWidth/2+0.1,kStaveWidth/2+0.1,0,-kStaveWidth/2-0.1,-kStaveWidth/2-0.1};
+      Double_t yv[5] = {-kConeOutRadius*2-0.07,0,staveHeight,0,-kConeOutRadius*2-0.07};    
+      mechStruct->DefinePolygon(5,xv,yv);
+      mechStruct->DefineSection(0,-kStaveLength-0.1,0,0,1.);
+      mechStruct->DefineSection(1,kStaveLength+0.1,0,0,1.);
+      mechLaddVol = new TGeoVolume(volname, mechStruct, medAir);
+      mechLaddVol->SetLineColor(12);
+      mechLaddVol->SetFillColor(12); 
+      mechLaddVol->SetVisibility(kTRUE);
+
+       // Silicon micro channels numbers
+      
+      TGeoBBox *tM0a=new TGeoBBox(smcWidth/2, 0.003/2, headWidth/2);
+      TGeoVolume *volTM0a=new TGeoVolume("microChanTop1", tM0a, medKapton);
+      volTM0a->SetLineColor(35);
+      volTM0a->SetFillColor(35); 
+
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0a, 0, new TGeoCombiTrans(x,yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));
+      mechLaddVol->AddNode(volTM0a, 1, new TGeoCombiTrans(x,yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));
+      }
+      TGeoBBox *tM0c=new TGeoBBox(0.3/2, 0.003/2,smcLength/2);
+      TGeoVolume *volTM0c=new TGeoVolume("microChanTop2", tM0c, medKapton);
+      volTM0c->SetLineColor(35);
+      volTM0c->SetFillColor(35); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0c, 0, new TGeoCombiTrans(x+(smcWidth/2)-(0.3/2),yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));
+      mechLaddVol->AddNode(volTM0c, 1, new TGeoCombiTrans(x-(smcWidth/2)+(0.3/2),yMC+0.03, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0c1=new TGeoBBox(0.2225/2, 0.003/2,smcLength/2);
+      TGeoVolume *volTM0c1=new TGeoVolume("microChanBot1", tM0c1, medKapton);
+      volTM0c1->SetLineColor(6);
+      volTM0c1->SetFillColor(6); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0c1, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick)-(0.2225/2),yMC+0.03-hh-(0.003), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      mechLaddVol->AddNode(volTM0c1, 1, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick)+(smcSide4Thick)+(0.2225/2),yMC+0.03-hh-(0.003), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0c2=new TGeoBBox(0.072/2, 0.003/2,smcLength/2);
+      TGeoVolume *volTM0c2=new TGeoVolume("microChanBot2", tM0c2, medKapton);
+      volTM0c2->SetLineColor(35);
+      volTM0c2->SetFillColor(35); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0c2, 0, new TGeoCombiTrans(x+smcWidth/2-(0.072/2),yMC+0.03-(0.035+0.0015)-(0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0c2r=new TGeoBBox(0.068/2, 0.003/2,smcLength/2);
+      TGeoVolume *volTM0c2r=new TGeoVolume("microChanBot3", tM0c2r, medKapton);
+      volTM0c2r->SetLineColor(35);
+      volTM0c2r->SetFillColor(35); 
+      for(Int_t  mo=1; mo<=modules; mo++) {      
+      mechLaddVol->AddNode(volTM0c2r, 0, new TGeoCombiTrans(x-smcWidth/2+(0.068/2),yMC+0.03-(0.035+0.0015)-(0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0d=new TGeoBBox(smcSide1Thick/2, 0.035/2,smcLength/2);
+      TGeoVolume *volTM0d=new TGeoVolume("microChanSide1", tM0d, medKapton);
+      volTM0d->SetLineColor(12);
+      volTM0d->SetFillColor(12); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0d, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      mechLaddVol->AddNode(volTM0d, 1, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+
+      TGeoBBox *tM0d1=new TGeoBBox(smcSide2Thick/2, 0.035/2,smcLength/2);
+      TGeoVolume *volTM0d1=new TGeoVolume("microChanSide2", tM0d1, medKapton);
+      volTM0d1->SetLineColor(12);
+      volTM0d1->SetFillColor(12); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0d1, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick/2),yMC+0.03-(0.003+0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      mechLaddVol->AddNode(volTM0d1, 1, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick/2),yMC+0.03-(0.003+0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0d2=new TGeoBBox(smcSide3Thick/2, (hh+0.003)/2, smcLength/2);
+      TGeoVolume *volTM0d2=new TGeoVolume("microChanSide3", tM0d2, medKapton);
+      volTM0d2->SetLineColor(12);
+      volTM0d2->SetFillColor(12); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0d2, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick/2),yMC+0.03-(0.003+hh+0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0d2r=new TGeoBBox(smcSide4Thick/2, (hh+0.003)/2, smcLength/2);
+      TGeoVolume *volTM0d2r=new TGeoVolume("microChanSide4", tM0d2r, medKapton);
+      volTM0d2r->SetLineColor(12);
+      volTM0d2r->SetFillColor(12); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0d2r, 0, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick)+(smcSide4Thick/2),yMC+0.03-(0.003+hh+0.003)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0e=new TGeoBBox(smcSide5Thick/2, hh/2,smcLength/2);
+      TGeoVolume *volTM0e=new TGeoVolume("microChanSide5", tM0e, medKapton);    
+      volTM0e->SetLineColor(12);
+      volTM0e->SetFillColor(12); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      for (Int_t ie=0;ie<11;ie++) {
+       mechLaddVol->AddNode(volTM0e, 0, new TGeoCombiTrans(x-(ie*(smcSpace+smcSide5Thick))+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick)-smcSpace-(smcSide5Thick/2),yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+       mechLaddVol->AddNode(volTM0e, 1, new TGeoCombiTrans(x+(ie*(smcSpace+smcSide5Thick))-smcWidth/2+(smcSide1Thick)+(liquidThick)+(smcSide2Thick)+(smcSide4Thick)+smcSpace+(smcSide5Thick/2),yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+         }
+      }
+      
+      TGeoBBox *tM0f=new TGeoBBox(0.02/2, hh/2, smcLength/2);
+      TGeoVolume *volTM0f=new TGeoVolume("microChanTop3", tM0f, medKapton);
+      //Double_t smcChannels=12;
+      Double_t smcCloseWallvapor=smcWidth/2-smcSide1Thick-vaporThick-smcSide2Thick-smcSide3Thick-12*smcSpace-11*smcSide5Thick;
+      Double_t smcCloseWallliquid=smcWidth/2-smcSide1Thick-liquidThick-smcSide2Thick-smcSide4Thick-12*smcSpace-11*smcSide5Thick;
+      volTM0f->SetLineColor(12);
+      volTM0f->SetFillColor(12); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+       mechLaddVol->AddNode(volTM0f, 0, new TGeoCombiTrans(x+smcCloseWallvapor-(0.02)/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+       mechLaddVol->AddNode(volTM0f, 1, new TGeoCombiTrans(x-smcCloseWallliquid+(0.02)/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      //Head(back) microchannel
+
+      TGeoBBox *tM0hb=new TGeoBBox(smcWidth/2, 0.025/2, headWidth/2);
+      TGeoVolume *volTM0hb=new TGeoVolume("microChanHeadBackBottom1", tM0hb, medKapton);
+      volTM0hb->SetLineColor(4);
+      volTM0hb->SetFillColor(4); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0hb, 0, new TGeoCombiTrans(x,yMC+0.03-0.0145-(0.025/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      mechLaddVol->AddNode(volTM0hb, 1, new TGeoCombiTrans(x,yMC+0.03-0.0145-(0.025)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-(headWidth/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0h1=new TGeoBBox(smcWidth/2, 0.013/2, 0.05/2);
+      TGeoVolume *volTM0h1=new TGeoVolume("microChanHeadBackBottom2", tM0h1, medKapton);
+      volTM0h1->SetLineColor(5);
+      volTM0h1->SetFillColor(5); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0h1, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-headWidth+(0.05/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0h2=new TGeoBBox(smcWidth/2, 0.003/2, 0.18/2);
+      TGeoVolume *volTM0h2=new TGeoVolume("microChanHeadBackBottom7", tM0h2, medKapton);
+      volTM0h2->SetLineColor(6);
+      volTM0h2->SetFillColor(6);
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0h2, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-0.01-(0.003/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-0.02-(0.18/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0h3=new TGeoBBox(smcWidth/2, 0.013/2, 0.02/2);
+      TGeoVolume *volTM0h3=new TGeoVolume("microChanHeadBackBottom3", tM0h3, medKapton);
+      volTM0h3->SetLineColor(5);
+      volTM0h3->SetFillColor(5); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0h3, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth-smcLength/2-(0.02/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0b1=new TGeoBBox(smcWidth/2, 0.013/2, 0.03/2);
+      TGeoVolume *volTM0b1=new TGeoVolume("microChanHeadBackBottom4", tM0b1, medKapton);
+      volTM0b1->SetLineColor(5);
+      volTM0b1->SetFillColor(5); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0b1, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+headWidth-(0.03/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0b2=new TGeoBBox(smcWidth/2, 0.003/2, 0.2/2);
+      TGeoVolume *volTM0b2=new TGeoVolume("microChanHeadBackBottom5", tM0b2, medKapton);
+      volTM0b2->SetLineColor(6);
+      volTM0b2->SetFillColor(6); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0b2, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-0.01-(0.003/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+0.02+(0.2/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0b3=new TGeoBBox(smcWidth/2, 0.013/2, 0.02/2);
+      TGeoVolume *volTM0b3=new TGeoVolume("microChanHeadBackBottom6", tM0b3, medKapton);
+      volTM0b3->SetLineColor(5);
+      volTM0b3->SetFillColor(5); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0b3, 0, new TGeoCombiTrans(x,yMC+0.03-0.0015-(0.013/2), z+(mo-3)*kStaveLength/4+smcLength/2+headWidth+smcLength/2+(0.02/2), new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+     
+      TGeoBBox *tM0b=new TGeoBBox(0.02/2, 0.02/2, zlad);
+      TGeoVolume *volTM0b=new TGeoVolume("microChanWalls", tM0b, medKapton);
+      volTM0b->SetLineColor(35);
+      volTM0b->SetFillColor(35); 
+      for (Int_t ib=0;ib<nb;ib++) {
+       //mechLaddVol->AddNode(volTM0b, ib, new TGeoCombiTrans(x+ib*0.1-xladMC+0.01,yMC, z, new TGeoRotation("",0, 0, 0)));
+      }
+      
+      } 
+    
+    if (fBuildLevel < 4) {
+
+      //**********cooling  inlet outlet
+
+      TGeoBBox *tM0dv=new TGeoBBox(vaporThick/2, 0.035/2,smcLength/2);
+      TGeoVolume *volTM0dv=new TGeoVolume("microChanVapor", tM0dv, medWater);
+      volTM0dv->SetLineColor(2);
+      volTM0dv->SetFillColor(2);
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0dv, 0, new TGeoCombiTrans(x+smcWidth/2-(smcSide1Thick)-(vaporThick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      TGeoBBox *tM0dl=new TGeoBBox(liquidThick/2, 0.035/2,smcLength/2);
+      TGeoVolume *volTM0dl=new TGeoVolume("microChanLiquid", tM0dl, medWater);
+      volTM0dl->SetLineColor(3);
+      volTM0dl->SetFillColor(3); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      mechLaddVol->AddNode(volTM0dl, 0, new TGeoCombiTrans(x-smcWidth/2+(smcSide1Thick)+(liquidThick/2),yMC+0.03-0.0015-(0.035)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      // small cooling fluid now using water wait for freeon value  
+      TGeoBBox *tM0dlq=new TGeoBBox(smcSpace/2, hh/2,smcLength/2);
+      TGeoVolume *volTM0dlq=new TGeoVolume("smallLiquid", tM0dlq, medWater);
+      volTM0dlq->SetLineColor(3);
+      volTM0dlq->SetFillColor(3); 
+      TGeoBBox *tM0dvp=new TGeoBBox(smcSpace/2, hh/2,smcLength/2);
+      TGeoVolume *volTM0dvp=new TGeoVolume("microChanVapor", tM0dvp, medWater);
+      volTM0dvp->SetLineColor(2);
+      volTM0dvp->SetFillColor(2); 
+      for(Int_t  mo=1; mo<=modules; mo++) {
+      for (Int_t is=0;is<12;is++) {
+       mechLaddVol->AddNode(volTM0dlq, 0, new TGeoCombiTrans(x+(is*(smcSpace+smcSide5Thick))-smcWidth/2+(smcSide1Thick)+(vaporThick)+(smcSide2Thick)+(smcSide3Thick)+smcSpace/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+       mechLaddVol->AddNode(volTM0dvp, 1, new TGeoCombiTrans(x-(is*(smcSpace+smcSide5Thick))+smcWidth/2-(smcSide1Thick)-(vaporThick)-(smcSide2Thick)-(smcSide3Thick)-smcSpace/2,yMC+0.03-(0.003+hh)/2, z+(mo-3)*kStaveLength/4+smcLength/2+headWidth, new TGeoRotation("",ang1, ang2, ang3)));//("",0, 0, 0)));
+      }
+      }
+
+      //*************
+
+    }
+    
+    if (fBuildLevel < 3) {
+
+      //Bottom filament CFRP black-12 Carbon structure TGeoBBox (thickness,width,length)
+      Double_t filWidth = 0.04;
+      Double_t filHeight= 0.02;
+      TGeoBBox *t1=new TGeoBBox(filHeight/2,filWidth/2,s1);
+      TGeoVolume *volT1=new TGeoVolume("bottomFilament", t1, medM60J3K);
+      volT1->SetLineColor(12);
+      volT1->SetFillColor(12); 
+      for(int i=0;i<loop;i++){//i<30;i++){
+               mechLaddVol->AddNode(volT1,4*i+0,
+                                   new TGeoCombiTrans(x+w,y-h+0.04+filHeight/2,z-kStaveLength/2+(4*l*i)+s1/2, 
+                                                      new TGeoRotation("volT1",-90,alpha,0)));
+       mechLaddVol->AddNode(volT1,4*i+1,
+                                   new TGeoCombiTrans(x-w,y-h+0.04+filHeight/2,z-kStaveLength/2+(4*l*i)+s1/2, 
+                                                      new TGeoRotation("volT1",90,alpha,0)));
+       mechLaddVol->AddNode(volT1,4*i+2,
+                                   new TGeoCombiTrans(x+w,y-h+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2, 
+                                                      new TGeoRotation("volT1",-90,-alpha,0)));
+       mechLaddVol->AddNode(volT1,4*i+3,
+                                   new TGeoCombiTrans(x-w,y-h+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2, 
+                                                      new TGeoRotation("volT1",-90,+alpha,0)));
+       }
+     // Top filament CERP black-12 Carbon structure TGeoBBox (length,thickness,width)
+
+      TGeoBBox *t2=new TGeoBBox(s2,filHeight/2,filWidth/2);
+      TGeoVolume *volT2=new TGeoVolume("topFilament", t2, medM60J3K);
+      volT2->SetLineColor(12);
+      volT2->SetFillColor(12); 
+      for(int i=0;i<loop;i++){ //i<30;i++){
+               mechLaddVol->AddNode(volT2,4*i+0,
+                                   new TGeoCombiTrans(x+w,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*l)+s1/2,
+                                                      new TGeoRotation("volT2",90,90-alpha,90-beta)));
+       mechLaddVol->AddNode(volT2,4*i+1,
+                                   new TGeoCombiTrans(x-w,y+0.04+filHeight/2,z-kStaveLength/2+(i*4*l)+s1/2,
+                                                      new TGeoRotation("volT2",90,-90+alpha,-90+beta)));
+       mechLaddVol->AddNode(volT2,4*i+2,
+                                   new TGeoCombiTrans(x+w,y+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2,
+                                                      new TGeoRotation("volT2",90,-90+alpha,90-beta)));
+       mechLaddVol->AddNode(volT2,4*i+3,
+                                   new TGeoCombiTrans(x-w,y+0.04+filHeight/2,z-kStaveLength/2+2*l+(i*4*l)+s1/2, 
+                                                      new TGeoRotation("volT2",90,90-alpha,-90+beta)));
+       }
+    }
+
+    if (fBuildLevel < 2) {
+
+      // Glue Filament and Silicon MicroChannel
+      TGeoBBox *tM0=new TGeoBBox(xladMC/5, klay4/2, zlad);
+      TGeoVolume *volTM0=new TGeoVolume("glueFM", tM0,medGlue );
+      volTM0->SetLineColor(5);
+      volTM0->SetFillColor(5); 
+      mechLaddVol->AddNode(volTM0, 0, new TGeoCombiTrans(x-xlad/2-0.25,0.03+yMC, z, new TGeoRotation("",0, 0, 0)));
+      mechLaddVol->AddNode(volTM0, 1, new TGeoCombiTrans(x+xlad/2+0.25,0.03+yMC, z, new TGeoRotation("",0, 0, 0)));
+
+            
+      // Glue microchannel and sensor
+      TGeoBBox *glueM = new TGeoBBox(xladMC/5, klay4/2, zlad);
+      TGeoVolume *volGlueM=new TGeoVolume("glueMS", glueM, medGlue);
+      volGlueM->SetLineColor(5);
+      volGlueM->SetFillColor(5); 
+      mechLaddVol->AddNode(volGlueM, 0, new TGeoCombiTrans(x-xlad/2-0.25,yMC-0.01, z, new TGeoRotation("",0, 0, 0)));
+      mechLaddVol->AddNode(volGlueM, 1, new TGeoCombiTrans(x+xlad/2+0.25,yMC-0.01, z, new TGeoRotation("",0, 0, 0)));
+     
+       // Glue sensor and kapton
+      TGeoBBox *glue = new TGeoBBox(xlad, klay4/2, zlad);
+      TGeoVolume *volGlue=new TGeoVolume("glueSensorBus", glue, medGlue);
+      volGlue->SetLineColor(5);
+      volGlue->SetFillColor(5); 
+       mechLaddVol->AddNode(volGlue, 1, new TGeoCombiTrans(x, y-0.154-fSensorThick-klay4/2, z, new TGeoRotation("",0, 0, 0)));
+    }      
+
+    if (fBuildLevel < 1) {
+      TGeoBBox *kapCable = new TGeoBBox(xlad, klay5/2, zlad);
+      TGeoVolume *volCable=new TGeoVolume("Flexcable", kapCable, medFlexCable);
+      volCable->SetLineColor(28);
+      volCable->SetFillColor(28); 
+      mechLaddVol->AddNode(volCable, 0, new TGeoCombiTrans(x, y-0.154-fSensorThick-klay4-klay5/2, z, new TGeoRotation("",0, 0, 0)));
+    }
+
+  // Done, return the stave structur
+    return mechLaddVol;
+ }
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveOuterB(const Double_t xlad,
+                                             const TGeoManager *mgr){
+//
+// Create the module stave for the Outer Barrel
+//
+// Input:
+//         xlad : X length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      20 Dec 2013  Mario Sitta
+//
+
+  TGeoVolume *mechLaddVol = 0;
+
+  switch (fStaveModel) {
+    case AliITSUv1::kOBModelDummy:
+      mechLaddVol = CreateStaveModelOuterBDummy(xlad,mgr);
+      break;
+    case AliITSUv1::kOBModel0:
+      mechLaddVol = CreateStaveModelOuterB0(xlad,mgr);
+      break;
+    case AliITSUv1::kOBModel1:
+      mechLaddVol = CreateStaveModelOuterB1(xlad,mgr);
+      break;
+    default:
+      AliFatal(Form("Unknown stave model %d",fStaveModel));
+      break;
+  }
+
+  return mechLaddVol; 
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelOuterBDummy(const Double_t ,
+                                                       const TGeoManager *) const {
+//
+// Create dummy stave
+//
+// Input:
+//         xlad : X length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      20 Dec 2013  Mario Sitta
+//
+
+
+  // Done, return the stave structure
+  return 0;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelOuterB0(const Double_t ,
+                                                   const TGeoManager *) const {
+//
+// Creation of the mechanical stave structure for the Outer Barrel as in v0
+// is done directly in CreateLadder, so this method does nothing
+// (doing it there is simpler, since all needed dimensions are known)
+//
+// Input:
+//         xlad : X length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      20 Dec 2013  Mario Sitta
+//
+
+  // Done, return the stave structure
+  return 0;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateStaveModelOuterB1(const Double_t xlad,
+                                                   const TGeoManager *mgr){
+//
+// Create the mechanical stave structure for the Outer Barrel as in TDR
+//
+// Input:
+//         xlad : X length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      20 Nov 2013  Anastasia Barbano
+// Updated:      16 Jan 2014  Mario Sitta
+//
+
+  // Materials defined in AliITSUv0
+  TGeoMedium *medAluminum     = mgr->GetMedium("ITS_ALUMINUM$");
+  TGeoMedium *medCarbon       = mgr->GetMedium("ITS_CARBON$");
+  TGeoMedium *medKapton       = mgr->GetMedium("ITS_KAPTON(POLYCH2)$");
+  TGeoMedium *medGlue         = mgr->GetMedium("ITS_GLUE$");
+  TGeoMedium *medWater        = mgr->GetMedium("ITS_WATER$");
+  TGeoMedium *medCarbonFleece = mgr->GetMedium("ITS_CarbonFleece$"); 
+  TGeoMedium *medFGS003       = mgr->GetMedium("ITS_FGS003$"); //amec thermasol
+  TGeoMedium *medAir          = mgr->GetMedium("ITS_AIR$");
+
+
+  // Local parameters
+  Double_t modGap             = fgkOBModuleGap;
+  Double_t yFlex1             = fgkOBFlexCable1Thick;
+  Double_t yFlex2             = fgkOBFlexCable2Thick;
+  Double_t yBus1              = fgkOBBusCable1Thick;
+  Double_t yBus2              = fgkOBBusCable2Thick;
+  Double_t xModPlate          = fgkOBHalfStaveWidth;
+  Double_t yModPlate          = fgkOBCarbonPlateThick;
+  Double_t xCPlate            = fgkOBHalfStaveWidth;
+  Double_t yCPlate            = fgkOBColdPlateThick;
+  Double_t yGlue              = fgkOBGlueThick;
+  Double_t flexOverlap        = 5;
+  Double_t deltaY             = 0.176;
+  Double_t xOverlap           = 0.23;       //overlapping of the halfStaves to cover the dead zone of sensors
+  Double_t zMod               = fgkOBModuleZLength;
+  Double_t xHalfSt            = fgkOBHalfStaveWidth/2;
+  Double_t xPos               = xOverlap/2 - xHalfSt;
+  Double_t xlen               = xlad;
+  Double_t rMin               = 0.267/2;
+  Double_t rMax               = rMin + 0.0065;
+  Double_t kLay1              = 0.004;      //carbon fleece
+  Double_t kLay2              = 0.003;      //carbon paper
+  Double_t yPos               = kLay1+kLay2;
+  Double_t ylen,zact;
+  Double_t zpos, zpos5cm;
+  Double_t ymod;
+  Double_t zbus;
+  Double_t zlen;
+
+
+  if (fIsTurbo) xlen = 0.5*fLadderWidth;
+  //ylen    = 0.5*fLadderThick;
+  ymod    = 0.005/2;//0.5*fSensorThick;
+  ylen    = 0.5*(2*kLay1+2*kLay2+2*rMax+yCPlate+yGlue+ yModPlate + ymod + 2*yFlex1 + 2*yFlex2 + yBus1 + yBus2 + deltaY);
+  zact    = fNModules*zMod; //active area 
+  zbus    = zact + (fNModules-1)*modGap; 
+  zlen    = zbus/2;
+
+
+  // First create all needed shapes
+
+  TGeoTube *coolTube   = new TGeoTube("CoolingTube",rMin,rMax,zbus/2);
+  TGeoTube *coolTubeW  = new TGeoTube("CoolingTubeWater",0,rMin,zbus/2);
+  TGeoBBox *coldPlate  = new TGeoBBox("ColdPlate",xCPlate/2,yCPlate/2,zbus/2);
+  TGeoBBox *glue       = new TGeoBBox("Glue",xCPlate/2,yGlue/2,zbus/2);
+  TGeoBBox *modPlate   = new TGeoBBox("CarbonPlate",xModPlate/2,yModPlate/2,zbus/2);
+  TGeoBBox *flex1      = new TGeoBBox("Flex1MV",xHalfSt,yFlex1/2,zMod/2);
+  TGeoBBox *flex2      = new TGeoBBox("Flex2MV",xHalfSt,yFlex2/2,zMod/2);
+  TGeoBBox *flex1_5cm  = new TGeoBBox("Flex1MV_5cm",xHalfSt,yFlex1/2,flexOverlap/2);
+  TGeoBBox *flex2_5cm  = new TGeoBBox("Flex2MV_5cm",xHalfSt,yFlex2/2,flexOverlap/2);
+  TGeoBBox *bus1       = new TGeoBBox("Bus1HV",xHalfSt,yBus1/2,zbus/2);
+  TGeoBBox *bus2       = new TGeoBBox("Bus2HV",xHalfSt,yBus2/2,zbus/2); 
+  TGeoTubeSeg *cone1   = new TGeoTubeSeg(rMax +kLay2,rMax+kLay1+kLay2,zlen,180.,360.);  //Carbon Fleece 
+  TGeoTubeSeg *cone2   = new TGeoTubeSeg(rMax ,rMax+kLay2,zlen,180.,360.);  //Graphite paper 
+  TGeoBBox *box11      = new TGeoBBox((0.95-kLay2-rMax)/2,kLay1/2,zlen);
+  TGeoBBox *box12      = new TGeoBBox((1.11-2*kLay2-2*rMax)/2,kLay1/2,zlen);
+  TGeoBBox *box13      = new TGeoBBox(kLay1/2,(rMax-(kLay1+kLay2))/2,zlen);
+  TGeoBBox *box21      = new TGeoBBox((0.95-rMax)/2,kLay2/2,zlen);
+  TGeoBBox *box22      = new TGeoBBox((1.11-2*rMax)/2,kLay2/2,zlen);
+  TGeoBBox *box23      = new TGeoBBox(kLay2/2,(rMax-kLay2)/2,zlen);
+  TGeoBBox *mechStruct = new TGeoBBox("mechanicalStructure",xlen, ylen, 0.5*fZLength); 
+
+
+  TGeoVolume *modVol       = CreateModuleOuterB(xHalfSt, ymod, zMod);
+  TGeoVolume *coolTubeVol  = new TGeoVolume("CoolingTubeVol",coolTube,medKapton);
+  TGeoVolume *coolTubeWVol = new TGeoVolume("CoolingTubeWaterVol",coolTubeW,medWater);
+  TGeoVolume *coldPlateVol = new TGeoVolume("ColdPlateVol",coldPlate,medCarbon);
+  TGeoVolume *glueVol      = new TGeoVolume("GlueVol",glue,medGlue);
+  TGeoVolume *modPlateVol  = new TGeoVolume("CarbonPlateVol",modPlate,medCarbon);
+  TGeoVolume *flex1Vol     = new TGeoVolume("Flex1Vol",flex1,medAluminum);
+  TGeoVolume *flex2Vol     = new TGeoVolume("Flex2Vol",flex2,medKapton);
+  TGeoVolume *flex1_5cmVol = new TGeoVolume("Flex1Vol5cm",flex1_5cm,medAluminum);
+  TGeoVolume *flex2_5cmVol = new TGeoVolume("Flex2Vol5cm",flex2_5cm,medKapton);
+  TGeoVolume *bus1Vol      = new TGeoVolume("Bus1Vol",bus1,medAluminum);
+  TGeoVolume *bus2Vol      = new TGeoVolume("Bus2Vol",bus2,medKapton);
+  TGeoVolume *cone1Vol     = new TGeoVolume("CarbonFleecePipeCover",cone1,medCarbonFleece);
+  TGeoVolume *cone2Vol     = new TGeoVolume("GraphitePaperPipeCover",cone2,medFGS003);
+  TGeoVolume *plate11Vol   = new TGeoVolume("CarbonFleeceLR1",box11,medCarbonFleece);
+  TGeoVolume *plate12Vol   = new TGeoVolume("CarbonFleeceMiddle1",box12,medCarbonFleece); 
+  TGeoVolume *plate13Vol   = new TGeoVolume("CarbonFleeceVertical1",box13,medCarbonFleece); 
+  TGeoVolume *plate21Vol   = new TGeoVolume("CarbonFleeceLR2",box21,medFGS003);
+  TGeoVolume *plate22Vol   = new TGeoVolume("CarbonFleeceMiddle2",box22,medFGS003);
+  TGeoVolume *plate23Vol   = new TGeoVolume("CarbonFleeceVertical2",box23,medFGS003);
+  TGeoVolume *mechLaddVol  = new TGeoVolume("mechLadderVolume",mechStruct,medAir);
+
+  mechLaddVol->SetLineColor(12);
+  mechLaddVol->SetFillColor(12); 
+  mechLaddVol->SetVisibility(kTRUE);
+
+  modVol->SetVisibility(kTRUE);
+  flex1_5cmVol->SetLineColor(kRed);
+  flex2_5cmVol->SetLineColor(kGreen);
+  modPlateVol->SetLineColor(kMagenta-8);
+  coolTubeVol->SetLineColor(kGray);
+  coolTubeWVol->SetLineColor(kBlue);
+  coldPlateVol->SetLineColor(kYellow-3);
+  glueVol->SetLineColor(kBlack);
+  flex1Vol->SetLineColor(kRed);
+  flex2Vol->SetLineColor(kGreen);
+  bus1Vol->SetLineColor(kCyan);
+  bus2Vol->SetLineColor(kBlue);
+  cone1Vol->SetFillColor(kViolet);
+  plate11Vol->SetFillColor(kViolet);
+  plate12Vol->SetLineColor(kViolet);
+  plate13Vol->SetLineColor(kViolet);
+  cone2Vol->SetLineColor(kGreen);
+  plate22Vol->SetFillColor(kGreen);
+  plate21Vol->SetLineColor(kGreen);
+  plate23Vol->SetLineColor(kGreen);
+
+
+  //Carbon Fleece
+
+  mechLaddVol->AddNode(plate11Vol,1,new TGeoTranslation(xPos -(1.11/2+rMax+box11->GetDX()+kLay2),-ylen + yPos +2*rMax-kLay2-kLay1/2,0));
+  mechLaddVol->AddNode(plate11Vol,2,new TGeoTranslation(xPos +(1.11/2+rMax+box11->GetDX()+kLay2),-ylen + yPos +2*rMax-kLay2-kLay1/2,0));
+  mechLaddVol->AddNode(plate11Vol,3,new TGeoTranslation(-xPos -(1.11/2+rMax+box11->GetDX()+kLay2),-ylen + yPos +2*rMax-kLay2-kLay1/2 +deltaY,0));
+  mechLaddVol->AddNode(plate11Vol,4,new TGeoTranslation(-xPos +(1.11/2+rMax+box11->GetDX()+kLay2),-ylen + yPos +2*rMax-kLay2-kLay1/2 +deltaY,0));
+  mechLaddVol->AddNode(plate12Vol,1,new TGeoTranslation(xPos ,-ylen + yPos +2*rMax-kLay2-kLay1/2,0));
+  mechLaddVol->AddNode(plate12Vol,2,new TGeoTranslation(-xPos ,-ylen + yPos +2*rMax-kLay2-kLay1/2 + deltaY,0));
+  mechLaddVol->AddNode(plate13Vol,1,new TGeoTranslation(xPos -(1.11/2+rMax+kLay2+box13->GetDX()),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY(),0));
+  mechLaddVol->AddNode(plate13Vol,2,new TGeoTranslation(xPos -1.11/2+rMax+kLay2+box13->GetDX(),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY(),0));
+  mechLaddVol->AddNode(plate13Vol,3,new TGeoTranslation(xPos +(1.11/2+rMax+kLay2+box13->GetDX()),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY(),0));
+  mechLaddVol->AddNode(plate13Vol,4,new TGeoTranslation(xPos +1.11/2-rMax-kLay2-box13->GetDX(),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY(),0));
+  mechLaddVol->AddNode(plate13Vol,5,new TGeoTranslation(-xPos -(1.11/2+rMax+kLay2+box13->GetDX()),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY() +deltaY,0));
+  mechLaddVol->AddNode(plate13Vol,6,new TGeoTranslation(-xPos -1.11/2+rMax+kLay2+box13->GetDX(),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY() +deltaY,0));
+  mechLaddVol->AddNode(plate13Vol,7,new TGeoTranslation(-xPos +(1.11/2+rMax+kLay2+box13->GetDX()),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY() +deltaY,0));
+  mechLaddVol->AddNode(plate13Vol,8,new TGeoTranslation(-xPos +1.11/2-rMax-kLay2-box13->GetDX(),-ylen + yPos +2*rMax-kLay1-kLay2-box13->GetDY() +deltaY,0));
+
+  mechLaddVol->AddNode(cone1Vol,1,new TGeoTranslation(xPos - 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(cone1Vol,2,new TGeoTranslation(xPos + 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(cone1Vol,3,new TGeoTranslation(-xPos - 0.555,-ylen + yPos + rMax + deltaY,0));
+  mechLaddVol->AddNode(cone1Vol,4,new TGeoTranslation(-xPos + 0.555,-ylen + yPos + rMax + deltaY,0));
+
+
+  //Carbon Paper
+
+  mechLaddVol->AddNode(plate21Vol,1,new TGeoTranslation(xPos -(1.11/2+rMax+box21->GetDX()),-ylen + yPos +2*rMax-kLay2/2,0));
+  mechLaddVol->AddNode(plate21Vol,2,new TGeoTranslation(xPos +(1.11/2+rMax+box21->GetDX()) ,-ylen + yPos +2*rMax-kLay2/2,0));
+  mechLaddVol->AddNode(plate21Vol,3,new TGeoTranslation(-xPos -(1.11/2+rMax+box21->GetDX()) ,-ylen + yPos +2*rMax-kLay2/2 +deltaY,0));
+  mechLaddVol->AddNode(plate21Vol,4,new TGeoTranslation(-xPos +(1.11/2+rMax+box21->GetDX()) ,-ylen + yPos +2*rMax-kLay2/2 +deltaY,0));
+  mechLaddVol->AddNode(plate22Vol,1,new TGeoTranslation(xPos ,-ylen + yPos +2*rMax-kLay2/2,0));
+  mechLaddVol->AddNode(plate22Vol,2,new TGeoTranslation(-xPos ,-ylen + yPos +2*rMax-kLay2/2 + deltaY,0));
+  mechLaddVol->AddNode(plate23Vol,1,new TGeoTranslation(xPos -(1.11/2+rMax+box23->GetDX()),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2,0));
+  mechLaddVol->AddNode(plate23Vol,2,new TGeoTranslation(xPos -1.11/2+rMax+box23->GetDX(),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2,0));
+  mechLaddVol->AddNode(plate23Vol,3,new TGeoTranslation(xPos +(1.11/2+rMax+box23->GetDX()),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2,0));
+  mechLaddVol->AddNode(plate23Vol,4,new TGeoTranslation(xPos +1.11/2-rMax-box23->GetDX(),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2,0));
+  mechLaddVol->AddNode(plate23Vol,5,new TGeoTranslation(-xPos -(1.11/2+rMax+box23->GetDX()),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2+deltaY,0));
+  mechLaddVol->AddNode(plate23Vol,6,new TGeoTranslation(-xPos -1.11/2+rMax+box23->GetDX(),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2+deltaY,0));
+  mechLaddVol->AddNode(plate23Vol,7,new TGeoTranslation(-xPos +(1.11/2+rMax+box23->GetDX()),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2+deltaY,0));
+  mechLaddVol->AddNode(plate23Vol,8,new TGeoTranslation(-xPos +1.11/2-rMax-box23->GetDX(),-ylen + yPos +2*rMax-kLay2-(rMax-kLay2)/2+deltaY,0));
+
+  mechLaddVol->AddNode(cone2Vol,1,new TGeoTranslation(xPos - 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(cone2Vol,2,new TGeoTranslation(xPos + 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(cone2Vol,3,new TGeoTranslation(-xPos - 0.555,-ylen + yPos + rMax + deltaY,0));
+  mechLaddVol->AddNode(cone2Vol,4,new TGeoTranslation(-xPos + 0.555,-ylen + yPos + rMax + deltaY,0));
+
+  //Cooling Tubes + water
+
+  mechLaddVol->AddNode(coolTubeVol,1,new TGeoTranslation(xPos - 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(coolTubeWVol,1,new TGeoTranslation(xPos - 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(coolTubeVol,2,new TGeoTranslation(xPos + 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(coolTubeWVol,2,new TGeoTranslation(xPos + 0.555,-ylen + yPos + rMax,0));
+  mechLaddVol->AddNode(coolTubeVol,3,new TGeoTranslation(-xPos - 0.555,-ylen + yPos + rMax + deltaY,0));
+  mechLaddVol->AddNode(coolTubeWVol,3,new TGeoTranslation(-xPos - 0.555,-ylen + yPos + rMax + deltaY,0));
+  mechLaddVol->AddNode(coolTubeVol,4,new TGeoTranslation(-xPos + 0.555,-ylen + yPos + rMax + deltaY,0));
+  mechLaddVol->AddNode(coolTubeWVol,4,new TGeoTranslation(-xPos + 0.555,-ylen + yPos + rMax + deltaY,0));
+
+  //Cold Plate
+
+  mechLaddVol->AddNode(coldPlateVol,1,new TGeoTranslation(xPos,-ylen + yPos + 2*rMax + yCPlate/2,0));
+  mechLaddVol->AddNode(coldPlateVol,2,new TGeoTranslation(-xPos,-ylen + yPos + 2*rMax + yCPlate/2 + deltaY,0));
+
+  //Glue
+
+  mechLaddVol->AddNode(glueVol,1,new TGeoTranslation(xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue/2,0));
+  mechLaddVol->AddNode(glueVol,2,new TGeoTranslation(-xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue/2 + deltaY,0));
+
+  //Module Carbon Plate
+
+  mechLaddVol->AddNode(modPlateVol,1,new TGeoTranslation(xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate/2,0));
+  mechLaddVol->AddNode(modPlateVol,2,new TGeoTranslation(-xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate/2 + deltaY,0));
+
+  //Bus
+
+  mechLaddVol->AddNode(bus1Vol,1,new TGeoTranslation(xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 2*yFlex2 + yBus1/2,0));
+  mechLaddVol->AddNode(bus1Vol,2,new TGeoTranslation(-xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 2*yFlex2 + yBus1/2 + deltaY,0));
+  mechLaddVol->AddNode(bus2Vol,1,new TGeoTranslation(xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 2*yFlex2 + yBus1 + yBus2/2,0));
+  mechLaddVol->AddNode(bus2Vol,2,new TGeoTranslation(-xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 2*yFlex2 + yBus1 + yBus2/2 + deltaY,0));
+  
+  //FPC + modules
+
+  for (Int_t j=0; j<fNModules; j++) {
+
+    zpos = -(zact + (fNModules-1)*modGap)/2 + j*(zMod + modGap) + zMod/2;
+    zpos5cm = -(zact + (fNModules-1)*modGap)/2 + (j+1)*(zMod + modGap) + flexOverlap/2 ;
+
+    mechLaddVol->AddNode(modVol, j, new TGeoTranslation(xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + ymod, zpos));
+    mechLaddVol->AddNode(modVol, fNModules+j, new TGeoTranslation(-xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + ymod +deltaY, zpos));
+    mechLaddVol->AddNode(flex1Vol,j,new TGeoTranslation(xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1/2,zpos));
+    mechLaddVol->AddNode(flex1Vol,fNModules+j,new TGeoTranslation(-xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1/2 + deltaY,zpos));
+    mechLaddVol->AddNode(flex2Vol,j,new TGeoTranslation(xPos, -ylen + yPos + yModPlate + 2*rMax + yCPlate + yGlue + 2*ymod + yFlex1 + yFlex2/2,zpos));
+    mechLaddVol->AddNode(flex2Vol,fNModules+j,new TGeoTranslation(-xPos, -ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1 + yFlex2/2 + deltaY,zpos));
+
+    if((j+1)!=fNModules){
+      mechLaddVol->AddNode(flex1_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1 + yFlex2 + yFlex1/2,zpos5cm));
+      mechLaddVol->AddNode(flex1_5cmVol,fNModules+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1 + yFlex2 + yFlex1/2 +deltaY,zpos5cm));
+      mechLaddVol->AddNode(flex2_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 3*yFlex2/2,zpos5cm));
+      mechLaddVol->AddNode(flex2_5cmVol,fNModules+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + 2*yFlex1 + 3*yFlex2/2 +deltaY,zpos5cm));
+    }
+    else {
+      mechLaddVol->AddNode(flex1_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1/2,zpos5cm-modGap));
+      mechLaddVol->AddNode(flex1_5cmVol,fNModules+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1/2 +deltaY,zpos5cm-modGap));
+      mechLaddVol->AddNode(flex2_5cmVol,j,new TGeoTranslation(xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate +2*ymod + yFlex1 + yFlex2/2,zpos5cm-modGap));
+      mechLaddVol->AddNode(flex2_5cmVol,fNModules+j,new TGeoTranslation(-xPos,-ylen + yPos + 2*rMax + yCPlate + yGlue + yModPlate + 2*ymod + yFlex1 + yFlex2/2 +deltaY,zpos5cm-modGap));
+
+      }
+  }
+  
+
+  // Done, return the stave structur
+  return mechLaddVol;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateSpaceFrameOuterB(const Double_t xlad,
+                                                  const TGeoManager *mgr){
+//
+// Create the space frame for the Outer Barrel
+//
+// Input:
+//         xlad : X length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+//
+
+  TGeoVolume *mechLaddVol = 0;
+
+  switch (fStaveModel) {
+    case AliITSUv1::kOBModelDummy:
+      mechLaddVol = CreateSpaceFrameOuterBDummy(xlad,mgr);
+      break;
+    case AliITSUv1::kOBModel1:
+      mechLaddVol = CreateSpaceFrameOuterB0(xlad,mgr);
+      break;
+    default:
+      AliFatal(Form("Unknown stave model %d",fStaveModel));
+      break;
+  }
+
+  return mechLaddVol; 
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateSpaceFrameOuterBDummy(const Double_t ,
+                                                       const TGeoManager *) const {
+//
+// Create dummy stave
+//
+// Input:
+//         xlad : X length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+
+
+  // Done, return the stave structur
+  return 0;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateSpaceFrameOuterB0(const Double_t xlen,
+                                                   const TGeoManager *mgr){
+//
+// Create the space frame for the Outer Barrel (Model 0)
+//
+// Input:
+//         xlen : X length
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//         a TGeoVolume with the Space Frame of a stave
+//
+// Created:      20 Dec 2013  Anastasia Barbano
+// Updated:      15 Jan 2014  Mario Sitta
+//
+
+
+  // Materials defined in AliITSUv0
+  TGeoMedium *medCarbon       = mgr->GetMedium("ITS_CARBON$");
+  TGeoMedium *medAir          = mgr->GetMedium("ITS_AIR$");
+
+
+  // Local parameters
+  Double_t ladderWidth        = 4.2;
+  Double_t ladderHeight       = 4.2;
+//  Double_t ladderSegBoxDW     = 7.5;
+//  Double_t ladderSegBoxDH     = 7.1;
+  Double_t ladderBeamRadius   = 0.06;
+  Double_t ladderLa           = 0.3;
+  Double_t ladderHa           = 0.0721979;
+  Double_t ladderLb           = 0.37;
+  Double_t ladderHb           = 0.0890428;
+  Double_t ladderl            = 0.025;
+  Double_t beamSidePhi        = 65;
+  Double_t bottomBeamAngle    = 56.5;
+//  Double_t dy                 = ladderSegBoxDH/2;
+  Double_t triangleHeight     = ladderHeight - ladderBeamRadius;
+  Double_t halfTheta          = TMath::ATan( 0.5*ladderWidth/triangleHeight );
+  Double_t alpha              = TMath::Pi()*3./4. - halfTheta/2.;
+  Double_t beta               = (TMath::Pi() - 2.*halfTheta)/4.;
+//  Double_t dYTranslation      = (ladderHeight/2. -0.5*ladderWidth*TMath::Tan(beta)-ladderBeamRadius);
+  Double_t distCenterSideDown =  0.5*ladderWidth/TMath::Cos(beta);
+  Double_t zact;
+  Double_t zbus;
+  Double_t zlen;
+  Double_t seglen;    
+
+
+  zact    = fNModules*fgkOBModuleZLength; //active area 
+  zbus    = zact + (fNModules-1)*fgkOBModuleGap; 
+  zlen    = zbus/2;
+  seglen  = zlen/10;
+
+  // First create all needed shapes and volumes
+
+  TGeoBBox *spaceFrame = new TGeoBBox("CarbonFrame",xlen, 2.2, zlen);
+  TGeoBBox *segment    = new TGeoBBox(ladderWidth/2,ladderHeight/2,seglen/2);
+
+  TGeoVolume *spaceFrameVol = new TGeoVolume("CarbonFrameVolume",
+                                            spaceFrame, medAir);
+  spaceFrameVol->SetVisibility(kTRUE);
+
+  TGeoVolume *segmentVol    = new TGeoVolume("segmentVol",segment,medAir);
+
+  //SpaceFrame
+
+  //--- the top V of the Carbon Fiber Ladder (segment)
+  TGeoArb8 *cfLaddTop1 = CreateLadderSide("CFladdTopCornerVol1shape", seglen/2., halfTheta, -1, ladderLa, ladderHa, ladderl);
+  TGeoVolume *cfLaddTopVol1 = new TGeoVolume("ITSsddCFladdTopCornerVol1", cfLaddTop1,medCarbon);
+  TGeoArb8 *cfLaddTop2 = CreateLadderSide( "CFladdTopCornerVol2shape", seglen/2., halfTheta, 1, ladderLa, ladderHa, ladderl);
+  TGeoVolume *cfLaddTopVol2 = new TGeoVolume("ITSsddCFladdTopCornerVol2",cfLaddTop2,medCarbon );
+
+  //TGeoTranslation *trTop1 = new TGeoTranslation(0, fgkLadderHeight/2-dy, 0);
+  TGeoTranslation *trTop1 = new TGeoTranslation(0, ladderHeight/2, 0);
+  
+  //--- the 2 side V
+  TGeoArb8 *cfLaddSide1 = CreateLadderSide( "CFladdSideCornerVol1shape", seglen/2., beta, -1,ladderLb, ladderHb, ladderl);
+  TGeoVolume *cfLaddSideVol1 = new TGeoVolume( "ITSsddCFladdSideCornerVol1", cfLaddSide1,medCarbon);
+  TGeoArb8 *cfLaddSide2 = CreateLadderSide( "CFladdSideCornerVol2shape", seglen/2., beta, 1, ladderLb, ladderHb, ladderl);
+  TGeoVolume *cfLaddSideVol2 = new TGeoVolume( "ITSsddCFladdSideCornerVol2", cfLaddSide2,medCarbon );
+
+  
+  TGeoCombiTrans *ctSideR = CreateCombiTrans("", distCenterSideDown, 0,alpha*TMath::RadToDeg());
+  //AddTranslationToCombiTrans(ctSideR, 0, -dYTranslation-dy, 0);
+  AddTranslationToCombiTrans(ctSideR, 0, ladderHeight/2-2.85/*2.765250/*triangleHeight*/, 0);
+  TGeoCombiTrans *ctSideL = CreateCombiTrans("", distCenterSideDown,0,-alpha*TMath::RadToDeg());
+  //AddTranslationToCombiTrans(ctSideL, 0, -dYTranslation-dy, 0);
+  AddTranslationToCombiTrans(ctSideL, 0, ladderHeight/2-2.85/*triangleHeight*/, 0);
+
+  segmentVol->AddNode(cfLaddTopVol1,1,trTop1);
+  segmentVol->AddNode(cfLaddTopVol2,1,trTop1);
+  segmentVol->AddNode(cfLaddSideVol1,1,ctSideR);
+  segmentVol->AddNode(cfLaddSideVol1,2,ctSideL);
+  segmentVol->AddNode(cfLaddSideVol2,1,ctSideR);
+  segmentVol->AddNode(cfLaddSideVol2,2,ctSideL);
+
+
+  //--- The beams
+  // Beams on the sides
+  Double_t beamPhiPrime = TMath::ASin(1./TMath::Sqrt( (1+TMath::Sin(2*beta)*TMath::Sin(2*beta)/(TanD(beamSidePhi)*TanD(beamSidePhi))) ));
+  Double_t beamLength = TMath::Sqrt( ladderHeight*ladderHeight/( TMath::Sin(beamPhiPrime)*TMath::Sin(beamPhiPrime))+ ladderWidth*ladderWidth/4.)-ladderLa/2-ladderLb/2;
+  TGeoTubeSeg *sideBeamS = new TGeoTubeSeg(0, ladderBeamRadius,beamLength/2.,0, 180);
+  TGeoVolume *sideBeam = new TGeoVolume("ITSsddCFSideBeamVol", sideBeamS,medCarbon);
+
+  //Euler rotation : about Z, then new X, then new Z
+  TGeoRotation *beamRot1 = new TGeoRotation("", 90-2.*beta*TMath::RadToDeg(),-beamPhiPrime*TMath::RadToDeg(),-90);
+  TGeoRotation *beamRot2 = new TGeoRotation("", 90-2.*beta*TMath::RadToDeg(), beamPhiPrime*TMath::RadToDeg(), -90);
+  TGeoRotation *beamRot3 = new TGeoRotation("", 90+2.*beta*TMath::RadToDeg(), beamPhiPrime*TMath::RadToDeg(), -90);
+  TGeoRotation *beamRot4 = new TGeoRotation("", 90+2.*beta*TMath::RadToDeg(),-beamPhiPrime*TMath::RadToDeg(),-90);
+
+  TGeoCombiTrans *beamTransf[8];
+  beamTransf[0] = new TGeoCombiTrans( 0.5*triangleHeight*TMath::Tan(halfTheta),ladderBeamRadius/2. ,-3*seglen/8, beamRot1);
+
+  beamTransf[1] = new TGeoCombiTrans( 0.5*triangleHeight*TMath::Tan(halfTheta),ladderBeamRadius/2. ,-3*seglen/8, beamRot1);
+  AddTranslationToCombiTrans(beamTransf[1], 0, 0, seglen/2);
+
+  beamTransf[2] = new TGeoCombiTrans(0.5*triangleHeight*TMath::Tan(halfTheta),ladderBeamRadius/2. ,-seglen/8, beamRot2);
+
+  beamTransf[3] = new TGeoCombiTrans(0.5*triangleHeight*TMath::Tan(halfTheta),ladderBeamRadius/2. ,-seglen/8, beamRot2);
+  AddTranslationToCombiTrans(beamTransf[3], 0, 0, seglen/2);
+
+  beamTransf[4] = new TGeoCombiTrans(-0.5*triangleHeight*TMath::Tan(halfTheta),ladderBeamRadius/2. ,-3*seglen/8, beamRot3);
+
+  beamTransf[5] = new TGeoCombiTrans(-0.5*triangleHeight*TMath::Tan(halfTheta),ladderBeamRadius/2. ,-3*seglen/8, beamRot3);
+  AddTranslationToCombiTrans(beamTransf[5], 0, 0, seglen/2);
+
+  beamTransf[6] = new TGeoCombiTrans(-0.5*triangleHeight* TMath::Tan(halfTheta),ladderBeamRadius/2., -seglen/8,beamRot4);
+  beamTransf[7] = new TGeoCombiTrans(-0.5*triangleHeight* TMath::Tan(halfTheta),ladderBeamRadius/2.,3*seglen/8,beamRot4);
+
+  //--- Beams of the bottom
+  TGeoTubeSeg *bottomBeam1 = new TGeoTubeSeg(0, ladderBeamRadius,ladderWidth/2.-ladderLb/3, 0, 180);
+  TGeoVolume *bottomBeam1Vol = new TGeoVolume("ITSsddBottomBeam1Vol", bottomBeam1, medCarbon);
+  TGeoTubeSeg *bottomBeam2 = new TGeoTubeSeg(0, ladderBeamRadius,ladderWidth/2.-ladderLb/3, 0, 90);
+  TGeoVolume *bottomBeam2Vol = new TGeoVolume("ITSsddBottomBeam2Vol",bottomBeam2, medCarbon);
+  TGeoTubeSeg *bottomBeam3 = new TGeoTubeSeg(0, ladderBeamRadius,0.5*ladderWidth/SinD(bottomBeamAngle) - ladderLb/3, 0, 180);
+  TGeoVolume *bottomBeam3Vol = new TGeoVolume("ITSsddBottomBeam3Vol", bottomBeam3, medCarbon);
+  TGeoRotation *bottomBeamRot1 = new TGeoRotation("", 90, 90,  90);
+  TGeoRotation *bottomBeamRot2 = new TGeoRotation("",-90, 90, -90);
+
+  TGeoCombiTrans *bottomBeamTransf1 = new TGeoCombiTrans("",0,-(ladderHeight/2-ladderBeamRadius),0, bottomBeamRot1);
+  TGeoCombiTrans *bottomBeamTransf2 = new TGeoCombiTrans(0,-(ladderHeight/2-ladderBeamRadius),-seglen/2, bottomBeamRot1);
+  TGeoCombiTrans *bottomBeamTransf3 = new TGeoCombiTrans(0,-(ladderHeight/2-ladderBeamRadius), seglen/2, bottomBeamRot2);
+  // be careful for beams #3: when "reading" from -z to +z and 
+  // from the bottom of the ladder, it should draw a Lambda, and not a V
+  TGeoRotation *bottomBeamRot4 = new TGeoRotation("", -90, bottomBeamAngle, -90);
+  TGeoRotation *bottomBeamRot5 = new TGeoRotation("" ,-90,-bottomBeamAngle, -90);
+  TGeoCombiTrans *bottomBeamTransf4 = new TGeoCombiTrans(0,-(ladderHeight/2-ladderBeamRadius),-seglen/4,bottomBeamRot4);
+  TGeoCombiTrans *bottomBeamTransf5 = new TGeoCombiTrans(0,-(ladderHeight/2-ladderBeamRadius),seglen/4, bottomBeamRot5);
+
+  cfLaddTopVol1->SetLineColor(35);
+  cfLaddTopVol2->SetLineColor(35);
+  cfLaddSideVol1->SetLineColor(35);
+  cfLaddSideVol2->SetLineColor(35);
+  sideBeam->SetLineColor(35);
+  bottomBeam1Vol->SetLineColor(35);
+  bottomBeam2Vol->SetLineColor(35);
+  bottomBeam3Vol->SetLineColor(35);
+
+
+  segmentVol->AddNode(sideBeam,1, beamTransf[0]);
+  segmentVol->AddNode(sideBeam,2, beamTransf[1]);
+  segmentVol->AddNode(sideBeam,3, beamTransf[2]);
+  segmentVol->AddNode(sideBeam,4, beamTransf[3]);
+  segmentVol->AddNode(sideBeam,5, beamTransf[4]);
+  segmentVol->AddNode(sideBeam,6, beamTransf[5]);
+  segmentVol->AddNode(sideBeam,7, beamTransf[6]);
+  segmentVol->AddNode(sideBeam,8, beamTransf[7]);
+  segmentVol->AddNode(bottomBeam1Vol,1,bottomBeamTransf1);
+  segmentVol->AddNode(bottomBeam2Vol,1,bottomBeamTransf2);
+  segmentVol->AddNode(bottomBeam2Vol,1,bottomBeamTransf3);
+  segmentVol->AddNode(bottomBeam3Vol,1,bottomBeamTransf4);
+  segmentVol->AddNode(bottomBeam3Vol,1,bottomBeamTransf5);
+
+  for(Int_t i=0;i<10;i++){
+    spaceFrameVol->AddNode(segmentVol,i,new TGeoTranslation(0,0,seglen*(0.5+i)));
+    spaceFrameVol->AddNode(segmentVol,11+i,new TGeoTranslation(0,0,-seglen*(0.5+i)));
+  }
+
+
+  // Done, return the stave structur
+  return spaceFrameVol;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateModuleInnerB(const Double_t xlad,
+                                              const Double_t ylad,   
+                                              const Double_t zlad,
+                                              const TGeoManager *mgr){
+//
+// Creates the actual Module
+//
+// Input:
+//         xlad,zlad : the ladder dimensions
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      22 Jun 2011  Mario Sitta
+//
+
+  char volname[30];
+  Double_t xlen, ylen, zlen;
+  Double_t xpos, ypos, zpos;
+
+
+  // First create all needed shapes
+
+  // The module
+  TGeoBBox *module = new TGeoBBox(xlad,  ylad, zlad/fNModules);
+
+  // The sensor
+  xlen = module->GetDX();
+  ylen = 0.5*fSensorThick;
+  zlen = module->GetDZ();
+  TGeoBBox *sensor = new TGeoBBox(xlen, ylen, zlen);
+
+
+  // We have all shapes: now create the real volumes
+  //TGeoMedium *medAir = mgr->GetMedium("ITS_AIR$");
+  TGeoMedium *medSi  = mgr->GetMedium("ITS_SI$");
+
+  snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSModulePattern(), fLayerNumber);
+  // TGeoVolume *modVol = new TGeoVolume(volname, module, medAir);
+  TGeoVolume *modVol = new TGeoVolume(volname, module, medSi);
+  modVol->SetVisibility(kTRUE);
+  modVol->SetLineColor(1);
+
+  snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSSensorPattern(), fLayerNumber);
+  TGeoVolume *sensVol = new TGeoVolume(volname, sensor, medSi);
+  sensVol->SetVisibility(kTRUE);
+  sensVol->SetLineColor(8);
+  sensVol->SetLineWidth(1);
+  sensVol->SetFillColor(sensVol->GetLineColor());
+  sensVol->SetFillStyle(4000); // 0% transparent
+
+
+  // Now build up the module
+  xpos = 0.;
+  ypos = -module->GetDY() + sensor->GetDY();
+  zpos = 0.;
+
+  modVol->AddNode(sensVol, 1, new TGeoTranslation(xpos, ypos, zpos));
+
+  // Done, return the module
+  return modVol;
+}
+
+//________________________________________________________________________
+TGeoVolume* AliITSUv1Layer::CreateModuleOuterB(const Double_t xlad,
+                                              const Double_t ylad,   
+                                              const Double_t zmod,
+                                              const TGeoManager *mgr){
+//
+// Creates the actual Module
+//
+// Input:
+//         xlad,ylad,zlad : the half stave dimensions
+//         mgr  : the GeoManager (used only to get the proper material)
+//
+// Output:
+//
+// Return:
+//
+// Created:      18 Dec 2013  M. Sitta, A. Barbano
+//
+
+
+  char volname[30];
+
+  Double_t xGap  = 0.01; 
+  Double_t zGap  = 0.01;
+
+  Double_t xlen, ylen, zlen;
+  Double_t xpos, ypos, zpos;
+  
+  // First create all needed shapes
+
+  // The module
+  TGeoBBox *module = new TGeoBBox(xlad,  ylad, zmod/2);
+
+  // The sensor
+  xlen = 0.5*(module->GetDX()-xGap/2);
+  //xlen = 0.5*1.5;
+  ylen = ylad;
+  zlen = (2*module->GetDZ()-6*zGap)/14;
+  TGeoBBox *sensor = new TGeoBBox(xlen, ylen, zlen);
+
+
+  // We have all shapes: now create the real volumes
+  TGeoMedium *medSi  = mgr->GetMedium("ITS_SI$");
+  snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSModulePattern(), fLayerNumber);
+  TGeoVolume *modVol = new TGeoVolume(volname, module, medSi);
+  modVol->SetVisibility(kTRUE);
+
+  snprintf(volname, 30, "%s%d", AliITSUGeomTGeo::GetITSSensorPattern(), fLayerNumber);
+  TGeoVolume *sensVol = new TGeoVolume(volname, sensor, medSi);
+  
+
+
+  // Now build up the module
+  xpos = -module->GetDX() + sensor->GetDX();
+  //xpos = -xGap/2 -sensor->GetDX();
+  ypos = -module->GetDY() + sensor->GetDY();
+  for(Int_t k=0;k<7;k++)   //put 7x2 chip into one module
+    {
+      zpos = -module->GetDZ() + sensor->GetDZ() + k*(2*sensor->GetDZ() + zGap);
+      modVol->AddNode(sensVol, k+1, new TGeoTranslation(xpos, ypos, zpos));
+      modVol->AddNode(sensVol, k+2, new TGeoTranslation(-xpos, ypos, zpos));
+    }
+  
+  //sensVol->SetVisibility(kTRUE);
+  sensVol->SetLineColor(kYellow);
+  //sensVol->SetLineWidth(1);
+  //sensVol->SetTransparency(30);
+  sensVol->SetFillColor(sensVol->GetLineColor());
+  sensVol->SetFillStyle(4000); // 0% transparent
+  // Done, return the module
+  return modVol;
+}
+
+//________________________________________________________________________
+Double_t AliITSUv1Layer::RadiusOfTurboContainer(){
+//
+// Computes the inner radius of the air container for the Turbo configuration
+// as the radius of either the circle tangent to the ladder or the circle
+// passing for the ladder's lower vertex
+//
+// Input:
+//         none (all needed parameters are class members)
+//
+// Output:
+//
+// Return:
+//        the radius of the container if >0, else flag to use the lower vertex
+//
+// Created:      08 Mar 2012  Mario Sitta
+//
+
+  Double_t rr, delta, z, lladd, rladd;
+
+  if (fLadderThick > 89.) // Very big angle: avoid overflows since surely
+    return -1;            // the radius from lower vertex is the right value
+
+  rladd = fLayRadius + 0.5*fLadderThick;
+  delta = (0.5*fLadderThick)/CosD(fLadderTilt);
+  z     = (0.5*fLadderThick)*TanD(fLadderTilt);
+
+  rr = rladd - delta;
+  lladd = (0.5*fLadderWidth) - z;
+
+  if ( (rr*SinD(fLadderTilt) < lladd) )
+    return (rr*CosD(fLadderTilt));
+  else
+    return -1;
+}
+
+//________________________________________________________________________
+void AliITSUv1Layer::SetLadderTilt(const Double_t t)
+{
+//
+// Sets the Ladder tilt angle (for turbo layers only)
+//
+// Input:
+//         t :  the ladder tilt angle
+//
+// Output:
+//
+// Return:
+//
+// Created:      08 Jul 2011  Mario Sitta
+//
+
+  if (fIsTurbo)
+    fLadderTilt = t;
+  else
+    AliError("Not a Turbo layer");
+
+}
+
+//________________________________________________________________________
+void AliITSUv1Layer::SetLadderWidth(const Double_t w){
+//
+// Sets the Ladder width (for turbo layers only)
+//
+// Input:
+//         w :  the ladder width
+//
+// Output:
+//
+// Return:
+//
+// Created:      08 Jul 2011  Mario Sitta
+//
+
+  if (fIsTurbo)
+    fLadderWidth = w;
+  else
+    AliError("Not a Turbo layer");
+
+}
+
+//________________________________________________________________________
+TGeoArb8 *AliITSUv1Layer::CreateLadderSide(const char *name,
+                         Double_t dz, Double_t angle, Double_t xSign,
+                         Double_t L, Double_t H, Double_t l) {
+//
+// Creates the V-shaped sides of the OB space frame
+// (from a similar method with same name and function
+// in AliITSv11GeometrySDD class by L.Gaudichet)
+//
+
+    // Create one half of the V shape corner of CF ladder
+  
+    TGeoArb8 *cfLaddSide = new TGeoArb8(dz);
+    cfLaddSide->SetName(name);
+
+    // Points must be in clockwise order
+    cfLaddSide->SetVertex(0, 0,  0);
+    cfLaddSide->SetVertex(2, xSign*(L*TMath::Sin(angle)-l*TMath::Cos(angle)),
+                         -L*TMath::Cos(angle)-l*TMath::Sin(angle));
+    cfLaddSide->SetVertex(4, 0,  0);
+    cfLaddSide->SetVertex(6, xSign*(L*TMath::Sin(angle)-l*TMath::Cos(angle)),
+                         -L*TMath::Cos(angle)-l*TMath::Sin(angle));
+    if (xSign < 0) {
+     cfLaddSide->SetVertex(1, 0, -H);
+     cfLaddSide->SetVertex(3, xSign*L*TMath::Sin(angle), -L*TMath::Cos(angle));
+     cfLaddSide->SetVertex(5, 0, -H);
+     cfLaddSide->SetVertex(7, xSign*L*TMath::Sin(angle), -L*TMath::Cos(angle));
+    } else {
+     cfLaddSide->SetVertex(1, xSign*L*TMath::Sin(angle), -L*TMath::Cos(angle));
+     cfLaddSide->SetVertex(3, 0, -H);
+     cfLaddSide->SetVertex(5, xSign*L*TMath::Sin(angle), -L*TMath::Cos(angle));
+     cfLaddSide->SetVertex(7, 0, -H);
+    }
+    return cfLaddSide;
+}
+
+//________________________________________________________________________
+TGeoCombiTrans *AliITSUv1Layer::CreateCombiTrans(const char *name,
+                                        Double_t dy, Double_t dz,
+                                        Double_t dphi, Bool_t planeSym) {
+//
+// Help method to create a TGeoCombiTrans matrix
+// (from a similar method with same name and function
+// in AliITSv11GeometrySDD class by L.Gaudichet)
+//
+
+    //
+    // return the TGeoCombiTrans which make a translation in y and z
+    // and a rotation in phi in the global coord system
+    // If planeSym = true, the rotation places the object symetrically
+    // (with respect to the transverse plane) to its position in the
+    // case planeSym = false
+    //
+
+    TGeoTranslation t1(dy*CosD(90.+dphi),dy*SinD(90.+dphi), dz);
+    TGeoRotation r1("",0.,0.,dphi);
+    TGeoRotation r2("",90, 180, -90-dphi);
+
+    TGeoCombiTrans *combiTrans1 = new TGeoCombiTrans(name);
+    combiTrans1->SetTranslation(t1);
+    if (planeSym) combiTrans1->SetRotation(r1);
+    else  combiTrans1->SetRotation(r2);
+    return combiTrans1;
+}
+
+//________________________________________________________________________
+void AliITSUv1Layer::AddTranslationToCombiTrans(TGeoCombiTrans* ct,
+                                                       Double_t dx,
+                                                       Double_t dy,
+                                                       Double_t dz) const{
+//
+// Help method to add a translation to a TGeoCombiTrans matrix
+// (from a similar method with same name and function
+// in AliITSv11GeometrySDD class by L.Gaudichet)
+//
+
+  // Add a dx,dy,dz translation to the initial TGeoCombiTrans
+  const Double_t *vect = ct->GetTranslation();
+  Double_t newVect[3] = {vect[0]+dx, vect[1]+dy, vect[2]+dz};
+  ct->SetTranslation(newVect);
+}
diff --git a/ITS/UPGRADE/AliITSUv1Layer.h b/ITS/UPGRADE/AliITSUv1Layer.h
new file mode 100644 (file)
index 0000000..520cbd0
--- /dev/null
@@ -0,0 +1,139 @@
+#ifndef ALIITSUV1LAYER_H
+#define ALIITSUV1LAYER_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+
+//*************************************************************************
+// This class Defines the Geometry for the ITS Upgrade using TGeo
+// This is a work class used to study different configurations
+// during the development of the new ITS structure.
+//
+//  Mario Sitta <sitta@to.infn.it>
+//*************************************************************************
+
+
+/*
+  $Id: AliITSUv1Layer.h
+ */
+
+#include "AliITSv11Geometry.h"
+#include "AliITSUv1.h"
+#include <TGeoManager.h>
+#include <TGeoCompositeShape.h>
+#include <TGeoXtru.h>
+
+class TGeoVolume;
+
+class AliITSUv1Layer : public AliITSv11Geometry {
+  public:
+    AliITSUv1Layer();
+    AliITSUv1Layer(Int_t debug);
+    AliITSUv1Layer(Int_t lay, Int_t debug);
+    AliITSUv1Layer(Int_t lay, Bool_t turbo, Int_t debug);
+    AliITSUv1Layer(const AliITSUv1Layer &source);
+    AliITSUv1Layer& operator=(const AliITSUv1Layer &source);
+    virtual ~AliITSUv1Layer();
+    //
+    Bool_t    IsTurbo() const {return fIsTurbo;};
+
+    Double_t  GetLadderThick() const {return fLadderThick;};
+    Double_t  GetLadderTilt()  const {return fLadderTilt;};
+    Double_t  GetLadderWidth() const {return fLadderWidth;};
+    Double_t  GetSensorThick() const {return fSensorThick;};
+    Double_t  GetNLadders()    const {return fNLadders;};
+    Double_t  GetNModules()    const {return fNModules;};
+    Double_t  GetRadius()      const {return fLayRadius;};
+    Double_t  GetPhi0()        const {return fPhi0;};
+    Double_t  GetZLength()     const {return fZLength;};
+    Int_t     GetDetType()     const {return fDetTypeID;}
+    AliITSUv1::AliITSUModel_t GetStaveModel() const {return fStaveModel;}
+    //
+    void      SetLadderThick(Double_t t)    {fLadderThick = t;};
+    void      SetLadderTilt(Double_t t);
+    void      SetLadderWidth(Double_t w);
+    void      SetSensorThick(Double_t t)    {fSensorThick = t;};
+    void      SetNLadders(Int_t n)          {fNLadders = n;};
+    void      SetNModules(Int_t m)          {fNModules = m;};
+    void      SetRadius(Double_t r)         {fLayRadius = r;};
+    void      SetPhi0(Double_t phi)         {fPhi0 = phi;}
+    void      SetZLength(Double_t z)        {fZLength   = z;};
+    void      SetDetType(Int_t tp)          {fDetTypeID = tp;}
+    void      SetBuildLevel(Int_t buildLevel){fBuildLevel=buildLevel;}
+    void      SetStaveModel(AliITSUv1::AliITSUModel_t model) {fStaveModel=model;}
+    virtual void CreateLayer(TGeoVolume *moth);
+
+  private:
+    void CreateLayerTurbo(TGeoVolume *moth);
+
+    Double_t RadiusOfTurboContainer();
+
+    TGeoVolume* CreateLadder(const TGeoManager *mgr=gGeoManager);
+    //TGeoVolume* CreateModule(Double_t x, Double_t z, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateModuleInnerB(Double_t x,Double_t y, Double_t z, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateModuleOuterB(Double_t x,Double_t y, Double_t z, const TGeoManager *mgr=gGeoManager);
+
+
+    TGeoVolume* CreateStaveStructInnerB(Double_t x,Double_t z, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateStaveModelInnerBDummy(Double_t x,Double_t z, const TGeoManager *mgr=gGeoManager) const;
+    TGeoVolume* CreateStaveModelInnerB0(Double_t x,Double_t z, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateStaveModelInnerB1(Double_t x,Double_t z, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateStaveModelInnerB21(Double_t x,Double_t z, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateStaveModelInnerB22(Double_t x,Double_t z, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateStaveModelInnerB3(Double_t x,Double_t z, const TGeoManager *mgr=gGeoManager);
+
+    TGeoVolume* CreateStaveOuterB(Double_t x, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateStaveModelOuterBDummy(Double_t x, const TGeoManager *mgr=gGeoManager) const;
+    TGeoVolume* CreateStaveModelOuterB0(Double_t x, const TGeoManager *mgr=gGeoManager) const;
+    TGeoVolume* CreateStaveModelOuterB1(Double_t x, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateSpaceFrameOuterB(Double_t x, const TGeoManager *mgr=gGeoManager);
+    TGeoVolume* CreateSpaceFrameOuterBDummy(Double_t x, const TGeoManager *mgr=gGeoManager) const;
+    TGeoVolume* CreateSpaceFrameOuterB0(Double_t x, const TGeoManager *mgr=gGeoManager);
+
+    TGeoArb8* CreateLadderSide(const char *name,
+                              Double_t dz, Double_t angle, Double_t xSign,
+                              Double_t L, Double_t H, Double_t l);
+    TGeoCombiTrans* CreateCombiTrans( const char *name,
+                                     Double_t dy, Double_t dz, Double_t dphi,
+                                     Bool_t planeSym=kFALSE);
+    void AddTranslationToCombiTrans( TGeoCombiTrans* ct,
+                                    Double_t dx=0, Double_t dy=0,
+                                    Double_t dz=0) const;
+
+
+    Int_t     fLayerNumber; // Current layer number
+    Double_t  fPhi0;        // lab phi of 1st ladder, in degrees!!!
+    Double_t  fLayRadius;   // Inner radius of this layer
+    Double_t  fZLength;     // Z length of this layer
+    Double_t  fSensorThick; // Sensor thickness
+    Double_t  fLadderThick; // Ladder thickness
+    Double_t  fLadderWidth; // Ladder width (for turbo layers only)
+    Double_t  fLadderTilt;  // Ladder tilt angle (for turbo layers only) in degrees
+    Int_t     fNLadders;    // Number of ladders in this layer
+    Int_t     fNModules;    // Number of modules per ladder in this layer
+    UInt_t    fDetTypeID;   // detector type id
+    Bool_t    fIsTurbo;     // True if this layer is a "turbo" layer
+    Int_t     fBuildLevel;  // Used for material studies
+
+    AliITSUv1::AliITSUModel_t fStaveModel; // The stave model
+
+    // Parameters for the Upgrade geometry
+
+    static const Double_t fgkDefaultSensorThick; // Default sensor thickness
+    static const Double_t fgkDefaultLadderThick; // Default ladder thickness
+
+    static const Double_t fgkOBHalfStaveWidth;   // OB Half Stave Width
+    static const Double_t fgkOBModuleGap;        // Gap between OB modules
+    static const Double_t fgkOBFlexCable1Thick;  // Thickness of
+    static const Double_t fgkOBFlexCable2Thick;  // OB flex cables
+    static const Double_t fgkOBBusCable1Thick;   // Thickness of
+    static const Double_t fgkOBBusCable2Thick;   // OB bus cables
+    static const Double_t fgkOBCarbonPlateThick; // OB Carbon Plate Thickness
+    static const Double_t fgkOBColdPlateThick;   // OB Cold Plate Thickness
+    static const Double_t fgkOBGlueThick;        // OB Glue total Thickness
+    static const Double_t fgkOBModuleZLength;    // OB Module Length along Z
+
+  ClassDef(AliITSUv1Layer,0) // ITS Upgrade v1 geometry
+};
+
+#endif
index 55846ed..971c874 100644 (file)
 set ( SRCS     
 #v0/AliITSupgrade.cxx 
 #v0/AliITSupgradeDigitizer.cxx 
-#AliITSUv11.cxx 
-#AliITSUv11Layer.cxx 
 #
 AliITSU.cxx 
 AliITSUv0.cxx 
 AliITSUv0Layer.cxx 
+AliITSUv1.cxx 
+AliITSUv1Layer.cxx 
 AliITSUModule.cxx
 AliITSUSimuParam.cxx
 AliITSUSimulation.cxx
index c49c7a8..b797698 100644 (file)
@@ -20,8 +20,8 @@
 #pragma link C++ class  AliITSU+;
 #pragma link C++ class  AliITSUv0+;
 #pragma link C++ class  AliITSUv0Layer+;
-//#pragma link C++ class  AliITSUv11+;       // obsolete
-//#pragma link C++ class  AliITSUv11Layer+;  // obsolete
+#pragma link C++ class  AliITSUv1+;
+#pragma link C++ class  AliITSUv1Layer+;
 #pragma link C++ class  AliITSUModule+;
 #pragma link C++ class  AliITSUSimuParam+;
 #pragma link C++ class  AliITSUSimulation+;
diff --git a/ITS/UPGRADE/testITSUv1/Config.C b/ITS/UPGRADE/testITSUv1/Config.C
new file mode 100644 (file)
index 0000000..12b0dff
--- /dev/null
@@ -0,0 +1,456 @@
+/// One can use the configuration macro in compiled mode by
+// root [0] gSystem->Load("libgeant321");
+// root [0] gSystem->SetIncludePath("-I$ROOTSYS/include -I$ALICE_ROOT/include\
+//                   -I$ALICE_ROOT -I$ALICE/geant3/TGeant3");
+// root [0] .x grun.C(1,"Config.C++"
+
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <Riostream.h>
+#include <TPDGCode.h>
+#include <TRandom.h>
+#include <TSystem.h>
+#include <TVirtualMC.h>
+#include <TGeant3TGeo.h>
+#include "STEER/AliRunLoader.h"
+#include "STEER/AliRun.h"
+#include "STEER/AliConfig.h"
+#include "PYTHIA6/AliDecayerPythia.h"
+#include "EVGEN/AliGenCocktail.h"
+#include "EVGEN/AliGenHIJINGpara.h"
+#include "EVGEN/AliGenFixed.h"
+#include "EVGEN/AliGenBox.h"
+#include "STEER/AliMagWrapCheb.h"
+#include "STRUCT/AliBODY.h"
+#include "STRUCT/AliMAG.h"
+#include "STRUCT/AliABSOv3.h"
+#include "STRUCT/AliDIPOv3.h"
+#include "STRUCT/AliHALLv3.h"
+#include "STRUCT/AliFRAMEv2.h"
+#include "STRUCT/AliSHILv3.h"
+#include "STRUCT/AliPIPEv3.h"
+#include "STRUCT/AliPIPEupgrade.h"
+#include "ITS/AliITSv11.h"
+#include "ITS/UPGRADE/AliITSUv1.h"
+#include "TPC/AliTPCv2.h"
+#include "TOF/AliTOFv6T0.h"
+#include "HMPID/AliHMPIDv3.h"
+#include "ZDC/AliZDCv3.h"
+#include "TRD/AliTRDv1.h"
+#include "TRD/AliTRDgeometry.h"
+#include "FMD/AliFMDv1.h"
+#include "MUON/AliMUONv1.h"
+#include "PHOS/AliPHOSv1.h"
+#include "PMD/AliPMDv1.h"
+#include "T0/AliT0v1.h"
+#include "EMCAL/AliEMCALv2.h"
+#include "ACORDE/AliACORDEv1.h"
+#include "VZERO/AliVZEROv7.h"
+#include <TVirtualMagField.h>
+#endif
+
+Int_t generatorFlag = 0;
+
+/* $Id: Config.C 47147 2011-02-07 11:46:44Z amastros $ */
+enum PprTrigConf_t
+{
+  kDefaultPPTrig, kDefaultPbPbTrig
+};
+
+const char * pprTrigConfName[] = {
+  "p-p","Pb-Pb"
+};
+
+
+Float_t EtaToTheta(Float_t arg);
+
+static PprTrigConf_t strig = kDefaultPPTrig;// default PP trigger configuration
+
+void Config()
+{
+  // ThetaRange is (0., 180.). It was (0.28,179.72) 7/12/00 09:00
+  // Theta range given through pseudorapidity limits 22/6/2001
+
+  // Set Random Number seed
+  gRandom->SetSeed(1); // Set 0 to use the currecnt time
+
+
+  // libraries required by geant321
+#if defined(__CINT__)
+  gSystem->Load("liblhapdf");
+  gSystem->Load("libEGPythia6");
+  gSystem->Load("libpythia6");
+  gSystem->Load("libAliPythia6");
+  gSystem->Load("libgeant321");
+  gSystem->Load("libhijing");  
+  gSystem->Load("libTHijing");
+#endif
+  gSystem->Load("libITSUpgradeBase.so");
+  gSystem->Load("libITSUpgradeSim.so");
+
+
+  new     TGeant3TGeo("C++ Interface to Geant3");
+
+  AliRunLoader* rl=0x0;
+
+
+  rl = AliRunLoader::Open("galice.root",
+                         AliConfig::GetDefaultEventFolderName(),
+                         "recreate");
+  if (rl == 0x0)
+    {
+      gAlice->Fatal("Config.C","Can not instatiate the Run Loader");
+      return;
+    }
+  rl->SetCompressionLevel(2);
+  rl->SetNumberOfEventsPerFile(2000);
+  gAlice->SetRunLoader(rl);
+
+  // Set the trigger configuration
+  // gAlice->SetTriggerDescriptor(pprTrigConfName[strig]);
+  //cout<<"Trigger configuration is set to  "<<pprTrigConfName[strig]<<endl;
+  AliSimulation::Instance()->SetTriggerConfig(pprTrigConfName[strig]);
+  cout<<"Trigger configuration is set to  pprTrigConfName[strig] "<<endl;
+
+  //
+  // Set External decayer
+  TVirtualMCDecayer *decayer = new AliDecayerPythia();
+
+  decayer->SetForceDecay(kAll);
+  decayer->Init();
+  gMC->SetExternalDecayer(decayer);
+  //=======================================================================
+  // ************* STEERING parameters FOR ALICE SIMULATION **************
+  // --- Specify event type to be tracked through the ALICE setup
+  // --- All positions are in cm, angles in degrees, and P and E in GeV
+
+
+  gMC->SetProcess("DCAY",1);
+  gMC->SetProcess("PAIR",1);
+  gMC->SetProcess("COMP",1);
+  gMC->SetProcess("PHOT",1);
+  gMC->SetProcess("PFIS",0);
+  gMC->SetProcess("DRAY",0);
+  gMC->SetProcess("ANNI",1);
+  gMC->SetProcess("BREM",1);
+  gMC->SetProcess("MUNU",1);
+  gMC->SetProcess("CKOV",1);
+  gMC->SetProcess("HADR",0);
+  gMC->SetProcess("LOSS",2);
+  gMC->SetProcess("MULS",1);
+  gMC->SetProcess("RAYL",1);
+
+  Float_t cut = 1.e-3;        // 1MeV cut by default
+  Float_t tofmax = 1.e10;
+
+  gMC->SetCut("CUTGAM", cut);
+  gMC->SetCut("CUTELE", cut);
+  gMC->SetCut("CUTNEU", cut);
+  gMC->SetCut("CUTHAD", cut);
+  gMC->SetCut("CUTMUO", cut);
+  gMC->SetCut("BCUTE",  cut); 
+  gMC->SetCut("BCUTM",  cut); 
+  gMC->SetCut("DCUTE",  cut); 
+  gMC->SetCut("DCUTM",  cut); 
+  gMC->SetCut("PPCUTM", cut);
+  gMC->SetCut("TOFMAX", tofmax); 
+
+  // Special generation for Valgrind tests
+  // Each detector is fired by few particles selected 
+  // to cover specific cases
+
+
+  // The cocktail itself
+  if (generatorFlag==0) {
+    // Fast generator with parametrized pi,kaon,proton distributions
+    
+    int  nParticles = 100;//14022;
+    AliGenHIJINGpara *gener = new AliGenHIJINGpara(nParticles);
+    gener->SetMomentumRange(0.1, 10.);
+    gener->SetPhiRange(0., 360.);
+    Float_t thmin = EtaToTheta(2.5);   // theta min. <---> eta max
+    Float_t thmax = EtaToTheta(-2.5);  // theta max. <---> eta min
+    gener->SetThetaRange(thmin,thmax);
+    gener->SetOrigin(0, 0, 0);  //vertex position
+    gener->SetSigma(50e-4, 50e-4, 5.0);   //Sigma in (X,Y,Z) (cm) on IP position
+    gener->SetVertexSmear(kPerEvent);
+    gener->Init();
+    
+  }
+  else if (generatorFlag==1) {
+    int  nParticlesHP = 12000;
+    int  nPiPFlat=200;
+    int  nPiMFlat=200;
+
+    AliGenCocktail *cocktail = new AliGenCocktail();
+    cocktail->SetProjectile("A", 208, 82);
+    cocktail->SetTarget    ("A", 208, 82);
+    Float_t thmin = EtaToTheta( 2.5);   // theta min. <---> eta max
+    Float_t thmax = EtaToTheta(-2.5);  // theta max. <---> eta min 
+    cocktail->SetThetaRange(thmin,thmax);
+    cocktail->SetEnergyCMS(5500);
+    cocktail->SetOrigin(0, 0, 0);  //vertex position
+    cocktail->SetSigma(50e-4, 50e-4, 5.0);   //Sigma in (X,Y,Z) (cm) on IP position
+    cocktail->SetVertexSmear(kPerEvent);
+    cocktail->Init();  
+
+    // HijingParam + flat pion spectrum
+    
+    AliGenHIJINGpara *generH = new AliGenHIJINGpara(nParticlesHP);
+    generH->SetMomentumRange(0.1, 10.);
+    generH->SetPhiRange(0., 360.);
+    generH->SetThetaRange(thmin,thmax);
+    generH->SetOrigin(0, 0, 0);  //vertex position
+    generH->SetSigma(0, 0, 0);   //Sigma in (X,Y,Z) (cm) on IP position
+    //    generH->Init();
+    //
+    cocktail->AddGenerator(generH,"hijingParam",1);
+    //
+    AliGenBox *gpipflat = new AliGenBox(nPiPFlat);
+    gpipflat->SetMomentumRange(0,10.);
+    gpipflat->SetPhiRange(0., 360.);
+    gpipflat->SetThetaRange(thmin,thmax);
+    gpipflat->SetPart(kPiPlus);
+    cocktail->AddGenerator(gpipflat,"genPiPlus",1);
+    //
+    //
+    AliGenBox *gpimflat = new AliGenBox(nPiMFlat);
+    gpimflat->SetMomentumRange(0,10.);
+    gpimflat->SetPhiRange(0., 360.);
+    gpimflat->SetThetaRange(thmin,thmax);
+    gpimflat->SetPart(kPiMinus);
+    cocktail->AddGenerator(gpimflat,"genPimus",1);
+    //
+    cocktail->Init();
+  }
+  else if (generatorFlag==2) {
+    
+    // Pure HiJing generator adapted to ~2000dNdy at highest energy
+    
+    AliGenHijing *generHijing = new AliGenHijing(-1);
+    generHijing->SetEnergyCMS(5500.); // GeV
+    generHijing->SetImpactParameterRange(0,2);
+    generHijing->SetReferenceFrame("CMS");
+    generHijing->SetProjectile("A", 208, 82);
+    generHijing->SetTarget    ("A", 208, 82);
+    generHijing->KeepFullEvent();
+    generHijing->SetJetQuenching(1);
+    generHijing->SetShadowing(1);
+    generHijing->SetSpectators(0);
+    generHijing->SetSelectAll(0);
+    generHijing->SetPtHardMin(4.5);
+    
+    AliGenerator*  gener = generHijing;
+    gener->SetSigma(50e-4, 50e-4, 5.0);   //Sigma in (X,Y,Z) (cm) on IP position
+    gener->SetVertexSmear(kPerEvent);
+    gener->Init();
+      
+  }
+  // 
+  
+
+  // 
+  // Activate this line if you want the vertex smearing to happen
+  // track by track
+  //
+  //VertexSmear_t perTrack;
+  //gener->SetVertexSmear(perTrack); 
+  // Field (L3 0.5 T)
+  //AliMagF* field = new AliMagF("map","map",2, -1.,1., 15, AliMagF::k5kGUniform);
+  //TGeoGlobalMagField::Instance()->SetField(field);
+  TGeoGlobalMagField::Instance()->SetField(new AliMagF("Maps","Maps", -1., -1., AliMagF::k5kG));
+
+  Int_t   iABSO  =  0;
+  Int_t   iDIPO  =  0;
+  Int_t   iFMD   =  0;
+  Int_t   iFRAME =  0;
+  Int_t   iHALL  =  0;
+  Int_t   iITS   =  1;
+  Int_t   iMAG   =  0;
+  Int_t   iMUON  =  0;
+  Int_t   iPHOS  =  0;
+  Int_t   iPIPE  =  0;
+  Int_t   iPMD   =  0;
+  Int_t   iHMPID =  0;
+  Int_t   iSHIL  =  0;
+  Int_t   iT0    =  0;
+  Int_t   iTOF   =  0;
+  Int_t   iTPC   =  0;
+  Int_t   iTRD   =  0;
+  Int_t   iZDC   =  0;
+  Int_t   iEMCAL =  0;
+  Int_t   iACORDE=  0;
+  Int_t   iVZERO =  0;
+  rl->CdGAFile();
+  //=================== Alice BODY parameters =============================
+  AliBODY *BODY = new AliBODY("BODY", "Alice envelop");
+
+  if (iMAG)
+    {
+      //=================== MAG parameters ============================
+      // --- Start with Magnet since detector layouts may be depending ---
+      // --- on the selected Magnet dimensions ---
+      AliMAG *MAG = new AliMAG("MAG", "Magnet");
+    }
+
+
+  if (iABSO)
+    {
+      //=================== ABSO parameters ============================
+      AliABSO *ABSO = new AliABSOv3("ABSO", "Muon Absorber");
+    }
+
+  if (iDIPO)
+    {
+      //=================== DIPO parameters ============================
+
+      AliDIPO *DIPO = new AliDIPOv3("DIPO", "Dipole version 3");
+    }
+
+  if (iHALL)
+    {
+      //=================== HALL parameters ============================
+
+      AliHALL *HALL = new AliHALLv3("HALL", "Alice Hall");
+    }
+
+
+  if (iFRAME)
+    {
+      //=================== FRAME parameters ============================
+
+      AliFRAMEv2 *FRAME = new AliFRAMEv2("FRAME", "Space Frame");
+      FRAME->SetHoles(1);
+    }
+
+  if (iSHIL)
+    {
+      //=================== SHIL parameters ============================
+
+      AliSHIL *SHIL = new AliSHILv3("SHIL", "Shielding Version 3");
+    }
+
+
+  if (iPIPE)
+    {
+      //=================== PIPE parameters ============================
+
+      AliPIPE *PIPE = new AliPIPEupgrade("PIPE", "Beam Pipe",0,1.8,0.08,40.0);
+      //AliPIPE *PIPE = new AliPIPEv3("PIPE", "Beam Pipe");
+    }
+  if (iITS)
+    {
+      //=================== ITS parameters ============================
+//      gROOT->ProcessLine(".x CreateITSU.C");
+      gROOT->ProcessLine(".x CreateITSUv1.C");
+//      gROOT->ProcessLine(".x CreateITSUv0.C");
+//      gROOT->ProcessLine(".x CreateITSU_MS.C");
+      //    CreateITSU();
+
+    }
+  if (iTPC)
+    {
+      //============================ TPC parameters ===================
+      AliTPC *TPC = new AliTPCv2("TPC", "Default");
+    }
+
+
+  if (iTOF) {
+    //=================== TOF parameters ============================
+    AliTOF *TOF = new AliTOFv6T0("TOF", "normal TOF");
+  }
+
+
+  if (iHMPID)
+    {
+      //=================== HMPID parameters ===========================
+      AliHMPID *HMPID = new AliHMPIDv3("HMPID", "normal HMPID");
+
+    }
+
+
+  if (iZDC)
+    {
+      //=================== ZDC parameters ============================
+
+      AliZDC *ZDC = new AliZDCv3("ZDC", "normal ZDC");
+    }
+
+  if (iTRD)
+    {
+      //=================== TRD parameters ============================
+
+      AliTRD *TRD = new AliTRDv1("TRD", "TRD slow simulator");
+      AliTRDgeometry *geoTRD = TRD->GetGeometry();
+      // Partial geometry: modules at 2,3,4,6,11,12,14,15
+      // starting at 6h in positive direction
+      geoTRD->SetSMstatus(0,0);
+      geoTRD->SetSMstatus(1,0);
+      geoTRD->SetSMstatus(5,0);
+      geoTRD->SetSMstatus(7,0);
+      geoTRD->SetSMstatus(8,0);
+      geoTRD->SetSMstatus(9,0);
+      geoTRD->SetSMstatus(10,0);
+      geoTRD->SetSMstatus(13,0);
+      geoTRD->SetSMstatus(16,0);
+      geoTRD->SetSMstatus(17,0);
+    }
+
+  if (iFMD)
+    {
+      //=================== FMD parameters ============================
+      AliFMD *FMD = new AliFMDv1("FMD", "normal FMD");
+    }
+
+  if (iMUON)
+    {
+      //=================== MUON parameters ===========================
+      // New MUONv1 version (geometry defined via builders)
+      AliMUON *MUON = new AliMUONv1("MUON","default");
+    }
+  //=================== PHOS parameters ===========================
+
+  if (iPHOS)
+    {
+      AliPHOS *PHOS = new AliPHOSv1("PHOS", "IHEP");
+    }
+
+
+  if (iPMD)
+    {
+      //=================== PMD parameters ============================
+      AliPMD *PMD = new AliPMDv1("PMD", "normal PMD");
+    }
+
+  if (iT0)
+    {
+      //=================== T0 parameters ============================
+      AliT0 *T0 = new AliT0v1("T0", "T0 Detector");
+    }
+
+  if (iEMCAL)
+    {
+      //=================== EMCAL parameters ============================
+      AliEMCAL *EMCAL = new AliEMCALv2("EMCAL", "EMCAL_COMPLETEV1");
+    }
+
+  if (iACORDE)
+    {
+      //=================== ACORDE parameters ============================
+      AliACORDE *ACORDE = new AliACORDEv1("ACORDE", "normal ACORDE");
+    }
+
+  if (iVZERO)
+    {
+      //=================== VZERO parameters ============================
+      AliVZERO *VZERO = new AliVZEROv7("VZERO", "normal VZERO");
+    }
+
+
+}
+
+Float_t EtaToTheta(Float_t arg){
+  return (180./TMath::Pi())*2.*atan(exp(-arg));
+}
+
diff --git a/ITS/UPGRADE/testITSUv1/CreateITSUv0.C b/ITS/UPGRADE/testITSUv1/CreateITSUv0.C
new file mode 100644 (file)
index 0000000..eb4689f
--- /dev/null
@@ -0,0 +1,158 @@
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <TSystem.h>
+#include <TMath.h>
+#endif
+
+//---------------------------------------
+double radii2Turbo(double rMin,double rMid,double rMax, double sensW)
+{
+  // compute turbo angle from radii and sensor width
+  return TMath::ASin((rMax*rMax-rMin*rMin)/(2*rMid*sensW))*TMath::RadToDeg();
+}
+
+double radii2Phi(double rMin,double rMid,double rMax, double sensW)
+{
+  // compute phi coverage
+  return 2*TMath::ACos((rMax+rMin)*
+                      (rMid*rMid+rMin*rMax-sensW*sensW/4.)/
+                      (4.*rMid*rMax*rMin));
+}
+
+void CreateITSUv0()
+{
+  //
+  gSystem->Load("libITSUpgradeBase.so");
+  gSystem->Load("libITSUpgradeSim.so");
+
+
+  // build ITS upgrade detector
+  // sensitive area 13x15mm (X,Z) with 20x20 micron pitch, 2mm dead zone on readout side and 50 micron guardring
+  const double kSensThick = 18e-4;
+  const double kPitchX = 20e-4;
+  const double kPitchZ = 20e-4;
+  const int    kNRow   = 650; 
+  const int    kNCol   = 750;
+  const int    kNChips = 2;
+  const double kLrThick03 = 120e-4;   // -> effective thickness for ~0.3%X layers
+  const double kLrThick08 = 600e-4;   // -> effective thickness for ~0.8%X layers
+  //
+  const double kReadOutEdge = 0.2;   // width of the readout edge (passive bottom)
+  const double kGuardRing   = 50e-4; // width of passive area on left/right/top of the sensor
+  //
+  const int kNLr = 7;
+  const int kNLrInner = 3;
+  const int kBuildLevel = 3;
+  enum {kRmn,kRmd,kRmx,kNModPerStave,kPhi0,kNStave,kNPar};
+  const double tdr5dat[kNLr][kNPar] = { 
+    {2.24, 2.34, 2.67,  9., 16.37, 12}, // for each inner layer: rMin,rMid,rMax,NMod/Stave,phi0, nStave
+    {3.01, 3.15, 3.46,  9., 12.03, 16},
+    {3.78, 3.93, 4.21,  9., 10.02, 20},
+    {-1,   19.4, -1,    28., 0.  , 49},  // for others: -, rMid, -, NMod/Stave, phi0, nStave
+    {-1,   24.7, -1,    28., 0.  , 61},
+    {-1,   35.32,-1,    49., 0.  , 88},
+    {-1,   40.52,-1,    49., 0.  , 100}
+  };
+
+  // create segmentations:
+  AliITSUSegmentationPix* seg0 = new AliITSUSegmentationPix(0,        // segID (0:9)
+                                                           kNChips,  // chips per module
+                                                           kNChips*kNCol,    // ncols (total for module)
+                                                           kNRow,    // nrows
+                                                           kPitchX,  // default row pitch in cm
+                                                           kPitchZ,  // default col pitch in cm
+                                                           kSensThick,  // sensor thickness in cm
+                                                           -1,     // no special left col between chips
+                                                           -1,     // no special right col between chips
+                                                           kGuardRing, // left
+                                                           kGuardRing, // right
+                                                           kGuardRing, // top
+                                                           kReadOutEdge  // bottom
+                                                           );    // see AliITSUSegmentationPix.h for extra options
+  seg0->Store(AliITSUGeomTGeo::GetITSsegmentationFileName());
+  //
+  AliITSUSegmentationPix* seg1 = new AliITSUSegmentationPix(1,        // segID (0:9)
+                                                           kNChips,  // chips per module
+                                                           kNChips*kNCol,    // ncols (total for module)
+                                                           2*kNRow,    // nrows for oute layers
+                                                           kPitchX,  // default row pitch in cm
+                                                           kPitchZ,  // default col pitch in cm
+                                                           kSensThick,  // sensor thickness in cm
+                                                           -1,     // no special left col between chips
+                                                           -1,     // no special right col between chips
+                                                           kGuardRing, // left
+                                                           kGuardRing, // right
+                                                           kReadOutEdge, // top   !!! readout from both sides
+                                                           kReadOutEdge  // bottom
+                                                           );    // see AliITSUSegmentationPix.h for extra options
+  seg1->Store(AliITSUGeomTGeo::GetITSsegmentationFileName());
+  //
+  seg0->Print();
+  seg1->Print();
+  //
+  const double kMinOvl = 0.005; // require active zones overlap
+  const double kTilt = -10.; // tilt in degrees for outer layers
+  double dzLr,rLr,phi0,turbo,thick;
+  AliITSUSegmentationPix* seg=0;
+  int nStaveLr,nModPerStaveLr,idLr;
+  //      virtual void   DefineLayerTurbo(const Int_t nlay, const Double_t r,  const Double_t zlen, const Int_t nladd,   const Int_t nmod, const Double_t width,
+  //                             const Double_t tilt,   const Double_t lthick = 0.,    const Double_t dthick = 0.,   const UInt_t detType=0);
+  AliITSUv1 *ITS  = new AliITSUv1("ITS Upgrade",7);
+  ITS->SetStaveModelIB(AliITSUv1::kIBModel22);
+  ITS->SetStaveModelOB(AliITSUv1::kOBModel0);
+  //
+  const int kNWrapVol = 3;
+  const double wrpRMin[kNWrapVol]  = { 2.1, 15.0, 32.0};
+  const double wrpRMax[kNWrapVol]  = { 7.0, 27.0, 43.0};
+  const double wrpZSpan[kNWrapVol] = {28.0, 86.0, 150.0};
+  ITS->SetNWrapVolumes(kNWrapVol); // define wrapper volumes for layers
+  for (int iw=0;iw<kNWrapVol;iw++) ITS->DefineWrapVolume(iw,wrpRMin[iw],wrpRMax[iw],wrpZSpan[iw]);
+  //
+  for (int idLr=0;idLr<kNLr;idLr++) {
+    rLr   = tdr5dat[idLr][kRmd];
+    phi0  = tdr5dat[idLr][kPhi0]; 
+    if (idLr<kNLrInner) {
+      seg = seg0;
+      turbo = -radii2Turbo(tdr5dat[idLr][kRmn],rLr,tdr5dat[idLr][kRmx],seg->Dx());     
+      thick = kLrThick03;
+    }
+    else {
+      seg   = seg1;
+      turbo = kTilt;
+      thick = kLrThick08;
+    }
+    nStaveLr = TMath::Nint(tdr5dat[idLr][kNStave]);
+    if (nStaveLr<0) nStaveLr = getNStaves(seg,kTilt,rLr,kMinOvl); // calculate automatically
+    nModPerStaveLr =  TMath::Nint(tdr5dat[idLr][kNModPerStave]);
+    ITS->DefineLayerTurbo(idLr, phi0, rLr, nModPerStaveLr*seg->Dz(), nStaveLr, nModPerStaveLr, 
+                         seg->Dx(), turbo, thick, seg->Dy(), seg->GetDetTypeID());
+    printf("Add Lr%d: R=%6.2f DZ:%6.2f Turbo:%+6.2f Staves:%3d NMod/Stave:%3d\n",idLr,rLr,nModPerStaveLr*seg->Dz(),turbo,nStaveLr,nModPerStaveLr);
+    //
+  }
+  //  
+}
+
+Int_t getNStaves(AliITSUSegmentationPix* seg, double tilt, double r0, double minOvl)
+{
+  double dphi = (90.-tilt)*TMath::DegToRad();
+  double cs = TMath::Cos(dphi);
+  double sn = TMath::Sin(dphi);  
+  double dx = seg->Dx();
+  double tL = -dx/2 + seg->GetGuardBot();
+  double tU =  dx/2 - seg->GetGuardTop();
+  //
+  double xL = r0 + cs*tL;
+  double yL =      sn*tL;
+  double xU = r0 + cs*tU;
+  double yU =      sn*tU;
+  double phiL = TMath::ATan2(yL,xL);
+  double phiU = TMath::ATan2(yU,xU);
+  double dphi = TMath::Abs(phiL-phiU);
+  if (dphi>TMath::Pi()) dphi = TMath::Abs(dphi-TMath::Pi()*2);
+  double span = dphi*r0;
+  //
+  double ov = -1;
+  int nStaveLr = 1 + r0*TMath::Pi()*2/span;
+  do { ov = 1.-r0*TMath::Pi()*2/nStaveLr/span; } while ( minOvl>=0 && ov<minOvl && nStaveLr++ );
+  printf("Reccommend %2d staves for R=%5.2f, ActiveOvl=%5.2f\% (%6.f micron)\n",nStaveLr,r0,ov*100,ov*span*1e4);
+  return nStaveLr;
+}
diff --git a/ITS/UPGRADE/testITSUv1/CreateITSUv1.C b/ITS/UPGRADE/testITSUv1/CreateITSUv1.C
new file mode 100644 (file)
index 0000000..06950e5
--- /dev/null
@@ -0,0 +1,168 @@
+#if !defined(__CINT__) || defined(__MAKECINT__)
+#include <TSystem.h>
+#include <TMath.h>
+#endif
+
+//---------------------------------------
+double radii2Turbo(double rMin,double rMid,double rMax, double sensW)
+{
+  // compute turbo angle from radii and sensor width
+  return TMath::ASin((rMax*rMax-rMin*rMin)/(2*rMid*sensW))*TMath::RadToDeg();
+}
+
+double radii2Phi(double rMin,double rMid,double rMax, double sensW)
+{
+  // compute phi coverage
+  return 2*TMath::ACos((rMax+rMin)*
+                      (rMid*rMid+rMin*rMax-sensW*sensW/4.)/
+                      (4.*rMid*rMax*rMin));
+}
+
+void CreateITSUv1()
+{
+  //
+  gSystem->Load("libITSUpgradeBase.so");
+  gSystem->Load("libITSUpgradeSim.so");
+
+
+  // build ITS upgrade detector
+  // sensitive area 13x15mm (X,Z) with 20x20 micron pitch, 2mm dead zone on readout side and 50 micron guardring
+  const double kSensThick = 18e-4;
+  const double kPitchX = 20e-4;
+  const double kPitchZ = 20e-4;
+  const int    kNRow   = 650; 
+  const int    kNCol   = 750;
+  const int    kNChips = 2;
+  const double kLrThick03 = 120e-4;   // -> effective thickness for ~0.3%X layers
+  const double kLrThick08 = 600e-4;   // -> effective thickness for ~0.8%X layers
+  //
+  const double kReadOutEdge = 0.2;   // width of the readout edge (passive bottom)
+  const double kGuardRing   = 50e-4; // width of passive area on left/right/top of the sensor
+  //
+  const int kNLr = 7;
+  const int kNLrInner = 3;
+  const int kBuildLevel = 3;
+  enum {kRmn,kRmd,kRmx,kNModPerStave,kPhi0,kNStave,kNPar};
+  // Radii are from last TDR (ALICE-TDR-017.pdf Tab. 1.1, rMid is mean value)
+  const double tdr5dat[kNLr][kNPar] = { 
+    {2.24, 2.34, 2.67,  9., 16.37, 12}, // for each inner layer: rMin,rMid,rMax,NMod/Stave,phi0, nStave
+    {3.01, 3.15, 3.46,  9., 12.03, 16},
+    {3.78, 3.93, 4.21,  9., 10.02, 20},
+    {-1,  19.6 ,   -1,  4.,  0.  , 24},  // for others: -, rMid, -, NMod/Stave, phi0, nStave // 24 was 49
+    {-1,  24.55, -1,    4.,  0.  , 30},  // 30 was 61
+    {-1,  34.39, -1,    7.,  0.  , 42},  // 42 was 88
+    {-1,  39.34, -1,    7.,  0.  , 48}   // 48 was 100
+  };
+  const int nChipsPerModule = 7; // For OB we have to specify how many chips
+
+  // create segmentations:
+  AliITSUSegmentationPix* seg0 = new AliITSUSegmentationPix(0,        // segID (0:9)
+                                                           kNChips,  // chips per module
+                                                           kNChips*kNCol,    // ncols (total for module)
+                                                           kNRow,    // nrows
+                                                           kPitchX,  // default row pitch in cm
+                                                           kPitchZ,  // default col pitch in cm
+                                                           kSensThick,  // sensor thickness in cm
+                                                           -1,     // no special left col between chips
+                                                           -1,     // no special right col between chips
+                                                           kGuardRing, // left
+                                                           kGuardRing, // right
+                                                           kGuardRing, // top
+                                                           kReadOutEdge  // bottom
+                                                           );    // see AliITSUSegmentationPix.h for extra options
+  seg0->Store(AliITSUGeomTGeo::GetITSsegmentationFileName());
+  //
+  AliITSUSegmentationPix* seg1 = new AliITSUSegmentationPix(1,        // segID (0:9)
+                                                           kNChips,  // chips per module
+                                                           kNChips*kNCol,    // ncols (total for module)
+                                                           2*kNRow,    // nrows for oute layers
+                                                           kPitchX,  // default row pitch in cm
+                                                           kPitchZ,  // default col pitch in cm
+                                                           kSensThick,  // sensor thickness in cm
+                                                           -1,     // no special left col between chips
+                                                           -1,     // no special right col between chips
+                                                           kGuardRing, // left
+                                                           kGuardRing, // right
+                                                           kReadOutEdge, // top   !!! readout from both sides
+                                                           kReadOutEdge  // bottom
+                                                           );    // see AliITSUSegmentationPix.h for extra options
+  seg1->Store(AliITSUGeomTGeo::GetITSsegmentationFileName());
+  //
+  seg0->Print();
+  seg1->Print();
+  //
+  const double kMinOvl = 0.005; // require active zones overlap
+  const double kTilt = -10.; // tilt in degrees for outer layers
+  double dzLr,rLr,phi0,turbo,thick;
+  AliITSUSegmentationPix* seg=0;
+  int nStaveLr,nModPerStaveLr,idLr;
+  //      virtual void   DefineLayerTurbo(const Int_t nlay, const Double_t r,  const Double_t zlen, const Int_t nladd,   const Int_t nmod, const Double_t width,
+  //                             const Double_t tilt,   const Double_t lthick = 0.,    const Double_t dthick = 0.,   const UInt_t detType=0);
+  AliITSUv1 *ITS  = new AliITSUv1("ITS Upgrade",7);
+  ITS->SetStaveModelIB(AliITSUv1::kIBModel22);
+  ITS->SetStaveModelOB(AliITSUv1::kOBModel1);
+  //
+  const int kNWrapVol = 3;
+  const double wrpRMin[kNWrapVol]  = { 2.1, 15.0, 32.0};
+  const double wrpRMax[kNWrapVol]  = { 7.0, 27.0, 43.0};
+  const double wrpZSpan[kNWrapVol] = {28.0, 96.0, 158.0};
+  ITS->SetNWrapVolumes(kNWrapVol); // define wrapper volumes for layers
+  for (int iw=0;iw<kNWrapVol;iw++) ITS->DefineWrapVolume(iw,wrpRMin[iw],wrpRMax[iw],wrpZSpan[iw]);
+  //
+  for (int idLr=0;idLr<kNLr;idLr++) {
+    rLr   = tdr5dat[idLr][kRmd];
+    phi0  = tdr5dat[idLr][kPhi0]; 
+    if (idLr<kNLrInner) {
+      seg = seg0;
+      turbo = -radii2Turbo(tdr5dat[idLr][kRmn],rLr,tdr5dat[idLr][kRmx],seg->Dx());     
+      thick = kLrThick03;
+    }
+    else {
+      seg   = seg1;
+      turbo = kTilt;
+      thick = kLrThick08;
+    }
+    nStaveLr = TMath::Nint(tdr5dat[idLr][kNStave]);
+    if (nStaveLr<0) nStaveLr = getNStaves(seg,kTilt,rLr,kMinOvl); // calculate automatically
+    nModPerStaveLr =  TMath::Nint(tdr5dat[idLr][kNModPerStave]);
+    int nChipsPerStaveLr = nModPerStaveLr;
+    if (idLr>=kNLrInner) {
+      nChipsPerStaveLr *= nChipsPerModule;
+      ITS->DefineLayer(idLr, phi0, rLr, nChipsPerStaveLr*seg->Dz(), nStaveLr, nModPerStaveLr, 
+                      thick, seg->Dy(), seg->GetDetTypeID(),kBuildLevel);
+      printf("Add Lr%d: R=%6.2f DZ:%6.2f Staves:%3d NMod/Stave:%3d\n",idLr,rLr,nChipsPerStaveLr*seg->Dz(),nStaveLr,nModPerStaveLr);
+    } else {
+      ITS->DefineLayerTurbo(idLr, phi0, rLr, nChipsPerStaveLr*seg->Dz(), nStaveLr, nModPerStaveLr, 
+                         seg->Dx(), turbo, thick, seg->Dy(), seg->GetDetTypeID());
+      printf("Add Lr%d: R=%6.2f DZ:%6.2f Turbo:%+6.2f Staves:%3d NMod/Stave:%3d\n",idLr,rLr,nChipsPerStaveLr*seg->Dz(),turbo,nStaveLr,nModPerStaveLr);
+    }
+    //
+  }
+  //  
+}
+
+Int_t getNStaves(AliITSUSegmentationPix* seg, double tilt, double r0, double minOvl)
+{
+  double dphi = (90.-tilt)*TMath::DegToRad();
+  double cs = TMath::Cos(dphi);
+  double sn = TMath::Sin(dphi);  
+  double dx = seg->Dx();
+  double tL = -dx/2 + seg->GetGuardBot();
+  double tU =  dx/2 - seg->GetGuardTop();
+  //
+  double xL = r0 + cs*tL;
+  double yL =      sn*tL;
+  double xU = r0 + cs*tU;
+  double yU =      sn*tU;
+  double phiL = TMath::ATan2(yL,xL);
+  double phiU = TMath::ATan2(yU,xU);
+  double dphi = TMath::Abs(phiL-phiU);
+  if (dphi>TMath::Pi()) dphi = TMath::Abs(dphi-TMath::Pi()*2);
+  double span = dphi*r0;
+  //
+  double ov = -1;
+  int nStaveLr = 1 + r0*TMath::Pi()*2/span;
+  do { ov = 1.-r0*TMath::Pi()*2/nStaveLr/span; } while ( minOvl>=0 && ov<minOvl && nStaveLr++ );
+  printf("Reccommend %2d staves for R=%5.2f, ActiveOvl=%5.2f\% (%6.f micron)\n",nStaveLr,r0,ov*100,ov*span*1e4);
+  return nStaveLr;
+}
diff --git a/ITS/UPGRADE/testITSUv1/sim.C b/ITS/UPGRADE/testITSUv1/sim.C
new file mode 100644 (file)
index 0000000..cce4ed5
--- /dev/null
@@ -0,0 +1,24 @@
+void sim(Int_t nev=3) {
+
+  gSystem->Exec(" rm itsSegmentations.root ");
+  AliSimulation simulator;
+  //  simulator.SetMakeSDigits("");
+
+  //  simulator.SetMakeDigits("");
+
+  simulator.SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  simulator.SetSpecificStorage("GRP/GRP/Data",
+                              Form("local://%s",gSystem->pwd()));
+  simulator.SetSpecificStorage("ITS/Align/Data",
+                              Form("local://%s",gSystem->pwd()));
+  simulator.SetSpecificStorage("ITS/Calib/SimuParam",
+                              Form("local://%s",gSystem->pwd()));
+  simulator.SetRunHLT("");
+  simulator.SetRunQA(":");
+
+  TStopwatch timer;
+  timer.Start();
+  simulator.Run(nev);
+  timer.Stop();
+  timer.Print();
+}