3 // Author: Constantin Loizides <mailto:loizides@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
8 #include "AliL3RootTypes.h"
9 #include "AliL3Logging.h"
10 #include "AliL3MemHandler.h"
11 #include "AliL3Transform.h"
12 #include "AliL3DigitData.h"
13 #include "AliL3HoughTransformerVhdl.h"
14 #include "AliL3FFloat.h"
20 /** \class AliL3HoughTransformerVhdl
22 //_____________________________________________________________
23 // AliL3HoughTransformerVhdl
25 // Hough transformation class for VHDL comparism.
30 ClassImp(AliL3HoughTransformerVhdl)
33 AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl()
34 : AliL3HoughTransformerLUT()
44 AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl(Int_t slice,Int_t patch,Int_t netasegments,Int_t nits)
45 : AliL3HoughTransformerLUT(slice,patch,netasegments)
54 AliL3HoughTransformerVhdl::~AliL3HoughTransformerVhdl()
59 void AliL3HoughTransformerVhdl::CreateHistograms(Int_t nxbin,Float_t ptmin,Int_t nybin,Float_t phimin,Float_t phimax)
61 //Create histograms containing the hough space
62 AliL3HoughTransformerLUT::CreateHistograms(nxbin,ptmin,nybin,phimin,phimax);
65 void AliL3HoughTransformerVhdl::CreateHistograms(Int_t nxbin,Float_t xmin,Float_t xmax,
66 Int_t nybin,Float_t ymin,Float_t ymax)
68 //Create histograms containing the hough space
69 AliL3HoughTransformerLUT::CreateHistograms(nxbin,xmin,xmax,nybin,ymin,ymax);
71 fEpsilon=(ymax-ymin)/nybin;
72 fSinEpsilon=sin(fEpsilon);
73 fCosEpsilon=cos(fEpsilon);
81 //cout << fEpsilon << " - " << (xmax-xmin)/nxbin << endl;
84 void AliL3HoughTransformerVhdl::Init(Int_t slice,Int_t patch,Int_t netasegments,Int_t /*nits*/)
86 //Init hough transformer
87 AliL3HoughTransformerLUT::Init(slice,patch,netasegments);
90 void AliL3HoughTransformerVhdl::TransformCircle()
92 //Transform the input data with a circle HT.
93 //The function loops over all the data, and transforms each pixel with the equation:
95 //kappa = lastkappa +- epsilon * lastkappaprime
97 //kappaprime = lastkappaprime -+ epsilon * lastkappa
99 //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find
100 //which histogram in which the pixel should be transformed, the eta-value is calcluated
101 //and the proper histogram index is found by GetEtaIndex(eta).
104 AliL3DigitRowData *tempPt = GetDataPointer();
107 LOG(AliL3Log::kError,"AliL3HoughTransformerVhdl::TransformCircle","Data")
108 <<"No input data "<<ENDLOG;
119 //Loop over the padrows:
120 for(Int_t i=fMinRow, row=0; i<=fMaxRow; i++, row++)
122 //Get the data on this padrow:
123 AliL3DigitData *digPt = tempPt->fDigitData;
124 if(i != (Int_t)tempPt->fRow)
126 LOG(AliL3Log::kError,"AliL3HoughTransformerVhdl::TransformCircle","Data")
127 <<"AliL3HoughTransformerLUT::TransformCircle : Mismatching padrow numbering "<<i<<" != "<<(Int_t)tempPt->fRow<<ENDLOG;
131 Float_t x = CalcX(row);
139 //Loop over the data on this padrow:
140 for(UInt_t j=0; j<tempPt->fNDigit; j++)
142 UShort_t charge = digPt[j].fCharge;
145 if((Int_t)charge <= GetLowerThreshold() || (Int_t)charge > GetUpperThreshold())
148 UChar_t pad = digPt[j].fPad;
149 UShort_t time = digPt[j].fTime;
151 if(fLastPad!=pad){ //only update if necessary
157 for(Int_t b=0; b<fNPhi0; b++)
158 fLUTKappa[b]=rr2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
160 //Fill the histogram along the phirange
162 Float_t kappaprime=0;
164 Float_t lastkappaprime=0;
166 Float_t rr2=1/(x*x+y*y);
171 Float_t phi = fLUTphi0[fNPhi0/2];
172 kappa=a*cos(phi)+b*sin(phi);
173 kappaprime=b*cos(phi)-a*sin(phi);
176 lastkappaprime=kappaprime;
177 // hist->Fill(kappa,phi,charge);
179 for(Int_t b=fNPhi0/2+1; b<fNPhi0; b++){
180 //Float_t exact_kappa=rr2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
184 if(its==0) { //initialize or re-adjust values
185 kappa=a*cos(phi)+b*sin(phi); //equals exact_kappa!
186 kappaprime=b*cos(phi)-a*sin(phi);
189 //kappa=fCosEpsilon*lastkappa+fSinEpsilon*lastkappaprime;
190 //kappaprime=fCosEpsilon*lastkappaprime-fSinEpsilon*lastkappa;
191 kappa=lastkappa+fEpsilon*lastkappaprime;
192 kappaprime=lastkappaprime-fEpsilon*lastkappa;
197 lastkappaprime=kappaprime;
198 //hist->Fill(kappa,phi,charge);
199 } // end positive running values
201 phi = fLUTphi0[fNPhi0/2];
202 kappa=a*cos(phi)+b*sin(phi);
203 kappaprime=b*cos(phi)-a*sin(phi);
206 lastkappaprime=kappaprime;
207 //hist->Fill(kappa,fLUTphi0[b],charge);
209 for(Int_t b=fNPhi0/2-1; b>=0; b--){
210 //Float_t exact_kappa=rr2*(y*fLUT2cosphi0[b]-x*fLUT2sinphi0[b]);
212 Float_t phi = fLUTphi0[b];
214 if(its==0) { //initialize or re-adjust values
215 kappa=a*cos(phi)+b*sin(phi); //equals exact_kappa!
216 kappaprime=b*cos(phi)-a*sin(phi);
219 //kappa=fCosEpsilon*lastkappa-fSinEpsilon*lastkappaprime;
220 //kappaprime=fCosEpsilon*lastkappaprime+fSinEpsilon*lastkappa;
221 kappa=lastkappa-fEpsilon*lastkappaprime;
222 kappaprime=lastkappaprime+fEpsilon*lastkappa;
227 lastkappaprime=kappaprime;
228 //hist->Fill(kappa,phi,charge);
234 Float_t z = CalcZ(time);
237 Float_t rz2 = 1 + (x*x+y*y)/(z*z);
238 Int_t etaindex = FindIndex(rz2);
240 if(etaindex < 0 || etaindex >= fNEtas){
241 //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"No histograms corresponding to eta index value of "<<etaindex<<"."<<ENDLOG;
245 //Get the correct histogrampointer:
246 AliL3Histogram *hist = fParamSpace[etaindex];
248 //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"Error getting histogram in index "<<etaindex<<"."<<ENDLOG;
252 for(Int_t b=0; b<fNPhi0; b++){
255 Float_t err=fabs((exact_kappa-kappa)/exact_kappa);
258 //cout << max_error << " - " << err << " " << kappa << " " << exact_kappa << " " << kappa/exact_kappa<< endl;
265 //hist->Fill(kappa,fLUTphi0[b],charge);
267 //cout << kappa << " " << fLUTphi0[b] << " " << charge << endl;
270 //Move the data pointer to the next padrow:
271 AliL3MemHandler::UpdateRowPointer(tempPt);
275 cout <<"Max Error: " << max_error << endl;
276 cout <<"Rel Error average: " << rel_error/counter << endl;
281 void AliL3HoughTransformerVhdl::Print()
283 //Print transformer params
284 AliL3HoughTransformerLUT::Print();
286 cout << "fEpsilon: " << fEpsilon << endl;
287 cout << "fIts: " << fIts << endl;
290 void AliL3HoughTransformerVhdl::PrintVhdl() const
292 //Print all transformer params
293 cout << "fSlice := " << GetSlice() << ";" << endl;
294 cout << "fPatch := " << GetPatch() << ";" << endl;
295 //cout << "fSector := " << fSector << ";" << endl;
296 //cout << "fSectorRow := " << fSectorRow << ";" << endl;
297 //cout << "fMinRow := " << fMinRow << ";" << endl;
298 //cout << "fMaxRow := " << fMaxRow << ";" << endl;
299 //cout << "fNRows := " << fNRows << ";" << endl;
300 //cout << "fNEtas := " << fNEtas << ";" << endl;
301 //cout << "fNPhi0 := " << fNPhi0 << ";" << endl;
302 cout << "fZSign := " << fZSign << ";" << endl;
303 cout << "fZLengthPlusOff := " << fZLengthPlusOff << ";" << endl;
304 cout << "fPadPitch := " << fPadPitch << ";" << endl;
305 cout << "fTimeWidth := " << fTimeWidth << ";" << endl;
308 cout << "fNLUTX :=" << fNRows << ";" << endl;
309 cout << "fLUTX := ( ";
310 for(Int_t i=0;i<fNRows-1;i++) cout << fLUTX[i] << ", ";
311 cout << fLUTX[fNRows-1] << " );\n" << endl;
312 cout << "fNLUTY := " << fNRows << ";" << endl;
313 cout << "fLUTY := ( ";
314 for(Int_t i=0;i<fNRows-1;i++) cout << fLUTY[i] << ", ";
315 cout << fLUTY[fNRows-1] << " );\n" << endl;
318 cout << "fNLUTEta := " << fNEtas << ";" << endl;
319 cout << "fLUTEta := (";
320 for(Int_t i=0;i<fNEtas-1;i++) cout << fLUTEta[i] << ", ";
321 cout << fLUTEta[fNEtas-1] << " );\n" << endl;
324 cout << "-- Kappa -- " << endl;
325 cout << "fNxbin := " << fNxbin << endl;
326 cout << "fxmin := " << fXmin << endl;
327 cout << "fxmax := " << fXmax << endl;
328 Float_t kdiff=(fXmax-fXmin)/fNxbin;
330 cout << "fKappa := ";
331 for(Int_t i=0;i<fNxbin;i++){
335 cout << k+kdiff << " );\n" << endl;
337 cout << "-- Phi --" << endl;
338 cout << "fNybin := " << fNybin << endl;
339 cout << "fymin := " << fYmin << endl;
340 cout << "fymax := " << fYmax << endl;
342 cout << "\nfNLUTphi0 := " << fNPhi0 << ";" << endl;
343 cout << "fLUTphi0 := (";
344 for(Int_t i=0;i<fNPhi0-1;i++) cout << fLUTphi0[i] << ", ";
345 cout << fLUTphi0[fNPhi0-1] << " );\n" << endl;
347 cout << "\nfNLUT2sinphi0 := " << fNPhi0 << ";" << endl;
348 cout << "fLUT2sinphi0 := (";
349 for(Int_t i=0;i<fNPhi0-1;i++) cout << fLUT2sinphi0[i] << ", ";
350 cout << fLUT2sinphi0[fNPhi0-1] << " );\n" << endl;
352 cout << "\nfNLUT2cosphi0 := " << fNPhi0 << ";" << endl;
353 cout << "fLUT2cosphi0 := (";
354 for(Int_t i=0;i<fNPhi0-1;i++) cout << fLUT2cosphi0[i] << ", ";
355 cout << fLUT2cosphi0[fNPhi0-1] << " );\n" << endl;
357 //cout << "\nfEpsilon := " << fEpsilon << endl;
358 //cout << "\nfSinEpsilon := " << fSinEpsilon << endl;
359 //cout << "\nfCosEpsilon := " << fCosEpsilon << endl;