]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITStrackerMI.cxx
fixed usage of SSD bads from OCDB; added protections;introduced AliDebug messages...
[u/mrichter/AliRoot.git] / ITS / AliITStrackerMI.cxx
index 7af608a487649efaf00a62aed73597942025af86..da4e3fb339da345fc8319b6bb40b8ec669aa495d 100644 (file)
@@ -227,21 +227,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);
   }
 }
 //------------------------------------------------------------------------
@@ -501,6 +495,7 @@ Int_t AliITStrackerMI::Clusters2Tracks(AliESDEvent *event) {
     Info("Clusters2Tracks", "Number of ESD tracks: %d\n", nentr);
     while (nentr--) {
       AliESDtrack *esd=event->GetTrack(nentr);
+      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;
@@ -780,7 +775,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:
@@ -837,7 +833,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];
@@ -848,6 +845,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) {
@@ -969,7 +968,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();
@@ -979,15 +978,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->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) 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;
@@ -1000,10 +1000,10 @@ 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;
-      currenttrack2.Propagate(det.GetPhi(),det.GetR());
+      if (!currenttrack2.Propagate(det.GetPhi(),det.GetR())) continue;
       currenttrack1.SetDetectorIndex(idet);
       currenttrack2.SetDetectorIndex(idet);
-      LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc); // local module coords
+      if(!LocalModuleCoord(ilayer,idet,&currenttrack1,xloc,zloc)) continue; // local module coords
 
       //***************
       // DEFINITION OF SEARCH ROAD AND CLUSTERS SELECTION
@@ -1101,7 +1101,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
        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();
-         currenttrack->PropagateTo(xTrOrig+cl->GetX(),0.,0.);
+         if (!currenttrack->PropagateTo(xTrOrig+cl->GetX(),0.,0.)) 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. ) 
@@ -1110,7 +1110,7 @@ void AliITStrackerMI::FollowProlongationTree(AliITStrackMI * otrack, Int_t esdin
              continue;
            }
          // bring track back to ideal detector plane
-         currenttrack->PropagateTo(xTrOrig,0.,0.);
+         if (!currenttrack->PropagateTo(xTrOrig,0.,0.)) continue;
        } else {                                      // have to move track to cluster's detector
          const AliITSdetector &detc=layer.GetDetector(idetc);
          // a first cut on track-cluster distance
@@ -1160,8 +1160,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);
          }
@@ -2023,13 +2024,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
@@ -2187,12 +2189,12 @@ 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;
 
      Double_t phi,z;
      if (!track->GetPhiZat(r,phi,z)) return kFALSE;
@@ -2203,17 +2205,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->AliExternalTrackParam::PropagateTo(xToGo,GetBz())) 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));
@@ -2227,7 +2230,7 @@ Bool_t AliITStrackerMI::RefitAt(Double_t xx,AliITStrackMI *track,
      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;
 
@@ -2244,7 +2247,7 @@ 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
         }
         Int_t cllayer = (idx & 0xf0000000) >> 28;;
         Double_t chi2=GetPredictedChi2MI(track,cl,cllayer);
@@ -2259,10 +2262,10 @@ 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
@@ -2319,7 +2322,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));
@@ -2439,8 +2442,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();
@@ -4033,9 +4038,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()));
@@ -4401,7 +4406,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.);
        }
@@ -4620,8 +4625,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")) {
@@ -4720,7 +4725,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;
@@ -4814,7 +4820,8 @@ 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;
 
@@ -4904,14 +4911,15 @@ 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);
+  if (!t->GetXYZ(globXYZ)) return 0;
 
   Double_t xOverX0=0.0,x0=0.0,lengthTimesMeanDensity=0.0;
   Double_t mparam[7];
@@ -5091,7 +5099,7 @@ Int_t AliITStrackerMI::CheckDeadZone(AliITStrackMI *track,
 
   // check if the road overlaps with bad chips
   Float_t xloc,zloc;
-  LocalModuleCoord(ilayer,idet,track,xloc,zloc);
+  if(!LocalModuleCoord(ilayer,idet,track,xloc,zloc)) return 0;
   Float_t zlocmin = zloc-dz;
   Float_t zlocmax = zloc+dz;
   Float_t xlocmin = xloc-dy;
@@ -5160,9 +5168,9 @@ Bool_t AliITStrackerMI::LocalModuleCoord(Int_t ilayer,Int_t idet,
 
   AliITSdetector &detector = fgLayers[ilayer].GetDetector(idet);
   // take into account the misalignment: xyz at real detector plane
-  track->GetXYZAt(detector.GetRmisal(),GetBz(),xyzGlob);
+  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];
@@ -5170,8 +5178,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 
@@ -5179,14 +5197,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;
@@ -5202,56 +5248,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()));
+  // 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::GetBoundaryWidth();
+  //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;
 }
 //------------------------------------------------------------------------
@@ -5275,7 +5299,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
@@ -5286,26 +5309,36 @@ 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
+//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
-  //
-  // road in global (rphi,z) [i.e. in tracking ref. system]
-  Double_t zmin,zmax,ymin,ymax;
-  if (!ComputeRoad(&tmp,ilayer,idet,zmin,zmax,ymin,ymax)) return;
-
-  // select clusters in road
+//***************
+// 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
+// Define criteria for track-cluster association
   Double_t msz = tmp.GetSigmaZ2() +
   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
   AliITSReconstructor::GetRecoParam()->GetNSigmaZLayerForRoadZ()*
@@ -5323,7 +5356,7 @@ void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
   }
   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;
@@ -5342,7 +5375,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);
@@ -5354,14 +5387,9 @@ void AliITStrackerMI::UseTrackForPlaneEff(AliITStrackMI* track, Int_t ilayer) {
     idetc = cl->GetDetectorIndex();
     if(idet!=idetc) continue;
     // here real control to see whether the cluster can be associated to the track.
-    // take into account the misalignment
-    tmp.PropagateTo(tmp.GetX()+cl->GetX(),0.,0.);
     // 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;
-    // bring track back to ideal detector plane, 
-    // important for correct treatment of misalignment in GetPredictedChi2MI()
-    tmp.PropagateTo(det.GetR(),0.,0.);
     // calculate track-clusters chi2
     chi2 = GetPredictedChi2MI(&tmp,cl,ilayer); // note that this method change track tmp
                                                // in particular, the error associated to the cluster 
@@ -5379,25 +5407,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();
@@ -5416,18 +5431,9 @@ 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);