/////////////////////////////////////////////////////////////////////////////// // // // Inner Traking System version 5 // // This class contains the base procedures for the Inner Tracking System // // // //Begin_Html /*

The responsible person for this module is Roberto Barbera.

*/
//End_Html
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

#include  

#include 
#include "AliITSv5.h"
#include "AliRun.h"
#include "stdlib.h"
#include "TSystem.h"

ClassImp(AliITSv5)
 
//_____________________________________________________________________________
AliITSv5::AliITSv5() : AliITS() 
{
  //
  // Default constructor for the ITS
  //
}
 
//_____________________________________________________________________________
AliITSv5::AliITSv5(const char *name, const char *title)
  : AliITS(name, title)
{
  //
  // Standard constructor for the ITS
  //
  fEuclidMaterial="$(ALICE_ROOT)/Euclid/ITSgeometry_5.tme";
  fEuclidGeometry="$(ALICE_ROOT)/Euclid/ITSgeometry_5.euc";
}

 
//_____________________________________________________________________________
void AliITSv5::CreateMaterials()
{
  //
  // Read materials for the ITS
  //
  char *filtmp;
  //
  filtmp=gSystem->ExpandPathName(fEuclidMaterial.Data());
  FILE *file = fopen(filtmp,"r");
  delete [] filtmp;
  if(file) {
    fclose(file);
    gAlice->ReadEuclidMedia(fEuclidMaterial.Data(),this);
  } else {
    Error("CreateMaterials"," THE MEDIA FILE %s DOES NOT EXIST !",fEuclidMaterial.Data());
    exit(1);
  }
}

//_____________________________________________________________________________
void AliITSv5::CreateGeometry()
{
  //
  // Read geometry for the ITS
  //

  char topvol[5];
  char *filtmp;
//
  filtmp=gSystem->ExpandPathName(fEuclidGeometry.Data());
  FILE *file = fopen(filtmp,"r");
  delete [] filtmp;
  if(file) {
    fclose(file);
    gAlice->ReadEuclid(fEuclidGeometry.Data(),this,topvol);
  } else {
    Error("CreateGeometry"," THE GEOM FILE %s DOES NOT EXIST !",fEuclidGeometry.Data());
    exit(1);
  }
  //
  // --- 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
  
    if (fEuclidOut) {
      gMC->WriteEuclid("ITSgeometry", "ITSV", 1, 5);
    }
}

//_____________________________________________________________________________
void AliITSv5::Init()
{
  //
  // Initialise the ITS after it has been created
  //
  AliITS::Init();
} 
 
//_____________________________________________________________________________
void AliITSv5::StepManager()
{
  //
  // Called for every step in the ITS
  //
  Int_t         copy, id;
  Int_t         copy1,copy2;
  Float_t       hits[7];
  Int_t         vol[3];
  TLorentzVector position, momentum;
  TClonesArray &lhits = *fHits;
  //
  if(gMC->TrackCharge() && gMC->Edep()) {
    //
    // Only entering charged tracks
    if((id=gMC->CurrentVolID(copy))==fIdSens1) {  
      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==fIdSens2) {
      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==fIdSens3) {
      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==fIdSens4) {
      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==fIdSens5) {
      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==fIdSens6) {
      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;
    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();
    new(lhits[fNhits++]) AliITShit(fIshunt,gAlice->CurrentTrack(),vol,hits);
  }      
}