]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Code cleanup and bug fix Fixed valgrind warning concerning conditional jump on undefi...
authormpuccio <maximiliano.puccio@cern.ch>
Wed, 28 Jan 2015 15:00:08 +0000 (16:00 +0100)
committermasera <massimo.masera@cern.ch>
Fri, 30 Jan 2015 16:48:21 +0000 (17:48 +0100)
ITS/UPGRADE/ITSUpgradeRec/AliITSUCATracker.cxx
ITS/UPGRADE/ITSUpgradeRec/AliITSUCATracker.h
ITS/UPGRADE/ITSUpgradeRec/AliITSUCATrackingStation.cxx

index 30280940a34ea605491836856eb977a3853ea9f4..ea32ea65543e559147d2091425afa5da761f9924 100644 (file)
@@ -90,31 +90,10 @@ static inline float Curvature(float x1, float y1, float x2, float y2, float x3,
   //
   // Initial approximation of the track curvature
   //
-//  return - 2.f * ((x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1))
-//               * invsqrt(((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) *
-//                         ((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)) *
-//                         ((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)));
-  
-  //calculates the curvature of track
-  float den = (x3 - x1) * (y2 - y1) - (x2 - x1) * (y3 - y1);
-  if(den * den < 1e-32) return 0.f;
-  float a = ((y3-y1)*(x2*x2+y2*y2-x1*x1-y1*y1)-(y2-y1)*(x3*x3+y3*y3-x1*x1-y1*y1))/den;
-  if((y2 - y1) * (y2 - y1) < 1e-32) return 0.f;
-  float b = -(x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1 + a * (x2 - x1)) / (y2 - y1);
-  float c = -x1 * x1 - y1 * y1 - a * x1 - b * y1;
-  float xc = -a / 2.f;
-  
-  if((a * a + b * b - 4 * c) < 0) return 0.f;
-  float rad = TMath::Sqrt(a * a + b * b - 4 * c) / 2.f;
-  if(rad * rad < 1e-32) return 1e16;
-  
-  if((x1 > 0.f && y1 > 0.f && x1 < xc)) rad *= -1.f;
-  if((x1 < 0.f && y1 > 0.f && x1 < xc)) rad *= -1.f;
-  //  if((x1<0 && y1<0 && x1<xc)) rad*=-1;
-  // if((x1>0 && y1<0 && x1<xc)) rad*=-1;
-  
-  return 1.f/rad;
-
+  return   2.f * ((x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1))
+               * invsqrt(((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) *
+                         ((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)) *
+                         ((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1)));
 }
 
 //__________________________________________________________________________________________________
@@ -126,18 +105,6 @@ static inline float TanLambda(float x1, float y1, float x2, float y2, float z1,
   return (z1 - z2) * invsqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
 }
 
-//__________________________________________________________________________________________________
-//static inline float XCenterOfCurvature(float x1, float y1, float x2, float y2, float x3, float y3)
-//{
-//    //
-//    // Initial approximation of the x-coordinate of the center of curvature
-//    //
-//
-//  const float k1 = (y2 - y1) / (x2 - x1), k2 = (y3 - y2) / (x3 - x2);
-//  return TMath::Abs(k2 - k1) > kAlmost0 ?
-//    0.5f * (k1 * k2 * (y1 - y3) + k2 * (x1 + x2) - k1 * (x2 + x3)) / (k2 - k1) : 1e12f;
-//}
-
 //__________________________________________________________________________________________________
 static inline bool CompareAngles(float alpha, float beta, float tolerance)
 {
@@ -273,12 +240,14 @@ bool AliITSUCATracker::CellParams(int l, ClsInfo_t* c1, ClsInfo_t* c2, ClsInfo_t
   n[1] = (mD10[2] * mD20[0]) - (mD10[0] * mD20[2]);
   n[2] = (mD10[0] * mD20[1]) - (mD10[1] * mD20[0]);
   // Normalisation
-  const float norm = TMath::Sqrt((n[0] * n[0]) + (n[1] * n[1]) + (n[2] * n[2]));
+  float norm = TMath::Sqrt((n[0] * n[0]) + (n[1] * n[1]) + (n[2] * n[2]));
   if (norm < 1e-20f || fabs(n[2]) < 1e-20f)
     return false;
-  n[0] /= norm;
-  n[1] /= norm;
-  n[2] /= norm;
+  else
+    norm = 1.f / norm;
+  n[0] *= norm;
+  n[1] *= norm;
+  n[2] *= norm;
   // Center of the circle
   const float c[2] = {-0.5f * n[0] / n[2], -0.5f * n[1] / n[2]};
   // Constant
@@ -597,9 +566,9 @@ void AliITSUCATracker::MakeCells(int iteration)
     ResetHistos();
 #endif
     for (int i = 0; i < 5; ++i)
-      fCells[i].clear();
+      vector<AliITSUCACell>().swap(fCells[i]);
     for (int i = 0; i < 6; ++i)
-      fDoublets[i].clear();
+      vector<Doublets>().swap(fDoublets[i]);
   }
   
   // Trick to speed up the navigation of the doublets array. The lookup table is build like:
@@ -608,9 +577,11 @@ void AliITSUCATracker::MakeCells(int iteration)
   // fLayer[l+1][i]
   vector<int> dLUT[5];
   for (int iL = 0; iL < 6; ++iL) {
-    if (iL < 5) {
+    if (fLayer[iL].GetNClusters() == 0) continue;
+    if (iL < 5)
       dLUT[iL].resize(fLayer[iL + 1].GetNClusters(),-1);
-    }
+    if (dLUT[iL - 1].size() == 0u)
+      continue;
     for (int iC = 0; iC < fLayer[iL].GetNClusters(); ++iC) {
       ClsInfo_t* cls = fLayer[iL].GetClusterInfo(iC);
       if (fUsedClusters[iL][cls->index]) {
@@ -661,18 +632,23 @@ void AliITSUCATracker::MakeCells(int iteration)
   // where n is the index inside fCells[l+1] of the first cells that uses the doublet
   // fDoublets[l+1][i]
   vector<int> tLUT[4];
+  tLUT[0].resize(fDoublets[1].size(),-1);
+  tLUT[1].resize(fDoublets[2].size(),-1);
+  tLUT[2].resize(fDoublets[3].size(),-1);
+  tLUT[3].resize(fDoublets[4].size(),-1);
+
   for (int iD = 0; iD < 5; ++iD)
   {
-    if (iD < 4) {
-      tLUT[iD].resize(fDoublets[iD + 1].size(),0);
-    }
+    if (fDoublets[iD + 1].size() == 0u || fDoublets[iD].size() == 0u) continue;
+
     for (size_t iD0 = 0; iD0 < fDoublets[iD].size(); ++iD0)
     {
       const int idx = fDoublets[iD][iD0].y;
       bool first = true;
       if (dLUT[iD][idx] == -1) continue;
-      for (size_t iD1 = dLUT[iD][idx]; idx == fDoublets[iD + 1][iD1].x;++iD1)
+      for (size_t iD1 = dLUT[iD][idx]; iD1 < fDoublets[iD + 1].size(); ++iD1)
       {
+        if (idx != fDoublets[iD + 1][iD1].x) break;
         if (TMath::Abs(fDoublets[iD][iD0].tanL - fDoublets[iD + 1][iD1].tanL) < fCDTanL &&
             TMath::Abs(fDoublets[iD][iD0].phi - fDoublets[iD + 1][iD1].phi) < fCDPhi) {
           const float tan = 0.5f * (fDoublets[iD][iD0].tanL + fDoublets[iD + 1][iD1].tanL);
@@ -714,16 +690,19 @@ void AliITSUCATracker::MakeCells(int iteration)
       }
     }
   }
-  
+
   // Adjacent cells: cells that share 2 points. In the following code adjacent cells are combined.
   // If they meet some requirements (~ same curvature, ~ same n) the innermost cell id is added
   // to the list of neighbours of the outermost cell. When the cell is added to the neighbours of
   // the outermost cell the "level" of the latter is set to the level of the innermost one + 1.
   // ( only if $(level of the innermost) + 1 > $(level of the outermost) )
   for (int iD = 0; iD < 4; ++iD) {
+    if (fCells[iD + 1].size() == 0u || tLUT[iD].size() == 0u) continue; // TODO: dealing with holes
     for (size_t c0 = 0; c0 < fCells[iD].size(); ++c0) {
       const int idx = fCells[iD][c0].d1();
-      for (size_t c1 = tLUT[iD][idx]; idx == fCells[iD + 1][c1].d0(); ++c1) {
+      if (tLUT[iD][idx] == -1) continue;
+      for (size_t c1 = tLUT[iD][idx]; c1 < fCells[iD + 1].size(); ++c1) {
+        if (idx != fCells[iD + 1][c1].d0()) break;
 #ifdef _TUNING_
         fGood = (fLayer[iD].GetClusterSorted(fCells[iD][c0].x())->GetLabel(0) ==
                  fLayer[iD + 1].GetClusterSorted(fCells[iD][c0].y())->GetLabel(0) &&
@@ -733,8 +712,8 @@ void AliITSUCATracker::MakeCells(int iteration)
                  fLayer[iD + 3].GetClusterSorted(fCells[iD + 1][c1].z())->GetLabel(0) &&
                  fLayer[iD].GetClusterSorted(fCells[iD][c0].x())->GetLabel(0) > 0);
 #endif
-        float *n0 = fCells[iD][c0].GetN();
-        float *n1 = fCells[iD + 1][c1].GetN();
+        floatn0 = fCells[iD][c0].GetN();
+        floatn1 = fCells[iD + 1][c1].GetN();
         const float dn2 = ((n0[0] - n1[0]) * (n0[0] - n1[0]) + (n0[1] - n1[1]) * (n0[1] - n1[1]) +
                            (n0[2] - n1[2]) * (n0[2] - n1[2]));
         const float dp = fabs(fCells[iD][c0].GetCurvature() - fCells[iD + 1][c1].GetCurvature());
index 142e68766993dc3f1fd11af40e73c4d2a19d0382..78f62e1876d12921428d8618002d43a3eda51474 100644 (file)
@@ -9,7 +9,7 @@
 #ifndef ALIITSUCATRACKER_H
 #define ALIITSUCATRACKER_H
 
-#define _TUNING_
+//#define _TUNING_
 
 #include <vector>
 
@@ -66,7 +66,7 @@ public:
   Bool_t   GetSAonly() const { return fSAonly; }
   void     SetChi2Cut(float cut) { fChi2Cut = cut; }
   void     SetPhiCut(float cut) { fPhiCut = cut; }
-  void     SetSAonly(Bool_t sa=kTRUE) { fSAonly=sa; }
+  void     SetSAonly(Bool_t sa = kTRUE) { fSAonly = sa; }
   void     SetZCut(float cut) { fZCut = cut; }
 
 #ifdef _TUNING_
@@ -92,11 +92,13 @@ public:
 #endif
   //
 protected:
-  bool   CellParams(int l, ClsInfo_t* c1, ClsInfo_t* c2, ClsInfo_t* c3, float &curv, float np[3]);
+  bool   CellParams(int l, ClsInfo_t*__restrict__ c1, ClsInfo_t*__restrict__ c2,
+                    ClsInfo_t*__restrict__ c3, float &curv, float np[3]);
   void   CellsTreeTraversal(vector<AliITSUCARoad> &roads, const int &iD, const int &doubl);
   void   FindTracksCA(int iteration);
   void   MakeCells(int iteration);
-  Bool_t RefitAt(Double_t xx, AliITSUTrackCooked *t, const AliITSUTrackCooked *c);
+  Bool_t RefitAt(Double_t xx, AliITSUTrackCooked*__restrict__ t,
+                 const AliITSUTrackCooked*__restrict__ c);
   void   SetCuts(int it);
   void   SetLabel(AliITSUTrackCooked &t, Float_t wrong);
   
index 743790e5e4d73e3ce76356b7a3e6cfa8073e9144..04eaf4cfbb9458ef373fa4ed15327bc4fae20cf8 100644 (file)
@@ -119,6 +119,7 @@ void AliITSUCATrackingStation::Init(AliITSURecoLayer *lr, AliITSUGeomTGeo *geo)
   fBins = new ClBinInfo_t[fNZBins * fNPhiBins];
   fOccBins = new int[fNZBins * fNPhiBins];
   fNClusters = fClusters->GetEntriesFast();
+  if(fNClusters == 0) return;
   fSortedClInfo.reserve(fClusters->GetEntriesFast());
   fVIDOffset = ((AliITSUClusterPix*)fClusters->UncheckedAt(0))->GetVolumeId();
   //