]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerMI.cxx
Plane efficiency framework (Guiseppe)
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
index f5ed74074e6006d19631bfe6ac81ddee2a78e819..15997d22599b7daee7618b07ec468576274bef53 100644 (file)
@@ -27,9 +27,9 @@
 #include <TMatrixD.h>
 #include <TTree.h>
 #include <TTreeStream.h>
-#include <TTree.h>
 #include <TDatabasePDG.h>
 #include <TString.h>
+#include <TRandom.h>
 
 
 #include "AliESDEvent.h"
 #include "AliHelix.h"
 #include "AliITSRecPoint.h"
 #include "AliITSgeomTGeo.h"
-#include "AliITStrackerMI.h"
 #include "AliITSReconstructor.h"
 #include "AliTrackPointArray.h"
 #include "AliAlignObj.h"
+#include "AliITSClusterParam.h"
+#include "AliCDBManager.h"
+#include "AliCDBEntry.h"
+#include "AliITSCalibrationSPD.h"
+#include "AliITSCalibrationSDD.h"
+#include "AliITSCalibrationSSD.h"
+#include "AliITSPlaneEff.h"
+#include "AliITSPlaneEffSPD.h"
+#include "AliITSPlaneEffSDD.h"
+#include "AliITSPlaneEffSSD.h"
+#include "AliITStrackerMI.h"
 
 ClassImp(AliITStrackerMI)
 
-
-
-AliITStrackerMI::AliITSlayer AliITStrackerMI::fgLayers[kMaxLayer]; // ITS layers
+AliITStrackerMI::AliITSlayer AliITStrackerMI::fgLayers[AliITSgeomTGeo::kNLayers]; // ITS layers
 
 AliITStrackerMI::AliITStrackerMI():AliTracker(),
 fI(0),
@@ -63,14 +71,28 @@ fAfterV0(kFALSE),
 fLastLayerToTrackTo(0),
 fCoefficients(0),
 fEsd(0),
-fUseTGeo(kFALSE),
-fDebugStreamer(0){
+fTrackingPhase("Default"),
+fUseTGeo(3),
+fNtracks(0),
+fxOverX0Pipe(-1.),
+fxTimesRhoPipe(-1.),
+fxOverX0PipeTrks(0),
+fxTimesRhoPipeTrks(0),
+fxOverX0ShieldTrks(0),
+fxTimesRhoShieldTrks(0),
+fxOverX0LayerTrks(0),
+fxTimesRhoLayerTrks(0),
+fDebugStreamer(0),
+fPlaneEff(0) {
   //Default constructor
-  for(Int_t i=0;i<4;i++) fSPDdetzcentre[i]=0.;
+  Int_t i;
+  for(i=0;i<4;i++) fSPDdetzcentre[i]=0.;
+  for(i=0;i<2;i++) {fxOverX0Shield[i]=-1.;fxTimesRhoShield[i]=-1.;}
+  for(i=0;i<6;i++) {fxOverX0Layer[i]=-1.;fxTimesRhoLayer[i]=-1.;}
 }
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITStrackerMI(const Char_t *geom) : AliTracker(),
-fI(kMaxLayer),
+fI(AliITSgeomTGeo::GetNLayers()),
 fBestTrack(),
 fTrackToFollow(),
 fTrackHypothesys(),
@@ -79,11 +101,22 @@ fOriginal(),
 fCurrentEsdTrack(),
 fPass(0),
 fAfterV0(kFALSE),
-fLastLayerToTrackTo(kLastLayerToTrackTo),
+fLastLayerToTrackTo(AliITSRecoParam::GetLastLayerToTrackTo()),
 fCoefficients(0),
 fEsd(0),
-fUseTGeo(kFALSE),
-fDebugStreamer(0){
+fTrackingPhase("Default"),
+fUseTGeo(3),
+fNtracks(0),
+fxOverX0Pipe(-1.),
+fxTimesRhoPipe(-1.),
+fxOverX0PipeTrks(0),
+fxTimesRhoPipeTrks(0),
+fxOverX0ShieldTrks(0),
+fxTimesRhoShieldTrks(0),
+fxOverX0LayerTrks(0),
+fxTimesRhoLayerTrks(0),
+fDebugStreamer(0),
+fPlaneEff(0) {
   //--------------------------------------------------------------------
   //This is the AliITStrackerMI constructor
   //--------------------------------------------------------------------
@@ -94,7 +127,7 @@ fDebugStreamer(0){
   fCoefficients = 0;
   fAfterV0     = kFALSE;
 
-  for (Int_t i=1; i<kMaxLayer+1; i++) {
+  for (Int_t i=1; i<AliITSgeomTGeo::GetNLayers()+1; i++) {
     Int_t nlad=AliITSgeomTGeo::GetNLadders(i);
     Int_t ndet=AliITSgeomTGeo::GetNDetectors(i);
 
@@ -134,7 +167,7 @@ fDebugStreamer(0){
 
   }
 
-  fI=kMaxLayer;
+  fI=AliITSgeomTGeo::GetNLayers();
 
   fPass=0;
   fConstraint[0]=1; fConstraint[1]=0;
@@ -147,8 +180,8 @@ fDebugStreamer(0){
                     AliITSReconstructor::GetRecoParam()->GetSigmaZVdef()}; 
   SetVertex(xyzVtx,ersVtx);
 
-  for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=kLayersNotToSkip[i];
-  fLastLayerToTrackTo=kLastLayerToTrackTo;
+  for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fLayersNotToSkip[i]=AliITSRecoParam::GetLayersNotToSkip(i);
+  fLastLayerToTrackTo=AliITSRecoParam::GetLastLayerToTrackTo();
   for (Int_t i=0;i<100000;i++){
     fBestTrackIndex[i]=0;
   }
@@ -164,11 +197,30 @@ fDebugStreamer(0){
   AliITSgeomTGeo::GetTranslation(1,1,4,tr);
   fSPDdetzcentre[3] = tr[2];
 
-
   fUseTGeo = AliITSReconstructor::GetRecoParam()->GetUseTGeoInTracker();
-  //
+  if(AliITSReconstructor::GetRecoParam()->GetExtendedEtaAcceptance() && fUseTGeo!=1 && fUseTGeo!=3) {
+    AliWarning("fUseTGeo changed to 3 because fExtendedEtaAcceptance is kTRUE");
+    fUseTGeo = 3;
+  }
+
+  for(Int_t i=0;i<2;i++) {fxOverX0Shield[i]=-1.;fxTimesRhoShield[i]=-1.;}
+  for(Int_t i=0;i<6;i++) {fxOverX0Layer[i]=-1.;fxTimesRhoLayer[i]=-1.;}
+  
   fDebugStreamer = new TTreeSRedirector("ITSdebug.root");
 
+  // only for plane efficiency evaluation
+  if (AliITSReconstructor::GetRecoParam()->GetComputePlaneEff()) {
+    for(Int_t ilay=0;ilay<6;ilay++) { 
+      if(AliITSReconstructor::GetRecoParam()->GetLayersToSkip(ilay)) {
+        if (ilay<2) fPlaneEff = new AliITSPlaneEffSPD();
+        else if (ilay<4) fPlaneEff = new AliITSPlaneEffSDD();
+        else fPlaneEff = new AliITSPlaneEffSSD();
+        break; // only one layer type to skip at once
+      }
+    }
+    if(!fPlaneEff->ReadFromCDB()) 
+      {AliWarning("AliITStrackerMI reading of AliITSPlaneEff from OCDB failed") ;}
+  }
 }
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITStrackerMI(const AliITStrackerMI &tracker):AliTracker(tracker),
@@ -184,9 +236,32 @@ fAfterV0(tracker.fAfterV0),
 fLastLayerToTrackTo(tracker.fLastLayerToTrackTo),
 fCoefficients(tracker.fCoefficients),
 fEsd(tracker.fEsd),
+fTrackingPhase(tracker.fTrackingPhase),
 fUseTGeo(tracker.fUseTGeo),
-fDebugStreamer(tracker.fDebugStreamer){
+fNtracks(tracker.fNtracks),
+fxOverX0Pipe(tracker.fxOverX0Pipe),
+fxTimesRhoPipe(tracker.fxTimesRhoPipe),
+fxOverX0PipeTrks(0),
+fxTimesRhoPipeTrks(0),
+fxOverX0ShieldTrks(0),
+fxTimesRhoShieldTrks(0),
+fxOverX0LayerTrks(0),
+fxTimesRhoLayerTrks(0),
+fDebugStreamer(tracker.fDebugStreamer),
+fPlaneEff(tracker.fPlaneEff) {
   //Copy constructor
+  Int_t i;
+  for(i=0;i<4;i++) {
+    fSPDdetzcentre[i]=tracker.fSPDdetzcentre[i];
+  }
+  for(i=0;i<6;i++) {
+    fxOverX0Layer[i]=tracker.fxOverX0Layer[i];
+    fxTimesRhoLayer[i]=tracker.fxTimesRhoLayer[i];
+  }
+  for(i=0;i<2;i++) {
+    fxOverX0Shield[i]=tracker.fxOverX0Shield[i];
+    fxTimesRhoShield[i]=tracker.fxTimesRhoShield[i];
+  }
 }
 //------------------------------------------------------------------------
 AliITStrackerMI & AliITStrackerMI::operator=(const AliITStrackerMI &tracker){
@@ -201,7 +276,8 @@ AliITStrackerMI::~AliITStrackerMI()
   //
   //destructor
   //
-  if (fCoefficients) delete []fCoefficients;
+  if (fCoefficients) delete [] fCoefficients;
+  DeleteTrksMaterialLUT();
   if (fDebugStreamer) {
     //fDebugStreamer->Close();
     delete fDebugStreamer;
@@ -212,7 +288,7 @@ void AliITStrackerMI::SetLayersNotToSkip(Int_t *l) {
   //--------------------------------------------------------------------
   //This function set masks of the layers which must be not skipped
   //--------------------------------------------------------------------
-  for (Int_t i=0; i<kMaxLayer; i++) fLayersNotToSkip[i]=l[i];
+  for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fLayersNotToSkip[i]=l[i];
 }
 //------------------------------------------------------------------------
 Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
@@ -230,7 +306,7 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
 
   Int_t j=0;
   Int_t detector=0;
-  for (Int_t i=0; i<kMaxLayer; i++) {
+  for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) {
     Int_t ndet=fgLayers[i].GetNdetectors();
     Int_t jmax = j + fgLayers[i].GetNladders()*ndet;
     for (; j<jmax; j++) {           
@@ -250,10 +326,10 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
       // add dead zone "virtual" cluster in SPD, if there is a cluster within 
       // zwindow cm from the dead zone      
       if (i<2 && AliITSReconstructor::GetRecoParam()->GetAddVirtualClustersInDeadZone()) {
-       for (Float_t xdead = 0; xdead < kSPDdetxlength; xdead += (i+1.)*AliITSReconstructor::GetRecoParam()->GetXPassDeadZoneHits()) {
+       for (Float_t xdead = 0; xdead < AliITSRecoParam::GetSPDdetxlength(); xdead += (i+1.)*AliITSReconstructor::GetRecoParam()->GetXPassDeadZoneHits()) {
          Int_t lab[4]   = {0,0,0,detector};
          Int_t info[3]  = {0,0,i};
-         Float_t q      = 0.;
+         Float_t q      = 0.; // this identifies virtual clusters
          Float_t hit[5] = {xdead,
                            0.,
                            AliITSReconstructor::GetRecoParam()->GetSigmaXDeadZoneHit2(),
@@ -261,26 +337,26 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
                            q};
          Bool_t local   = kTRUE;
          Double_t zwindow = AliITSReconstructor::GetRecoParam()->GetZWindowDeadZone();
-         hit[1] = fSPDdetzcentre[0]+0.5*kSPDdetzlength;
+         hit[1] = fSPDdetzcentre[0]+0.5*AliITSRecoParam::GetSPDdetzlength();
          if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<zwindow) 
            fgLayers[i].InsertCluster(new AliITSRecPoint(lab,hit,info,local));
-         hit[1] = fSPDdetzcentre[1]-0.5*kSPDdetzlength;
+         hit[1] = fSPDdetzcentre[1]-0.5*AliITSRecoParam::GetSPDdetzlength();
          if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<zwindow) 
            fgLayers[i].InsertCluster(new AliITSRecPoint(lab,hit,info,local));
-         hit[1] = fSPDdetzcentre[1]+0.5*kSPDdetzlength;
+         hit[1] = fSPDdetzcentre[1]+0.5*AliITSRecoParam::GetSPDdetzlength();
          if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<zwindow) 
            fgLayers[i].InsertCluster(new AliITSRecPoint(lab,hit,info,local));
-         hit[1] = fSPDdetzcentre[2]-0.5*kSPDdetzlength;
+         hit[1] = fSPDdetzcentre[2]-0.5*AliITSRecoParam::GetSPDdetzlength();
          if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<zwindow) 
            fgLayers[i].InsertCluster(new AliITSRecPoint(lab,hit,info,local));
-         hit[1] = fSPDdetzcentre[2]+0.5*kSPDdetzlength;
+         hit[1] = fSPDdetzcentre[2]+0.5*AliITSRecoParam::GetSPDdetzlength();
          if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<zwindow) 
            fgLayers[i].InsertCluster(new AliITSRecPoint(lab,hit,info,local));
-         hit[1] = fSPDdetzcentre[3]-0.5*kSPDdetzlength;
+         hit[1] = fSPDdetzcentre[3]-0.5*AliITSRecoParam::GetSPDdetzlength();
          if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<zwindow) 
            fgLayers[i].InsertCluster(new AliITSRecPoint(lab,hit,info,local));
        }
-      }
+      } // "virtual" clusters in SPD
       
     }
     //
@@ -295,41 +371,27 @@ void AliITStrackerMI::UnloadClusters() {
   //--------------------------------------------------------------------
   //This function unloads ITS clusters
   //--------------------------------------------------------------------
-  for (Int_t i=0; i<kMaxLayer; i++) fgLayers[i].ResetClusters();
+  for (Int_t i=0; i<AliITSgeomTGeo::GetNLayers(); i++) fgLayers[i].ResetClusters();
 }
 //------------------------------------------------------------------------
 static Int_t CorrectForTPCtoITSDeadZoneMaterial(AliITStrackMI *t) {
   //--------------------------------------------------------------------
   // Correction for the material between the TPC and the ITS
   //--------------------------------------------------------------------
-  if (t->GetX() > kriw) {                 // inward direction 
-      if (!t->PropagateToTGeo(kriw,1)) return 1;// TPC inner wall
-      if (!t->PropagateToTGeo(krcd,1)) return 1;// TPC central drum
-      if (!t->PropagateToTGeo(krs,1))  return 1;// ITS screen
-      /* without TGeo:
-        if (!t->PropagateTo(kriw,kdiw,kX0iw)) return 1;// TPC inner wall
-        if (TMath::Abs(t->GetY())>kyr) t->CorrectForMaterial(kdr);//rods 
-        if (TMath::Abs(t->GetZ())<kzm) t->CorrectForMaterial(kdm);//membrane 
-        if (!t->PropagateTo(krcd,kdcd,kX0cd)) return 1;// TPC central drum
-        //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
-        //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,dr,x0r); 
-        if (!t->PropagateTo(krs,kds,kX0Air)) return 1;// ITS screen */
-  } else if (t->GetX() < krs) {          // outward direction
-      if (!t->PropagateToTGeo(krs,1))        return 1;// ITS screen
-      if (!t->PropagateToTGeo(krcd,1))       return 1;// TPC central drum
-      if (!t->PropagateToTGeo(kriw+0.001,1)) return 1;// TPC inner wall
-      /* without TGeo
-      if (!t->PropagateTo(krs,-kds,kX0Air)) return 1;
-      //Double_t x,y,z; t->GetGlobalXYZat(rr,x,y,z);
-      //if (TMath::Abs(y)<yyr) t->PropagateTo(rr,-dr,x0r); 
-      if (!t->PropagateTo(krcd,-kdcd,kX0cd)) return 1;// TPC central drum
-      if (!t->PropagateTo(kriw+0.001,-kdiw,kX0iw)) return 1; */
+  if (t->GetX() > AliITSRecoParam::Getriw()) {   // inward direction 
+      if (!t->PropagateToTGeo(AliITSRecoParam::Getriw(),1)) return 0;// TPC inner wall
+      if (!t->PropagateToTGeo(AliITSRecoParam::Getrcd(),1)) return 0;// TPC central drum
+      if (!t->PropagateToTGeo(AliITSRecoParam::Getrs(),1))  return 0;// ITS screen
+  } else if (t->GetX() < AliITSRecoParam::Getrs()) {  // outward direction
+      if (!t->PropagateToTGeo(AliITSRecoParam::Getrs(),1))        return 0;// ITS screen
+      if (!t->PropagateToTGeo(AliITSRecoParam::Getrcd(),1))       return 0;// TPC central drum
+      if (!t->PropagateToTGeo(AliITSRecoParam::Getriw()+0.001,1)) return 0;// TPC inner wall
   } else {
     Error("CorrectForTPCtoITSDeadZoneMaterial","Track is already in the dead zone !");
-    return 1;
+    return 0;
   }
   
-  return 0;
+  return 1;
 }
 //------------------------------------------------------------------------
 Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
@@ -337,6 +399,8 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   // This functions reconstructs ITS tracks
   // The clusters must be already loaded !
   //--------------------------------------------------------------------
+  fTrackingPhase="Clusters2Tracks";
+
   TObjArray itsTracks(15000);
   fOriginal.Clear();
   fEsd = event;         // store pointer to the esd 
@@ -373,6 +437,8 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
       }
       t->GetDZ(GetX(),GetY(),GetZ(),t->GetDP());              //I.B.
       Double_t vdist = TMath::Sqrt(t->GetD(0)*t->GetD(0)+t->GetD(1)*t->GetD(1));
+
+
       // look at the ESD mass hypothesys !
       if (t->GetMass()<0.9*pimass) t->SetMass(pimass); 
       // write expected q
@@ -384,8 +450,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        if (TMath::Abs(t->GetD(0))>AliITSReconstructor::GetRecoParam()->GetMaxDForProlongation()) {
          delete t;
          continue;
-       }
-       
+       }       
        if (TMath::Abs(vdist)>AliITSReconstructor::GetRecoParam()->GetMaxDZForProlongation()) {
          delete t;
          continue;
@@ -394,10 +459,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
          delete t;
          continue;
        }
-       
-       if (CorrectForTPCtoITSDeadZoneMaterial(t)!=0) {
-         //Warning("Clusters2Tracks",
-         //        "failed to correct for the material in the dead zone !\n");
+       if (!CorrectForTPCtoITSDeadZoneMaterial(t)) {
          delete t;
          continue;
        }
@@ -414,14 +476,14 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   fTrackHypothesys.Expand(nentr);
   fBestHypothesys.Expand(nentr);
   MakeCoefficients(nentr);
+  if(fUseTGeo==3 || fUseTGeo==4) MakeTrksMaterialLUT(event->GetNumberOfTracks());
   Int_t ntrk=0;
   // THE TWO TRACKING PASSES
   for (fPass=0; fPass<2; fPass++) {
      Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
-     for (Int_t i=0; i<nentr; i++) {
-       //cerr<<fPass<<"    "<<i<<'\r';
-       fCurrentEsdTrack = i;
-       AliITStrackMI *t=(AliITStrackMI*)itsTracks.UncheckedAt(i);
+     for (fCurrentEsdTrack=0; fCurrentEsdTrack<nentr; fCurrentEsdTrack++) {
+       //cerr<<fPass<<"    "<<fCurrentEsdTrack<<'\n';
+       AliITStrackMI *t=(AliITStrackMI*)itsTracks.UncheckedAt(fCurrentEsdTrack);
        if (t==0) continue;              //this track has been already tracked
        if (t->GetReconstructed()&&(t->GetNUsed()<1.5)) continue;  //this track was  already  "succesfully" reconstructed
        Float_t dz[2]; t->GetDZ(GetX(),GetY(),GetZ(),dz);              //I.B.
@@ -434,11 +496,12 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        fI = 6;
        ResetTrackToFollow(*t);
        ResetBestTrack();
-       FollowProlongationTree(t,i,fConstraint[fPass]);
+
+       FollowProlongationTree(t,fCurrentEsdTrack,fConstraint[fPass]);
 
        SortTrackHypothesys(fCurrentEsdTrack,20,0);  //MI change
        //
-       AliITStrackMI * besttrack = GetBestHypothesys(fCurrentEsdTrack,t,15);
+       AliITStrackMI *besttrack = GetBestHypothesys(fCurrentEsdTrack,t,15);
        if (!besttrack) continue;
        besttrack->SetLabel(tpcLabel);
        //       besttrack->CookdEdx();
@@ -464,7 +527,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   itsTracks.Delete();
   //
   Int_t entries = fTrackHypothesys.GetEntriesFast();
-  for (Int_t ientry=0;ientry<entries;ientry++){
+  for (Int_t ientry=0; ientry<entries; ientry++) {
     TObjArray * array =(TObjArray*)fTrackHypothesys.UncheckedAt(ientry);
     if (array) array->Delete();
     delete fTrackHypothesys.RemoveAt(ientry); 
@@ -475,7 +538,11 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   fOriginal.Clear();
   delete [] fCoefficients;
   fCoefficients=0;
+  DeleteTrksMaterialLUT();
+
   Info("Clusters2Tracks","Number of prolonged tracks: %d\n",ntrk);
+
+  fTrackingPhase="Default";
   
   return 0;
 }
@@ -485,6 +552,7 @@ Int_t AliITStrackerMI::PropagateBack(AliESDEvent *event) {
   // This functions propagates reconstructed ITS tracks back
   // The clusters must be loaded !
   //--------------------------------------------------------------------
+  fTrackingPhase="PropagateBack";
   Int_t nentr=event->GetNumberOfTracks();
   Info("PropagateBack", "Number of ESD tracks: %d\n", nentr);
 
@@ -509,27 +577,16 @@ Int_t AliITStrackerMI::PropagateBack(AliESDEvent *event) {
 
      // propagate to vertex [SR, GSI 17.02.2003]
      // Start Time measurement [SR, GSI 17.02.2003], corrected by I.Belikov
-     if(fUseTGeo) {
-       if (fTrackToFollow.PropagateToTGeo(krInsidePipe,1)) {
-        if (fTrackToFollow.PropagateToVertex(event->GetVertex())) {
-          fTrackToFollow.StartTimeIntegral();
-        }
-        fTrackToFollow.PropagateToTGeo(krOutsidePipe,1);
-       }
-     } else {
-       if (fTrackToFollow.PropagateTo(krInsidePipe,kdPipe,kX0Be)) {
-        if (fTrackToFollow.PropagateToVertex(event->GetVertex())) {
-          fTrackToFollow.StartTimeIntegral();
-        }
-        fTrackToFollow.PropagateTo(krOutsidePipe,-kdPipe,kX0Be);
-       }
+     if (CorrectForPipeMaterial(&fTrackToFollow,"inward")) {
+       if (fTrackToFollow.PropagateToVertex(event->GetVertex()))
+        fTrackToFollow.StartTimeIntegral();
+       // from vertex to outside pipe
+       CorrectForPipeMaterial(&fTrackToFollow,"outward");
      }
 
      fTrackToFollow.ResetCovariance(10.); fTrackToFollow.ResetClusters();
-     if (RefitAt(krInsideITSscreen,&fTrackToFollow,t)) {
-        if (CorrectForTPCtoITSDeadZoneMaterial(&fTrackToFollow)!=0) {
-          //Warning("PropagateBack",
-          //        "failed to correct for the material in the dead zone !\n");
+     if (RefitAt(AliITSRecoParam::GetrInsideITSscreen(),&fTrackToFollow,t)) {
+        if (!CorrectForTPCtoITSDeadZoneMaterial(&fTrackToFollow)) {
           delete t;
           continue;
         }
@@ -545,6 +602,8 @@ Int_t AliITStrackerMI::PropagateBack(AliESDEvent *event) {
 
   Info("PropagateBack","Number of back propagated ITS tracks: %d\n",ntrk);
 
+  fTrackingPhase="Default";
+
   return 0;
 }
 //------------------------------------------------------------------------
@@ -554,6 +613,7 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
   // "inward propagated" TPC tracks
   // The clusters must be loaded !
   //--------------------------------------------------------------------
+  fTrackingPhase="RefitInward";
   if(AliITSReconstructor::GetRecoParam()->GetFindV0s()) RefitV02(event);
   Int_t nentr=event->GetNumberOfTracks();
   Info("RefitInward", "Number of ESD tracks: %d\n", nentr);
@@ -576,9 +636,7 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
         continue;
     }
     t->SetExpQ(TMath::Max(0.8*t->GetESDtrack()->GetTPCsignal(),30.));
-    if (CorrectForTPCtoITSDeadZoneMaterial(t)!=0) {
-      //Warning("RefitInward",
-      //         "failed to correct for the material in the dead zone !\n");
+    if (!CorrectForTPCtoITSDeadZoneMaterial(t)) {
        delete t;
        continue;
     }
@@ -590,7 +648,8 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
       fTrackToFollow.ResetCovariance(10.);
 
     //Refitting...
-    if (RefitAt(krInsideSPD1, &fTrackToFollow, t,kTRUE)) {
+    Bool_t pe=AliITSReconstructor::GetRecoParam()->GetComputePlaneEff();
+    if (RefitAt(AliITSRecoParam::GetrInsideSPD1(),&fTrackToFollow,t,kTRUE,pe)) {
        fTrackToFollow.SetLabel(t->GetLabel());
        //       fTrackToFollow.CookdEdx();
        CookdEdx(&fTrackToFollow);
@@ -598,27 +657,24 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
        CookLabel(&fTrackToFollow,0.0); //For comparison only
 
        //The beam pipe
-       Bool_t okToPipe;
-       if(fUseTGeo) { 
-        okToPipe = fTrackToFollow.PropagateToTGeo(krInsidePipe,1); 
-       } else {
-        okToPipe = fTrackToFollow.PropagateTo(krInsidePipe,kdPipe,kX0Be);
-       }
-       if(okToPipe) {
+       if (CorrectForPipeMaterial(&fTrackToFollow,"inward")) {
+        fTrackToFollow.UpdateESDtrack(AliESDtrack::kITSrefit);
         AliESDtrack  *esdTrack =fTrackToFollow.GetESDtrack();
-        esdTrack->UpdateTrackParams(&fTrackToFollow,AliESDtrack::kITSrefit);
+        //printf("                                       %d\n",esdTrack->GetITSModuleIndex(0));
+        //esdTrack->UpdateTrackParams(&fTrackToFollow,AliESDtrack::kITSrefit); //original line
         Float_t r[3]={0.,0.,0.};
         Double_t maxD=3.;
         esdTrack->RelateToVertex(event->GetVertex(),GetBz(r),maxD);
         ntrk++;
        }
-
     }
     delete t;
   }
 
   Info("RefitInward","Number of refitted tracks: %d\n",ntrk);
 
+  fTrackingPhase="Default";
+
   return 0;
 }
 //------------------------------------------------------------------------
@@ -703,8 +759,7 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   Float_t expQ = TMath::Max(0.8*t->GetTPCsignal(),30.);
 
   Float_t errlocalx,errlocalz;
-  GetError(l,cl,tgl,tgphi,expQ,errlocalx,errlocalz);
-
+  AliITSClusterParam::GetError(l,cl,tgl,tgphi,expQ,errlocalx,errlocalz);
 
   Float_t xyz[3];
   Float_t cov[6];
@@ -754,6 +809,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
   Double_t xyzVtx[]={GetX(),GetY(),GetZ()};
   Double_t ersVtx[]={GetSigmaX(),GetSigmaY(),GetSigmaZ()};
 
+
   AliESDtrack * esd = otrack->GetESDtrack();
   if (esd->GetV0Index(0)>0) {
     // TEMPORARY SOLLUTION: map V0 indexes to point to proper track
@@ -795,19 +851,22 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
   new (&(tracks[6][0])) AliITStrackMI(*otrack);
   ntracks[6]=1;
   for (Int_t i=0;i<7;i++) nindexes[i][0]=0;
+  Int_t modstatus = 1; // found 
+  Float_t xloc,zloc;
   // 
   //
   // follow prolongations
-  for (Int_t ilayer=5;ilayer>=0;ilayer--){
+  for (Int_t ilayer=5; ilayer>=0; ilayer--) {
+    fI = ilayer;
     //
-    AliITSlayer &layer=fgLayers[ilayer]; 
-    Double_t r=layer.GetR();
+    AliITSlayer &layer=fgLayers[ilayer];
+    Double_t r = layer.GetR(); 
     ntracks[ilayer]=0;
     //
     //
-   Int_t nskipped=0;
+    Int_t nskipped=0;
     Float_t nused =0;
-    for (Int_t itrack =0;itrack<ntracks[ilayer+1];itrack++){
+    for (Int_t itrack =0; itrack<ntracks[ilayer+1]; itrack++) {
       //set current track
       if (ntracks[ilayer]>=100) break;  
       if (tracks[ilayer+1][nindexes[ilayer+1][itrack]].GetNSkipped()>0) nskipped++;
@@ -820,58 +879,52 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       new(&currenttrack1)  AliITStrackMI(tracks[ilayer+1][nindexes[ilayer+1][itrack]]);
   
       // material between SSD and SDD, SDD and SPD
-      if (ilayer==3 || ilayer==1) {
-       Double_t rshield,dshield,x0shield;
-       if (ilayer==3) { // SDDouter
-         rshield=0.5*(fgLayers[ilayer+1].GetR() + r);
-         dshield=kdshieldSDD;
-         x0shield=kX0shieldSDD;
-       } else {        // SPDouter
-         rshield=krshieldSPD; 
-         dshield=kdshieldSPD; 
-         x0shield=kX0shieldSPD;
-       }
-       if (fUseTGeo) {
-         if (!currenttrack1.PropagateToTGeo(rshield,1)) continue;
-       } else {
-         if (!currenttrack1.PropagateTo(rshield,dshield,x0shield)) continue;
-       }
-      }
+      if (ilayer==3) 
+       if(!CorrectForShieldMaterial(&currenttrack1,"SDD","inward")) continue;
+      if (ilayer==1) 
+       if(!CorrectForShieldMaterial(&currenttrack1,"SPD","inward")) continue;
 
+      // detector number
       Double_t phi,z;
       if (!currenttrack1.GetPhiZat(r,phi,z)) continue;
-
       Int_t idet=layer.FindDetectorIndex(phi,z);
-      if (idet<0) continue;
-      
-      Double_t trackGlobXYZ1[3],trackGlobXYZ2[3];
+
+      Double_t trackGlobXYZ1[3];
       currenttrack1.GetXYZ(trackGlobXYZ1);
 
-      //propagate to the intersection
+      // Get the budget to the primary vertex for the current track being prolonged
+      Double_t budgetToPrimVertex = GetEffectiveThickness();
+
+      // check if we allow a prolongation without point
+      Int_t skip = CheckSkipLayer(&currenttrack1,ilayer,idet);
+      if (skip) {
+       AliITStrackMI* vtrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(currenttrack1);
+       // propagate to the layer radius
+       Double_t xToGo; vtrack->GetLocalXat(r,xToGo);
+       vtrack->AliExternalTrackParam::PropagateTo(xToGo,GetBz());
+       // apply correction for material of the current layer
+       CorrectForLayerMaterial(vtrack,ilayer,trackGlobXYZ1,"inward");
+       vtrack->SetNDeadZone(vtrack->GetNDeadZone()+1);
+       vtrack->SetClIndex(ilayer,0);
+       modstatus = (skip==1 ? 3 : 4); // skipped : out in z
+       LocalModuleCoord(ilayer,idet,vtrack,xloc,zloc); // local module coords
+       vtrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+       if(constrain) vtrack->Improve(budgetToPrimVertex,xyzVtx,ersVtx);
+       ntracks[ilayer]++;
+       continue;
+      }
+
+      // track outside layer acceptance in z
+      if (idet<0) continue;
+      
+      //propagate to the intersection with the detector plane
       const AliITSdetector &det=layer.GetDetector(idet);
       new(&currenttrack2)  AliITStrackMI(currenttrack1);
       if (!currenttrack1.Propagate(det.GetPhi(),det.GetR())) continue;
+      LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc); // local module coords
       currenttrack2.Propagate(det.GetPhi(),det.GetR());
       currenttrack1.SetDetectorIndex(idet);
       currenttrack2.SetDetectorIndex(idet);
-      
-      // Get the budget to the primary vertex and between the two layers
-      // for the current track being prolonged (before searching for clusters
-      // on this layer)
-      fI = ilayer;
-      Double_t budgetToPrimVertex = 0.;
-      if (fUseTGeo) {
-       if (!currenttrack2.MeanBudgetToPrimVertex(xyzVtx,2,budgetToPrimVertex))
-         budgetToPrimVertex = GetEffectiveThickness(0,0);
-      } else {
-         budgetToPrimVertex = GetEffectiveThickness(0,0);
-      }
-      Double_t mparam[7];
-      currenttrack2.GetXYZ(trackGlobXYZ2);
-      if(fUseTGeo) {
-       AliTracker::MeanMaterialBudget(trackGlobXYZ1,trackGlobXYZ2,mparam);
-      }
-
 
       //***************
       // DEFINITION OF SEARCH ROAD FOR CLUSTERS SELECTION
@@ -888,23 +941,26 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
                    AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
       
       // track at boundary between detectors, enlarge road
-      if ( (currenttrack1.GetY()-dy < det.GetYmin()+kBoundaryWidth) || 
-          (currenttrack1.GetY()+dy > det.GetYmax()-kBoundaryWidth) || 
-          (currenttrack1.GetZ()-dz < det.GetZmin()+kBoundaryWidth) ||
-          (currenttrack1.GetZ()+dz > det.GetZmax()-kBoundaryWidth) ) {
+      Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidth();
+      if ( (currenttrack1.GetY()-dy < det.GetYmin()+boundaryWidth) || 
+          (currenttrack1.GetY()+dy > det.GetYmax()-boundaryWidth) || 
+          (currenttrack1.GetZ()-dz < det.GetZmin()+boundaryWidth) ||
+          (currenttrack1.GetZ()+dz > det.GetZmax()-boundaryWidth) ) {
        Float_t tgl = TMath::Abs(currenttrack1.GetTgl());
        if (tgl > 1.) tgl=1.;
-       dz = TMath::Sqrt(dz*dz+kDeltaXNeighbDets*kDeltaXNeighbDets*tgl*tgl);
+       Double_t deltaXNeighbDets=AliITSRecoParam::GetDeltaXNeighbDets();
+       dz = TMath::Sqrt(dz*dz+deltaXNeighbDets*deltaXNeighbDets*tgl*tgl);
        Float_t snp = TMath::Abs(currenttrack1.GetSnp());
        if (snp > AliITSReconstructor::GetRecoParam()->GetMaxSnp()) continue;
-       dy = TMath::Sqrt(dy*dy+kDeltaXNeighbDets*kDeltaXNeighbDets*snp*snp);
+       dy = TMath::Sqrt(dy*dy+deltaXNeighbDets*deltaXNeighbDets*snp*snp);
       } // boundary
       
-      // road in global (rphi,z)
+      // road in global (rphi,z) [i.e. in tracking ref. system]
       Double_t zmin = currenttrack1.GetZ() - dz; 
       Double_t zmax = currenttrack1.GetZ() + dz;
       Double_t ymin = currenttrack1.GetY() + r*det.GetPhi() - dy;
       Double_t ymax = currenttrack1.GetY() + r*det.GetPhi() + dy;
+
       // select clusters in road
       layer.SelectClusters(zmin,zmax,ymin,ymax); 
       //********************
@@ -934,13 +990,55 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       const AliITSRecPoint *cl=0; 
       Int_t clidx=-1;
       Double_t chi2trkcl=AliITSReconstructor::GetRecoParam()->GetMaxChi2(); // init with big value
-      Int_t deadzone=0;
+      Bool_t deadzoneSPD=kFALSE;
       currenttrack = &currenttrack1;
-      // loop over selected clusters
+
+      // check if the road contains a dead zone 
+      Int_t dead = CheckDeadZone(ilayer,idet,zmin,zmax); 
+      // create a prolongation without clusters (check also if there are no clusters in the road)
+      if (dead || 
+         ((layer.GetNextCluster(clidx,kTRUE))==0 && 
+          AliITSReconstructor::GetRecoParam()->GetAllowProlongationWithEmptyRoad())) {
+       AliITStrackMI * updatetrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(*currenttrack);
+       updatetrack->SetClIndex(ilayer,0);
+       if (dead==0) {
+         modstatus = 5; // no cls in road
+       } else if (dead==1) {
+         modstatus = 7; // holes in z in SPD
+       } else if (dead==2) {
+         modstatus = 2; // dead from OCDB
+       }
+       updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+       // apply correction for material of the current layer
+       CorrectForLayerMaterial(updatetrack,ilayer,trackGlobXYZ1,"inward");
+       if (constrain) { // apply vertex constrain
+         updatetrack->SetConstrain(constrain);
+         Bool_t isPrim = kTRUE;
+         if (ilayer<4) { // check that it's close to the vertex
+           updatetrack->GetDZ(GetX(),GetY(),GetZ(),updatetrack->GetDP()); //I.B.
+           if (TMath::Abs(updatetrack->GetD(0)/(1.+ilayer)) > // y
+               AliITSReconstructor::GetRecoParam()->GetMaxDZforPrimTrk() || 
+               TMath::Abs(updatetrack->GetD(1)/(1.+ilayer)) > // z
+               AliITSReconstructor::GetRecoParam()->GetMaxDZforPrimTrk()) isPrim=kFALSE;
+         }
+         if (isPrim) updatetrack->Improve(budgetToPrimVertex,xyzVtx,ersVtx);
+       }
+       if (dead) {
+         updatetrack->SetNDeadZone(updatetrack->GetNDeadZone()+1);
+         if (dead==1) { // dead zone at z=0,+-7cm in SPD
+           updatetrack->SetDeadZoneProbability(GetSPDDeadZoneProbability(updatetrack->GetZ(),TMath::Sqrt(updatetrack->GetSigmaZ2())));
+           deadzoneSPD=kTRUE;
+         }
+       }
+       ntracks[ilayer]++;
+      }
+
+      clidx=-1;
+      // loop over clusters in the road
       while ((cl=layer.GetNextCluster(clidx))!=0) { 
        if (ntracks[ilayer]>95) break; //space for skipped clusters  
        Bool_t changedet =kFALSE;  
-       if (cl->GetQ()==0 && (deadzone==1)) continue;
+       if (cl->GetQ()==0 && deadzoneSPD==kTRUE) continue;
        Int_t idet=cl->GetDetectorIndex();
 
        if (currenttrack->GetDetectorIndex()==idet) { // track already on the cluster's detector
@@ -966,48 +1064,43 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
            continue;
          }
          currenttrack->SetDetectorIndex(idet);
-         // Get again the budget to the primary vertex and between the two 
-         // layers for the current track being prolonged, if had to change detector 
-         if (fUseTGeo) {
-           if (!currenttrack->MeanBudgetToPrimVertex(xyzVtx,2,budgetToPrimVertex))
-             budgetToPrimVertex = GetEffectiveThickness(0,0);
-           currenttrack->GetXYZ(trackGlobXYZ2);
-           AliTracker::MeanMaterialBudget(trackGlobXYZ1,trackGlobXYZ2,mparam);
-         } else {
-           budgetToPrimVertex = GetEffectiveThickness(0,0);
-         }
+         // Get again the budget to the primary vertex 
+         // for the current track being prolonged, if had to change detector 
+         //budgetToPrimVertex = GetEffectiveThickness();// not needed at the moment because anyway we take a mean material for this correction
        }
 
        // calculate track-clusters chi2
        chi2trkcl = GetPredictedChi2MI(currenttrack,cl,ilayer); 
        // chi2 cut
        if (chi2trkcl < AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)) {
-         if (cl->GetQ()==0) deadzone=1;            // take dead zone only once   
+         if (cl->GetQ()==0) deadzoneSPD=kTRUE; // only 1 prolongation with virtual cluster       
          if (ntracks[ilayer]>=100) continue;
          AliITStrackMI * updatetrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(*currenttrack);
          updatetrack->SetClIndex(ilayer,0);
          if (changedet) new (&currenttrack2) AliITStrackMI(backuptrack);
-         
-         if (cl->GetQ()!=0) {
+
+         if (cl->GetQ()!=0) { // real cluster
            if (!UpdateMI(updatetrack,cl,chi2trkcl,(ilayer<<28)+clidx)) continue; 
            updatetrack->SetSampledEdx(cl->GetQ(),updatetrack->GetNumberOfClusters()-1); //b.b.
-         } else { // cluster in dead zone
+           modstatus = 1; // found
+         } else {             // virtual cluster in dead zone
            updatetrack->SetNDeadZone(updatetrack->GetNDeadZone()+1);
-           updatetrack->SetDeadZoneProbability(GetDeadZoneProbability(updatetrack->GetZ(),TMath::Sqrt(updatetrack->GetSigmaZ2())));
+           updatetrack->SetDeadZoneProbability(GetSPDDeadZoneProbability(updatetrack->GetZ(),TMath::Sqrt(updatetrack->GetSigmaZ2())));
+           modstatus = 7; // holes in z in SPD
          }
-         if (cl->IsUsed()) updatetrack->IncrementNUsed();
 
-         // apply correction for material of the current layer
-         if(fUseTGeo) { 
-           Double_t d,lengthTimesMeanDensity;
-           d=mparam[1]; 
-           lengthTimesMeanDensity=mparam[0]*mparam[4]; 
-           updatetrack->CorrectForMeanMaterial(d,lengthTimesMeanDensity);        
+         if (changedet) {
+           Float_t xlocnewdet,zlocnewdet;
+           LocalModuleCoord(ilayer,idet,updatetrack,xlocnewdet,zlocnewdet); // local module coords
+           updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xlocnewdet,zlocnewdet);
          } else {
-           Double_t d,x0;
-           d=layer.GetThickness(updatetrack->GetY(),updatetrack->GetZ(),x0);
-           updatetrack->CorrectForMaterial(d,x0);        
+           updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
          }
+         if (cl->IsUsed()) updatetrack->IncrementNUsed();
+
+         // apply correction for material of the current layer
+         CorrectForLayerMaterial(updatetrack,ilayer,trackGlobXYZ1,"inward");
+
          if (constrain) { // apply vertex constrain
            updatetrack->SetConstrain(constrain);
            Bool_t isPrim = kTRUE;
@@ -1022,25 +1115,36 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          } //apply vertex constrain              
          ntracks[ilayer]++;
        }  // create new hypothesis
-      } // loop over possible cluster prolongation      
-      if (constrain&&itrack<2&&currenttrack1.GetNSkipped()==0 && deadzone==0&&ntracks[ilayer]<100) {   
+      } // loop over possible prolongations 
+     
+      // allow one prolongation without clusters
+      if (constrain && itrack<=1 && currenttrack1.GetNSkipped()==0 && deadzoneSPD==kFALSE && ntracks[ilayer]<100) {
        AliITStrackMI* vtrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(currenttrack1);
+       // apply correction for material of the current layer
+       CorrectForLayerMaterial(vtrack,ilayer,trackGlobXYZ1,"inward");
        vtrack->SetClIndex(ilayer,0);
+       modstatus = 3; // skipped 
+       vtrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
        vtrack->Improve(budgetToPrimVertex,xyzVtx,ersVtx);
        vtrack->IncrementNSkipped();
        ntracks[ilayer]++;
       }
 
-      if (constrain&&itrack<1&&TMath::Abs(currenttrack1.GetTgl())>1.1) {  //big theta - for low flux
+      // allow one prolongation without clusters for tracks with |tgl|>1.1
+      if (constrain && itrack==0 && TMath::Abs(currenttrack1.GetTgl())>1.1) {  //big theta - for low flux
        AliITStrackMI* vtrack = new (&tracks[ilayer][ntracks[ilayer]]) AliITStrackMI(currenttrack1);
+       // apply correction for material of the current layer
+       CorrectForLayerMaterial(vtrack,ilayer,trackGlobXYZ1,"inward");
        vtrack->SetClIndex(ilayer,0);
+       modstatus = 3; // skipped
+       vtrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
        vtrack->Improve(budgetToPrimVertex,xyzVtx,ersVtx);
        vtrack->SetNDeadZone(vtrack->GetNDeadZone()+1);
        ntracks[ilayer]++;
       }
      
       
-    }
+    } // loop over tracks in layer ilayer+1
 
     //loop over track candidates for the current layer
     //
@@ -1071,7 +1175,6 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
     if (ntracks[ilayer]>90) ntracks[ilayer]=90; 
   } // end loop over layers
 
-  //printf("%d\t%d\t%d\t%d\t%d\t%d\n",ntracks[0],ntracks[1],ntracks[2],ntracks[3],ntracks[4],ntracks[5]);
 
   //
   // Now select tracks to be kept
@@ -1083,7 +1186,9 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
     AliITStrackMI & track= tracks[0][nindexes[0][i]];
     if (track.GetNumberOfClusters()<2) continue;
     if (!constrain && track.GetNormChi2(0) >
-       AliITSReconstructor::GetRecoParam()->GetMaxNormChi2NonCForHypothesis()) continue;
+       AliITSReconstructor::GetRecoParam()->GetMaxNormChi2NonCForHypothesis()) {
+      continue;
+    }
     AddTrackHypothesys(new AliITStrackMI(track), esdindex);
   }
 
@@ -1104,7 +1209,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
     AddTrackHypothesys(new AliITStrackMI(track), esdindex);
   }
 
-  // tracks that reack layer 2 (SDD inner), only during non-constrained pass
+  // tracks that reach layer 2 (SDD inner), only during non-constrained pass
   if (!constrain){  
     for (Int_t i=0;i<TMath::Min(2,ntracks[2]);i++) {
       AliITStrackMI & track= tracks[2][nindexes[2][i]];
@@ -1223,7 +1328,7 @@ fRoad(0){
   //--------------------------------------------------------------------
   //default AliITSlayer constructor
   //--------------------------------------------------------------------
-  for (Int_t i=0; i<kMaxClusterPerLayer;i++) {
+  for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
     fClusterWeight[i]=0;
     fClusterTracks[0][i]=-1;
     fClusterTracks[1][i]=-1;
@@ -1299,7 +1404,7 @@ AliITStrackerMI::AliITSlayer::~AliITSlayer() {
   //--------------------------------------------------------------------
   delete[] fDetectors;
   for (Int_t i=0; i<fN; i++) delete fClusters[i];
-  for (Int_t i=0; i<kMaxClusterPerLayer;i++) {
+  for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
     fClusterWeight[i]=0;
     fClusterTracks[0][i]=-1;
     fClusterTracks[1][i]=-1;
@@ -1313,7 +1418,7 @@ void AliITStrackerMI::AliITSlayer::ResetClusters() {
   // This function removes loaded clusters
   //--------------------------------------------------------------------
   for (Int_t i=0; i<fN; i++) delete fClusters[i];
-  for (Int_t i=0; i<kMaxClusterPerLayer;i++){
+  for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++){
     fClusterWeight[i]=0;
     fClusterTracks[0][i]=-1;
     fClusterTracks[1][i]=-1;
@@ -1329,7 +1434,7 @@ void AliITStrackerMI::AliITSlayer::ResetWeights() {
   //--------------------------------------------------------------------
   // This function reset weights of the clusters
   //--------------------------------------------------------------------
-  for (Int_t i=0; i<kMaxClusterPerLayer;i++) {
+  for (Int_t i=0; i<AliITSRecoParam::GetMaxClusterPerLayer(); i++) {
     fClusterWeight[i]=0;
     fClusterTracks[0][i]=-1;
     fClusterTracks[1][i]=-1;
@@ -1358,7 +1463,7 @@ Int_t AliITStrackerMI::AliITSlayer::InsertCluster(AliITSRecPoint *cl) {
   //--------------------------------------------------------------------
   //This function adds a cluster to this layer
   //--------------------------------------------------------------------
-  if (fN==kMaxClusterPerLayer) {
+  if (fN==AliITSRecoParam::GetMaxClusterPerLayer()) {
     ::Error("InsertCluster","Too many clusters !\n");
     return 1;
   }
@@ -1430,7 +1535,7 @@ void  AliITStrackerMI::AliITSlayer::SortClusters()
       Float_t curY = fY[i]+irot*TMath::TwoPi()*fR; 
       // slice 5
       for (Int_t slice=0; slice<6;slice++){
-       if (fBy5[slice][0]<curY && curY<fBy5[slice][1]&&fN5[slice]<kMaxClusterPerLayer5){
+       if (fBy5[slice][0]<curY && curY<fBy5[slice][1]&&fN5[slice]<AliITSRecoParam::GetMaxClusterPerLayer5()){
          fClusters5[slice][fN5[slice]] = fClusters[i];
          fY5[slice][fN5[slice]] = curY;
          fZ5[slice][fN5[slice]] = fZ[i];
@@ -1440,7 +1545,7 @@ void  AliITStrackerMI::AliITSlayer::SortClusters()
       }
       // slice 10
       for (Int_t slice=0; slice<11;slice++){
-       if (fBy10[slice][0]<curY && curY<fBy10[slice][1]&&fN10[slice]<kMaxClusterPerLayer10){
+       if (fBy10[slice][0]<curY && curY<fBy10[slice][1]&&fN10[slice]<AliITSRecoParam::GetMaxClusterPerLayer10()){
          fClusters10[slice][fN10[slice]] = fClusters[i];
          fY10[slice][fN10[slice]] = curY;
          fZ10[slice][fN10[slice]] = fZ[i];
@@ -1450,7 +1555,7 @@ void  AliITStrackerMI::AliITSlayer::SortClusters()
       }
       // slice 20
       for (Int_t slice=0; slice<21;slice++){
-       if (fBy20[slice][0]<curY && curY<fBy20[slice][1]&&fN20[slice]<kMaxClusterPerLayer20){
+       if (fBy20[slice][0]<curY && curY<fBy20[slice][1]&&fN20[slice]<AliITSRecoParam::GetMaxClusterPerLayer20()){
          fClusters20[slice][fN20[slice]] = fClusters[i];
          fY20[slice][fN20[slice]] = curY;
          fZ20[slice][fN20[slice]] = fZ[i];
@@ -1465,14 +1570,14 @@ void  AliITStrackerMI::AliITSlayer::SortClusters()
   //
   for (Int_t i=0;i<fN-1;i++){
     if (fZ[i]>fZ[i+1]){
-      printf("Bugg\n");
+      printf("Bug\n");
     }
   }
   //
   for (Int_t slice=0;slice<21;slice++)
   for (Int_t i=0;i<fN20[slice]-1;i++){
     if (fZ20[slice][i]>fZ20[slice][i+1]){
-      printf("Bugg\n");
+      printf("Bug\n");
     }
   }
 
@@ -1513,10 +1618,12 @@ SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
   Double_t circle=2*TMath::Pi()*fR;
   fYmin = ymin; fYmax =ymax;
   Float_t ymiddle = (fYmin+fYmax)*0.5;
-  if (ymiddle<fYB[0]) {fYmin+=circle; fYmax+=circle;ymiddle+=circle;}
-  else{
-    if (ymiddle>fYB[1]) {fYmin-=circle; fYmax-=circle;ymiddle-=circle;}
+  if (ymiddle<fYB[0]) {
+    fYmin+=circle; fYmax+=circle; ymiddle+=circle;
+  } else if (ymiddle>fYB[1]) {
+    fYmin-=circle; fYmax-=circle; ymiddle-=circle;
   }
+  
   //
   fCurrentSlice =-1;
   // defualt take all
@@ -1564,7 +1671,7 @@ SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
     if (slice<0) slice=0;
     if (slice>5) slice=5;
     Bool_t isOK = (fYmin>fBy5[slice][0]&&fYmax<fBy5[slice][1]);
-    if ( isOK){
+    if (isOK) {
       fCurrentSlice=slice;
       fClustersCs = fClusters5[fCurrentSlice];
       fClusterIndexCs = fClusterIndex5[fCurrentSlice];
@@ -1578,6 +1685,8 @@ SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
   fImax = TMath::Min(FindClusterIndex(zmax)+1,fNcs);
   fSkip = 0;
   fAccepted =0;
+
+  return;
 }
 //------------------------------------------------------------------------
 Int_t AliITStrackerMI::AliITSlayer::
@@ -1591,26 +1700,30 @@ FindDetectorIndex(Double_t phi, Double_t z) const {
   else                       // new geometry
     dphi = phi-fPhiOffset;
 
+
   if      (dphi <  0) dphi += 2*TMath::Pi();
   else if (dphi >= 2*TMath::Pi()) dphi -= 2*TMath::Pi();
   Int_t np=Int_t(dphi*fNladders*0.5/TMath::Pi()+0.5);
   if (np>=fNladders) np-=fNladders;
   if (np<0)          np+=fNladders;
 
+
   Double_t dz=fZOffset-z;
-  Int_t nz=Int_t(dz*(fNdetectors-1)*0.5/fZOffset+0.5);
+  Double_t nnz = dz*(fNdetectors-1)*0.5/fZOffset+0.5;
+  Int_t nz = (nnz<0 ? -1 : (Int_t)nnz);
   if (nz>=fNdetectors) return -1;
   if (nz<0)            return -1;
 
   return np*fNdetectors + nz;
 }
 //------------------------------------------------------------------------
-const AliITSRecPoint *AliITStrackerMI::AliITSlayer::GetNextCluster(Int_t &ci){
+const AliITSRecPoint *AliITStrackerMI::AliITSlayer::GetNextCluster(Int_t &ci,Bool_t test)
+{
   //--------------------------------------------------------------------
   // This function returns clusters within the "window" 
   //--------------------------------------------------------------------
 
-  if (fCurrentSlice<0){
+  if (fCurrentSlice<0) {
     Double_t rpi2 = 2.*fR*TMath::Pi();
     for (Int_t i=fI; i<fImax; i++) {
       Double_t y = fY[i];
@@ -1620,17 +1733,16 @@ const AliITSRecPoint *AliITStrackerMI::AliITSlayer::GetNextCluster(Int_t &ci){
       if (y>fYmax) continue;
       if (fClusters[i]->GetQ()==0&&fSkip==2) continue;
       ci=i;
-      fI=i+1;
+      if (!test) fI=i+1;
       return fClusters[i];
     }
-  }
-  else{
+  } else {
     for (Int_t i=fI; i<fImax; i++) {
       if (fYcs[i]<fYmin) continue;
       if (fYcs[i]>fYmax) continue;
       if (fClustersCs[i]->GetQ()==0&&fSkip==2) continue;
       ci=fClusterIndexCs[i];
-      fI=i+1;
+      if (!test) fI=i+1;
       return fClustersCs[i];
     }
   }
@@ -1643,7 +1755,7 @@ const {
   // This function returns the layer thickness at this point (units X0)
   //--------------------------------------------------------------------
   Double_t d=0.0085;
-  x0=kX0Air;
+  x0=AliITSRecoParam::GetX0Air();
   if (43<fR&&fR<45) { //SSD2
      Double_t dd=0.0034;
      d=dd;
@@ -1735,37 +1847,45 @@ const {
   return d;
 }
 //------------------------------------------------------------------------
-Double_t AliITStrackerMI::GetEffectiveThickness(Double_t y,Double_t z) const
+Double_t AliITStrackerMI::GetEffectiveThickness()
 {
   //--------------------------------------------------------------------
   // Returns the thickness between the current layer and the vertex (units X0)
   //--------------------------------------------------------------------
 
+  if(fUseTGeo!=0) {
+    if(fxOverX0Layer[0]<0) BuildMaterialLUT("Layers");
+    if(fxOverX0Shield[0]<0) BuildMaterialLUT("Shields");
+    if(fxOverX0Pipe<0) BuildMaterialLUT("Pipe");
+  }
+
   // beam pipe
-  Double_t d=kdPipe*krPipe*krPipe;
+  Double_t dPipe = (fUseTGeo==0 ? AliITSRecoParam::GetdPipe() : fxOverX0Pipe);
+  Double_t d=dPipe*AliITSRecoParam::GetrPipe()*AliITSRecoParam::GetrPipe();
 
   // layers
   Double_t x0=0;
   Double_t xn=fgLayers[fI].GetR();
   for (Int_t i=0; i<fI; i++) {
     Double_t xi=fgLayers[i].GetR();
-    d+=fgLayers[i].GetThickness(y,z,x0)*xi*xi;
+    Double_t dLayer = (fUseTGeo==0 ? fgLayers[i].GetThickness(0,0,x0) : fxOverX0Layer[i]);
+    d+=dLayer*xi*xi;
   }
 
   // shields
   if (fI>1) {
-    d+=kdshieldSPD*krshieldSPD*krshieldSPD;
+    Double_t dshieldSPD = (fUseTGeo==0 ? AliITSRecoParam::Getdshield(0) : fxOverX0Shield[0]);
+    d+=dshieldSPD*AliITSRecoParam::GetrInsideShield(0)*AliITSRecoParam::GetrInsideShield(0);
   }
   if (fI>3) {
-    Double_t xi=0.5*(fgLayers[3].GetR()+fgLayers[4].GetR());
-    d+=kdshieldSDD*xi*xi;
+    Double_t dshieldSDD = (fUseTGeo==0 ? AliITSRecoParam::Getdshield(1) : fxOverX0Shield[1]);
+    d+=dshieldSDD*AliITSRecoParam::GetrInsideShield(1)*AliITSRecoParam::GetrInsideShield(1);
   }
-
   return d/(xn*xn);
 }
 //------------------------------------------------------------------------
 Int_t AliITStrackerMI::AliITSlayer::InRoad() const {
-  //--------------------------------------------------------------------
+  //-------------------------------------------------------------------
   // This function returns number of clusters within the "window" 
   //--------------------------------------------------------------------
   Int_t ncl=0;
@@ -1786,333 +1906,240 @@ Int_t AliITStrackerMI::AliITSlayer::InRoad() const {
   return ncl;
 }
 //------------------------------------------------------------------------
-Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *t,
-                               const AliITStrackMI *c, Bool_t extra) {
+Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
+                               const AliITStrackMI *clusters,Bool_t extra, Bool_t planeeff) 
+{
   //--------------------------------------------------------------------
-  // This function refits the track "t" at the position "x" using
-  // the clusters from "c"
+  // This function refits the track "track" at the position "x" using
+  // the clusters from "clusters"
   // If "extra"==kTRUE, 
-  //    the clusters from overlapped modules get attached to "t" 
+  //    the clusters from overlapped modules get attached to "track" 
+  // If "planeff"==kTRUE,
+  //    special approach for plane efficiency evaluation is applyed
   //--------------------------------------------------------------------
-  Int_t index[kMaxLayer];
+
+  Int_t index[AliITSgeomTGeo::kNLayers];
   Int_t k;
-  for (k=0; k<kMaxLayer; k++) index[k]=-1;
-  Int_t nc=c->GetNumberOfClusters();
+  for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) index[k]=-1;
+  Int_t nc=clusters->GetNumberOfClusters();
   for (k=0; k<nc; k++) { 
-    Int_t idx=c->GetClusterIndex(k),nl=(idx&0xf0000000)>>28;
-    index[nl]=idx; 
+    Int_t idx=clusters->GetClusterIndex(k);
+    Int_t ilayer=(idx&0xf0000000)>>28;
+    index[ilayer]=idx; 
   }
 
-  // special for cosmics: check which the innermost layer crossed
-  // by the track
-  Int_t innermostlayer=5;
-  Double_t d = TMath::Abs(t->GetD(0.,0.));
-  for(innermostlayer=0; innermostlayer<kMaxLayer; innermostlayer++)
-    if(d<fgLayers[innermostlayer].GetR()) break;
-  //printf(" d  %f  innermost %d\n",d,innermostlayer);
-
-  Int_t from, to, step;
-  if (xx > t->GetX()) {
-      from=innermostlayer; to=kMaxLayer;
-      step=+1;
-  } else {
-      from=kMaxLayer-1; to=innermostlayer-1;
-      step=-1;
-  }
-
-  // loop on the layers
-  for (Int_t i=from; i != to; i += step) {
-     AliITSlayer &layer=fgLayers[i];
-     Double_t r=layer.GetR();
-     // material between SSD and SDD, SDD and SPD
-     Double_t hI=i-0.5*step; 
-     if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {             
-       Double_t rshield,dshield,x0shield;
-       if (TMath::Abs(hI-3.5)<0.01) { // SDDouter
-         rshield=0.5*(fgLayers[i-step].GetR() + r);
-         dshield=kdshieldSDD;
-         x0shield=kX0shieldSDD;
-       } else {        // SPDouter
-         rshield=krshieldSPD; 
-         dshield=kdshieldSPD; 
-         x0shield=kX0shieldSPD;
-       }
-       if (fUseTGeo) {
-         if (!t->PropagateToTGeo(rshield,1)) return kFALSE;
-       } else {
-         if (!t->PropagateTo(rshield,-step*dshield,x0shield)) return kFALSE;
-       }
-     }
-     
-     // remember old position [SR, GSI 18.02.2003]
-     Double_t oldX=0., oldY=0., oldZ=0.;
-     if (t->IsStartedTimeIntegral() && step==1) {
-        t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
-     }
-     //
-
-     Double_t oldGlobXYZ[3];
-     t->GetXYZ(oldGlobXYZ);
-
-     Double_t phi,z;
-     if (!t->GetPhiZat(r,phi,z)) return kFALSE;
-
-     Int_t idet=layer.FindDetectorIndex(phi,z);
-     if (idet<0) { 
-       return kFALSE;
-     }
-
-     const AliITSdetector &det=layer.GetDetector(idet);
-     phi=det.GetPhi();
-     if (!t->Propagate(phi,det.GetR())) {
-       return kFALSE;
-     }
-     t->SetDetectorIndex(idet);
-
-     const AliITSRecPoint *cl=0;
-     Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
-
-     Int_t idx=index[i];
-     if (idx>=0) {
-        const AliITSRecPoint *c=(AliITSRecPoint *)GetCluster(idx); 
-       if (c){
-         if (idet != c->GetDetectorIndex()) {
-           idet=c->GetDetectorIndex();
-           const AliITSdetector &det=layer.GetDetector(idet);
-           if (!t->Propagate(det.GetPhi(),det.GetR())) {
-             return kFALSE;
-           }
-           t->SetDetectorIndex(idet);
-         }
-         //Double_t chi2=t->GetPredictedChi2(c);
-         Int_t layer = (idx & 0xf0000000) >> 28;;
-         Double_t chi2=GetPredictedChi2MI(t,c,layer);
-         if (chi2<maxchi2) { 
-           cl=c; 
-           maxchi2=chi2; 
-         } else {
-           return kFALSE;
-         }
-       }
-     }
-
-     if (cl) {
-       if (!UpdateMI(t,cl,maxchi2,idx)) return kFALSE;
-       t->SetSampledEdx(cl->GetQ(),t->GetNumberOfClusters()-1);
-     }
-
-     // Correct for material of the current layer
-     Double_t d,x0;
-     if(fUseTGeo) {
-       Double_t globXYZ[3];
-       t->GetXYZ(globXYZ);
-       Double_t mparam[7];
-       AliTracker::MeanMaterialBudget(oldGlobXYZ,globXYZ,mparam);
-       if (mparam[1]<900000) {
-        d=mparam[1]; 
-        Double_t lengthTimesMeanDensity=mparam[0]*mparam[4]; 
-        t->CorrectForMeanMaterial(d,lengthTimesMeanDensity);
-       } else {
-        d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
-        t->CorrectForMaterial(-step*d,x0);
-       }
-     } else {
-       d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
-       t->CorrectForMaterial(-step*d,x0);
-     }
-     
-                 
-     if (extra) { //search for extra clusters
-        AliITStrackV2 tmp(*t);
-        Double_t dz=4*TMath::Sqrt(tmp.GetSigmaZ2()+AliITSReconstructor::GetRecoParam()->GetSigmaZ2(i));
-        if (dz < 0.5*TMath::Abs(tmp.GetTgl())) dz=0.5*TMath::Abs(tmp.GetTgl());
-        Double_t dy=4*TMath::Sqrt(t->GetSigmaY2()+AliITSReconstructor::GetRecoParam()->GetSigmaY2(i));
-        if (dy < 0.5*TMath::Abs(tmp.GetSnp())) dy=0.5*TMath::Abs(tmp.GetSnp());
-        Double_t zmin=t->GetZ() - dz;
-        Double_t zmax=t->GetZ() + dz;
-        Double_t ymin=t->GetY() + phi*r - dy;
-        Double_t ymax=t->GetY() + phi*r + dy;
-        layer.SelectClusters(zmin,zmax,ymin,ymax);
-
-        const AliITSRecPoint *c=0; Int_t ci=-1,cci=-1;
-        Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2(), tolerance=0.1;
-        while ((c=layer.GetNextCluster(ci))!=0) {
-           if (idet == c->GetDetectorIndex()) continue;
-
-          const AliITSdetector &det=layer.GetDetector(c->GetDetectorIndex());
-
-          if (!tmp.Propagate(det.GetPhi(),det.GetR())) continue;
-           
-          if (TMath::Abs(tmp.GetZ() - c->GetZ()) > tolerance) continue;
-           if (TMath::Abs(tmp.GetY() - c->GetY()) > tolerance) continue;
-
-           Double_t chi2=tmp.GetPredictedChi2(c);
-           if (chi2<maxchi2) { maxchi2=chi2; cci=ci; }
-        }
-        if (cci>=0) t->SetExtraCluster(i,(i<<28)+cci);
-     }
-
-     // track time update [SR, GSI 17.02.2003]
-     if (t->IsStartedTimeIntegral() && step==1) {
-        Double_t newX, newY, newZ;
-        t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
-        Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
-                       (oldZ-newZ)*(oldZ-newZ);
-        t->AddTimeStep(TMath::Sqrt(dL2));
-     }
-     //
-
-  } // end loop on the layers
-
-  if (!t->PropagateTo(xx,0.,0.)) return kFALSE;
-  return kTRUE;
+  return RefitAt(xx,track,index,extra,planeeff); // call the method below
 }
 //------------------------------------------------------------------------
-Bool_t 
-AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *t,const Int_t *clindex) {
+Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
+                               const Int_t *clusters,Bool_t extra, Bool_t planeeff) 
+{
   //--------------------------------------------------------------------
-  // This function refits the track "t" at the position "x" using
+  // This function refits the track "track" at the position "x" using
   // the clusters from array
+  // If "extra"==kTRUE, 
+  //    the clusters from overlapped modules get attached to "track" 
+  // If "planeff"==kTRUE,
+  //    special approach for plane efficiency evaluation is applyed
   //--------------------------------------------------------------------
-  Int_t index[kMaxLayer];
+  Int_t index[AliITSgeomTGeo::kNLayers];
   Int_t k;
-  for (k=0; k<kMaxLayer; k++) index[k]=-1;
+  for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) index[k]=-1;
   //
-  for (k=0; k<kMaxLayer; k++) { 
-    index[k]=clindex[k]; 
+  for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) { 
+    index[k]=clusters[k]; 
   }
 
   // special for cosmics: check which the innermost layer crossed
   // by the track
   Int_t innermostlayer=5;
-  Double_t d = TMath::Abs(t->GetD(0.,0.));
-  for(innermostlayer=0; innermostlayer<kMaxLayer; innermostlayer++)
-    if(d<fgLayers[innermostlayer].GetR()) break;
-  //printf(" d  %f  innermost %d\n",d,innermostlayer);
+  Double_t drphi = TMath::Abs(track->GetD(0.,0.));
+  for(innermostlayer=0; innermostlayer<AliITSgeomTGeo::GetNLayers(); innermostlayer++) {
+    if(drphi < fgLayers[innermostlayer].GetR()) break;
+  }
+  //printf(" drphi  %f  innermost %d\n",drphi,innermostlayer);
 
+  Int_t modstatus=1; // found
+  Float_t xloc,zloc;
   Int_t from, to, step;
-  if (xx > t->GetX()) {
-      from=innermostlayer; to=kMaxLayer;
+  if (xx > track->GetX()) {
+      from=innermostlayer; to=AliITSgeomTGeo::GetNLayers();
       step=+1;
   } else {
-      from=kMaxLayer-1; to=innermostlayer-1;
+      from=AliITSgeomTGeo::GetNLayers()-1; to=innermostlayer-1;
       step=-1;
   }
+  TString dir = (step>0 ? "outward" : "inward");
 
-  for (Int_t i=from; i != to; i += step) {
-     AliITSlayer &layer=fgLayers[i];
+  for (Int_t ilayer = from; ilayer != to; ilayer += step) {
+     AliITSlayer &layer=fgLayers[ilayer];
      Double_t r=layer.GetR();
      if (step<0 && xx>r) break;
 
      // material between SSD and SDD, SDD and SPD
-     Double_t hI=i-0.5*step; 
-     if (TMath::Abs(hI-1.5)<0.01 || TMath::Abs(hI-3.5)<0.01) {             
-       Double_t rshield,dshield,x0shield;
-       if (TMath::Abs(hI-3.5)<0.01) { // SDDouter
-         rshield=0.5*(fgLayers[i-step].GetR() + r);
-         dshield=kdshieldSDD;
-         x0shield=kX0shieldSDD;
-       } else {        // SPDouter
-         rshield=krshieldSPD; 
-         dshield=kdshieldSPD; 
-         x0shield=kX0shieldSPD;
-       }
-       if (fUseTGeo) {
-         if (!t->PropagateToTGeo(rshield,1)) return kFALSE;
-       } else {
-         if (!t->PropagateTo(rshield,-step*dshield,x0shield)) return kFALSE;
-       }
-     }
+     Double_t hI=ilayer-0.5*step; 
+     if (TMath::Abs(hI-3.5)<0.01) // SDDouter
+       if(!CorrectForShieldMaterial(track,"SDD",dir)) return kFALSE;
+     if (TMath::Abs(hI-1.5)<0.01) // SPDouter
+       if(!CorrectForShieldMaterial(track,"SPD",dir)) return kFALSE;
 
      // remember old position [SR, GSI 18.02.2003]
      Double_t oldX=0., oldY=0., oldZ=0.;
-     if (t->IsStartedTimeIntegral() && step==1) {
-        t->GetGlobalXYZat(t->GetX(),oldX,oldY,oldZ);
+     if (track->IsStartedTimeIntegral() && step==1) {
+        track->GetGlobalXYZat(track->GetX(),oldX,oldY,oldZ);
      }
      //
+
      Double_t oldGlobXYZ[3];
-     t->GetXYZ(oldGlobXYZ);
+     track->GetXYZ(oldGlobXYZ);
 
      Double_t phi,z;
-     if (!t->GetPhiZat(r,phi,z)) return kFALSE;
+     if (!track->GetPhiZat(r,phi,z)) return kFALSE;
 
      Int_t idet=layer.FindDetectorIndex(phi,z);
-     if (idet<0) { 
-       return kFALSE;
+
+     // check if we allow a prolongation without point for large-eta tracks
+     Int_t skip = CheckSkipLayer(track,ilayer,idet);
+     if (skip==2) {
+       // propagate to the layer radius
+       Double_t xToGo; track->GetLocalXat(r,xToGo);
+       track->AliExternalTrackParam::PropagateTo(xToGo,GetBz());
+       // apply correction for material of the current layer
+       CorrectForLayerMaterial(track,ilayer,oldGlobXYZ,dir);
+       modstatus = 4; // out in z
+       LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
+       track->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+       // track time update [SR, GSI 17.02.2003]
+       if (track->IsStartedTimeIntegral() && step==1) {
+        Double_t newX, newY, newZ;
+        track->GetGlobalXYZat(track->GetX(),newX,newY,newZ);
+        Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
+                       (oldZ-newZ)*(oldZ-newZ);
+        track->AddTimeStep(TMath::Sqrt(dL2));
+       }
+       continue;
      }
+
+     if (idet<0) return kFALSE;
+
      const AliITSdetector &det=layer.GetDetector(idet);
      phi=det.GetPhi();
-     if (!t->Propagate(phi,det.GetR())) {
-       return kFALSE;
-     }
-     t->SetDetectorIndex(idet);
+     if (!track->Propagate(phi,det.GetR())) return kFALSE;
+     track->SetDetectorIndex(idet);
+     LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
 
-     const AliITSRecPoint *cl=0;
-     Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
+     Double_t dz,zmin,zmax;
 
-     Int_t idx=index[i];
-     if (idx>=0) {
-        const AliITSRecPoint *c=(AliITSRecPoint *)GetCluster(idx); 
-       if (c){
-         if (idet != c->GetDetectorIndex()) {
-           idet=c->GetDetectorIndex();
-           const AliITSdetector &det=layer.GetDetector(idet);
-           if (!t->Propagate(det.GetPhi(),det.GetR())) {
-             return kFALSE;
-           }
-           t->SetDetectorIndex(idet);
-         }
-         //Double_t chi2=t->GetPredictedChi2(c);
-         Int_t layer = (idx & 0xf0000000) >> 28;;
-         Double_t chi2=GetPredictedChi2MI(t,c,layer);
-         if (chi2<maxchi2) { 
-           cl=c; 
-           maxchi2=chi2; 
-         } else {
-           return kFALSE;
-         }
-       }
-     }
-
-     if (cl) {
-       if (!UpdateMI(t,cl,maxchi2,idx)) return kFALSE;
-       t->SetSampledEdx(cl->GetQ(),t->GetNumberOfClusters()-1);
-     }
+     const AliITSRecPoint *clAcc=0;
+     Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
 
-     // Correct for material of the current layer
-     Double_t d,x0;
-     if(fUseTGeo) {
-       Double_t globXYZ[3];
-       t->GetXYZ(globXYZ);
-       Double_t mparam[7];
-       AliTracker::MeanMaterialBudget(oldGlobXYZ,globXYZ,mparam);
-       if (mparam[1]<900000) {
-        d=mparam[1]; 
-        Double_t lengthTimesMeanDensity=mparam[0]*mparam[4]; 
-        t->CorrectForMeanMaterial(d,lengthTimesMeanDensity);
+     Int_t idx=index[ilayer];
+     if (idx>=0) { // cluster in this layer
+       modstatus = 6; // no refit
+       const AliITSRecPoint *cl=(AliITSRecPoint *)GetCluster(idx); 
+       if (cl) {
+        if (idet != cl->GetDetectorIndex()) {
+          idet=cl->GetDetectorIndex();
+          const AliITSdetector &det=layer.GetDetector(idet);
+          if (!track->Propagate(det.GetPhi(),det.GetR())) return kFALSE;
+          track->SetDetectorIndex(idet);
+          LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
+        }
+        //Double_t chi2=track->GetPredictedChi2(cl);
+        Int_t cllayer = (idx & 0xf0000000) >> 28;;
+        Double_t chi2=GetPredictedChi2MI(track,cl,cllayer);
+        if (chi2<maxchi2) { 
+          clAcc=cl; 
+          maxchi2=chi2; 
+          modstatus = 1; // found
+        } else {
+           return kFALSE; //
+        }
+       }
+     } else { // no cluster in this layer
+       if (skip==1) {
+        modstatus = 3; // skipped
+         if (planeeff) {  // Plane Eff determination: 
+           if (IsOKForPlaneEff(track,ilayer))  // only adequate track for plane eff. evaluation
+              UseTrackForPlaneEff(track,ilayer); 
+         }
        } else {
-        d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
-        t->CorrectForMaterial(-step*d,x0);
+        modstatus = 5; // no cls in road
+        // check dead
+        dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
+                    TMath::Sqrt(track->GetSigmaZ2() + 
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                   AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
+        zmin=track->GetZ() - dz;
+        zmax=track->GetZ() + dz;
+        Int_t dead = CheckDeadZone(ilayer,idet,zmin,zmax);
+        if (dead==1) modstatus = 7; // holes in z in SPD
+        if (dead==2) modstatus = 2; // dead from OCDB
        }
-     } else {
-       d=layer.GetThickness(t->GetY(),t->GetZ(),x0);
-       t->CorrectForMaterial(-step*d,x0);
      }
+     
+     if (clAcc) {
+       if (!UpdateMI(track,clAcc,maxchi2,idx)) return kFALSE;
+       track->SetSampledEdx(clAcc->GetQ(),track->GetNumberOfClusters()-1);
+     }
+     track->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
+
+
+     if (extra) { // search for extra clusters in overlapped modules
+       AliITStrackV2 tmp(*track);
+       Double_t dy,ymin,ymax;
+       dz=4*TMath::Sqrt(tmp.GetSigmaZ2()+AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
+       if (dz < 0.5*TMath::Abs(tmp.GetTgl())) dz=0.5*TMath::Abs(tmp.GetTgl());
+       dy=4*TMath::Sqrt(track->GetSigmaY2()+AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
+       if (dy < 0.5*TMath::Abs(tmp.GetSnp())) dy=0.5*TMath::Abs(tmp.GetSnp());
+       zmin=track->GetZ() - dz;
+       zmax=track->GetZ() + dz;
+       ymin=track->GetY() + phi*r - dy;
+       ymax=track->GetY() + phi*r + dy;
+       layer.SelectClusters(zmin,zmax,ymin,ymax);
+       
+       const AliITSRecPoint *clExtra=0; Int_t ci=-1,cci=-1;
+       Int_t idetExtra=-1;  
+       Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2(), tolerance=0.1;
+       while ((clExtra=layer.GetNextCluster(ci))!=0) {
+        // only clusters in another module! (overlaps)
+        idetExtra = clExtra->GetDetectorIndex();
+        if (idet == idetExtra) continue;
+        
+        const AliITSdetector &det=layer.GetDetector(idetExtra);
+        
+        if (!tmp.Propagate(det.GetPhi(),det.GetR())) continue;
+        
+        if (TMath::Abs(tmp.GetZ() - clExtra->GetZ()) > tolerance) continue;
+        if (TMath::Abs(tmp.GetY() - clExtra->GetY()) > tolerance) continue;
+        
+        Double_t chi2=tmp.GetPredictedChi2(clExtra);
+        if (chi2<maxchi2) { maxchi2=chi2; cci=ci; }
+       }
+       if (cci>=0) {
+        track->SetExtraCluster(ilayer,(ilayer<<28)+cci);
+        track->SetExtraModule(ilayer,idetExtra);
+       }
+     } // end search for extra clusters in overlapped modules
+     
+     // Correct for material of the current layer
+     if(!CorrectForLayerMaterial(track,ilayer,oldGlobXYZ,dir)) return kFALSE;
                  
      // track time update [SR, GSI 17.02.2003]
-     if (t->IsStartedTimeIntegral() && step==1) {
+     if (track->IsStartedTimeIntegral() && step==1) {
         Double_t newX, newY, newZ;
-        t->GetGlobalXYZat(t->GetX(),newX,newY,newZ);
+        track->GetGlobalXYZat(track->GetX(),newX,newY,newZ);
         Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
                        (oldZ-newZ)*(oldZ-newZ);
-        t->AddTimeStep(TMath::Sqrt(dL2));
+        track->AddTimeStep(TMath::Sqrt(dL2));
      }
      //
 
-  }
+  } // end loop on layers
+
+  if (!track->PropagateTo(xx,0.,0.)) return kFALSE;
 
-  if (!t->PropagateTo(xx,0.,0.)) return kFALSE;
   return kTRUE;
 }
 //------------------------------------------------------------------------
@@ -2137,7 +2164,7 @@ Double_t AliITStrackerMI::GetNormalizedChi2(AliITStrackMI * track, Int_t mode)
        cerry*=cerry;
        cerrz*=cerrz;   
        Float_t cchi2 = (track->GetDy(i)*track->GetDy(i)/cerry)+(track->GetDz(i)*track->GetDz(i)/cerrz);
-       if (i>1){
+       if (i>1 && AliITSReconstructor::GetRecoParam()->GetUseAmplitudeInfo(i)) {
          Float_t ratio = track->GetNormQ(i)/track->GetExpQ();
          if (ratio<0.5) {
            cchi2+=(0.5-ratio)*10.;
@@ -2202,7 +2229,13 @@ Double_t AliITStrackerMI::GetNormalizedChi2(AliITStrackMI * track, Int_t mode)
   //
   Double_t match = TMath::Sqrt(track->GetChi22());
   if (track->GetConstrain())  match/=track->GetNumberOfClusters();
-  if (!track->GetConstrain()) match/=track->GetNumberOfClusters()-2.;
+  if (!track->GetConstrain()) { 
+    if (track->GetNumberOfClusters()>2) {
+      match/=track->GetNumberOfClusters()-2.;
+    } else {
+      match=0;
+    }
+  }
   if (match<0) match=0;
   Float_t deadzonefactor = (track->GetNDeadZone()>0) ? 3*(1.1-track->GetDeadZoneProbability()):0.;
   Double_t normchi2 = 2*track->GetNSkipped()+match+deadzonefactor+(1+(2*track->GetNSkipped()+deadzonefactor)/track->GetNumberOfClusters())*
@@ -2252,7 +2285,7 @@ Double_t AliITStrackerMI::GetMatchingChi2(AliITStrackMI * track1, AliITStrackMI
   return chi2(0,0);
 }
 //------------------------------------------------------------------------
-Double_t  AliITStrackerMI::GetDeadZoneProbability(Double_t zpos, Double_t zerr)
+Double_t  AliITStrackerMI::GetSPDDeadZoneProbability(Double_t zpos, Double_t zerr)
 {
   //
   //  return probability that given point (characterized by z position and error) 
@@ -2265,14 +2298,14 @@ Double_t  AliITStrackerMI::GetDeadZoneProbability(Double_t zpos, Double_t zerr)
   if (TMath::Abs(absz-nearestz)>0.25+3.*zerr) return probability;
   Double_t zmin, zmax;   
   if (zpos<-6.) { // dead zone at z = -7
-    zmin = fSPDdetzcentre[0] + 0.5*kSPDdetzlength;
-    zmax = fSPDdetzcentre[1] - 0.5*kSPDdetzlength;
+    zmin = fSPDdetzcentre[0] + 0.5*AliITSRecoParam::GetSPDdetzlength();
+    zmax = fSPDdetzcentre[1] - 0.5*AliITSRecoParam::GetSPDdetzlength();
   } else if (zpos>6.) { // dead zone at z = +7
-    zmin = fSPDdetzcentre[2] + 0.5*kSPDdetzlength;
-    zmax = fSPDdetzcentre[3] - 0.5*kSPDdetzlength;
+    zmin = fSPDdetzcentre[2] + 0.5*AliITSRecoParam::GetSPDdetzlength();
+    zmax = fSPDdetzcentre[3] - 0.5*AliITSRecoParam::GetSPDdetzlength();
   } else if (absz<2.) { // dead zone at z = 0
-    zmin = fSPDdetzcentre[1] + 0.5*kSPDdetzlength;
-    zmax = fSPDdetzcentre[2] - 0.5*kSPDdetzlength;
+    zmin = fSPDdetzcentre[1] + 0.5*AliITSRecoParam::GetSPDdetzlength();
+    zmax = fSPDdetzcentre[2] - 0.5*AliITSRecoParam::GetSPDdetzlength();
   } else {
     zmin = 0.;
     zmax = 0.;
@@ -2416,7 +2449,8 @@ Float_t AliITStrackerMI::GetNumberOfSharedClusters(AliITStrackMI* track,Int_t id
     //
     Float_t deltan = 0;
     if (l>3&&cl->GetNy()+cl->GetNz()>6) continue;
-    if (l>2&&track->GetNormQ(l)/track->GetExpQ()>3.5) continue;
+    if (l>2&&AliITSReconstructor::GetRecoParam()->GetUseAmplitudeInfo(l))
+      if (track->GetNormQ(l)/track->GetExpQ()>3.5) continue;
     if (l<2 || l>3){      
       deltan = (cl->GetNy()+cl->GetNz()-ny[l]-nz[l]);
     }
@@ -2466,7 +2500,8 @@ Int_t AliITStrackerMI::GetOverlapTrack(AliITStrackMI *track, Int_t trackID, Int_
     //
     Float_t deltan = 0;
     if (l>3&&cl->GetNy()+cl->GetNz()>6) continue;
-    if (l>2&&track->GetNormQ(l)/track->GetExpQ()>3.5) continue;
+    if (l>2&&AliITSReconstructor::GetRecoParam()->GetUseAmplitudeInfo(l))
+      if (track->GetNormQ(l)/track->GetExpQ()>3.5) continue;
     if (l<2 || l>3){      
       deltan = (cl->GetNy()+cl->GetNz()-ny[l]-nz[l]);
     }
@@ -3028,11 +3063,7 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
     // backtrack
     backtrack = new(backtrack) AliITStrackMI(*track); 
     if (track->GetConstrain()) {
-      if(fUseTGeo) {
-       if (!backtrack->PropagateToTGeo(krInsidePipe,1)) continue;
-      } else {
-       if (!backtrack->PropagateTo(krInsidePipe,kdPipe,kX0Be)) continue;
-      }
+      if (!CorrectForPipeMaterial(backtrack,"inward")) continue;
       if (!backtrack->Improve(0,xyzVtx,ersVtx))         continue;     
       backtrack->ResetCovariance(10.);      
     }else{
@@ -3130,7 +3161,7 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
   AliITStrackMI *longtrack =0;
   minchi2 =1000;
   Float_t minn=besttrack->GetNumberOfClusters()+besttrack->GetNDeadZone();
-  for (Int_t itrack=entries-1;itrack>0;itrack--){
+  for (Int_t itrack=entries-1;itrack>0;itrack--) {
     AliITStrackMI * track = (AliITStrackMI*)array->At(itrack);
     if (!track->GetConstrain()) continue;
     if (track->GetNumberOfClusters()+track->GetNDeadZone()<minn) continue;
@@ -3187,7 +3218,8 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
       if (ilayer>3&&c->GetNy()+c->GetNz()>6) continue;
       if ( (c->GetNy()+c->GetNz() )> ny[i]+nz[i]+0.7) continue; //shared track
       if (  c->GetNz()> nz[i]+0.7) continue; //shared track
-      if ( ilayer>2&& besttrack->GetNormQ(ilayer)/besttrack->GetExpQ()>1.5) continue;
+      if ( ilayer>2&& AliITSReconstructor::GetRecoParam()->GetUseAmplitudeInfo(ilayer)) 
+       if (besttrack->GetNormQ(ilayer)/besttrack->GetExpQ()>1.5) continue;
       //if (  c->GetNy()> ny[i]+0.7) continue; //shared track
 
       Bool_t cansign = kTRUE;
@@ -3368,7 +3400,7 @@ void AliITStrackerMI::CookdEdx(AliITStrackMI* track)
   track->SetdEdx(sumamp/sumweight);
 }
 //------------------------------------------------------------------------
-void  AliITStrackerMI::MakeCoefficients(Int_t ntracks){
+void AliITStrackerMI::MakeCoefficients(Int_t ntracks){
   //
   //
   if (fCoefficients) delete []fCoefficients;
@@ -3385,10 +3417,10 @@ Double_t AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSR
   Float_t theta = track->GetTgl();
   Float_t phi   = track->GetSnp();
   phi = TMath::Sqrt(phi*phi/(1.-phi*phi));
-  GetError(layer,cluster,theta,phi,track->GetExpQ(),erry,errz);
+  AliITSClusterParam::GetError(layer,cluster,theta,phi,track->GetExpQ(),erry,errz);
   Double_t chi2 = track->GetPredictedChi2MI(cluster->GetY(),cluster->GetZ(),erry,errz);
   Float_t ny,nz;
-  GetNTeor(layer,cluster, theta,phi,ny,nz);  
+  AliITSClusterParam::GetNTeor(layer,cluster,theta,phi,ny,nz);  
   Double_t delta = cluster->GetNy()+cluster->GetNz()-nz-ny;
   if (delta>1){
     chi2+=0.5*TMath::Min(delta/2,2.);
@@ -3404,17 +3436,19 @@ Double_t AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSR
   return chi2;
 
 }
-
-Int_t    AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSRecPoint* cl,Double_t chi2,Int_t index) const 
+//------------------------------------------------------------------------
+Int_t AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSRecPoint* cl,Double_t chi2,Int_t index) const 
 {
   //
   //
   //
   Int_t layer = (index & 0xf0000000) >> 28;
   track->SetClIndex(layer, index);
-  if ( (layer>1) &&track->GetNormQ(layer)/track->GetExpQ()<0.5 ) {
-    chi2+= (0.5-track->GetNormQ(layer)/track->GetExpQ())*10.;
-    track->SetdEdxMismatch(track->GetdEdxMismatch()+(0.5-track->GetNormQ(layer)/track->GetExpQ())*10.);
+  if (layer>1&&AliITSReconstructor::GetRecoParam()->GetUseAmplitudeInfo(layer)) {
+    if (track->GetNormQ(layer)/track->GetExpQ()<0.5 ) {
+      chi2+= (0.5-track->GetNormQ(layer)/track->GetExpQ())*10.;
+      track->SetdEdxMismatch(track->GetdEdxMismatch()+(0.5-track->GetNormQ(layer)/track->GetExpQ())*10.);
+    }
   }
 
   if (cl->GetQ()<=0) return 0;  // ingore the "virtual" clusters
@@ -3426,191 +3460,15 @@ Int_t    AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSRecPoint* c
   Double_t x=track->GetX()+cl->GetX();
   if (!track->PropagateTo(x,0.,0.)) return 0;
   
-  return track->UpdateMI(cl->GetY(),cl->GetZ(),track->GetSigmaY(layer),track->GetSigmaZ(layer),chi2,index);
-}
+  AliCluster c(*cl);
+  c.SetSigmaY2(track->GetSigmaY(layer)*track->GetSigmaY(layer));
+  c.SetSigmaZ2(track->GetSigmaZ(layer)*track->GetSigmaZ(layer));
 
-void AliITStrackerMI::GetNTeor(Int_t layer, const AliITSRecPoint* /*cl*/, Float_t theta, Float_t phi, Float_t &ny, Float_t &nz)
-{
-  //
-  //get "mean shape"
-  //
-  if (layer==0){
-    ny = 1.+TMath::Abs(phi)*3.2;
-    nz = 1.+TMath::Abs(theta)*0.34;
-    return;
-  }
-  if (layer==1){
-    ny = 1.+TMath::Abs(phi)*3.2;
-    nz = 1.+TMath::Abs(theta)*0.28;
-    return;
-  }
-  
-  if (layer>3){
-    ny = 2.02+TMath::Abs(phi)*1.95;
-    nz = 2.02+TMath::Abs(phi)*2.35;
-    return;
-  }
-  ny  = 6.6-2.7*TMath::Abs(phi);
-  nz  = 2.8-3.11*TMath::Abs(phi)+0.45*TMath::Abs(theta);
+  return track->UpdateMI(&c,chi2,index);
 }
 
-
-
-Int_t AliITStrackerMI::GetError(Int_t layer, const AliITSRecPoint*cl, Float_t theta, Float_t phi,Float_t expQ, Float_t &erry, Float_t &errz)
-{
-  //calculate cluster position error
-  //
-  Float_t nz,ny;
-  GetNTeor(layer, cl,theta,phi,ny,nz);  
-  erry   = TMath::Sqrt(cl->GetSigmaY2()); 
-  errz   = TMath::Sqrt(cl->GetSigmaZ2()); 
-  //
-  // PIXELS
-  if (layer<2){
-    if (TMath::Abs(ny-cl->GetNy())>0.6)  {
-      if (ny<cl->GetNy()){
-       erry*=0.4+TMath::Abs(ny-cl->GetNy());
-       errz*=0.4+TMath::Abs(ny-cl->GetNy());
-      }else{
-       erry*=0.7+0.5*TMath::Abs(ny-cl->GetNy());
-       errz*=0.7+0.5*TMath::Abs(ny-cl->GetNy());
-      }
-    }
-    if (TMath::Abs(nz-cl->GetNz())>1.)  {
-      erry*=TMath::Abs(nz-cl->GetNz());
-      errz*=TMath::Abs(nz-cl->GetNz());              
-    }
-    erry*=0.85;
-    errz*=0.85;
-    erry= TMath::Min(erry,float(0.0050));
-    errz= TMath::Min(errz,float(0.0300));
-    return 10;
-  }
-
-  //STRIPS
-  if (layer>3){ 
-    //factor 1.8 appears in new simulation
-    //
-    Float_t scale=1.8;
-    if (cl->GetNy()==100||cl->GetNz()==100){
-      erry = 0.004*scale;
-      errz = 0.2*scale;
-      return 100;
-    }
-    if (cl->GetNy()+cl->GetNz()>12){
-      erry = 0.06*scale;
-      errz = 0.57*scale;
-      return 100;
-    }
-    Float_t normq = cl->GetQ()/(TMath::Sqrt(1+theta*theta+phi*phi));
-    Float_t chargematch = TMath::Max(double(normq/expQ),2.);
-    //
-    if (cl->GetType()==1 || cl->GetType()==10 ){                                                              
-      if (chargematch<1.0 || (cl->GetNy()+cl->GetNz()<nz+ny+0.5)){
-       errz = 0.043*scale;
-       erry = 0.00094*scale;
-       return 101;
-      }
-      if (cl->GetNy()+cl->GetNz()<nz+ny+1.2){
-       errz = 0.06*scale;
-       erry =0.0013*scale;
-       return 102;
-      }
-      erry = 0.0027*scale;
-      errz = TMath::Min(0.028*(chargematch+cl->GetNy()+cl->GetNz()-nz+ny),0.15)*scale;
-      return 103;
-    }
-    if (cl->GetType()==2 || cl->GetType()==11 ){ 
-      erry = TMath::Min(0.0010*(1+chargematch+cl->GetNy()+cl->GetNz()-nz+ny),0.05)*scale;
-      errz = TMath::Min(0.025*(1+chargematch+cl->GetNy()+cl->GetNz()-nz+ny),0.5)*scale;
-      return 104;
-    }
-    
-    if (cl->GetType()>100 ){                                                                  
-      if ((chargematch+cl->GetNy()+cl->GetNz()-nz-ny<1.5)){
-       errz = 0.05*scale;
-       erry = 0.00096*scale;
-       return 105;
-      }
-      if (cl->GetNy()+cl->GetNz()-nz-ny<1){
-       errz = 0.10*scale;
-       erry = 0.0025*scale;
-       return 106;
-      }
-
-      errz = TMath::Min(0.05*(chargematch+cl->GetNy()+cl->GetNz()-nz-ny),0.4)*scale;
-      erry = TMath::Min(0.003*(chargematch+cl->GetNy()+cl->GetNz()-nz-ny),0.05)*scale;
-      return 107;
-    }    
-    Float_t diff = cl->GetNy()+cl->GetNz()-ny-nz;
-    if (diff<1) diff=1;
-    if (diff>4) diff=4;
-        
-    if (cl->GetType()==5||cl->GetType()==6||cl->GetType()==7||cl->GetType()==8){
-      errz = 0.14*diff;
-      erry = 0.003*diff;
-      return 108;
-    }  
-    erry = 0.04*diff;
-    errz = 0.06*diff;
-    return 109;
-  }
-  //DRIFTS
-  Float_t normq = cl->GetQ()/(TMath::Sqrt(1+theta*theta+phi*phi));
-  Float_t chargematch = normq/expQ;
-  chargematch/=2.4; // F. Prino Sept. 2007: SDD charge conversion keV->ADC
-  Float_t factorz=1;
-  Int_t   cnz = cl->GetNz()%10;
-  //charge match
-  if (cl->GetType()==1){
-    if (chargematch<1.25){
-      erry =  0.0028*(1.+6./cl->GetQ());  // gold clusters
-    }
-    else{
-      erry = 0.003*chargematch;
-      if (cl->GetNz()==3) erry*=1.5;
-    }
-    if (chargematch<1.0){
-      errz =  0.0011*(1.+6./cl->GetQ());
-    }
-    else{
-      errz = 0.002*(1+2*(chargematch-1.));
-    }
-    if (cnz>nz+0.6) {
-      erry*=(cnz-nz+0.5);
-      errz*=1.4*(cnz-nz+0.5);
-    }
-  }
-  if (cl->GetType()>1){
-    if (chargematch<1){
-      erry =  0.00385*(1.+6./cl->GetQ());  // gold clusters
-      errz =  0.0016*(1.+6./cl->GetQ());
-    }
-    else{
-      errz = 0.0014*(1+3*(chargematch-1.));
-      erry = 0.003*(1+3*(chargematch-1.));
-    } 
-    if (cnz>nz+0.6) {
-      erry*=(cnz-nz+0.5);
-      errz*=1.4*(cnz-nz+0.5);
-    }
-  }
-
-  if (TMath::Abs(cl->GetY())>2.5){
-    factorz*=1+2*(TMath::Abs(cl->GetY())-2.5);
-  }
-  if (TMath::Abs(cl->GetY())<1){
-    factorz*=1.+0.5*TMath::Abs(TMath::Abs(cl->GetY())-1.);
-  }
-  factorz= TMath::Min(factorz,float(4.));  
-  errz*=factorz;
-
-  erry= TMath::Min(erry,float(0.05));
-  errz= TMath::Min(errz,float(0.05));  
-  return 200;
-}
 //------------------------------------------------------------------------
-void   AliITStrackerMI::GetDCASigma(AliITStrackMI* track, Float_t & sigmarfi, Float_t &sigmaz)
+void AliITStrackerMI::GetDCASigma(AliITStrackMI* track, Float_t & sigmarfi, Float_t &sigmaz)
 {
   //
   //DCA sigmas parameterization
@@ -3620,8 +3478,7 @@ void   AliITStrackerMI::GetDCASigma(AliITStrackMI* track, Float_t & sigmarfi, Fl
   sigmarfi = 0.0040+1.4 *TMath::Abs(track->GetC())+332.*track->GetC()*track->GetC();
   sigmaz   = 0.0110+4.37*TMath::Abs(track->GetC());
 }
-
-
+//------------------------------------------------------------------------
 void AliITStrackerMI::SignDeltas( TObjArray *ClusterArray, Float_t vz)
 {
   //
@@ -3706,7 +3563,7 @@ void AliITStrackerMI::UpdateESDtrack(AliITStrackMI* track, ULong_t flags) const
 //------------------------------------------------------------------------
 Int_t AliITStrackerMI::GetNearestLayer(const Double_t *xr) const{
   //
-  //Get nearest upper layer close to the point xr.
+  // Get nearest upper layer close to the point xr.
   // rough approximation 
   //
   const Float_t kRadiuses[6]={4,6.5,15.03,24.,38.5,43.7};
@@ -3832,7 +3689,7 @@ void AliITStrackerMI::UpdateTPCV0(AliESDEvent *event){
   //
 }
 //------------------------------------------------------------------------
-void  AliITStrackerMI::FindV02(AliESDEvent *event)
+void AliITStrackerMI::FindV02(AliESDEvent *event)
 {
   //
   // V0 finder
@@ -4184,11 +4041,15 @@ void  AliITStrackerMI::FindV02(AliESDEvent *event)
       //
       //
       TObjArray * array0b     = (TObjArray*)fBestHypothesys.At(itrack0);
-      if (!array0b&&pvertex->GetRr()<40 && TMath::Abs(track0->GetTgl())<1.1) 
+      if (!array0b&&pvertex->GetRr()<40 && TMath::Abs(track0->GetTgl())<1.1) {
+       fCurrentEsdTrack = itrack0;
        FollowProlongationTree((AliITStrackMI*)fOriginal.At(itrack0),itrack0, kFALSE);
+      }
       TObjArray * array1b    = (TObjArray*)fBestHypothesys.At(itrack1);
-      if (!array1b&&pvertex->GetRr()<40 && TMath::Abs(track1->GetTgl())<1.1) 
+      if (!array1b&&pvertex->GetRr()<40 && TMath::Abs(track1->GetTgl())<1.1) { 
+       fCurrentEsdTrack = itrack1;
        FollowProlongationTree((AliITStrackMI*)fOriginal.At(itrack1),itrack1, kFALSE);
+      }
       //
       AliITStrackMI * track0b = (AliITStrackMI*)fOriginal.At(itrack0);       
       AliITStrackMI * track1b = (AliITStrackMI*)fOriginal.At(itrack1);
@@ -4540,10 +4401,658 @@ void AliITStrackerMI::RefitV02(AliESDEvent *event)
   }
 }
 //------------------------------------------------------------------------
+void AliITStrackerMI::BuildMaterialLUT(TString material) {
+  //--------------------------------------------------------------------
+  // Fill a look-up table with mean material
+  //--------------------------------------------------------------------
+
+  Int_t n=1000;
+  Double_t mparam[7];
+  Double_t point1[3],point2[3];
+  Double_t phi,cosphi,sinphi,z;
+  // 0-5 layers, 6 pipe, 7-8 shields 
+  Double_t rmin[9]={ 3.5, 5.5,13.0,22.0,35.0,41.0, 2.0, 7.5,25.0};
+  Double_t rmax[9]={ 5.5, 7.3,17.0,26.0,41.0,47.0, 3.0,10.5,30.0};
+
+  Int_t ifirst=0,ilast=0;  
+  if(material.Contains("Pipe")) {
+    ifirst=6; ilast=6;
+  } else if(material.Contains("Shields")) {
+    ifirst=7; ilast=8;
+  } else if(material.Contains("Layers")) {
+    ifirst=0; ilast=5;
+  } else {
+    Error("BuildMaterialLUT","Wrong layer name\n");
+  }
+
+  for(Int_t imat=ifirst; imat<=ilast; imat++) {
+    Double_t param[5]={0.,0.,0.,0.,0.};
+    for (Int_t i=0; i<n; i++) {
+      phi = 2.*TMath::Pi()*gRandom->Rndm();
+      cosphi = TMath::Cos(phi); sinphi = TMath::Sin(phi); 
+      z = 14.*(-1.+2.*gRandom->Rndm()); // SPD barrel
+      point1[0] = rmin[imat]*cosphi;
+      point1[1] = rmin[imat]*sinphi;
+      point1[2] = z;
+      point2[0] = rmax[imat]*cosphi;
+      point2[1] = rmax[imat]*sinphi;
+      point2[2] = z;
+      AliTracker::MeanMaterialBudget(point1,point2,mparam);
+      for(Int_t j=0;j<5;j++) param[j]+=mparam[j];
+    }
+    for(Int_t j=0;j<5;j++) param[j]/=(Float_t)n;
+    if(imat<=5) {
+      fxOverX0Layer[imat] = param[1];
+      fxTimesRhoLayer[imat] = param[0]*param[4];
+    } else if(imat==6) {
+      fxOverX0Pipe = param[1];
+      fxTimesRhoPipe = param[0]*param[4];
+    } else if(imat==7) {
+      fxOverX0Shield[0] = param[1];
+      fxTimesRhoShield[0] = param[0]*param[4];
+    } else if(imat==8) {
+      fxOverX0Shield[1] = param[1];
+      fxTimesRhoShield[1] = param[0]*param[4];
+    }
+  }
+  /*
+  printf("%s\n",material.Data());
+  printf("%f  %f\n",fxOverX0Pipe,fxTimesRhoPipe);
+  printf("%f  %f\n",fxOverX0Shield[0],fxTimesRhoShield[0]);
+  printf("%f  %f\n",fxOverX0Shield[1],fxTimesRhoShield[1]);
+  printf("%f  %f\n",fxOverX0Layer[0],fxTimesRhoLayer[0]);
+  printf("%f  %f\n",fxOverX0Layer[1],fxTimesRhoLayer[1]);
+  printf("%f  %f\n",fxOverX0Layer[2],fxTimesRhoLayer[2]);
+  printf("%f  %f\n",fxOverX0Layer[3],fxTimesRhoLayer[3]);
+  printf("%f  %f\n",fxOverX0Layer[4],fxTimesRhoLayer[4]);
+  printf("%f  %f\n",fxOverX0Layer[5],fxTimesRhoLayer[5]);
+  */
+  return;
+}
+//------------------------------------------------------------------------
+Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
+                                             TString direction) {
+  //-------------------------------------------------------------------
+  // Propagate beyond beam pipe and correct for material
+  // (material budget in different ways according to fUseTGeo value)
+  //-------------------------------------------------------------------
+
+  // Define budget mode:
+  // 0: material from AliITSRecoParam (hard coded)
+  // 1: material from TGeo (on the fly)
+  // 2: material from lut
+  // 3: material from TGeo (same for all hypotheses)
+  Int_t mode;
+  switch(fUseTGeo) {
+  case 0:
+    mode=0; 
+    break;    
+  case 1:
+    mode=1;
+    break;    
+  case 2:
+    mode=2;
+    break;
+  case 3:
+    if(fTrackingPhase.Contains("Clusters2Tracks")) 
+      { mode=3; } else { mode=1; }
+    break;
+  case 4:
+    if(fTrackingPhase.Contains("Clusters2Tracks")) 
+      { mode=3; } else { mode=2; }
+    break;
+  default:
+    mode=0;
+    break;
+  }
+  if(fTrackingPhase.Contains("Default")) mode=0;
+
+  Int_t index=fCurrentEsdTrack;
+
+  Float_t  dir = (direction.Contains("inward") ? 1. : -1.);
+  Double_t rToGo=(dir>0 ? AliITSRecoParam::GetrInsidePipe() : AliITSRecoParam::GetrOutsidePipe());
+  Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
+
+  Double_t xOverX0,x0,lengthTimesMeanDensity;
+  Bool_t anglecorr=kTRUE;
+
+  switch(mode) {
+  case 0:
+    xOverX0 = AliITSRecoParam::GetdPipe();
+    x0 = AliITSRecoParam::GetX0Be();
+    lengthTimesMeanDensity = xOverX0*x0;
+    break;
+  case 1:
+    if (!t->PropagateToTGeo(xToGo,1)) return 0;
+    return 1;
+    break;
+  case 2:
+    if(fxOverX0Pipe<0) BuildMaterialLUT("Pipe");  
+    xOverX0 = fxOverX0Pipe;
+    lengthTimesMeanDensity = fxTimesRhoPipe;
+    break;
+  case 3:
+    if(!fxOverX0PipeTrks || index<0 || index>=fNtracks) Error("CorrectForPipeMaterial","Incorrect usage of UseTGeo option!\n");
+    if(fxOverX0PipeTrks[index]<0) {
+      if (!t->PropagateToTGeo(xToGo,1,xOverX0,lengthTimesMeanDensity)) return 0;
+      Double_t angle=TMath::Sqrt((1.+t->GetTgl()*t->GetTgl())/
+                                (1.-t->GetSnp()*t->GetSnp()));
+      fxOverX0PipeTrks[index] = TMath::Abs(xOverX0)/angle;
+      fxTimesRhoPipeTrks[index] = TMath::Abs(lengthTimesMeanDensity)/angle;
+      return 1;
+    }
+    xOverX0 = fxOverX0PipeTrks[index];
+    lengthTimesMeanDensity = fxTimesRhoPipeTrks[index];
+    break;
+  }
+
+  lengthTimesMeanDensity *= dir;
+
+  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
+  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
+
+  return 1;
+}
+//------------------------------------------------------------------------
+Int_t AliITStrackerMI::CorrectForShieldMaterial(AliITStrackMI *t,
+                                               TString shield,
+                                               TString direction) {
+  //-------------------------------------------------------------------
+  // Propagate beyond SPD or SDD shield and correct for material
+  // (material budget in different ways according to fUseTGeo value)
+  //-------------------------------------------------------------------
+
+  // Define budget mode:
+  // 0: material from AliITSRecoParam (hard coded)
+  // 1: material from TGeo (on the fly)
+  // 2: material from lut
+  // 3: material from TGeo (same for all hypotheses)
+  Int_t mode;
+  switch(fUseTGeo) {
+  case 0:
+    mode=0; 
+    break;    
+  case 1:
+    mode=1;
+    break;    
+  case 2:
+    mode=2;
+    break;
+  case 3:
+    if(fTrackingPhase.Contains("Clusters2Tracks")) 
+      { mode=3; } else { mode=1; }
+    break;
+  case 4:
+    if(fTrackingPhase.Contains("Clusters2Tracks")) 
+      { mode=3; } else { mode=2; }
+    break;
+  default:
+    mode=0;
+    break;
+  }
+  if(fTrackingPhase.Contains("Default")) mode=0;
+
+  Float_t  dir = (direction.Contains("inward") ? 1. : -1.);
+  Double_t rToGo;
+  Int_t    shieldindex=0;
+  if (shield.Contains("SDD")) { // SDDouter
+    rToGo=(dir>0 ? AliITSRecoParam::GetrInsideShield(1) : AliITSRecoParam::GetrOutsideShield(1));
+    shieldindex=1;
+  } else if (shield.Contains("SPD")) {        // SPDouter
+    rToGo=(dir>0 ? AliITSRecoParam::GetrInsideShield(0) : AliITSRecoParam::GetrOutsideShield(0)); 
+    shieldindex=0;
+  } else {
+    Error("CorrectForShieldMaterial"," Wrong shield name\n");
+    return 0;
+  }
+  Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
+
+  Int_t index=2*fCurrentEsdTrack+shieldindex;
+
+  Double_t xOverX0,x0,lengthTimesMeanDensity;
+  Bool_t anglecorr=kTRUE;
+
+  switch(mode) {
+  case 0:
+    xOverX0 = AliITSRecoParam::Getdshield(shieldindex);
+    x0 = AliITSRecoParam::GetX0shield(shieldindex);
+    lengthTimesMeanDensity = xOverX0*x0;
+    break;
+  case 1:
+    if (!t->PropagateToTGeo(xToGo,1)) return 0;
+    return 1;
+    break;
+  case 2:
+    if(fxOverX0Shield[shieldindex]<0) BuildMaterialLUT("Shields");  
+    xOverX0 = fxOverX0Shield[shieldindex];
+    lengthTimesMeanDensity = fxTimesRhoShield[shieldindex];
+    break;
+  case 3:
+    if(!fxOverX0ShieldTrks || index<0 || index>=2*fNtracks) Error("CorrectForShieldMaterial","Incorrect usage of UseTGeo option!\n");
+    if(fxOverX0ShieldTrks[index]<0) {
+      if (!t->PropagateToTGeo(xToGo,1,xOverX0,lengthTimesMeanDensity)) return 0;
+      Double_t angle=TMath::Sqrt((1.+t->GetTgl()*t->GetTgl())/
+                                (1.-t->GetSnp()*t->GetSnp()));
+      fxOverX0ShieldTrks[index] = TMath::Abs(xOverX0)/angle;
+      fxTimesRhoShieldTrks[index] = TMath::Abs(lengthTimesMeanDensity)/angle;
+      return 1;
+    }
+    xOverX0 = fxOverX0ShieldTrks[index];
+    lengthTimesMeanDensity = fxTimesRhoShieldTrks[index];
+    break;
+  }
+
+  lengthTimesMeanDensity *= dir;
+
+  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
+  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
+
+  return 1;
+}
+//------------------------------------------------------------------------
+Int_t AliITStrackerMI::CorrectForLayerMaterial(AliITStrackMI *t,
+                                              Int_t layerindex,
+                                              Double_t oldGlobXYZ[3],
+                                              TString direction) {
+  //-------------------------------------------------------------------
+  // Propagate beyond layer and correct for material
+  // (material budget in different ways according to fUseTGeo value)
+  //-------------------------------------------------------------------
+
+  // Define budget mode:
+  // 0: material from AliITSRecoParam (hard coded)
+  // 1: material from TGeo (on the fly)
+  // 2: material from lut
+  // 3: material from TGeo (same for all hypotheses)
+  Int_t mode;
+  switch(fUseTGeo) {
+  case 0:
+    mode=0; 
+    break;    
+  case 1:
+    mode=1;
+    break;    
+  case 2:
+    mode=2;
+    break;
+  case 3:
+    if(fTrackingPhase.Contains("Clusters2Tracks"))
+      { mode=3; } else { mode=1; }
+    break;
+  case 4:
+    if(fTrackingPhase.Contains("Clusters2Tracks")) 
+      { mode=3; } else { mode=2; }
+    break;
+  default:
+    mode=0;
+    break;
+  }
+  if(fTrackingPhase.Contains("Default")) mode=0;
+
+  Float_t  dir = (direction.Contains("inward") ? 1. : -1.);
+
+  Double_t r=fgLayers[layerindex].GetR();
+  Double_t deltar=(layerindex<2 ? 0.10*r : 0.05*r);
+
+  Double_t rToGo=TMath::Sqrt(t->GetX()*t->GetX()+t->GetY()*t->GetY())-deltar*dir;
+  Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
+
+  Int_t index=6*fCurrentEsdTrack+layerindex;
+
+  // Bring the track beyond the material
+  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
+  Double_t globXYZ[3];
+  t->GetXYZ(globXYZ);
+
+  Double_t xOverX0=0.0,x0=0.0,lengthTimesMeanDensity=0.0;
+  Double_t mparam[7];
+  Bool_t anglecorr=kTRUE;
+
+  switch(mode) {
+  case 0:
+    xOverX0 = fgLayers[layerindex].GetThickness(t->GetY(),t->GetZ(),x0);
+    lengthTimesMeanDensity = xOverX0*x0;
+    break;
+  case 1:
+    AliTracker::MeanMaterialBudget(oldGlobXYZ,globXYZ,mparam);
+    if(mparam[1]>900000) return 0;
+    xOverX0=mparam[1];
+    lengthTimesMeanDensity=mparam[0]*mparam[4];
+    anglecorr=kFALSE;
+    break;
+  case 2:
+    if(fxOverX0Layer[layerindex]<0) BuildMaterialLUT("Layers");  
+    xOverX0 = fxOverX0Layer[layerindex];
+    lengthTimesMeanDensity = fxTimesRhoLayer[layerindex];
+    break;
+  case 3:
+    if(!fxOverX0LayerTrks || index<0 || index>=6*fNtracks) Error("CorrectForLayerMaterial","Incorrect usage of UseTGeo option!\n");
+    if(fxOverX0LayerTrks[index]<0) {
+      AliTracker::MeanMaterialBudget(oldGlobXYZ,globXYZ,mparam);
+      if(mparam[1]>900000) return 0;
+      Double_t angle=TMath::Sqrt((1.+t->GetTgl()*t->GetTgl())/
+                                (1.-t->GetSnp()*t->GetSnp()));
+      xOverX0=mparam[1]/angle;
+      lengthTimesMeanDensity=mparam[0]*mparam[4]/angle;
+      fxOverX0LayerTrks[index] = TMath::Abs(xOverX0);
+      fxTimesRhoLayerTrks[index] = TMath::Abs(lengthTimesMeanDensity);
+    }
+    xOverX0 = fxOverX0LayerTrks[index];
+    lengthTimesMeanDensity = fxTimesRhoLayerTrks[index];
+    break;
+  }
+
+  lengthTimesMeanDensity *= dir;
+
+  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
+
+  return 1;
+}
+//------------------------------------------------------------------------
+void AliITStrackerMI::MakeTrksMaterialLUT(Int_t ntracks) {
+  //-----------------------------------------------------------------
+  // Initialize LUT for storing material for each prolonged track
+  //-----------------------------------------------------------------
+  fxOverX0PipeTrks = new Float_t[ntracks]; 
+  fxTimesRhoPipeTrks = new Float_t[ntracks]; 
+  fxOverX0ShieldTrks = new Float_t[ntracks*2]; 
+  fxTimesRhoShieldTrks = new Float_t[ntracks*2]; 
+  fxOverX0LayerTrks = new Float_t[ntracks*6]; 
+  fxTimesRhoLayerTrks = new Float_t[ntracks*6]; 
+
+  for(Int_t i=0; i<ntracks; i++) {
+    fxOverX0PipeTrks[i] = -1.;
+    fxTimesRhoPipeTrks[i] = -1.;
+  }
+  for(Int_t j=0; j<ntracks*2; j++) {
+    fxOverX0ShieldTrks[j] = -1.;
+    fxTimesRhoShieldTrks[j] = -1.;
+  }
+  for(Int_t k=0; k<ntracks*6; k++) {
+    fxOverX0LayerTrks[k] = -1.;
+    fxTimesRhoLayerTrks[k] = -1.;
+  }
+
+  fNtracks = ntracks;  
+
+  return;
+}
+//------------------------------------------------------------------------
+void AliITStrackerMI::DeleteTrksMaterialLUT() {
+  //-----------------------------------------------------------------
+  // Delete LUT for storing material for each prolonged track
+  //-----------------------------------------------------------------
+  if(fxOverX0PipeTrks) { 
+    delete [] fxOverX0PipeTrks; fxOverX0PipeTrks = 0; 
+  } 
+  if(fxOverX0ShieldTrks) { 
+    delete [] fxOverX0ShieldTrks; fxOverX0ShieldTrks = 0; 
+  } 
+  
+  if(fxOverX0LayerTrks) { 
+    delete [] fxOverX0LayerTrks;  fxOverX0LayerTrks = 0; 
+  } 
+  if(fxTimesRhoPipeTrks) { 
+    delete [] fxTimesRhoPipeTrks;  fxTimesRhoPipeTrks = 0; 
+  } 
+  if(fxTimesRhoShieldTrks) { 
+    delete [] fxTimesRhoShieldTrks; fxTimesRhoShieldTrks = 0; 
+  } 
+  if(fxTimesRhoLayerTrks) { 
+    delete [] fxTimesRhoLayerTrks; fxTimesRhoLayerTrks = 0; 
+  } 
+  return;
+}
+//------------------------------------------------------------------------
+Int_t AliITStrackerMI::CheckSkipLayer(AliITStrackMI *track,
+                                     Int_t ilayer,Int_t idet) const {
+  //-----------------------------------------------------------------
+  // This method is used to decide whether to allow a prolongation 
+  // without clusters, because we want to skip the layer.
+  // In this case the return value is > 0:
+  // return 1: the user requested to skip a layer
+  // return 2: track outside z acceptance of SSD/SDD and will cross both SPD
+  //-----------------------------------------------------------------
+
+  if (AliITSReconstructor::GetRecoParam()->GetLayersToSkip(ilayer)) return 1;
+
+  if (idet<0 && ilayer>1 && AliITSReconstructor::GetRecoParam()->GetExtendedEtaAcceptance()) {
+    // check if track will cross SPD outer layer
+    Double_t phiAtSPD2,zAtSPD2;
+    if (track->GetPhiZat(fgLayers[1].GetR(),phiAtSPD2,zAtSPD2)) {
+      if (TMath::Abs(zAtSPD2)<2.*AliITSRecoParam::GetSPDdetzlength()) return 2;
+    }
+  }
+
+  return 0;
+}
+//------------------------------------------------------------------------
+Int_t AliITStrackerMI::CheckDeadZone(/*AliITStrackMI *track,*/
+                                    Int_t ilayer,Int_t idet,
+                                    Double_t zmin,Double_t zmax/*,Double_t ymin,Double_t ymax*/) const {
+  //-----------------------------------------------------------------
+  // This method is used to decide whether to allow a prolongation 
+  // without clusters, because there is a dead zone in the road.
+  // In this case the return value is > 0:
+  // return 1: dead zone at z=0,+-7cm in SPD
+  // return 2: dead area from the OCDB // NOT YET IMPLEMENTED
+  //-----------------------------------------------------------------
+
+  // check dead zones at z=0,+-7cm in the SPD
+  if (ilayer<2 && !AliITSReconstructor::GetRecoParam()->GetAddVirtualClustersInDeadZone()) {
+    Double_t zmindead[3]={fSPDdetzcentre[0] + 0.5*AliITSRecoParam::GetSPDdetzlength(),
+                         fSPDdetzcentre[1] + 0.5*AliITSRecoParam::GetSPDdetzlength(),
+                         fSPDdetzcentre[2] + 0.5*AliITSRecoParam::GetSPDdetzlength()};
+    Double_t zmaxdead[3]={fSPDdetzcentre[1] - 0.5*AliITSRecoParam::GetSPDdetzlength(),
+                         fSPDdetzcentre[2] - 0.5*AliITSRecoParam::GetSPDdetzlength(),
+                         fSPDdetzcentre[3] - 0.5*AliITSRecoParam::GetSPDdetzlength()};
+    for (Int_t i=0; i<3; i++)
+      if (zmin<zmaxdead[i] && zmax>zmindead[i]) return 1;  
+  }
+
+  // check dead zones from OCDB
+  if (!AliITSReconstructor::GetRecoParam()->GetUseDeadZonesFromOCDB()) return 0;
+
+  if(idet<0) return 0;
+
+  // look in OCDB (only entire dead modules for the moment)
+  if (ilayer==0 || ilayer==1) { // SPD
+    AliCDBEntry* cdbEntry = AliCDBManager::Instance()->Get("ITS/Calib/SPDDead");
+    if (!cdbEntry) {
+      Error("CheckDeadZone","Cannot get CDB entry for SPD\n");
+      return 0;
+    }
+    TObjArray* spdEntry = (TObjArray*)cdbEntry->GetObject();
+    if (!spdEntry) {
+      Error("CheckDeadZone","Cannot get CDB entry for SPD\n");
+      return 0;
+    }
+    if(ilayer==1) idet += AliITSgeomTGeo::GetNLadders(1)*AliITSgeomTGeo::GetNDetectors(1);
+    //printf("SPD det: %d\n",idet);
+    AliITSCalibrationSPD *calibSPD = (AliITSCalibrationSPD*)spdEntry->At(idet);
+    if (calibSPD->IsBad()) return 2;
+  } else if (ilayer==2 || ilayer==3) { // SDD
+    AliCDBEntry* cdbEntry = AliCDBManager::Instance()->Get("ITS/Calib/CalibSDD");
+    if (!cdbEntry) {
+      Error("CheckDeadZone","Cannot get CDB entry for SDD\n");
+      return 0;
+    }
+    TObjArray* sddEntry = (TObjArray*)cdbEntry->GetObject();
+    if (!sddEntry) {
+      Error("CheckDeadZone","Cannot get CDB entry for SDD\n");
+      return 0;
+    }
+    if(ilayer==3) idet += AliITSgeomTGeo::GetNLadders(3)*AliITSgeomTGeo::GetNDetectors(3);
+    //printf("SDD det: %d\n",idet);
+    AliITSCalibrationSDD *calibSDD = (AliITSCalibrationSDD*)sddEntry->At(idet);
+    if (calibSDD->IsDead()) return 2;
+  } else if (ilayer==4 || ilayer==5) { // SSD
+  } else {
+    Error("CheckDeadZone","Wrong layer number\n");
+    if(ilayer==5) idet += AliITSgeomTGeo::GetNLadders(5)*AliITSgeomTGeo::GetNDetectors(5);
+    return 0;
+  }
+
+  return 0;
+}
+//------------------------------------------------------------------------
+Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
+                                      AliITStrackMI *track,
+                                      Float_t &xloc,Float_t &zloc) const {
+  //-----------------------------------------------------------------
+  // Gives position of track in local module ref. frame
+  //-----------------------------------------------------------------
+
+  xloc=0.; 
+  zloc=0.;
+
+  if(idet<0) return kFALSE;
+
+  Int_t ndet=AliITSgeomTGeo::GetNDetectors(ilayer+1); // layers from 1 to 6 
 
+  Int_t lad = Int_t(idet/ndet) + 1;
 
+  Int_t det = idet - (lad-1)*ndet + 1;
 
+  Double_t xyzGlob[3],xyzLoc[3];
 
+  track->GetXYZ(xyzGlob);
 
+  AliITSgeomTGeo::GlobalToLocal(ilayer+1,lad,det,xyzGlob,xyzLoc);
 
+  xloc = (Float_t)xyzLoc[0];
+  zloc = (Float_t)xyzLoc[2];
 
+  return kTRUE;
+}
+//------------------------------------------------------------------------
+Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, Int_t ilayer) const {
+// Method still to be implemented: 
+//
+// it will apply a pre-selection to obtain good quality tracks.  
+// Here also  you will have the possibility to put a control on the 
+// impact point of the track on the basic block, in order to exclude border regions 
+// this will be done by calling a proper method of the AliITSPlaneEff class.  
+//
+// input: AliITStrackMI* track, ilayer= layer number [0,5]
+// output: Bool_t   -> kTRUE if usable track, kFALSE if not usable. 
+return kTRUE;
+}
+//------------------------------------------------------------------------
+void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
+//
+// This Method has to be optimized! For the time-being it uses the same criteria
+// as those used in the search of extra clusters for overlapping modules.
+//
+// Method Purpose: estabilish whether a track has produced a recpoint or not
+//                 in the layer under study (For Plane efficiency)
+//
+// inputs: AliITStrackMI* track  (pointer to a usable track)
+// outputs: none
+// side effects: update (by 1 count) the Plane Efficiency statistics of the basic block
+//               traversed by this very track. In details:
+//               - if a cluster can be associated to the track then call
+//                  AliITSPlaneEff::UpDatePlaneEff(key,kTRUE);
+//               - if not, the AliITSPlaneEff::UpDatePlaneEff(key,kFALSE) is called
+//
+  AliITSlayer &layer=fgLayers[ilayer];
+  Double_t r=layer.GetR();
+  //AliITStrackV2 tmp(*track);
+  AliITStrackMI tmp(*track);
+
+// detector number
+  Double_t phi,z;
+  if (!tmp.GetPhiZat(r,phi,z)) return;
+  Int_t idet=layer.FindDetectorIndex(phi,z);
+
+  if(idet<0) return;
+
+  Double_t trackGlobXYZ1[3];
+  tmp.GetXYZ(trackGlobXYZ1);
+
+// Get the budget to the primary vertex for the current track being prolonged
+  Double_t budgetToPrimVertex = GetEffectiveThickness();
+
+//propagate to the intersection with the detector plane
+  const AliITSdetector &det=layer.GetDetector(idet);
+  if (!tmp.Propagate(det.GetPhi(),det.GetR())) return;
+  
+  //Float_t xloc,zloc;
+
+//***************
+// DEFINITION OF SEARCH ROAD FOR CLUSTERS SELECTION
+//
+  Double_t dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
+                    TMath::Sqrt(tmp.GetSigmaZ2() +
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                    AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
+  Double_t dy=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY()*
+                    TMath::Sqrt(tmp.GetSigmaY2() +
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                    AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                    AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
+
+// road in global (rphi,z) [i.e. in tracking ref. system]
+  Double_t zmin = tmp.GetZ() - dz;
+  Double_t zmax = tmp.GetZ() + dz;
+  Double_t ymin = tmp.GetY() + r*det.GetPhi() - dy;
+  Double_t ymax = tmp.GetY() + r*det.GetPhi() + dy;
+
+// select clusters in road
+  layer.SelectClusters(zmin,zmax,ymin,ymax);
+
+// Define criteria for track-cluster association
+  Double_t msz = tmp.GetSigmaZ2() +
+  AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+  AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+  AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer);
+  Double_t msy = tmp.GetSigmaY2() +
+  AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+  AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+  AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer);
+ // if (constrain) {
+    msz *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadZC();
+    msy *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadYC();
+ // }  else {
+ //   msz *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadZNonC();
+ //   msy *= AliITSReconstructor::GetRecoParam()->GetNSigma2RoadYNonC();
+ // }
+  msz = 1./msz; // 1/RoadZ^2
+  msy = 1./msy; // 1/RoadY^2
+//
+
+  const AliITSRecPoint *cl=0; Int_t clidx=-1, ci=-1;
+  Int_t idetc=-1;
+  Double_t maxchi2=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2(), tolerance=0.1;
+  while ((cl=layer.GetNextCluster(clidx))!=0) {
+    idetc = cl->GetDetectorIndex();
+    if(idet!=idetc) continue;
+    //Int_t ilay = cl->GetLayer();
+
+    if (TMath::Abs(tmp.GetZ() - cl->GetZ()) > tolerance) continue;
+    if (TMath::Abs(tmp.GetY() - cl->GetY()) > tolerance) continue;
+
+    Double_t chi2=tmp.GetPredictedChi2(cl);
+    if (chi2<maxchi2) { maxchi2=chi2; ci=clidx; }
+  }
+  Float_t locx; // to be changed (if no cluster)
+  Float_t locz; // to be changed (if no cluster)
+  LocalModuleCoord(ilayer,idet,&tmp,locx,locz);
+//
+  AliDebug(2,Form("ilayer= %d, idet=%d, x= %f, z=%f",ilayer,idet,locx,locz));
+  UInt_t key=fPlaneEff->GetKeyFromDetLocCoord(ilayer,idet,locx,locz);
+  if(key>fPlaneEff->Nblock()) return;
+  Bool_t found=kFALSE;
+  if (ci>=0) {
+    cl=layer.GetCluster(ci);
+    // here real control to see whether the cluster can be associated to the track.  
+    // if() ....
+    found=kTRUE;
+   // track->SetExtraCluster(ilayer,(ilayer<<28)+ci);
+   // track->SetExtraModule(ilayer,idetExtra);
+  }
+  if(!fPlaneEff->UpDatePlaneEff(found,key))
+       AliError(Form("UseTrackForPlaneEff: cannot UpDate PlaneEff for key=%d",key));
+return;
+}