]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerMI.cxx
When calculating a*a-b*b the form (a-b)*(a+b) is usually more numerically stable.
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
index 0bef1f784fe7ef6aff0dfc4ee6d84a5687885241..300815ad56698589622331bd901d68f28fe3a699 100644 (file)
@@ -34,6 +34,7 @@
 #include <TRandom.h>
 
 
+#include "AliLog.h"
 #include "AliESDEvent.h"
 #include "AliESDtrack.h"
 #include "AliESDVertex.h"
@@ -171,6 +172,14 @@ fPlaneEff(0) {
 
         AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1); 
         new(&det) AliITSdetector(r,phi); 
+       // compute the real radius (with misalignment)
+        TGeoHMatrix mmisal(*(AliITSgeomTGeo::GetMatrix(i,j,k)));
+        mmisal.Multiply(tm);
+       xyz[0]=0.;xyz[1]=0.;xyz[2]=0.;
+        mmisal.LocalToMaster(txyz,xyz);
+        Double_t rmisal=TMath::Sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
+       det.SetRmisal(rmisal);
+       
       } // end loop on detectors
     } // end loop on ladders
   } // end loop on layers
@@ -219,21 +228,15 @@ fPlaneEff(0) {
 
   // 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
-      }
-    }
+    Int_t iplane=AliITSReconstructor::GetRecoParam()->GetIPlanePlaneEff();
+    if(AliITSReconstructor::GetRecoParam()->GetLayersToSkip(iplane))
+      AliWarning(Form("Evaluation of Plane Eff for layer %d will be attempted without removing it from tracker",iplane));
+    if (iplane<2) fPlaneEff = new AliITSPlaneEffSPD();
+    else if (iplane<4) fPlaneEff = new AliITSPlaneEffSDD();
+    else fPlaneEff = new AliITSPlaneEffSSD();
     if(AliITSReconstructor::GetRecoParam()->GetReadPlaneEffFromOCDB())
-      if(!fPlaneEff->ReadFromCDB()) 
-       {AliWarning("AliITStrackerMI reading of AliITSPlaneEff from OCDB failed") ;}
-    if(AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) {
-      fPlaneEff->SetCreateHistos(kTRUE); 
-      //fPlaneEff->ReadHistosFromFile();
-    }
+       if(!fPlaneEff->ReadFromCDB()) {AliWarning("AliITStrackerMI reading of AliITSPlaneEff from OCDB failed") ;}
+    if(AliITSReconstructor::GetRecoParam()->GetHistoPlaneEff()) fPlaneEff->SetCreateHistos(kTRUE);
   }
 }
 //------------------------------------------------------------------------
@@ -317,24 +320,27 @@ void AliITStrackerMI::ReadBadFromDetTypeRec() {
 
   if(!AliITSReconstructor::GetRecoParam()->GetUseBadZonesFromOCDB()) return;
 
-  Info("ReadBadFromDetTypeRec","Reading info about bad ITS detectors and channels\n");
+  Info("ReadBadFromDetTypeRec","Reading info about bad ITS detectors and channels");
 
   if(!fDetTypeRec) Error("ReadBadFromDetTypeRec","AliITSDetTypeRec nof found!\n");
 
   // ITS channels map
   if(fITSChannelStatus) delete fITSChannelStatus;
-  fITSChannelStatus = new AliITSChannelStatus(AliCDBManager::Instance());
+  fITSChannelStatus = new AliITSChannelStatus(fDetTypeRec);
 
   // ITS detectors and chips
   Int_t i=0,j=0,k=0,ndet=0;
   for (i=1; i<AliITSgeomTGeo::GetNLayers()+1; i++) {
+    Int_t nBadDetsPerLayer=0;
     ndet=AliITSgeomTGeo::GetNDetectors(i);    
     for (j=1; j<AliITSgeomTGeo::GetNLadders(i)+1; j++) {
       for (k=1; k<ndet+1; k++) {
         AliITSdetector &det=fgLayers[i-1].GetDetector((j-1)*ndet + k-1);  
        det.ReadBadDetectorAndChips(i-1,(j-1)*ndet + k-1,fDetTypeRec);
+       if(det.IsBad()) {nBadDetsPerLayer++;}
       } // end loop on detectors
     } // end loop on ladders
+    Info("ReadBadFromDetTypeRec",Form("Layer %d: %d bad out of %d",i-1,nBadDetsPerLayer,ndet*AliITSgeomTGeo::GetNLadders(i)));
   } // end loop on layers
   
   return;
@@ -493,6 +499,8 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
     Info("Clusters2Tracks", "Number of ESD tracks: %d\n", nentr);
     while (nentr--) {
       AliESDtrack *esd=event->GetTrack(nentr);
+      //  ---- for debugging:
+      //if(TMath::Abs(esd->GetX()-83.65)<0.1) { FILE *f=fopen("tpc.dat","a"); fprintf(f,"%f %f %f %f %f %f\n",(Float_t)event->GetEventNumberInFile(),(Float_t)TMath::Abs(esd->GetLabel()),(Float_t)esd->GetX(),(Float_t)esd->GetY(),(Float_t)esd->GetZ(),(Float_t)esd->Pt()); fclose(f); }
 
       if ((esd->GetStatus()&AliESDtrack::kTPCin)==0) continue;
       if (esd->GetStatus()&AliESDtrack::kTPCout) continue;
@@ -553,9 +561,9 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
   for (fPass=0; fPass<2; fPass++) {
      Int_t &constraint=fConstraint[fPass]; if (constraint<0) continue;
      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
+       //cout<<"========== "<<fPass<<"    "<<fCurrentEsdTrack<<" =========\n";
        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.
        if (fConstraint[fPass]) { 
@@ -564,11 +572,13 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        }
 
        Int_t tpcLabel=t->GetLabel(); //save the TPC track label       
+       AliDebug(2,Form("LABEL %d pass %d",tpcLabel,fPass));
        fI = 6;
        ResetTrackToFollow(*t);
        ResetBestTrack();
 
        FollowProlongationTree(t,fCurrentEsdTrack,fConstraint[fPass]);
 
        SortTrackHypothesys(fCurrentEsdTrack,20,0);  //MI change
        //
@@ -584,7 +594,8 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
        if (fConstraint[fPass]&&(!besttrack->IsGoldPrimary())) continue;  //to be tracked also without vertex constrain 
 
        t->SetReconstructed(kTRUE);
-       ntrk++;                     
+       ntrk++;  
+       AliDebug(2,Form("TRACK! (label %d) ncls %d",besttrack->GetLabel(),besttrack->GetNumberOfClusters()));
      }
      GetBestHypothesysMIP(itsTracks); 
   } // end loop on the two tracking passes
@@ -718,7 +729,9 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
 
     //Refitting...
     Bool_t pe=AliITSReconstructor::GetRecoParam()->GetComputePlaneEff();
+    AliDebug(2,Form("Refit LABEL %d  %d",t->GetLabel(),t->GetNumberOfClusters()));
     if (RefitAt(AliITSRecoParam::GetrInsideSPD1(),&fTrackToFollow,t,kTRUE,pe)) {
+       AliDebug(2,"  refit OK");
        fTrackToFollow.SetLabel(t->GetLabel());
        //       fTrackToFollow.CookdEdx();
        CookdEdx(&fTrackToFollow);
@@ -731,7 +744,7 @@ Int_t AliITStrackerMI::RefitInward(AliESDEvent *event) {
         AliESDtrack  *esdTrack =fTrackToFollow.GetESDtrack();
         //printf("                                       %d\n",esdTrack->GetITSModuleIndex(0));
         //esdTrack->UpdateTrackParams(&fTrackToFollow,AliESDtrack::kITSrefit); //original line
-        Float_t r[3]={0.,0.,0.};
+        Double_t r[3]={0.,0.,0.};
         Double_t maxD=3.;
         esdTrack->RelateToVertex(event->GetVertex(),GetBz(r),maxD);
         ntrk++;
@@ -771,7 +784,8 @@ Bool_t AliITStrackerMI::GetTrackPoint(Int_t index, AliTrackPoint& p) const {
   cl->GetGlobalXYZ(xyz);
   cl->GetGlobalCov(cov);
   p.SetXYZ(xyz, cov);
-
+  p.SetCharge(cl->GetQ());
+  p.SetDriftTime(cl->GetDriftTime());
   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; 
   switch (l) {
   case 0:
@@ -812,6 +826,7 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   Int_t c=(index & 0x0fffffff) >> 00;
   const AliITSRecPoint *cl = fgLayers[l].GetCluster(c);
   Int_t idet = cl->GetDetectorIndex();
+
   const AliITSdetector &det=fgLayers[l].GetDetector(idet);
 
   // tgphi and tglambda of the track in tracking frame with alpha=det.GetPhi
@@ -820,7 +835,7 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   detxy[1] = det.GetR()*TMath::Sin(det.GetPhi());
   Double_t alpha = t->GetAlpha();
   Double_t xdetintrackframe = detxy[0]*TMath::Cos(alpha)+detxy[1]*TMath::Sin(alpha);
-  Float_t phi = TMath::ASin(t->GetSnpAt(xdetintrackframe,AliTracker::GetBz()));
+  Float_t phi = TMath::ASin(t->GetSnpAt(xdetintrackframe,GetBz()));
   phi += alpha-det.GetPhi();
   Float_t tgphi = TMath::Tan(phi);
 
@@ -828,7 +843,8 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   Float_t expQ = TMath::Max(0.8*t->GetTPCsignal(),30.);
 
   Float_t errlocalx,errlocalz;
-  AliITSClusterParam::GetError(l,cl,tgl,tgphi,expQ,errlocalx,errlocalz);
+  Bool_t addMisalErr=kFALSE;
+  AliITSClusterParam::GetError(l,cl,tgl,tgphi,expQ,errlocalx,errlocalz,addMisalErr);
 
   Float_t xyz[3];
   Float_t cov[6];
@@ -839,6 +855,8 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
   tmpcl.GetGlobalCov(cov);
 
   p.SetXYZ(xyz, cov);
+  p.SetCharge(cl->GetQ());
+  p.SetDriftTime(cl->GetDriftTime());
 
   AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; 
   switch (l) {
@@ -865,6 +883,7 @@ Bool_t AliITStrackerMI::GetTrackPointTrackingError(Int_t index,
     break;
   };
   UShort_t volid = AliGeomManager::LayerToVolUID(iLayer,idet);
+
   p.SetVolumeID((UShort_t)volid);
   return kTRUE;
 }
@@ -926,6 +945,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
   //
   // follow prolongations
   for (Int_t ilayer=5; ilayer>=0; ilayer--) {
+    AliDebug(2,Form("FollowProlongationTree: layer %d",ilayer));
     fI = ilayer;
     //
     AliITSlayer &layer=fgLayers[ilayer];
@@ -959,7 +979,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       Int_t idet=layer.FindDetectorIndex(phi,z);
 
       Double_t trackGlobXYZ1[3];
-      currenttrack1.GetXYZ(trackGlobXYZ1);
+      if (!currenttrack1.GetXYZ(trackGlobXYZ1)) continue;
 
       // Get the budget to the primary vertex for the current track being prolonged
       Double_t budgetToPrimVertex = GetEffectiveThickness();
@@ -969,15 +989,16 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       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());
+       Double_t xToGo; if (!vtrack->GetLocalXat(r,xToGo)) continue;
+       if(!vtrack->Propagate(xToGo)) continue;
        // 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(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;
@@ -990,46 +1011,17 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       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());
+      if (!currenttrack2.Propagate(det.GetPhi(),det.GetR())) continue;
       currenttrack1.SetDetectorIndex(idet);
       currenttrack2.SetDetectorIndex(idet);
+      if(!LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc)) continue; // local module coords
 
       //***************
-      // DEFINITION OF SEARCH ROAD FOR CLUSTERS SELECTION
+      // DEFINITION OF SEARCH ROAD AND CLUSTERS SELECTION
       //
-      Double_t dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
-                    TMath::Sqrt(currenttrack1.GetSigmaZ2() + 
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
-                   AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
-      Double_t dy=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY()*
-                    TMath::Sqrt(currenttrack1.GetSigmaY2() + 
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
-                   AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
-      
-      // track at boundary between detectors, enlarge road
-      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.;
-       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+deltaXNeighbDets*deltaXNeighbDets*snp*snp);
-      } // boundary
-      
       // 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;
+      Double_t zmin,zmax,ymin,ymax;
+      if (!ComputeRoad(&currenttrack1,ilayer,idet,zmin,zmax,ymin,ymax)) continue;
 
       // select clusters in road
       layer.SelectClusters(zmin,zmax,ymin,ymax); 
@@ -1053,6 +1045,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       }
       msz = 1./msz; // 1/RoadZ^2
       msy = 1./msy; // 1/RoadY^2
+
       //
       //
       // LOOP OVER ALL POSSIBLE TRACK PROLONGATIONS ON THIS LAYER
@@ -1066,7 +1059,11 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
       // check if the road contains a dead zone 
       Bool_t noClusters = kFALSE;
       if (!layer.GetNextCluster(clidx,kTRUE)) noClusters=kTRUE;
-      Int_t dead = CheckDeadZone(&currenttrack1,ilayer,idet,zmin,zmax,ymin,ymax,noClusters); 
+      if (noClusters) AliDebug(2,"no clusters in road");
+      Double_t dz=0.5*(zmax-zmin);
+      Double_t dy=0.5*(ymax-ymin);
+      Int_t dead = CheckDeadZone(&currenttrack1,ilayer,idet,dz,dy,noClusters); 
+      if(dead) AliDebug(2,Form("DEAD (%d)\n",dead));
       // create a prolongation without clusters (check also if there are no clusters in the road)
       if (dead || 
          (noClusters && 
@@ -1114,15 +1111,23 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        Int_t idetc=cl->GetDetectorIndex();
 
        if (currenttrack->GetDetectorIndex()==idetc) { // track already on the cluster's detector
+         // take into account misalignment (bring track to real detector plane)
+         Double_t xTrOrig = currenttrack->GetX();
+         if (!currenttrack->Propagate(xTrOrig+cl->GetX())) continue;
          // a first cut on track-cluster distance
          if ( (currenttrack->GetZ()-cl->GetZ())*(currenttrack->GetZ()-cl->GetZ())*msz + 
               (currenttrack->GetY()-cl->GetY())*(currenttrack->GetY()-cl->GetY())*msy > 1. ) 
-           continue; // cluster not associated to track
+           {  // cluster not associated to track
+             AliDebug(2,"not associated");
+             continue;
+           }
+         // bring track back to ideal detector plane
+         if (!currenttrack->Propagate(xTrOrig)) continue;
        } else {                                      // have to move track to cluster's detector
          const AliITSdetector &detc=layer.GetDetector(idetc);
          // a first cut on track-cluster distance
          Double_t y;
-         if (!currenttrack2.GetProlongationFast(detc.GetPhi(),detc.GetR(),y,z)) continue;
+         if (!currenttrack2.GetProlongationFast(detc.GetPhi(),detc.GetR()+cl->GetX(),y,z)) continue;
          if ( (z-cl->GetZ())*(z-cl->GetZ())*msz + 
               (y-cl->GetY())*(y-cl->GetY())*msy > 1. ) 
            continue; // cluster not associated to track
@@ -1144,6 +1149,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        // calculate track-clusters chi2
        chi2trkcl = GetPredictedChi2MI(currenttrack,cl,ilayer); 
        // chi2 cut
+       AliDebug(2,Form("chi2 %f max %f",chi2trkcl,AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)));
        if (chi2trkcl < AliITSReconstructor::GetRecoParam()->GetMaxChi2s(ilayer)) {
          if (cl->GetQ()==0) deadzoneSPD=kTRUE; // only 1 prolongation with virtual cluster       
          if (ntracks[ilayer]>=100) continue;
@@ -1152,7 +1158,10 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          if (changedet) new (&currenttrack2) AliITStrackMI(backuptrack);
 
          if (cl->GetQ()!=0) { // real cluster
-           if (!UpdateMI(updatetrack,cl,chi2trkcl,(ilayer<<28)+clidx)) continue; 
+           if (!UpdateMI(updatetrack,cl,chi2trkcl,(ilayer<<28)+clidx)) {
+             AliDebug(2,"update failed");
+             continue;
+           } 
            updatetrack->SetSampledEdx(cl->GetQ(),updatetrack->GetNumberOfClusters()-1); //b.b.
            modstatus = 1; // found
          } else {             // virtual cluster in dead zone
@@ -1163,8 +1172,9 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
 
          if (changedet) {
            Float_t xlocnewdet,zlocnewdet;
-           LocalModuleCoord(ilayer,idet,updatetrack,xlocnewdet,zlocnewdet); // local module coords
-           updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xlocnewdet,zlocnewdet);
+           if(LocalModuleCoord(ilayer,idet,updatetrack,xlocnewdet,zlocnewdet)) { // local module coords
+             updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xlocnewdet,zlocnewdet);
+           }
          } else {
            updatetrack->SetModuleIndexInfo(ilayer,idet,modstatus,xloc,zloc);
          }
@@ -1187,6 +1197,10 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
          } //apply vertex constrain              
          ntracks[ilayer]++;
        }  // create new hypothesis
+       else {
+         AliDebug(2,"chi2 too large");
+       }
+
       } // loop over possible prolongations 
      
       // allow one prolongation without clusters
@@ -1681,6 +1695,58 @@ Int_t AliITStrackerMI::AliITSlayer::FindClusterIndex(Float_t z) const {
   return m;
 }
 //------------------------------------------------------------------------
+Bool_t AliITStrackerMI::ComputeRoad(AliITStrackMI* track,Int_t ilayer,Int_t idet,Double_t &zmin,Double_t &zmax,Double_t &ymin,Double_t &ymax) const {
+  //--------------------------------------------------------------------
+  // This function computes the rectangular road for this track
+  //--------------------------------------------------------------------
+
+
+  AliITSdetector &det = fgLayers[ilayer].GetDetector(idet);
+  // take into account the misalignment: propagate track to misaligned detector plane
+  if (!track->Propagate(det.GetPhi(),det.GetRmisal())) return kFALSE;
+
+  Double_t dz=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadZ()*
+                    TMath::Sqrt(track->GetSigmaZ2() + 
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
+                   AliITSReconstructor::GetRecoParam()->GetSigmaZ2(ilayer));
+  Double_t dy=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY()*
+                    TMath::Sqrt(track->GetSigmaY2() + 
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
+                   AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
+      
+  // track at boundary between detectors, enlarge road
+  Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidth();
+  if ( (track->GetY()-dy < det.GetYmin()+boundaryWidth) || 
+       (track->GetY()+dy > det.GetYmax()-boundaryWidth) || 
+       (track->GetZ()-dz < det.GetZmin()+boundaryWidth) ||
+       (track->GetZ()+dz > det.GetZmax()-boundaryWidth) ) {
+    Float_t tgl = TMath::Abs(track->GetTgl());
+    if (tgl > 1.) tgl=1.;
+    Double_t deltaXNeighbDets=AliITSRecoParam::GetDeltaXNeighbDets();
+    dz = TMath::Sqrt(dz*dz+deltaXNeighbDets*deltaXNeighbDets*tgl*tgl);
+    Float_t snp = TMath::Abs(track->GetSnp());
+    if (snp > AliITSReconstructor::GetRecoParam()->GetMaxSnp()) return kFALSE;
+    dy = TMath::Sqrt(dy*dy+deltaXNeighbDets*deltaXNeighbDets*snp*snp);
+  } // boundary
+  
+  // add to the road a term (up to 2-3 mm) to deal with misalignments
+  dy = TMath::Sqrt(dy*dy + AliITSReconstructor::GetRecoParam()->GetRoadMisal()*AliITSReconstructor::GetRecoParam()->GetRoadMisal());
+  dz = TMath::Sqrt(dz*dz + AliITSReconstructor::GetRecoParam()->GetRoadMisal()*AliITSReconstructor::GetRecoParam()->GetRoadMisal());
+
+  Double_t r = fgLayers[ilayer].GetR();
+  zmin = track->GetZ() - dz; 
+  zmax = track->GetZ() + dz;
+  ymin = track->GetY() + r*det.GetPhi() - dy;
+  ymax = track->GetY() + r*det.GetPhi() + dy;
+
+  // bring track back to idead detector plane
+  if (!track->Propagate(det.GetPhi(),det.GetR())) return kFALSE;
+
+  return kTRUE;
+}
+//------------------------------------------------------------------------
 void AliITStrackerMI::AliITSlayer::
 SelectClusters(Double_t zmin,Double_t zmax,Double_t ymin, Double_t ymax) {
   //--------------------------------------------------------------------
@@ -1932,6 +1998,7 @@ const {
 //------------------------------------------------------------------------
 AliITStrackerMI::AliITSdetector::AliITSdetector(const AliITSdetector& det):
 fR(det.fR),
+fRmisal(det.fRmisal),
 fPhi(det.fPhi),
 fSinPhi(det.fSinPhi),
 fCosPhi(det.fCosPhi),
@@ -1972,13 +2039,14 @@ void AliITStrackerMI::AliITSdetector::ReadBadDetectorAndChips(Int_t ilayer,Int_t
 
   // Get calibration from AliITSDetTypeRec
   AliITSCalibration *calib = (AliITSCalibration*)detTypeRec->GetCalibrationModel(idet);
+  calib->SetModuleIndex(idet);
   AliITSCalibration *calibSPDdead = 0;
   if(detType==0) calibSPDdead = (AliITSCalibration*)detTypeRec->GetSPDDeadModel(idet); // TEMPORARY
   if (calib->IsBad() ||
       (detType==0 && calibSPDdead->IsBad())) // TEMPORARY
     {
       SetBad();
-      printf("lay %d bad %d\n",ilayer,idet);
+      //      printf("lay %d bad %d\n",ilayer,idet);
     }
 
   // Get segmentation from AliITSDetTypeRec
@@ -1992,6 +2060,7 @@ void AliITStrackerMI::AliITSdetector::ReadBadDetectorAndChips(Int_t ilayer,Int_t
   for (Int_t iCh=0;iCh<fNChips;iCh++) {
     fChipIsBad[iCh] = calib->IsChipBad(iCh);
     if (detType==0 && calibSPDdead->IsChipBad(iCh)) fChipIsBad[iCh] = kTRUE; // TEMPORARY
+    //if(fChipIsBad[iCh]) {printf("lay %d det %d bad chip %d\n",ilayer,idet,iCh);}
   }
 
   return;
@@ -2136,12 +2205,13 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      // remember old position [SR, GSI 18.02.2003]
      Double_t oldX=0., oldY=0., oldZ=0.;
      if (track->IsStartedTimeIntegral() && step==1) {
-        track->GetGlobalXYZat(track->GetX(),oldX,oldY,oldZ);
+        if (!track->GetGlobalXYZat(track->GetX(),oldX,oldY,oldZ)) return kFALSE;
      }
      //
 
      Double_t oldGlobXYZ[3];
-     track->GetXYZ(oldGlobXYZ);
+     if (!track->GetXYZ(oldGlobXYZ)) return kFALSE;
+     //TMath::Sqrt(track->GetSigmaY2());
 
      Double_t phi,z;
      if (!track->GetPhiZat(r,phi,z)) return kFALSE;
@@ -2152,17 +2222,18 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      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());
+       Double_t xToGo; if (!track->GetLocalXat(r,xToGo)) return kFALSE;
+       if (!track->Propagate(xToGo)) return kFALSE;
        // 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);
+       if(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);
+        if (!track->GetGlobalXYZat(track->GetX(),newX,newY,newZ)) return kFALSE;
         Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
                        (oldZ-newZ)*(oldZ-newZ);
         track->AddTimeStep(TMath::Sqrt(dL2));
@@ -2173,11 +2244,10 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      if (idet<0) return kFALSE;
 
      const AliITSdetector &det=layer.GetDetector(idet);
-     phi=det.GetPhi();
-     if (!track->Propagate(phi,det.GetR())) return kFALSE;
+     if (!track->Propagate(det.GetPhi(),det.GetR())) return kFALSE;
 
      track->SetDetectorIndex(idet);
-     LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
+     if(!LocalModuleCoord(ilayer,idet,track,xloc,zloc)) return kFALSE; // local module coords
 
      Double_t dz,zmin,zmax,dy,ymin,ymax;
 
@@ -2194,9 +2264,8 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
           const AliITSdetector &detc=layer.GetDetector(idet);
           if (!track->Propagate(detc.GetPhi(),detc.GetR())) return kFALSE;
           track->SetDetectorIndex(idet);
-          LocalModuleCoord(ilayer,idet,track,xloc,zloc); // local module coords
+          if(!LocalModuleCoord(ilayer,idet,track,xloc,zloc)) return kFALSE; // 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) { 
@@ -2210,29 +2279,18 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      } 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); 
+         // Plane Eff determination:
+         if (planeeff && ilayer==AliITSReconstructor::GetRecoParam()->GetIPlanePlaneEff()) {
+           if (IsOKForPlaneEff(track,clusters,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;
-        dy=AliITSReconstructor::GetRecoParam()->GetNSigmaRoadY()*
-                    TMath::Sqrt(track->GetSigmaY2() + 
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
-                   AliITSReconstructor::GetRecoParam()->GetNSigmaYLayerForRoadY()*
-                   AliITSReconstructor::GetRecoParam()->GetSigmaY2(ilayer));
-        ymin=track->GetY() - dy;
-        ymax=track->GetY() + dy;
-        Int_t dead = CheckDeadZone(track,ilayer,idet,zmin,zmax,ymin,ymax,kTRUE);
+        if (!ComputeRoad(track,ilayer,idet,zmin,zmax,ymin,ymax)) return kFALSE;
+        dz = 0.5*(zmax-zmin);
+        dy = 0.5*(ymax-ymin);
+        Int_t dead = CheckDeadZone(track,ilayer,idet,dz,dy,kTRUE);
         if (dead==1) modstatus = 7; // holes in z in SPD
         if (dead==2 || dead==3) modstatus = 2; // dead from OCDB
        }
@@ -2247,15 +2305,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
 
      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;
+       if (!ComputeRoad(track,ilayer,idet,zmin,zmax,ymin,ymax)) return kFALSE;
        layer.SelectClusters(zmin,zmax,ymin,ymax);
        
        const AliITSRecPoint *clExtra=0; Int_t ci=-1,cci=-1;
@@ -2269,10 +2319,10 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
         
         const AliITSdetector &detx=layer.GetDetector(idetExtra);
         
-        if (!tmp.Propagate(detx.GetPhi(),detx.GetR())) continue;
-        
+        if (!tmp.Propagate(detx.GetPhi(),detx.GetR()+clExtra->GetX())) continue;
         if (TMath::Abs(tmp.GetZ() - clExtra->GetZ()) > tolerance) continue;
         if (TMath::Abs(tmp.GetY() - clExtra->GetY()) > tolerance) continue;
+        if (!tmp.Propagate(detx.GetPhi(),detx.GetR())) continue;
         
         Double_t chi2=tmp.GetPredictedChi2(clExtra);
         if (chi2<maxchi2) { maxchi2=chi2; cci=ci; }
@@ -2289,7 +2339,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      // 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);
+        if (!track->GetGlobalXYZat(track->GetX(),newX,newY,newZ)) return kFALSE;
         Double_t dL2 = (oldX-newX)*(oldX-newX) + (oldY-newY)*(oldY-newY) + 
                        (oldZ-newZ)*(oldZ-newZ);
         track->AddTimeStep(TMath::Sqrt(dL2));
@@ -2409,8 +2459,10 @@ Double_t AliITStrackerMI::GetMatchingChi2(AliITStrackMI * track1, AliITStrackMI
 {
   //
   // return matching chi2 between two tracks
+  Double_t largeChi2=1000.;
+
   AliITStrackMI track3(*track2);
-  track3.Propagate(track1->GetAlpha(),track1->GetX());
+  if (!track3.Propagate(track1->GetAlpha(),track1->GetX())) return largeChi2;
   TMatrixD vec(5,1);
   vec(0,0)=track1->GetY()   - track3.GetY();
   vec(1,0)=track1->GetZ()   - track3.GetZ();
@@ -3497,6 +3549,7 @@ void AliITStrackerMI::CookLabel(AliITStrackMI *track,Float_t wrong) const {
      for (Int_t ind=0;ind<3;ind++){
        if (tpcLabel>0)
         if (cl->GetLabel(ind)==tpcLabel) isWrong=0;
+       AliDebug(2,Form("icl %d  ilab %d lab %d",i,ind,cl->GetLabel(ind)));
      }
      track->SetChi2MIP(9,track->GetChi2MIP(9)+isWrong*(2<<l));
      nwrong+=isWrong;
@@ -3509,6 +3562,7 @@ void AliITStrackerMI::CookLabel(AliITStrackMI *track,Float_t wrong) const {
      else
        track->SetLabel(tpcLabel);
    }
+   AliDebug(2,Form(" nls %d wrong %d  label %d  tpcLabel %d\n",nclusters,nwrong,track->GetLabel(),tpcLabel));
    
 }
 //------------------------------------------------------------------------
@@ -3577,9 +3631,17 @@ Double_t AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSR
   Float_t erry,errz;
   Float_t theta = track->GetTgl();
   Float_t phi   = track->GetSnp();
-  phi = TMath::Sqrt(phi*phi/(1.-phi*phi));
+  phi = TMath::Abs(phi)*TMath::Sqrt(1./((1.-phi)*(1.+phi)));
   AliITSClusterParam::GetError(layer,cluster,theta,phi,track->GetExpQ(),erry,errz);
+  AliDebug(2,Form(" chi2: tr-cl   %f  %f   tr X %f cl X %f",track->GetY()-cluster->GetY(),track->GetZ()-cluster->GetZ(),track->GetX(),cluster->GetX()));
+  // Take into account the mis-alignment (bring track to cluster plane)
+  Double_t xTrOrig=track->GetX();
+  if (!track->Propagate(xTrOrig+cluster->GetX())) return 1000.;
+  AliDebug(2,Form(" chi2: tr-cl   %f  %f   tr X %f cl X %f",track->GetY()-cluster->GetY(),track->GetZ()-cluster->GetZ(),track->GetX(),cluster->GetX()));
   Double_t chi2 = track->GetPredictedChi2MI(cluster->GetY(),cluster->GetZ(),erry,errz);
+  // Bring the track back to detector plane in ideal geometry
+  // [mis-alignment will be accounted for in UpdateMI()]
+  if (!track->Propagate(xTrOrig)) return 1000.;
   Float_t ny,nz;
   AliITSClusterParam::GetNTeor(layer,cluster,theta,phi,ny,nz);  
   Double_t delta = cluster->GetNy()+cluster->GetNz()-nz-ny;
@@ -3593,7 +3655,7 @@ Double_t AliITStrackerMI::GetPredictedChi2MI(AliITStrackMI* track, const AliITSR
   track->SetSigmaY(layer,erry);
   track->SetSigmaZ(layer, errz);
   //track->fNormQ[layer] = cluster->GetQ()/TMath::Sqrt(1+theta*theta+phi*phi);
-  track->SetNormQ(layer,cluster->GetQ()/TMath::Sqrt((1.+ track->GetTgl()*track->GetTgl())/(1.- track->GetSnp()*track->GetSnp())));
+  track->SetNormQ(layer,cluster->GetQ()/TMath::Sqrt((1.+ track->GetTgl()*track->GetTgl())/((1.-track->GetSnp())*(1.+track->GetSnp()))));
   return chi2;
 
 }
@@ -3614,20 +3676,29 @@ 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]);
 
+  // Take into account the mis-alignment (bring track to cluster plane)
+  Double_t xTrOrig=track->GetX();
+  Float_t clxyz[3]; cl->GetGlobalXYZ(clxyz);Double_t trxyz[3]; track->GetXYZ(trxyz);
+  AliDebug(2,Form("gtr %f %f %f",trxyz[0],trxyz[1],trxyz[2]));
+  AliDebug(2,Form("gcl %f %f %f",clxyz[0],clxyz[1],clxyz[2]));
+  AliDebug(2,Form(" xtr %f  xcl %f",track->GetX(),cl->GetX()));
 
-  // Take into account the mis-alignment
-  Double_t x=track->GetX()+cl->GetX();
-  if (!track->PropagateTo(x,0.,0.)) return 0;
-
+  if (!track->Propagate(xTrOrig+cl->GetX())) return 0;
 
   
   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);
+
+  Int_t updated = track->UpdateMI(&c,chi2,index);
+
+  // Bring the track back to detector plane in ideal geometry
+  if (!track->Propagate(xTrOrig)) return 0;
+
+  if(!updated) AliDebug(2,"update failed");
+  return updated;
 }
 
 //------------------------------------------------------------------------
@@ -3987,9 +4058,9 @@ void AliITStrackerMI::FindV02(AliESDEvent *event)
     //I.B. trackat0 = *bestLong;
     new (&trackat0) AliITStrackMI(*bestLong);
     Double_t xx,yy,zz,alpha; 
-    bestLong->GetGlobalXYZat(bestLong->GetX(),xx,yy,zz);
+    if (!bestLong->GetGlobalXYZat(bestLong->GetX(),xx,yy,zz)) continue;
     alpha = TMath::ATan2(yy,xx);    
-    trackat0.Propagate(alpha,0);      
+    if (!trackat0.Propagate(alpha,0)) continue;      
     // calculate normalized distances to the vertex 
     //
     Float_t ptfac  = (1.+100.*TMath::Abs(trackat0.GetC()));
@@ -4355,7 +4426,7 @@ void AliITStrackerMI::FindV02(AliESDEvent *event)
        if (fnorm0<0) fnorm0*=-3;
        Float_t fnorm1 = normdist[itrack1];
        if (fnorm1<0) fnorm1*=-3;
-       if (pvertex->GetAnglep()[2]>0.1 ||  (pvertex->GetRr()<10.5)&& pvertex->GetAnglep()[2]>0.05 || pvertex->GetRr()<3){
+       if ((pvertex->GetAnglep()[2]>0.1) || ( (pvertex->GetRr()<10.5)&& pvertex->GetAnglep()[2]>0.05 ) || (pvertex->GetRr()<3)){
          pb0    =  TMath::Exp(-TMath::Min(fnorm0,Float_t(16.))/12.);
          pb1    =  TMath::Exp(-TMath::Min(fnorm1,Float_t(16.))/12.);
        }
@@ -4574,8 +4645,8 @@ void AliITStrackerMI::BuildMaterialLUT(TString material) {
   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};
+  Double_t rmin[9]={ 3.5, 5.5,13.0,22.0,35.0,41.0, 2.0, 8.0,25.0};
+  Double_t rmax[9]={ 5.5, 8.0,17.0,26.0,41.0,47.0, 3.0,10.5,30.0};
 
   Int_t ifirst=0,ilast=0;  
   if(material.Contains("Pipe")) {
@@ -4642,9 +4713,9 @@ Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
 
   // Define budget mode:
   // 0: material from AliITSRecoParam (hard coded)
-  // 1: material from TGeo (on the fly)
+  // 1: material from TGeo in one step (on the fly)
   // 2: material from lut
-  // 3: material from TGeo (same for all hypotheses)
+  // 3: material from TGeo in one step (same for all hypotheses)
   Int_t mode;
   switch(fUseTGeo) {
   case 0:
@@ -4674,7 +4745,8 @@ Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
 
   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 xToGo;
+  if (!t->GetLocalXat(rToGo,xToGo)) return 0;
 
   Double_t xOverX0,x0,lengthTimesMeanDensity;
   Bool_t anglecorr=kTRUE;
@@ -4684,36 +4756,39 @@ Int_t AliITStrackerMI::CorrectForPipeMaterial(AliITStrackMI *t,
     xOverX0 = AliITSRecoParam::GetdPipe();
     x0 = AliITSRecoParam::GetX0Be();
     lengthTimesMeanDensity = xOverX0*x0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 1:
     if (!t->PropagateToTGeo(xToGo,1)) return 0;
-    return 1;
     break;
   case 2:
     if(fxOverX0Pipe<0) BuildMaterialLUT("Pipe");  
     xOverX0 = fxOverX0Pipe;
     lengthTimesMeanDensity = fxTimesRhoPipe;
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     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()));
+                                ((1.-t->GetSnp())*(1.+t->GetSnp())));
       fxOverX0PipeTrks[index] = TMath::Abs(xOverX0)/angle;
       fxTimesRhoPipeTrks[index] = TMath::Abs(lengthTimesMeanDensity)/angle;
       return 1;
     }
     xOverX0 = fxOverX0PipeTrks[index];
     lengthTimesMeanDensity = fxTimesRhoPipeTrks[index];
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   }
 
-  lengthTimesMeanDensity *= dir;
-
-  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
-  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
-
   return 1;
 }
 //------------------------------------------------------------------------
@@ -4727,9 +4802,10 @@ Int_t AliITStrackerMI::CorrectForShieldMaterial(AliITStrackMI *t,
 
   // Define budget mode:
   // 0: material from AliITSRecoParam (hard coded)
-  // 1: material from TGeo (on the fly)
+  // 1: material from TGeo in steps of X cm (on the fly)
+  //    X = AliITSRecoParam::GetStepSizeTGeo()
   // 2: material from lut
-  // 3: material from TGeo (same for all hypotheses)
+  // 3: material from TGeo in one step (same for all hypotheses)
   Int_t mode;
   switch(fUseTGeo) {
   case 0:
@@ -4768,48 +4844,54 @@ Int_t AliITStrackerMI::CorrectForShieldMaterial(AliITStrackMI *t,
     Error("CorrectForShieldMaterial"," Wrong shield name\n");
     return 0;
   }
-  Double_t xToGo; t->GetLocalXat(rToGo,xToGo);
+  Double_t xToGo;
+  if (!t->GetLocalXat(rToGo,xToGo)) return 0;
 
   Int_t index=2*fCurrentEsdTrack+shieldindex;
 
   Double_t xOverX0,x0,lengthTimesMeanDensity;
   Bool_t anglecorr=kTRUE;
+  Int_t nsteps=1;
 
   switch(mode) {
   case 0:
     xOverX0 = AliITSRecoParam::Getdshield(shieldindex);
     x0 = AliITSRecoParam::GetX0shield(shieldindex);
     lengthTimesMeanDensity = xOverX0*x0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 1:
-    if (!t->PropagateToTGeo(xToGo,1)) return 0;
-    return 1;
+    nsteps= (Int_t)(TMath::Abs(t->GetX()-xToGo)/AliITSReconstructor::GetRecoParam()->GetStepSizeTGeo())+1;
+    if (!t->PropagateToTGeo(xToGo,nsteps)) return 0; // cross the material and apply correction
     break;
   case 2:
     if(fxOverX0Shield[shieldindex]<0) BuildMaterialLUT("Shields");  
     xOverX0 = fxOverX0Shield[shieldindex];
     lengthTimesMeanDensity = fxTimesRhoShield[shieldindex];
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     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()));
+                                ((1.-t->GetSnp())*(1.+t->GetSnp())));
       fxOverX0ShieldTrks[index] = TMath::Abs(xOverX0)/angle;
       fxTimesRhoShieldTrks[index] = TMath::Abs(lengthTimesMeanDensity)/angle;
       return 1;
     }
     xOverX0 = fxOverX0ShieldTrks[index];
     lengthTimesMeanDensity = fxTimesRhoShieldTrks[index];
+    lengthTimesMeanDensity *= dir;
+    if (!t->Propagate(xToGo)) return 0;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   }
 
-  lengthTimesMeanDensity *= dir;
-
-  if (!t->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) return 0;
-  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
-
   return 1;
 }
 //------------------------------------------------------------------------
@@ -4824,9 +4906,10 @@ Int_t AliITStrackerMI::CorrectForLayerMaterial(AliITStrackMI *t,
 
   // Define budget mode:
   // 0: material from AliITSRecoParam (hard coded)
-  // 1: material from TGeo (on the fly)
+  // 1: material from TGeo in stepsof X cm (on the fly)
+  //    X = AliITSRecoParam::GetStepSizeTGeo()
   // 2: material from lut
-  // 3: material from TGeo (same for all hypotheses)
+  // 3: material from TGeo in one step (same for all hypotheses)
   Int_t mode;
   switch(fUseTGeo) {
   case 0:
@@ -4858,43 +4941,55 @@ Int_t AliITStrackerMI::CorrectForLayerMaterial(AliITStrackMI *t,
   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);
+  Double_t xToGo;
+  if (!t->GetLocalXat(rToGo,xToGo)) return 0;
 
   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;
+  Int_t nsteps=1;
+  Double_t rOld,xOld;
 
+  Bool_t addTime = kFALSE;
   switch(mode) {
   case 0:
     xOverX0 = fgLayers[layerindex].GetThickness(t->GetY(),t->GetZ(),x0);
     lengthTimesMeanDensity = xOverX0*x0;
+    // Bring the track beyond the material
+    if (!t->Propagate(xToGo)) return 0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 1:
-    AliTracker::MeanMaterialBudget(oldGlobXYZ,globXYZ,mparam);
-    if(mparam[1]>900000) return 0;
-    xOverX0=mparam[1];
-    lengthTimesMeanDensity=mparam[0]*mparam[4];
-    anglecorr=kFALSE;
+    rOld=TMath::Sqrt(oldGlobXYZ[0]*oldGlobXYZ[0]+oldGlobXYZ[1]*oldGlobXYZ[1]);
+    if (!t->GetLocalXat(rOld,xOld)) return 0;
+    if (!t->Propagate(xOld)) return 0; // back before material (no correction)
+    nsteps = (Int_t)(TMath::Abs(xOld-xToGo)/AliITSReconstructor::GetRecoParam()->GetStepSizeTGeo())+1;
+    if (!t->PropagateToTGeo(xToGo,nsteps,addTime)) return 0; // cross the material and apply correction
     break;
   case 2:
     if(fxOverX0Layer[layerindex]<0) BuildMaterialLUT("Layers");  
     xOverX0 = fxOverX0Layer[layerindex];
     lengthTimesMeanDensity = fxTimesRhoLayer[layerindex];
+    // Bring the track beyond the material
+    if (!t->Propagate(xToGo)) return 0;
+    lengthTimesMeanDensity *= dir;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   case 3:
     if(!fxOverX0LayerTrks || index<0 || index>=6*fNtracks) Error("CorrectForLayerMaterial","Incorrect usage of UseTGeo option!\n");
-    if(fxOverX0LayerTrks[index]<0) {
+    // Bring the track beyond the material
+    if (!t->Propagate(xToGo)) return 0;
+    Double_t globXYZ[3];
+    if (!t->GetXYZ(globXYZ)) return 0;
+    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()));
+                                ((1.-t->GetSnp())*(1.+t->GetSnp())));
       xOverX0=mparam[1]/angle;
       lengthTimesMeanDensity=mparam[0]*mparam[4]/angle;
       fxOverX0LayerTrks[index] = TMath::Abs(xOverX0);
@@ -4902,13 +4997,11 @@ Int_t AliITStrackerMI::CorrectForLayerMaterial(AliITStrackMI *t,
     }
     xOverX0 = fxOverX0LayerTrks[index];
     lengthTimesMeanDensity = fxTimesRhoLayerTrks[index];
+    lengthTimesMeanDensity *= dir;
+    if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
     break;
   }
 
-  lengthTimesMeanDensity *= dir;
-
-  if (!t->CorrectForMeanMaterial(xOverX0,lengthTimesMeanDensity,anglecorr)) return 0;  
-
   return 1;
 }
 //------------------------------------------------------------------------
@@ -4992,8 +5085,7 @@ Int_t AliITStrackerMI::CheckSkipLayer(AliITStrackMI *track,
 //------------------------------------------------------------------------
 Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
                                     Int_t ilayer,Int_t idet,
-                                    Double_t zmin,Double_t zmax,
-                                    Double_t ymin,Double_t ymax,
+                                    Double_t dz,Double_t dy,
                                     Bool_t noClusters) const {
   //-----------------------------------------------------------------
   // This method is used to decide whether to allow a prolongation 
@@ -5013,7 +5105,10 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
                          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;  
+      if (track->GetZ()-dz<zmaxdead[i] && track->GetZ()+dz>zmindead[i]) {
+       AliDebug(2,Form("crack SPD %d",ilayer));
+       return 1; 
+      } 
   }
 
   // check bad zones from OCDB
@@ -5023,12 +5118,6 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
 
   AliITSdetector &det=fgLayers[ilayer].GetDetector(idet);  
 
-  // check if this detector is bad
-  if (det.IsBad()) {
-    //printf("lay %d  bad detector %d\n",ilayer,idet);
-    return 2;
-  }
-
   Int_t detType=-1;
   Float_t detSizeFactorX=0.0001,detSizeFactorZ=0.0001;
   if (ilayer==0 || ilayer==1) {        // ----------  SPD
@@ -5047,23 +5136,38 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
   // check if the road overlaps with bad chips
   Float_t xloc,zloc;
   LocalModuleCoord(ilayer,idet,track,xloc,zloc);
-  Float_t zlocmin = zloc-0.5*(zmax-zmin);
-  Float_t zlocmax = zloc+0.5*(zmax-zmin);
-  Float_t xlocmin = xloc-0.5*(ymax-ymin);
-  Float_t xlocmax = xloc+0.5*(ymax-ymin);
+  Float_t zlocmin = zloc-dz;
+  Float_t zlocmax = zloc+dz;
+  Float_t xlocmin = xloc-dy;
+  Float_t xlocmax = xloc+dy;
   Int_t chipsInRoad[100];
 
-  if (TMath::Max(TMath::Abs(xlocmin),TMath::Abs(xlocmax))>0.5*detSizeX ||
-      TMath::Max(TMath::Abs(zlocmin),TMath::Abs(zlocmax))>0.5*detSizeZ) return 0;
-  //printf("lay %d det %d zmim zmax %f %f xmin xmax %f %f   %f %f\n",ilayer,idet,zlocmin,zlocmax,xlocmin,xlocmax,segm->Dx(),segm->Dz());
+  // check if road goes out of detector
+  Bool_t touchNeighbourDet=kFALSE; 
+  if (TMath::Abs(xlocmin)>0.5*detSizeX) {xlocmin=-0.5*detSizeX; touchNeighbourDet=kTRUE;} 
+  if (TMath::Abs(xlocmax)>0.5*detSizeX) {xlocmax=+0.5*detSizeX; touchNeighbourDet=kTRUE;} 
+  if (TMath::Abs(zlocmin)>0.5*detSizeZ) {zlocmin=-0.5*detSizeZ; touchNeighbourDet=kTRUE;} 
+  if (TMath::Abs(zlocmax)>0.5*detSizeZ) {zlocmax=+0.5*detSizeZ; touchNeighbourDet=kTRUE;} 
+  AliDebug(2,Form("layer %d det %d zmim zmax %f %f xmin xmax %f %f   %f %f",ilayer,idet,zlocmin,zlocmax,xlocmin,xlocmax,detSizeZ,detSizeX));
+
+  // check if this detector is bad
+  if (det.IsBad()) {
+    AliDebug(2,Form("lay %d  bad detector %d",ilayer,idet));
+    if(!touchNeighbourDet) {
+      return 2; // all detectors in road are bad
+    } else { 
+      return 3; // at least one is bad
+    }
+  }
+
   Int_t nChipsInRoad = segm->GetChipsInLocalWindow(chipsInRoad,zlocmin,zlocmax,xlocmin,xlocmax);
-  //printf("lay %d nChipsInRoad %d\n",ilayer,nChipsInRoad);
+  AliDebug(2,Form("lay %d nChipsInRoad %d",ilayer,nChipsInRoad));
   if (!nChipsInRoad) return 0;
 
   Bool_t anyBad=kFALSE,anyGood=kFALSE;
   for (Int_t iCh=0; iCh<nChipsInRoad; iCh++) {
     if (chipsInRoad[iCh]<0 || chipsInRoad[iCh]>det.GetNChips()-1) continue;
-    //printf("  chip %d bad %d\n",chipsInRoad[iCh],(Int_t)det.IsChipBad(chipsInRoad[iCh]));
+    AliDebug(2,Form("  chip %d bad %d",chipsInRoad[iCh],(Int_t)det.IsChipBad(chipsInRoad[iCh])));
     if (det.IsChipBad(chipsInRoad[iCh])) {
       anyBad=kTRUE;
     } else {
@@ -5071,9 +5175,19 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
     } 
   }
 
-  if (!anyGood) return 2; // all chips in road are bad
+  if (!anyGood) {
+    if(!touchNeighbourDet) {
+      AliDebug(2,"all bad in road");
+      return 2;  // all chips in road are bad
+    } else {
+      return 3; // at least a bad chip in road
+    }
+  }
 
-  if (anyBad) return 3; // at least a bad chip in road
+  if (anyBad) {
+    AliDebug(2,"at least a bad in road");
+    return 3; // at least a bad chip in road
+  } 
 
 
   if (!AliITSReconstructor::GetRecoParam()->GetUseSingleBadChannelsFromOCDB()
@@ -5083,12 +5197,14 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
   // There are no clusters in road: check if there is at least 
   // a bad SPD pixel or SDD anode 
 
-  if(ilayer==1 || ilayer==3 || ilayer==5) 
-    idet += AliITSgeomTGeo::GetNLadders(ilayer)*AliITSgeomTGeo::GetNDetectors(ilayer);
-
-  //if (fITSChannelStatus->AnyBadInRoad(idet,zlocmin,zlocmax,xlocmin,xlocmax)) return 3;
+  Int_t idetInITS=idet;
+  for(Int_t l=0;l<ilayer;l++) idetInITS+=AliITSgeomTGeo::GetNLadders(l+1)*AliITSgeomTGeo::GetNDetectors(l+1);
 
-  if (fITSChannelStatus->FractionOfBadInRoad(idet,zlocmin,zlocmax,xlocmin,xlocmax) > AliITSReconstructor::GetRecoParam()->GetMinFractionOfBadInRoad()) return 3;
+  if (fITSChannelStatus->AnyBadInRoad(idetInITS,zlocmin,zlocmax,xlocmin,xlocmax)) {
+    AliDebug(2,Form("Bad channel in det %d of layer %d\n",idet,ilayer));
+    return 3;
+  }
+  //if (fITSChannelStatus->FractionOfBadInRoad(idet,zlocmin,zlocmax,xlocmin,xlocmax) > AliITSReconstructor::GetRecoParam()->GetMinFractionOfBadInRoad()) return 3;
 
   return 0;
 }
@@ -5113,9 +5229,11 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
 
   Double_t xyzGlob[3],xyzLoc[3];
 
-  track->GetXYZ(xyzGlob);
+  AliITSdetector &detector = fgLayers[ilayer].GetDetector(idet);
+  // take into account the misalignment: xyz at real detector plane
+  if(!track->GetXYZAt(detector.GetRmisal(),GetBz(),xyzGlob)) return kFALSE;
 
-  AliITSgeomTGeo::GlobalToLocal(ilayer+1,lad,det,xyzGlob,xyzLoc);
+  if(!AliITSgeomTGeo::GlobalToLocal(ilayer+1,lad,det,xyzGlob,xyzLoc)) return kFALSE;
 
   xloc = (Float_t)xyzLoc[0];
   zloc = (Float_t)xyzLoc[2];
@@ -5123,8 +5241,18 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
   return kTRUE;
 }
 //------------------------------------------------------------------------
-Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, Int_t ilayer) const {
-// Method still to be implemented: 
+Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, const Int_t *clusters, Int_t ilayer) const {
+//
+// Method to be optimized further: 
+// Aim: decide whether a track can be used for PlaneEff evaluation
+//      the decision is taken based on the track quality at the layer under study
+//      no information on the clusters on this layer has to be used
+//      The criterium is to reject tracks at boundaries between basic block (e.g. SPD chip)
+//      the cut is done on number of sigmas from the boundaries
+//
+//  Input: Actual track, layer [0,5] under study
+//  Output: none
+//  Return: kTRUE if this is a good track
 //
 // it will apply a pre-selection to obtain good quality tracks.  
 // Here also  you will have the possibility to put a control on the 
@@ -5132,14 +5260,42 @@ Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, Int_t ilayer) cons
 // 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) 
+// return: Bool_t   -> kTRUE if usable track, kFALSE if not usable. 
+//
+  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]=clusters[k];
+  }
+
+  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);
 
+// require a minimal number of cluster in other layers and eventually clusters in closest layers 
+  Int_t ncl=0; 
+  for(Int_t lay=AliITSgeomTGeo::kNLayers-1;lay>ilayer;lay--) {
+    AliDebug(2,Form("trak=%d  lay=%d  ; index=%d ESD label= %d",tmp.GetLabel(),lay,
+                    tmp.GetClIndex(lay),((AliESDtrack*)tmp.GetESDtrack())->GetLabel())) ;
+    if (tmp.GetClIndex(lay)>0) ncl++;
+  }
+  Bool_t nextout = kFALSE;
+  if(ilayer==AliITSgeomTGeo::kNLayers-1) nextout=kTRUE; // you are already on the outermost layer
+  else nextout = ((tmp.GetClIndex(ilayer+1)>0)? kTRUE : kFALSE );
+  Bool_t nextin = kFALSE;
+  if(ilayer==0) nextin=kTRUE; // you are already on the innermost layer
+  else nextin = ((index[ilayer-1]>=0)? kTRUE : kFALSE );
+  if(ncl<AliITSgeomTGeo::kNLayers-(ilayer+1)-AliITSReconstructor::GetRecoParam()->GetMaxMissingClustersPlaneEff()) 
+     return kFALSE; 
+  if(AliITSReconstructor::GetRecoParam()->GetRequireClusterInOuterLayerPlaneEff() && !nextout)  return kFALSE;
+  if(AliITSReconstructor::GetRecoParam()->GetRequireClusterInInnerLayerPlaneEff() && !nextin)   return kFALSE;
+  if(tmp.Pt() < AliITSReconstructor::GetRecoParam()->GetMinPtPlaneEff()) return kFALSE;
+ //  if(AliITSReconstructor::GetRecoParam()->GetOnlyConstraintPlaneEff()  && !tmp.GetConstrain()) return kFALSE;
+
 // detector number
   Double_t phi,z;
   if (!tmp.GetPhiZat(r,phi,z)) return kFALSE;
@@ -5155,56 +5311,34 @@ Bool_t AliITStrackerMI::IsOKForPlaneEff(AliITStrackMI* track, Int_t ilayer) cons
 
   Float_t locx; //
   Float_t locz; //
-  LocalModuleCoord(ilayer,idet,&tmp,locx,locz);
+  if(!LocalModuleCoord(ilayer,idet,&tmp,locx,locz)) return kFALSE;
   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 
+  // 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 nsigx=AliITSRecoParam::GetNSigXFarFromBoundary();
+  // Double_t nsigz=AliITSRecoParam::GetNSigZFarFromBoundary();
+  Double_t nsigz=4; 
+  Double_t nsigx=4; 
+  Double_t dx=nsigx*TMath::Sqrt(tmp.GetSigmaY2());  // those are precisions in the tracking reference system
+  Double_t dz=nsigz*TMath::Sqrt(tmp.GetSigmaZ2());  // Use it also for the module reference system, as it is
+                                                // done for RecPoints
+
+  // exclude tracks at boundary between detectors
+  //Double_t boundaryWidth=AliITSRecoParam::GetBoundaryWidthPlaneEff();
   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;
+  AliDebug(2,Form("Local:    track impact x=%f, z=%f",locx,locz));
+  AliDebug(2,Form("Search Road. Tracking: dy=%f , dz=%f",dx,dz));
 
+  if ( (locx-dx < blockXmn+boundaryWidth) ||
+       (locx+dx > blockXmx-boundaryWidth) ||
+       (locz-dz < blockZmn+boundaryWidth) ||
+       (locz+dz > blockZmx-boundaryWidth) ) return kFALSE;
   return kTRUE;
 }
 //------------------------------------------------------------------------
@@ -5228,7 +5362,6 @@ void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
     {AliWarning("UseTrackForPlaneEff: null pointer to AliITSPlaneEff"); return;}
   AliITSlayer &layer=fgLayers[ilayer];
   Double_t r=layer.GetR();
-  //AliITStrackV2 tmp(*track);
   AliITStrackMI tmp(*track);
 
 // detector number
@@ -5239,14 +5372,11 @@ void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
   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
@@ -5308,7 +5438,7 @@ void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
   }*/
   Float_t locx; //
   Float_t locz; //
-  LocalModuleCoord(ilayer,idet,&tmp,locx,locz);
+  if(!LocalModuleCoord(ilayer,idet,&tmp,locx,locz)) return;
 //
   AliDebug(2,Form("ilayer= %d, idet=%d, x= %f, z=%f",ilayer,idet,locx,locz));
   UInt_t key=fPlaneEff->GetKeyFromDetLocCoord(ilayer,idet,locx,locz);
@@ -5340,25 +5470,12 @@ void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
     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]);
-      }
-    }
+
+    tr[0]=locx;
+    tr[1]=locz;
+    tr[2]=TMath::Sqrt(tmp.GetSigmaY2());  // those are precisions in the tracking reference system
+    tr[3]=TMath::Sqrt(tmp.GetSigmaZ2());  // Use it also for the module reference system, as it is
+
     if (found){
       clu[0]=layer.GetCluster(ci)->GetDetLocalX();
       clu[1]=layer.GetCluster(ci)->GetDetLocalZ();
@@ -5377,21 +5494,13 @@ void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t 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]);  
-          }
-        }
+        clu[2]=TMath::Sqrt(c.GetSigmaY2());
+        clu[3]=TMath::Sqrt(c.GetSigmaZ2());
       //}
     }
     fPlaneEff->FillHistos(key,found,tr,clu,cltype);
   }
 return;
 }
+