]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDtrackerV1.cxx
Added protection against wrongly formed cloning list
[u/mrichter/AliRoot.git] / TRD / AliTRDtrackerV1.cxx
index 334417376e4911e9a9025d934a4784a6e604d2af..e49f3787d2c1e9f6458c96a8319a7f9292c0af7a 100644 (file)
@@ -61,11 +61,7 @@ ClassImp(AliTRDtrackerV1)
 ClassImp(AliTRDtrackerV1::AliTRDLeastSquare)
 ClassImp(AliTRDtrackerV1::AliTRDtrackFitterRieman)
 
-const  Float_t  AliTRDtrackerV1::fgkMinClustersInTrack =  0.5;  //
-const  Float_t  AliTRDtrackerV1::fgkLabelFraction      =  0.8;  //
-const  Double_t AliTRDtrackerV1::fgkMaxChi2            = 12.0;  //
-const  Double_t AliTRDtrackerV1::fgkMaxSnp             =  0.95; // Maximum local sine of the azimuthal angle
-const  Double_t AliTRDtrackerV1::fgkMaxStep            =  2.0;  // Maximal step size in propagation 
+AliTRDtrackerV1::ETRDtrackerV1BetheBloch AliTRDtrackerV1::fgBB = AliTRDtrackerV1::kGeant;
 Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
   0.5112, 0.5112, 0.5112, 0.0786, 0.0786,
   0.0786, 0.0786, 0.0579, 0.0579, 0.0474,
@@ -73,6 +69,8 @@ Double_t AliTRDtrackerV1::fgTopologicQA[kNConfigs] = {
 };  
 const Double_t AliTRDtrackerV1::fgkX0[kNPlanes]    = {
   300.2, 312.8, 325.4, 338.0, 350.6, 363.2};
+// Number of Time Bins/chamber should be also stored independently by the traker
+// (also in AliTRDReconstructor) in oder to be able to run HLT. Fix TODO
 Int_t AliTRDtrackerV1::fgNTimeBins = 0;
 AliRieman* AliTRDtrackerV1::fgRieman = NULL;
 TLinearFitter* AliTRDtrackerV1::fgTiltedRieman = NULL;
@@ -89,6 +87,7 @@ AliTRDtrackerV1::AliTRDtrackerV1(AliTRDReconstructor *rec)
   ,fTracks(NULL)
   ,fTracksESD(NULL)
   ,fSieveSeeding(0)
+  ,fEventInFile(-1)
 {
   //
   // Default constructor.
@@ -288,12 +287,13 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
   
   Float_t *quality = NULL;
   Int_t   *index   = NULL;
+  fEventInFile  = event->GetEventNumberInFile();
   nSeeds   = event->GetNumberOfTracks();
   // Sort tracks according to quality 
   // (covariance in the yz plane)
   if(nSeeds){  
     quality = new Float_t[nSeeds];
-    index   = new Int_t[nSeeds];
+    index   = new Int_t[4*nSeeds];
     for (Int_t iSeed = nSeeds; iSeed--;) {
       AliESDtrack *seed = event->GetTrack(iSeed);
       Double_t covariance[15];
@@ -320,7 +320,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
     // Propagate to the entrance in the TRD mother volume
     track.~AliTRDtrackV1();
     new(&track) AliTRDtrackV1(*seed);
-    if(AliTRDgeometry::GetXtrdBeg() > (fgkMaxStep + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), fgkMaxStep)){ 
+    if(AliTRDgeometry::GetXtrdBeg() > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, AliTRDgeometry::GetXtrdBeg(), AliTRDReconstructor::GetMaxStep())){
       seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
       continue;
     }    
@@ -328,7 +328,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
       seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
       continue;
     }
-    if(TMath::Abs(track.GetSnp()) > fgkMaxSnp) {
+    if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
       seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
       continue;
     }
@@ -375,7 +375,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
       // Make backup for back propagation
       Int_t foundClr = track.GetNumberOfClusters();
       if (foundClr >= foundMin) {
-        track.CookLabel(1. - fgkLabelFraction);
+        track.CookLabel(1. - AliTRDReconstructor::GetLabelFraction());
         //if(track.GetBackupTrack()) UseClusters(track.GetBackupTrack());
 
         // Sign only gold tracks
@@ -430,7 +430,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
           xtof = TMath::Sqrt(glob[0]*glob[0]+glob[1]*glob[1]);
         }
       }
-      if(xtof > (fgkMaxStep + track.GetX()) && !PropagateToX(track, xtof, fgkMaxStep)){ 
+      if(xtof > (AliTRDReconstructor::GetMaxStep() + track.GetX()) && !PropagateToX(track, xtof, AliTRDReconstructor::GetMaxStep())){
         seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
         continue;
       }
@@ -438,7 +438,7 @@ Int_t AliTRDtrackerV1::PropagateBack(AliESDEvent *event)
         seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
         continue;
       }
-      if(TMath::Abs(track.GetSnp()) > fgkMaxSnp){ 
+      if(TMath::Abs(track.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
         seed->UpdateTrackParams(&track, AliESDtrack::kTRDStop);
         continue;
       }
@@ -514,7 +514,7 @@ Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
       }
 
       // Prolongate to TPC
-      if (PropagateToX(track, xTPC, fgkMaxStep)) { //  -with update
+      if (PropagateToX(track, xTPC, AliTRDReconstructor::GetMaxStep())) { //  -with update
         seed->UpdateTrackParams(&track, AliESDtrack::kTRDrefit);
         found++;
         kUPDATE = kTRUE;
@@ -524,7 +524,7 @@ Int_t AliTRDtrackerV1::RefitInward(AliESDEvent *event)
     // Prolongate to TPC without update
     if(!kUPDATE) {
       AliTRDtrackV1 tt(*seed);
-      if (PropagateToX(tt, xTPC, fgkMaxStep)) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
+      if (PropagateToX(tt, xTPC, AliTRDReconstructor::GetMaxStep())) seed->UpdateTrackParams(&tt, AliESDtrack::kTRDbackup);
     }
   }
   AliInfo(Form("Number of seeds: TRDout[%d]", nseed));
@@ -572,12 +572,12 @@ Int_t AliTRDtrackerV1::FollowProlongation(AliTRDtrackV1 &t)
     }
     Double_t x  = tracklet->GetX();//GetX0();
     // reject tracklets which are not considered for inward refit
-    if(x > t.GetX()+fgkMaxStep) continue;
+    if(x > t.GetX()+AliTRDReconstructor::GetMaxStep()) continue;
 
     // append tracklet to track
     t.SetTracklet(tracklet, index);
     
-    if (x < (t.GetX()-fgkMaxStep) && !PropagateToX(t, x+fgkMaxStep, fgkMaxStep)) break;
+    if (x < (t.GetX()-AliTRDReconstructor::GetMaxStep()) && !PropagateToX(t, x+AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) break;
     if (!AdjustSector(&t)) break;
     
     // Start global position
@@ -728,7 +728,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
 
   // Loop through the TRD layers
   TGeoHMatrix *matrix = NULL;
-  Double_t x, y, z;
+  Double_t x(0.), y(0.), z(0.);
   for (Int_t ily=startLayer, sm=-1, stk=-1, det=-1; ily < AliTRDgeometry::kNlayer; ily++) {
     AliDebug(2, Form("Propagate to x[%d] = %7.2f", ily, fR[ily]));
 
@@ -746,7 +746,6 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     stk = fGeom->GetStack(z, ily);
     det = stk>=0 ? AliTRDgeometry::GetDetector(ily, stk, sm) : -1;
     matrix = det>=0 ? fGeom->GetClusterMatrix(det) : NULL;
-    AliDebug(3, Form("Propagate to det[%3d]", det));
 
     // check if supermodule/chamber is installed
     if( !fGeom->GetSMstatus(sm) ||
@@ -755,7 +754,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
         !matrix ){ 
       AliDebug(4, Form("Missing Geometry ly[%d]. Guess radial position", ily));
       // propagate to the default radial position
-      if(fR[ily] > (fgkMaxStep + t.GetX()) && !PropagateToX(t, fR[ily], fgkMaxStep)){
+      if(fR[ily] > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, fR[ily], AliTRDReconstructor::GetMaxStep())){
         n=-1; 
         t.SetStatus(AliTRDtrackV1::kPropagation);
         AliDebug(4, "Failed Propagation [Missing Geometry]");
@@ -767,7 +766,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
         AliDebug(4, "Failed Adjust Sector [Missing Geometry]");
         break;
       }
-      if(TMath::Abs(t.GetSnp()) > fgkMaxSnp){
+      if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()){
         n=-1; 
         t.SetStatus(AliTRDtrackV1::kSnp);
         AliDebug(4, "Failed Max Snp [Missing Geometry]");
@@ -781,10 +780,11 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     Double_t loc[] = {AliTRDgeometry::AnodePos()- driftLength, 0., 0.};
     Double_t glb[] = {0., 0., 0.};
     matrix->LocalToMaster(loc, glb);
+    AliDebug(3, Form("Propagate to det[%3d] x_anode[%7.2f] (%f %f)", det, glb[0]+driftLength, glb[1], glb[2]));
 
     // Propagate to the radial distance of the current layer
-    x = glb[0] - fgkMaxStep;
-    if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)){
+    x = glb[0] - AliTRDReconstructor::GetMaxStep();
+    if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())){
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kPropagation);
       AliDebug(4, Form("Failed Initial Propagation to x[%7.2f]", x));
@@ -796,10 +796,10 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
       AliDebug(4, "Failed Adjust Sector Start");
       break;
     }
-    if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
+    if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kSnp);
-      AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
+      AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
       break;
     }
     Bool_t doRecalculate = kFALSE;
@@ -819,14 +819,14 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
         continue;
       }
       matrix->LocalToMaster(loc, glb);
-      x = glb[0] - fgkMaxStep;
+      x = glb[0] - AliTRDReconstructor::GetMaxStep();
     }
 
     // check if track is well inside fiducial volume 
-    if (!t.GetProlongation(x+fgkMaxStep, y, z)) {
+    if (!t.GetProlongation(x+AliTRDReconstructor::GetMaxStep(), y, z)) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kProlongation);
-      AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+fgkMaxStep, y, z));
+      AliDebug(4, Form("Failed Prolongation to x[%7.2f] y[%7.2f] z[%7.2f]", x+AliTRDReconstructor::GetMaxStep(), y, z));
       break;
     }
     if(fGeom->IsOnBoundary(det, y, z, .5)){ 
@@ -834,11 +834,6 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
       AliDebug(4, "Failed Track on Boundary");
       continue;
     }
-    // mark track as entering the FIDUCIAL volume of TRD
-    if(kStoreIn){
-      t.SetTrackIn(); 
-      kStoreIn = kFALSE;
-    }
 
     ptrTracklet  = tracklets[ily];
     if(!ptrTracklet){ // BUILD TRACKLET
@@ -880,12 +875,12 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
         AliDebug(4, "Failed Tracklet Init");
         break;
       }
-      if(!ptrTracklet->AttachClusters(chamber, kTRUE)){
+      if(!ptrTracklet->AttachClusters(chamber, kTRUE, t.Charge()>0?kTRUE:kFALSE, fEventInFile)){
         t.SetStatus(AliTRDtrackV1::kNoAttach, ily);
         if(debugLevel>3){
           AliTRDseedV1 trackletCp(*ptrTracklet);
           UChar_t status(t.GetStatusTRD(ily));
-          (*cstreamer)   << "FollowBackProlongation2"
+          (*cstreamer)   << "FollowBackProlongation4"
           <<"status="    << status
           <<"tracklet.=" << &trackletCp
           << "\n";
@@ -899,7 +894,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
         if(debugLevel>3){
           AliTRDseedV1 trackletCp(*ptrTracklet);
           UChar_t status(t.GetStatusTRD(ily));
-          (*cstreamer)   << "FollowBackProlongation2"
+          (*cstreamer)   << "FollowBackProlongation4"
           <<"status="    << status
           <<"tracklet.=" << &trackletCp
           << "\n";
@@ -915,13 +910,13 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
     // tilt correction options
     // 0 : no correction
     // 2 : pseudo tilt correction
-    if(!ptrTracklet->Fit(2)){
+    if(!ptrTracklet->FitRobust(t.Charge()>0?kTRUE:kFALSE)){
       t.SetStatus(AliTRDtrackV1::kNoFit, ily);
       AliDebug(4, "Failed Tracklet Fit");
       continue;
     } 
     x = ptrTracklet->GetX(); //GetX0();
-    if(x > (fgkMaxStep + t.GetX()) && !PropagateToX(t, x, fgkMaxStep)) {
+    if(x > (AliTRDReconstructor::GetMaxStep() + t.GetX()) && !PropagateToX(t, x, AliTRDReconstructor::GetMaxStep())) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kPropagation);
       AliDebug(4, Form("Failed Propagation to Tracklet x[%7.2f]", x));
@@ -933,10 +928,10 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
       AliDebug(4, "Failed Adjust Sector");
       break;
     }
-    if(TMath::Abs(t.GetSnp()) > fgkMaxSnp) {
+    if(TMath::Abs(t.GetSnp()) > AliTRDReconstructor::GetMaxSnp()) {
       n=-1; 
       t.SetStatus(AliTRDtrackV1::kSnp);
-      AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), fgkMaxSnp));
+      AliDebug(4, Form("Failed Max Snp[%f] MaxSnp[%f]", t.GetSnp(), AliTRDReconstructor::GetMaxSnp()));
       break;
     }
     Double_t cov[3]; ptrTracklet->GetCovAt(x, cov);
@@ -950,7 +945,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
         AliTRDseedV1  trackletCp(*ptrTracklet);
         AliTRDtrackV1 trackCp(t);
         trackCp.SetOwner();
-        (*cstreamer) << "FollowBackProlongation1"
+        (*cstreamer) << "FollowBackProlongation3"
             << "status="      << status
             << "tracklet.="   << &trackletCp
             << "track.="      << &trackCp
@@ -959,6 +954,11 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
       AliDebug(4, Form("Failed Chi2[%f]", chi2));
       continue; 
     }
+    // mark track as entering the FIDUCIAL volume of TRD
+    if(kStoreIn){
+      t.SetTrackIn();
+      kStoreIn = kFALSE;
+    }
     if(kUseTRD){
       if(!((AliExternalTrackParam&)t).Update(p, cov)) {
         n=-1; 
@@ -968,7 +968,7 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
           AliTRDseedV1  trackletCp(*ptrTracklet);
           AliTRDtrackV1 trackCp(t);
           trackCp.SetOwner();
-          (*cstreamer) << "FollowBackProlongation1"
+          (*cstreamer) << "FollowBackProlongation3"
               << "status="      << status
               << "tracklet.="   << &trackletCp
               << "track.="      << &trackCp
@@ -1006,13 +1006,12 @@ Int_t AliTRDtrackerV1::FollowBackProlongation(AliTRDtrackV1 &t)
   //printf("clusters[%d] chi2[%f] x[%f] status[%d ", n, t.GetChi2(), t.GetX(), t.GetStatusTRD());
   //for(int i=0; i<6; i++) printf("%d ", t.GetStatusTRD(i)); printf("]\n");
 
-  if(debugLevel > 1){
-    Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
+  if(n && debugLevel > 1){
+    //Int_t eventNumber = AliTRDtrackerDebug::GetEventNumber();
     AliTRDtrackV1 track(t);
     track.SetOwner();
-    (*cstreamer) << "FollowBackProlongation0"
-        << "EventNumber=" << eventNumber
-        << "ncl="         << n
+    (*cstreamer) << "FollowBackProlongation2"
+        << "EventNumber=" << fEventInFile
         << "track.="      << &track
         << "\n";
   }
@@ -1671,7 +1670,8 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const t
   //if(points) printf("First marker point @ x[%d] = %f\n", ip, points[ip].GetX());
 
 
-  AliTRDseedV1 tracklet, *ptrTracklet = NULL;
+  AliTRDseedV1 tracklet;
+  AliTRDseedV1 *ptrTracklet = NULL;
 
   //Loop through the TRD planes
   for (Int_t jplane = 0; jplane < kNPlanes; jplane++) {
@@ -1694,8 +1694,8 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const t
 
     while(ip < np){
       //don't do anything if next marker is after next update point.
-      if((up?-1:1) * (points[ip].GetX() - x) - fgkMaxStep < 0) break;
-      if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
+      if((up?-1:1) * (points[ip].GetX() - x) - AliTRDReconstructor::GetMaxStep() < 0) break;
+      if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
       
       Double_t xyz[3]; // should also get the covariance
       track->GetXYZ(xyz);
@@ -1706,10 +1706,10 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const t
     // printf("plane[%d] tracklet[%p] x[%f]\n", iplane, ptrTracklet, x);
 
     // Propagate closer to the next update point 
-    if(((up?-1:1) * (x - track->GetX()) + fgkMaxStep < 0) && !PropagateToX(*track, x + (up?-1:1)*fgkMaxStep, fgkMaxStep)) return -1.;
+    if(((up?-1:1) * (x - track->GetX()) + AliTRDReconstructor::GetMaxStep() < 0) && !PropagateToX(*track, x + (up?-1:1)*AliTRDReconstructor::GetMaxStep(), AliTRDReconstructor::GetMaxStep())) return -1.;
 
     if(!AdjustSector(track)) return -1;
-    if(TMath::Abs(track->GetSnp()) > fgkMaxSnp) return -1;
+    if(TMath::Abs(track->GetSnp()) > AliTRDReconstructor::GetMaxSnp()) return -1;
     
     //load tracklet to the tracker and the track
 /*    Int_t index;
@@ -1758,7 +1758,7 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const t
 
   // extrapolation
   while(ip < np){
-    if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), fgkMaxStep)) return -1.;
+    if(((up?-1:1) * (points[ip].GetX() - track->GetX()) < 0) && !PropagateToX(*track, points[ip].GetX(), AliTRDReconstructor::GetMaxStep())) return -1.;
     
     Double_t xyz[3]; // should also get the covariance
     track->GetXYZ(xyz); 
@@ -1771,7 +1771,7 @@ Double_t AliTRDtrackerV1::FitKalman(AliTRDtrackV1 *track, AliTRDseedV1 * const t
 }
 
 //_________________________________________________________________________
-Float_t AliTRDtrackerV1::CalculateChi2Z(AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
+Float_t AliTRDtrackerV1::CalculateChi2Z(const AliTRDseedV1 *tracklets, Double_t offset, Double_t slope, Double_t xref)
 {
   //
   // Calculates the chi2-value of the track in z-Direction including tilting pad correction.
@@ -1803,16 +1803,15 @@ Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t m
   // Returns 1 if track reaches the plane, and 0 otherwise 
   //
 
-  const Double_t kEpsilon = 0.00001;
-
   // Current track X-position
-  Double_t xpos = t.GetX();
+  Double_t xpos = t.GetX()/*,
+           mass = t.GetMass()*/;
 
   // Direction: inward or outward
   Double_t dir  = (xpos < xToGo) ? 1.0 : -1.0;
 
-  while (((xToGo - xpos) * dir) > kEpsilon) {
-
+  while (((xToGo - xpos) * dir) > AliTRDReconstructor::GetEpsilon()) {
+//    printf("to go %f\n", (xToGo - xpos) * dir);
     Double_t xyz0[3];
     Double_t xyz1[3];
     Double_t param[7];
@@ -1840,10 +1839,45 @@ Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t m
     // Calculate the mean material budget between start and
     // end point of this prolongation step
     if(AliTracker::MeanMaterialBudget(xyz0, xyz1, param)<=0.) return 0;
-
+    
     // Propagate the track to the X-position after the next step
     if (!t.PropagateTo(x, param[1], param[0]*param[4])) return 0;
 
+/*    // Correct for mean material budget
+    Double_t dEdx(0.),
+             bg(t.GetP()/mass);
+    if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3){
+      const char *pn[] = {"rho", "x/X0", "<A>", "<Z>", "L", "<Z/A>", "Nb"};
+      printf("D-AliTRDtrackerV1::PropagateTo(): x[%6.2f] bg[%6.2f]\n", xpos, bg);
+      printf("     param :: %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e] %s[%e]\n"
+          , pn[0], param[0]
+          , pn[1], param[1]
+          , pn[2], param[2]
+          , pn[3], param[3]
+          , pn[4], param[4]
+          , pn[5], param[5]
+          , pn[6], param[6]);
+    }  
+    switch(fgBB){
+    case kSolid:
+      dEdx = AliExternalTrackParam::BetheBlochSolid(bg);
+      break;
+    case kGas:
+      dEdx = AliExternalTrackParam::BetheBlochGas(bg);
+      break;
+    case kGeant:
+      { // mean exitation energy (GeV)
+        Double_t mee = ((param[3] < 13.) ? (12. * param[3] + 7.) : (9.76 * param[3] + 58.8 * TMath::Power(param[3],-0.19))) * 1.e-9;
+        Double_t mZA = param[5]>1.e-5?param[5]:(param[3]/param[2]);
+        if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=3) printf("D-AliTRDtrackerV1::PropagateTo(): Mee[%e] <Z/A>[%e]\n", mee, mZA);
+        // protect against failed calculation of rho in MeanMaterialBudget()
+        dEdx = AliExternalTrackParam::BetheBlochGeant(bg, param[0]>1.e-6?param[0]:2.33, 0.2, 3., mee, mZA);
+      }
+      break;
+    }
+    if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1")>=2) printf("D-AliTRDtrackerV1::PropagateTo(): dEdx(bg=%e, m=%e)= %e[GeV/cm]\n", bg, mass, dEdx);
+    if (!t.CorrectForMeanMaterialdEdx(param[1], dir*param[0]*param[4], mass, dEdx)) return 0;
+*/
     // Rotate the track if necessary
     if(!AdjustSector(&t)) return 0;
 
@@ -1856,7 +1890,6 @@ Int_t AliTRDtrackerV1::PropagateToX(AliTRDtrackV1 &t, Double_t xToGo, Double_t m
 
 }
 
-
 //_____________________________________________________________________________
 Bool_t AliTRDtrackerV1::ReadClusters(TTree *clusterTree)
 {
@@ -2282,7 +2315,7 @@ Int_t AliTRDtrackerV1::Clusters2TracksStack(AliTRDtrackingChamber **stack, TClon
     if(!ntracks) break;
     
     // Sort the seeds according to their quality
-    Int_t sort[kMaxTracksStack];
+    Int_t sort[kMaxTracksStack+1];
     TMath::Sort(ntracks, fTrackQuality, sort, kTRUE);
     if(AliLog::GetDebugLevel("TRD", "AliTRDtrackerV1") > 2){
       AliDebug(3, "Track candidates classification:");
@@ -3124,7 +3157,7 @@ Bool_t AliTRDtrackerV1::ImproveSeedQuality(AliTRDtrackingChamber **stack, AliTRD
   for (Int_t iter = 0; iter < 4; iter++) {
     // Try better cluster set
     Int_t nLayers(0); Float_t qualitynew(0.);
-    Int_t  indexes[AliTRDgeometry::kNlayer];
+    Int_t  indexes[4*AliTRDgeometry::kNlayer];
     TMath::Sort(Int_t(AliTRDgeometry::kNlayer), lQuality, indexes, kFALSE);
     for(Int_t jLayer=AliTRDgeometry::kNlayer; jLayer--;) {
       Int_t bLayer = indexes[jLayer];
@@ -3787,6 +3820,7 @@ Double_t AliTRDtrackerV1::FitTiltedRiemanV1(AliTRDseedV1 *const tracklets){
 //____________________________________________________________________
 void AliTRDtrackerV1::UnsetTrackletsTrack(const AliTRDtrackV1 * const track)
 {
+//  Remove tracklets from tracker list attached to "track"
   Int_t idx(-1);
   for(Int_t il(0); il<kNPlanes; il++){
     if((idx = track->GetTrackletIndex(il)) < 0) continue;
@@ -3873,7 +3907,7 @@ Bool_t AliTRDtrackerV1::AliTRDLeastSquare::Eval(){
   //
   
   Double_t det = fSums[0] * fSums[4] - fSums[1] *fSums[1];
-  if(det==0) return kFALSE;
+  if(TMath::Abs(det)<1.e-30) return kFALSE;
 
   //   for(Int_t isum = 0; isum < 5; isum++)
   //           printf("fSums[%d] = %f\n", isum, fSums[isum]);