]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSvBeamTestITS04.cxx
Changes in SSD segmentation and simulation classes in order to take into account...
[u/mrichter/AliRoot.git] / ITS / AliITSvBeamTestITS04.cxx
index 60543e1cdd5d15d09b7fff3f303e7845449df34e..e2245cf839bca946b956fab373a74222edaeec41 100644 (file)
@@ -3,34 +3,28 @@
 //   integrated ITS test beam of Nov. 04              //
 //  Author: mercedes.lopez.noriega@cern.ch            //
 ////////////////////////////////////////////////////////
+
+#include <TLorentzVector.h>
+
+#include <TGeoManager.h>
+#include <TGeoVolume.h>
+#include <TGeoMatrix.h>
+#include <TGeoPcon.h>
 #include "AliRun.h"
 #include "AliITSvBeamTestITS04.h"
-#include <TBranch.h>
 #include <TClonesArray.h>
 #include <TString.h>
-#include <TTree.h>
 #include "AliITS.h"
-#include "AliITSDetType.h"
-#include "AliITSLoader.h"
-#include "AliITSdigitSPD.h"
-#include "AliITSdigitSDD.h"
-#include "AliITSdigitSSD.h"
-#include "AliITSgeom.h"
-#include "AliITShit.h"
-#include "AliITSresponseSDD.h"
-#include "AliITSresponseSPD.h"
-#include "AliITSresponseSSD.h"
-#include "AliITSsegmentationSDD.h"
-#include "AliITSsegmentationSPD.h"
-#include "AliITSsegmentationSSD.h"
 #include "AliMagF.h"
 #include "TVirtualMC.h"
 #include "AliMC.h"
+#include "AliTrackReference.h"
+#include "AliITSgeom.h"
+#include "AliITShit.h"
 
 const Int_t AliITSvBeamTestITS04::fgkNumberOfSPD = 4;
 const Int_t AliITSvBeamTestITS04::fgkNumberOfSDD = 2;
 const Int_t AliITSvBeamTestITS04::fgkNumberOfSSD = 4;
-
 // Dimension (thickness:Y (beam direction), width:X, length:Z)
 
 const char*    AliITSvBeamTestITS04::fgSPDsensitiveVolName = "ITSspdSensitiv";
@@ -73,40 +67,29 @@ const Double_t AliITSvBeamTestITS04::fgkSSD1y = 80.6;
 
 //===============================================================
 
-#include <Riostream.h>
-
-#include <TLorentzVector.h>
-#include "AliTrackReference.h"
-#include "AliITSDetType.h"
-#include "AliITSgeom.h"
-#include "AliITSgeomSDD.h"
-#include "AliITSgeomSPD.h"
-#include "AliITSgeomSSD.h"
-#include "AliITShit.h"
-#include "AliITSresponseSDD.h"
-#include "AliITSresponseSPD.h"
-#include "AliITSresponseSSD.h"
-#include "AliITSsegmentationSDD.h"
-#include "AliITSsegmentationSPD.h"
-#include "AliITSsegmentationSSD.h"
 
-#include <TGeoManager.h>
-#include <TGeoVolume.h>
-#include <TGeoPcon.h>
 
 ClassImp(AliITSvBeamTestITS04)
     
 //_____________________________________________________________
-AliITSvBeamTestITS04::AliITSvBeamTestITS04() : AliITS()
+  AliITSvBeamTestITS04::AliITSvBeamTestITS04() : 
+AliITS(),              // Base class
+fITSmotherVolume(0),   // Pointer to ITS mother volume.
+fNspd(fgkNumberOfSPD), //Number of SPD modules
+fNsdd(fgkNumberOfSDD), //Number of SDD modules
+fNssd(fgkNumberOfSSD), //Number of SSD modules
+fGeomDetOut(kFALSE),   // Flag to write .det file out
+fGeomDetIn(kFALSE),    // Flag to read geometry file (JC)
+fWrite(),              //! file name to write .det file 
+fRead(),               // file name to read .det file (JC)
+fMajorVersion(kvITS04),// Major Version
+fMinorVersion(1),      // Minor Version
+fIgm(kvITS04)          //! Init geometry object
 {
     //
     // Constructor
     //
-    
-    SetNumberOfSPD(fgkNumberOfSPD);
-    SetNumberOfSDD(fgkNumberOfSDD);
-    SetNumberOfSSD(fgkNumberOfSSD);
-    
+
     fIdN = 3;         
     fIdName    = new TString[fIdN];
     fIdName[0] = fgSPDsensitiveVolName;
@@ -115,27 +98,27 @@ AliITSvBeamTestITS04::AliITSvBeamTestITS04() : AliITS()
     fIdSens    = new Int_t[fIdN];
     for(Int_t i=0; i<fIdN; i++) fIdSens[i] = 0;
     
-    //for writing out geometry
-    fGeomDetOut   = kFALSE; 
-
-    // for reading in geometry (JC)
-    fGeomDetIn = kFALSE;
-
     for(Int_t a=0;a<60;a++) fWrite[a] = '\0';
 }
-
 //_____________________________________________________________
-AliITSvBeamTestITS04::AliITSvBeamTestITS04(const char* name,const char *title)
-    : AliITS(name,title)
+AliITSvBeamTestITS04::AliITSvBeamTestITS04(const char* name,const char *title):
+AliITS(name,title),   // Base class
+fITSmotherVolume(0),   // Pointer to ITS mother volume.
+fNspd(fgkNumberOfSPD), //Number of SPD modules
+fNsdd(fgkNumberOfSDD), //Number of SDD modules
+fNssd(fgkNumberOfSSD), //Number of SSD modules
+fGeomDetOut(kFALSE),   // Flag to write .det file out
+fGeomDetIn(kFALSE),    // Flag to read geometry file (JC)
+fWrite(),              //! file name to write .det file 
+fRead(),               // file name to read .det file (JC)
+fMajorVersion(kvITS04),// Major Version
+fMinorVersion(1),       // Minor Version
+fIgm(kvITS04)          //! Init geometry object
 {
     //
     // Constructor
     //
-    
-    SetNumberOfSPD(fgkNumberOfSPD);
-    SetNumberOfSDD(fgkNumberOfSDD);
-    SetNumberOfSSD(fgkNumberOfSSD);
-    
+
     fIdN = 3;         
     fIdName    = new TString[fIdN];
     fIdName[0] = fgSPDsensitiveVolName;
@@ -143,47 +126,18 @@ AliITSvBeamTestITS04::AliITSvBeamTestITS04(const char* name,const char *title)
     fIdName[2] = fgSSDsensitiveVolName;
     fIdSens    = new Int_t[fIdN];
     for(Int_t i=0; i<fIdN; i++) fIdSens[i] = 0;
-    
-    //for writing out geometry
-    fGeomDetOut   = kFALSE; // Don't write .det file
-
-    // for reading in geometry (JC)
-    fGeomDetIn = kFALSE;
-
     for(Int_t a=0;a<60;a++) fWrite[a] = '\0';    
 }
-
-//______________________________________________________________________
-AliITSvBeamTestITS04::AliITSvBeamTestITS04(const AliITSvBeamTestITS04 &source) :  AliITS(source){
-  //Copy constructor (dummy)
-    if(&source == this) return;
-    Warning("Copy Constructor","Not allowed to copy AliITSvSDD03");
-    return;
-}
-//______________________________________________________________________
-AliITSvBeamTestITS04& AliITSvBeamTestITS04::operator=(const AliITSvBeamTestITS04 &source){
-
-
-    // This class is not to be copied. Function only dummy.
-    if(&source == this) return *this;
-    Warning("= operator","Not allowed to copy AliITSvSDD03");
-    return *this;
-}
-
 //__________________________________________________________________
-AliITSvBeamTestITS04::~AliITSvBeamTestITS04()
-{
+AliITSvBeamTestITS04::~AliITSvBeamTestITS04(){
     //
     // Destructor
     //
 }
-
 //______________________________________________________________________
-void AliITSvBeamTestITS04::CreateMaterials()
-{
+void AliITSvBeamTestITS04::CreateMaterials(){
     // Media defined here should correspond to the one defined in galice.cuts
     // This file is read in (AliMC*) fMCApp::Init() { ReadTransPar(); }
-    
     // Create ITS materials
     Int_t   ifield = gAlice->Field()->Integ();
     Float_t fieldm = gAlice->Field()->Max();
@@ -223,9 +177,12 @@ void AliITSvBeamTestITS04::CreateMaterials()
 }
 
 //______________________________________________________________________
-void AliITSvBeamTestITS04::CreateGeometry()
-{    
-  //Creates geometry
+void AliITSvBeamTestITS04::CreateGeometry(){    
+    //Creates geometry
+    // 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$";
     TGeoManager *geoManager = gGeoManager;
     TGeoVolume *vALIC = geoManager->GetTopVolume();
     
@@ -237,8 +194,19 @@ void AliITSvBeamTestITS04::CreateGeometry()
     sITS->DefineSection(0,-100.0,0.01,100.0); // Units in cms
     sITS->DefineSection(1,+100.0,0.01,100.0);
     
-    TGeoMedium *air = gGeoManager->GetMedium("ITSair");
-    fITSmotherVolume = new TGeoVolume("vITS",sITS,air);
+    TGeoMedium *air = geoManager->GetMedium("ITSair");
+    fITSmotherVolume = new TGeoVolume("ITSV",sITS,air);
+    const Int_t kLength=100;
+    Char_t vstrng[kLength];
+    if(fIgm.WriteVersionString(vstrng,kLength,(AliITSVersion_t)IsVersion(),
+                               fMinorVersion,cvsDate,cvsRevision))
+        fITSmotherVolume->SetTitle(vstrng);
+    else Error("CreateGeometry","Error writing/setting version string");
+    //printf("Title set to %s\n",vstrng);
+    if(vALIC==0) {
+        Error("CreateGeometry","alic=0");
+        return;
+    } // end if
     fITSmotherVolume->SetVisibility(kFALSE);
     vALIC->AddNode(fITSmotherVolume,1,0);
     
@@ -264,20 +232,23 @@ void AliITSvBeamTestITS04::CreateGeometry()
 void AliITSvBeamTestITS04::Init()
 {
     // Initialize the ITS after it has been created.
-    Int_t i;
-    for(i=0;i<20;i++) printf("*");
-    printf( " ITSbeamtest_Init " );
-    for(i=0;i<20;i++) printf("*"); printf("\n");
-
-//    // Create geometry
-//    if(!fGeomDetIn) this->InitAliITSgeom();
-
-    // Initialize AliITS
+    // Inputs:
+    //   none.
+    // Outputs:
+    //   none.
+    // Return:
+    //   none.
+
+    AliDebug(1,Form("Init: Major version %d Minor version %d",fMajorVersion,
+                 fMinorVersion));
+    //
+    UpdateInternalGeometry();
     AliITS::Init();
-    for(i=0;i<40+16;i++) printf("*"); printf("\n");
+    if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
 
+    //
 }
-
+/*
 //______________________________________________________________________
 void AliITSvBeamTestITS04::InitAliITSgeom()
 {    
@@ -293,21 +264,21 @@ void AliITSvBeamTestITS04::InitAliITSgeom()
     nlad[5] = 1; ndet[5] = 2;
 
     Int_t nModTot = fNspd + fNsdd + fNssd;
-    if (fITSgeom) delete fITSgeom;
-    fITSgeom = new AliITSgeom(0,knlayers,nlad,ndet,nModTot);
-    
-    //*** Set default shapes 
+    if (GetITSgeom()) SetITSgeom(0x0);
+    AliITSgeom* geom = new AliITSgeom(0,knlayers,nlad,ndet,nModTot);
+    SetITSgeom(geom);
+    // *** Set default shapes 
     const Float_t kDxyzSPD[] = {fgkSPDwidthSens/2, fgkSPDthickSens/2,fgkSPDlengthSens/2};  
-    if(!(fITSgeom->IsShapeDefined(kSPD)))
-       fITSgeom->ReSetShape(kSPD,new AliITSgeomSPD425Short(3,(Float_t *)kDxyzSPD));
+    if(!(GetITSgeom()->IsShapeDefined(kSPD)))
+       GetITSgeom()->ReSetShape(kSPD,new AliITSgeomSPD425Short(3,(Float_t *)kDxyzSPD));
     
     const Float_t kDxyzSDD[] = {fgkSDDwidthSens/2., fgkSDDthickSens/2.,fgkSDDlengthSens/2.};
-    if(!(fITSgeom->IsShapeDefined(kSDD)))
-       fITSgeom->ReSetShape(kSDD, new AliITSgeomSDD256(3,(Float_t *)kDxyzSDD));
+    if(!(GetITSgeom()->IsShapeDefined(kSDD)))
+       GetITSgeom()->ReSetShape(kSDD, new AliITSgeomSDD256(3,(Float_t *)kDxyzSDD));
     
     const Float_t kDxyzSSD[] = {fgkSSDlengthSens/2, fgkSSDthickSens/2,fgkSSDwidthSens/2};
-    if(!(fITSgeom->IsShapeDefined(kSSD)))
-       fITSgeom->ReSetShape(kSSD,new AliITSgeomSSD75and275(3,(Float_t *)kDxyzSSD));
+    if(!(GetITSgeom()->IsShapeDefined(kSSD)))
+       GetITSgeom()->ReSetShape(kSSD,new AliITSgeomSSD75and275(3,(Float_t *)kDxyzSSD));
     
     // Creating the matrices in AliITSgeom for each sensitive volume
     // (like in AliITSv11GeometrySDD) mln
@@ -332,7 +303,7 @@ void AliITSvBeamTestITS04::InitAliITSgeom()
            Int_t iLad = 1;
            Int_t iLay = 1;
            if (i+1>2) iLay = 2;
-           fITSgeom->CreatMatrix(startMod,iLay,iLad,iDet,kSPD,trans,rot);
+           GetITSgeom()->CreateMatrix(startMod,iLay,iLad,iDet,kSPD,trans,rot);
            startMod++;
        };
     };
@@ -351,7 +322,7 @@ void AliITSvBeamTestITS04::InitAliITSgeom()
            Int_t iDet = 1;
            Int_t iLad = 1;
            Int_t iLay = fNspd-1+i;
-           fITSgeom->CreatMatrix(startMod,iLay,iLad,iDet,kSDD,trans,rot);
+           GetITSgeom()->CreateMatrix(startMod,iLay,iLad,iDet,kSDD,trans,rot);
            startMod++;
        };
     };
@@ -372,14 +343,13 @@ void AliITSvBeamTestITS04::InitAliITSgeom()
            Int_t iLad = 1;
            Int_t iLay = 5;
            if (i+1>2) iLay = 6;
-           fITSgeom->CreatMatrix(startMod,iLay,iLad,iDet,kSSD,trans,rot);
+           GetITSgeom()->CreateMatrix(startMod,iLay,iLad,iDet,kSSD,trans,rot);
            startMod++;
        };
     };
     
     return;
 }
-
 //______________________________________________________________________
 void AliITSvBeamTestITS04::SetDefaults()
 {
@@ -387,7 +357,11 @@ void AliITSvBeamTestITS04::SetDefaults()
     
     const Float_t kconv = 1.0e+04; // convert cm to microns
     
-    AliITSDetType *iDetType;
+    if(!fDetTypeSim) fDetTypeSim = new AliITSDetTypeSim();
+    fDetTypeSim->SetITSgeom(GetITSgeom());
+    fDetTypeSim->ResetCalibrationArray();
+    fDetTypeSim->ResetSegmentation();
     AliITSgeomSPD *s0;
     AliITSgeomSDD *s1;
     AliITSgeomSSD *s2;
@@ -396,20 +370,22 @@ void AliITSvBeamTestITS04::SetDefaults()
 
     // If fGeomDetIn is set true the geometry will
     // be initialised from file (JC)
-    if(fITSgeom!=0) delete fITSgeom;
-    fITSgeom = new AliITSgeom();
-    if(fGeomDetIn) fITSgeom->ReadNewFile(fRead);
+    if(GetITSgeom()!=0) SetITSgeom(0x0);
+    AliITSgeom* geom = new AliITSgeom();
+    SetITSgeom(geom);
+    if(fGeomDetIn) GetITSgeom()->ReadNewFile(fRead);
     if(!fGeomDetIn) this->InitAliITSgeom();
-    if(fGeomDetOut) fITSgeom->WriteNewFile(fWrite);
+    if(fGeomDetOut) GetITSgeom()->WriteNewFile(fWrite);
 
    
     // SPD
-    iDetType=DetType(kSPD);
-    s0 = (AliITSgeomSPD*) fITSgeom->GetShape(kSPD);// Get shape info.
+
+    s0 = (AliITSgeomSPD*) GetITSgeom()->GetShape(kSPD);// Get shape info.
     if (s0) {
-       AliITSresponse *resp0=new AliITSresponseSPD();
-       SetResponseModel(kSPD,resp0);
-       AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD(fITSgeom);
+       AliITSCalibration *resp0=new AliITSCalibrationSPD();
+       SetCalibrationModel(kSPD,resp0);
+
+       AliITSsegmentationSPD *seg0=new AliITSsegmentationSPD();
        seg0->SetDetSize(s0->GetDx()*2.*kconv, // base this on AliITSgeomSPD
                         s0->GetDz()*2.*kconv, // for now.
                         s0->GetDy()*2.*kconv);// x,z,y full width in microns.
@@ -424,57 +400,44 @@ void AliITSvBeamTestITS04::SetDefaults()
        bz[160] = 425.0;                       // Set so that there is no zero pixel size for fNz.
        seg0->SetBinSize(bx,bz);               // Based on AliITSgeomSPD for now.
        SetSegmentationModel(kSPD,seg0);
-       // set digit and raw cluster classes to be used
-       const char *kData0=(iDetType->GetResponseModel())->DataType();
-       if (strstr(kData0,"real")) 
-           iDetType->ClassNames("AliITSdigit","AliITSRawClusterSPD");
-       else iDetType->ClassNames("AliITSdigitSPD","AliITSRawClusterSPD");
-    };
+    }
   
     // SDD
-    iDetType=DetType(kSDD);
-    s1 = (AliITSgeomSDD*) fITSgeom->GetShape(kSDD);// Get shape info.
+   
+    s1 = (AliITSgeomSDD*) GetITSgeom()->GetShape(kSDD);// Get shape info.
     if (s1) {
-       AliITSresponseSDD *resp1=new AliITSresponseSDD("simulated");
-       SetResponseModel(kSDD,resp1);
-       AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD(fITSgeom,resp1);
-       seg1->SetDetSize(s1->GetDx()*kconv, // base this on AliITSgeomSDD
-                        s1->GetDz()*4.*kconv, // for now.
-                        s1->GetDy()*4.*kconv); // x,z,y full width in microns.
-       seg1->SetNPads(256,256);// Use AliITSgeomSDD for now
-       SetSegmentationModel(kSDD,seg1);
-       const char *kData1=(iDetType->GetResponseModel())->DataType();
-       const char *kopt=iDetType->GetResponseModel()->ZeroSuppOption();
-       if((!strstr(kopt,"2D")) && (!strstr(kopt,"1D")) || strstr(kData1,"real") ){
-           iDetType->ClassNames("AliITSdigit","AliITSRawClusterSDD");
-       } else iDetType->ClassNames("AliITSdigitSDD","AliITSRawClusterSDD");
-    };
+      AliITSCalibrationSDD *resp1=new AliITSCalibrationSDD("simulated");
+      SetCalibrationModel(kSDD,resp1);
+      AliITSsegmentationSDD *seg1=new AliITSsegmentationSDD();
+      seg1->SetDetSize(s1->GetDx()*kconv, // base this on AliITSgeomSDD
+                      s1->GetDz()*4.*kconv, // for now.
+                      s1->GetDy()*4.*kconv); // x,z,y full width in microns.
+      seg1->SetDriftSpeed(AliITSresponseSDD::DefaultDriftSpeed());
+      seg1->SetNPads(256,256);// Use AliITSgeomSDD for now
+      SetSegmentationModel(kSDD,seg1);
+    }
     
     // SSD
-    iDetType=DetType(kSSD);
-    s2 = (AliITSgeomSSD*) fITSgeom->GetShape(kSSD);// Get shape info. Do it this way for now.
+    
+    s2 = (AliITSgeomSSD*) GetITSgeom()->GetShape(kSSD);// Get shape info. Do it this way for now.
     if (s2) {
-       AliITSresponse *resp2=new AliITSresponseSSD("simulated");
-       SetResponseModel(kSSD,resp2);
-       AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD(fITSgeom);
-       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.
-       seg2->SetPadSize(95.,0.); // strip x pitch in microns
-       seg2->SetNPads(768,0); // number of strips on each side.
-       seg2->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
-       seg2->SetAnglesLay5(0.0075,0.0275); // strip angels rad P and N side.
-       seg2->SetAnglesLay6(0.0275,0.0075); // strip angels rad P and N side.
-       SetSegmentationModel(kSSD,seg2); 
-       const char *kData2=(iDetType->GetResponseModel())->DataType();
-       if(strstr(kData2,"real") ) iDetType->ClassNames("AliITSdigit","AliITSRawClusterSSD");
-       else iDetType->ClassNames("AliITSdigitSSD","AliITSRawClusterSSD");
-    };
-  
-  if(kNTYPES>3){Warning("SetDefaults","Only the four basic detector types are initialised!");}
+      AliITSCalibration *resp2=new AliITSCalibrationSSD("simulated");
+      SetCalibrationModel(kSSD,resp2);
+
+      AliITSsegmentationSSD *seg2=new AliITSsegmentationSSD();
+      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.
+      seg2->SetPadSize(95.,0.); // strip x pitch in microns
+      seg2->SetNPads(768,0); // number of strips on each side.
+      seg2->SetAngles(0.0075,0.0275); // strip angels rad P and N side.
+      SetSegmentationModel(kSSD,seg2); 
+    }
+    
+  if(fgkNTYPES>3){Warning("SetDefaults","Only the four basic detector types are initialised!");}
   return;
-};
-
+}
+*/
 //______________________________________________________________________
 void AliITSvBeamTestITS04::AddSPDGeometry(TGeoVolume *moth) const
 {
@@ -505,7 +468,7 @@ void AliITSvBeamTestITS04::AddSPDGeometry(TGeoVolume *moth) const
     //draw options
     waferSPD->SetLineColor(4);
     sensVolSPD->SetLineColor(4);
-};
+}
 
 
 //______________________________________________________________________
@@ -533,7 +496,7 @@ void AliITSvBeamTestITS04::AddSDDGeometry(TGeoVolume *moth) const
     //draw options
     waferSDD->SetLineColor(3);
     sensVolSDD->SetLineColor(3);
-};
+}
 
 
 //______________________________________________________________________
@@ -569,7 +532,7 @@ void AliITSvBeamTestITS04::AddSSDGeometry(TGeoVolume *moth) const
     //draw options
     waferSSD->SetLineColor(2);
     sensVolSSD->SetLineColor(2);
-};
+}
 
 //______________________________________________________________________
 void AliITSvBeamTestITS04::StepManager()
@@ -578,78 +541,62 @@ void AliITSvBeamTestITS04::StepManager()
     // creator with the information to be recoreded about that hit.
 
     // "Standard" StepManager. (Similar to AliITSv11) mln
-    Int_t copy, id;
+    Int_t cpy0,mod,status,id,kk;
     TLorentzVector position, momentum;
-    static TLorentzVector position0;
-    static Int_t stat0=0;
-    
-    if(!(this->IsActive())){
-       return;
-    } // end if !Active volume.
+    static AliITShit hit;// Saves on calls to construtors
     
+    if(!(this->IsActive())) return;
     if(!(gMC->TrackCharge())) return;
+    //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;
     
-    id=gMC->CurrentVolID(copy);
+    id=gMC->CurrentVolID(cpy0);
     
     Bool_t sensvol = kFALSE;
-    for(Int_t kk = 0; kk < fIdN; kk++)
-       if(id == fIdSens[kk]) sensvol = kTRUE;
-    
-    if (sensvol && (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
-    
-    Int_t   vol[5];
-    TClonesArray &lhits = *fHits;
+    for(kk=0;kk<fIdN;kk++) if(id == fIdSens[kk]) sensvol = kTRUE;
+    if(!sensvol) return;
+
+    fIgm.DecodeDetector(mod,gGeoManager->GetMother(1)->GetNumber(),1,1,1);
     //
-    // Track status
-    vol[3] = 0;
-    vol[4] = 0;
     // Fill hit structure.
-    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;
-    
-    // Only entering charged tracks
-    if(!(gMC->TrackCharge())) return;
-    
-    if( ((id = gMC->CurrentVolID(copy)) == fIdSens[0]) ||
-       ((id = gMC->CurrentVolID(copy)) == fIdSens[1]) ||
-       ((id = gMC->CurrentVolID(copy)) == fIdSens[2]) )
-    {
-       GetCurrentLayLaddDet(vol[0], vol[2], vol[1]);
-       // vol[2], vol[1]) : in this order because the ladder
-       // index and the det. index are exchanged in the constructor
-       // of AliITShit...
-    } else {
-       return; // not an ITS volume?
-    };
-    
+    //
+    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.
-    new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->GetMCApp()->GetCurrentTrackNumber(),
-                                  vol, gMC->Edep(),gMC->TrackTime(),position,
-                                  position0,momentum);
-    //
-    position0 = position;
-    stat0 = vol[3];
+    //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;
-};
-
+}
+/*
 //______________________________________________________________________
 Int_t AliITSvBeamTestITS04::GetCurrentLayLaddDet(Int_t &lay,Int_t &ladd, Int_t &det) const
 { 
@@ -682,8 +629,8 @@ Int_t AliITSvBeamTestITS04::GetCurrentLayLaddDet(Int_t &lay,Int_t &ladd, Int_t &
     };  
     
     return kTRUE;
-};
-
+}
+*/
 //_____________________________________________________________
 
  Int_t AliITSvBeamTestITS04::GetNumberOfSubDet(const TString& det) const{