]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSvSSD03.cxx
New default values for baselines (F.Prino)
[u/mrichter/AliRoot.git] / ITS / AliITSvSSD03.cxx
index 729708edbc39bca65b2fc9d300821302bb5440a7..a8bad6d4854c37552b8cea25ef3cfdfaff6696ae 100644 (file)
 // Enrico Fragiacomo - 15/03/2004
 // Geometry for the June 2003 SSD beam test
 
-#include <Riostream.h>
-#include <TMath.h>
 #include <TGeometry.h>
 #include <TNode.h>
 #include <TLorentzVector.h>
 #include <TClonesArray.h>
 #include <TBRIK.h>
+#include <TVirtualMC.h>
+#include <TGeoMatrix.h>
+#include <TGeoManager.h>
 
 #include "AliRun.h"
 #include "AliMagF.h"
-#include "AliITSGeant3Geometry.h"
 #include "AliTrackReference.h"
 #include "AliITShit.h"
 #include "AliITS.h"
 #include "AliITSvSSD03.h"
 #include "AliITSgeom.h"
 #include "AliITSgeomSSD.h"
-#include "AliITSDetType.h"
-#include "AliITSresponseSPD.h"
-#include "AliITSresponseSDD.h"
-#include "AliITSresponseSSD.h"
-#include "AliITSsegmentationSPD.h"
-#include "AliITSsegmentationSDD.h"
+#include "AliITSDetTypeSim.h"
+#include "AliITSCalibrationSSD.h"
 #include "AliITSsegmentationSSD.h"
-#include "AliITSsimulationSPDdubna.h"
-#include "AliITSsimulationSDD.h"
 #include "AliITSsimulationSSD.h"
 #include "AliMC.h"
 
+
 ///////////////////////////////////////////////////////////////////////
 // Step manager and 
 // geometry class
 ClassImp(AliITSvSSD03)
 
 //______________________________________________________________________
-AliITSvSSD03::AliITSvSSD03() {
+AliITSvSSD03::AliITSvSSD03():
+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 
+fGeomNumber(2003),         // Geometry version number (year)
+fEuclidGeomDet(),          // file where detector transormation are define.
+fRead(),                   //! file name to read .det file
+fWrite(),                  //! file name to write .det file 
+fIDMother(0),              //! ITS Mother Volume id.
+fIgm(kvSSD03){             //! AliITSInitGeometry object {
     ////////////////////////////////////////////////////////////////////////
     // Standard default constructor for the ITS SSD test beam 2003 version 1.
     // Inputs:
@@ -71,18 +77,23 @@ AliITSvSSD03::AliITSvSSD03() {
     fIdN          = 0;
     fIdName       = 0;
     fIdSens       = 0;
-    fEuclidOut    = kFALSE; // Don't write Euclide file
-    fGeomDetOut   = kFALSE; // Don't write .det file
-    fGeomDetIn    = kFALSE; // Don't Read .det file
-    fMajorVersion = IsVersion();
-    fMinorVersion = -1;
-    fGeomNumber   = 2003; // default value
     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';
 }
 //______________________________________________________________________
-AliITSvSSD03::AliITSvSSD03(const char *title,Int_t gn) : AliITS("ITS", title){
+AliITSvSSD03::AliITSvSSD03(const char *title,Int_t gn) :
+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(2),         // Minor version number 
+fGeomNumber(gn),         // Geometry version number (year)
+fEuclidGeomDet(),          // file where detector transormation are define.
+fRead(),                   //! file name to read .det file
+fWrite(),                  //! file name to write .det file 
+fIDMother(0),              //! ITS Mother Volume id.
+fIgm(kvSSD03){             //! AliITSInitGeometry object {
     ////////////////////////////////////////////////////////////////////////
     //    Standard constructor for the ITS SSD testbeam 2003 version 1.
     // Inputs:
@@ -95,24 +106,12 @@ AliITSvSSD03::AliITSvSSD03(const char *title,Int_t gn) : AliITS("ITS", title){
     ////////////////////////////////////////////////////////////////////////
     Int_t i;
 
-    fGeomNumber = gn;
 
     fIdN = 1; 
     fIdName = new TString[fIdN];
     fIdName[0] = "ITST";
     fIdSens    = new Int_t[fIdN];
-    for(i=0;i<fIdN;i++) fIdSens[i] = 0;
-
-    fMajorVersion = IsVersion();
-    fMinorVersion = 2;
-    fEuclidOut    = kFALSE; // Don't write Euclide file
-    fGeomDetOut   = kFALSE; // Don't write .det file
-    fGeomDetIn    = kFALSE; // Don't Read .det file
-
-    SetThicknessDet1();
-    SetThicknessDet2();
-    SetThicknessChip1();
-    SetThicknessChip2();                        
+    for(i=0;i<fIdN;i++) fIdSens[i] = 0;                         
 
     fEuclidGeometry="$ALICE_ROOT/ITS/ITSgeometry_vSSD03.euc";
     strncpy(fEuclidGeomDet,"$ALICE_ROOT/ITS/ITSgeometry_vSSD03.det",60);
@@ -120,38 +119,6 @@ AliITSvSSD03::AliITSvSSD03(const char *title,Int_t gn) : AliITS("ITS", title){
     strncpy(fWrite,fEuclidGeomDet,60);
 }
 //______________________________________________________________________
-AliITSvSSD03::AliITSvSSD03(const AliITSvSSD03 &source) : AliITS(source){
-    ////////////////////////////////////////////////////////////////////////
-    //     Copy Constructor for ITS SSD test beam 2003 version 1.
-    // This class is not to be copied. Function only dummy.
-    // Inputs:
-    //    const AliITSvSSD03 &source   The class to be copied
-    // Outputs:
-    //    none.
-    // Return:
-    //    A warning message.
-    ////////////////////////////////////////////////////////////////////////
-    if(&source == this) return;
-    Warning("Copy Constructor","Not allowed to copy AliITSvSSD03");
-    return;
-}
-//______________________________________________________________________
-AliITSvSSD03& AliITSvSSD03::operator=(const AliITSvSSD03 &source){
-    ////////////////////////////////////////////////////////////////////////
-    //    Assignment operator for the ITS SSD test beam 2003 version 1.
-    // This class is not to be copied. Function only dummy.
-    // Inputs:
-    //    const AliITSvSSD03 &source   The class to be copied
-    // Outputs:
-    //    none.
-    // Return:
-    //    A Warning message
-    ////////////////////////////////////////////////////////////////////////
-    if(&source == this) return *this;
-    Warning("= operator","Not allowed to copy AliITSvSSD03");
-    return *this;
-}
-//______________________________________________________________________
 AliITSvSSD03::~AliITSvSSD03() {
     ////////////////////////////////////////////////////////////////////////
     //    Standard destructor for the ITS SSD test beam 2003 version 1.
@@ -265,49 +232,75 @@ void AliITSvSSD03::CreateGeometry(){
 }
 //______________________________________________________________________
 void AliITSvSSD03::CreateGeometry2003(){
-  ////////////////////////////////////////////////////////////////////////
-  //
-  //    ALIC    ALICE Mother Volume
-  //     |- ITSV     Beamtest Mother Volume
-  //         |
-  //         |- ITSA       Aluminum cover for scintillator
-  //         |    |-ITSS    first Trieste trigger plastic scintillator 
-  //         |- ITSA       Aluminum cover for scintillator
-  //         |    |-ITSS    second Trieste's trigger plastic scintillator
-  //         |
-  //         |- IGAR       Black box around ITST       
-  //         |    |-IAIR    Air inside the black box
-  //         |        |-ITST    Detector under Test 
-  //         |
-  //         |- IFRA       Aluminum cover for scintillator
-  //         |    |-IFRS    French plastic scintillator 
-  //         |
-  //         |- ITSA       Aluminum cover for scintillator
-  //         |    |-ITSS    third Trieste's plastic scintillator
-  // Inputs:
-  //    none.
-  // Outputs:
-  //    none.
-  // Return:
-  //    none.
-  ////////////////////////////////////////////////////////////////////////
-  
-  Float_t data[49];
-  // Define media off-set
-  Int_t *idtmed = fIdtmed->GetArray()+1; // array of media indexes
-  Int_t idrotm[4]; // Array of rotation matrix indexes
-   //Float_t yposition= 0.0;
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //    ALIC    ALICE Mother Volume
+    //     |- ITSV     Beamtest Mother Volume
+    //         |
+    //         |- ITSA       Aluminum cover for scintillator
+    //         |    |-ITSS    first Trieste trigger plastic scintillator 
+    //         |- ITSA       Aluminum cover for scintillator
+    //         |    |-ITSS    second Trieste's trigger plastic scintillator
+    //         |
+    //         |- IGAR       Black box around ITST       
+    //         |    |-IAIR    Air inside the black box
+    //         |        |-ITST    Detector under Test 
+    //         |
+    //         |- IFRA       Aluminum cover for scintillator
+    //         |    |-IFRS    French plastic scintillator 
+    //         |
+    //         |- ITSA       Aluminum cover for scintillator
+    //         |    |-ITSS    third Trieste's plastic scintillator
+    //
+    //      ITSA ITSA IGAR IFRA ITSA
+    // Z->  -282 -280   0   16   270
+    //        |    |    |    |    |
+    // cpn0   1    2    1    1    3
+    //
+    // Inputs:
+    //    none.
+    // Outputs:
+    //    none.
+    // Return:
+    //    none.
+    ////////////////////////////////////////////////////////////////////////
+    Float_t data[49];
+    // Define media off-set
+    Int_t *idtmed = fIdtmed->GetArray()+1; // array of media indexes
+    Int_t idrotm[4]; // Array of rotation matrix indexes
+    // 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$";
+    //Float_t yposition= 0.0;
   
   if(gMC==0) return;
   // Define Rotation-reflextion Matrixes needed
   // 0 is the unit matrix
 
+  /*
   // Beamtest mother volume (air) positioned in ALIC mother volume
   data[0] = 500.0;
   data[1] = 500.0;
   data[2] = 1000.0;
   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 length=100;
+    Char_t vstrng[length];
+    if(fIgm.WriteVersionString(vstrng,length,(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
+    // See idrotm[199] for angle definitions.
+    alic->AddNode(itsV,1,0);
   
   // Trieste's plastic scintillators for the trigger (2 at beam enter)
   // ...define them (aluminum cover + scintillator inside)
@@ -388,7 +381,7 @@ void AliITSvSSD03::CreateMaterials(){
     // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
     // AliITSvSSD03.
     // 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.
@@ -419,7 +412,7 @@ void AliITSvSSD03::CreateMaterials2003(){
     // Monte Carlo simulations for the geometries AliITSv1, AliITSv3,
     // AliITSvSSD03.
     // 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.
@@ -484,11 +477,9 @@ void AliITSvSSD03::CreateMaterials2003(){
     // Kapton
     AliMaterial(5, "Kapton$", 12.011, 6., 1.3, 31.27, 999.);
     AliMedium(5, "Kapton$",    5, 0,ifield,fieldm, 10., .01, .1, .003, .003);
-}
+}/*
 //______________________________________________________________________
 void AliITSvSSD03::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.
   // Inputs:
   //    none.
@@ -496,104 +487,25 @@ void AliITSvSSD03::InitAliITSgeom(){
   //    none.
   // Return:
   //    none.
-
-  //const Int_t kltypess = 2;   // was 2 for SPD beamtest 
-  const Int_t kltypess = 1;
-  //const Int_t knlayers = 5; // was 5 for the SPD telescope
-  const Int_t knlayers = 1;   // for one SSD module
-  const Int_t kndeep = 5;    
-  
-  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;
-  AliITSGeant3Geometry *ig=0;
-  Int_t mod=0,typ=0,lay=0,lad=0,det=0,cpy=0,i=0,j=0,k=0;
-  
-  if(gMC==0) {// No MonteCarlo to init. Default set fITSgeom by hand
-    if(fITSgeom!=0) delete fITSgeom;
-    
-    //nlad[0]=1;nlad[1]=1;nlad[2]=1;nlad[3]=1;nlad[4]=1;
-    //ndet[0]=1;ndet[1]=1;ndet[2]=1;ndet[3]=1;ndet[4]=1;
-    nlad[0]=1;
-    ndet[0]=1;
-    
-    fITSgeom = new AliITSgeom(0,knlayers,nlad,ndet,mod);
-    
-    r[0] = 1.0; r[1] =  0.0; r[2] = 0.0;
-    r[3] = 0.0; r[4] =  0.0; r[5] = 1.0;
-    r[6] = 0.0; r[7] = -1.0; r[8] = 0.0; r[9] = 1.0; // not Unit.
-    
-    Double_t tt[1][3]={{0.0,0.0,0.0}};
-    
-    // for(mod=0;mod<5;mod++){
-    for(mod=0;mod<1;mod++){
-      lay = 1;
-      lad = 1;
-      det = mod+1;
-      t[0] = tt[mod][0]; t[1] = tt[mod][1]; t[2] = tt[mod][2];
-      fITSgeom->CreatMatrix(mod,lay,lad,det,kSSD,t,r);
-      
-      npar=3;par[0]=3.5;par[1]=0.5*300.0E-4;par[2]=2.0;
-      
-      fITSgeom->ReSetShape(kSSD,new AliITSgeomSSD275and75(npar,par));
-    } // end for det
-    return;
-  } // end if gMC==0
-  
-  if(strcmp(gMC->GetName(),"TGeant3")) {
-    Error("InitAliITSgeom",
-         "Wrong Monte Carlo. InitAliITSgeom uses TGeant3 calls");
+    const Int_t knlayers=1;
+    const TString kname="ALIC_1/ITSV_1/IGAR_1/IAIR_1/ITST_1";
+    const Int_t knlad[knlayers]={knlayers*1},kndet[knlayers]={knlayers*1};
+    Int_t npar;
+    Float_t par[20];
+    Double_t trans[3]={3*0.0},rot[10]={10*0.0};
+    TGeoHMatrix materix;
+
+    AliITSgeom* geom = new AliITSgeom(0,knlayers,knlad,kndet,1);
+    SetITSgeom(geom);
+    npar=3;par[0]=3.5;par[1]=0.5*300.0E-4;par[2]=2.0;
+    geom->ReSetShape(kSSD,new AliITSgeomSSD275and75(npar,par));
+    gMC->GetTransformation(kname.Data(),materix);
+    geom->CreateMatrix(0,1,1,1,kSSD,trans,rot);
+    geom->SetTrans(0,materix.GetTranslation());
+    geom->SetRotMatrix(0,materix.GetRotationMatrix());
+    geom->GetGeomMatrix(0)->SetPath(kname.Data());
     return;
-  } // end if
-  
-  cout << "Reading Geometry transformation directly from Geant 3." << endl;
-  ig = new AliITSGeant3Geometry();
-  Char_t names[kltypess][kndeep][4];
-  Int_t itsGeomTreeCopys[kltypess][kndeep];
-  const char *namesA[kltypess][kndeep] = 
-    {{"ALIC","ITSV","IGAR","IAIR","ITST"}}; // Test SSD
-  Int_t itsGeomTreeCopysA[kltypess][kndeep]= {{1,1,1,1,1}};// TestSSD
-  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
-  
-  cout << "Reading Geometry informaton from Geant3 common blocks" << endl;
-  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 = 1;   // was 5
-  if(fITSgeom!=0) delete fITSgeom;
-
-  nlad[0]=1;
-  ndet[0]=1;
-  fITSgeom = new AliITSgeom(0,knlayers,nlad,ndet,mod);
-  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];
-    lad = 1;
-    det = 1;
-    for(cpy=1;cpy<=itsGeomTreeCopys[typ-1][2];cpy++){
-      lnum[2] = cpy;
-      lay = cpy;
-      if(cpy>2 && typ==1) lay = cpy +1;
-      if(typ==2) lay = 3;
-      mod = lay-1;
-      ig->GetGeometry(kndeep,lnam,lnum,t,r,idshape,npar,natt,par,att,
-                     imat,imed);
-      fITSgeom->CreatMatrix(mod,lay,lad,det,kSSD,t,r);
-      //cout<<mod<<" "<<lay<<" "<<lad<<" "<<det<<endl;
-      //cout<<npar<<" "<<par[0]<<" "<<par[1]<<" "<<par[2]<<endl;
-      if(!(fITSgeom->IsShapeDefined((Int_t)kSSD)))
-       fITSgeom->ReSetShape(kSSD, new AliITSgeomSSD275and75(npar,par));
-       } // end for cpy
-    } // end for typ
-    return;
-}
+}*/
 //______________________________________________________________________
 void AliITSvSSD03::Init(){
     ////////////////////////////////////////////////////////////////////////
@@ -605,30 +517,24 @@ void AliITSvSSD03::Init(){
     // Return:
     //    none.
     ////////////////////////////////////////////////////////////////////////
-    Int_t i;
 
-    cout << endl;
-    for(i=0;i<26;i++) cout << "*";
-    cout << " ITSvSSD03" << fMinorVersion << "_Init ";
-    for(i=0;i<25;i++) cout << "*";cout << endl;
-//
-    if(fRead[0]=='\0') strncpy(fRead,fEuclidGeomDet,60);
-    if(fWrite[0]=='\0') strncpy(fWrite,fEuclidGeomDet,60);
-    if(fITSgeom!=0) delete fITSgeom;
-    fITSgeom = new AliITSgeom();
-    if(fGeomDetIn) fITSgeom->ReadNewFile(fRead);
-    if(!fGeomDetIn) this->InitAliITSgeom();
-    if(fGeomDetOut) fITSgeom->WriteNewFile(fWrite);
+
+    Info("Init","**********AliITSvSSD03 %d _Init *************",fMinorVersion);
+
+    AliDebug(1,Form("Init: Major version %d Minor version %d",fMajorVersion,
+                 fMinorVersion));
+    //
+    UpdateInternalGeometry();
     AliITS::Init();
-//
-    for(i=0;i<72;i++) cout << "*";
-    cout << endl;
-    if(gMC) fIDMother = gMC->VolId("ITSV"); // ITS Mother Volume ID.
-    else fIDMother = 0;
-}
+    if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
+
+    //
+    fIDMother = gMC->VolId("ITSV"); // ITS Mother Volume ID.
+
+}/*
 //______________________________________________________________________
 void AliITSvSSD03::SetDefaults(){
-    // sets the default segmentation, response, digit and raw cluster classes
+    // sets the default segmentation, rerponse, digit and raw cluster classes
     // Inputs:
     //    none.
     // Outputs:
@@ -639,18 +545,20 @@ void AliITSvSSD03::SetDefaults(){
 
     Info("SetDefaults","Setting up only SSD detector");
 
-    AliITSDetType *iDetType;
+    if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
+    fDetTypeSim->SetITSgeom(GetITSgeom());
     AliITSgeomSSD  *s0;
-
+    fDetTypeSim->ResetCalibrationArray();
+    fDetTypeSim->ResetSegmentation();
     //SSD
-    iDetType=DetType(kSSD);
 
     // Get shape info. Do it this way for now.
-    s0 = (AliITSgeomSSD*) fITSgeom->GetShape(kSSD);
-    AliITSresponse *resp0=new AliITSresponseSSD("simulated");
+    s0 = (AliITSgeomSSD*) GetITSgeom()->GetShape(kSSD);
+    AliITSCalibration *resp0=new AliITSCalibrationSSD("simulated");
+    SetCalibrationModel(GetITSgeom()->GetStartSSD(),resp0);    
 
-    SetResponseModel(kSSD,resp0);
-    AliITSsegmentationSSD *seg0=new AliITSsegmentationSSD(fITSgeom);
+    AliITSsegmentationSSD *seg0=new AliITSsegmentationSSD();
     seg0->SetDetSize(s0->GetDx()*2.*kconv, // base this on AliITSgeomSSD
                     s0->GetDz()*2.*kconv, // for now.
                     s0->GetDy()*2.*kconv); // x,z,y full width in microns.
@@ -659,25 +567,24 @@ void AliITSvSSD03::SetDefaults(){
     SetSegmentationModel(kSSD,seg0);
 
     // set digit and raw cluster classes to be used
-    const char *kData0=(iDetType->GetResponseModel())->DataType();
-    if (strstr(kData0,"real")) iDetType->ClassNames("AliITSdigit",
-                                                   "AliITSRawClusterSSD");
-    else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
+    const char *kData0=(fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSSD()))->DataType();
+    if (strstr(kData0,"real")) fDetTypeSim->SetDigitClassName(kSSD,"AliITSdigit");
+    else fDetTypeSim->SetDigitClassName(kSSD,"AliITSdigitSSD");
 //    SetSimulationModel(kSSD,new AliITSsimulationSSD(seg0,resp0));
 //    iDetType->ReconstructionModel(new AliITSClusterFinderSSD());
 
 
-    SetResponseModel(kSPD,new AliITSresponseSPD());
-    SetSegmentationModel(kSPD,new AliITSsegmentationSPD());
-    DetType(kSPD)->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
+    //SetResponseModel(kSPD,new AliITSCalibrationSPD());
+    //SetSegmentationModel(kSPD,new AliITSsegmentationSPD());
+    //fDetTypeSim->SetDigitClassName(kSPD,"AliITSdigitSPD");
 
-    SetResponseModel(kSDD,new AliITSresponseSDD());
-    SetSegmentationModel(kSDD,new AliITSsegmentationSDD());
-    DetType(kSDD)->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
+    //SetResponseModel(kSDD,new AliITSCalibrationSDD());
+    //SetSegmentationModel(kSDD,new AliITSsegmentationSDD());
+    //fDetTypeSim->SetDigitClassName(kSDD,"AliITSdigitSDD");
 
 
 
-    if(kNTYPES>3){
+    if(fgkNTYPES>3){
        Warning("SetDefaults",
                "Only the four basic detector types are initialised!");
     }// end if
@@ -693,63 +600,70 @@ void AliITSvSSD03::SetDefaultSimulation(){
     // Return:
     //      none.
 
-    AliITSDetType *iDetType;
-    AliITSsimulation *sim;
-    AliITSsegmentation *seg;
-    AliITSresponse *res;
-
-    iDetType=DetType(kSPD);
-    if(!iDetType){
-        sim = iDetType->GetSimulationModel();
-        if (!sim) {
-            seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
-            res = (AliITSresponse*)iDetType->GetResponseModel();
-            sim = new AliITSsimulationSPDdubna(seg,res,1);
-            SetSimulationModel(kSPD,sim);
-        }else{ // simulation exists, make sure it is set up properly.
-            ((AliITSsimulation*)sim)->Init();
-//        if(sim->GetResponseModel()==0) sim->SetResponseModel(
-//            (AliITSresponse*)iDetType->GetResponseModel());
-//        if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
-//            (AliITSsegmentation*)iDetType->GetSegmentationModel());
-        } // end if
-    } // end if !iDetType
-
-    iDetType=DetType(kSDD);
-    if(!iDetType){
-        sim = iDetType->GetSimulationModel();
-        if (!sim) {
-            seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
-            res = (AliITSresponse*)iDetType->GetResponseModel();
-            sim = new AliITSsimulationSDD(seg,res);
-            SetSimulationModel(kSDD,sim);
-        }else{ // simulation exists, make sure it is set up properly.
-            ((AliITSsimulation*)sim)->Init();
-//        if(sim->GetResponseModel()==0) sim->SetResponseModel(
-//            (AliITSresponse*)iDetType->GetResponseModel());
-//        if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
-//            (AliITSsegmentation*)iDetType->GetSegmentationModel());
-    } //end if
-    } // end if !iDetType
-
-    iDetType=DetType(kSSD);
-    if(!iDetType){
-        sim = iDetType->GetSimulationModel();
-        if (!sim) {
-            seg = (AliITSsegmentation*)iDetType->GetSegmentationModel();
-            res = (AliITSresponse*)iDetType->GetResponseModel();
-            sim = new AliITSsimulationSSD(seg,res);
-            SetSimulationModel(kSSD,sim);
-        }else{ // simulation exists, make sure it is set up properly.
-            ((AliITSsimulation*)sim)->Init();
-//        if(sim->GetResponseModel()==0) sim->SetResponseModel(
-//            (AliITSresponse*)iDetType->GetResponseModel());
-//        if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
-//            (AliITSsegmentation*)iDetType->GetSegmentationModel());
-        } // end if
-    } // end if !iDetType
+  if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
+
+  AliITSsimulation *sim;
+  //  AliITSsegmentation *seg;
+  // AliITSCalibration *res;
+
+  //SPD
+  //if(fDetTypeSim){
+    //sim = fDetTypeSim->GetSimulationModel(kSPD);
+    //if (!sim) {
+      //seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD);
+      //res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(nspd);
+      //sim = new AliITSsimulationSPDdubna(seg,res,1);
+      //SetSimulationModel(kSPD,sim);
+    //}else{ // simulation exists, make sure it is set up properly.
+      //sim->SetSegmentationModel((AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSPD));
+      //sim->SetResponseModel((AliITSCalibration*)fDetTypeSim->GetResponseModel(nspd));
+      //((AliITSsimulation*)sim)->Init();
+      //        if(sim->GetResponseModel()==0) sim->SetResponseModel(
+      //            (AliITSCalibration*)iDetType->GetResponseModel());
+      //        if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
+      //            (AliITSsegmentation*)iDetType->GetSegmentationModel());
+    //} // end if
+  //} // end if !fDetTypeSim
+
+  //SDD
+  //if(fDetTypeSim){
+    //sim = fDetTypeSim->GetSimulationModel(kSDD);
+    //if (!sim) {
+      //seg = (AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD);
+      //res = (AliITSCalibration*)fDetTypeSim->GetResponseModel(nsdd);
+      //sim = new AliITSsimulationSDD(seg,res);
+      //SetSimulationModel(kSDD,sim);
+    //}else{ // simulation exists, make sure it is set up properly.
+      //sim->SetSegmentationModel((AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSDD));
+      //sim->SetResponseModel((AliITSCalibration*)fDetTypeSim->GetResponseModel(nsdd));
+
+      //((AliITSsimulation*)sim)->Init();
+      //        if(sim->GetResponseModel()==0) sim->SetResponseModel(
+      //            (AliITSCalibration*)iDetType->GetResponseModel());
+      //        if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
+      //            (AliITSsegmentation*)iDetType->GetSegmentationModel());
+    //} //end if
+  //} // end if !iDetType
+  //SSD
+  if(fDetTypeSim){
+    sim = fDetTypeSim->GetSimulationModel(kSSD);
+    if (!sim) {
+      //  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(kSSD,(AliITSsegmentation*)fDetTypeSim->GetSegmentationModel(kSSD));
+      sim->SetCalibrationModel(GetITSgeom()->GetStartSSD(),(AliITSCalibration*)fDetTypeSim->GetCalibrationModel(GetITSgeom()->GetStartSSD()));
+      ((AliITSsimulation*)sim)->Init();
+      //        if(sim->GetResponseModel()==0) sim->SetResponseModel(
+      //            (AliITSCalibration*)iDetType->GetResponseModel());
+      //        if(sim->GetSegmentationModel()==0) sim->SetSegmentationModel(
+      //            (AliITSsegmentation*)iDetType->GetSegmentationModel());
+    } // end if
+  } // end if !iDetType
 }
-
+*/
 //______________________________________________________________________
 void AliITSvSSD03::DrawModule() const {
     ////////////////////////////////////////////////////////////////////////
@@ -791,63 +705,60 @@ void AliITSvSSD03::StepManager(){
     // Return:
     //    none.
     ////////////////////////////////////////////////////////////////////////
-    Int_t         copy, id;
-    TLorentzVector position, momentum;
-    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;
+        return;
     } // end if !Active volume.
+    if(!(gMC->TrackCharge())) return;
 
-
-    Int_t   vol[5];
-    TClonesArray &lhits = *fHits;
+    Int_t cpy0,mod,id,status;
+    TLorentzVector position, momentum;
+    static AliITShit hit;// Saves on calls to construtors
+    //TClonesArray &lhits = *(GetDetTypeSim()->GetHits());
+    TClonesArray &lhits = *(Hits());
     //
     // 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;
+    // 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.
-    if(!(gMC->TrackCharge())) return;
-    id = gMC->CurrentVolID(copy);
+    id = gMC->CurrentVolID(cpy0);
     if(id==fIdSens[0]){  // Volume name "ITST"
-       vol[2] = vol[1] = vol[0] = 1; // Det, ladder
+       mod=2; // Det, ladder
     } else return; // end if
     //
+    //
+    // Fill hit structure.
+    //
+    hit.SetModule(mod);
+    hit.SetTrack(gAlice->GetMCApp()->GetCurrentTrackNumber());
     gMC->TrackPosition(position);
     gMC->TrackMomentum(momentum);
-    vol[4] = stat0;
+    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;
+        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 only for non-entrerance hits.
-    else new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->GetMCApp()->GetCurrentTrackNumber(),vol,
-                                       gMC->Edep(),gMC->TrackTime(),position,
-                                       position0,momentum);
-    //cout<<gMC->Edep()<<endl;
-    //
-    position0 = position;
-    stat0 = vol[3];
-
+    // 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;
 }