]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtracker.cxx
TRD track crossing the material: storing the parameters and errors before the materia...
[u/mrichter/AliRoot.git] / TRD / AliTRDtracker.cxx
index 5000020a7b7a57ade44d28a6c21585ed289b4f2f..a2d3392c33de63bd455cee213f6d6aa6c4e503ef 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
                                                       
-/*
-$Log$
-Revision 1.31  2003/11/06 09:28:15  cblume
-Next round of coding conventions
-
-Revision 1.30  2003/09/18 09:06:07  cblume
-Geometry update, Removal of compiler warnings
-
-Revision 1.29  2003/07/22 15:56:14  hristov
-Implementing ESD functionality in the NewIO (Yu.Belikov)
-
-Revision 1.27.2.2  2003/07/14 09:19:33  hristov
-TOF included in the combined PID (Yu.Belikov)
-
-Revision 1.27.2.1  2003/07/11 10:53:01  hristov
-Inward refit for TPC and TRD in the ESD schema (T.Kuhr)
-
-Revision 1.27  2003/05/27 17:46:13  hristov
-TRD PID included in the ESD schema (T.Kuhr)
-
-Revision 1.26  2003/04/10 10:36:54  hristov
-Code for unified TPC/TRD tracking (S.Radomski)
-
-Revision 1.25  2003/03/19 17:14:11  hristov
-Load/UnloadClusters added to the base class and the derived classes changed correspondingly. Possibility to give 2 input files for ITS and TPC tracks in PropagateBack. TRD tracker uses fEventN from the base class (T.Kuhr)
-
-Revision 1.24  2003/02/19 09:02:28  hristov
-Track time measurement (S.Radomski)
-
-Revision 1.23  2003/02/10 14:06:10  cblume
-Add tracking without tilted pads as option
-
-Revision 1.22  2003/01/30 15:19:58  cblume
-New set of  parameters
-
-Revision 1.21  2003/01/27 16:34:49  cblume
-Update of tracking by Sergei and Chuncheng
-
-Revision 1.20  2002/11/07 15:52:09  cblume
-Update of tracking code for tilted pads
-
-Revision 1.19  2002/10/22 15:53:08  alibrary
-Introducing Riostream.h
-
-Revision 1.18  2002/10/14 14:57:44  hristov
-Merging the VirtualMC branch to the main development branch (HEAD)
-
-Revision 1.14.6.2  2002/07/24 10:09:31  alibrary
-Updating VirtualMC
-
-Revision 1.17  2002/06/13 12:09:58  hristov
-Minor corrections
-
-Revision 1.16  2002/06/12 09:54:36  cblume
-Update of tracking code provided by Sergei
-
-Revision 1.14  2001/11/14 10:50:46  cblume
-Changes in digits IO. Add merging of summable digits
-
-Revision 1.13  2001/05/30 12:17:47  hristov
-Loop variables declared once
-
-Revision 1.12  2001/05/28 17:07:58  hristov
-Last minute changes; ExB correction in AliTRDclusterizerV1; taking into account of material in G10 TEC frames and material between TEC planes (C.Blume,S.Sedykh)
-
-Revision 1.8  2000/12/20 13:00:44  cblume
-Modifications for the HP-compiler
-
-Revision 1.7  2000/12/08 16:07:02  cblume
-Update of the tracking by Sergei
-
-Revision 1.6  2000/11/30 17:38:08  cblume
-Changes to get in line with new STEER and EVGEN
-
-Revision 1.5  2000/11/14 14:40:27  cblume
-Correction for the Sun compiler (kTRUE and kFALSE)
-
-Revision 1.4  2000/11/10 14:57:52  cblume
-Changes in the geometry constants for the DEC compiler
-
-Revision 1.3  2000/10/15 23:40:01  cblume
-Remove AliTRDconst
-
-Revision 1.2  2000/10/06 16:49:46  cblume
-Made Getters const
-
-Revision 1.1.2.2  2000/10/04 16:34:58  cblume
-Replace include files by forward declarations
-
-Revision 1.1.2.1  2000/09/22 14:47:52  cblume
-Add the tracking code
-
-*/   
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -114,7 +22,6 @@ Add the tracking code
 ///////////////////////////////////////////////////////////////////////////////
 
 #include <Riostream.h>
-
 #include <TFile.h>
 #include <TBranch.h>
 #include <TTree.h>  
@@ -122,11 +29,11 @@ Add the tracking code
 
 #include "AliTRDgeometry.h"
 #include "AliTRDparameter.h"
-#include "AliTRDgeometryDetail.h"
+#include "AliTRDgeometryHole.h"
 #include "AliTRDcluster.h" 
 #include "AliTRDtrack.h"
-#include "AliTRDPartID.h"
-#include "../TPC/AliTPCtrack.h"
+#include "AliBarrelTrack.h"
+#include "AliESD.h"
 
 #include "AliTRDtracker.h"
 
@@ -161,6 +68,30 @@ const Int_t AliTRDtracker::fgkFirstPlane = 5;
 const Int_t AliTRDtracker::fgkLastPlane = 17;
 
 
+//____________________________________________________________________
+AliTRDtracker::AliTRDtracker():AliTracker(),
+                              fGeom(0),
+                              fPar(0),
+                              fNclusters(0),
+                              fClusters(0),
+                              fNseeds(0),
+                              fSeeds(0),
+                              fNtracks(0),
+                              fTracks(0),
+                              fSY2corr(0),
+                              fSZ2corr(0),
+                              fTimeBinsPerPlane(0),
+                              fMaxGap(0),
+                              fVocal(kFALSE),
+                              fAddTRDseeds(kFALSE),
+                              fNoTilt(kFALSE)
+{
+  // Default constructor
+
+  for(Int_t i=0;i<kTrackingSectors;i++) fTrSec[i]=0;
+  for(Int_t j=0;j<5;j++)
+    for(Int_t k=0;k<18;k++) fHoles[j][k]=kFALSE;
+} 
 //____________________________________________________________________
 AliTRDtracker::AliTRDtracker(const TFile *geomfile):AliTracker()
 {
@@ -194,8 +125,11 @@ AliTRDtracker::AliTRDtracker(const TFile *geomfile):AliTracker()
   }
   else { 
     printf("AliTRDtracker::AliTRDtracker(): can't find TRD geometry!\n");
-    printf("The DETAIL TRD geometry will be used\n");
-    fGeom = new AliTRDgeometryDetail();
+    //printf("The DETAIL TRD geometry will be used\n");
+    //fGeom = new AliTRDgeometryDetail();
+    fGeom = new AliTRDgeometryHole();
+    fGeom->SetPHOShole();
+    fGeom->SetRICHhole();    
   } 
 
   if (!fPar) {  
@@ -220,6 +154,9 @@ AliTRDtracker::AliTRDtracker(const TFile *geomfile):AliTracker()
   for(Int_t geomS = 0; geomS < kTrackingSectors; geomS++) {
     Int_t trS = CookSectorIndex(geomS);
     fTrSec[trS] = new AliTRDtrackingSector(fGeom, geomS, fPar);
+    for (Int_t icham=0;icham<AliTRDgeometry::kNcham; icham++){
+      fHoles[icham][trS]=fGeom->IsHole(0,icham,geomS);
+    }
   }
 
   Float_t tiltAngle = TMath::Abs(fPar->GetTiltingAngle()); 
@@ -271,9 +208,18 @@ AliTRDtracker::~AliTRDtracker()
   // Destructor of AliTRDtracker 
   //
 
-  delete fClusters;
-  delete fTracks;
-  delete fSeeds;
+  if (fClusters) {
+    fClusters->Delete();
+    delete fClusters;
+  }
+  if (fTracks) {
+    fTracks->Delete();
+    delete fTracks;
+  }
+  if (fSeeds) {
+    fSeeds->Delete();
+    delete fSeeds;
+  }
   delete fGeom;  
   delete fPar;  
 
@@ -434,173 +380,43 @@ inline Double_t f3trd(Double_t x1,Double_t y1,
   return (z1 - z2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
 }            
 
-//___________________________________________________________________
-Int_t AliTRDtracker::Clusters2Tracks(const TFile *inp, TFile *out)
-{
+
+AliTRDcluster * AliTRDtracker::GetCluster(AliTRDtrack * track, Int_t plane, Int_t timebin){
   //
-  // Finds tracks within the TRD. File <inp> is expected to contain seeds 
-  // at the outer part of the TRD. If <inp> is NULL, the seeds
-  // are found within the TRD if fAddTRDseeds is TRUE. 
-  // The tracks are propagated to the innermost time bin 
-  // of the TRD and stored in file <out>. 
+  //try to find cluster in the backup list
   //
-
-  LoadEvent();
-  TDirectory *savedir=gDirectory;
-
-  char   tname[100];
-
-  if (!out->IsOpen()) {
-    cerr<<"AliTRDtracker::Clusters2Tracks(): output file is not open !\n";
-    return 1;
-  }    
-
-  sprintf(tname,"seedTRDtoTPC_%d",GetEventNumber()); 
-  TTree tpcTree(tname,"Tree with seeds from TRD at outer TPC pad row");
-  AliTPCtrack *iotrack=0;
-  tpcTree.Branch("tracks","AliTPCtrack",&iotrack,32000,0); 
-
-  sprintf(tname,"TreeT%d_TRD",GetEventNumber());
-  TTree trdTree(tname,"TRD tracks at inner TRD time bin");
-  AliTRDtrack *iotrackTRD=0;
-  trdTree.Branch("tracks","AliTRDtrack",&iotrackTRD,32000,0);  
-
-  Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
-  Float_t foundMin = fgkMinClustersInTrack * timeBins; 
-
-  if (inp) {
-     TFile *in=(TFile*)inp;
-     if (!in->IsOpen()) {
-        cerr<<
-          "AliTRDtracker::Clusters2Tracks(): file with seeds is not open !\n";
-        cerr<<" ... going for seeds finding inside the TRD\n";
-     }
-     else {
-       in->cd();
-       sprintf(tname,"TRDb_%d",GetEventNumber());  
-       TTree *seedTree=(TTree*)in->Get(tname);  
-       if (!seedTree) {
-         cerr<<"AliTRDtracker::Clusters2Tracks(): ";
-         cerr<<"can't get a tree with track seeds !\n";
-         return 3;
-       }  
-       AliTRDtrack *seed=new AliTRDtrack;
-       seedTree->SetBranchAddress("tracks",&seed);
-
-       Int_t n=(Int_t)seedTree->GetEntries();
-       for (Int_t i=0; i<n; i++) {
-         seedTree->GetEvent(i);
-         seed->ResetCovariance(); 
-         AliTRDtrack *tr = new AliTRDtrack(*seed,seed->GetAlpha());
-         fSeeds->AddLast(tr);
-         fNseeds++;
-       }          
-       delete seed;
-       delete seedTree;
-     }
-  }
-
-  out->cd();
-
-
-  // find tracks from loaded seeds
-
-  Int_t nseed=fSeeds->GetEntriesFast();
-  Int_t i, found = 0;
-  Int_t innerTB = fTrSec[0]->GetInnerTimeBin();
-
-  for (i=0; i<nseed; i++) {   
-    AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt; 
-    FollowProlongation(t, innerTB); 
-    if (t.GetNumberOfClusters() >= foundMin) {
-      UseClusters(&t);
-      CookLabel(pt, 1-fgkLabelFraction);
-      //      t.CookdEdx();
+  AliTRDcluster * cl =0;
+  UInt_t *indexes = track->GetBackupIndexes();
+  for (UInt_t i=0;i<kMaxTimeBinIndex;i++){
+    if (indexes[i]==0) break;  
+    AliTRDcluster * cli = (AliTRDcluster*)fClusters->UncheckedAt(indexes[i]);
+    if (!cli) break;
+    if (cli->GetLocalTimeBin()!=timebin) continue;
+    Int_t iplane = fGeom->GetPlane(cli->GetDetector());
+    if (iplane==plane) {
+      cl = cli;
+      break;
     }
-    iotrackTRD = pt;
-    trdTree.Fill();
-    found++;
-//    cout<<found<<'\r';     
-
-    if(PropagateToTPC(t)) {
-      AliTPCtrack *tpc = new AliTPCtrack(*pt,pt->GetAlpha());
-      iotrack = tpc;
-      tpcTree.Fill();
-      delete tpc;
-    }  
-    delete fSeeds->RemoveAt(i);
-    fNseeds--;
-  }     
-
-  cout<<"Number of loaded seeds: "<<nseed<<endl;  
-  cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
-
-  // after tracks from loaded seeds are found and the corresponding 
-  // clusters are used, look for additional seeds from TRD
+  }
+  return cl;
+}
 
-  if(fAddTRDseeds) { 
-    // Find tracks for the seeds in the TRD
-    Int_t timeBins = fTrSec[0]->GetNumberOfTimeBins();
-  
-    Int_t nSteps = (Int_t) (fgkSeedDepth / fgkSeedStep);
-    Int_t gap = (Int_t) (timeBins * fgkSeedGap);
-    Int_t step = (Int_t) (timeBins * fgkSeedStep);
-  
-    // make a first turn with tight cut on initial curvature
-    for(Int_t turn = 1; turn <= 2; turn++) {
-      if(turn == 2) {
-        nSteps = (Int_t) (fgkSeedDepth / (3*fgkSeedStep));
-        step = (Int_t) (timeBins * (3*fgkSeedStep));
-      }
-      for(Int_t i=0; i<nSteps; i++) {
-        Int_t outer=timeBins-1-i*step; 
-        Int_t inner=outer-gap;
 
-        nseed=fSeeds->GetEntriesFast();
-      
-        MakeSeeds(inner, outer, turn);
-      
-        nseed=fSeeds->GetEntriesFast();
-        printf("\n turn %d, step %d: number of seeds for TRD inward %d\n", 
-               turn, i, nseed); 
-              
-        for (Int_t i=0; i<nseed; i++) {   
-          AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt; 
-          FollowProlongation(t,innerTB); 
-          if (t.GetNumberOfClusters() >= foundMin) {
-            UseClusters(&t);
-            CookLabel(pt, 1-fgkLabelFraction);
-            t.CookdEdx();
-            found++;
-//            cout<<found<<'\r';     
-            iotrackTRD = pt;
-            trdTree.Fill();
-            if(PropagateToTPC(t)) {
-              AliTPCtrack *tpc = new AliTPCtrack(*pt,pt->GetAlpha());
-              iotrack = tpc;
-              tpcTree.Fill();
-              delete tpc;
-            }        
-          }
-          delete fSeeds->RemoveAt(i);
-          fNseeds--;
-        }
-      }
+Int_t  AliTRDtracker::GetLastPlane(AliTRDtrack * track){
+  //
+  //return last updated plane
+  Int_t lastplane=0;
+  UInt_t *indexes = track->GetBackupIndexes();
+  for (UInt_t i=0;i<kMaxTimeBinIndex;i++){
+    AliTRDcluster * cli = (AliTRDcluster*)fClusters->UncheckedAt(indexes[i]);
+    if (!cli) break;
+    Int_t iplane = fGeom->GetPlane(cli->GetDetector());
+    if (iplane>lastplane) {
+      lastplane = iplane;
     }
   }
-  tpcTree.Write(); 
-  trdTree.Write(); 
-  
-  cout<<"Total number of found tracks: "<<found<<endl;
-    
-  UnloadEvent();
-    
-  savedir->cd();  
-  
-  return 0;    
-}     
-          
+  return lastplane;
+}
 //___________________________________________________________________
 Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
 {
@@ -627,7 +443,7 @@ Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
     nseed++;
 
     AliTRDtrack* seed2 = new AliTRDtrack(*seed);
-    seed2->ResetCovariance(); 
+    //seed2->ResetCovariance(); 
     AliTRDtrack *pt = new AliTRDtrack(*seed2,seed2->GetAlpha());
     AliTRDtrack &t=*pt; 
     FollowProlongation(t, innerTB); 
@@ -675,8 +491,8 @@ Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
         MakeSeeds(inner, outer, turn);
       
         nseed=fSeeds->GetEntriesFast();
-        printf("\n turn %d, step %d: number of seeds for TRD inward %d\n", 
-               turn, i, nseed); 
+       //        printf("\n turn %d, step %d: number of seeds for TRD inward %d\n", 
+       //               turn, i, nseed); 
               
         for (Int_t i=0; i<nseed; i++) {   
           AliTRDtrack *pt=(AliTRDtrack*)fSeeds->UncheckedAt(i), &t=*pt; 
@@ -691,6 +507,7 @@ Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
              AliESDtrack track;
              track.UpdateTrackParams(pt,AliESDtrack::kTRDin);
              event->AddTrack(&track);
+             //              track.SetTRDtrack(new AliTRDtrack(*pt));
             }        
           }
           delete fSeeds->RemoveAt(i);
@@ -707,196 +524,6 @@ Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
      
   
 
-//_____________________________________________________________________________
-Int_t AliTRDtracker::PropagateBack(const TFile *inp, TFile *out) {
-  //
-  // Reads seeds from file <inp>. The seeds are AliTPCtrack's found and
-  // backpropagated by the TPC tracker. Each seed is first propagated 
-  // to the TRD, and then its prolongation is searched in the TRD.
-  // If sufficiently long continuation of the track is found in the TRD
-  // the track is updated, otherwise it's stored as originaly defined 
-  // by the TPC tracker.   
-  //  
-
-  LoadEvent();
-
-  TDirectory *savedir=gDirectory;
-
-  TFile *in=(TFile*)inp;
-
-  if (!in->IsOpen()) {
-     cerr<<"AliTRDtracker::PropagateBack(): ";
-     cerr<<"file with back propagated TPC tracks is not open !\n";
-     return 1;
-  }                   
-
-  if (!out->IsOpen()) {
-     cerr<<"AliTRDtracker::PropagateBack(): ";
-     cerr<<"file for back propagated TRD tracks is not open !\n";
-     return 2;
-  }      
-
-  in->cd();
-  char   tname[100];
-  sprintf(tname,"seedsTPCtoTRD_%d",GetEventNumber());       
-  TTree *seedTree=(TTree*)in->Get(tname);
-  if (!seedTree) {
-     cerr<<"AliTRDtracker::PropagateBack(): ";
-     cerr<<"can't get a tree with seeds from TPC !\n";
-     cerr<<"check if your version of TPC tracker creates tree "<<tname<<"\n";
-     return 3;
-  }
-
-  AliTPCtrack *seed=new AliTPCtrack;
-  seedTree->SetBranchAddress("tracks",&seed);
-
-  Int_t n=(Int_t)seedTree->GetEntries();
-  for (Int_t i=0; i<n; i++) {
-     seedTree->GetEvent(i);
-     Int_t lbl = seed->GetLabel();
-     AliTRDtrack *tr = new AliTRDtrack(*seed,seed->GetAlpha());
-     tr->SetSeedLabel(lbl);
-     fSeeds->AddLast(tr);
-     fNseeds++;
-  }
-
-  delete seed;
-  delete seedTree;
-
-  out->cd();
-
-  AliTPCtrack *otrack=0;
-
-  sprintf(tname,"seedsTRDtoTOF1_%d",GetEventNumber());  
-  TTree tofTree1(tname,"Tracks back propagated through TPC and TRD");
-  tofTree1.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
-
-  sprintf(tname,"seedsTRDtoTOF2_%d",GetEventNumber());  
-  TTree tofTree2(tname,"Tracks back propagated through TPC and TRD");
-  tofTree2.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
-
-  sprintf(tname,"seedsTRDtoPHOS_%d",GetEventNumber());  
-  TTree phosTree(tname,"Tracks back propagated through TPC and TRD");
-  phosTree.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
-
-  sprintf(tname,"seedsTRDtoRICH_%d",GetEventNumber());  
-  TTree richTree(tname,"Tracks back propagated through TPC and TRD");
-  richTree.Branch("tracks","AliTPCtrack",&otrack,32000,0);  
-
-  sprintf(tname,"TRDb_%d",GetEventNumber());  
-  TTree trdTree(tname,"Back propagated TRD tracks at outer TRD time bin");
-  AliTRDtrack *otrackTRD=0;
-  trdTree.Branch("tracks","AliTRDtrack",&otrackTRD,32000,0);   
-     
-  if (IsStoringBarrel()) SetBarrelTree("back");
-  out->cd();
-
-  Int_t found=0;  
-  Int_t nseed=fSeeds->GetEntriesFast();
-
-  //  Float_t foundMin = fgkMinClustersInTrack * fTimeBinsPerPlane * fGeom->Nplan(); 
-  Float_t foundMin = 40;
-
-  Int_t outermostTB  = fTrSec[0]->GetOuterTimeBin();
-
-  for (Int_t i=0; i<nseed; i++) {  
-
-    AliTRDtrack *ps=(AliTRDtrack*)fSeeds->UncheckedAt(i), &s=*ps;
-    Int_t expectedClr = FollowBackProlongation(s);
-
-    if (IsStoringBarrel()) {
-      StoreBarrelTrack(ps, fgkLastPlane, kTrackBack);
-      fBarrelTree->Fill();        
-    }
-
-    Int_t foundClr = s.GetNumberOfClusters();
-    Int_t lastTB = fTrSec[0]->GetLayerNumber(s.GetX());
-
-    //    printf("seed %d: found %d out of %d expected clusters, Min is %f\n",
-    //     i, foundClr, expectedClr, foundMin);
-
-    if (foundClr >= foundMin) {
-      if(foundClr >= 2) {
-       s.CookdEdx(); 
-       CookLabel(ps, 1-fgkLabelFraction);
-       UseClusters(ps);
-      }
-      
-      // Propagate to outer reference plane [SR, GSI, 18.02.2003]
-      ps->PropagateTo(364.8);
-      otrackTRD=ps;
-      trdTree.Fill();
-      found++;
-//      cout<<found<<'\r';
-    }
-
-    if(((expectedClr < 10) && (lastTB == outermostTB)) ||
-       ((expectedClr >= 10) && 
-        (((Float_t) foundClr) / ((Float_t) expectedClr) >= 
-         fgkMinFractionOfFoundClusters) && (lastTB == outermostTB))) {
-
-      Double_t xTOF = 375.5;
-    
-      if(PropagateToOuterPlane(s,xTOF)) {
-        AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
-        otrack = pt;
-        tofTree1.Fill();
-        delete pt;
-
-        xTOF = 381.5;
-    
-        if(PropagateToOuterPlane(s,xTOF)) {
-          AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
-          otrack = pt;
-          tofTree2.Fill();
-          delete pt;
-
-          Double_t xPHOS = 460.;
-          
-          if(PropagateToOuterPlane(s,xPHOS)) {
-            AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
-            otrack = pt;
-            phosTree.Fill();
-            delete pt;
-            
-            Double_t xRICH = 490+1.267;
-            
-            if(PropagateToOuterPlane(s,xRICH)) {
-              AliTPCtrack *pt = new AliTPCtrack(*ps,ps->GetAlpha());
-              otrack = pt;
-              richTree.Fill();
-              delete pt;
-            }   
-          }
-        }
-      }      
-    }
-  }
-  
-  
-  out->cd();
-  tofTree1.Write(); 
-  tofTree2.Write(); 
-  phosTree.Write(); 
-  richTree.Write(); 
-  trdTree.Write(); 
-
-  if (IsStoringBarrel()) { // [SR, 03.04.2003]
-    fBarrelFile->cd();
-    fBarrelTree->Write();
-    fBarrelFile->Flush();
-  }
-
-  savedir->cd();  
-  cerr<<"Number of seeds: "<<nseed<<endl;  
-  cerr<<"Number of back propagated TRD tracks: "<<found<<endl;
-
-  UnloadEvent();
-
-  return 0;
-
-}
-
 //_____________________________________________________________________________
 Int_t AliTRDtracker::PropagateBack(AliESD* event) {
   //
@@ -909,7 +536,7 @@ Int_t AliTRDtracker::PropagateBack(AliESD* event) {
   //  
 
   Int_t found=0;  
-  Float_t foundMin = 40;
+  Float_t foundMin = 20;
 
   Int_t n = event->GetNumberOfTracks();
   for (Int_t i=0; i<n; i++) {
@@ -922,42 +549,89 @@ Int_t AliTRDtracker::PropagateBack(AliESD* event) {
     AliTRDtrack *track = new AliTRDtrack(*seed);
     track->SetSeedLabel(lbl);
     fNseeds++;
-
-    /*Int_t expectedClr = */FollowBackProlongation(*track);
-
+    Float_t p4 = track->GetC();
+    //
+    Int_t expectedClr = FollowBackProlongation(*track);
+    if (track->GetNumberOfClusters()<expectedClr/3){
+      AliTRDtrack *track1 = new AliTRDtrack(*seed);
+      track1->SetSeedLabel(lbl);
+      FollowBackProlongation(*track1);
+      AliTRDtrack *track2= new AliTRDtrack(*seed);
+      track->SetSeedLabel(lbl);
+      FollowBackProlongation(*track2);      
+      delete track1;
+      delete track2;
+    }
+    if (TMath::Abs(track->GetC()-p4)/TMath::Abs(p4)>0.2) {
+      delete track;
+      continue; //too big change of curvature - to be checked
+    }
     Int_t foundClr = track->GetNumberOfClusters();
     if (foundClr >= foundMin) {
       if(foundClr >= 2) {
        track->CookdEdx(); 
-//     CookLabel(track, 1-fgkLabelFraction);
+       CookLabel(track, 1-fgkLabelFraction);
        UseClusters(track);
       }
       
       // Propagate to outer reference plane [SR, GSI, 18.02.2003]
-//      track->PropagateTo(364.8);  why?
+      //      track->PropagateTo(364.8);  why?
       
       //seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
       //found++;
+      if (track->GetNCross()==0) seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
+      else{
+       if (track->GetBackupTrack()) seed->UpdateTrackParams(track->GetBackupTrack(), AliESDtrack::kTRDbackup);
+      }
     }
 
     //Propagation to the TOF (I.Belikov)
-    Double_t xtof=378.;
-    Double_t c2=track->GetC()*xtof - track->GetEta();
-    if (TMath::Abs(c2)>=0.9999999) continue;
+    
+    if (track->GetStop()==kFALSE){
 
-    Double_t ymax=xtof*TMath::Tan(0.5*AliTRDgeometry::GetAlpha());
-    Double_t y=track->GetYat(xtof);
-    if (y > ymax) {
-       if (!track->Rotate(AliTRDgeometry::GetAlpha())) return 1;
-    } else if (y <-ymax) {
-       if (!track->Rotate(-AliTRDgeometry::GetAlpha())) return 1;
+      Double_t xtof=371.;
+      Double_t c2=track->GetC()*xtof - track->GetEta();
+      if (TMath::Abs(c2)>=0.85) {
+       delete track;
+       continue;
+      }
+      Double_t xTOF0 = 371. ;          
+      PropagateToOuterPlane(*track,xTOF0); 
+      //      
+      Double_t ymax=xtof*TMath::Tan(0.5*AliTRDgeometry::GetAlpha());
+      Double_t y=track->GetYat(xtof);
+      if (y > ymax) {
+       if (!track->Rotate(AliTRDgeometry::GetAlpha())) {
+         delete track;
+         continue;
+       }
+      } else if (y <-ymax) {
+       if (!track->Rotate(-AliTRDgeometry::GetAlpha())) {
+         delete track;
+         continue;
+       }
+      }
+      
+      if (track->PropagateTo(xtof)) {
+       seed->UpdateTrackParams(track, AliESDtrack::kTRDout);    
+       seed->SetTRDtrack(new AliTRDtrack(*track));
+       if (track->GetNumberOfClusters()>foundMin) found++;
+      }
+    }else{
+      if (track->GetNumberOfClusters()>15&&track->GetNumberOfClusters()>0.5*expectedClr){
+       seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
+       //seed->SetStatus(AliESDtrack::kTRDStop);    
+       seed->SetTRDtrack(new AliTRDtrack(*track));
+       found++;
+      }
     }
 
-    if (track->PropagateTo(xtof)) {
-       seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
-       found++;
-    }
+    delete track;
+    
     //End of propagation to the TOF
+    //if (foundClr>foundMin)
+    //  seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
+    
 
   }
   
@@ -996,21 +670,52 @@ Int_t AliTRDtracker::RefitInward(AliESD* event)
     nseed++;
 
     AliTRDtrack* seed2 = new AliTRDtrack(*seed);
-    seed2->ResetCovariance(); 
+    seed2->ResetCovariance(5.); 
     AliTRDtrack *pt = new AliTRDtrack(*seed2,seed2->GetAlpha());
+    UInt_t * indexes2 = seed2->GetIndexes();
+    UInt_t * indexes3 = pt->GetBackupIndexes();
+    for (Int_t i=0;i<200;i++) {
+      if (indexes2[i]==0) break;
+      indexes3[i] = indexes2[i];
+    }          
+    //AliTRDtrack *pt = seed2;
     AliTRDtrack &t=*pt; 
     FollowProlongation(t, innerTB); 
+    /*
+    if (t.GetNumberOfClusters()<seed->GetTRDclusters(indexes3)*0.5){
+      // debug  - why we dont go back?
+      AliTRDtrack *pt2 = new AliTRDtrack(*seed2,seed2->GetAlpha());
+      UInt_t * indexes2 = seed2->GetIndexes();
+      UInt_t * indexes3 = pt2->GetBackupIndexes();
+      for (Int_t i=0;i<200;i++) {
+       if (indexes2[i]==0) break;
+       indexes3[i] = indexes2[i];
+      }  
+      FollowProlongation(*pt2, innerTB);
+      delete pt2;
+    }
+    */
     if (t.GetNumberOfClusters() >= foundMin) {
-      UseClusters(&t);
-      CookLabel(pt, 1-fgkLabelFraction);
+      //      UseClusters(&t);
+      //CookLabel(pt, 1-fgkLabelFraction);
       //      t.CookdEdx();
     }
     found++;
 //    cout<<found<<'\r';     
 
     if(PropagateToTPC(t)) {
-      seed->UpdateTrackParams(pt, AliESDtrack::kTRDin);
+      seed->UpdateTrackParams(pt, AliESDtrack::kTRDrefit);
+    }else{
+      //if not prolongation to TPC - propagate without update
+      AliTRDtrack* seed2 = new AliTRDtrack(*seed);
+      seed2->ResetCovariance(5.); 
+      AliTRDtrack *pt2 = new AliTRDtrack(*seed2,seed2->GetAlpha());
+      delete seed2;
+      if (PropagateToTPC(*pt2)) 
+       seed->UpdateTrackParams(pt2, AliESDtrack::kTRDrefit);
+      delete pt2;
     }  
+
     delete seed2;
     delete pt;
   }     
@@ -1037,6 +742,7 @@ Int_t AliTRDtracker::FollowProlongation(AliTRDtrack& t, Int_t rf)
   Float_t  wPx, wPy, wPz, wC;
   Double_t px, py, pz;
   Float_t  wSigmaC2, wSigmaTgl2, wSigmaY2, wSigmaZ2;
+  Int_t lastplane = GetLastPlane(&t);
 
   Int_t trackIndex = t.GetLabel();  
 
@@ -1124,12 +830,6 @@ Int_t AliTRDtracker::FollowProlongation(AliTRDtrack& t, Int_t rf)
       wSigmaZ2 = (Float_t) t.GetSigmaZ2();
       wChi2 = -1;            
       
-      if (road>fgkWideRoad) {
-        if (t.GetNumberOfClusters()>4)
-          cerr<<t.GetNumberOfClusters()
-              <<"FindProlongation warning: Too broad road !\n";
-        return 0;
-      }             
 
       AliTRDcluster *cl=0;
       UInt_t index=0;
@@ -1163,21 +863,48 @@ Int_t AliTRDtracker::FollowProlongation(AliTRDtrack& t, Int_t rf)
       // Now go for the real cluster search
 
       if (timeBin) {
-
-        for (Int_t i=timeBin.Find(y-road); i<timeBin; i++) {
-          AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
-          if (c->GetY() > y+road) break;
-          if (c->IsUsed() > 0) continue;
-          if((c->GetZ()-z)*(c->GetZ()-z) > 3 * sz2) continue;
-
-          Double_t h01 = GetTiltFactor(c);
-          Double_t chi2=t.GetPredictedChi2(c,h01);
-          
-          if (chi2 > maxChi2) continue;
-          maxChi2=chi2;
-          cl=c;
-          index=timeBin.GetIndex(i);
-        }               
+       //
+       //find cluster in history
+       cl =0;
+       
+       AliTRDcluster * cl0 = timeBin[0];
+       if (!cl0) {
+         continue;
+       }
+       Int_t plane = fGeom->GetPlane(cl0->GetDetector());
+       if (plane>lastplane) continue;
+       Int_t timebin = cl0->GetLocalTimeBin();
+       AliTRDcluster * cl2= GetCluster(&t,plane, timebin);
+       if (cl2) {
+         cl =cl2;      
+         Double_t h01 = GetTiltFactor(cl);
+         maxChi2=t.GetPredictedChi2(cl,h01);
+       }
+       if ((!cl) && road>fgkWideRoad) {
+         //if (t.GetNumberOfClusters()>4)
+         //  cerr<<t.GetNumberOfClusters()
+         //    <<"FindProlongation warning: Too broad road !\n";
+         continue;
+       }             
+
+
+       if(!cl){
+
+         for (Int_t i=timeBin.Find(y-road); i<timeBin; i++) {
+           AliTRDcluster* c=(AliTRDcluster*)(timeBin[i]);
+           if (c->GetY() > y+road) break;
+           if (c->IsUsed() > 0) continue;
+           if((c->GetZ()-z)*(c->GetZ()-z) > 3 * sz2) continue;
+           
+           Double_t h01 = GetTiltFactor(c);
+           Double_t chi2=t.GetPredictedChi2(c,h01);
+           
+           if (chi2 > maxChi2) continue;
+           maxChi2=chi2;
+           cl=c;
+           index=timeBin.GetIndex(i);
+         }               
+       }
 
         if(!cl) {
 
@@ -1197,21 +924,25 @@ Int_t AliTRDtracker::FollowProlongation(AliTRDtrack& t, Int_t rf)
             index=timeBin.GetIndex(i);
           }
         }        
-        
-
         if (cl) {
           wYclosest = cl->GetY();
           wZclosest = cl->GetZ();
           Double_t h01 = GetTiltFactor(cl);
 
           t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters()); 
-          if(!t.Update(cl,maxChi2,index,h01)) {
-            if(!tryAgain--) return 0;
+         //printf("Track   position\t%f\t%f\t%f\n",t.GetX(),t.GetY(),t.GetZ());
+         //printf("Cluster position\t%d\t%f\t%f\n",cl->GetLocalTimeBin(),cl->GetY(),cl->GetZ());
+         Int_t det = cl->GetDetector();    
+         Int_t plane = fGeom->GetPlane(det);
+
+         if(!t.UpdateMI(cl,maxChi2,index,h01,plane)) {
+           //if(!t.Update(cl,maxChi2,index,h01)) {
+            //if(!tryAgain--) return 0;
           }  
           else tryAgain=fMaxGap;
         }
         else {
-          if (tryAgain==0) break; 
+          //if (tryAgain==0) break; 
           tryAgain--;
         }
 
@@ -1257,6 +988,7 @@ Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
   // layers confirms prolongation if a close cluster is found. 
   // Returns the number of clusters expected to be found in sensitive layers
 
+
   Float_t  wIndex, wTB, wChi2;
   Float_t  wYrt, wYclosest, wYcorrect, wYwindow;
   Float_t  wZrt, wZclosest, wZcorrect, wZwindow;
@@ -1286,8 +1018,9 @@ Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
 
   Double_t chi2;
   Double_t minDY;
-
-  for (Int_t nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr<outerTB+1; nr++) { 
+  Int_t zone =-10;
+  Int_t nr;
+  for (nr=fTrSec[0]->GetLayerNumber(t.GetX()); nr<outerTB+1; nr++) { 
     
     y = t.GetY(); 
     z = t.GetZ();
@@ -1301,7 +1034,29 @@ Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
     z = t.GetZ();
 
     if(!t.PropagateTo(x,radLength,rho)) break;
+    //    if (!AdjustSector(&t)) break;
+    //
+    // MI -fix untill correct material desription will be implemented
+    //
+    Float_t angle =  t.GetAlpha();  // MI - if rotation - we go through the material 
     if (!AdjustSector(&t)) break;
+    Int_t cross = kFALSE;
+    
+    if (TMath::Abs(angle -  t.GetAlpha())>0.000001) cross = kTRUE; //better to stop track
+    Int_t currentzone = fTrSec[s]->GetLayer(nr)->GetZone(z);
+    if (currentzone==-10) cross = kTRUE;  // we are in the frame
+    if (currentzone>-10){   // layer knows where we are
+      if (zone==-10) zone = currentzone;
+      if (zone!=currentzone) cross=kTRUE;  
+    }
+    if (cross) {
+      t.IncCross();
+      if (t.GetNCross()==1) t.MakeBackupTrack();
+      if (t.GetNCross()>2) break;
+    }
+    
+    //
+    //
     s = t.GetSector();
     if (!t.PropagateTo(x,radLength,rho)) break;
 
@@ -1465,7 +1220,11 @@ Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
 
           t.SetSampledEdx(cl->GetQ()/dx,t.GetNumberOfClusters()); 
           Double_t h01 = GetTiltFactor(cl);
-          if(!t.Update(cl,maxChi2,index,h01)) {
+         Int_t det = cl->GetDetector();    
+         Int_t plane = fGeom->GetPlane(det);
+
+         if(!t.UpdateMI(cl,maxChi2,index,h01,plane)) {
+          //if(!t.Update(cl,maxChi2,index,h01)) {
             if(!tryAgain--) return 0;
           }  
           else tryAgain=fMaxGap;
@@ -1510,6 +1269,10 @@ Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
       }
     }  
   }
+  if (nr<outerTB) 
+    t.SetStop(kTRUE);
+  else
+    t.SetStop(kFALSE);
   return expectedNumberOfClusters;
 
 
@@ -1723,42 +1486,10 @@ Int_t AliTRDtracker::PropagateToTPC(AliTRDtrack& t)
     if(!t.PropagateTo(x,radLength,rho)) return 0;
     AdjustSector(&t);
     if(!t.PropagateTo(x,radLength,rho)) return 0;
-  }
+  } 
   return 1;
 }         
 
-void AliTRDtracker::LoadEvent()
-{
-  // Fills clusters into TRD tracking_sectors 
-  // Note that the numbering scheme for the TRD tracking_sectors 
-  // differs from that of TRD sectors
-
-  ReadClusters(fClusters);
-  Int_t ncl=fClusters->GetEntriesFast();
-  cout<<"\n LoadSectors: sorting "<<ncl<<" clusters"<<endl;
-              
-  UInt_t index;
-  while (ncl--) {
-//    printf("\r %d left  ",ncl); 
-    AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
-    Int_t detector=c->GetDetector();
-    Int_t localTimeBin=c->GetLocalTimeBin();
-    Int_t sector=fGeom->GetSector(detector);
-    Int_t plane=fGeom->GetPlane(detector);
-
-    Int_t trackingSector = CookSectorIndex(sector);
-
-    Int_t gtb = fTrSec[trackingSector]->CookTimeBinIndex(plane,localTimeBin);
-    if(gtb < 0) continue; 
-    Int_t layer = fTrSec[trackingSector]->GetLayerNumber(gtb);
-
-    index=ncl;
-    fTrSec[trackingSector]->GetLayer(layer)->InsertCluster(c,index);
-  }    
-  printf("\r\n");
-
-}
-
 //_____________________________________________________________________________
 Int_t AliTRDtracker::LoadClusters(TTree *cTree)
 {
@@ -1771,9 +1502,16 @@ Int_t AliTRDtracker::LoadClusters(TTree *cTree)
      return 1;
   }
   Int_t ncl=fClusters->GetEntriesFast();
+  fNclusters=ncl;
   cout<<"\n LoadSectors: sorting "<<ncl<<" clusters"<<endl;
               
   UInt_t index;
+  for (Int_t ichamber=0;ichamber<5;ichamber++)
+    for (Int_t isector=0;isector<18;isector++){
+      fHoles[ichamber][isector]=kTRUE;
+    }
+
+
   while (ncl--) {
 //    printf("\r %d left  ",ncl); 
     AliTRDcluster *c=(AliTRDcluster*)fClusters->UncheckedAt(ncl);
@@ -1781,8 +1519,12 @@ Int_t AliTRDtracker::LoadClusters(TTree *cTree)
     Int_t localTimeBin=c->GetLocalTimeBin();
     Int_t sector=fGeom->GetSector(detector);
     Int_t plane=fGeom->GetPlane(detector);
-
+      
     Int_t trackingSector = CookSectorIndex(sector);
+    if (c->GetLabel(0)>0){
+      Int_t chamber = fGeom->GetChamber(detector);
+      fHoles[chamber][trackingSector]=kFALSE;
+    }
 
     Int_t gtb = fTrSec[trackingSector]->CookTimeBinIndex(plane,localTimeBin);
     if(gtb < 0) continue; 
@@ -1791,13 +1533,22 @@ Int_t AliTRDtracker::LoadClusters(TTree *cTree)
     index=ncl;
     fTrSec[trackingSector]->GetLayer(layer)->InsertCluster(c,index);
   }    
-  printf("\r\n");
-
+  //  printf("\r\n");
+  //
+  //
+  /*
+  for (Int_t isector=0;isector<18;isector++){
+    for (Int_t ichamber=0;ichamber<5;ichamber++)      
+      if (fHoles[ichamber][isector]!=fGeom->IsHole(0,ichamber,17-isector)) 
+       printf("Problem \t%d\t%d\t%d\t%d\n",isector,ichamber,fHoles[ichamber][isector],
+            fGeom->IsHole(0,ichamber,17-isector));
+  }
+  */
   return 0;
 }
 
 //_____________________________________________________________________________
-void AliTRDtracker::UnloadEvent() 
+void AliTRDtracker::UnloadClusters() 
 { 
   //
   // Clears the arrays of clusters and tracks. Resets sectors and timebins 
@@ -1807,6 +1558,7 @@ void AliTRDtracker::UnloadEvent()
 
   nentr = fClusters->GetEntriesFast();
   for (i = 0; i < nentr; i++) delete fClusters->RemoveAt(i);
+  fNclusters = 0;
 
   nentr = fSeeds->GetEntriesFast();
   for (i = 0; i < nentr; i++) delete fSeeds->RemoveAt(i);
@@ -1996,7 +1748,7 @@ void AliTRDtracker::MakeSeeds(Int_t inner, Int_t outer, Int_t turn)
 }            
 
 //_____________________________________________________________________________
-Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree) 
+Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree) const
 {
   //
   // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0) 
@@ -2013,12 +1765,12 @@ Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree)
   branch->SetAddress(&clusterArray); 
   
   Int_t nEntries = (Int_t) ClusterTree->GetEntries();
-  printf("found %d entries in %s.\n",nEntries,ClusterTree->GetName());
+  //  printf("found %d entries in %s.\n",nEntries,ClusterTree->GetName());
   
   // Loop through all entries in the tree
-  Int_t nbytes;
+  Int_t nbytes = 0;
   AliTRDcluster *c = 0;
-  printf("\n");
+  //  printf("\n");
 
   for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {    
     
@@ -2047,139 +1799,6 @@ Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree)
   return 0;
 }
 
-//______________________________________________________________________
-void AliTRDtracker::ReadClusters(TObjArray *array, const Char_t *filename)
-{
-  //
-  // Reads AliTRDclusters from file <filename>. The names of the cluster
-  // tree and branches should match the ones used in
-  // AliTRDclusterizer::WriteClusters()
-  // if <array> == 0, clusters are added into AliTRDtracker fCluster array
-  //
-
-  TDirectory *savedir=gDirectory;
-
-  TFile *file = TFile::Open(filename);
-  if (!file->IsOpen()) {
-    cerr<<"Can't open file with TRD clusters"<<endl;
-    return;
-  }
-
-  Char_t treeName[12];
-  sprintf(treeName,"TreeR%d_TRD",GetEventNumber());
-  TTree *clusterTree = (TTree*) gDirectory->Get(treeName);
-
-  if (!clusterTree) {
-     cerr<<"AliTRDtracker::ReadClusters(): ";
-     cerr<<"can't get a tree with clusters !\n";
-     return;
-  }
-
-  TObjArray *clusterArray = new TObjArray(400);
-
-  clusterTree->GetBranch("TRDcluster")->SetAddress(&clusterArray);
-
-  Int_t nEntries = (Int_t) clusterTree->GetEntries();
-  cout<<"found "<<nEntries<<" in clusterTree"<<endl;   
-
-  // Loop through all entries in the tree
-  Int_t nbytes;
-  AliTRDcluster *c = 0;
-
-  printf("\n");
-
-  for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {
-
-    // Import the tree
-    nbytes += clusterTree->GetEvent(iEntry);
-
-    // Get the number of points in the detector
-    Int_t nCluster = clusterArray->GetEntriesFast();
-    printf("\n Read %d clusters from entry %d", nCluster, iEntry);
-
-    // Loop through all TRD digits
-    for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) {
-      c = (AliTRDcluster*)clusterArray->UncheckedAt(iCluster);
-      AliTRDcluster *co = new AliTRDcluster(*c);
-      co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
-      Int_t ltb = co->GetLocalTimeBin();
-      if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
-      else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
-      array->AddLast(co);
-      delete clusterArray->RemoveAt(iCluster);
-    }
-  }
-
-  file->Close();
-  delete clusterArray;
-  savedir->cd();
-
-}                      
-
-void AliTRDtracker::ReadClusters(TObjArray *array, const TFile *inp) 
-{
-  //
-  // Reads AliTRDclusters (option >= 0) or AliTRDrecPoints (option < 0) 
-  // from the file. The names of the cluster tree and branches 
-  // should match the ones used in AliTRDclusterizer::WriteClusters()
-  //
-
-  TDirectory *savedir=gDirectory; 
-
-  if (inp) {
-     TFile *in=(TFile*)inp;
-     if (!in->IsOpen()) {
-        cerr<<"AliTRDtracker::ReadClusters(): input file is not open !\n";
-        return;
-     }
-     else{
-       in->cd();
-     }
-  }
-
-  Char_t treeName[12];
-  sprintf(treeName,"TreeR%d_TRD",GetEventNumber());
-  TTree *clusterTree = (TTree*) gDirectory->Get(treeName);
-  
-  TObjArray *clusterArray = new TObjArray(400); 
-  
-  clusterTree->GetBranch("TRDcluster")->SetAddress(&clusterArray); 
-  
-  Int_t nEntries = (Int_t) clusterTree->GetEntries();
-  printf("found %d entries in %s.\n",nEntries,clusterTree->GetName());
-  
-  // Loop through all entries in the tree
-  Int_t nbytes;
-  AliTRDcluster *c = 0;
-  printf("\n");
-
-  for (Int_t iEntry = 0; iEntry < nEntries; iEntry++) {    
-    
-    // Import the tree
-    nbytes += clusterTree->GetEvent(iEntry);  
-    
-    // Get the number of points in the detector
-    Int_t nCluster = clusterArray->GetEntriesFast();  
-//    printf("\r Read %d clusters from entry %d", nCluster, iEntry);
-    
-    // Loop through all TRD digits
-    for (Int_t iCluster = 0; iCluster < nCluster; iCluster++) { 
-      c = (AliTRDcluster*)clusterArray->UncheckedAt(iCluster);
-      AliTRDcluster *co = new AliTRDcluster(*c);
-      co->SetSigmaY2(c->GetSigmaY2() * fSY2corr);
-      Int_t ltb = co->GetLocalTimeBin();
-      if(ltb == 19) co->SetSigmaZ2(c->GetSigmaZ2());
-      else if(fNoTilt) co->SetSigmaZ2(c->GetSigmaZ2() * fSZ2corr);
-      array->AddLast(co);
-      delete clusterArray->RemoveAt(iCluster); 
-    }
-  }
-
-  delete clusterArray;
-  savedir->cd();   
-
-}
-
 //__________________________________________________________________
 void AliTRDtracker::CookLabel(AliKalmanTrack* pt, Float_t wrong) const 
 {
@@ -2325,6 +1944,7 @@ AliTRDtracker::AliTRDpropagationLayer::AliTRDpropagationLayer(Double_t x,
     fIndex = new UInt_t[kMaxClusterPerTimeBin];
   }
 
+  for (Int_t i=0;i<5;i++) fIsHole[i] = kFALSE;
   fHole = kFALSE;
   fHoleZc = 0;
   fHoleZmax = 0;
@@ -2343,7 +1963,6 @@ void AliTRDtracker::AliTRDpropagationLayer::SetHole(
   //
   // Sets hole in the layer 
   //
-
   fHole = kTRUE;
   fHoleZc = Zc;
   fHoleZmax = Zmax;
@@ -2366,7 +1985,16 @@ AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, I
   fGeomSector = gs;
   fTzeroShift = 0.13;
   fN = 0;
-
+  //
+  // get holes description from geometry
+  Bool_t holes[AliTRDgeometry::kNcham];
+  //printf("sector\t%d\t",gs);
+  for (Int_t icham=0; icham<AliTRDgeometry::kNcham;icham++){
+    holes[icham] = fGeom->IsHole(0,icham,gs);
+    //printf("%d",holes[icham]);
+  } 
+  //printf("\n");
+  
   for(UInt_t i=0; i < kMaxTimeBinIndex; i++) fTimeBinIndex[i] = -1;
 
 
@@ -2473,7 +2101,7 @@ AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, I
   }
 
 
-  Double_t alpha=AliTRDgeometry::GetAlpha();
+  //  Double_t alpha=AliTRDgeometry::GetAlpha();
 
   // add layers for each of the planes
 
@@ -2487,37 +2115,38 @@ AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, I
 
   Int_t tb, tbIndex;
   const Int_t  kNchambers = AliTRDgeometry::Ncham();
-  Double_t  ymax = 0, holeYmax = 0;
+  Double_t  ymax = 0;
+  //, holeYmax = 0;
+  Double_t ymaxsensitive=0;
   Double_t *zc = new Double_t[kNchambers];
   Double_t *zmax = new Double_t[kNchambers];
-  Double_t  holeZmax = 1000.;   // the whole sector is missing
+  Double_t *zmaxsensitive = new Double_t[kNchambers];  
+  //  Double_t  holeZmax = 1000.;   // the whole sector is missing
 
   for(Int_t plane = 0; plane < AliTRDgeometry::Nplan(); plane++) {
-
+    //
     // Radiator 
     xin = xtrd + plane * dxPlane; xout = xin + dxRad;
     steps = 12; dx = (xout - xin)/steps; rho = 0.074; radLength = 40.6; 
     for(Int_t i=0; i<steps; i++) {
       x = xin + i*dx + dx/2;
-      ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
-      if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
-      if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
+      ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);      
       InsertLayer(ppl);
     }
 
-    ymax = fGeom->GetChamberWidth(plane)/2;
+    ymax          = fGeom->GetChamberWidth(plane)/2.;
+    ymaxsensitive = (fPar->GetColPadSize(plane)*fPar->GetColMax(plane)-4)/2.;
+    
     for(Int_t ch = 0; ch < kNchambers; ch++) {
       zmax[ch] = fGeom->GetChamberLength(plane,ch)/2;
       Float_t pad = fPar->GetRowPadSize(plane,ch,0);
       Float_t row0 = fPar->GetRow0(plane,ch,0);
       Int_t nPads = fPar->GetRowMax(plane,ch,0);
-      zc[ch] = (pad * nPads)/2 + row0 - pad/2;
+      zmaxsensitive[ch] = Float_t(nPads)*pad/2.;      
+      //      zc[ch] = (pad * nPads)/2 + row0 - pad/2;
+      zc[ch] = (pad * nPads)/2 + row0;
+      //zc[ch] = row0+zmax[ch]-AliTRDgeometry::RpadW();
+
     }
 
     dx = fPar->GetTimeBinSize(); 
@@ -2526,45 +2155,26 @@ AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, I
     Double_t x0 = (Double_t) fPar->GetTime0(plane);
     Double_t xbottom = x0 - dxDrift;
     Double_t xtop = x0 + dxAmp;
-
+    //
     // Amplification region
-
     steps = (Int_t) (dxAmp/dx);
 
     for(tb = 0; tb < steps; tb++) {
       x = x0 + tb * dx + dx/2;
       tbIndex = CookTimeBinIndex(plane, -tb-1);
       ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
-      ppl->SetYmax(ymax);
-      for(Int_t ch = 0; ch < kNchambers; ch++) {
-        ppl->SetZmax(ch, zc[ch], zmax[ch]);
-      }
-      if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
-      if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
+      ppl->SetYmax(ymax,ymaxsensitive);
+      ppl->SetZ(zc, zmax, zmaxsensitive);
+      ppl->SetHoles(holes);
       InsertLayer(ppl);
     }
     tbIndex = CookTimeBinIndex(plane, -steps);
     x = (x + dx/2 + xtop)/2;
     dx = 2*(xtop-x);
     ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
-    ppl->SetYmax(ymax);
-    for(Int_t ch = 0; ch < kNchambers; ch++) {
-      ppl->SetZmax(ch, zc[ch], zmax[ch]);
-    }
-    if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-      holeYmax = x*TMath::Tan(0.5*alpha);
-      ppl->SetHole(holeYmax, holeZmax);
-    }
-    if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-      holeYmax = x*TMath::Tan(0.5*alpha);
-      ppl->SetHole(holeYmax, holeZmax);
-    }
+    ppl->SetYmax(ymax,ymaxsensitive);
+    ppl->SetZ(zc, zmax,zmaxsensitive);
+    ppl->SetHoles(holes);
     InsertLayer(ppl);
 
     // Drift region
@@ -2576,49 +2186,26 @@ AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, I
       tbIndex = CookTimeBinIndex(plane, tb);
 
       ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
-      ppl->SetYmax(ymax);
-      for(Int_t ch = 0; ch < kNchambers; ch++) {
-        ppl->SetZmax(ch, zc[ch], zmax[ch]);
-      }
-      if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
-      if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
+      ppl->SetYmax(ymax,ymaxsensitive);
+      ppl->SetZ(zc, zmax, zmaxsensitive);
+      ppl->SetHoles(holes);
       InsertLayer(ppl);
     }
     tbIndex = CookTimeBinIndex(plane, steps);
     x = (x - dx/2 + xbottom)/2;
     dx = 2*(x-xbottom);
     ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,tbIndex);
-    ppl->SetYmax(ymax);
-    for(Int_t ch = 0; ch < kNchambers; ch++) {
-      ppl->SetZmax(ch, zc[ch], zmax[ch]);
-    }
-    if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-      holeYmax = x*TMath::Tan(0.5*alpha);
-      ppl->SetHole(holeYmax, holeZmax);
-    }
-    if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-      holeYmax = x*TMath::Tan(0.5*alpha);
-      ppl->SetHole(holeYmax, holeZmax);
-    }
+    ppl->SetYmax(ymax,ymaxsensitive);
+    ppl->SetZ(zc, zmax, zmaxsensitive);
+    ppl->SetHoles(holes);    
     InsertLayer(ppl);
 
     // Pad Plane
     xin = xtop; dx = 0.025; xout = xin + dx; rho = 1.7; radLength = 33.0;
     ppl = new AliTRDpropagationLayer(xin+dx/2,dx,rho,radLength,-1);
-    if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-      holeYmax = (xin+dx/2)*TMath::Tan(0.5*alpha);
-      ppl->SetHole(holeYmax, holeZmax);
-    }
-    if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-      holeYmax = (xin+dx/2)*TMath::Tan(0.5*alpha);
-      ppl->SetHole(holeYmax, holeZmax);
-    }
+    ppl->SetYmax(ymax,ymaxsensitive);
+    ppl->SetZ(zc, zmax,zmax);
+    ppl->SetHoles(holes);        
     InsertLayer(ppl);
 
     // Rohacell
@@ -2627,14 +2214,9 @@ AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, I
     for(Int_t i=0; i<steps; i++) {
       x = xin + i*dx + dx/2;
       ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
-      if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
-      if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
+      ppl->SetYmax(ymax,ymaxsensitive);
+      ppl->SetZ(zc, zmax,zmax);
+      ppl->SetHoles(holes);
       InsertLayer(ppl);
     }
 
@@ -2644,14 +2226,6 @@ AliTRDtracker::AliTRDtrackingSector::AliTRDtrackingSector(AliTRDgeometry* geo, I
     for(Int_t i=0; i<steps; i++) {
       x = xin + i*dx + dx/2;
       ppl = new AliTRDpropagationLayer(x,dx,rho,radLength,-1);
-      if((fGeom->GetPHOShole()) && (fGeomSector >= 2) && (fGeomSector <= 6)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
-      if((fGeom->GetRICHhole()) && (fGeomSector >= 12) && (fGeomSector <= 14)) {
-        holeYmax = x*TMath::Tan(0.5*alpha);
-        ppl->SetHole(holeYmax, holeZmax);
-      }
       InsertLayer(ppl);
     }
   }    
@@ -2850,8 +2424,33 @@ Int_t AliTRDtracker::AliTRDtrackingSector::Find(Double_t x) const
   return m;
 }             
 
+//______________________________________________________
+void AliTRDtracker::AliTRDpropagationLayer::SetZ(Double_t* center, Double_t *w, Double_t *wsensitive )
+{
+  //
+  // set centers and the width of sectors
+  for (Int_t icham=0;icham< AliTRDgeometry::kNcham;icham++){
+    fZc[icham] = center[icham];  
+    fZmax[icham] = w[icham];
+    fZmaxSensitive[icham] = wsensitive[icham];
+    //   printf("chamber\t%d\tzc\t%f\tzmax\t%f\tzsens\t%f\n",icham,fZc[icham],fZmax[icham],fZmaxSensitive[icham]);
+  }  
+}
 //______________________________________________________
 
+void AliTRDtracker::AliTRDpropagationLayer::SetHoles(Bool_t *holes)
+{
+  //
+  // set centers and the width of sectors
+  fHole = kFALSE;
+  for (Int_t icham=0;icham< AliTRDgeometry::kNcham;icham++){
+    fIsHole[icham] = holes[icham]; 
+    if (holes[icham]) fHole = kTRUE;
+  }  
+}
+
+
+
 void AliTRDtracker::AliTRDpropagationLayer::GetPropagationParameters(
         Double_t y, Double_t z, Double_t &dx, Double_t &rho, Double_t &radLength, 
         Bool_t &lookForCluster) const
@@ -2865,31 +2464,58 @@ void AliTRDtracker::AliTRDpropagationLayer::GetPropagationParameters(
   rho = fRho;
   radLength  = fX0;
   lookForCluster = kFALSE;
-
-  // check dead regions
+  //
+  // check dead regions in sensitive volume 
   if(fTimeBinIndex >= 0) {
+    //
+    Int_t zone=-1;
     for(Int_t ch = 0; ch < (Int_t) kZones; ch++) {
-      if(TMath::Abs(z - fZc[ch]) < fZmax[ch]) 
-        lookForCluster = kTRUE;
-      //  else { rho = 1.7; radLength = 33.0; } // G10 
-    }
-    if(TMath::Abs(y) > fYmax) lookForCluster = kFALSE;
-    if(!lookForCluster) { 
-      //      rho = 1.7; radLength = 33.0; // G10 
+      if  (TMath::Abs(z - fZc[ch]) < fZmaxSensitive[ch]){ 
+       zone = ch;
+       lookForCluster = !(fIsHole[zone]);
+       if(TMath::Abs(y) > fYmaxSensitive){  
+         lookForCluster = kFALSE;
+       }
+       if (fIsHole[zone]) {
+         //if hole
+         rho = 1.29e-3;
+         radLength = 36.66;
+       }
+      }    
     }
+    return;
   }
-
+  //
+  //
   // check hole
-  if(fHole && (TMath::Abs(y - fHoleYc) < fHoleYmax) && 
-              (TMath::Abs(z - fHoleZc) < fHoleZmax)) {
-    lookForCluster = kFALSE;
-    rho = fHoleRho;
-    radLength  = fHoleX0;
-  }         
-
+  if (fHole==kFALSE) return;
+  //
+  for(Int_t ch = 0; ch < (Int_t) kZones; ch++) {
+    if  (TMath::Abs(z - fZc[ch]) < fZmax[ch]){ 
+      if (fIsHole[ch]) {
+       //if hole
+       rho = 1.29e-3;
+       radLength = 36.66;
+      }
+    }
+  }
   return;
 }
 
+Int_t  AliTRDtracker::AliTRDpropagationLayer::GetZone( Double_t z) const
+{
+  //
+  //
+  if (fTimeBinIndex < 0) return -20;  //unknown 
+  Int_t zone=-10;   // dead zone
+  for(Int_t ch = 0; ch < (Int_t) kZones; ch++) {
+    if(TMath::Abs(z - fZc[ch]) < fZmax[ch]) 
+      zone = ch;
+  }
+  return zone;
+}
+
+
 //______________________________________________________
 
 void AliTRDtracker::AliTRDpropagationLayer::InsertCluster(AliTRDcluster* c, 
@@ -2941,7 +2567,8 @@ Double_t AliTRDtracker::GetTiltFactor(const AliTRDcluster* c) {
   Int_t det = c->GetDetector();    
   Int_t plane = fGeom->GetPlane(det);
 
-  if((plane == 1) || (plane == 3) || (plane == 5)) h01=-h01;
+  //if((plane == 1) || (plane == 3) || (plane == 5)) h01=-h01;
+  if((plane == 0) || (plane == 2) || (plane == 4)) h01=-h01;
 
   if(fNoTilt) h01 = 0;