]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtracker.cxx
Reconstruction and PID using transition radiation photons: first implementation ...
[u/mrichter/AliRoot.git] / TRD / AliTRDtracker.cxx
index 657e19dd2340dce53ae4d9e1de39ba3b4e2c57dd..da922a7133c7ae08763b278bee776dbc3e058e04 100644 (file)
 
 #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"
 
@@ -87,6 +86,8 @@ AliTRDtracker::AliTRDtracker():AliTracker(),
                               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;
@@ -416,173 +417,6 @@ Int_t  AliTRDtracker::GetLastPlane(AliTRDtrack * track){
   }
   return lastplane;
 }
-//___________________________________________________________________
-Int_t AliTRDtracker::Clusters2Tracks(const TFile *inp, TFile *out)
-{
-  //
-  // 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>. 
-  //
-
-  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();
-    }
-    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
-
-  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--;
-        }
-      }
-    }
-  }
-  tpcTree.Write(); 
-  trdTree.Write(); 
-  
-  cout<<"Total number of found tracks: "<<found<<endl;
-    
-  UnloadEvent();
-    
-  savedir->cd();  
-  
-  return 0;    
-}     
-          
 //___________________________________________________________________
 Int_t AliTRDtracker::Clusters2Tracks(AliESD* event)
 {
@@ -657,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; 
@@ -673,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);
@@ -689,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) {
   //
@@ -891,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++) {
@@ -903,9 +548,13 @@ Int_t AliTRDtracker::PropagateBack(AliESD* event) {
     Int_t lbl = seed->GetLabel();
     AliTRDtrack *track = new AliTRDtrack(*seed);
     track->SetSeedLabel(lbl);
+    seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup); //make backup
     fNseeds++;
-
+    Float_t p4 = track->GetC();
+    //
     Int_t expectedClr = FollowBackProlongation(*track);
+    /*
+      // only debug purpose
     if (track->GetNumberOfClusters()<expectedClr/3){
       AliTRDtrack *track1 = new AliTRDtrack(*seed);
       track1->SetSeedLabel(lbl);
@@ -916,57 +565,87 @@ Int_t AliTRDtracker::PropagateBack(AliESD* event) {
       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);
+      track->CookdEdx(0.,1.);
+      CookdEdxTimBin(*track);
+      CookLabel(track, 1-fgkLabelFraction);
+      if(track->GetChi2()/track->GetNumberOfClusters()<6) {   // sign only gold tracks
        UseClusters(track);
       }
-      
-      // Propagate to outer reference plane [SR, GSI, 18.02.2003]
-//      track->PropagateTo(364.8);  why?
-      
-      //seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
-      //found++;
+      Bool_t isGold = kFALSE;
+     
+      if (track->GetChi2()/track->GetNumberOfClusters()<5) {  //full gold track
+       seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
+       isGold = kTRUE;
+      }
+      if (!isGold && track->GetNCross()==0&&track->GetChi2()/track->GetNumberOfClusters()<7){ //almost gold track
+       seed->UpdateTrackParams(track, AliESDtrack::kTRDbackup);
+       isGold = kTRUE;
+      }
+      if (!isGold && track->GetBackupTrack()){
+       if (track->GetBackupTrack()->GetNumberOfClusters()>foundMin&&
+           (track->GetBackupTrack()->GetChi2()/(track->GetBackupTrack()->GetNumberOfClusters()+1))<7){   
+         seed->UpdateTrackParams(track->GetBackupTrack(), AliESDtrack::kTRDbackup);
+         isGold = kTRUE;
+       }
+      }
+    }
+    else{
+      continue;
     }
 
-    //Propagation to the TOF (I.Belikov)
     
     if (track->GetStop()==kFALSE){
-      Double_t xTOF = 375.5;    
-      PropagateToOuterPlane(*track,xTOF); 
-      
-      Double_t xtof=378.;
+
+      Double_t xtof=371.;
       Double_t c2=track->GetC()*xtof - track->GetEta();
-      if (TMath::Abs(c2)>=0.9999999){
+      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;
-         return 1;
+         continue;
        }
       } else if (y <-ymax) {
        if (!track->Rotate(-AliTRDgeometry::GetAlpha())) {
          delete track;
-         return 1;
+         continue;
        }
       }
       
       if (track->PropagateTo(xtof)) {
-       seed->UpdateTrackParams(track, AliESDtrack::kTRDout);    
+       seed->UpdateTrackParams(track, AliESDtrack::kTRDout);
+        for (Int_t i=0;i<kNPlane;i++) {
+           seed->SetTRDsignals(track->GetPIDsignals(i),i);
+           seed->SetTRDTimBin(track->GetPIDTimBin(i),i);
+        }
+       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->UpdateTrackParams(track, AliESDtrack::kTRDStop);    
+       //seed->SetStatus(AliESDtrack::kTRDStop);    
+        for (Int_t i=0;i<kNPlane;i++) {
+           seed->SetTRDsignals(track->GetPIDsignals(i),i);
+           seed->SetTRDTimBin(track->GetPIDTimBin(i),i);
+        }
+       seed->SetTRDtrack(new AliTRDtrack(*track));
        found++;
       }
     }
@@ -1009,14 +688,23 @@ Int_t AliTRDtracker::RefitInward(AliESD* event)
   Int_t n = event->GetNumberOfTracks();
   for (Int_t i=0; i<n; i++) {
     AliESDtrack* seed=event->GetTrack(i);
+    AliTRDtrack* seed2 = new AliTRDtrack(*seed);
+    if (seed2->GetX()<270){
+      seed->UpdateTrackParams(seed2, AliESDtrack::kTRDbackup); // backup TPC track - only update
+      continue;
+    }
+
     ULong_t status=seed->GetStatus();
     if ( (status & AliESDtrack::kTRDout ) == 0 ) continue;
     if ( (status & AliESDtrack::kTRDin) != 0 ) continue;
-    nseed++;
-
-    AliTRDtrack* seed2 = new AliTRDtrack(*seed);
+    nseed++;    
     seed2->ResetCovariance(5.); 
     AliTRDtrack *pt = new AliTRDtrack(*seed2,seed2->GetAlpha());
+    for (Int_t i=0;i<kNPlane;i++) {
+        pt->SetPIDsignals(seed2->GetPIDsignals(i),i);
+        pt->SetPIDTimBin(seed2->GetPIDTimBin(i),i);
+    }
+
     UInt_t * indexes2 = seed2->GetIndexes();
     UInt_t * indexes3 = pt->GetBackupIndexes();
     for (Int_t i=0;i<200;i++) {
@@ -1026,7 +714,7 @@ Int_t AliTRDtracker::RefitInward(AliESD* event)
     //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());
@@ -1039,7 +727,7 @@ Int_t AliTRDtracker::RefitInward(AliESD* event)
       FollowProlongation(*pt2, innerTB);
       delete pt2;
     }
-
+    */
     if (t.GetNumberOfClusters() >= foundMin) {
       //      UseClusters(&t);
       //CookLabel(pt, 1-fgkLabelFraction);
@@ -1050,10 +738,31 @@ Int_t AliTRDtracker::RefitInward(AliESD* event)
 
     if(PropagateToTPC(t)) {
       seed->UpdateTrackParams(pt, AliESDtrack::kTRDrefit);
+      for (Int_t i=0;i<kNPlane;i++) {
+        seed->SetTRDsignals(pt->GetPIDsignals(i),i);
+        seed->SetTRDTimBin(pt->GetPIDTimBin(i),i);
+      }
+    }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)) { 
+        pt2->CookdEdx(0.,1.);
+        CookdEdxTimBin(*pt2);
+       seed->UpdateTrackParams(pt2, AliESDtrack::kTRDrefit);
+        for (Int_t i=0;i<kNPlane;i++) {
+          seed->SetTRDsignals(seed2->GetPIDsignals(i),i);
+          seed->SetTRDTimBin(seed2->GetPIDTimBin(i),i);
+        }
+      }
+      delete pt2;
     }  
+
     delete seed2;
     delete pt;
-  }     
+  }   
 
   cout<<"Number of loaded seeds: "<<nseed<<endl;  
   cout<<"Number of found tracks from loaded seeds: "<<found<<endl;
@@ -1323,6 +1032,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;
@@ -1372,15 +1082,23 @@ Int_t AliTRDtracker::FollowBackProlongation(AliTRDtrack& t)
     //
     // MI -fix untill correct material desription will be implemented
     //
-    Float_t angle =  t.GetAlpha();  // MI - if rotation - we go through the material 
+    Float_t angle =  t.GetAlpha();  // MI - if rotation - we go through the material 
     if (!AdjustSector(&t)) break;
-    if (TMath::Abs(angle -  t.GetAlpha())>0.000001) break; //better to stop track
+    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) break;  // we are in the frame
+    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) break;  
+      if (zone!=currentzone) cross=kTRUE;  
     }
+    if (cross) {
+      t.IncCross();
+      if (t.GetNCross()==1) t.MakeBackupTrack();
+      if (t.GetNCross()>2) break;
+    }
+    
     //
     //
     s = t.GetSector();
@@ -1812,42 +1530,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<<"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)
 {
@@ -1860,6 +1546,7 @@ 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;
@@ -1890,7 +1577,7 @@ Int_t AliTRDtracker::LoadClusters(TTree *cTree)
     index=ncl;
     fTrSec[trackingSector]->GetLayer(layer)->InsertCluster(c,index);
   }    
-  printf("\r\n");
+  //  printf("\r\n");
   //
   //
   /*
@@ -1905,7 +1592,7 @@ Int_t AliTRDtracker::LoadClusters(TTree *cTree)
 }
 
 //_____________________________________________________________________________
-void AliTRDtracker::UnloadEvent() 
+void AliTRDtracker::UnloadClusters() 
 { 
   //
   // Clears the arrays of clusters and tracks. Resets sectors and timebins 
@@ -1915,6 +1602,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);
@@ -2104,7 +1792,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) 
@@ -2124,9 +1812,9 @@ Int_t AliTRDtracker::ReadClusters(TObjArray *array, TTree *ClusterTree)
   //  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++) {    
     
@@ -2155,139 +1843,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 
 {
@@ -3056,7 +2611,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;
   
@@ -3064,6 +2620,66 @@ Double_t AliTRDtracker::GetTiltFactor(const AliTRDcluster* c) {
 }
 
 
+void AliTRDtracker::CookdEdxTimBin(AliTRDtrack& TRDtrack)
+{
+  // *** ADDED TO GET MORE INFORMATION FOR TRD PID  ---- PS
+  // This is setting fdEdxPlane and fTimBinPlane
+  // Sums up the charge in each plane for track TRDtrack and also get the 
+  // Time bin for Max. Cluster
+  // Prashant Shukla (shukla@physi.uni-heidelberg.de)
+
+  //  const Int_t kNPlane = AliTRDgeometry::Nplan();
+  //  const Int_t kNPlane = 6;
+  Double_t  clscharge[kNPlane], maxclscharge[kNPlane];
+  Int_t  nCluster[kNPlane], timebin[kNPlane];
+
+  //Initialization of cluster charge per plane.  
+  for (Int_t iPlane = 0; iPlane < kNPlane; iPlane++) {
+    clscharge[iPlane] = 0.0;
+    nCluster[iPlane] = 0;
+    timebin[iPlane] = -1;
+    maxclscharge[iPlane] = 0.0;
+  }
+
+  // Loop through all clusters associated to track TRDtrack
+  Int_t nClus = TRDtrack.GetNumberOfClusters();  // from Kalmantrack
+  for (Int_t iClus = 0; iClus < nClus; iClus++) {
+    Double_t charge = TRDtrack.GetClusterdQdl(iClus);
+    Int_t index = TRDtrack.GetClusterIndex(iClus);
+    AliTRDcluster *TRDcluster = (AliTRDcluster *) GetCluster(index); 
+    if (!TRDcluster) continue;
+    Int_t tb = TRDcluster->GetLocalTimeBin();
+    if (!tb) continue;
+    Int_t detector = TRDcluster->GetDetector();
+    Int_t iPlane   = fGeom->GetPlane(detector);
+    clscharge[iPlane] = clscharge[iPlane]+charge;
+    if(charge > maxclscharge[iPlane]) {
+      maxclscharge[iPlane] = charge;
+      timebin[iPlane] = tb;
+    }
+    nCluster[iPlane]++;
+  } // end of loop over cluster
+
+  // Setting the fdEdxPlane and fTimBinPlane variabales 
+  Double_t Total_ch = 0;
+  for (Int_t iPlane = 0; iPlane < kNPlane; iPlane++) {
+    if (nCluster[iPlane]) clscharge[iPlane] /= nCluster[iPlane];
+    TRDtrack.SetPIDsignals(clscharge[iPlane], iPlane);
+    TRDtrack.SetPIDTimBin(timebin[iPlane], iPlane);
+    Total_ch= Total_ch+clscharge[iPlane];
+  }
+  //  Int_t i;
+  //  Int_t nc=TRDtrack.GetNumberOfClusters(); 
+  //  Float_t dedx=0;
+  //  for (i=0; i<nc; i++) dedx += TRDtrack.GetClusterdQdl(i);
+  //  dedx /= nc;
+  //  for (Int_t iPlane = 0; iPlane < kNPlane; iPlane++) {
+  //    TRDtrack.SetPIDsignals(dedx, iPlane);
+  //    TRDtrack.SetPIDTimBin(timbin[iPlane], iPlane);
+  //  }
+
+} // end of function
+