]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerMI.cxx
Bug fix: adding SHLIB to SYSLIBS (C.Holm)
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
index b4a9abb9c8ad8e14466382d7a75ffdbfd49588e1..97cc085c21f050df658e7353ea8a79913ff2aaf1 100644 (file)
@@ -31,7 +31,6 @@
 #include <TString.h>
 #include <TRandom.h>
 
-
 #include "AliESDEvent.h"
 #include "AliESDtrack.h"
 #include "AliESDVertex.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)
 
@@ -63,7 +71,7 @@ fLastLayerToTrackTo(0),
 fCoefficients(0),
 fEsd(0),
 fTrackingPhase("Default"),
-fUseTGeo(0),
+fUseTGeo(3),
 fNtracks(0),
 fxOverX0Pipe(-1.),
 fxTimesRhoPipe(-1.),
@@ -73,7 +81,8 @@ fxOverX0ShieldTrks(0),
 fxTimesRhoShieldTrks(0),
 fxOverX0LayerTrks(0),
 fxTimesRhoLayerTrks(0),
-fDebugStreamer(0){
+fDebugStreamer(0),
+fPlaneEff(0) {
   //Default constructor
   Int_t i;
   for(i=0;i<4;i++) fSPDdetzcentre[i]=0.;
@@ -95,7 +104,7 @@ fLastLayerToTrackTo(AliITSRecoParam::GetLastLayerToTrackTo()),
 fCoefficients(0),
 fEsd(0),
 fTrackingPhase("Default"),
-fUseTGeo(0),
+fUseTGeo(3),
 fNtracks(0),
 fxOverX0Pipe(-1.),
 fxTimesRhoPipe(-1.),
@@ -105,7 +114,8 @@ fxOverX0ShieldTrks(0),
 fxTimesRhoShieldTrks(0),
 fxOverX0LayerTrks(0),
 fxTimesRhoLayerTrks(0),
-fDebugStreamer(0){
+fDebugStreamer(0),
+fPlaneEff(0) {
   //--------------------------------------------------------------------
   //This is the AliITStrackerMI constructor
   //--------------------------------------------------------------------
@@ -187,12 +197,33 @@ fDebugStreamer(0){
   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(AliITSReconstructor::GetRecoParam()->GetReadPlaneEffFromOCDB())
+       if(!fPlaneEff->ReadFromCDB()) {AliWarning("AliITStrackerMI reading of AliITSPlaneEff from OCDB failed") ;}
+    if(AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) {
+      fPlaneEff->SetCreateHistos(kTRUE); 
+      //fPlaneEff->ReadHistosFromFile();
+    }
+  }
 }
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITStrackerMI(const AliITStrackerMI &tracker):AliTracker(tracker),
@@ -219,7 +250,8 @@ fxOverX0ShieldTrks(0),
 fxTimesRhoShieldTrks(0),
 fxOverX0LayerTrks(0),
 fxTimesRhoLayerTrks(0),
-fDebugStreamer(tracker.fDebugStreamer){
+fDebugStreamer(tracker.fDebugStreamer),
+fPlaneEff(tracker.fPlaneEff) {
   //Copy constructor
   Int_t i;
   for(i=0;i<4;i++) {
@@ -300,7 +332,7 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
        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(),
@@ -327,7 +359,7 @@ Int_t AliITStrackerMI::LoadClusters(TTree *cTree) {
          if (TMath::Abs(fgLayers[i].GetDetector(detector).GetZmax()-hit[1])<zwindow) 
            fgLayers[i].InsertCluster(new AliITSRecPoint(lab,hit,info,local));
        }
-      }
+      } // "virtual" clusters in SPD
       
     }
     //
@@ -370,6 +402,8 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   // This functions reconstructs ITS tracks
   // The clusters must be already loaded !
   //--------------------------------------------------------------------
+
+
   fTrackingPhase="Clusters2Tracks";
 
   TObjArray itsTracks(15000);
@@ -408,6 +442,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
@@ -445,13 +481,13 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   fTrackHypothesys.Expand(nentr);
   fBestHypothesys.Expand(nentr);
   MakeCoefficients(nentr);
-  if(fUseTGeo==3 || fUseTGeo==4) MakeTrksMaterialLUT(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 (fCurrentEsdTrack=0; fCurrentEsdTrack<nentr; fCurrentEsdTrack++) {
-       //cerr<<fPass<<"    "<<fCurrentEsdTrack<<'\r';
+       //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
@@ -465,11 +501,12 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        fI = 6;
        ResetTrackToFollow(*t);
        ResetBestTrack();
+
        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();
@@ -486,11 +523,9 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
      GetBestHypothesysMIP(itsTracks); 
   } // end loop on the two tracking passes
 
-  //GetBestHypothesysMIP(itsTracks);
   if(event->GetNumberOfV0s()>0) UpdateTPCV0(event);
   if(AliITSReconstructor::GetRecoParam()->GetFindV0s()) FindV02(event);
   fAfterV0 = kTRUE;
-  //GetBestHypothesysMIP(itsTracks);
   //
   itsTracks.Delete();
   //
@@ -616,7 +651,8 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
       fTrackToFollow.ResetCovariance(10.);
 
     //Refitting...
-    if (RefitAt(AliITSRecoParam::GetrInsideSPD1(), &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);
@@ -625,8 +661,10 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
 
        //The beam pipe
        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);
@@ -774,6 +812,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
@@ -815,18 +854,20 @@ 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--) {
+    fI = ilayer;
     //
-    AliITSlayer &layer=fgLayers[ilayer]; 
-    Double_t r=layer.GetR();    
-    Double_t deltar=(ilayer<2 ? 0.10*r : 0.05*r);
+    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++) {
       //set current track
@@ -846,29 +887,47 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       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;
-      
-      //propagate to the intersection
-      const AliITSdetector &det=layer.GetDetector(idet);
-      new(&currenttrack2)  AliITStrackMI(currenttrack1);
 
       Double_t trackGlobXYZ1[3];
       currenttrack1.GetXYZ(trackGlobXYZ1);
 
+      // 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);
-      
-      fI = ilayer;
-      // 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)
-      Double_t budgetToPrimVertex = GetEffectiveThickness();
 
       //***************
       // DEFINITION OF SEARCH ROAD FOR CLUSTERS SELECTION
@@ -899,11 +958,12 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        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); 
       //********************
@@ -933,13 +993,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
@@ -974,18 +1076,28 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        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 (changedet) {
+           Float_t xlocnewdet,zlocnewdet;
+           LocalModuleCoord(ilayer,idet,updatetrack,xlocnewdet,zlocnewdet); // local module coords
+           updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xlocnewdet,zlocnewdet);
+         } else {
+           updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
          }
          if (cl->IsUsed()) updatetrack->IncrementNUsed();
 
@@ -1006,22 +1118,29 @@ 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) {   
-       // Bring the track beyond the material
-       currenttrack1.AliExternalTrackParam::PropagateTo(currenttrack1.GetX()-deltar,GetBz());
+      } // 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
-       // Bring the track beyond the material
-       currenttrack1.AliExternalTrackParam::PropagateTo(currenttrack1.GetX()-deltar,GetBz());
+      // 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]++;
@@ -1059,7 +1178,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
@@ -1071,7 +1189,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);
   }
 
@@ -1092,7 +1212,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]];
@@ -1453,14 +1573,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");
     }
   }
 
@@ -1501,10 +1621,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
@@ -1552,7 +1674,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];
@@ -1566,6 +1688,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::
@@ -1579,26 +1703,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];
@@ -1608,17 +1736,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];
     }
   }
@@ -1761,7 +1888,7 @@ Double_t AliITStrackerMI::GetEffectiveThickness()
 }
 //------------------------------------------------------------------------
 Int_t AliITStrackerMI::AliITSlayer::InRoad() const {
-  //--------------------------------------------------------------------
+  //-------------------------------------------------------------------
   // This function returns number of clusters within the "window" 
   //--------------------------------------------------------------------
   Int_t ncl=0;
@@ -1782,266 +1909,241 @@ 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[AliITSgeomTGeo::kNLayers];
   Int_t k;
   for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) index[k]=-1;
-  Int_t nc=c->GetNumberOfClusters();
+  Int_t nc=clusters->GetNumberOfClusters();
   for (k=0; k<nc; k++) { 
-    Int_t idx=c->GetClusterIndex(k),nl=(idx&0xf0000000)>>28;
-    index[nl]=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<AliITSgeomTGeo::GetNLayers(); 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=AliITSgeomTGeo::GetNLayers();
-      step=+1;
-  } else {
-      from=AliITSgeomTGeo::GetNLayers()-1; to=innermostlayer-1;
-      step=-1;
+    Int_t idx=clusters->GetClusterIndex(k);
+    Int_t ilayer=(idx&0xf0000000)>>28;
+    index[ilayer]=idx; 
   }
-  TString dir=(step>0 ? "outward" : "inward");
-
-  // 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-3.5)<0.01) // SDDouter
-       if(!CorrectForShieldMaterial(t,"SDD",dir)) return kFALSE;
-     if (TMath::Abs(hI-1.5)<0.01) // SPDouter
-       if(!CorrectForShieldMaterial(t,"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);
-     }
-     //
-
-     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);
-     }
-
-     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));
-     }
-     //
-
-     // Correct for material of the current layer
-     if(!CorrectForLayerMaterial(t,i,oldGlobXYZ,dir)) return kFALSE;
-
-  } // 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[AliITSgeomTGeo::kNLayers];
   Int_t k;
   for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) index[k]=-1;
   //
   for (k=0; k<AliITSgeomTGeo::GetNLayers(); k++) { 
-    index[k]=clindex[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<AliITSgeomTGeo::GetNLayers(); 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()) {
+  if (xx > track->GetX()) {
       from=innermostlayer; to=AliITSgeomTGeo::GetNLayers();
       step=+1;
   } else {
       from=AliITSgeomTGeo::GetNLayers()-1; to=innermostlayer-1;
       step=-1;
   }
-  TString dir=(step>0 ? "outward" : "inward");
+  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; 
+     Double_t hI=ilayer-0.5*step; 
      if (TMath::Abs(hI-3.5)<0.01) // SDDouter
-       if(!CorrectForShieldMaterial(t,"SDD",dir)) return kFALSE;
+       if(!CorrectForShieldMaterial(track,"SDD",dir)) return kFALSE;
      if (TMath::Abs(hI-1.5)<0.01) // SPDouter
-       if(!CorrectForShieldMaterial(t,"SPD",dir)) return kFALSE;
+       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);
+
+     // 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
+
+     Double_t dz,zmin,zmax;
 
-     const AliITSRecPoint *cl=0;
+     const AliITSRecPoint *clAcc=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;
-         }
-       }
+     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
+         // Plane Eff determination: 
+         if (planeeff && AliITSReconstructor::GetRecoParam()->GetLayersToSkip(ilayer)) { 
+           if (IsOKForPlaneEff(track,ilayer))  // only adequate track for plane eff. evaluation
+              UseTrackForPlaneEff(track,ilayer); 
+         }
+       } else {
+        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
+       }
      }
-
-     if (cl) {
-       if (!UpdateMI(t,cl,maxchi2,idx)) return kFALSE;
-       t->SetSampledEdx(cl->GetQ(),t->GetNumberOfClusters()-1);
+     
+     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(t,i,oldGlobXYZ,dir)) return kFALSE;
+     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;
 }
 //------------------------------------------------------------------------
@@ -2131,7 +2233,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())*
@@ -2181,7 +2289,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) 
@@ -2748,7 +2856,8 @@ void AliITStrackerMI::AddTrackHypothesys(AliITStrackMI * track, Int_t esdindex)
   // add track to the list of hypothesys
   //------------------------------------------------------------------
 
-  if (esdindex>=fTrackHypothesys.GetEntriesFast()) fTrackHypothesys.Expand(esdindex*2+10);
+  if (esdindex>=fTrackHypothesys.GetEntriesFast()) 
+    fTrackHypothesys.Expand(TMath::Max(fTrackHypothesys.GetSize(),esdindex*2+10));
   //
   TObjArray * array = (TObjArray*) fTrackHypothesys.At(esdindex);
   if (!array) {
@@ -3029,7 +3138,8 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
   delete forwardtrack;
   Int_t accepted=0;
   for (Int_t i=0;i<entries;i++){    
-    AliITStrackMI * track = (AliITStrackMI*)array->At(i);   
+    AliITStrackMI * track = (AliITStrackMI*)array->At(i);
+   
     if (!track) continue;
     
     if (accepted>checkmax || track->GetChi2MIP(3)>AliITSReconstructor::GetRecoParam()->GetMaxChi2PerCluster(3)*6. || 
@@ -3047,6 +3157,7 @@ AliITStrackMI * AliITStrackerMI::GetBestHypothesys(Int_t esdindex, AliITStrackMI
   //
   array->Compress();
   SortTrackHypothesys(esdindex,checkmax,1);
+
   array = (TObjArray*) fTrackHypothesys.At(esdindex);
   if (!array) return 0; // PH What can be the reason? Check SortTrackHypothesys
   besttrack = (AliITStrackMI*)array->At(0);  
@@ -3057,7 +3168,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;
@@ -3349,15 +3460,22 @@ Int_t AliITStrackerMI::UpdateMI(AliITStrackMI* track, const AliITSRecPoint* cl,D
 
   if (cl->GetQ()<=0) return 0;  // ingore the "virtual" clusters
 
-  //Float_t clxyz[3]; cl->GetGlobalXYZ(clxyz);Double_t trxyz[3]; track->GetXYZ(trxyz);printf("gtr %f %f %f\n",trxyz[0],trxyz[1],trxyz[2]);printf("gcl %f %f %f\n",clxyz[0],clxyz[1],clxyz[2]);
+  //  Float_t clxyz[3]; cl->GetGlobalXYZ(clxyz);Double_t trxyz[3]; track->GetXYZ(trxyz);//printf("gtr %f %f %f\n",trxyz[0],trxyz[1],trxyz[2]);printf("gcl %f %f %f\n",clxyz[0],clxyz[1],clxyz[2]);
 
 
   // Take into account the mis-alignment
   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));
+
+  return track->UpdateMI(&c,chi2,index);
 }
+
 //------------------------------------------------------------------------
 void AliITStrackerMI::GetDCASigma(AliITStrackMI* track, Float_t & sigmarfi, Float_t &sigmaz)
 {
@@ -3454,7 +3572,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};
@@ -3932,11 +4050,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);
@@ -4490,7 +4612,6 @@ Int_t AliITStrackerMI::CorrectForShieldMaterial(AliITStrackMI *t,
     shieldindex=0;
   } else {
     Error("CorrectForShieldMaterial"," Wrong shield name\n");
-    //    printf("%s\n",shield.Data());
     return 0;
   }
   Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
@@ -4692,10 +4813,397 @@ void AliITStrackerMI::DeleteTrksMaterialLUT() {
   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->IsBad()) 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 2f usable track, kFALSE if not usable. 
+  if(!fPlaneEff) 
+    {AliWarning("IsOKForPlaneEff: null pointer to AliITSPlaneEff"); return kFALSE;}
+  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 kFALSE;
+  Int_t idet=layer.FindDetectorIndex(phi,z);
+  if(idet<0) { AliInfo(Form("cannot find detector"));
+    return kFALSE;}
+
+  // here check if it has good Chi Square.
+
+  //propagate to the intersection with the detector plane
+  const AliITSdetector &det=layer.GetDetector(idet);
+  if (!tmp.Propagate(det.GetPhi(),det.GetR())) return kFALSE;
+
+  Float_t locx; //
+  Float_t locz; //
+  LocalModuleCoord(ilayer,idet,&tmp,locx,locz);
+  UInt_t key=fPlaneEff->GetKeyFromDetLocCoord(ilayer,idet,locx,locz);
+  if(key>fPlaneEff->Nblock()) return kFALSE;
+  Float_t blockXmn,blockXmx,blockZmn,blockZmx;
+  if (!fPlaneEff->GetBlockBoundaries(key,blockXmn,blockXmx,blockZmn,blockZmx)) return kFALSE;
+  // transform Local boundaries of the basic block into 
+  //  Global (i.e. ALICE, not tracking reference) coordinate
+  //
+  Double_t a1[3]={blockXmn,0.,blockZmn};
+  Double_t a2[3]={blockXmx,0.,blockZmn};
+  Double_t a3[3]={blockXmn,0.,blockZmx};
+  Int_t ndet=AliITSgeomTGeo::GetNDetectors(ilayer+1); // layers from 1 to 6
+  Int_t lad = Int_t(idet/ndet) + 1;
+  Int_t hdet = idet - (lad-1)*ndet + 1;
+  Double_t xyzGlob[3];
+  AliITSgeomTGeo::LocalToGlobal(ilayer+1,lad,hdet,a1,a1);
+  AliITSgeomTGeo::LocalToGlobal(ilayer+1,lad,hdet,a2,a2);
+  AliITSgeomTGeo::LocalToGlobal(ilayer+1,lad,hdet,a3,a3);
+  Double_t gBlockYmn,gBlockYmx,gBlockZmn,gBlockZmx;
+  if(a1[1]>a2[1]) {gBlockYmn=a2[1]; gBlockYmx=a1[1];}
+  else            {gBlockYmn=a1[1]; gBlockYmx=a2[1];}
+  if(a2[2]>a3[2]) {gBlockZmn=a3[2]; gBlockZmx=a2[2];}
+  else            {gBlockZmn=a2[2]; gBlockZmx=a3[2];}
+  AliDebug(2,Form("Boundaries in Global system Ymin=%f, Ymax=%f, Zmin=%f, Zmax=%f", 
+           gBlockYmn,gBlockYmx,gBlockZmn,gBlockZmx));
+
+  //***************
+  // DEFINITION OF SEARCH ROAD FOR accepting a track 
+  //
+  //For the time being they are hard-wired, later on from AliITSRecoParam
+  Double_t dz=4.*TMath::Sqrt(tmp.GetSigmaZ2());  // those are precisions in the tracking reference system
+  Double_t dy=4.*TMath::Sqrt(tmp.GetSigmaY2());  // dy needs to be reduced (it is max now) if you do  
+                                                 // comparison in Global Reference system 
+  Float_t gdz=dz;
+  Float_t gdy=dy*TMath::Abs(TMath::Cos(tmp.GetAlpha()));
+
+ // exclude tracks at boundary between detectors
+  //Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidth();
+  Double_t boundaryWidth=0; // for the time being hard-wired, later on from AliITSRecoParam
+  AliDebug(2,Form("Tracking: track impact x=%f, y=%f, z=%f",tmp.GetX(), tmp.GetY(), tmp.GetZ()));
+  tmp.GetXYZ(xyzGlob);
+  AliDebug(2,Form("Global:   track impact x=%f, y=%f, z=%f",xyzGlob[0],xyzGlob[1],xyzGlob[2]));
+  //AliInfo(Form("TEST GLOBAL track y = %f, z=%f",tmp.GetY(),tmp.GetZ()));
+  AliDebug(2,Form("Search Road. Tracking: dy=%f , dz=%f",dy,dz));
+  AliDebug(2,Form("Search Road. Global: Gdy=%f , Gdz=%f",gdy,gdz));
+  if ( (xyzGlob[1]-gdy < gBlockYmn+boundaryWidth) ||
+       (xyzGlob[1]+gdy > gBlockYmx-boundaryWidth) ||
+       (xyzGlob[2]-gdz < gBlockZmn+boundaryWidth) ||
+       (xyzGlob[2]+gdz > gBlockZmx-boundaryWidth) ) return kFALSE;
+
+  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
+//
+  if(!fPlaneEff)
+    {AliWarning("UseTrackForPlaneEff: null pointer to AliITSPlaneEff"); return;}
+  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) { AliInfo(Form("cannot find detector"));
+    return;}
+
+  //Double_t trackGlobXYZ1[3];
+  //tmp.GetXYZ(trackGlobXYZ1);
+
+//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 (tmp.GetConstrain()) {
+    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 chi2trkcl=1000.*AliITSReconstructor::GetRecoParam()->GetMaxChi2();
+  //Double_t  tolerance=0.2;
+  /*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<chi2trkcl) { chi2trkcl=chi2; ci=clidx; }
+  }*/
+  Float_t locx; //
+  Float_t locz; //
+  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) {
+  Double_t chi2;
+  while ((cl=layer.GetNextCluster(clidx))!=0) {
+    idetc = cl->GetDetectorIndex();
+    if(idet!=idetc) continue;
+    // here real control to see whether the cluster can be associated to the track.
+    // cluster not associated to track
+    if ( (tmp.GetZ()-cl->GetZ())*(tmp.GetZ()-cl->GetZ())*msz +
+         (tmp.GetY()-cl->GetY())*(tmp.GetY()-cl->GetY())*msy   > 1. ) continue;
+    // calculate track-clusters chi2
+    chi2 = GetPredictedChi2MI(&tmp,cl,ilayer); // note that this method change track tmp
+                                               // in particular, the error associated to the cluster 
+    //Double_t chi2 = tmp.GetPredictedChi(cl); // this method does not change track tmp
+    // chi2 cut
+    if (chi2 > AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)) continue;
+    found=kTRUE;
+    if (chi2<chi2trkcl) { chi2trkcl=chi2; ci=clidx; } // this just to trace which cluster is selected
+   // track->SetExtraCluster(ilayer,(ilayer<<28)+ci);
+   // track->SetExtraModule(ilayer,idetExtra);
+  }
+  if(!fPlaneEff->UpDatePlaneEff(found,key))
+       AliWarning(Form("UseTrackForPlaneEff: cannot UpDate PlaneEff for key=%d",key));
+  if(fPlaneEff->GetCreateHistos()&&  AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) {
+    Float_t tr[4]={99999.,99999.,9999.,9999.};    // initialize to high values 
+    Float_t clu[4]={-99999.,-99999.,9999.,9999.}; // (in some cases GetCov fails) 
+    Int_t cltype[2]={-999,-999};
+    Int_t ndet=AliITSgeomTGeo::GetNDetectors(ilayer+1); // layers from 1 to 6
+    Int_t lad = Int_t(idet/ndet) + 1;
+    Int_t hdet = idet - (lad-1)*ndet + 1;
+    Double_t xyzGlob[3],xyzLoc[3],cv[21],exyzLoc[3],exyzGlob[3];
+    if(tmp.GetXYZ(xyzGlob)) {
+      if (AliITSgeomTGeo::GlobalToLocal(ilayer+1,lad,hdet,xyzGlob,xyzLoc)) {
+        tr[0]=xyzLoc[0];
+        tr[1]=xyzLoc[2];
+      }
+    }
+    if(tmp.GetCovarianceXYZPxPyPz(cv)) {
+      exyzGlob[0]=TMath::Sqrt(cv[0]);
+      exyzGlob[1]=TMath::Sqrt(cv[2]);
+      exyzGlob[2]=TMath::Sqrt(cv[5]);
+      if (AliITSgeomTGeo::GlobalToLocalVect(AliITSgeomTGeo::GetModuleIndex(ilayer+1,lad,hdet),exyzGlob,exyzLoc)) { 
+        tr[2]=TMath::Abs(exyzLoc[0]);
+        tr[3]=TMath::Abs(exyzLoc[2]);
+      }
+    }
+    if (found){
+      clu[0]=layer.GetCluster(ci)->GetDetLocalX();
+      clu[1]=layer.GetCluster(ci)->GetDetLocalZ();
+      cltype[0]=layer.GetCluster(ci)->GetNy();
+      cltype[1]=layer.GetCluster(ci)->GetNz();
+     
+     // Without the following 6 lines you would retrieve the nominal error of a cluster (e.g. for the SPD:
+     //  X->50/sqrt(12)=14 micron   Z->450/sqrt(12)= 120 micron) 
+     // Within AliTrackerMI/AliTrackMI the error on the cluster is associated to the AliITStrackMI (fSigmaY,Z)
+     // It is computed properly by calling the method 
+     // AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSRecPoint *cluster,Int_t layer)
+     // T
+     //Double_t x=0.5*(tmp.GetX()+layer.GetCluster(ci)->GetX()); // Take into account the mis-alignment
+      //if (tmp.PropagateTo(x,0.,0.)) {
+        chi2=GetPredictedChi2MI(&tmp,layer.GetCluster(ci),ilayer);
+        AliCluster c(*layer.GetCluster(ci));
+        c.SetSigmaY2(tmp.GetSigmaY(ilayer)*tmp.GetSigmaY(ilayer));
+        c.SetSigmaZ2(tmp.GetSigmaZ(ilayer)*tmp.GetSigmaZ(ilayer));
+        Float_t cov[6];
+        //if (layer.GetCluster(ci)->GetGlobalCov(cov))  // by using this, instead, you got nominal cluster errors
+        if (c.GetGlobalCov(cov)) 
+        {
+          exyzGlob[0]=TMath::Sqrt(cov[0]);
+          exyzGlob[1]=TMath::Sqrt(cov[3]);
+          exyzGlob[2]=TMath::Sqrt(cov[5]);
+          if (AliITSgeomTGeo::GlobalToLocalVect(AliITSgeomTGeo::GetModuleIndex(ilayer+1,lad,hdet),exyzGlob,exyzLoc)) {
+            clu[2]=TMath::Abs(exyzLoc[0]);  
+            clu[3]=TMath::Abs(exyzLoc[2]);  
+          }
+        }
+      //}
+    }
+    fPlaneEff->FillHistos(key,found,tr,clu,cltype);
+  }
+return;
+}