Cleaning up. Made some changes in AliL3HoughMaxFinder. Peaks are now
authorvestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 23 May 2002 11:59:19 +0000 (11:59 +0000)
committervestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 23 May 2002 11:59:19 +0000 (11:59 +0000)
stored in private arrays, and does not have to be passed as arguments
for every function. Instead, they should be reached with getters.
Some minor cleaning was also done in AliL3Hough and AliL3HoughEval.

HLT/hough/AliL3Hough.cxx
HLT/hough/AliL3Hough.h
HLT/hough/AliL3HoughEval.cxx
HLT/hough/AliL3HoughMaxFinder.cxx
HLT/hough/AliL3HoughMaxFinder.h
HLT/hough/AliL3HoughTransformer.cxx

index 70385e3..9ffd6a6 100644 (file)
@@ -104,11 +104,11 @@ void AliL3Hough::CleanUp()
       if(fMemHandler[i]) delete fMemHandler[i];
     }
   
-  /*    
-       if(fTracks) delete [] fTracks;
-       if(fEval) delete [] fEval;
-       if(fHoughTransformer) delete [] fHoughTransformer;
-       if(fMemHandler) delete [] fMemHandler;
+  /*
+  if(fTracks) delete [] fTracks;
+  if(fEval) delete [] fEval;
+  if(fHoughTransformer) delete [] fHoughTransformer;
+  if(fMemHandler) delete [] fMemHandler;
   */
 }
 
@@ -127,7 +127,7 @@ void AliL3Hough::Init()
   fEval = new AliL3HoughEval*[fNPatches];
   for(Int_t i=0; i<fNPatches; i++)
     {
-      fHoughTransformer[i] = new AliL3HoughTransformer(1,i,fNEtaSegments);
+      fHoughTransformer[i] = new AliL3HoughTransformer(0,i,fNEtaSegments);
       //fHoughTransformer[i]->CreateHistograms(64,-0.003,0.003,64,-0.26,0.26);
       fHoughTransformer[i]->CreateHistograms(64,0.1,64,-30,30);
       fHoughTransformer[i]->SetThreshold(3);
@@ -142,7 +142,7 @@ void AliL3Hough::Init()
 #endif
       
     }
-  fPeakFinder = new AliL3HoughMaxFinder("KappaPhi");
+  fPeakFinder = new AliL3HoughMaxFinder("KappaPhi",100);
   fMerger = new AliL3HoughMerger(fNPatches);
   fInterMerger = new AliL3HoughIntMerger();
   fGlobalMerger = 0;
@@ -177,6 +177,7 @@ void AliL3Hough::ReadData(Int_t slice)
       UInt_t ndigits=0;
       AliL3DigitRowData *digits =0;
       Char_t name[256];
+      fMemHandler[i]->Init(slice,i);
       if(fBinary)//take input data from binary files
        {
          sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,i);
@@ -187,8 +188,7 @@ void AliL3Hough::ReadData(Int_t slice)
       else //read data from root file
        {
 #ifdef use_aliroot
-         const Int_t rows[2] = {AliL3Transform::GetFirstRow(i),AliL3Transform::GetLastRow(i)};
-         fMemHandler[i]->Init(slice,i,rows);
+         fMemHandler[i]->Init(slice,i);
          digits=(AliL3DigitRowData *)fMemHandler[i]->AliDigits2Memory(ndigits); 
 #else
          cerr<<"You cannot read from rootfile now"<<endl;
@@ -321,20 +321,15 @@ void AliL3Hough::FindTrackCandidates()
        {
          AliL3Histogram *hist = tr->GetHistogram(j);
          if(hist->GetNEntries()==0) continue;
+         fPeakFinder->Reset();
          fPeakFinder->SetHistogram(hist);
          fPeakFinder->SetThreshold(fPeakThreshold);
-         Int_t n=20;
-         Float_t x[n];
-         Float_t y[n];
-         Int_t weight[n];
-         //fPeakFinder->FindPeak1(x,y,weight,n,2,1);
-         fPeakFinder->FindMaxima(x,y,weight,n);
-         for(Int_t k=0; k<n; k++)
+         fPeakFinder->FindMaxima(); //Simple maxima finder
+         for(Int_t k=0; k<fPeakFinder->GetEntries(); k++)
            {
-             if(weight[k] == 0) continue;
-             
+             if(fPeakFinder->GetWeight(k) == 0) continue;
              AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[i]->NextTrack();
-             track->SetTrackParameters(x[k],y[k],weight[k]);
+             track->SetTrackParameters(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetWeight(k));
              track->SetEtaIndex(j);
              track->SetEta((Double_t)(j*eta_slice));
              track->SetRowRange(AliL3Transform::GetFirstRow(0),AliL3Transform::GetLastRow(5));
@@ -344,11 +339,21 @@ void AliL3Hough::FindTrackCandidates()
     }
 }
 
+void AliL3Hough::InitEvaluate()
+{
+  //Pass the transformer objects to the AliL3HoughEval objects:
+  //This will provide the evaluation objects with all the necessary
+  //data it needs.
+  
+  for(Int_t i=0; i<fNPatches; i++) 
+    fEval[i]->InitTransformer(fHoughTransformer[i]);
+}
+
 void AliL3Hough::Evaluate(Int_t road_width)
 {
   //Evaluate the tracks, by looking along the road in the raw data.
+  //If track does not cross all padrows - rows2miss, it is removed from the arrray.
   
-
   if(!fTracks[0])
     {
       LOG(AliL3Log::kError,"AliL3Hough::Evaluate","Track Array")
@@ -356,12 +361,11 @@ void AliL3Hough::Evaluate(Int_t road_width)
       return;
     }
   
-  printf("Number of tracks before evaluation %d\n",fTracks[0]->GetNTracks());
+  InitEvaluate();
+  
   AliL3TrackArray *tracks;
   for(Int_t i=0; i<fNPatches; i++)
     {
-      fEval[i]->InitTransformer(fHoughTransformer[i]);
-      continue;
       fEval[i]->SetNumOfRowsToMiss(2);
       fEval[i]->SetNumOfPadsToLook(road_width);
       if(fAddHistograms)
@@ -394,6 +398,8 @@ void AliL3Hough::Evaluate(Int_t road_width)
 
 void AliL3Hough::EvaluateWithEta()
 {
+
+  
   if(!fTracks[0])
     {
       printf("AliL3Hough::EvaluateWithEta: NO TRACKS\n");
@@ -409,13 +415,13 @@ void AliL3Hough::EvaluateWithEta()
   fMerger->FillTracks(fTracks[0],0);
 }
 
-void AliL3Hough::WriteTracks(Char_t *path)
+void AliL3Hough::WriteTracks(Int_t slice,Char_t *path)
 {
   AliL3MemHandler *mem = new AliL3MemHandler();
   Char_t fname[100];
   if(fAddHistograms)
     {
-      sprintf(fname,"%s/tracks.raw",path);
+      sprintf(fname,"%s/tracks_ho_%d.raw",path,slice);
       mem->SetBinaryOutput(fname);
       mem->TrackArray2Binary(fTracks[0]);
       mem->CloseBinaryOutput();
@@ -424,7 +430,7 @@ void AliL3Hough::WriteTracks(Char_t *path)
     {
       for(Int_t i=0; i<fNPatches; i++)
        {
-         sprintf(fname,"%s/tracks_%d.raw",path,i);
+         sprintf(fname,"%s/tracks_ho_%d_%d.raw",path,slice,i);
          mem->SetBinaryOutput(fname);
          mem->TrackArray2Binary(fTracks[i]);
          mem->CloseBinaryOutput();
index 16d7616..9351625 100644 (file)
@@ -54,16 +54,17 @@ class AliL3Hough {
   void ProcessPatchIter(Int_t patch);
   void MergePatches();
   void MergeInternally();
-
+  
   void FindTrackCandidates();
   void AddAllHistograms();
   void Evaluate(Int_t road_width=1);
   void EvaluateWithEta();
-  void WriteTracks(Char_t *path="./");
+  void WriteTracks(Int_t slice,Char_t *path="./");
 #ifdef use_aliroot
   void WriteDigits(Char_t *outfile="output_digits.root");
 #endif
-
+  void InitEvaluate();
+  
   //Setters
   void SetNEtaSegments(Int_t i) {fNEtaSegments = i;}
   void SetAddHistograms() {fAddHistograms = kTRUE;}
index cacef4d..e205d65 100644 (file)
@@ -116,7 +116,6 @@ Bool_t AliL3HoughEval::LookInsideRoad(AliL3HoughTrack *track,Int_t eta_index,Boo
       Int_t prow = padrow - AliL3Transform::GetFirstRow(fPatch);
       if(!track->GetCrossingPoint(padrow,xyz))  
        {
-         //printf("AliL3HoughEval::LookInsideRoad : Track does not cross line!!; pt %f phi0 %f\n",track->GetPt(),track->GetPhi0());
          continue;
        }
       
@@ -139,13 +138,12 @@ Bool_t AliL3HoughEval::LookInsideRoad(AliL3HoughTrack *track,Int_t eta_index,Boo
          AliL3DigitData *digPt = tempPt->fDigitData;
          for(UInt_t j=0; j<tempPt->fNDigit; j++)
            {
-             //if(digPt->fCharge <= fHoughTransformer->GetThreshold()) continue;
              UChar_t pad = digPt[j].fPad;
              if(pad < p) continue;
              if(pad > p) break;
              UShort_t time = digPt[j].fTime;
              Double_t eta = AliL3Transform::GetEta(padrow,pad,time);
-             Int_t pixel_index = (Int_t)(eta/etaslice);
+             Int_t pixel_index = fHoughTransformer->GetEtaIndex(eta);
              if(pixel_index > eta_index) continue;
              if(pixel_index != eta_index) break;
              total_charge += digPt[j].fCharge;
@@ -165,12 +163,6 @@ Bool_t AliL3HoughEval::LookInsideRoad(AliL3HoughTrack *track,Int_t eta_index,Boo
   
   if(nrow >= rows_crossed - fNumOfRowsToMiss)//this was a good track
     {
-      Double_t eta_track = (Double_t)eta_index*etaslice;
-      track->SetEtaIndex(eta_index);
-      track->SetWeight(total_charge,kTRUE);
-      track->SetEta(eta_track);
-      track->SetRowRange(AliL3Transform::GetFirstRow(fPatch),AliL3Transform::GetLastRow(fPatch));
-      track->SetSlice(fSlice);
       if(fRemoveFoundTracks)
        LookInsideRoad(track,eta_index,kTRUE);
       return kTRUE;
index 3b36ab7..2bf9a71 100644 (file)
@@ -3,10 +3,9 @@
 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
 //*-- Copyright &copy ASV 
 
-#include <string.h>
 #include <math.h>
 #include <stdlib.h>
-#include <stream.h>
+#include <string.h>
 
 #include "AliL3Histogram.h"
 #include "AliL3TrackArray.h"
@@ -25,12 +24,15 @@ AliL3HoughMaxFinder::AliL3HoughMaxFinder()
 {
   //Default constructor
   fThreshold = 0;
-  //fTracks = 0;
   fHistoType=0;
+  fXPeaks=0;
+  fYPeaks=0;
+  fNPeaks=0;
+  fNMax=0;
 }
 
 
-AliL3HoughMaxFinder::AliL3HoughMaxFinder(Char_t *histotype,AliL3Histogram *hist)
+AliL3HoughMaxFinder::AliL3HoughMaxFinder(Char_t *histotype,Int_t nmax,AliL3Histogram *hist)
 {
   //Constructor
 
@@ -40,16 +42,37 @@ AliL3HoughMaxFinder::AliL3HoughMaxFinder(Char_t *histotype,AliL3Histogram *hist)
   
   if(hist)
     fCurrentHisto = hist;
+  
+  fNMax=nmax;
+  fXPeaks = new Float_t[fNMax];
+  fYPeaks = new Float_t[fNMax];
+  fWeight = new Int_t[fNMax];
 }
 
 
 AliL3HoughMaxFinder::~AliL3HoughMaxFinder()
 {
   //Destructor
+  if(fXPeaks)
+    delete [] fXPeaks;
+  if(fYPeaks)
+    delete [] fYPeaks;
+  if(fWeight)
+    delete [] fWeight;
+}
 
+void AliL3HoughMaxFinder::Reset()
+{
+  for(Int_t i=0; i<fNMax; i++)
+    {
+      fXPeaks[i]=0;
+      fYPeaks[i]=0;
+      fWeight[i]=0;
+    }
+  fNPeaks=0;
 }
 
-void AliL3HoughMaxFinder::FindAbsMaxima(Int_t &max_xbin,Int_t &max_ybin)
+void AliL3HoughMaxFinder::FindAbsMaxima()
 {
   if(!fCurrentHisto)
     {
@@ -64,7 +87,8 @@ void AliL3HoughMaxFinder::FindAbsMaxima(Int_t &max_xbin,Int_t &max_ybin)
   Int_t ymax = hist->GetLastYbin();  
   Int_t bin;
   Double_t value,max_value=0;
-
+  
+  Int_t max_xbin=0,max_ybin=0;
   for(Int_t xbin=xmin; xbin<=xmax; xbin++)
     {
       for(Int_t ybin=ymin; ybin<=ymax; ybin++)
@@ -80,11 +104,25 @@ void AliL3HoughMaxFinder::FindAbsMaxima(Int_t &max_xbin,Int_t &max_ybin)
        }
     }
   
+  if(fNPeaks > fNMax)
+    {
+      cerr<<"AliL3HoughMaxFinder::FindAbsMaxima : Array out of range : "<<fNPeaks<<endl;
+      return;
+    }
+  
+  Double_t max_x = hist->GetBinCenterX(max_xbin);
+  Double_t max_y = hist->GetBinCenterY(max_ybin);
+  fXPeaks[fNPeaks] = max_x;
+  fYPeaks[fNPeaks] = max_y;
+  fWeight[fNPeaks] = (Int_t)max_value;
+  fNPeaks++;
+
 }
 
-AliL3TrackArray *AliL3HoughMaxFinder::FindBigMaxima(AliL3Histogram *hist)
+void AliL3HoughMaxFinder::FindBigMaxima()
 {
   
+  AliL3Histogram *hist = fCurrentHisto;
   Int_t xmin = hist->GetFirstXbin();
   Int_t xmax = hist->GetLastXbin();
   Int_t ymin = hist->GetFirstYbin();
@@ -92,9 +130,6 @@ AliL3TrackArray *AliL3HoughMaxFinder::FindBigMaxima(AliL3Histogram *hist)
   Int_t bin[25],bin_index;
   Double_t value[25];
   
-  AliL3TrackArray *tracks = new AliL3TrackArray("AliL3HoughTrack");
-  AliL3HoughTrack *track;
-  
   for(Int_t xbin=xmin+2; xbin<xmax-3; xbin++)
     {
       for(Int_t ybin=ymin+2; ybin<ymax-3; ybin++)
@@ -116,32 +151,34 @@ AliL3TrackArray *AliL3HoughMaxFinder::FindBigMaxima(AliL3Histogram *hist)
            {
              if(value[b] > value[12] || b==bin_index) break;
              b++;
-             printf("b %d\n",b);
+             //printf("b %d\n",b);
            }
          if(b == bin_index)
            {
              //Found maxima
+             if(fNPeaks > fNMax)
+               {
+                 cerr<<"AliL3HoughMaxFinder::FindBigMaxima : Array out of range "<<fNPeaks<<endl;
+                 return;
+               }
+             
              Double_t max_x = hist->GetBinCenterX(xbin);
              Double_t max_y = hist->GetBinCenterY(ybin);
-             track = (AliL3HoughTrack*)tracks->NextTrack();
-             track->SetTrackParameters(max_x,max_y,(Int_t)value[12]);
+             fXPeaks[fNPeaks] = max_x;
+             fYPeaks[fNPeaks] = max_y;
+             fNPeaks++;
            }
        }
     }
-  
-  tracks->QSort();
-  return tracks;
 }
 
 
-void AliL3HoughMaxFinder::FindMaxima(Float_t *xpeaks,Float_t *ypeaks,Int_t *weight,Int_t &entries)
+void AliL3HoughMaxFinder::FindMaxima()
 {
   //Locate all the maxima in input histogram.
   //Maxima is defined as bins with more entries than the
   //immediately neighbouring bins. 
   
-  Int_t max_entries = entries;
-  entries = 0;
   Int_t xmin = fCurrentHisto->GetFirstXbin();
   Int_t xmax = fCurrentHisto->GetLastXbin();
   Int_t ymin = fCurrentHisto->GetFirstYbin();
@@ -149,9 +186,9 @@ void AliL3HoughMaxFinder::FindMaxima(Float_t *xpeaks,Float_t *ypeaks,Int_t *weig
   Int_t bin[9];
   Double_t value[9];
   
-  Double_t kappa_overlap = 0.001;
-  Double_t phi_overlap = 0.05;
-  
+  Double_t grad_x = 3;
+  Double_t grad_y = 3;
+
   for(Int_t xbin=xmin+1; xbin<xmax-1; xbin++)
     {
       for(Int_t ybin=ymin+1; ybin<ymax-1; ybin++)
@@ -188,19 +225,31 @@ void AliL3HoughMaxFinder::FindMaxima(Float_t *xpeaks,Float_t *ypeaks,Int_t *weig
              
              if((Int_t)value[4] <= fThreshold) continue;//central bin below threshold
              
-             if(entries >= max_entries)
+             if(fNPeaks > fNMax)
                {
-                 cerr<<"AliL3HoughMaxFinder::FindMaxima : Array out of range : "<<entries<<" "<<max_entries<<endl;
+                 cerr<<"AliL3HoughMaxFinder::FindMaxima : Array out of range "<<fNPeaks<<endl;
                  return;
                }
              
+             //Check the gradient:
+             if(value[4]/value[3] < grad_x || value[4]/value[5] < grad_x ||
+                value[4]/value[1] < grad_y || value[4]/value[7] < grad_y)
+               continue;
+             
+             
+             fXPeaks[fNPeaks] = max_x;
+             fYPeaks[fNPeaks] = max_y;
+             fWeight[fNPeaks] = (Int_t)value[4];
+             fNPeaks++;
+             
+             /*
              //Check if the peak is overlapping with a previous:
              Bool_t bigger = kFALSE;
              for(Int_t p=0; p<entries; p++)
-               {
-                 if(fabs(max_x - xpeaks[p]) < kappa_overlap && fabs(max_y - ypeaks[p]) < phi_overlap)
-                   {
-                     bigger = kTRUE;
+             {
+               if(fabs(max_x - xpeaks[p]) < kappa_overlap && fabs(max_y - ypeaks[p]) < phi_overlap)
+             {
+             bigger = kTRUE;
                      if(value[4] > weight[p]) //this peak is bigger.
                        {
                          xpeaks[p] = max_x;
@@ -213,11 +262,12 @@ void AliL3HoughMaxFinder::FindMaxima(Float_t *xpeaks,Float_t *ypeaks,Int_t *weig
                }
              if(!bigger) //there were no overlapping peaks.
                {
-                 xpeaks[entries] = max_x;
+               xpeaks[entries] = max_x;
                  ypeaks[entries] = max_y;
                  weight[entries] = (Int_t)value[4];
                  entries++;
                }
+             */
            }
          else
            continue; //not a maxima
index 0d5b241..6484062 100644 (file)
@@ -2,6 +2,7 @@
 #define ALIL3_HOUGH_MaxFinder
 
 #include "AliL3RootTypes.h"
+#include <stream.h>
 
 class AliL3Histogram;
 class AliL3TrackArray;
@@ -21,19 +22,28 @@ class AliL3HoughMaxFinder {
 
   Int_t fThreshold;
   AliL3Histogram *fCurrentHisto;  //!
-
+  
+  Float_t *fXPeaks; //!
+  Float_t *fYPeaks; //!
+  Int_t *fWeight;   //!
+  Int_t fNPeaks;
+  Int_t fNMax;
+  
   Char_t fHistoType;
 
  public:
   AliL3HoughMaxFinder(); 
-  AliL3HoughMaxFinder(Char_t *histotype,AliL3Histogram *hist=0);
+  AliL3HoughMaxFinder(Char_t *histotype,Int_t nmax,AliL3Histogram *hist=0);
   virtual ~AliL3HoughMaxFinder();
-
-  void FindAbsMaxima(Int_t &max_xbin,Int_t &max_ybin);
-  AliL3TrackArray *FindBigMaxima(AliL3Histogram *hist);
-  void FindMaxima(Float_t *xpeaks,Float_t *ypeaks,Int_t *weight,Int_t &entries);
-  AliL3TrackArray *LookForPeaks(AliL3Histogram *hist,Int_t nbins);
+  void Reset();
+  
+  //Simple maxima finders:
+  void FindAbsMaxima();
+  void FindBigMaxima();
+  void FindMaxima();
   
+  //More sophisticated peak finders:
+  AliL3TrackArray *LookForPeaks(AliL3Histogram *hist,Int_t nbins);
   void FindPeak(Int_t t1,Double_t t2,Int_t t3,Float_t &kappa,Float_t &phi0);
   AliL3HoughTrack *FindPeakLine(Double_t rho,Double_t theta);
   AliL3HoughTrack *CalculatePeakInWindow(Int_t *maxbin,Int_t t0,Int_t t1,Double_t t2,Int_t t3);
@@ -41,12 +51,49 @@ class AliL3HoughMaxFinder {
   void SortPeaks(struct AxisWindow **a,Int_t first,Int_t last);
   Int_t PeakCompare(struct AxisWindow *a,struct AxisWindow *b);
   
+  //Setters:
   void SetThreshold(Int_t f) {fThreshold = f;}
-  
   void SetHistogram(AliL3Histogram *hist) {fCurrentHisto = hist;}
   
+  //Getters:
+  Float_t GetXPeak(Int_t i);
+  Float_t GetYPeak(Int_t i);
+  Int_t GetWeight(Int_t i);
+  Int_t GetEntries() {return fNPeaks;}
+
   ClassDef(AliL3HoughMaxFinder,1) //Maximum finder class
 
 };
 
+inline Float_t AliL3HoughMaxFinder::GetXPeak(Int_t i)
+{
+  if(i<0 || i>fNMax)
+    {
+      cerr<<"AliL3HoughMaxFinder::GetXPeak : Invalid index "<<i<<endl;
+      return 0;
+    }
+  return fXPeaks[i];
+}
+
+inline Float_t AliL3HoughMaxFinder::GetYPeak(Int_t i)
+{
+  if(i<0 || i>fNMax)
+    {
+      cerr<<"AliL3HoughMaxFinder::GetYPeak : Invalid index "<<i<<endl;
+      return 0;
+    }
+  return fYPeaks[i];
+
+}
+
+inline Int_t AliL3HoughMaxFinder::GetWeight(Int_t i)
+{
+  if(i<0 || i>fNMax)
+    {
+      cerr<<"AliL3HoughMaxFinder::GetWeight : Invalid index "<<i<<endl;
+      return 0;
+    }
+  return fWeight[i];
+}
+
 #endif
index b9830bc..951b124 100644 (file)
@@ -137,7 +137,7 @@ void AliL3HoughTransformer::TransformCircle()
          printf("AliL3HoughTransform::TransformCircle : Mismatching padrow numbering\n");
          continue;
        }
-      
+
       //Loop over the data on this padrow:
       for(UInt_t j=0; j<tempPt->fNDigit; j++)
        {