Bugfix in destructor etc.
authorvestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 25 Oct 2001 16:42:58 +0000 (16:42 +0000)
committervestbo <vestbo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 25 Oct 2001 16:42:58 +0000 (16:42 +0000)
HLT/hough/AliL3Hough.cxx
HLT/hough/AliL3Hough.h

index f3c37e7..a4d2298 100644 (file)
@@ -5,6 +5,7 @@
 #include <TCanvas.h>
 #include <TFile.h>
 
+#include "AliL3Logging.h"
 #include "AliL3Histogram.h"
 #include "AliL3Hough.h"
 #include "AliL3HoughTransformer.h"
@@ -21,8 +22,11 @@ ClassImp(AliL3Hough)
 
 AliL3Hough::AliL3Hough()
 {
-
-  
+  fBinary = kFALSE;
+  fNEtaSegments = 0;
+  fAddHistograms = kFALSE;
+  fRemoveFoundTracks = kFALSE; 
+  fWriteDigits=kFALSE;
 }
 
 
@@ -31,6 +35,9 @@ AliL3Hough::AliL3Hough(Char_t *path,Bool_t binary,Int_t n_eta_segments)
   fBinary = binary;
   strcpy(fPath,path);
   fNEtaSegments = n_eta_segments;
+  fAddHistograms = kFALSE;
+  fRemoveFoundTracks = kFALSE; 
+  fWriteDigits = kFALSE;
   Init();
 }
 
@@ -41,6 +48,12 @@ AliL3Hough::~AliL3Hough()
     DeleteMemory();
   if(fHoughTransformer)
     DeleteTransformers();
+  if(fEval)
+    DeleteEval();
+  if(fPeakFinder)
+    delete fPeakFinder;
+  if(fTracks)
+    delete fTracks;
   if(fRootFile)
     {
       fRootFile->Close();
@@ -48,12 +61,22 @@ AliL3Hough::~AliL3Hough()
     }
 }
 
+void AliL3Hough::DeleteEval()
+{
+  for(Int_t i=0; i<NPatches; i++)
+    {
+      if(!fEval[i]) continue;
+      delete fEval[i];
+    }
+  delete [] fEval;
+}
+
 void AliL3Hough::DeleteTransformers()
 {
   for(Int_t i=0; i<NPatches; i++)
     {
       if(!fHoughTransformer[i]) continue;
-      delete fHoughTransformer;
+      delete fHoughTransformer[i];
     }
   delete [] fHoughTransformer;
 }
@@ -75,10 +98,29 @@ void AliL3Hough::Init()
   for(Int_t i=0; i<NPatches; i++)
     {
       fHoughTransformer[i] = new AliL3HoughTransformer(1,i,fNEtaSegments);
+      fHoughTransformer[i]->CreateHistograms(64,-0.003,0.003,64,-0.26,0.26);
+      fHoughTransformer[i]->SetThreshold(3);
       fMemHandler[i] = new AliL3FileHandler();
+      if(!fBinary)
+       fMemHandler[i]->SetAliInput(fPath);
+    }
+  fPeakFinder = new AliL3HoughMaxFinder("KappaPhi");
+}
+
+void AliL3Hough::Process(Int_t minslice,Int_t maxslice)
+{
+  //Process all slices [minslice,maxslice].
+
+  for(Int_t i=minslice; i<=maxslice; i++)
+    {
+      TransformSlice(i);
+      if(fAddHistograms)
+       AddAllHistograms();
+      FindTrackCandidates();
+      Evaluate(fRemoveFoundTracks);
+      if(fWriteDigits)
+       WriteDigits();
     }
-  if(!fBinary)
-    fRootFile = new TFile(fPath);
 }
 
 void AliL3Hough::TransformSlice(Int_t slice)
@@ -86,13 +128,13 @@ void AliL3Hough::TransformSlice(Int_t slice)
   
   for(Int_t i=0; i<NPatches; i++)
     {
-      fHoughTransformer[i]->CreateHistograms(64,-0.006,0.006,64,-0.26,0.26);
-      fHoughTransformer[i]->SetThreshold(3);
+      //Reset memories
+      fHoughTransformer[i]->Reset();      
       fMemHandler[i]->Free();
       UInt_t ndigits=0;
       AliL3DigitRowData *digits =0;
       Char_t name[256];
-      if(fBinary)
+      if(fBinary)//take input data from binary files
        {
          sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,i);
          fMemHandler[i]->SetBinaryInput(name);
@@ -101,7 +143,6 @@ void AliL3Hough::TransformSlice(Int_t slice)
        }
       else //read data from root file
        {
-         fMemHandler[i]->SetAliInput(fRootFile);
          fMemHandler[i]->Init(slice,i,NRows[i]);
          digits=(AliL3DigitRowData *)fMemHandler[i]->AliDigits2Memory(ndigits); 
        }
@@ -111,29 +152,127 @@ void AliL3Hough::TransformSlice(Int_t slice)
   
 }
 
-AliL3Histogram *AliL3Hough::AddHistograms()
+AliL3Histogram *AliL3Hough::AddHistograms(Int_t eta_index)
 {
-  AliL3Histogram *hist0 = fHoughTransformer[0]->GetHistogram(0);
+
+  AliL3Histogram *hist0 = fHoughTransformer[0]->GetHistogram(eta_index);
   for(Int_t i=1; i<NPatches; i++)
     {
-      AliL3Histogram *hist = fHoughTransformer[i]->GetHistogram(0);
+      AliL3Histogram *hist = fHoughTransformer[i]->GetHistogram(eta_index);
       hist0->Add(hist);
     }
   
   return hist0;
 }
 
-void AliL3Hough::Evaluate(AliL3Histogram *hist)
+void AliL3Hough::AddAllHistograms()
 {
+  //Add the histograms within one etaslice.
+  //Resulting histogram are in patch=0.
+  
+  LOG(AliL3Log::kDebug,"AliL3Hough::AddAllHistograms","Progress")
+    <<"Adding all histograms"<<ENDLOG;
+  for(Int_t i=0; i<fNEtaSegments; i++)
+    {
+      AliL3Histogram *hist0 = fHoughTransformer[0]->GetHistogram(i);
+      for(Int_t j=1; j<NPatches; j++)
+       {
+         AliL3Histogram *hist = fHoughTransformer[j]->GetHistogram(i);
+         hist0->Add(hist);
+       }
+    }
+}
+
+void AliL3Hough::FindTrackCandidates()
+{
+  //Look for peaks in histograms, and find the track candidates
+  
+  if(fTracks)
+  {
+    LOG(AliL3Log::kDebug,"AliL3Hough::FindTrackCandidates","Track array")
+      <<"Deleting old track array"<<ENDLOG;
+    delete fTracks;
+  }
+  fTracks = new AliL3TrackArray("AliL3HoughTrack");
   
-  AliL3HoughEval **eval = new AliL3HoughEval*[NPatches];
+  Int_t n_patches;
+  if(fAddHistograms)
+    n_patches = 1; //Histograms has been added.
+  else
+    n_patches = NPatches;
+
+  for(Int_t i=0; i<n_patches; i++)
+    {
+      AliL3HoughTransformer *tr = fHoughTransformer[i];
+      for(Int_t j=0; j<fNEtaSegments; j++)
+       {
+         AliL3Histogram *hist = tr->GetHistogram(j);
+         fPeakFinder->SetHistogram(hist);
+         Int_t n=10;
+         Float_t x[10];
+         Float_t y[10];
+         fPeakFinder->FindPeak1(x,y,n);
+         for(Int_t k=0; k<n; k++)
+           {
+             AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks->NextTrack();
+             track->SetTrackParameters(x[k],y[k],1);
+             track->SetEtaIndex(j);
+           }
+       }
+    }
+  
+}
+
+void AliL3Hough::Evaluate(Bool_t remove)
+{
+  //Evaluate the tracks, by looking along the road in the raw data.
+  //You may choose to remove the found tracks from the image.
+  
+  if(!fTracks)
+    {
+      LOG(AliL3Log::kError,"AliL3Hough::Evaluate","Track array")
+       <<AliL3Log::kHex<<"No tracks to work on "<<(Int_t)fTracks<<ENDLOG;
+      return;
+    }
+  
+  if(fEval)
+    {
+      LOG(AliL3Log::kDebug,"AliL3Hough::Evaluate","Evaluate object")
+       <<"Deleting old AliL3HoughEval objects"<<ENDLOG;
+      DeleteEval();
+    }
+  
+  fEval = new AliL3HoughEval*[NPatches];
   for(Int_t i=0; i<NPatches; i++)
     {
-      eval[i] = new AliL3HoughEval(fHoughTransformer[i]);
-      eval[i]->DisplayEtaSlice(0,hist);
-      delete eval[i];
+      fEval[i] = new AliL3HoughEval(fHoughTransformer[i]);
+      if(remove)
+       fEval[i]->RemoveFoundTracks();
+      for(Int_t j=0; j<fTracks->GetNTracks(); j++)
+       {
+         AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks->GetCheckedTrack(j);
+         if(!track)
+           {
+             printf("AliL3Hough::Evaluate : Missing track object...\n");
+             continue;
+           }
+         //fEval[i]->LookInsideRoad(track,track->GetEtaIndex());
+         if(!fEval[i]->LookInsideRoad(track,track->GetEtaIndex()))
+           fTracks->Remove(j);
+       }
+      fTracks->Compress();
     }
   
-  delete [] eval;
+}
 
+void AliL3Hough::WriteDigits(Char_t *outfile)
+{
+  //Write the current data to a new rootfile.
+
+  for(Int_t i=0; i<NPatches; i++)
+    {
+      AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fHoughTransformer[i]->GetDataPointer();
+      fMemHandler[i]->AliDigits2RootFile(tempPt,outfile);
+    }
+  
 }
index 86d7982..3f0208d 100644 (file)
@@ -17,11 +17,18 @@ class AliL3Hough : public TObject {
  private:
   Char_t fPath[256];
   Bool_t fBinary;
+  Bool_t fAddHistograms;
+  Bool_t fRemoveFoundTracks;
+  Bool_t fWriteDigits;
   Int_t fNEtaSegments;
   AliL3FileHandler **fMemHandler; //!
   AliL3HoughTransformer **fHoughTransformer; //!
+  AliL3HoughEval **fEval; //!
+  AliL3HoughMaxFinder *fPeakFinder; //!
+  AliL3TrackArray *fTracks; //!
   TFile *fRootFile; //!
-
+  
+  void DeleteEval();
   void DeleteTransformers();
   void DeleteMemory();
   void Init();
@@ -32,15 +39,23 @@ class AliL3Hough : public TObject {
   AliL3Hough(Char_t *path,Bool_t binary,Int_t n_eta_segments=100);
   virtual ~AliL3Hough();
   
+  void Process(Int_t minslice,Int_t maxslice);
   void TransformSlice(Int_t slice);
-  AliL3Histogram *AddHistograms();
-  void Evaluate(AliL3Histogram *hist);
-
+  void FindTrackCandidates();
+  AliL3Histogram *AddHistograms(Int_t eta_index);
+  void AddAllHistograms();
+  void Evaluate(Bool_t remove=kFALSE);
+  void WriteDigits(Char_t *outfile="output_digits.root");
+  
   //Setters
   void SetNEtaSegments(Int_t i) {fNEtaSegments = i;}
+  void SetAddHistograms() {fAddHistograms = kTRUE;}
+  void SetRemoveFoundTracks() {fRemoveFoundTracks = kTRUE;}
+  void SetWriteDigits() {fWriteDigits = kTRUE;}
   
   //Getters
   AliL3HoughTransformer *GetTransformer(Int_t i) {if(!fHoughTransformer[i]) return 0; return fHoughTransformer[i];}
+  AliL3TrackArray *GetTracks() {if(!fTracks) return 0; return fTracks;}
 
   ClassDef(AliL3Hough,1)