]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSvSDD03.cxx
removing unnecessary include file
[u/mrichter/AliRoot.git] / ITS / AliITSvSDD03.cxx
index da825529efae0223b17f87aa6c64db9d82a904ce..2bde3773b69bb33f78864b77cb5d74ec0e7c33f3 100644 (file)
 //                                                             //
 /////////////////////////////////////////////////////////////////
 
-#include <TGeometry.h>
-#include <TNode.h>
-#include <TBRIK.h>
+#include <TGeoGlobalMagField.h>
+#include <TGeoManager.h>
+#include <TGeoMatrix.h>
 #include <TLorentzVector.h>
 #include <TVirtualMC.h>
 
 #include "AliMC.h"
 #include "AliRun.h"
 #include "AliMagF.h"
-#include "AliITSGeant3Geometry.h"
 #include "AliTrackReference.h"
 #include "AliITShit.h"
-#include "AliITS.h"
-#include "AliITSvSDD03.h"
 #include "AliITSgeom.h"
 #include "AliITSgeomSDD.h"
 #include "AliITSgeomSSD.h"
 #include "AliITSDetTypeSim.h"
-#include "AliITSresponseSPD.h"
-#include "AliITSresponseSDD.h"
-#include "AliITSresponseSSD.h"
+#include "AliITSCalibrationSPD.h"
+#include "AliITSCalibrationSDD.h"
+#include "AliITSCalibrationSSD.h"
 #include "AliITSsegmentationSPD.h"
 #include "AliITSsegmentationSDD.h"
 #include "AliITSsegmentationSSD.h"
-#include "AliITSsimulationSPDdubna.h"
+#include "AliITSsimulationSPD.h"
 #include "AliITSsimulationSDD.h"
 #include "AliITSsimulationSSD.h"
 
+#include "AliITSvSDD03.h"
 
 ClassImp(AliITSvSDD03)
 
 //______________________________________________________________________
 AliITSvSDD03::AliITSvSDD03() :
 AliITS(),
-fGeomDetOut(kFALSE),
-fGeomDetIn(kFALSE),
-fMajorVersion(1),
+fMajorVersion(IsVersion()),
 fMinorVersion(2),
-fEuclidGeomDet(),
-fRead(),
-fWrite(),
-fDet1(300.0),
-fDet2(300.0),
-fChip1(300.0),
-fChip2(300.0),
 fIDMother(0),
-fYear(2003){
+fYear(2003),
+fTarg(kNoTarg),
+fTargThick(0.0),
+fIgm(kvSDD03){
     ////////////////////////////////////////////////////////////////////////
     // Standard default constructor for the ITS SDD test beam 2002 version 1.
     // Inputs:
@@ -78,34 +70,21 @@ fYear(2003){
     // Return:
     //    A default created class.
     ////////////////////////////////////////////////////////////////////////
-    Int_t i;
 
     fIdN          = 0;
     fIdName       = 0;
     fIdSens       = 0;
-    fEuclidOut    = kFALSE; // Don't write Euclide file
-    for(i=0;i<60;i++) fRead[i] = '\0';
-    for(i=0;i<60;i++) fWrite[i] = '\0';
-    for(i=0;i<60;i++) fEuclidGeomDet[i] = '\0';
-    fTarg=kNoTarg;
-    fTargThick=0;
 }
 //______________________________________________________________________
 AliITSvSDD03::AliITSvSDD03(const char *title,Int_t year):
 AliITS("ITS", title),
-fGeomDetOut(kFALSE),
-fGeomDetIn(kFALSE),
-fMajorVersion(1),
+fMajorVersion(IsVersion()),
 fMinorVersion(2),
-fEuclidGeomDet(),
-fRead(),
-fWrite(),
-fDet1(300.0),
-fDet2(300.0),
-fChip1(300.0),
-fChip2(300.0),
 fIDMother(0),
-fYear(2003){
+fYear(year),
+fTarg(kNoTarg),
+fTargThick(0.0),
+fIgm(kvSDD03){
     ////////////////////////////////////////////////////////////////////////
     //    Standard constructor for the ITS SDD testbeam 2002 version 1.
     // Inputs:
@@ -124,51 +103,7 @@ fYear(2003){
     fIdName[2] = "ISNT";
     fIdSens    = new Int_t[fIdN];
     for(i=0;i<fIdN;i++) fIdSens[i] = 0;
-    fEuclidOut    = kFALSE; // Don't write Euclide file
-    fYear         = year;
-    fTarg=kNoTarg;
-    fTargThick=0;    
-    SetThicknessDet1();
-    SetThicknessDet2();
-    SetThicknessChip1();
-    SetThicknessChip2();                        
 
-    fEuclidGeometry="$ALICE_ROOT/ITS/ITSgeometry_vSDD032.euc";
-    strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_vSDD032.det",60);
-    strncpy(fRead,fEuclidGeomDet,60);
-    strncpy(fWrite,fEuclidGeomDet,60);
-}
-//______________________________________________________________________
-AliITSvSDD03::AliITSvSDD03(const AliITSvSDD03 &source) :  AliITS(source){
-    ////////////////////////////////////////////////////////////////////////
-    //     Copy Constructor for ITS SDD test beam 2002 version 1.
-    // This class is not to be copied. Function only dummy.
-    // Inputs:
-    //    const AliITSvSDD03 &source   The class to be copied
-    // Outputs:
-    //    none.
-    // Return:
-    //    A warning message.
-    ////////////////////////////////////////////////////////////////////////
-    if(&source == this) return;
-    Warning("Copy Constructor","Not allowed to copy AliITSvSDD03");
-    return;
-}
-//______________________________________________________________________
-AliITSvSDD03& AliITSvSDD03::operator=(const AliITSvSDD03 &source){
-    ////////////////////////////////////////////////////////////////////////
-    //    Assignment operator for the ITS SDD test beam 2002 version 1.
-    // This class is not to be copied. Function only dummy.
-    // Inputs:
-    //    const AliITSvSDD03 &source   The class to be copied
-    // Outputs:
-    //    none.
-    // Return:
-    //    A Warning message
-    ////////////////////////////////////////////////////////////////////////
-    if(&source == this) return *this;
-    Warning("= operator","Not allowed to copy AliITSvSDD03");
-    return *this;
 }
 //______________________________________________________________________
 AliITSvSDD03::~AliITSvSDD03() {
@@ -182,127 +117,7 @@ AliITSvSDD03::~AliITSvSDD03() {
     //    none.
     ////////////////////////////////////////////////////////////////////////
 }
-//______________________________________________________________________
-void AliITSvSDD03::BuildGeometry(){
-    ////////////////////////////////////////////////////////////////////////
-    //    Geometry builder for the ITS SDD test beam 2002 version 1.
-    //    ALIC    ALICE Mother Volume
-    //     |- ITSV     ITS Mother Volume
-    //         |- IDET       Detector under Test
-    //         |   |- ITS0       SDD Si Chip
-    //         |   |  |- ITST      SDD Sensitivve Volume
-    //         |   |- IPC0 *5    Readout chip
-    //         |- ITEL *4    SDD Telescope
-    //             |- IMB0       SDD Si Chip
-    //             |   |- IMBS     SDD Sensitive volume
-    //             |- ICMB       Chip MiniBus.
-    // Inputs:
-    //    none.
-    // Outputs:
-    //    none.
-    // Return:
-    //    none.
-    ////////////////////////////////////////////////////////////////////////
-    // Get the top alice volume.
-    TNode *nALIC = gAlice->GetGeometry()->GetNode("alice");
-    nALIC->cd();
-
-    // Define ITS Mother Volume
-    Float_t data[3];
-    Float_t ddettest=200.0E-4,ddettelescope=300.0E-4;
-    //Float_t yposition= 0.0;
-    TRotMatrix *r0 = new TRotMatrix("ITSidrotm0","ITSidrotm0",
-                                   90.0,0,0.0,0,90.0,270.0);
-    data[0] = 10.0;
-    data[1] = 10.0;
-    data[2] = 100.0;
-    TBRIK *sITSVshape =new TBRIK("ITSVshape","ITS Logical Mother Volume","Air",
-                                data[0],data[1],data[2]);
-    TNode *sITSV = new TNode("ITSV","ITS Mother Volume",sITSVshape,
-                           0.0,0.0,0.0,0,0);
-    sITSV->cd(); // set ourselve into ITSV subvolume of ALIC
-
-    // SSD part of telescope (MiniBuS)
-    data[0] = 1.06;
-    data[1] = 0.5*ddettelescope;
-    data[2] = 1.1;
-    TBRIK *sIMB0shape = new TBRIK("IMB0shape","SDD wafer","Si",
-                                data[0],data[1],data[2]);
-    Float_t detMiniBusX,detMiniBusY,detMiniBusZ;
-    data[0] = detMiniBusX = 0.5*384*50.0E-4;
-    data[1] = detMiniBusY = 0.5*ddettelescope;
-    data[2] = detMiniBusZ = 1.0;
-    TBRIK *sIMBSshape = new TBRIK("IMBSshape","SDD Sensitive volume","Si",
-                                data[0],data[1],data[2]);
-
-    data[0] = 1.36;
-    data[1] = 0.47;
-    data[2] = 1.36;
-    TBRIK *sITELshape = new TBRIK("ITELshape","ITELshape","Air",
-                                data[0],data[1],data[2]);
-
-
-    // SDD under test
-    Float_t spdX,spdY,spdZ;
-    data[0] = 3.62500;
-    data[1] = 0.5*ddettest;
-    data[2] = 4.37940;
-    TBRIK *sITS0shape = new TBRIK("ITS0shape","SDD wafer","Si",
-                                data[0],data[1],data[2]); // contains detector
-    data[0] = spdX = 3.50860;
-    data[1] = spdY = 0.5*ddettest;
-    data[2] = spdZ = 3.76320;
-    TBRIK *sITSTshape = new TBRIK("ITSTshape","SDD sensitive volume","Si",
-                                data[0],data[1],data[2]);
-
-    data[0] = 4.2;
-    data[1] = 0.52;
-    data[2] = 5.2;
-    TBRIK *sIDETshape = new TBRIK("IDETshape","Detector Under Test","Air",
-                                data[0],data[1],data[2]);
-
-
-    // Place volumes in geometry
-    char name[20],title[50];
-
-    //place SDD under test
-    Double_t px=0.0,py=0.0;
-    Double_t pz[2]={0.0,5.2};
-    TNode *nIDET[2],*nITS0[2],*nITST[2];
-    for(Int_t i=0;i<2;i++){
-       sITSV->cd();
-       sprintf(name,"IDET%d",i);
-       sprintf(title,"SDD #%d under test",i+1);
-       nIDET[i] = new TNode(name,title,sIDETshape,px,py,pz[i],r0,0);
-        nIDET[i]->cd();
-       nITS0[i] = new TNode("ITS0","SDD wafer",sITS0shape,0.0,0.0,0.0,0,0);
-        nITS0[i]->cd();
-       nITST[i] = new TNode("ITST","SDD sensitive volume",sITSTshape,
-                           0.0,0.0,0.0,0,0);
-        nITST[i]->SetLineColor(kYellow);
-        fNodes->Add(nITST[i]);
-    } // end for i
-
-    //place SSD telescope planes
-    Double_t qx=0.0,qy=0.0;
-    Double_t qz[10]={-58.4,-57.4,-50.4,-49.4,60.1,61.1,68.4,69.4,87.7,88.7};
-    TNode *nITEL[10],*nIMB0[10],*nIMBS[10];
-    for(Int_t i=0;i<10;i++){
-       sITSV->cd();
-       sprintf(name,"ITEL%d",i);
-       sprintf(title,"Test beam telescope element #%d",i+1);
-       nITEL[i] = new TNode(name,title,sITELshape,qx,qy,qz[i],r0,0);
-       nITEL[i]->cd();
-       nIMB0[i] = new TNode("IMB0","Chip MiniBus",sIMB0shape,
-                           0.0, 0.0,0.0,0,0);
-       nIMB0[i]->cd();
-       nIMBS[i] = new TNode("IMBS","IMBS",sIMBSshape,0.0,0.0,0.0,0,0);
-       nIMBS[i]->SetLineColor(kGreen);
-       fNodes->Add(nIMBS[i]);
-    } // end for i
-    nALIC->cd();
-    sITSV->Draw();
-}
+/*
 //______________________________________________________________________
 Int_t AliITSvSDD03::DecodeDetector(Int_t id,Int_t cpy,Int_t &lay,
                                    Int_t &det,Int_t &lad) const{
@@ -336,13 +151,14 @@ Int_t AliITSvSDD03::DecodeDetector(Int_t id,Int_t cpy,Int_t &lay,
     }// end if
     return mod;
 }
+*/
 //______________________________________________________________________
 void AliITSvSDD03::CreateGeometry(){
     ////////////////////////////////////////////////////////////////////////
     //  This routine defines and Creates the geometry for version 1 of the ITS.
     //    ALIC    ALICE Mother Volume
     //     |- ITSV     ITS Mother Volume
-    //         |- IDET       Detector under Test (boxcontaining SDD)
+    //         |- IDET *2    Detector under Test (boxcontaining SDD)
     //         |   |-IDAI        Air inside box
     //         |       |- ITS0       SDD Si Chip
     //         |          |- ITST      SDD Sensitivve Volume
@@ -351,6 +167,12 @@ void AliITSvSDD03::CreateGeometry(){
     //         |       |- IMB0       SDD Si Chip
     //         |           |- IMBS     SDD Sensitive volume
     //         |-ISNT*4    Sintilator triggers
+    //
+    //      ITEL ITEL ITEL ITEL IDET IDET ITEL ITEL ITEL ITEL ITEL ITEL
+    // Z->  -584 -574 -504 -494  000 +052 +601 +610 +684 +694 +877 +887
+    //        |    |    |    |    |    |    |    |    |    |    |    |
+    // cpn1   1    2    3    4    1    2    5    6    7    8    9   10
+    //
     // Inputs:
     //    none.
     // Outputs:
@@ -366,18 +188,36 @@ void AliITSvSDD03::CreateGeometry(){
     //Float_t dchipMiniBus=750.0E-4,dchiptest=300.0E-4;
     //Float_t yposition= 0.0;
     const Float_t kmm=0.1,kcm=1.0,kmicm=kmm/1000.;
+    // These constant character strings are set by cvs during commit
+    // do not change them unless you know what you are doing!
+    const Char_t *cvsDate="$Date$";
+    const Char_t *cvsRevision="$Revision$";
     // Define Rotation-reflextion Matrixes needed
     // 0 is the unit matrix
     AliMatrix(idrotm[0], 90.0,0.0, 0.0,0.0, 90.0,270.0); // SDD and SSD X
     AliMatrix(idrotm[1], 90.0,90.0, 0.0,180.0, 90.0,270.0); // SSD Y
     AliMatrix(idrotm[2],90.0,90.0,90.0,180.0,0.0,0.0);  //Rotate about Z 90 degree
-
+    /*
     data[0] = 150.0*kmm;
     data[1] = 150.0*kmm;
     data[2] = 1100.0*kmm;
     gMC->Gsvolu("ITSV","BOX ",idtmed[0],data,3);
     gMC->Gspos("ITSV",1,"ALIC",0.0,0.0,0.0,0,"ONLY");
-
+    */
+    TGeoVolumeAssembly *itsV = gGeoManager->MakeVolumeAssembly("ITSV");
+    const Int_t kLength=100;
+    Char_t vstrng[kLength];
+    if(fIgm.WriteVersionString(vstrng,kLength,(AliITSVersion_t)IsVersion(),
+                               fMinorVersion,cvsDate,cvsRevision))
+        itsV->SetTitle(vstrng);
+    else Error("CreateGeometry","Error writing/setting version string");
+    //printf("Title set to %s\n",vstrng);
+    TGeoVolume *alic = gGeoManager->GetVolume("ALIC");
+    if(alic==0) {
+        Error("CreateGeometry","alic=0");
+        return;
+    } // end if
+    alic->AddNode(itsV,1,0);
 
     // Crossed sintilator triggers (2 in front 2 in back)
     data[0] = 10.0*kcm;
@@ -507,7 +347,7 @@ void AliITSvSDD03::CreateGeometry(){
 
       Float_t a,z,dens,radl,absl;
       Float_t* ubuf=0; Int_t nbuf;
-      char* ssss="";
+      char* ssss=0;
       gMC->Gfmate(idtmed[fTarg],ssss,a,z,dens,radl,absl,ubuf,nbuf);
 
       Info("CreateGeometry","Target A=%f,  Z=%f,  dens=%f",a,z,dens);
@@ -531,7 +371,7 @@ void AliITSvSDD03::CreateMaterials(){
     // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
     // AliITSvSDD03.
     // In general it is automatically replaced by
-    // the CreatMaterials routine defined in AliITSv?. Should the function
+    // 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.
@@ -554,8 +394,8 @@ void AliITSvSDD03::CreateMaterials(){
     Float_t deemaxAir = 0.1; // Fraction of particle's energy 0<deemax<=1
     Float_t epsilAir  = 1.0E-4;//
     Float_t stminAir  = 0.0; // cm "Default value used"
-    Int_t   ifield = gAlice->Field()->Integ();
-    Float_t fieldm = gAlice->Field()->Max();
+    Int_t   ifield = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Integ();
+    Float_t fieldm = ((AliMagF*)TGeoGlobalMagField::Instance()->GetField())->Max();
     //
 
     // AIR
@@ -696,7 +536,7 @@ void AliITSvSDD03::CreateMaterials(){
    AliMedium(96,"SI$",2,0,ifield,fieldm,tmaxfdSi,stemaxSi,deemaxSi,
              epsilSi,stminSi);
 
-}           
+}/*
 //______________________________________________________________________
 void AliITSvSDD03::InitAliITSgeom(){
     //     Based on the geometry tree defined in Geant 3.21, this
@@ -708,97 +548,66 @@ void AliITSvSDD03::InitAliITSgeom(){
     //    none.
     // Return:
     //    none.
+    const Int_t knlayers=12;
+    //   const Int_t kndeep=6;
+    const Int_t kltypess=2;
+    const AliITSDetector kidet[knlayers]={kSSD,kSDD};
+    const TString knames[kltypess]={
+        "/ALIC_1/ITSV_1/ITEL_%d/ITAI_1/IMB0_1/IMBS_1",
+        "/ALIC_1/ITSV_1/IDET_%d/IDAI_1/ITS0_1/ITST_1"};
+    const Int_t kitsGeomTreeCopys[kltypess]={10,2};
+    const Int_t knp=384;
+    const Float_t kpitch=50.E-4;//cm
+    Float_t box[3]={0.5*kpitch*(Float_t)knp,150.E-4,1.0},p[knp+1],n[knp+1];
+    Int_t nlad[knlayers]={knlayers*1};
+    Int_t ndet[knlayers]={knlayers*1};
+    Int_t mod=knlayers,lay=0,lad=0,det=0,i,j,cp0;
+    TString path,shapeName;
+    TGeoHMatrix matrix;
+    Double_t trans[3]={3*0.0},rot[10]={10*0.0};
+    TArrayD shapePar;
+    TArrayF shapeParF;
+    Bool_t isShapeDefined[kltypess]={kltypess*kFALSE};
+    AliITSgeom *geom = new AliITSgeom(0,knlayers,nlad,ndet,mod);
+    if(GetITSgeom()!=0) SetITSgeom(0x0);// delet existing if there.
+    SetITSgeom(geom);
 
-  
-  if(strcmp(gMC->GetName(),"TGeant3")) {
-    Error("InitAliITSgeom",
-         "Wrong Monte Carlo. InitAliITSgeom uses TGeant3 calls");
+    p[0]=-box[0];
+    n[0]=box[0];
+    // Fill in anode and cathode strip locations (lower edge)
+    for(i=1;i<knp;i++){
+        p[i] =p[i-1]+kpitch;
+        n[i] =n[i-1]-kpitch;
+    } // end for i
+    p[knp]=box[0];
+    n[knp]=-box[0];
+    for(i=0;i<kltypess;i++)for(cp0=1;cp0<=kitsGeomTreeCopys[i];cp0++){
+        mod = DecodeDetector(fIdSens[i],cp0,lay,lad,det);
+        path.Form(knames[i].Data(),cp0);
+        gMC->GetTransformation(path.Data(),matrix);
+        gMC->GetShape(path.Data(),shapeName,shapePar);
+        shapeParF.Set(shapePar.GetSize());
+        for(j=0;j<shapePar.GetSize();j++)shapeParF[j]=shapePar[j];
+        geom->CreateMatrix(mod,lay,lad,det,kidet[i],trans,rot);
+        geom->SetTrans(mod,matrix.GetTranslation());
+        geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
+        geom->GetGeomMatrix(mod)->SetPath(path.Data());
+        switch (kidet[i]){
+        case kSDD: if(!(GetITSgeom()->IsShapeDefined((Int_t)kSDD))){
+            geom->ReSetShape(kSDD,new AliITSgeomSDD256(shapeParF.GetSize(),
+                                                       shapeParF.GetArray()));
+            isShapeDefined[i]=kTRUE;
+        } break;
+        case kSSD:if(!(GetITSgeom()->IsShapeDefined((Int_t)kSSD))){
+            geom->ReSetShape(kSSD,new AliITSgeomSSD(box,0.0,0.0,
+                                                    knp+1,p,knp+1,n));
+            isShapeDefined[i]=kTRUE;
+        } break;
+        default:{} break;
+        } // end switch
+    } // end for i,cp0
     return;
-  } // end if
-  Info("InitAliITSgeom","Reading geometry transformation directly from Geant 3");
-  const Int_t knp=384;
-  const Float_t kpitch=50.E-4;/*cm*/
-  Float_t box[3]={0.5*kpitch*(Float_t)knp,150.E-4,1.0},p[knp+2],n[knp+2];
-  const Int_t kltypess = 2;
-  const Int_t knlayers = 12;
-  const Int_t kndeep = 6;
-  Int_t itsGeomTreeNames[kltypess][kndeep],lnam[20],lnum[20];
-  Int_t nlad[knlayers],ndet[knlayers];
-  Double_t t[3],r[10];
-  Float_t  par[20],att[20];
-  Int_t    npar,natt,idshape,imat,imed,id;
-  AliITSGeant3Geometry *ig = new AliITSGeant3Geometry();
-  Int_t mod,typ,lay,lad,det,cpy,i,j,k;
-  Char_t names[kltypess][kndeep][4];
-  Int_t itsGeomTreeCopys[kltypess][kndeep];
-  Char_t *namesA[kltypess][kndeep] = {
-    {"ALIC","ITSV","ITEL","ITAI","IMB0","IMBS"}, 
-    {"ALIC","ITSV","IDET","IDAI","ITS0","ITST"}};
-  Int_t itsGeomTreeCopysA[kltypess][kndeep]= {{1,1,10,1,1,1},
-                                           {1,1,2,1,1,1}};
-  for(i=0;i<kltypess;i++)for(j=0;j<kndeep;j++){
-    for(k=0;k<4;k++) names[i][j][k] = namesA[i][j][k];
-    itsGeomTreeCopys[i][j] = itsGeomTreeCopysA[i][j];
-  } // end for i,j
-  p[0]=-box[0];
-  n[0]=box[0];
-  for(i=1;i<knp;i++){// Fill in anode and cathode strip locations (lower edge)
-    p[i] =p[i-1]+kpitch;
-    n[i] =n[i-1]-kpitch;
-  } // end for i
-  p[knp+1]=box[0];
-  n[knp+1]=-box[0];
-
-  for(i=0;i<20;i++) lnam[i] = lnum[i] = 0;
-  for(i=0;i<kltypess;i++)for(j=0;j<kndeep;j++) 
-    strncpy((char*) &itsGeomTreeNames[i][j],names[i][j],4);
-  //   itsGeomTreeNames[i][j] = ig->StringToInt(names[i][j]);
-  mod = knlayers;
-  if(GetITSgeom()!=0) SetITSgeom(0x0);
-  for(Int_t iMod=0; iMod<knlayers; iMod++){
-    nlad[iMod]=1; ndet[iMod]=1;
-  }
-  
-  AliITSgeom* geom = new AliITSgeom(0,knlayers,nlad,ndet,mod);
-  SetITSgeom(geom);
-  fIdSens[0] = 0; fIdSens[1] = 1; // Properly reset in Init later.
-  for(typ=1;typ<=kltypess;typ++){
-    for(j=0;j<kndeep;j++) lnam[j] = itsGeomTreeNames[typ-1][j];
-    for(j=0;j<kndeep;j++) lnum[j] = itsGeomTreeCopys[typ-1][j];
-    if(typ == 1) id = fIdSens[0];
-    else id = fIdSens[1];
-    lad = 1;
-    det = 1;
-    for(cpy=1;cpy<=itsGeomTreeCopys[typ-1][2];cpy++){
-      mod = DecodeDetector(id,cpy,lay,lad,det);
-      //lunm[2] is the copy number, from 1 to 10 for SSD
-      // 1,2 for SDD, depending on the module number
-      if(mod<=3) lnum[2]=mod+1;
-      if(mod>=6) lnum[2]=mod-1;
-      if(mod==4) lnum[2]=1;
-      if(mod==5) lnum[2]=2;
-      ig->GetGeometry(kndeep,lnam,lnum,t,r,idshape,npar,natt,par,att,
-                     imat,imed);
-
-      switch (typ){
-      case 2:
-       GetITSgeom()->CreatMatrix(mod,lay,lad,det,kSDD,t,r);
-       if(!(GetITSgeom()->IsShapeDefined((Int_t)kSDD))){
-         GetITSgeom()->ReSetShape(kSDD,new AliITSgeomSDD256(npar,par));
-       } // end if
-       break;
-      case 1:
-       GetITSgeom()->CreatMatrix(mod,lay,lad,det,kSSD,t,r);
-       if(!(GetITSgeom()->IsShapeDefined((Int_t)kSSD))){
-         GetITSgeom()->ReSetShape(kSSD,new AliITSgeomSSD(box,0.0,0.0,
-                                                     knp+1,p,knp+1,n));
-       } // end if
-       break;
-      } // end switch
-    } // end for cpy
-  } // end for typ
-  return;
-}
+}*/
 //______________________________________________________________________
 void AliITSvSDD03::Init(){
     ////////////////////////////////////////////////////////////////////////
@@ -814,18 +623,15 @@ void AliITSvSDD03::Init(){
 
     Info("Init","**********AliITSvSDD03 %d _Init *************",fMinorVersion);
 
-    if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
-    if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
-    if(GetITSgeom()!=0) SetITSgeom(0x0);
-    AliITSgeom* geom = new AliITSgeom();
-    SetITSgeom(geom);
-    if(fGeomDetIn) GetITSgeom()->ReadNewFile(fRead);
-    if(!fGeomDetIn) this->InitAliITSgeom();
-    if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
+    AliDebug(1,Form("Init: Major version %d Minor version %d",fMajorVersion,
+                 fMinorVersion));
+    //
+    UpdateInternalGeometry();
     AliITS::Init();
+    //
     fIDMother = gMC->VolId("ITSV"); // ITS Mother Volume ID.
 
-}
+}/*
 //______________________________________________________________________
 void AliITSvSDD03::SetDefaults(){
     // sets the default segmentation, response, digit and raw cluster classes
@@ -836,48 +642,41 @@ void AliITSvSDD03::SetDefaults(){
     // Return:
     //    none.
 
-    const Float_t kconv = 1.0e+04; // convert cm to microns
+  //    const Float_t kconv = 1.0e+04; // convert cm to microns
 
     if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
     fDetTypeSim->SetITSgeom(GetITSgeom());
-    fDetTypeSim->ResetResponse();
+    fDetTypeSim->ResetCalibrationArray();
     fDetTypeSim->ResetSegmentation();
  
     AliITSgeomSDD *s1;
     AliITSgeomSSD *s2;
-    SetResponseModel(kSPD,new AliITSresponseSPD());
-    SetSegmentationModel(kSPD,new AliITSsegmentationSPD());
+    SetCalibrationModel(GetITSgeom()->GetStartSPD(),new AliITSCalibrationSPD());
+    SetSegmentationModel(kSPD,(AliITSsegmentationSPD*)
+                        (GetITSgeom()->GetShape(kSPD)));
     fDetTypeSim->SetDigitClassName(kSPD,"AliITSdigitSPD");
 
     // SDD
     s1 = (AliITSgeomSDD*) GetITSgeom()->GetShape(kSDD);// Get shape info. Do it this way for now.
-    AliITSresponseSDD *resp1=new AliITSresponseSDD("simulated");
-    SetResponseModel(kSDD,resp1);
-
-    AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD(GetITSgeom(),resp1);
-    seg1->SetDetSize(s1->GetDx()*kconv, // base this on AliITSgeomSDD
-                    s1->GetDz()*2.*kconv, // for now.
-                    s1->GetDy()*2.*kconv); // x,z,y full width in microns.
+    AliITSCalibrationSDD *resp1=new AliITSCalibrationSDD("simulated");
+    SetCalibrationModel(GetITSgeom()->GetStartSDD(),resp1);
 
+    AliITSsegmentationSDD *seg1 = (AliITSsegmentationSDD*)
+                        (GetITSgeom()->GetShape(kSDD));
+    seg1->SetDriftSpeed(AliITSDriftSpeedSDD::DefaultDriftSpeed());
     seg1->SetNPads(256,256);// Use AliITSgeomSDD for now
     SetSegmentationModel(kSDD,seg1);
-    const char *kData1=(fDetTypeSim->GetResponseModel(kSDD))->DataType();
-    const char *kopt=fDetTypeSim->GetResponseModel(kSDD)->ZeroSuppOption();
-    if((!strstr(kopt,"2D")) && (!strstr(kopt,"1D")) || strstr(kData1,"real") ){
-       fDetTypeSim->SetDigitClassName(kSDD,"AliITSdigit");
-    } else fDetTypeSim->SetDigitClassName(kSDD,"AliITSdigitSDD");
+    const char *kData1=(fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSDD()))->DataType();
 
     // SSD  Layer 5
 
     s2 = (AliITSgeomSSD*) GetITSgeom()->GetShape(kSSD);// Get shape info. Do it this way for now.
    
-    AliITSresponse *resp2= new AliITSresponseSSD("simulated");
-    SetResponseModel(kSSD,resp2);
+    AliITSCalibration *resp2= new AliITSCalibrationSSD("simulated");
+    SetCalibrationModel(GetITSgeom()->GetStartSSD(),resp2);
 
-    AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD(GetITSgeom());
-    seg2->SetDetSize(s2->GetDx()*2.*kconv, // base this on AliITSgeomSSD
-                    s2->GetDz()*2.*kconv, // for now.
-                    s2->GetDy()*2.*kconv); // x,z,y full width in microns.
+    AliITSsegmentationSSD *seg2 = (AliITSsegmentationSSD*)
+                        (GetITSgeom()->GetShape(kSSD));
     seg2->SetPadSize(50.,0.); // strip x pitch in microns
     seg2->SetNPads(384,0); // number of strips on each side.
     seg2->SetLayer(5);
@@ -886,7 +685,7 @@ void AliITSvSDD03::SetDefaults(){
     seg2->SetAnglesLay6(0.,0.); // strip angles rad P and N side.
 
     SetSegmentationModel(kSSD,seg2); 
-    const char *kData2=(fDetTypeSim->GetResponseModel(kSSD))->DataType();
+    const char *kData2=(fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSSD()))->DataType();
     if(strstr(kData2,"real") ) fDetTypeSim->SetDigitClassName(kSSD,"AliITSdigit");
     else fDetTypeSim->SetDigitClassName(kSSD,"AliITSdigitSSD");
 
@@ -908,21 +707,21 @@ void AliITSvSDD03::SetDefaultSimulation(){
 
   if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
   AliITSsimulation *sim;
-  AliITSsegmentation *seg;
-  AliITSresponse *res;
+  //AliITSsegmentation *seg;
+  //AliITSCalibration *res;
   //SPD
   if(fDetTypeSim){
     sim = fDetTypeSim->GetSimulationModel(kSPD);
     if (!sim) {
-      seg =(AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD);
-      if(seg==0) seg = new AliITSsegmentationSPD();
-      res = (AliITSresponse*)fDetTypeSim->GetResponseModel(kSPD);
-      if(res==0) res = new AliITSresponseSPD();
-      sim = new AliITSsimulationSPDdubna(seg,res,0);
+      //seg =(AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD);
+      //if(seg==0) seg = new AliITSsegmentationSPD();
+      //res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSPD());
+      //if(res==0) res = new AliITSCalibrationSPD();
+      sim = new AliITSsimulationSPD(fDetTypeSim);
       SetSimulationModel(kSPD,sim);
     }else{ // simulation exists, make sure it is set up properly.
-      sim->SetSegmentationModel((AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD));
-      sim->SetResponseModel((AliITSresponse*)fDetTypeSim->GetResponseModel(kSPD));
+      sim->SetSegmentationModel(kSPD,(AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD));
+      sim->SetCalibrationModel(GetITSgeom()->GetStartSPD(),(AliITSCalibration*)fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSPD()));
       sim->Init();
     } // end if
   } // end if iDetType
@@ -930,13 +729,13 @@ void AliITSvSDD03::SetDefaultSimulation(){
   if(fDetTypeSim){
     sim = fDetTypeSim->GetSimulationModel(kSDD);
     if (!sim) {
-      seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD);
-      res = (AliITSresponse*)fDetTypeSim->GetResponseModel(kSDD);
-      sim = new AliITSsimulationSDD(seg,res);
+      //      seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD);
+      //res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSDD());
+      sim = new AliITSsimulationSDD(fDetTypeSim);
       SetSimulationModel(kSDD,sim);
     }else{ // simulation exists, make sure it is set up properly.
-      sim->SetSegmentationModel((AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD));
-      sim->SetResponseModel((AliITSresponse*)fDetTypeSim->GetResponseModel(kSDD));
+      sim->SetSegmentationModel(kSDD,(AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD));
+      sim->SetCalibrationModel(GetITSgeom()->GetStartSDD(),(AliITSCalibration*)fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSDD()));
       
       sim->Init();
     } //end if
@@ -945,17 +744,17 @@ void AliITSvSDD03::SetDefaultSimulation(){
   if(fDetTypeSim){
     sim = fDetTypeSim->GetSimulationModel(kSSD);
     if (!sim) {
-      seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSSD);
-      res = (AliITSresponse*)fDetTypeSim->GetResponseModel(kSSD);
-      sim = new AliITSsimulationSSD(seg,res);
+      //      seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSSD);
+      // res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(GetITSgeom()->GetStartSSD());
+      sim = new AliITSsimulationSSD(fDetTypeSim);
       SetSimulationModel(kSSD,sim);
     }else{ // simulation exists, make sure it is set up properly.
-      sim->SetSegmentationModel((AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSSD));
-      sim->SetResponseModel((AliITSresponse*)fDetTypeSim->GetResponseModel(kSSD));
+      sim->SetSegmentationModel(kSSD,(AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSSD));
+      sim->SetCalibrationModel(GetITSgeom()->GetStartSSD(),(AliITSCalibration*)fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSSD()));
       sim->Init();
     } // end if
   } // end if iDetType
-}
+  }*/
 //______________________________________________________________________
 void AliITSvSDD03::DrawModule() const{
     ////////////////////////////////////////////////////////////////////////
@@ -1008,71 +807,60 @@ void AliITSvSDD03::StepManager(){
     // Return:
     //    none.
     ////////////////////////////////////////////////////////////////////////
-    Int_t  copy, id;
-    static TLorentzVector position0;
-    static Int_t stat0=0;
-    if((id=gMC->CurrentVolID(copy) == fIDMother)&&
-       (gMC->IsTrackEntering()||gMC->IsTrackExiting())){
-        copy = fTrackReferences->GetEntriesFast();
-        TClonesArray &lTR = *fTrackReferences;
-        // Fill TrackReference structure with this new TrackReference.
-        new(lTR[copy]) AliTrackReference(gAlice->GetMCApp()->
-                                         GetCurrentTrackNumber());
-    } // if Outer ITS mother Volume
-    //if(!(this->IsActive())) return;
+    if(!(this->IsActive())) return;
     if(!(gMC->TrackCharge())) return;
-    Int_t   vol[5],copy3;
+
+    Int_t  cpy0,cpy1,ncpys=0,status,id,mod;
     TLorentzVector position, momentum;
-    TClonesArray &lhits = *fHits;
+    static AliITShit hit;// Saves on calls to construtors
+    //TClonesArray &lhits = *(GetDetTypeSim()->GetHits());
+    TClonesArray &lhits = *(Hits());
+    //
+    // Track status
+    // Track status
+    status = 0;
+    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;
     //
     // Fill hit structure.
     gMC->TrackPosition(position);
     gMC->TrackMomentum(momentum);
-    id   = gMC->CurrentVolID(copy);
-    if(id==fIdSens[0] || id==fIdSens[1]){ // Volumes "ITST" or "IMBS"
-        copy = gMC->CurrentVolOffID(3,copy3);
-        copy = DecodeDetector(id,copy3,vol[0],vol[1],vol[2]);
-       //    cout << "0: mod,lay,lad,det="<<copy<<","<<vol[0]<<","<<vol[1]
-        //     <<","<<vol[2]<<" name="<<gMC->CurrentVolName()
-       //     <<","<<fIdSens[0]<<","<<fIdSens[1]<<","<<id<<" z="
-        //     <<position.Z()<<endl;
-    }else if(id==fIdSens[2]){ // "ISNT" Sintilator
-        //cout << "1: id,copy="<<id<<","<<copy
-        //     <<" name="<<gMC->CurrentVolName()<<" z="
-        //     <<position.Z()<<endl;
-        return; // Do nothing for now.
-    }else{
-        //cout << "2: id,copy="<<id<<","<<copy
-        //     <<" name="<<gMC->CurrentVolName()<<" z="
-        //     <<position.Z()<<endl;
-        return;
-    } // end if
+    id   = gMC->CurrentVolID(cpy0);
+    gMC->CurrentVolOffID(3,cpy1);
+    if(id==fIdSens[0])ncpys=10;
+    if(id==fIdSens[1])ncpys=2;
+    fIgm.DecodeDetector(mod,ncpys,cpy0,cpy1,1);
     //
-    // Track status
-    vol[3] = 0;
-    vol[4] = 0;
-    if(gMC->IsTrackInside())      vol[3] +=  1;
-    if(gMC->IsTrackEntering())    vol[3] +=  2;
-    if(gMC->IsTrackExiting())     vol[3] +=  4;
-    if(gMC->IsTrackOut())         vol[3] +=  8;
-    if(gMC->IsTrackDisappeared()) vol[3] += 16;
-    if(gMC->IsTrackStop())        vol[3] += 32;
-    if(gMC->IsTrackAlive())       vol[3] += 64;
+    // Fill hit structure.
     //
-    vol[4] = stat0;
+    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()){
-        position0 = position;
-        stat0 = vol[3];
-        return;
-    }else{
-        new(lhits[fNhits++]) AliITShit(fIshunt,
-                                   gAlice->GetMCApp()->GetCurrentTrackNumber(),
-                                       vol,gMC->Edep(),gMC->TrackTime(),
-                                       position,position0,momentum);
-    }// end if gMC->IsTrackEntering()
-    position0 = position;
-    stat0 = vol[3];
-
+        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++]) AliITShit(hit); // Use Copy Construtor.
+    // Save old position... for next hit.
+    hit.SetStartPosition(position);
+    hit.SetStartTime(gMC->TrackTime());
+    hit.SetStartStatus(status);
     return;
 }