]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HLT/hough/AliL3HoughTransformer.cxx
Some additional changes related to the previous changes. AliL3Transform
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughTransformer.cxx
index 10eebbc1754a94963885433a09d01bcf18cb2e38..753f6e122bfa2f49cca416c49fab75346817c11d 100644 (file)
-//Author:        Anders Strand Vestbo
-//Last Modified: 28.6.01
+//$Id$
 
-#include <math.h>
-#include <TH2.h>
-#include <time.h>
+// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
+//*-- Copyright &copy ASV 
 
-#include <TFile.h>
-#include <TTree.h>
-
-#include "AliTPCParam.h"
-#include "AliSimDigits.h"
-
-#include "AliL3Histogram.h"
+#include "AliL3MemHandler.h"
 #include "AliL3Logging.h"
+#include "AliL3HoughTransformer.h"
 #include "AliL3Defs.h"
 #include "AliL3Transform.h"
-#include "AliL3HoughTransformer.h"
-#include "AliL3HoughTrack.h"
-#include "AliL3TrackArray.h"
 #include "AliL3DigitData.h"
+#include "AliL3Histogram.h"
+
+//_____________________________________________________________
+// AliL3HoughTransformer
+//
+// Hough transformation class
+//
 
 ClassImp(AliL3HoughTransformer)
 
 AliL3HoughTransformer::AliL3HoughTransformer()
 {
   //Default constructor
-  
+  fParamSpace = 0;
 }
 
-
-AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Float_t *etarange)
+AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Int_t n_eta_segments) : AliL3HoughBaseTransformer(slice,patch,n_eta_segments)
 {
-  //Constructor
-  
-  fTransform = new AliL3Transform();
-
-  fEtaMin = etarange[0];
-  fEtaMax = etarange[1];
-  fSlice = slice; 
-  fPatch = patch;
-  fNumOfPadRows=NRowsSlice;
+  //Normal constructor
+  fParamSpace = 0;
 }
 
-AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Double_t *etarange,Int_t n_eta_segments)
+AliL3HoughTransformer::~AliL3HoughTransformer()
 {
-  
-  fTransform = new AliL3Transform();
-  if(etarange)
-    {
-      //assumes you want to look at a given etaslice only
-      fEtaMin = etarange[0];
-      fEtaMax = etarange[1];
-    }
-  else
-    {
-      //transform in all etaslices
-      fEtaMin = 0;
-      fEtaMax = slice < 18 ? 0.9 : -0.9;
-    }
-  fNumEtaSegments = n_eta_segments;
-  fSlice = slice;
-  fPatch = patch;
-  fNumOfPadRows = NRowsSlice;
-  
-  fNRowsInPatch = NRows[fPatch][1]-NRows[fPatch][0] + 1;
-  fBinTableBounds = (fNRowsInPatch+1)*(MaxNPads+1);
-  fNDigitRowData = 0;
-  fDigitRowData = 0;
-  fHistoPt = 0;
+  DeleteHistograms();
 }
 
-
-AliL3HoughTransformer::~AliL3HoughTransformer()
+void AliL3HoughTransformer::DeleteHistograms()
 {
-  //Destructor
-  if(fBinTable)
+  if(!fParamSpace)
+    return;
+  for(Int_t i=0; i<GetNEtaSegments(); i++)
     {
-      for(Int_t i=0; i<fBinTableBounds; i++)
-       delete [] fBinTable[i];
-      delete [] fBinTable;
+      if(!fParamSpace[i]) continue;
+      delete fParamSpace[i];
     }
-  if(fEtaIndex)
-    delete [] fEtaIndex;
-  if(fTrackTable)
-    {
-      for(Int_t i=0; i<fNumEtaSegments; i++)
-       delete [] fTrackTable[i];
-      delete [] fTrackTable;
-    }
-  if(fTransform)
-    delete fTransform;
-  
-  
+  delete [] fParamSpace;
 }
 
-void AliL3HoughTransformer::SetInputData(UInt_t ndigits,AliL3DigitRowData *ptr)
+void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t pt_min,
+                                            Int_t nybin,Double_t phimin,Double_t phimax)
 {
-  fNDigitRowData = ndigits;
-  fDigitRowData = ptr;
+  //Create the histograms (parameter space).
+  //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis).
+  //The arguments give the range and binning; 
+  //nxbin = #bins in kappa
+  //nybin = #bins in phi0
+  //pt_min = mimium Pt of track (corresponding to maximum kappa)
+  //phi_min = mimimum phi0 (degrees)
+  //phi_max = maximum phi0 (degrees)
+    
+  Double_t bfact = 0.0029980;
+  Double_t bfield = 0.2;
+  Double_t x = bfact*bfield/pt_min;
+  CreateHistograms(nxbin,-1.*x,x,nybin,phimin*ToRad,phimax*ToRad);
 }
 
-void AliL3HoughTransformer::InitTables()
+void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
+                                            Int_t nybin,Double_t ymin,Double_t ymax)
 {
-  //Create LUT for the circle transform.
-  //the actual transformation is done in TransformTables.
-
-  AliL3Histogram *hist = fHistoPt;
   
-  Int_t nbinsy = hist->GetNbinsY();
+  fParamSpace = new AliL3Histogram*[GetNEtaSegments()];
   
-  fBinTable = new Int_t*[fBinTableBounds];
-  Int_t index;
+  Char_t histname[256];
+  for(Int_t i=0; i<GetNEtaSegments(); i++)
+    {
+      sprintf(histname,"paramspace_%d",i);
+      fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
+    }
+}
 
-  Double_t etaslice = fEtaMax/fNumEtaSegments;
-  
-  Int_t etabounds = (MaxNPads+1)*(fNRowsInPatch+1)*(MaxNTimeBins+1);
+void AliL3HoughTransformer::Reset()
+{
+  //Reset all the histograms
 
-  fEtaIndex = new Int_t[etabounds];
-  for(Int_t i=0; i<etabounds; i++)
-    fEtaIndex[i] = -1;
-  
-  fTrackTable = new Char_t*[fNumEtaSegments];
-  for(Int_t i=0; i<fNumEtaSegments; i++)
+  if(!fParamSpace)
     {
-      fTrackTable[i] = new Char_t[fBinTableBounds];
-      for(Int_t j=0; j<fBinTableBounds; j++)
-       fTrackTable[i][j] = 0;
+      LOG(AliL3Log::kWarning,"AliL3HoughTransformer::Reset","Histograms")
+       <<"No histograms to reset"<<ENDLOG;
+      return;
     }
   
-  for(Int_t r=NRows[fPatch][0]; r<=NRows[fPatch][1]; r++)
-    {
-      Int_t prow = r - NRows[fPatch][0];
-      
-      for(Int_t p=0; p<fTransform->GetNPads(r); p++)
-       {
-         Float_t xyz[3];
-         Int_t sector,row;
-         for(Int_t t=0; t<fTransform->GetNTimeBins(); t++)
-           {
-             fTransform->Slice2Sector(fSlice,r,sector,row);
-             fTransform->Raw2Local(xyz,sector,row,p,t);
-             Double_t eta = fTransform->GetEta(xyz);
-             if(eta < fEtaMin || eta > fEtaMax) continue;
-             Int_t ind = (prow<<17) + (p<<9) + t;
-             if(fEtaIndex[ind]>=0)
-               printf("AliL3HoughTransformer::InitTables : Overlapping indexes in eta!!\n");
-             Int_t eta_index = (Int_t)(eta/etaslice);        
-             if(eta_index < 0 || eta_index > fNumEtaSegments)
-               continue;
-             fEtaIndex[ind] = eta_index;
-             
-           }
-         
-         Double_t r_pix = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
-         Double_t phi_pix = fTransform->GetPhi(xyz);
-         index = (prow<<8) + p;
-         fBinTable[index] = new Int_t[nbinsy+1];
-         
-         for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
-           {
-             Double_t phi0 = hist->GetBinCenterY(b);
-             Double_t kappa = 2*sin(phi_pix-phi0)/r_pix;
-             Int_t bin = hist->FindBin(kappa,phi0);
-             if(fBinTable[index][b]!=0)
-               printf("AliL3HoughTransformer::InitTables : Overlapping indexes %d %d b %d\n",fBinTable[index][b],index,b);
-             fBinTable[index][b] = bin;
-           }
-       }
+  for(Int_t i=0; i<GetNEtaSegments(); i++)
+    fParamSpace[i]->Reset();
+}
 
-    }
 
+Int_t AliL3HoughTransformer::GetEtaIndex(Double_t eta)
+{
+  //Return the histogram index of the corresponding eta. 
+
+  Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
+  Double_t index = (eta-GetEtaMin())/etaslice;
+  return (Int_t)index;
 }
 
-void AliL3HoughTransformer::TransformTables(AliL3Histogram **histos,AliL3Histogram **images)
+void AliL3HoughTransformer::TransformCircle()
 {
-  //Transform all the pixels while reading, and fill the corresponding histograms.
-  //Transform is done using LUT created in InitTables.
-  //fTrackTable : table telling whether a specific pixel is active (nonzero):
-  //fTrackTable = 0  ->  no track
-  //fTrackindex > 0  ->  track present
-  //fTrackindex = -1  ->  track has been removed (already found)
-  //fEtaIndex : table storing the etaindex -> used to find correct histogram to fill
-  //fBinTable : table storing all the bins to fill for each nonzero pixel
-    
-  Int_t eta_index;
-  AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
-  AliL3Histogram *hist;
-  
+  //Transform the input data with a circle HT.
+  //The function loops over all the data, and transforms each pixel with the equations:
+  // 
+  //kappa = 2/R*sin(phi - phi0)
+  //
+  //where R = sqrt(x*x +y*y), and phi = arctan(y/x)
+  //
+  //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find
+  //which histogram in which the pixel should be transformed, the eta-value is calcluated
+  //and the proper histogram index is found by GetEtaIndex(eta).
+
+
+  AliL3DigitRowData *tempPt = GetDataPointer();
   if(!tempPt)
     {
-      LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformTables","data")<<
-       "Zero datapointer"<<ENDLOG;
+      LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircle","Data")
+       <<"No input data "<<ENDLOG;
       return;
     }
-
-  Int_t out_count=0,tot_count=0;
-  Int_t index,ind;
-
-  for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
+  if(!fTransform)
+    {
+      LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircle","Transformer")
+       <<"No AliL3Transform object"<<ENDLOG;
+      return;
+    }
+  
+  //Loop over the padrows:
+  for(Int_t i=NRows[GetPatch()][0]; i<=NRows[GetPatch()][1]; i++)
     {
-      Int_t prow = i - NRows[fPatch][0];
-      AliL3DigitData *bins = tempPt->fDigitData;
-      for(UInt_t dig=0; dig<tempPt->fNDigit; dig++)
+      //Get the data on this padrow:
+      AliL3DigitData *digPt = tempPt->fDigitData;
+      if(i != (Int_t)tempPt->fRow)
        {
-         index = (prow<<8) + bins[dig].fPad;
-         ind = (prow<<17) + (bins[dig].fPad<<9) + bins[dig].fTime;
-         eta_index = fEtaIndex[ind];
-         if(eta_index < 0) continue;  //pixel out of etarange
+         printf("AliL3HoughTransform::TransformCircle : Mismatching padrow numbering\n");
+         continue;
+       }
+      
+      //Loop over the data on this padrow:
+      for(UInt_t j=0; j<tempPt->fNDigit; j++)
+       {
+         UShort_t charge = digPt[j].fCharge;
+         UChar_t pad = digPt[j].fPad;
+         UShort_t time = digPt[j].fTime;
+         if(charge <= GetThreshold())
+           continue;
+         Int_t sector,row;
+         Float_t xyz[3];
          
-         if(fTrackTable[eta_index][index]<0) continue; //this pixel has already been removed. 
-         fTrackTable[eta_index][index]++; //this pixel is now marked as active (it is nonzero)
+         //Transform data to local cartesian coordinates:
+         fTransform->Slice2Sector(GetSlice(),i,sector,row);
+         fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
          
-         tot_count++;
-         hist = histos[eta_index];
+         //Calculate the eta:
+         Double_t eta = fTransform->GetEta(xyz);
          
-         if(images)
-           {
-             //Display the transformed images.
-             AliL3Histogram *image = images[eta_index];
-             Float_t xyz_local[3];
-             Int_t sector,row;
-             fTransform->Slice2Sector(fSlice,i,sector,row);
-             fTransform->Raw2Local(xyz_local,sector,row,bins[dig].fPad,bins[dig].fTime);
-             image->Fill(xyz_local[0],xyz_local[1],bins[dig].fCharge);
-           }
+         //Get the corresponding index, which determines which histogram to fill:
+         Int_t eta_index = GetEtaIndex(eta);
+         if(eta_index < 0 || eta_index >= GetNEtaSegments())
+           continue;
          
+         //Get the correct histogrampointer:
+         AliL3Histogram *hist = fParamSpace[eta_index];
          if(!hist)
            {
-             printf("Error getting histogram!\n");
+             printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
              continue;
            }
-         for(Int_t p=hist->GetFirstYbin(); p<=hist->GetLastYbin(); p++)
-           hist->AddBinContent(fBinTable[index][p],bins[dig].fCharge);
+
+         //Do the transformation:
+         Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]); 
+         Float_t phi = fTransform->GetPhi(xyz);
          
+         //Fill the histogram along the phirange
+         for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
+           {
+             Float_t phi0 = hist->GetBinCenterY(b);
+             Float_t kappa = 2*sin(phi - phi0)/R;
+             hist->Fill(kappa,phi0,charge);
+           }
        }
       
-      Byte_t *tmp = (Byte_t*)tempPt;
-      Int_t size = sizeof(AliL3DigitRowData) + tempPt->fNDigit*sizeof(AliL3DigitData);
-      tmp += size;
-      tempPt = (AliL3DigitRowData*)tmp;
-    }  
-  
+      //Move the data pointer to the next padrow:
+      AliL3MemHandler::UpdateRowPointer(tempPt);
+    }
 }
 
-void AliL3HoughTransformer::WriteTables()
+void AliL3HoughTransformer::TransformCircleC(Int_t row_range)
 {
-  //Write the tables to asci files.
-  
-  AliL3Histogram *hist = fHistoPt;
-  Char_t name[100];
-  sprintf(name,"histogram_table_%d.txt",fPatch);
-  FILE *file = fopen(name,"w");
+  //Circle transform, using combinations of every 2 points lying
+  //on different padrows and within the same etaslice.
   
-  Int_t etabounds = (MaxNPads+1)*(fNRowsInPatch+1)*(MaxNTimeBins+1);
-  for(Int_t i=0; i<etabounds; i++)
+  AliL3DigitRowData *tempPt = GetDataPointer();
+  if(!tempPt)
+    LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircleC","Data")
+      <<"No input data "<<ENDLOG;
+  if(!fTransform)
     {
-      if(fEtaIndex[i]<0) continue;
-      fprintf(file,"%d %d\n",i,fEtaIndex[i]);
+      LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircleC","Transformer")
+       <<"No AliL3Transform object"<<ENDLOG;
+      return;
     }
-  fclose(file);
   
-  sprintf(name,"bin_table_%d.txt",fPatch);
-  FILE *file2 = fopen(name,"w");
-  for(Int_t i=0; i<fBinTableBounds; i++)
+  Int_t counter=0;
+  for(Int_t i=NRows[GetPatch()][0]; i<=NRows[GetPatch()][1]; i++)
     {
-      if(!fBinTable[i]) continue;
-      fprintf(file2,"%d ",i);
-      for(Int_t j=hist->GetFirstYbin(); j<=hist->GetLastYbin(); j++)
-       {
-         fprintf(file2,"%d ",fBinTable[i][j]);
-       }
-      fprintf(file2,"\n");
+      counter += tempPt->fNDigit;
+      AliL3MemHandler::UpdateRowPointer(tempPt);
     }
-  fclose(file2);
-}
-
-Double_t AliL3HoughTransformer::CpuTime()
-{
-  return (Double_t)(clock()) / CLOCKS_PER_SEC;
-}
-
-/*
-void AliL3HoughTransformer::InitTemplates(TH2F *hist)
-{
-
-  AliL3Digits *pixel;
-
-  Int_t ymin = hist->GetYaxis()->GetFirst();
-  Int_t ymax = hist->GetYaxis()->GetLast();
-  Int_t nbinsy = hist->GetNbinsY();
-
-  fIndex = new Int_t*[fNDigits];
-  for(Int_t i=0; i<fNDigits; i++)
-    fIndex[i] = new Int_t[nbinsy+1];
-    
-  Int_t sector,row;
   
-  for(Int_t padrow = NRows[fPatch][0]; padrow <= NRows[fPatch][1]; padrow++)
-    {        
-      
-      for(pixel=(AliL3Digits*)fRowContainer[padrow].first; pixel!=0; pixel=(AliL3Digits*)pixel->nextRowPixel)
-       {
-         Float_t xyz[3];
-         fTransform->Slice2Sector(fSlice,padrow,sector,row);
-         fTransform->Raw2Local(xyz,sector,row,pixel->fPad,pixel->fTime);
-         
-         Double_t r_pix = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
-         
-         Double_t phi_pix = fTransform->GetPhi(xyz);
-         Int_t index = pixel->fIndex;
-         if(index >= fNDigits)
-           printf("AliL3HoughTransformer::InitTemplates : Index error! %d\n",index);
-         for(Int_t p=ymin; p<=ymax; p++)
-           {
-             
-             Double_t phi0 = hist->GetYaxis()->GetBinCenter(p);
-             Double_t kappa = 2*sin(phi_pix-phi0)/r_pix;
-             //printf("kappa %f phi0 %f\n",kappa,phi0);
-             Int_t bin = hist->FindBin(kappa,phi0);
-             if(fIndex[index][p]!=0)
-               printf("AliL3HoughTransformer::InitTemplates : Overlapping indexes\n");
-             fIndex[index][p] = bin;
-           }
-       }
-    }
+  struct Digit {
+    Int_t row;
+    Double_t r;
+    Double_t phi;
+    Int_t eta_index;
+    Int_t charge;
+  };
   
-}
-
-
-void AliL3HoughTransformer::Transform2Circle(TH2F *hist,Int_t eta_index)
-{
-  //Transformation is done with respect to local coordinates in slice.
-  //Transform every pixel into whole phirange, using parametrisation:
-  //kappa = 2*sin(phi-phi0)/R
-  //Assumes you run InitTemplates first!!!!
-
-  AliL3Digits *pix1;
-    
-  Int_t nbinsy = hist->GetNbinsY();
-
-  Int_t totsignal=0,vol_index;
-  if(fNumEtaSegments==1)
-    eta_index=0; //only looking in one etaslice.
-
-  for(Int_t padrow = NRows[fPatch][0]; padrow <= NRows[fPatch][1]; padrow++)
+  Digit *digits = new Digit[counter];
+  cout<<"Allocating "<<counter*sizeof(Digit)<<" bytes to digitsarray"<<endl;
+  
+  Int_t total_digits=counter;
+  Int_t sector,row,tot_charge,pad,time,charge;
+  Double_t r1,r2,phi1,phi2,eta,kappa,phi_0;
+  Float_t xyz[3];
+  
+  counter=0;
+  tempPt = GetDataPointer();
+  
+  for(Int_t i=NRows[GetPatch()][0]; i<=NRows[GetPatch()][1]; i++)
     {
-      vol_index = eta_index*fNumOfPadRows + padrow;
-      //for(pix1=(AliL3Digits*)fRowContainer[padrow].first; pix1!=0; pix1=(AliL3Digits*)pix1->nextRowPixel)
-      for(pix1=(AliL3Digits*)fVolume[vol_index].first; pix1!=0; pix1=(AliL3Digits*)pix1->fNextVolumePixel)
+      AliL3DigitData *digPt = tempPt->fDigitData;
+      for(UInt_t di=0; di<tempPt->fNDigit; di++)
        {
-         Float_t xyz[3];
-         fTransform->Raw2Global(xyz,2,padrow,pix1->fPad,pix1->fTime);
-         Double_t eta = fTransform->GetEta(xyz);
-         if(eta < fEtaMin || eta > fEtaMax)
-           printf("\n Eta OUT OF RANGE\n");
-
-         Short_t signal = pix1->fCharge;
-         Int_t index = pix1->fIndex;
-         if(index < 0) continue; //This pixel has been removed.
-         totsignal += signal;
-         for(Int_t p=0; p <= nbinsy; p++)
-           hist->AddBinContent(fIndex[index][p],signal);
-                         
+         charge = digPt[di].fCharge;
+         pad = digPt[di].fPad;
+         time = digPt[di].fTime;
+         fTransform->Slice2Sector(GetSlice(),i,sector,row);
+         fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
+         eta = fTransform->GetEta(xyz);
+         digits[counter].row = i;
+         digits[counter].r = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
+         digits[counter].phi = atan2(xyz[1],xyz[0]);
+         digits[counter].eta_index = GetEtaIndex(eta);
+         digits[counter].charge = charge;
+         counter++;
        }
-      
+      AliL3MemHandler::UpdateRowPointer(tempPt);
     }
-    
-  printf("Total signal %d\n",totsignal);
-}
-
-void AliL3HoughTransformer::Transform2Circle(TH2F **histos,Int_t n_eta_segments,UInt_t ndigits,AliL3DigitRowData *ptr)
-{
-  //Transform all the pixels while reading them, and fill the corresponding histograms.
-  //Everything is done in one go here. 
-
-  Double_t etaslice = 0.9/n_eta_segments;
-  Int_t eta_index;
-  AliL3DigitRowData *tempPt = (AliL3DigitRowData*)ptr;
-  TH2F *hist;
-
-  Int_t out_count=0,tot_count=0;
-  for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
+  
+  for(Int_t i=0; i<total_digits; i++)
     {
-      printf("doing row %d\n",i);
-      for(UInt_t dig=0; dig<tempPt->fNDigit; dig++)
+      if(digits[i].eta_index < 0 || digits[i].eta_index >= GetNEtaSegments()) continue;
+      Int_t ind = digits[i].eta_index;
+      
+      for(Int_t j=i+1; j<total_digits; j++)
        {
+         if(digits[i].row == digits[j].row) continue;
+         if(digits[i].eta_index != digits[j].eta_index) continue;
+         if(digits[i].row + row_range < digits[j].row) break;
          
-         AliL3DigitData *bins = tempPt->fDigitData;
-         Float_t xyz[3];
-         Int_t sector,row;
-         fTransform->Slice2Sector(fSlice,i,sector,row);
-         fTransform->Raw2Local(xyz,sector,row,bins[dig].fPad,bins[dig].fTime);
-         Double_t eta = fTransform->GetEta(xyz);
-         eta_index = (Int_t)(eta/etaslice);
-         if(eta_index < 0 || eta_index >= n_eta_segments)
-           {
-             //printf("Eta index out of range %d\n",eta_index);
-             out_count++;
-             continue;
-           }
-         tot_count++;
-         hist = histos[eta_index];
+         //Get the correct histogrampointer:
+         AliL3Histogram *hist = fParamSpace[ind];
          if(!hist)
            {
-             printf("Error getting histogramm!\n");
-             return;
+             printf("AliL3HoughTransformer::TransformCircleC() : No histogram at index %d\n",ind);
+             continue;
            }
          
-         Int_t ymin = hist->GetYaxis()->GetFirst();
-         Int_t ymax = hist->GetYaxis()->GetLast();
-         
-         Double_t r_pix = sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
-         Double_t phi_pix = fTransform->GetPhi(xyz);
-         for(Int_t p=ymin; p<=ymax; p++)
-           {
-             Double_t phi0 = hist->GetYaxis()->GetBinCenter(p);
-             Double_t kappa = 2*sin(phi_pix-phi0)/r_pix;
-             //printf("kappa %f phi0 %f\n",kappa,phi0);
-             hist->Fill(kappa,phi0,bins[dig].fCharge);
-           }
+         r1 = digits[i].r;
+         phi1 = digits[i].phi;
+         r2 = digits[j].r;
+         phi2 = digits[j].phi;
+         phi_0 = atan( (r2*sin(phi1)-r1*sin(phi2))/(r2*cos(phi1)-r1*cos(phi2)) );
+         kappa = 2*sin(phi2-phi_0)/r2;
+         tot_charge = digits[i].charge + digits[j].charge;
+         hist->Fill(kappa,phi_0,tot_charge);
        }
-      
-      
-      Byte_t *tmp = (Byte_t*)tempPt;
-      Int_t size = sizeof(AliL3DigitRowData) + tempPt->fNDigit*sizeof(AliL3DigitData);
-      tmp += size;
-      tempPt = (AliL3DigitRowData*)tmp;
-      
     }
-  
-  printf("There were %d pixels out of range and %d inside\n", out_count,tot_count);
-
+  delete [] digits;
 }
 
-
-void AliL3HoughTransformer::TransformLines2Circle(TH2F *hist,AliL3TrackArray *tracks)
+void AliL3HoughTransformer::TransformLine()
 {
+  //Do a line transform on the data.
 
-  for(Int_t i=0; i<tracks->GetNTracks(); i++)
+  
+  AliL3DigitRowData *tempPt = GetDataPointer();
+  if(!tempPt)
     {
-      AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(i);
-      if(!track) {printf("AliL3HoughTransformer::TransformLines2Circle : NO TRACK IN ARRAY\n"); continue;}
-     
-      Double_t xmin = fTransform->Row2X(track->GetFirstRow());
-      Double_t xmax = fTransform->Row2X(track->GetLastRow());
-      
-      Double_t a = -1./tan(track->GetPsiLine());
-      Double_t b = track->GetDLine()/sin(track->GetPsiLine());
-      
-      Double_t ymin = a*xmin + b;
-      Double_t ymax = a*xmax + b;
-      
-      Double_t middle_x = xmin + (xmax-xmin)/2;
-      Double_t middle_y = ymin + (ymax-ymin)/2;
-      
-      Double_t r_middle = sqrt(middle_x*middle_x + middle_y*middle_y);
-      Double_t phi = atan2(middle_y,middle_x);
-      Double_t phi0 = 2*phi - track->GetPsiLine();
-      Double_t kappa = 2*sin(phi-phi0)/r_middle;
-      hist->Fill(kappa,phi0,track->GetWeight());
-     
+      LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformLine","Data")
+       <<"No input data "<<ENDLOG;
+      return;
+    }
+  if(!fTransform)
+    {
+      LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformLine","Transformer")
+       <<"No AliL3Transform object"<<ENDLOG;
+      return;
     }
-
-  
-}
-
-void AliL3HoughTransformer::Transform2Line(TH2F *hist,Int_t ref_row,Int_t *rowrange,Double_t *phirange,TH2F *raw)
-{
-  //Transform every pixel into histogram, using parametrisation:
-  //D = x*cos(psi) + y*sin(psi)
-
-  //  printf("In Transform; rowrange %d %d ref_row %d phirange %f %f\n",rowrange[0],rowrange[1],ref_row,phirange[0],phirange[1]);
-
-  AliL3Digits *pix1;
-  
-  Int_t xmin = hist->GetXaxis()->GetFirst();
-  Int_t xmax = hist->GetXaxis()->GetLast();
-  
-  Double_t x0 = fTransform->Row2X(ref_row);
-  Double_t y0 = 0;
-
-  Int_t sector,row;
-  //for(Int_t padrow = NRows[fPatch][0]; padrow <= NRows[fPatch][1]; padrow++)
-  
-  Double_t phi_min = -10*ToRad;
-  Double_t phi_max = 10*ToRad;
-  Double_t delta_phi = (phi_max-phi_min)/fNPhiSegments;
-  
-
-  Int_t phi_min_index = (Int_t)((phirange[0]*ToRad-phi_min)/delta_phi);
-  Int_t phi_max_index = (Int_t)((phirange[1]*ToRad-phi_min)/delta_phi);
-    
-  
-  Int_t index;
   
-  for(Int_t phi=phi_min_index; phi <= phi_max_index; phi++)
+  for(Int_t i=NRows[GetPatch()][0]; i<=NRows[GetPatch()][1]; i++)
     {
-      for(Int_t padrow = rowrange[0]; padrow <= rowrange[1]; padrow++)
+      AliL3DigitData *digPt = tempPt->fDigitData;
+      if(i != (Int_t)tempPt->fRow)
        {
+         printf("AliL3HoughTransform::TransformLine : Mismatching padrow numbering\n");
+         continue;
+       }
+      for(UInt_t j=0; j<tempPt->fNDigit; j++)
+       {
+         UShort_t charge = digPt[j].fCharge;
+         UChar_t pad = digPt[j].fPad;
+         UShort_t time = digPt[j].fTime;
+         if(charge < GetThreshold())
+           continue;
+         Int_t sector,row;
+         Float_t xyz[3];
+         fTransform->Slice2Sector(GetSlice(),i,sector,row);
+         fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
+         Float_t eta = fTransform->GetEta(xyz);
+         Int_t eta_index = GetEtaIndex(eta);//(Int_t)(eta/etaslice);
+         if(eta_index < 0 || eta_index >= GetNEtaSegments())
+           continue;
          
-         index = phi*fNumOfPadRows + padrow;
-         //printf("Looping index %d\n",index);
-         if(index > fContainerBounds || index < 0)
+         //Get the correct histogram:
+         AliL3Histogram *hist = fParamSpace[eta_index];
+         if(!hist)
            {
-             printf("AliL3HoughTransformer::Transform2Line : index %d out of range \n",index);
-             return;
+             printf("AliL3HoughTransformer::TransformLine : Error getting histogram in index %d\n",eta_index);
+             continue;
            }
-         for(pix1=(AliL3Digits*)fRowContainer[padrow].first; pix1!=0; pix1=(AliL3Digits*)pix1->nextRowPixel)
-         //for(pix1=(AliL3Digits*)fPhiRowContainer[index].first; pix1!=0; pix1=(AliL3Digits*)pix1->nextPhiRowPixel)
+         for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
            {
-             //printf("Transforming pixel in index %d pad %d time %d padrow %d\n",index,pix1->fPad,pix1->fTime,padrow);
-             Float_t xyz[3];
-             fTransform->Slice2Sector(fSlice,padrow,sector,row);
-             fTransform->Raw2Local(xyz,sector,row,pix1->fPad,pix1->fTime);
-                 
-             if(raw)
-               raw->Fill(xyz[0],xyz[1],pix1->fCharge);
-
-             xyz[0] = xyz[0]-x0;
-             xyz[1] = xyz[1]-y0;
-             
-             //printf("calculating...");
-             for(Int_t d=xmin+1; d<=xmax; d++)
-               {
-                 Double_t psi = hist->GetXaxis()->GetBinCenter(d);
-                 Double_t D = xyz[0]*cos(psi) + xyz[1]*sin(psi);
-                 
-                 Short_t signal = pix1->fCharge;
-                 hist->Fill(psi,D,signal);
-                 //printf("Filling histo, psi %f D %f\n",psi,D);
-               }
-             //printf("done\n");
+             Double_t theta = hist->GetBinCenterX(xbin);
+             Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
+             hist->Fill(theta,rho,charge);
            }
-         //printf(" done\n");
        }
-      
-    }
-    
-}
-
-
-void AliL3HoughTransformer::GetPixels(Char_t *rootfile,TH2F *hist)
-{
-
-  //read data from rootfile. more or less obsolete code this.
-
-  TFile *file = new TFile(rootfile);
-  file->cd();
-
-  AliTPCParam *param=(AliTPCParam *)file->Get("75x40_100x60");
-  TTree *t=(TTree*)file->Get("TreeD_75x40_100x60");      
-    
-  AliSimDigits da, *digarr=&da;
-  t->GetBranch("Segment")->SetAddress(&digarr);
-  Stat_t num_of_entries=t->GetEntries();
-
-  Int_t digit_counter=0;
-  Float_t xyz[3];
-  Double_t eta;
-  
-  Int_t nrows = NRows[fPatch][1] - NRows[fPatch][0] + 1;
-  printf("nrows %d slice %d patch %d\n",nrows,fSlice,fPatch);
-  
-  if(fRowContainer)
-    delete [] fRowContainer;
-  fRowContainer = new AliL3HoughContainer[fNumOfPadRows];
-  memset(fRowContainer,0,fNumOfPadRows*sizeof(AliL3HoughContainer));
-
-
-  //fContainerBounds = (fNPhiSegments+1)*(fNumOfPadRows+1);
-  //printf("Allocating %d bytes to container of size %d\n",fContainerBounds*sizeof(AliL3HoughContainer),fContainerBounds);
-
-  
-  //  if(fPhiRowContainer)
-  //  delete [] fPhiRowContainer;
-  //  fPhiRowContainer = new AliL3HoughContainer[fContainerBounds];
-  //  memset(fPhiRowContainer,0,fContainerBounds*sizeof(AliL3HoughContainer));
-  
-  fContainerBounds = (fNumEtaSegments+1)*(fNumOfPadRows+1);
-  if(fVolume)
-    delete [] fVolume;
-  fVolume = new AliL3HoughContainer[fContainerBounds];
-  memset(fVolume,0,fContainerBounds*sizeof(AliL3HoughContainer));
-  
-  //  Double_t phi_min = -10*ToRad;
-  //  Double_t phi_max = 10*ToRad;
-  //  Double_t delta_phi = (phi_max-phi_min)/fNPhiSegments;
-  
-  Double_t eta_slice = (fEtaMax-fEtaMin)/fNumEtaSegments;
-  Int_t index;
-  digit_counter=0;
-
-  //printf("\nLoading ALL pixels in slice\n\n");
-
-  for (Int_t i=0; i<num_of_entries; i++) 
-    { 
-      t->GetEvent(i);
-      Int_t sector; 
-      Int_t row;    
-      param->AdjustSectorRow(digarr->GetID(),sector,row);
-      Int_t slice,padrow;
-      fTransform->Sector2Slice(slice,padrow,sector,row);
-      if(slice != fSlice) continue;
-      if(padrow < NRows[fPatch][0]) continue;
-      if(padrow > NRows[fPatch][1]) break;
-      digarr->First();
-      do {
-       Int_t time=digarr->CurrentRow();
-       Int_t pad=digarr->CurrentColumn();
-       Short_t signal=digarr->CurrentDigit();
-       if(time < param->GetMaxTBin()-1 && time > 0)
-         if(digarr->GetDigit(time-1,pad) <= param->GetZeroSup()
-            && digarr->GetDigit(time+1,pad) <= param->GetZeroSup()) 
-           continue;
-       
-       
-       fTransform->Raw2Global(xyz,sector,row,pad,time);
-       eta = fTransform->GetEta(xyz);
-       
-       if(eta < fEtaMin || eta > fEtaMax) continue;
-       fTransform->Global2Local(xyz,sector);
-       
-       
-       //phi = fTransform->GetPhi(xyz);
-       if(hist)
-         hist->Fill(xyz[0],xyz[1],signal);
-       
-       AliL3Digits *dig = new AliL3Digits;
-       dig->fIndex = digit_counter;
-       digit_counter++;
-       dig->fCharge = signal;
-       dig->fPad = pad;
-       dig->fTime = time;
-       
-       if(fRowContainer[padrow].first == NULL)
-         fRowContainer[padrow].first = (void*)dig;
-       else
-         ((AliL3Digits*)(fRowContainer[padrow].last))->nextRowPixel=dig;
-       fRowContainer[padrow].last = (void*)dig;
-       
-       //thisHit->etaIndex=(Int_t)((thisHit->GetEta()-fEtaMin)/etaSlice + 1);
-       Int_t eta_index = (Int_t)((eta-fEtaMin)/eta_slice);
-       index = eta_index*fNumOfPadRows + padrow;
-       if(index > fContainerBounds || index < 0)
-         {
-           
-           //printf("AliL3HoughTransformer::GetPixels : index out of range %d %d eta_index %d padrow %d\n",index,fContainerBounds,eta_index,padrow);
-           continue;
-         }
-       
-       if(fVolume[index].first == NULL)
-         fVolume[index].first = (void*)dig;
-       else
-         ((AliL3Digits*)(fVolume[index].last))->fNextVolumePixel = dig;
-       fVolume[index].last = (void*)dig;
-       
-       
-       //  Int_t phi_index = (Int_t)((phi-phi_min)/delta_phi);
-       //  index = phi_index*fNumOfPadRows + padrow;
-       //  if(phi_index > fContainerBounds || phi_index < 0)
-       // {
-       //  printf("AliL3HoughTransform::GetPixels : index out of range %d\n",phi_index);
-       //  continue;
-       //  }
-         
-       //  if(fPhiRowContainer[index].first == NULL)
-       //  fPhiRowContainer[index].first = (void*)dig;
-       //  else
-       //  ((AliL3Digits*)(fPhiRowContainer[index].last))->nextPhiRowPixel = dig;
-       //  fPhiRowContainer[index].last=(void*)dig;
-       
-      }while (digarr->Next());
-      
+      AliL3MemHandler::UpdateRowPointer(tempPt);
     }
   
-  fNDigits = digit_counter;
-  printf("digitcounter %d\n",digit_counter);
-  printf("Allocated %d bytes to pixels\n",digit_counter*sizeof(AliL3Digits));
-  file->Close();
-  delete file;
-  
 }
-*/