Updates concerning the geometry: versioning system, new V11hybrid version, bug fixes...
[u/mrichter/AliRoot.git] / ITS / AliITSvtest.cxx
index b14098d..f915886 100644 (file)
 #include <TLorentzVector.h>
 #include <TMath.h>
 #include <TSystem.h>
+#include <TGeometry.h>
 #include <TVirtualMC.h>
 #include <TGeoMatrix.h>
+#include <TGeoManager.h>
+#include <TGeoMaterial.h>
+#include <TGeoMedium.h>
+#include <TGeoBBox.h>
+#include <TGeoVolume.h>
 
 #include "AliRun.h"
+#include "AliMC.h"
+#include "AliMagF.h"
 #include "AliITSgeom.h"
 #include "AliITSgeomSDD.h"
 #include "AliITSgeomSPD.h"
 #include "AliITSgeomSSD.h"
 #include "AliITShit.h"
 #include "AliITSvtest.h"
-#include "AliRun.h"
-#include "AliMC.h"
 
 ClassImp(AliITSvtest)
+
+const Double_t AliITSvtest::fgkmicron = 1.0E-4;
+const Double_t AliITSvtest::fgkmm = 0.10;
+const Double_t AliITSvtest::fgkcm = 1.00;
+const Double_t AliITSvtest::fgkDegree = 1.0;
+const Double_t AliITSvtest::fgkRadian = 180./3.14159265358979323846;
+const Double_t AliITSvtest::fgkgcm3 = 1.0; // assume default is g/cm^3
+const Double_t AliITSvtest::fgkCelsius = 1.0; // Assume default is C
+const Double_t AliITSvtest::fgkPascal  = 1.0E-3; // Assume kPascal
+const Double_t AliITSvtest::fgkKPascal = 1.0;    // Asume kPascal
+const Double_t AliITSvtest::fgkeV      = 1.0E-9; // GeV default
+const Double_t AliITSvtest::fgkKeV     = 1.0e-6; // GeV default
+const Double_t AliITSvtest::fgkMeV     = 1.0e-3; // GeV default
+const Double_t AliITSvtest::fgkGeV     = 1.0;    // GeV default
+
  
 //_____________________________________________________________________________
-AliITSvtest::AliITSvtest() {
-    // Standard constructor for the ITS
+AliITSvtest::AliITSvtest() :
+AliITS(),                   // Base Class
+fGeomDetOut(kFALSE),       // Flag to write .det file out
+fGeomDetIn(kFALSE),         // Flag to read .det file or directly from Geat.
+fMajorVersion(IsVersion()), // Major version number == IsVersion
+fMinorVersion(-1),          // Minor version number
+fEuclidGeomDet(),           // file where detector transormation are define.
+fRead(),                    //! file name to read .det file
+fWrite(),                   //! file name to write .det file
+fIgm()                      //! Geometry initilization object
+{
+    // Default constructor for the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+} 
+//_____________________________________________________________________________
+AliITSvtest::AliITSvtest(const Char_t *title,Int_t version) :
+AliITS("ITS",title),        // Base Class
+fGeomDetOut(kFALSE),       // Flag to write .det file out
+fGeomDetIn(kFALSE),         // Flag to read .det file or directly from Geat.
+fMajorVersion(IsVersion()), // Major version number == IsVersion
+fMinorVersion(version),     // Minor version number
+fEuclidGeomDet("$ALICE_ROOT/ITS/ITSgeometry_test.det"),// file where detector transormation are define.
+fRead("$ALICE_ROOT/ITS/ITSgeometry_test.det"),//! file name to read .det file
+fWrite("$ALICE_ROOT/ITS/ITSgeometry_test.det"),//! file name to write .det file
+fIgm()                      //! Geometry initilization object
+{
+    // Default constructor for the ITS. version=1 reads Euclide file for
+    // geometry. version=2 use's internal geometry
+    // Inputs:
+    //   Char_t *title   Geomety title
+    //   Int_t   version Minor version number to use.
+    //                       =-1 Not defined
+    //                       = 1 read Euclid geometry
+    //                       = 2 use internal geometry minor verion 2.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
     Int_t i;
 
-    fIdN    = 0;
-    fIdName = 0;
-    fIdSens = 0;
-    SetEUCLID(kFALSE);
-    fGeomDetOut   = kFALSE; // Don't write .det file
-    fGeomDetIn    = kTRUE; // Read .det file
-    fMajorVersion = IsVersion();
-    fMinorVersion = -1;
-    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';
+    fIdN    = 6;
+    fIdName    = new TString[fIdN];
+    fIdName[0] = "ITS1";
+    fIdName[1] = "ITS2";
+    fIdName[2] = "ITS3";
+    fIdName[3] = "ITS4";
+    fIdName[4] = "ITS5";
+    fIdName[5] = "ITS6";
+    fIdSens    = new Int_t[fIdN];
+    for(i=0;i<fIdN;i++) fIdSens[i] = 0;
 }
 //_____________________________________________________________________________
 AliITSvtest::~AliITSvtest() {
     // Standard destructor for the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
 }
 //_____________________________________________________________________________
 AliITSvtest::AliITSvtest(const char *fileeuc,const char *filetme,
-                        const char *name, const char *title) 
-    : AliITS(name, title){
-    //
+                        const char *name, const char *title) :
+AliITS(name, title),        // Base Class
+fGeomDetOut(kFALSE),       // Flag to write .det file out
+fGeomDetIn(kFALSE),         // Flag to read .det file or directly from Geat.
+fMajorVersion(IsVersion()), // Major version number == IsVersion
+fMinorVersion(1),           // Minor version number
+fEuclidGeomDet("$ALICE_ROOT/ITS/ITSgeometry_test.det"),// file where detector transormation are define.
+fRead("$ALICE_ROOT/ITS/ITSgeometry_test.det"),//! file name to read .det file
+fWrite("$ALICE_ROOT/ITS/ITSgeometry_test.det"),//! file name to write .det file
+fIgm()                      //! Geometry initilization object
+{
     // Standard constructor for the ITS
-    //
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+    Int_t i;
+
     fIdN    = 6;
     fIdName    = new TString[fIdN];
     fIdName[0] = "ITS1";
@@ -84,320 +166,551 @@ AliITSvtest::AliITSvtest(const char *fileeuc,const char *filetme,
     fIdName[4] = "ITS5";
     fIdName[5] = "ITS6";
     fIdSens    = new Int_t[fIdN];
-    for (Int_t i=0;i<fIdN;i++) fIdSens[i] = 0;
-    fMajorVersion = IsVersion();
-    fMinorVersion = 1;
-    SetEUCLID(kFALSE);
-    fGeomDetOut   = kFALSE; // Don't write .det file
-    fGeomDetIn    = kTRUE; // Read .det file
+    for(i=0;i<fIdN;i++) fIdSens[i] = 0;
 
     fEuclidMaterial = filetme;
     fEuclidGeometry = fileeuc;
-    strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_PPR.det",60);
-    strncpy(fRead,fEuclidGeomDet,60);
-    strncpy(fWrite,fEuclidGeomDet,60);
-//  The .det file for the geometry must have the same name as fileeuc with
-//  .euc replaced by .det.
+    //  The .det file for the geometry must have the same name as 
+    // fileeuc with .euc replaced by .det.
 }
-
 //_____________________________________________________________________________
 void AliITSvtest::CreateMaterials(){
-  //
-  // Read materials for the ITS
-  //
+    // Read materials for the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    switch(GetMinorVersion()){
+    case 1:
+        CreateMaterialsEuclid();
+        break;
+    case 2:
+        CreateMaterials2();
+        break;
+    default:
+        Warning("CreateMaterials","No CreateMaterials for minor version=%d",
+                 GetMinorVersion());
+        break;
+    } // end switch
+    return;
+}
+//_____________________________________________________________________________
+void AliITSvtest::CreateMaterialsEuclid(){
+    // Read materials for the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
     char *filtmp;
-//
-  filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
-//  FILE *file = fopen(fEuclidMaterial.Data(),"r");
-  FILE *file = fopen(filtmp,"r");
-  if(file) {
-    fclose(file);
-//    ReadEuclidMedia(fEuclidMaterial.Data(),this);
-    ReadEuclidMedia(filtmp);
-  } else {
-    Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",
-//       fEuclidMaterial.Data());
-         filtmp);
-    exit(1);
-  } // end if(file)
+
+    filtmp = gSystem->ExpandPathName(fEuclidMaterial.Data());
+    //  FILE *file = fopen(fEuclidMaterial.Data(),"r");
+    FILE *file = fopen(filtmp,"r");
+    if(file) {
+        fclose(file);
+        //    ReadEuclidMedia(fEuclidMaterial.Data(),this);
+        ReadEuclidMedia(filtmp);
+    } else {
+        Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",
+              //         fEuclidMaterial.Data());
+              filtmp);
+        exit(1);
+    } // end if(file)
 }
+//_____________________________________________________________________________
+void AliITSvtest::CreateMaterials2(){
+    // Read materials for the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+    //TGeoManager *mgr = gGeoManager;
+    TGeoMaterial *si,*n2;
+    TGeoMedium *sims,*simn,*simN2;
+    Double_t params[8];
+    Int_t   ifield = gAlice->Field()->Integ();
+    Double_t fieldm = gAlice->Field()->Max(); // [kilogauss]
 
+    params[0] = 1.0; // sensitive volume flag
+    params[1] = (Double_t)ifield; // magnetic field type
+    params[2] = fieldm; // magnetic field stregth
+    params[3] = 0.1*fgkDegree; // tmaxfd  Theta max deviation over step
+    params[4] = 0.0075*fgkcm; // maximum step size
+    params[5] = 0.1; // Maximum fractional energy loss over a step
+    params[6] = 1.0E-4*fgkcm; // tracking precision
+    params[7] = 0.0*fgkcm; // Minimum step (=0 compute automatically)
+                           // must always be =0!
+
+    si = new TGeoMaterial("SI",28.86,14.0,2.33*fgkgcm3,
+                          TGeoMaterial::kMatStateSolid,25.0*fgkCelsius,
+                          0.0*fgkPascal);
+    sims = new TGeoMedium("ITSsensitiveSi",4,si,params);
+    params[0] = 0.0; // non sesitive.
+    simn = new TGeoMedium("ITSnonsensitiveSi",5,si,params);
+    //
+    n2 = new TGeoMaterial("Nitrogen Gas",14.00674,7.0,1.250E-3*fgkgcm3,
+                          TGeoMaterial::kMatStateGas,25.0*fgkCelsius,
+                          101325.0*fgkPascal);
+    simN2 = new TGeoMedium("ITSN2",6,n2,params);
+    //
+    if(sims==0 || simn==0 || simN2==0)
+        Error("CreateMaterial","Error getting medium ITSsensitiveSi=%p"
+              " ITSnonsensitiveSi=%p ITSN2=%p",sims,simn,simN2);
+}
 //_____________________________________________________________________________
 void AliITSvtest::CreateGeometry(){
-//////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-// Read geometry for the ITS
-//
+    // Read geometry for the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    switch(GetMinorVersion()){
+    case 1:
+        CreateGeometryEuclid();
+        break;
+    case 2:
+        CreateGeometry2();
+        break;
+    default:
+        Warning("CreateGeometry","No CreateMaterials for minor version=%d",
+                 GetMinorVersion());
+        break;
+    } // end switch
+    return;
+}
+//_____________________________________________________________________________
+void AliITSvtest::CreateGeometryEuclid(){
+    // Read geometry for the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
     char topvol[5];
     char *filtmp;
-//
-  filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
-  FILE *file = fopen(filtmp,"r");
-  delete [] filtmp;
-  if(file) {
-    fclose(file);
-    printf("Ready to read Euclid geometry file\n");
-    ReadEuclid(fEuclidGeometry.Data(),topvol);
-    printf("Read in euclid geometries\n");
-  } else {
-    Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
-         fEuclidGeometry.Data());
-    exit(1);
-  } // end if(file)
-  //
-  //---Place the ITS ghost volume ITSV in its mother volume (ALIC) and make it
-  //     invisible
-  //
-  gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
-  //
-  //---Outputs the geometry tree in the EUCLID/CAD format
-  
+
+    filtmp = gSystem->ExpandPathName(fEuclidGeometry.Data());
+    FILE *file = fopen(filtmp,"r");
+    delete [] filtmp;
+    if(file) {
+        fclose(file);
+        printf("Ready to read Euclid geometry file\n");
+        ReadEuclid(fEuclidGeometry.Data(),topvol);
+        printf("Read in euclid geometries\n");
+    } else {
+        Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",
+              fEuclidGeometry.Data());
+        exit(1);
+    } // end if(file)
+    //
+    //---Place the ITS logical volume ITSV in its mother volume (ALIC) 
+    //   and make it invisible
+    //
+    gMC->Gspos("ITSV",1,"ALIC",0,0,0,0,"ONLY");
+    //
+    //---Outputs the geometry tree in the EUCLID/CAD format
+    
     if (fEuclidOut) {
-      gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
+        gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
     } // end if (fEuclidOut)
     cout <<"finished with euclid geometrys"<< endl;
 }
-//______________________________________________________________________
-void AliITSvtest::InitAliITSgeom(){
-    //     Based on the geometry tree defined in Geant 3.21, this
-    // routine initilizes the Class AliITSgeom from the Geant 3.21 ITS geometry
-    // sturture.
+//_____________________________________________________________________________
+void AliITSvtest::CreateGeometry2(){
+    // Test geometry verion 2.
+    //  /ALIC_1/ITSV_1/ITSspd1_1/ITS1_1/   lay=1
+    //  /ALIC_1/ITSV_1/ITSspd2_1/ITS2_1/   lay=2
+    //  /ALIC_1/ITSV_1/ITSsdd1_1/ITS3_1/   lay=3
+    //  /ALIC_1/ITSV_1/ITSsdd2_1/ITS4_1/   lay=4
+    //  /ALIC_1/ITSV_1/ITSssd1_1/ITS5_1/   lay=5
+    //  /ALIC_1/ITSV_1/ITSssd2_1/ITS6_1/   Lay=6
     // Inputs:
     //   none.
     // Outputs:
     //   none.
     // Return:
     //   none.
-    const Int_t knlayers = 6;
-    const Int_t kndeep = 3;
-    const AliITSDetector idet[knlayers]={kSPD,kSPD,kSDD,kSDD,kSSD,kSSDp};
-    const TString names[2][knlayers] = {
-     {"/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12A_%d/I10A_%d/I103_%d/I101_1/ITS1_1", // lay=1
-      "/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12A_%d/I20A_%d/I1D3_%d/I1D1_1/ITS2_1", // lay=2
-      "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I004_%d/I302_%d/ITS3_%d", // lay=3
-      "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I005_%d/I402_%d/ITS4_%d", // lay=4
-      "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I565_%d/I562_%d/ITS5_%d", // lay=5
-      "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I569_%d/I566_%d/ITS6_%d"},// lay=6
-     {"/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12B_%d/I10B_%d/I107_%d/I101_1/ITS1_1", // lay=1
-      "/ALIC_1/ITSV_1/ITSD_1/IT12_1/I12B_%d/I20B_%d/I1D7_%d/I1D1_1/ITS2_1", // lay=2
-      "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I004_%d/I302_%d/ITS3_%d", // lay=3
-      "/ALIC_1/ITSV_1/ITSD_1/IT34_1/I005_%d/I402_%d/ITS4_%d", // lay=4
-      "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I565_%d/I562_%d/ITS5_%d", // lay=5
-      "/ALIC_1/ITSV_1/ITSD_1/IT56_1/I569_%d/I566_%d/ITS6_%d"}
-    };
-    const Int_t itsGeomTreeCopys[knlayers][kndeep]= {{10, 2, 4},// lay=1
-                                                     {10, 4, 4},// lay=2
-                                                     {14, 6, 1},// lay=3
-                                                     {22, 8, 1},// lay=4
-                                                     {34,22, 1},// lay=5
-                                                     {38,25, 1}};//lay=6
-    Int_t       nlad[knlayers],ndet[knlayers];
-    Int_t       mod,lay,lad=0,det=0,i,j,k,cp0,cp1,cp2;
-    TString path,shapeName;
-    TGeoHMatrix matrix;
-    Double_t trans[3]={3*0.0},rot[10]={9*0.0,1.0};
-    TArrayD shapePar;
-    TArrayF shapeParF;
-    Bool_t shapeDefined[4]={kFALSE,kFALSE,kFALSE,kFALSE};
+    // 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$";
+    const Double_t ksensitiveSPD[3]={0.6*fgkcm,0.01*fgkcm,3.5*fgkcm};
+    const Double_t ksensitiveSDD[3]={3.5085*fgkcm,0.01499*fgkcm,3.7485*fgkcm};
+    const Double_t ksensitiveSSD[3]={3.75*fgkcm,0.0150*fgkcm,2.1*fgkcm};
+    const Double_t kwaferSPD[3]={0.7*fgkcm,0.01*fgkcm,3.6*fgkcm};
+    const Double_t kwaferSDD[3]={3.61*fgkcm,0.0150*fgkcm,4.38*fgkcm};
+    const Double_t kwaferSSD[3]={3.85*fgkcm,0.0150*fgkcm,2.2*fgkcm};
+    TGeoManager *mgr = gGeoManager;
+    TGeoVolume *vALIC=0;
+    TGeoMedium *sensitiveSi=0,*bulckSi=0,*n2=0;
+    TGeoBBox *sITS,*sSPD,*sSDD,*sSSD;
+    TGeoBBox *sITS1,*sITS2,*sITS3,*sITS4,*sITS5,*sITS6;
+    TGeoVolume *vITS,*vSPD1,*vSPD2,*vSDD1,*vSDD2,*vSSD1,*vSSD2;
+    TGeoVolume *vITS1,*vITS2,*vITS3,*vITS4,*vITS5,*vITS6;
 
-    AliDebug(1,"Reading Geometry transformation directly from Modler.");
-    mod = 0;
-    for(i=0;i<knlayers;i++){
-        k = 1;
-        for(j=0;j<kndeep;j++) if(itsGeomTreeCopys[i][j]!=0)
-            k *= TMath::Abs(itsGeomTreeCopys[i][j]);
-        mod += k;
-    } // end for i
+    vALIC = mgr->GetTopVolume();
+    if(vALIC==0) {
+        vALIC = mgr->GetVolume("ALIC");
+        if(vALIC==0) {
+            Error("CreateGeometry2","vALIC=0");
+            return;
+        }// end if
+    } // end if
+    //sensitiveSi = mgr->GetMedium("ITSsensitiveSi");
+    sensitiveSi = mgr->GetMedium(4);
+    //bulckSi     = mgr->GetMedium("ITSnonesensitiveSi");
+    bulckSi     = mgr->GetMedium(5);
+    //n2          = mgr->GetMedium("ITSN2");
+    n2          = mgr->GetMedium(6);
+    if(sensitiveSi==0 || bulckSi==0 || n2==0){
+        Error("CreateGeometry2","Error getting medium sensitiveSi=%p"
+              " bulckSi=%p n2=%p",sensitiveSi,bulckSi,n2);
+        TList *lmed = mgr->GetListOfMedia();
+        TIter next(lmed);
+        while(TGeoMedium *med = (TGeoMedium*) next())
+            med->Inspect();
+    } //
+    sITS1 = new TGeoBBox((Double_t*)ksensitiveSPD);
+    vITS1 = new TGeoVolume("ITS1",sITS1,sensitiveSi);
+    sITS2 = new TGeoBBox((Double_t*)ksensitiveSPD);
+    vITS2 = new TGeoVolume("ITS2",sITS2,sensitiveSi);
+    sSPD  = new TGeoBBox((Double_t*)kwaferSPD);
+    vSPD1 = new TGeoVolume("ITSspd1",sSPD,bulckSi);
+    vSPD2 = new TGeoVolume("ITSspd2",sSPD,bulckSi);
+    vSPD1->AddNode(vITS1,1,0); // one copy no translation/rotation
+    vSPD2->AddNode(vITS2,1,0); // one copy no translation/rotation
+    //
+    sITS3 = new TGeoBBox((Double_t*)ksensitiveSDD);
+    vITS3 = new TGeoVolume("ITS3",sITS3,sensitiveSi);
+    sITS4 = new TGeoBBox((Double_t*)ksensitiveSDD);
+    vITS4 = new TGeoVolume("ITS4",sITS4,sensitiveSi);
+    sSDD  = new TGeoBBox((Double_t*)kwaferSDD);
+    vSDD1 = new TGeoVolume("ITSsdd1",sSDD,bulckSi);
+    vSDD2 = new TGeoVolume("ITSsdd2",sSDD,bulckSi);
+    vSDD1->AddNode(vITS3,1,0); // one copy no translation/rotation
+    vSDD2->AddNode(vITS4,1,0); // one copy no translation/rotation
+    //
+    sITS5 = new TGeoBBox((Double_t*)ksensitiveSSD);
+    vITS5 = new TGeoVolume("ITS5",sITS5,sensitiveSi);
+    sITS6 = new TGeoBBox((Double_t*)ksensitiveSSD);
+    vITS6 = new TGeoVolume("ITS6",sITS6,sensitiveSi);
+    sSSD  = new TGeoBBox((Double_t*)kwaferSSD);
+    vSSD1 = new TGeoVolume("ITSssd1",sSSD,bulckSi);
+    vSSD2 = new TGeoVolume("ITSssd2",sSSD,bulckSi);
+    vSSD1->AddNode(vITS5,1,0); // one copy no translation/rotation
+    vSSD2->AddNode(vITS6,1,0); // one copy no translation/rotation
+    //
+    sITS = new TGeoBBox(100.0,100.,100.0);
+    vITS = new TGeoVolume("ITSV",sITS,n2); // one copy of vacume ITSV
+    const Int_t length=100;
+    Char_t vstrng[length];
+    if(fIgm.WriteVersionString(vstrng,length,(AliITSVersion_t)IsVersion(),
+                               fMinorVersion,cvsDate,cvsRevision))
+        vITS->SetTitle(vstrng);
+    else Error("CreateGeometry2","Error writing/setting version string");
 
-    SetITSgeom(0);
-    nlad[0]=20;nlad[1]=40;nlad[2]=14;nlad[3]=22;nlad[4]=34;nlad[5]=38;
-    ndet[0]= 4;ndet[1]= 4;ndet[2]= 6;ndet[3]= 8;ndet[4]=22;ndet[5]=25;
-    AliITSgeom* geom = new AliITSgeom(0,6,nlad,ndet,mod);
-    SetITSgeom(geom);
-    mod = 0;
-    for(lay=1;lay<=knlayers;lay++){
-        for(cp0=1;cp0<=itsGeomTreeCopys[lay-1][0];cp0++){
-            for(cp1=1;cp1<=itsGeomTreeCopys[lay-1][1];cp1++){
-                for(cp2=1;cp2<=itsGeomTreeCopys[lay-1][2];cp2++){
-                    path.Form(names[fMinorVersion-1][lay-1].Data(),
-                              cp0,cp1,cp2);
-                    switch (lay){
-                    case 1:{
-                        det = cp2;
-                        lad = cp1+2*(cp0-1);
-                    }break;
-                    case 2:{
-                        det = cp2;
-                        lad = cp1+4*(cp0-1);
-                    } break;
-                    case 3: case 4: case 5: case 6:{
-                        det = cp1;
-                        lad = cp0;
-                    } break;
-                    } // end switch
-                         //AliInfo(Form("path=%s lay=%d lad=%d det=%d",
-                         //             path.Data(),lay,lad,det));
-                    gMC->GetTransformation(path.Data(),matrix);
-                    gMC->GetShape(path.Data(),shapeName,shapePar);
-                    shapeParF.Set(shapePar.GetSize());
-                    for(i=0;i<shapePar.GetSize();i++) shapeParF[i]=shapePar[i];
-                    geom->CreateMatrix(mod,lay,lad,det,idet[lay-1],trans,rot);
-                    geom->SetTrans(mod,matrix.GetTranslation());
-                    geom->SetRotMatrix(mod,matrix.GetRotationMatrix());
-                   geom->GetGeomMatrix(mod)->SetPath(path.Data());
-                    switch (lay){
-                    case 1: case 2:
-                       if(!shapeDefined[kSPD]){
-                        geom->ReSetShape(kSPD,new AliITSgeomSPD425Short(
-                                shapeParF.GetSize(),shapeParF.GetArray()));
-                       shapeDefined[kSPD] = kTRUE;
-                    }break;
-                    case 3: case 4:
-                       if(!shapeDefined[kSDD]){
-                        geom->ReSetShape(kSDD,new AliITSgeomSDD256(
-                                shapeParF.GetSize(),shapeParF.GetArray()));
-                       shapeDefined[kSDD] = kTRUE;
-                    }break;
-                    case 5:
-                       if(!shapeDefined[kSSD]){
-                        geom->ReSetShape(kSSD,new AliITSgeomSSD75and275(
-                                shapeParF.GetSize(),shapeParF.GetArray()));
-                       shapeDefined[kSSD] = kTRUE;
-                    }break;
-                    case 6:
-                       if(!shapeDefined[kSSDp]){
-                        geom->ReSetShape(kSSDp,new AliITSgeomSSD275and75(
-                                shapeParF.GetSize(),shapeParF.GetArray()));
-                       shapeDefined[kSSDp] = kTRUE;
-                    }break;
-                    default:{
-                    }break;
-                    } // end switch
-                    mod++;
-                } /// end for cp2
-            } // end for cp1
-        } // end for cp0
-    } // end for lay
+    vALIC->AddNode(vITS,1,0);// one copy no translation/rotation
+    //
+    TGeoTranslation *t1,*t2,*t3,*t4,*t5,*t6;
+    TGeoRotation    *r1,*r2,*r3,*r4,*r5,*r6;
+    TGeoCombiTrans  *tr1,*tr2,*tr3,*tr4,*tr5,*tr6;
+    t1 = new TGeoTranslation( +4.0,+0.0,+0.0); // "perfect" location
+    r1 = new TGeoRotation("",90.0,0.0,0.0);    // "perfect" location
+    tr1= new TGeoCombiTrans(*t1,*r1);// "perfect" location
+    t2 = new TGeoTranslation( +7.0,+0.2,-0.5);
+    r2 = new TGeoRotation("",-91.0,10.0,-5.0);
+    tr2= new TGeoCombiTrans(*t2,*r2);
+    t3 = new TGeoTranslation(+14.9,-0.6,+0.1);
+    r3 = new TGeoRotation("",93.0,-7.0,5.0);
+    tr3= new TGeoCombiTrans(*t3,*r3);
+    t4 = new TGeoTranslation(+23.8,+0.3,-0.2);
+    r4 = new TGeoRotation("",91.0,10.0,-5.0);
+    tr4= new TGeoCombiTrans(*t4,*r4);
+    t5 = new TGeoTranslation(+39.1,+0.1,+0.4);
+    r5 = new TGeoRotation("",88.0,1.0,5.0);
+    tr5= new TGeoCombiTrans(*t5,*r5);
+    t6 = new TGeoTranslation(+43.6,-0.5,+0.2);
+    r6 = new TGeoRotation("",92.0,0.0,-5.0);
+    tr6= new TGeoCombiTrans(*t6,*r6);
+    //
+    vITS->AddNode(vSPD1,1,tr1);
+    vITS->AddNode(vSPD2,1,tr2);
+    vITS->AddNode(vSDD1,1,tr3);
+    vITS->AddNode(vSDD2,1,tr4);
+    vITS->AddNode(vSSD1,1,tr5);
+    vITS->AddNode(vSSD2,1,tr6);
+    //
     return;
 }
 //_____________________________________________________________________________
 void AliITSvtest::Init(){
-////////////////////////////////////////////////////////////////////////
-//     Initialise the ITS after it has been created.
-////////////////////////////////////////////////////////////////////////
+    // Initialise the ITS after it has been created.
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
     Int_t i;
 
     cout << endl;
     for(i=0;i<29;i++) cout << "*";cout << " ITSvtest_Init ";
     for(i=0;i<28;i++) cout << "*";cout << endl;
-//
-    if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
-    if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
-    if(GetITSgeom()!=0) SetITSgeom(0x0);
-    SetITSgeom(new AliITSgeom());
-    if(fGeomDetIn) GetITSgeom()->ReadNewFile(fRead);
-    if(!fGeomDetIn) this->InitAliITSgeom();
-    if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
+
+    switch(GetMinorVersion()){
+    case 1:
+        InitEuclid();
+        break;
+    case 2:
+        Init2();
+        break;
+    default:
+        break;
+    } // end switch
+    UpdateInternalGeometry();
     AliITS::Init();
-//
+    if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite.Data());
+
     for(i=0;i<72;i++) cout << "*";
     cout << endl;
 }
 //_____________________________________________________________________________
+void AliITSvtest::InitEuclid(){
+    // Initialise the ITS after it has been created. Euclid version
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+}
+//_____________________________________________________________________________
+void AliITSvtest::Init2(){
+    // Initialise the ITS after it has been created. Geometry 2 verion
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+    Int_t i,n=3,imed[3];
+    TGeoManager *mgr = gGeoManager;
+    if(mgr==0) Error("Init2","mgr=0");
+    TGeoMedium *sensitiveSi = mgr->GetMedium("ITSsensitiveSi");
+    TGeoMedium *bulckSi = mgr->GetMedium("ITSnonsensitiveSi");
+    TGeoMedium *n2 = mgr->GetMedium("ITSN2");
+
+    if(sensitiveSi==0) Error("Init2","sensitiveSi=0");
+    if(bulckSi==0) Error("Init2","bulckSi=0");
+    if(n2==0) Error("Init2","n2=0");
+    imed[0] = sensitiveSi->GetId();
+    imed[1] = bulckSi->GetId();
+    imed[2] = n2->GetId();
+    for(i=0;i<n;i++){
+        if(imed[i]<=0){
+            Error("Init2","GetId failed for imed[i=%d]=%d",i,imed[i]);
+            return;
+        } // end if
+        gMC->Gstpar(imed[i],"CUTGAM",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"CUTELE",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"CUTNEU",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"CUTHAD",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"CUTMUO",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"BCUTE",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"BCUTM",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"DCUTE",30.0*fgkKeV);
+        gMC->Gstpar(imed[i],"DCUTM",30.0*fgkKeV);
+        //gMC->Gstpar(imed[i],"PPCUTM",);
+        //gMC->Gstpar(imed[i],"PAIR",);
+        //gMC->Gstpar(imed[i],"COMPT",);
+        //gMC->Gstpar(imed[i],"PHOT",);
+        //gMC->Gstpar(imed[i],"PFIS",);
+        gMC->Gstpar(imed[i],"DRAY",1);
+        //gMC->Gstpar(imed[i],"ANNI",);
+        //gMC->Gstpar(imed[i],"BREM",);
+        //gMC->Gstpar(imed[i],"HADR",);
+        //gMC->Gstpar(imed[i],"MUNU",);
+        //gMC->Gstpar(imed[i],"DCAY",);
+        gMC->Gstpar(imed[i],"LOSS",1);
+        //gMC->Gstpar(imed[i],"MULS",);
+        //gMC->Gstpar(imed[i],"GHCOR1",);
+        //gMC->Gstpar(imed[i],"BIRK1",);
+        //gMC->Gstpar(imed[i],"BRIK2",);
+        //gMC->Gstpar(imed[i],"BRIK3",);
+        //gMC->Gstpar(imed[i],"LABS",);
+        //gMC->Gstpar(imed[i],"SYNC",);
+        //gMC->Gstpar(imed[i],"STRA",);
+    } // end for i
+    return;
+}
+//_____________________________________________________________________________
 void AliITSvtest::StepManager(){
-  //
-  // Called for every step in the ITS
-  //
-  Int_t          copy, id;
-  Int_t          copy1,copy2;
-  Float_t        hits[8];
-  Int_t          vol[4];
-  TLorentzVector position, momentum;
-  TClonesArray   &lhits = *fHits;
-  //
-  // Track status
-  vol[3] = 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.
-  if(!(gMC->TrackCharge())) return;
-  //
-  // Only entering charged tracks
-  if((id = gMC->CurrentVolID(copy)) == fIdSens[0]) {
-      vol[0] = 1;
-      id = gMC->CurrentVolOffID(0,copy);
-      //detector copy in the ladder = 1<->4  (ITS1)
-      vol[1] = copy;
-      gMC->CurrentVolOffID(1,copy1);
-      //ladder copy in the module   = 1<->2  (I186)
-      gMC->CurrentVolOffID(2,copy2);
-      //module copy in the layer    = 1<->10 (I132)
-      vol[2] = copy1+(copy2-1)*2;//# of ladders in one module  = 2
-  } else if(id == fIdSens[1]){
-      vol[0] = 2;
-      id = gMC->CurrentVolOffID(0,copy);
-      //detector copy in the ladder = 1<->4  (ITS2)
-      vol[1] = copy;
-      gMC->CurrentVolOffID(1,copy1);
-      //ladder copy in the module   = 1<->4  (I131)
-      gMC->CurrentVolOffID(2,copy2);
-      //module copy in the layer    = 1<->10 (I132)
-      vol[2] = copy1+(copy2-1)*4;//# of ladders in one module  = 4
-  } else if(id == fIdSens[2]){
-      vol[0] = 3;
-      id = gMC->CurrentVolOffID(1,copy);
-      //detector copy in the ladder = 1<->5  (ITS3 is inside I314)
-      vol[1] = copy;
-      id = gMC->CurrentVolOffID(2,copy);
-      //ladder copy in the layer    = 1<->12 (I316)
-      vol[2] = copy;
-  } else if(id == fIdSens[3]){
-      vol[0] = 4;
-      id = gMC->CurrentVolOffID(1,copy);
-      //detector copy in the ladder = 1<->8  (ITS4 is inside I414)
-      vol[1] = copy;
-      id = gMC->CurrentVolOffID(2,copy);
-      //ladder copy in the layer    = 1<->22 (I417)
-      vol[2] = copy;
-  }else if(id == fIdSens[4]){
-      vol[0] = 5;
-      id = gMC->CurrentVolOffID(1,copy);
-      //detector copy in the ladder = 1<->23  (ITS5 is inside I562)
-      vol[1] = copy;
-      id = gMC->CurrentVolOffID(2,copy);
-     //ladder copy in the layer    = 1<->34 (I565)
-      vol[2] = copy;
-  }else if(id == fIdSens[5]){
-      vol[0] = 6;
-      id = gMC->CurrentVolOffID(1,copy);
-      //detector copy in the ladder = 1<->26  (ITS6 is inside I566)
-      vol[1] = copy;
-      id = gMC->CurrentVolOffID(2,copy);
-      //ladder copy in the layer = 1<->38 (I569)
-      vol[2] = copy;
-  } else {
-      return; // not an ITS volume?
-  } // end if/else if (gMC->CurentVolID(copy) == fIdSens[i])
-//
-  gMC->TrackPosition(position);
-  gMC->TrackMomentum(momentum);
-  hits[0]=position[0];
-  hits[1]=position[1];
-  hits[2]=position[2];
-  hits[3]=momentum[0];
-  hits[4]=momentum[1];
-  hits[5]=momentum[2];
-  hits[6]=gMC->Edep();
-  hits[7]=gMC->TrackTime();
-  // Fill hit structure with this new hit.
-  new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->GetMCApp()->GetCurrentTrackNumber(),vol,hits);
+    // Called for every step in the ITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+    //
+    // Fill hit structure.
+    static TLorentzVector position, momentum; // Saves on calls to construtors
+    static AliITShit hit;                     // Saves on calls to construtors
+    Int_t cpn0,cpn1,cpn2,status,lay,mod,id;
+
+    if(!(gMC->TrackCharge())) return;
+    if(!(this->IsActive())) return;
+    TClonesArray &lhits = *(Hits());
+    // 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;
+    // Only entering charged tracks
+    id = gMC->CurrentVolID(cpn0);
+    for(lay=0;lay<6;lay++) if(id == fIdSens[lay]) break;
+    lay++;
+    if(lay>6) return; // not in detector
+    cpn0=cpn1=cpn2=1;
+    fIgm.DecodeDetector(mod,lay,cpn0,cpn1,cpn2);
+    // 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.
+    new(lhits[fNhits++]) AliITShit(hit); // Use Copy Construtor.
+    // Save old position... for next hit.
+    hit.SetStartPosition(position);
+    hit.SetStartTime(gMC->TrackTime());
+    hit.SetStartStatus(status);
+    //
+    Double_t g0[4],l0[4],g1[4];
+    position.GetXYZT(g0);
+    gMC->Gmtod(g0,l0,1); // flag=1 convert coordiantes
+    gMC->Gdtom(l0,g1,1); // flag=1 convert coordinates
+    printf("    gMC: mod=%d g=%g %g %g %g -> l= %g %g %g %g ->g=%g %g %g %g\n",
+           mod,g0[0],g0[1],g0[2],g0[3],l0[0],l0[1],l0[2],l0[3],g1[0],g1[2],g1[2],g1[3]);
+    GetITSgeom()->GtoL(mod,g0,l0);
+    GetITSgeom()->LtoG(mod,l0,g1);
+    printf("ITSgeom: mod=%d g=%g %g %g %g -> l= %g %g %g %g ->g=%g %g %g %g\n",
+           mod,g0[0],g0[1],g0[2],g0[3],l0[0],l0[1],l0[2],l0[3],g1[0],g1[2],g1[2],g1[3]);
+    TGeoNode *cur = gGeoManager->GetCurrentNode();
+    cur->MasterToLocal(g0,l0);
+    cur->LocalToMaster(l0,g1);
+    printf("   TGeo: mod=%d g=%g %g %g %g -> l= %g %g %g %g ->g=%g %g %g %g\n",
+           mod,g0[0],g0[1],g0[2],g0[3],l0[0],l0[1],l0[2],l0[3],g1[0],g1[2],g1[2],g1[3]);
+    printf("=====================\n");
+    //
+
   return;
 }
+//______________________________________________________________________
+void AliITSvtest::PrintAscii(ostream *os)const{
+    // Print out class data values in Ascii Form to output stream
+    // Inputs:
+    //   ostream *os   Output stream where Ascii data is to be writen
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+#if defined __GNUC__
+#if __GNUC__ > 2
+    ios::fmtflags fmt;
+#else
+    Int_t fmt;
+#endif
+#else
+#if defined __ICC || defined __ECC || defined __xlC__
+    ios::fmtflags fmt;
+#else
+    Int_t fmt;
+#endif
+#endif
+
+    *os << fGeomDetOut << " " << fGeomDetIn  << " ";
+    *os << fMajorVersion << " " << fMinorVersion << " ";
+    *os << "\"" << fEuclidGeomDet.Data() << "\"" << " ";
+    *os << "\"" << fRead.Data() << "\"" << " ";
+    *os << "\"" << fWrite.Data() << "\"" << " ";
+    fmt = os->setf(ios::scientific); // set scientific floating point output
+    os->flags(fmt); // reset back to old Formating.
+    return;
+}
+//______________________________________________________________________
+void AliITSvtest::ReadAscii(istream *is){
+    // Read in class data values in Ascii Form to output stream
+    // Inputs:
+    //   istream *is   Input stream where Ascii data is to be read in from
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+    Char_t name[120];
 
+    *is >> fGeomDetOut >> fGeomDetIn ;
+    *is >> fMajorVersion >> fMinorVersion;
+    *is >> name;
+    fEuclidGeomDet = name;
+    *is >> name;
+    fRead = name;
+    *is >> name;
+    fWrite = name;
+    fIgm.SetVersion((AliITSVersion_t)fMajorVersion,fMinorVersion);
+    fIgm.SetGeometryName("ITS test geometry");
+}
+//______________________________________________________________________
+ostream &operator<<(ostream &os,const AliITSvtest &s){
+    // Standard output streaming function
+    // Inputs:
+    //   ostream            &os  output steam
+    //   AliITSvtest &s class to be streamed.
+    // Output:
+    //   none.
+    // Return:
+    //   ostream &os  The stream pointer
+
+    s.PrintAscii(&os);
+    return os;
+}
+//______________________________________________________________________
+istream &operator>>(istream &is,AliITSvtest &s){
+    // Standard inputput streaming function
+    // Inputs:
+    //   istream            &is  input steam
+    //   AliITSvtest &s class to be streamed.
+    // Output:
+    //   none.
+    // Return:
+    //   ostream &os  The stream pointer
+
+    s.ReadAscii(&is);
+    return is;
+}