Changes done for new aliroot version. Faster calculation through saving LUT for kappa.
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughTransformerVhdl.cxx
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; 
+}