Rewriting and cleaning up
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Hough.cxx
index c4e2dda9eb771286e542a92055d009c74cd51479..f3c37e706520a48817f345e2c36b4c5fd3ad1458 100644 (file)
@@ -22,132 +22,118 @@ ClassImp(AliL3Hough)
 AliL3Hough::AliL3Hough()
 {
 
-
-
+  
 }
 
 
-AliL3Hough::AliL3Hough(Int_t n_eta_segments,Int_t xbin,Double_t *xrange,Int_t ybin,Double_t *yrange)
+AliL3Hough::AliL3Hough(Char_t *path,Bool_t binary,Int_t n_eta_segments)
 {
-  
+  fBinary = binary;
+  strcpy(fPath,path);
   fNEtaSegments = n_eta_segments;
-  fNxbin = xbin;
-  fNybin = ybin;
-  fXmin = xrange[0];
-  fXmax = xrange[1];
-  fYmin = yrange[0];
-  fYmax = yrange[1];
-
-  fMemHandler = new AliL3FileHandler();
-  fMaxFinder = new AliL3HoughMaxFinder("KappaPhi");
-  fEval = new AliL3HoughEval();
-  fTransform = new AliL3Transform();
-  fDeleteTrack = kTRUE;
-  fTracks = new AliL3TrackArray("AliL3HoughTrack");
+  Init();
 }
 
 
 AliL3Hough::~AliL3Hough()
 {
-  
-  if(fHoughTransformer)
-    delete fHoughTransformer;
   if(fMemHandler)
-    delete fMemHandler;
-  if(fMaxFinder)
-    delete fMaxFinder;
-  if(fEval)
-    delete fEval;
-  if(fTransform)
-    delete fTransform;
+    DeleteMemory();
+  if(fHoughTransformer)
+    DeleteTransformers();
+  if(fRootFile)
+    {
+      fRootFile->Close();
+      delete fRootFile;
+    }
 }
 
-void AliL3Hough::SetInput(Char_t *input,Bool_t binary)
+void AliL3Hough::DeleteTransformers()
 {
-  if(binary)
+  for(Int_t i=0; i<NPatches; i++)
     {
-      strcpy(fPath,input);
-      fUseBinary = kTRUE;
+      if(!fHoughTransformer[i]) continue;
+      delete fHoughTransformer;
     }
-  else
-    {
-      TFile *file = new TFile(input);
-      fMemHandler->SetAliInput(file);
-      fUseBinary = kFALSE;
-    }
-  
+  delete [] fHoughTransformer;
 }
 
-void AliL3Hough::ProcessSlice(Int_t slice)
+void AliL3Hough::DeleteMemory()
 {
-  
+  for(Int_t i=0; i<NPatches; i++)
+    {
+      if(!fMemHandler[i]) continue;
+      delete fMemHandler[i];
+    }
+  delete [] fMemHandler;
 }
 
-void AliL3Hough::ProcessPatch(Int_t slice,Int_t patch)
+void AliL3Hough::Init()
 {
-  
-  Char_t histname[50];
-  Int_t i;
-  
-  if(fHoughTransformer)
-    delete fHoughTransformer;
-  fHoughTransformer = new AliL3HoughTransformer(slice,patch);//,0,fNEtaSegments);
-  
-  fHistos = new AliL3Histogram*[fNEtaSegments];
-  printf("Allocating %d bytes to histograms\n",fNEtaSegments*sizeof(AliL3Histogram));
-  for(i=0; i<fNEtaSegments; i++)
+  fHoughTransformer = new AliL3HoughTransformer*[NPatches];
+  fMemHandler = new AliL3FileHandler*[NPatches];
+  for(Int_t i=0; i<NPatches; i++)
     {
-      sprintf(histname,"hist%d",i);
-      fHistos[i] = new AliL3Histogram(histname,"",fNxbin,fXmin,fXmax,fNybin,fYmin,fYmax);
+      fHoughTransformer[i] = new AliL3HoughTransformer(1,i,fNEtaSegments);
+      fMemHandler[i] = new AliL3FileHandler();
     }
+  if(!fBinary)
+    fRootFile = new TFile(fPath);
+}
 
-  Char_t name[256];
+void AliL3Hough::TransformSlice(Int_t slice)
+{
   
-  UInt_t ndigits=0;
-  AliL3DigitRowData *digits =0;
-  // fMemHandler->Init(slice,patch,NRows[patch]);
-  //fMemHandler->Init(fTransform);
-  if(fUseBinary)
+  for(Int_t i=0; i<NPatches; i++)
     {
-      fMemHandler->Free();
-      sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,patch);
-      fMemHandler->SetBinaryInput(name);
-      digits = (AliL3DigitRowData *)fMemHandler->CompBinary2Memory(ndigits);
-      fMemHandler->CloseBinaryInput();
+      fHoughTransformer[i]->CreateHistograms(64,-0.006,0.006,64,-0.26,0.26);
+      fHoughTransformer[i]->SetThreshold(3);
+      fMemHandler[i]->Free();
+      UInt_t ndigits=0;
+      AliL3DigitRowData *digits =0;
+      Char_t name[256];
+      if(fBinary)
+       {
+         sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,i);
+         fMemHandler[i]->SetBinaryInput(name);
+         digits = (AliL3DigitRowData *)fMemHandler[i]->CompBinary2Memory(ndigits);
+         fMemHandler[i]->CloseBinaryInput();
+       }
+      else //read data from root file
+       {
+         fMemHandler[i]->SetAliInput(fRootFile);
+         fMemHandler[i]->Init(slice,i,NRows[i]);
+         digits=(AliL3DigitRowData *)fMemHandler[i]->AliDigits2Memory(ndigits); 
+       }
+      fHoughTransformer[i]->SetInputData(ndigits,digits);
+      fHoughTransformer[i]->TransformCircle();
     }
-  else
+  
+}
+
+AliL3Histogram *AliL3Hough::AddHistograms()
+{
+  AliL3Histogram *hist0 = fHoughTransformer[0]->GetHistogram(0);
+  for(Int_t i=1; i<NPatches; i++)
     {
-      digits=(AliL3DigitRowData *)fMemHandler->AliDigits2Memory(ndigits); 
+      AliL3Histogram *hist = fHoughTransformer[i]->GetHistogram(0);
+      hist0->Add(hist);
     }
-  printf("Setting up tables\n");
-  fHoughTransformer->SetHistogram(fHistos[0]);
-  fHoughTransformer->InitTables();
-  fHoughTransformer->SetInputData(ndigits,digits);
-  fEval->SetTransformer(fHoughTransformer);
   
-  AliL3HoughTrack *track;
-  Int_t good_count;
-  while(1)
+  return hist0;
+}
+
+void AliL3Hough::Evaluate(AliL3Histogram *hist)
+{
+  
+  AliL3HoughEval **eval = new AliL3HoughEval*[NPatches];
+  for(Int_t i=0; i<NPatches; i++)
     {
-      fHoughTransformer->TransformTables(fHistos);
-      
-      good_count=0;
-      for(Int_t e=0; e<fNEtaSegments; e++)
-       {
-         fMaxFinder->SetHistogram(fHistos[e]);
-         track = (AliL3HoughTrack*)fMaxFinder->FindPeak(3,0.95,5);
-         if(fEval->LookInsideRoad(track,e,fDeleteTrack))
-           {
-             //Found a good track here
-             fTracks->AddLast(track);
-             good_count++;
-           }
-       }
-      break;
-      if(good_count==0)
-       break;
+      eval[i] = new AliL3HoughEval(fHoughTransformer[i]);
+      eval[i]->DisplayEtaSlice(0,hist);
+      delete eval[i];
     }
-  printf("good_count %d\n",good_count);
   
-}
+  delete [] eval;
 
+}