]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Changes done for new aliroot version. Faster calculation through saving LUT for kappa.
authorloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 5 Sep 2002 11:13:54 +0000 (11:13 +0000)
committerloizides <loizides@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 5 Sep 2002 11:13:54 +0000 (11:13 +0000)
HLT/hough/AliL3HoughTransformerLUT.cxx
HLT/hough/AliL3HoughTransformerLUT.h
HLT/hough/AliL3HoughTransformerVhdl.cxx
HLT/hough/AliL3HoughTransformerVhdl.h

index 1c218e523697d27fbe46577f783674fe8b4c72c2..a0f39a0a68ce103e50e01766215e9aa784686c72 100644 (file)
@@ -47,6 +47,10 @@ AliL3HoughTransformerLUT::AliL3HoughTransformerLUT() : AliL3HoughBaseTransformer
   fLUTphi0=0;
   fLUT2sinphi0=0;
   fLUT2cosphi0=0;
+  fLUTKappa=0;
+
+  fLastPad=0;
+  fLastIndex=0;
 }
 
 AliL3HoughTransformerLUT::AliL3HoughTransformerLUT(Int_t slice,Int_t patch,Int_t n_eta_segments) : AliL3HoughBaseTransformer(slice,patch,n_eta_segments)
@@ -71,6 +75,10 @@ AliL3HoughTransformerLUT::AliL3HoughTransformerLUT(Int_t slice,Int_t patch,Int_t
   fLUTphi0=0;
   fLUT2sinphi0=0;
   fLUT2cosphi0=0;
+  fLUTKappa=0;
+
+  fLastPad=0;
+  fLastIndex=0;
 
   Init(slice,patch,n_eta_segments);
 }
@@ -109,10 +117,12 @@ void AliL3HoughTransformerLUT::DeleteHistograms()
     delete[] fLUT2sinphi0;
     delete[] fLUT2cosphi0;
     delete[] fLUTphi0;
+    delete[] fLUTKappa;
     fNPhi0=0;
     fLUTphi0=0;
     fLUT2sinphi0=0;
     fLUT2cosphi0=0;
+    fLUTKappa=0;
   }
 
   if(!fParamSpace){
@@ -229,6 +239,7 @@ void AliL3HoughTransformerLUT::CreateHistograms(Int_t nxbin,Double_t xmin,Double
   fLUTphi0=new Float_t[fNPhi0];
   fLUT2sinphi0=new Float_t[fNPhi0];
   fLUT2cosphi0=new Float_t[fNPhi0];
+  fLUTKappa=new Float_t[fNPhi0];
   Float_t diff=(ymax-ymin)/nybin;
   Float_t phi0=ymin-0.5*diff;
   for(Int_t i=0; i<fNPhi0; i++){
@@ -236,6 +247,7 @@ void AliL3HoughTransformerLUT::CreateHistograms(Int_t nxbin,Double_t xmin,Double
     fLUTphi0[i]=phi0;
     fLUT2sinphi0[i]=2.*sin(phi0);
     fLUT2cosphi0[i]=2.*cos(phi0);
+    fLUTKappa[i]=0.;
     //cout << i << ": " << fLUTphi0[i] << " " << fLUT2sinphi0[i] << " " << fLUT2cosphi0[i] << endl;
   }  
 }
@@ -272,13 +284,22 @@ Int_t AliL3HoughTransformerLUT::GetEtaIndex(Double_t eta)
   return FindIndex(rz2);
 }
 
-Int_t AliL3HoughTransformerLUT::FindIndex(Float_t rz2)
+Int_t AliL3HoughTransformerLUT::FindIndex(Float_t rz2, Int_t start)
 {
-  Int_t index=0; //could improve search through devide and conquere strategy
-  while((index<fNEtas)&&(rz2<=fLUTEta[index])){
-    index++;
-    //cout << index << ": " << rz2 << " " << fLUTEta[index] << endl;
+  //could improve search through devide and conquere strategy
+  
+  Int_t index=start; 
+  if(index==-100){
+    index=0;
+    while((index<fNEtas)&&(rz2<=fLUTEta[index])){
+      index++;
+    }
+  } else {
+    while((index>=0)&&(rz2>fLUTEta[index])){
+      index--;
+    }
   }
+  //cout << start << " - " << index << ": " << rz2 << " " << fLUTEta[index] << endl;
   return index;
 }
 
@@ -373,6 +394,13 @@ void AliL3HoughTransformerLUT::TransformCircle()
          continue;
        }
 
+      Float_t x = CalcX(row);
+      Float_t x2=x*x;
+      Float_t y=0,y2=0;
+      Float_t r2=0;
+      Float_t R2=0;
+      fLastPad=-1;
+
       //Loop over the data on this padrow:
       for(UInt_t j=0; j<tempPt->fNDigit; j++)
        {
@@ -385,14 +413,25 @@ void AliL3HoughTransformerLUT::TransformCircle()
          UChar_t pad = digPt[j].fPad;
          UShort_t time = digPt[j].fTime;
 
-         Float_t x = CalcX(row);
-         Float_t y = CalcY(pad,row);
+         if(fLastPad!=pad){ //only update if necessary
+           fLastIndex=fNEtas-1;   
+           y = CalcY(pad,row);
+           y2 = y*y;
+           r2 = x2 + y2;
+           R2 = 1. / r2;
+           for(Int_t b=0; b<fNPhi0; b++)
+             fLUTKappa[b]=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
+
+           fLastPad=pad;
+         }
+
          Float_t z = CalcZ(time);
 
          //find eta slice
-         Float_t rz2 = 1 + (x*x+y*y)/(z*z);
-         Int_t eta_index = FindIndex(rz2);
-
+         Float_t rz2 = 1 + r2/(z*z);
+         Int_t eta_index = FindIndex(rz2,fLastIndex);
+         //cout << row << " " << (int)pad << " " << (int)time << " " << eta_index <<" " <<fLastIndex<< endl;
+         fLastIndex=eta_index;
          if(eta_index < 0 || eta_index >= fNEtas){
            //LOG(AliL3Log::kWarning,"AliL3HoughTransformerLUT::TransformCircle","Histograms")<<"No histograms corresponding to eta index value of "<<eta_index<<"."<<ENDLOG;
            continue;
@@ -406,10 +445,10 @@ void AliL3HoughTransformerLUT::TransformCircle()
          }
 
          //Fill the histogram along the phirange
-         Float_t R2=1/(x*x+y*y);
-         for(Int_t b=0; b<fNPhi0; b++){
-           Float_t kappa=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
 
+         for(Int_t b=0; b<fNPhi0; b++){
+           //Float_t kappa=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
+           Float_t kappa=fLUTKappa[b];
            hist->Fill(kappa,fLUTphi0[b],charge);
            //cout << kappa << " " << fLUTphi0[b] << " " << charge << endl;
 
index 2861f98449817a791b3f3323809e828aba120af6..5f00b2db5a81e0eb1c03676013d1851c8c42ccde 100644 (file)
@@ -37,14 +37,18 @@ class AliL3HoughTransformerLUT : public AliL3HoughBaseTransformer {
   Float_t *fLUTphi0; //!
   Float_t *fLUT2sinphi0; //!   
   Float_t *fLUT2cosphi0; //!
+  Float_t *fLUTKappa; //!
   
+  Int_t fLastPad;
+  Int_t fLastIndex;
+
   Float_t CalcRoverZ2(Float_t eta);
   Float_t CalcEta(Float_t roverz2);
   Float_t CalcX(Int_t row);
   Float_t CalcY(Int_t pad, Int_t row);
   Float_t CalcZ(Int_t time);  
 
-  Int_t FindIndex(Float_t rz2);
+  Int_t FindIndex(Float_t rz2, Int_t start=-100);
 
  public:
 
@@ -73,7 +77,3 @@ class AliL3HoughTransformerLUT : public AliL3HoughBaseTransformer {
 };
 
 #endif
-
-
-
-
index 0aac048497f53ce2b052af340ce8e0a45f647784..de7faf66e3d2ea0e50468c84a6dd90406159368e 100644 (file)
@@ -11,6 +11,7 @@
 #include "AliL3Transform.h"
 #include "AliL3DigitData.h"
 #include "AliL3HoughTransformerVhdl.h"
+#include "AliL3FFloat.h"
 
 #if GCCVERSION == 3
 using namespace std;
@@ -67,6 +68,12 @@ void AliL3HoughTransformerVhdl::CreateHistograms(Int_t nxbin,Double_t xmin,Doubl
   fSinEpsilon=sin(fEpsilon);
   fCosEpsilon=cos(fEpsilon);
 
+  fNxbin=nxbin;
+  fXmin=xmin;
+  fXmax=xmax;
+  fNybin=nybin;
+  fYmin=ymin;
+  fYmax=ymax;
   //  cout << fEpsilon << " - " << (xmax-xmin)/nxbin << endl;
 }
 
@@ -88,6 +95,7 @@ void AliL3HoughTransformerVhdl::TransformCircle()
   //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)
     {
@@ -115,6 +123,14 @@ void AliL3HoughTransformerVhdl::TransformCircle()
          continue;
        }
 
+      Float_t x = CalcX(row);
+      Float_t x2=x*x;
+      Float_t y=0,y2=0;
+      Float_t r2=0;
+      Float_t R2=0;
+      fLastPad=-1;
+
+
       //Loop over the data on this padrow:
       for(UInt_t j=0; j<tempPt->fNDigit; j++)
        {
@@ -127,8 +143,91 @@ void AliL3HoughTransformerVhdl::TransformCircle()
          UChar_t pad = digPt[j].fPad;
          UShort_t time = digPt[j].fTime;
 
-         Float_t x = CalcX(row);
-         Float_t y = CalcY(pad,row);
+         if(fLastPad!=pad){ //only update if necessary
+           fLastIndex=fNEtas-1;   
+           y = CalcY(pad,row);
+           y2 = y*y;
+           r2 = x2 + y2;
+           R2 = 1. / r2;
+           for(Int_t b=0; b<fNPhi0; b++)
+             fLUTKappa[b]=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
+
+           //Fill the histogram along the phirange
+           Float_t kappa=0;
+           Float_t kappaprime=0;
+           Float_t lastkappa=0;
+           Float_t lastkappaprime=0;
+           Int_t its=0;
+           Float_t R2=1/(x*x+y*y);
+           Float_t A=2*y*R2;
+           Float_t B=-2*x*R2;
+
+           //starting point
+           Float_t phi = fLUTphi0[fNPhi0/2];
+           kappa=A*cos(phi)+B*sin(phi);
+           kappaprime=B*cos(phi)-A*sin(phi);
+           its=fIts;
+           lastkappa=kappa;
+           lastkappaprime=kappaprime;
+           //    hist->Fill(kappa,phi,charge);
+
+           for(Int_t b=fNPhi0/2+1; b<fNPhi0; b++){ 
+             Float_t exact_kappa=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
+             
+             phi=fLUTphi0[b];
+
+             if(its==0) { //initialize or re-adjust values
+               kappa=A*cos(phi)+B*sin(phi); //equals exact_kappa!
+               kappaprime=B*cos(phi)-A*sin(phi);
+               its=fIts;
+             } else {
+               //kappa=fCosEpsilon*lastkappa+fSinEpsilon*lastkappaprime;
+               //kappaprime=fCosEpsilon*lastkappaprime-fSinEpsilon*lastkappa;
+               kappa=lastkappa+fEpsilon*lastkappaprime;
+               kappaprime=lastkappaprime-fEpsilon*lastkappa;
+               its--;
+             }
+
+             lastkappa=kappa;
+             lastkappaprime=kappaprime;
+
+             //            hist->Fill(kappa,phi,charge);
+           } // end positive running values
+
+           phi = fLUTphi0[fNPhi0/2];
+           kappa=A*cos(phi)+B*sin(phi);
+           kappaprime=B*cos(phi)-A*sin(phi);
+           its=fIts;
+           lastkappa=kappa;
+           lastkappaprime=kappaprime;
+           //hist->Fill(kappa,fLUTphi0[b],charge);
+
+           for(Int_t b=fNPhi0/2-1; b>=0; b--){ 
+             Float_t exact_kappa=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
+
+             Float_t phi = fLUTphi0[b];
+
+             if(its==0) { //initialize or re-adjust values
+               kappa=A*cos(phi)+B*sin(phi); //equals exact_kappa!
+               kappaprime=B*cos(phi)-A*sin(phi);
+               its=fIts;
+             } else {
+               //kappa=fCosEpsilon*lastkappa-fSinEpsilon*lastkappaprime;
+               //kappaprime=fCosEpsilon*lastkappaprime+fSinEpsilon*lastkappa;
+               kappa=lastkappa-fEpsilon*lastkappaprime;
+               kappaprime=lastkappaprime+fEpsilon*lastkappa;
+               its--;
+             }
+
+             lastkappa=kappa;
+             lastkappaprime=kappaprime;
+             
+             //            hist->Fill(kappa,phi,charge);
+           }
+
+           fLastPad=pad;
+         }
+
          Float_t z = CalcZ(time);
 
          //find eta slice
@@ -147,97 +246,7 @@ void AliL3HoughTransformerVhdl::TransformCircle()
            continue;
          }
 
-         //Fill the histogram along the phirange
-         Float_t kappa=0;
-         Float_t kappaprime=0;
-         Float_t lastkappa=0;
-         Float_t lastkappaprime=0;
-         Int_t its=0;
-         Float_t R2=1/(x*x+y*y);
-         Float_t A=2*y*R2;
-         Float_t B=-2*x*R2;
-
-#if 1
-         //starting point
-         Float_t phi = fLUTphi0[fNPhi0/2];
-         kappa=A*cos(phi)+B*sin(phi);
-         kappaprime=B*cos(phi)-A*sin(phi);
-         its=fIts;
-         lastkappa=kappa;
-         lastkappaprime=kappaprime;
-         hist->Fill(kappa,phi,charge);
-
-         for(Int_t b=fNPhi0/2+1; b<fNPhi0; b++){ 
-           Float_t exact_kappa=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
-
-           phi=fLUTphi0[b];
-
-           if(its==0) { //initialize or re-adjust values
-             kappa=A*cos(phi)+B*sin(phi); //equals exact_kappa!
-             kappaprime=B*cos(phi)-A*sin(phi);
-             its=fIts;
-           } else {
-             //kappa=fCosEpsilon*lastkappa+fSinEpsilon*lastkappaprime;
-             //kappaprime=fCosEpsilon*lastkappaprime-fSinEpsilon*lastkappa;
-             kappa=lastkappa+fEpsilon*lastkappaprime;
-             kappaprime=lastkappaprime-fEpsilon*lastkappa;
-             its--;
-           }
-
-           lastkappa=kappa;
-           lastkappaprime=kappaprime;
-
-           hist->Fill(kappa,phi,charge);
-         } // end positive running values
-
-         phi = fLUTphi0[fNPhi0/2];
-         kappa=A*cos(phi)+B*sin(phi);
-         kappaprime=B*cos(phi)-A*sin(phi);
-         its=fIts;
-         lastkappa=kappa;
-         lastkappaprime=kappaprime;
-         //hist->Fill(kappa,fLUTphi0[b],charge);
-
-         for(Int_t b=fNPhi0/2-1; b>=0; b--){ 
-           Float_t exact_kappa=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
-
-           Float_t phi = fLUTphi0[b];
-
-           if(its==0) { //initialize or re-adjust values
-             kappa=A*cos(phi)+B*sin(phi); //equals exact_kappa!
-             kappaprime=B*cos(phi)-A*sin(phi);
-             its=fIts;
-           } else {
-             //kappa=fCosEpsilon*lastkappa-fSinEpsilon*lastkappaprime;
-             //kappaprime=fCosEpsilon*lastkappaprime+fSinEpsilon*lastkappa;
-             kappa=lastkappa-fEpsilon*lastkappaprime;
-             kappaprime=lastkappaprime+fEpsilon*lastkappa;
-             its--;
-           }
-
-           lastkappa=kappa;
-           lastkappaprime=kappaprime;
-
-           hist->Fill(kappa,phi,charge);
-         }
-
-#else
          for(Int_t b=0; b<fNPhi0; b++){ 
-           Float_t exact_kappa=R2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
-
-           Float_t phi = fLUTphi0[b];
-
-           if(its==0) { //initialize or re-adjust values
-             kappa=A*cos(phi)+B*sin(phi); //equals exact_kappa!
-             kappaprime=B*cos(phi)-A*sin(phi);
-             its=fIts;
-           } else {
-             //kappa=fCosEpsilon*lastkappa+fSinEpsilon*lastkappaprime;
-             //kappaprime=fCosEpsilon*lastkappaprime-fSinEpsilon*lastkappa;
-             kappa=lastkappa+fEpsilon*lastkappaprime;
-             kappaprime=lastkappaprime-fEpsilon*lastkappa;
-             its--;
-           }
 
 #ifdef use_error
            Float_t err=fabs((exact_kappa-kappa)/exact_kappa);
@@ -250,16 +259,10 @@ void AliL3HoughTransformerVhdl::TransformCircle()
            rel_error+=err;
            counter++;
 #endif
-
-           lastkappa=kappa;
-           lastkappaprime=kappaprime;
-
-           hist->Fill(kappa,fLUTphi0[b],charge);
+           //hist->Fill(kappa,fLUTphi0[b],charge);
 
            //cout << kappa << " " << fLUTphi0[b] << " " << charge << endl;
          }
-#endif /*test*/
-
        }
       //Move the data pointer to the next padrow:
       AliL3MemHandler::UpdateRowPointer(tempPt);
@@ -269,6 +272,7 @@ void AliL3HoughTransformerVhdl::TransformCircle()
   cout <<"Max Error: " << max_error << endl;
   cout <<"Rel Error average: " << rel_error/counter << endl;
 #endif
+
 }
 
 void AliL3HoughTransformerVhdl::Print()
@@ -278,3 +282,57 @@ void AliL3HoughTransformerVhdl::Print()
   cout << "fEpsilon: " << fEpsilon << endl;
   cout << "fIts: " << fIts << endl;
 }
+
+void AliL3HoughTransformerVhdl::PrintVhdl()
+{
+  cout << "fSlice := " << GetSlice() << ";" << endl;
+  cout << "fPatch := " << GetPatch() << ";" << endl;
+  //  cout << "fSector := " << fSector << ";" << endl;
+  //  cout << "fSectorRow := " << fSectorRow << ";" << endl;
+  //  cout << "fMinRow := " << fMinRow << ";" << endl;
+  //  cout << "fMaxRow := " << fMaxRow << ";" << endl;
+  //  cout << "fNRows := " << fNRows << ";" << endl;
+  //  cout << "fNEtas := " << fNEtas << ";" << endl;
+  //  cout << "fNPhi0 := " << fNPhi0 << ";" << endl;
+  cout << "fZSign := " << fZSign << ";" << endl;
+  cout << "fZLengthPlusOff := " << fZLengthPlusOff << ";" << endl;
+  cout << "fPadPitch := " << fPadPitch << ";" << endl;
+  cout << "fTimeWidth := " << fTimeWidth << ";" << endl;
+  
+  if(!fNRows) return;
+  cout << "fNLUTX :=" << fNRows << ";" << endl;
+  cout << "fLUTX := ( ";
+  for(Int_t i=0;i<fNRows-1;i++) cout << fLUTX[i] << ", ";
+  cout << fLUTX[fNRows-1] << " );\n" << endl; 
+  cout << "fNLUTY := " << fNRows << ";" << endl;
+  cout << "fLUTY := ( ";
+  for(Int_t i=0;i<fNRows-1;i++) cout << fLUTY[i] << ", ";
+  cout << fLUTY[fNRows-1] << " );\n" << endl;
+  if(!fNEtas) return;
+  cout << "fNLUTEta := " << fNEtas << ";" << endl;
+  cout << "fLUTEta := ("; 
+  for(Int_t i=0;i<fNEtas-1;i++) cout << fLUTEta[i] << ", ";
+  cout << fLUTEta[fNEtas-1] << " );\n" << endl; 
+
+  if(!fNPhi0) return;
+  cout << "fNxbin := " << fNxbin << endl;
+  cout << "fxmin := " << fXmin << endl;
+  cout << "fxmax := " << fXmax << endl;
+  cout << "fNybin := " << fNybin << endl;
+  cout << "fymin := " << fYmin << endl;
+  cout << "fymax := " << fYmax << endl;
+
+  cout << "\nfNLUTphi0 := " << fNPhi0 << ";" << endl;
+  cout << "fLUTphi0 := (";
+  for(Int_t i=0;i<fNPhi0-1;i++) cout << fLUTphi0[i] << ", ";
+  cout << fLUTphi0[fNPhi0-1] << " );\n" << endl; 
+
+  cout << "fLUT2sinphi0 := (";
+  for(Int_t i=0;i<fNPhi0-1;i++) cout << fLUT2sinphi0[i] << ", ";
+  cout << fLUT2sinphi0[fNPhi0-1] << " );\n" << endl; 
+
+  cout << "fLUT2cosphi0 := (";
+  for(Int_t i=0;i<fNPhi0;i++) cout << fLUT2cosphi0[i] << ", ";
+  cout << fLUT2cosphi0[fNPhi0-1] << " );\n" << endl; 
+}
index a1b6f10f88835154f912e91207b73d9ffc25a9b8..c17da613d1b4c20a5dafa1874ed8ecb4d51c2a19 100644 (file)
@@ -13,6 +13,13 @@ class AliL3HoughTransformerVhdl : public AliL3HoughTransformerLUT
   Float_t fCosEpsilon;
   Int_t fIts;
 
+  Int_t fNxbin;
+  Float_t fXmin;
+  Float_t fXmax;
+  Int_t fNybin;
+  Float_t fYmin;
+  Float_t fYmax;
+
  public:
 
   AliL3HoughTransformerVhdl(); 
@@ -24,22 +31,10 @@ class AliL3HoughTransformerVhdl : public AliL3HoughTransformerLUT
                        Int_t nybin,Double_t ymin,Double_t ymax);
 
   void TransformCircle();
-#if 0
-
-
-  void Reset();
-
-  void TransformCircleC(Int_t row_range) {STDCERR<<"TransformCircleC is not defined!"<<STDENDL;}
-  void TransformLine() {STDCERR<<"TransformLine is not defined!"<<STDENDL;}
 
-  Int_t GetEtaIndex(Double_t eta);
-  AliL3Histogram *GetHistogram(Int_t eta_index);
-  Double_t GetEta(Int_t eta_index,Int_t slice);
-
-
-#endif
   void Init(Int_t slice=0,Int_t patch=0,Int_t n_eta_segments=100,Int_t n_its=-1);
   void Print();
+  void PrintVhdl();
 
   ClassDef(AliL3HoughTransformerVhdl,1) //Normal Hough transformation class