]>
Commit | Line | Data |
---|---|---|
b46b53c1 | 1 | //$Id$ |
2 | ||
3 | // Author: Constantin Loizides <mailto:loizides@fi.uib.no> | |
6173606e | 4 | //*-- Copyright&Copy CL |
5 | ||
6 | #include <stream.h> | |
b46b53c1 | 7 | |
8 | #include "AliL3MemHandler.h" | |
9 | #include "AliL3Logging.h" | |
10 | #include "AliL3Transform.h" | |
11 | #include "AliL3DigitData.h" | |
12 | #include "AliL3Histogram.h" | |
6173606e | 13 | |
14 | ||
15 | //try to be close to VHDL version (eg. LUTs) | |
16 | //VESTBO: if you switch that of, you should get your version | |
17 | //of the transformer!!! | |
18 | #define VHDLVERSION | |
19 | ||
20 | //dont use dynamic objects on heap | |
21 | //VESTBO: this a desperately switched on in order | |
22 | //to find the bug, which i thought hat something | |
23 | //to do with a wrong heap assignment! But the | |
24 | //data still gets overwritten! | |
25 | #define VHDLSTATIC | |
26 | ||
27 | //switch off if you want to have floating point | |
28 | //#define USEFFLOAT | |
b46b53c1 | 29 | #include "AliL3HoughTransformerVhdl.h" |
30 | ||
6173606e | 31 | /** \class AliL3HoughTransformerVhdl |
32 | // <pre> | |
b46b53c1 | 33 | //_____________________________________________________________ |
34 | // AliL3HoughTransformerVhdl | |
35 | // | |
6173606e | 36 | // Hough transformation class for VHDL comparism. |
b46b53c1 | 37 | // |
6173606e | 38 | //</pre> |
39 | */ | |
b46b53c1 | 40 | |
41 | ClassImp(AliL3HoughTransformerVhdl) | |
42 | ||
6173606e | 43 | #ifdef VHDLVERSION |
44 | ||
b46b53c1 | 45 | AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl() |
6173606e | 46 | : AliL3HoughBaseTransformer() |
b46b53c1 | 47 | { |
6173606e | 48 | fParamSpace=0; |
49 | #ifndef VHDLSTATIC | |
50 | fLUTX=0; | |
51 | fLUTY=0; | |
52 | fLUTEta=0; | |
53 | fLUTphi0=0; | |
54 | fLUT2sinphi0=0; | |
55 | fLUT2cosphi0=0; | |
56 | #endif | |
57 | fMinRow=0; | |
58 | fMaxRow=0; | |
59 | fNRows=0; | |
60 | fNEtas=0; | |
61 | fNPhi0=0; | |
62 | fSector=0; | |
63 | fSectorRow=0; | |
64 | fZSign=0; | |
65 | fZLengthPlusOff=0.; | |
66 | fTimeWidth=0.; | |
67 | fPadPitch=0.; | |
68 | fEtaSlice=0.; | |
b46b53c1 | 69 | } |
70 | ||
6173606e | 71 | AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl(Int_t slice,Int_t patch,Int_t n_eta_segments) |
72 | : AliL3HoughBaseTransformer(slice,patch,n_eta_segments) | |
b46b53c1 | 73 | { |
6173606e | 74 | AliL3HoughTransformerVhdl(); |
75 | ||
76 | Init(slice,patch,n_eta_segments); | |
77 | } | |
78 | ||
79 | AliL3HoughTransformerVhdl::~AliL3HoughTransformerVhdl() | |
80 | { | |
81 | DeleteHistograms(); | |
82 | ||
83 | #ifndef VHDLSTATIC | |
84 | if(fNRows){ | |
85 | delete[] fLUTX; | |
86 | delete[] fLUTY; | |
87 | } | |
88 | if(fNEtas) delete[] fLUTEta; | |
89 | #endif | |
90 | } | |
91 | ||
92 | void AliL3HoughTransformerVhdl::Init(Int_t slice=0,Int_t patch=0,Int_t n_eta_segments=100) | |
93 | { | |
94 | cout << "InitVhdl " << slice << " " << patch << " " << n_eta_segments << endl; | |
95 | AliL3HoughBaseTransformer::Init(slice,patch,n_eta_segments); | |
96 | ||
97 | #ifndef VHDLSTATIC | |
98 | //delete old LUT tables | |
99 | if(fNRows){ | |
100 | fNRows=0; | |
101 | delete[] fLUTX; | |
102 | delete[] fLUTY; | |
103 | } | |
104 | if(fNEtas){ | |
105 | delete[] fLUTEta; | |
106 | fNEtas=0; | |
107 | } | |
108 | #endif | |
109 | ||
110 | //set when histogram is filled | |
111 | //fLUTphi0=0; | |
112 | //fLUT2sinphi0=0; | |
113 | //fLUT2cosphi0=0; | |
114 | ||
115 | Int_t minrow_=AliL3Transform::GetFirstRow(patch); | |
116 | Int_t maxrow_=AliL3Transform::GetLastRow(patch); | |
117 | Int_t n_=AliL3Transform::GetNRows(patch); | |
118 | Int_t sector_=0,sectorrow_=0; | |
119 | AliL3Transform::Slice2Sector(slice,minrow_,sector_,sectorrow_); | |
120 | Float_t padpitch_=0.; | |
121 | if(sector_<AliL3Transform::GetNSectorLow()) | |
122 | padpitch_=AliL3Transform::GetPadPitchWidthLow(); | |
123 | else | |
124 | padpitch_=AliL3Transform::GetPadPitchWidthUp(); | |
125 | ||
126 | Float_t etamax_=GetEtaMax(); | |
127 | Float_t etamin_=GetEtaMin(); | |
128 | Float_t etaslice_=(etamax_-etamin_)/n_eta_segments; | |
129 | ||
130 | //lookup tables for X and Y | |
131 | #ifndef VHDLSTATIC | |
132 | fLUTX=new AliL3FFloat[n_]; | |
133 | fLUTY=new AliL3FFloat[n_]; | |
134 | #endif | |
135 | for(Int_t rr=0;rr<n_;rr++){ | |
136 | fLUTX[rr]=Float_t(AliL3Transform::Row2X(rr+minrow_)); | |
137 | fLUTY[rr]=Float_t(0.5*(AliL3Transform::GetNPads(rr+minrow_)-1)*padpitch_); | |
138 | //VESTBO: uncomment to see values (and compare with Print function) | |
139 | //cout << rr << ": " << (Float_t)fLUTX[rr] << " " << (Float_t)fLUTY[rr] << endl; | |
140 | } | |
141 | ||
142 | //lookup tables for rz2s <=> etas | |
143 | #ifndef VHDLSTATIC | |
144 | fLUTEta=new AliL3FFloat[n_eta_segments]; | |
145 | #endif | |
146 | for(Int_t rr=0;rr<n_eta_segments;rr++){ | |
147 | fLUTEta[rr]=CalcRoverZ2(etamin_+(rr+1)*etaslice_); | |
148 | //VESTBO: uncomment to see values (and compare with Print function) | |
149 | //cout << rr << ": " << fLUTEta[rr] << endl; | |
150 | } | |
151 | ||
152 | //member values | |
153 | fMinRow=minrow_; | |
154 | fMaxRow=maxrow_; | |
155 | fNRows=n_; | |
156 | fNEtas=n_eta_segments; | |
157 | fNPhi0=0; | |
158 | fSector=sector_; | |
159 | fSectorRow=sectorrow_; | |
160 | fZSign = slice < 18 ? 1:-1; | |
161 | fZLengthPlusOff=AliL3Transform::GetZLength()+AliL3Transform::GetZOffset(); | |
162 | fTimeWidth=AliL3Transform::GetZWidth(); | |
163 | fPadPitch=padpitch_; | |
164 | fEtaSlice=etaslice_; | |
165 | } | |
166 | ||
167 | Float_t AliL3HoughTransformerVhdl::CalcRoverZ2(Float_t eta) | |
168 | { | |
169 | Float_t e=exp(2*eta); | |
170 | Float_t ret=(e+1)/(e-1); | |
171 | ret*=ret; | |
172 | return ret; | |
173 | } | |
174 | ||
175 | Float_t AliL3HoughTransformerVhdl::CalcEta(Float_t roverz2) | |
176 | { | |
177 | Float_t rz=sqrt(roverz2); | |
178 | if(fZSign>0) rz=-rz; | |
179 | Float_t ret=(1+rz)/(rz-1); | |
180 | ret=0.5*log(ret); | |
181 | return ret; | |
182 | } | |
183 | ||
184 | inline Float_t AliL3HoughTransformerVhdl::CalcX(Int_t row) | |
185 | { | |
186 | return fLUTX[row]; | |
187 | } | |
188 | ||
189 | inline Float_t AliL3HoughTransformerVhdl::CalcY(Int_t pad,Int_t row) | |
190 | { | |
191 | return pad*fPadPitch-fLUTY[row]; | |
192 | } | |
193 | ||
194 | inline Float_t AliL3HoughTransformerVhdl::CalcZ(Int_t time) | |
195 | { | |
196 | Float_t ret=time*fTimeWidth; | |
197 | if(fZSign>0) ret=fZLengthPlusOff-ret; | |
198 | else ret=ret-fZLengthPlusOff; | |
199 | return ret; | |
200 | } | |
201 | ||
202 | void AliL3HoughTransformerVhdl::DeleteHistograms() | |
203 | { | |
204 | if(!fParamSpace) return; | |
205 | for(Int_t i=0; i<GetNEtaSegments(); i++){ | |
206 | if(!fParamSpace[i]) continue; | |
207 | delete fParamSpace[i]; | |
208 | } | |
209 | delete[] fParamSpace; | |
210 | ||
211 | #ifndef VHDLSTATIC | |
212 | if(fNPhi0){ | |
213 | fNPhi0=0; | |
214 | delete[] fLUT2sinphi0; | |
215 | delete[] fLUT2cosphi0; | |
216 | delete[] fLUTphi0; | |
217 | } | |
218 | #endif | |
219 | } | |
220 | ||
221 | void AliL3HoughTransformerVhdl::CreateHistograms(Int_t nxbin,Double_t pt_min,Int_t nybin,Double_t phimin,Double_t phimax) | |
222 | { | |
223 | //Create the histograms (parameter space). | |
224 | //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis). | |
225 | //The arguments give the range and binning; | |
226 | //nxbin = #bins in kappa | |
227 | //nybin = #bins in phi0 | |
228 | //pt_min = mimium Pt of track (corresponding to maximum kappa) | |
229 | //phi_min = mimimum phi0 (degrees) | |
230 | //phi_max = maximum phi0 (degrees) | |
231 | ||
232 | AliL3FFloat x = AliL3Transform::GetBFieldValue()/pt_min; | |
233 | AliL3FFloat torad = AliL3Transform::Pi()/180; | |
234 | AliL3FFloat phimin_=phimin*torad; | |
235 | AliL3FFloat phimax_=phimax*torad; | |
236 | ||
237 | CreateHistograms(nxbin,-x,x,nybin,phimin_,phimax_); | |
238 | } | |
239 | ||
240 | void AliL3HoughTransformerVhdl::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax, | |
241 | Int_t nybin,Double_t ymin,Double_t ymax) | |
242 | { | |
243 | ||
244 | AliL3FFloat xminf=xmin; | |
245 | AliL3FFloat xmaxf=xmax; | |
246 | AliL3FFloat yminf=ymin; | |
247 | AliL3FFloat ymaxf=ymax; | |
248 | /* | |
249 | cout << xminf << endl; | |
250 | cout << xmaxf << " " << ((xmaxf-xminf)/nxbin) << endl; | |
251 | cout << yminf << endl; | |
252 | cout << ymaxf << " " << ((ymaxf-yminf)/nybin) << endl; | |
253 | */ | |
254 | ||
255 | fParamSpace = new AliL3Histogram*[GetNEtaSegments()]; | |
256 | Char_t histname[256]; | |
257 | for(Int_t i=0; i<GetNEtaSegments(); i++) | |
258 | { | |
259 | sprintf(histname,"paramspace_vhdl_%d",i); | |
260 | fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xminf,xmaxf,nybin,yminf,ymaxf); | |
261 | } | |
262 | ||
263 | //create lookup table for sin and cos | |
264 | fNPhi0=nybin+1; | |
265 | #ifndef VHDLSTATIC | |
266 | fLUTphi0=new AliL3FFloat[fNPhi0]; | |
267 | fLUT2sinphi0=new AliL3FFloat[fNPhi0]; | |
268 | fLUT2cosphi0=new AliL3FFloat[fNPhi0]; | |
269 | #endif | |
270 | AliL3FFloat diff=(ymax-ymin)/nybin; | |
271 | AliL3FFloat phi0=ymin-0.5*diff; | |
272 | for(Int_t i=0; i<fNPhi0; i++){ | |
273 | phi0+=diff; | |
274 | fLUTphi0[i]=phi0; | |
275 | fLUT2sinphi0[i]=Float_t(2*sin(phi0)); | |
276 | fLUT2cosphi0[i]=Float_t(2*cos(phi0)); | |
277 | //VESTBO: uncomment to see values (and compare with Print function) | |
278 | //cout << i << ": " << fLUTphi0[i] << " " << fLUT2sinphi0[i] << " " << fLUT2cosphi0[i] << endl; | |
279 | } | |
280 | } | |
281 | ||
282 | void AliL3HoughTransformerVhdl::Reset() | |
283 | { | |
284 | //Reset all the histograms | |
285 | ||
286 | if(!fParamSpace) | |
287 | { | |
288 | LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::Reset","Histograms") | |
289 | <<"No histograms to reset"<<ENDLOG; | |
290 | return; | |
291 | } | |
292 | ||
293 | for(Int_t i=0; i<GetNEtaSegments(); i++) | |
294 | fParamSpace[i]->Reset(); | |
295 | } | |
296 | ||
297 | inline AliL3Histogram *AliL3HoughTransformerVhdl::GetHistogram(Int_t eta_index) | |
298 | { | |
299 | if(!fParamSpace || eta_index >= GetNEtaSegments() || eta_index < 0) return 0; | |
300 | if(!fParamSpace[eta_index]) return 0; | |
301 | return fParamSpace[eta_index]; | |
302 | } | |
303 | ||
304 | inline Int_t AliL3HoughTransformerVhdl::FindIndex(Double_t rz2) | |
305 | { | |
306 | Int_t index=0; | |
307 | while((index<fNEtas)&&(rz2<=fLUTEta[index])){ | |
308 | index++; | |
309 | //cout << index << ": " << rz2 << " " << fLUTEta[index] << endl; | |
310 | } | |
311 | return index; | |
312 | } | |
313 | ||
314 | Int_t AliL3HoughTransformerVhdl::GetEtaIndex(Double_t eta) | |
315 | { | |
316 | AliL3FFloat rz2=CalcRoverZ2(eta); | |
317 | return FindIndex(rz2); | |
318 | } | |
319 | ||
afd8fed4 | 320 | Double_t AliL3HoughTransformerVhdl::GetEta(Int_t eta_index,Int_t slice){ |
6173606e | 321 | if(eta_index >= fNEtas || eta_index < 0){ |
322 | LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::GetEta","Index") | |
323 | <<"Index out of range."<<ENDLOG; | |
324 | return 0.; | |
325 | } | |
326 | return (CalcEta(fLUTEta[eta_index])-0.5*fEtaSlice); | |
327 | } | |
328 | ||
329 | void AliL3HoughTransformerVhdl::TransformCircle() | |
330 | { | |
331 | //Transform the input data with a circle HT. | |
332 | //The function loops over all the data, and transforms each pixel with the equations: | |
333 | // | |
334 | //kappa = 1/x * ( y/x*2*cos(phi0) - 2*sin(phi0) ) | |
335 | ||
336 | AliL3DigitRowData *tempPt = GetDataPointer(); | |
337 | if(!tempPt) | |
338 | { | |
339 | LOG(AliL3Log::kError,"AliL3HoughTransformerVhdl::TransformCircle","Data") | |
340 | <<"No input data "<<ENDLOG; | |
341 | return; | |
342 | } | |
343 | ||
344 | AliL3FFloat x=0.,y=0.,z=0.,rz2=0.; | |
345 | //Loop over the padrows: | |
346 | for(Int_t i=fMinRow, row=0; i<=fMaxRow; i++, row++){ | |
347 | ||
348 | //Get the data on this padrow: | |
349 | AliL3DigitData *digPt = tempPt->fDigitData; | |
350 | if(i != (Int_t)tempPt->fRow){ | |
351 | LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Padrows") | |
352 | <<"Mismatching padrow numbering "<<i<<"!="<<(Int_t)tempPt->fRow<<ENDLOG; | |
353 | continue; | |
354 | } | |
355 | ||
356 | //Loop over the data on this padrow: | |
357 | for(UInt_t j=0; j<tempPt->fNDigit; j++){ | |
358 | Int_t charge = digPt[j].fCharge; | |
359 | if((Int_t)charge <= GetLowerThreshold()) continue; | |
360 | ||
361 | Int_t pad = digPt[j].fPad; | |
362 | Int_t time = digPt[j].fTime; | |
363 | ||
364 | x=CalcX(row); | |
365 | y=CalcY(pad,row); | |
366 | z=CalcZ(time); | |
367 | ||
368 | //find eta slice | |
369 | rz2=1+(x*x+y*y)/z/z; | |
370 | Int_t eta_index = FindIndex(rz2); | |
371 | if(eta_index < 0 || eta_index >= GetNEtaSegments()){ | |
372 | //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"No histograms corresponding to eta index value of "<<eta_index<<"."<<ENDLOG; | |
373 | continue; | |
374 | } | |
375 | //Get the correct histogrampointer: | |
376 | AliL3Histogram *hist = fParamSpace[eta_index]; | |
377 | if(!hist){ | |
378 | //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"Error getting histogram in index "<<eta_index<<"."<<ENDLOG; | |
379 | continue; | |
380 | } | |
381 | ||
382 | //Fill the histogram along the phirange | |
383 | AliL3FFloat kappa,ydx=y/x; | |
384 | for(Int_t b=0; b<fNPhi0; b++){ | |
385 | kappa=ydx*fLUT2cosphi0[b]-fLUT2sinphi0[b]; | |
386 | kappa/=x; | |
387 | hist->Fill(kappa,fLUTphi0[b],charge); | |
388 | //cout << kappa << " " << fLUTphi0[b] << " " << charge << endl; | |
389 | } | |
390 | ||
391 | } | |
392 | //Move the data pointer to the next padrow: | |
393 | AliL3MemHandler::UpdateRowPointer(tempPt); | |
394 | } | |
395 | } | |
396 | ||
397 | void AliL3HoughTransformerVhdl::Print() | |
398 | { | |
399 | cout << "fSlice: " << GetSlice() << endl; | |
400 | cout << "fPatch: " << GetPatch() << endl; | |
401 | cout << "fSector: " << fSector << endl; | |
402 | cout << "fSectorRow: " << fSectorRow << endl; | |
403 | cout << "fMinRow: " << fMinRow << endl; | |
404 | cout << "fMaxRow: " << fMaxRow << endl; | |
405 | cout << "fNRows: " << fNRows << endl; | |
406 | cout << "fNEtas: " << fNEtas << endl; | |
407 | cout << "fNPhi0: " << fNPhi0 << endl; | |
408 | cout << "fZSign: " << fZSign << endl; | |
409 | cout << "fZLengthPlusOff: " << fZLengthPlusOff << endl; | |
410 | cout << "fPadPitch: " << fPadPitch << endl; | |
411 | cout << "fTimeWidth: " << fTimeWidth << endl; | |
412 | if(!fNRows) return; | |
413 | cout << "fLUTX " << fNRows << endl; | |
414 | for(Int_t i=0;i<fNRows;i++) cout << "fLUTX[" << i << "]=" << (Float_t)fLUTX[i] << endl; | |
415 | cout << "fLUTY " << fNRows << endl; | |
416 | for(Int_t i=0;i<fNRows;i++) cout << "fLUTY[" << i << "]=" << fLUTY[i] << endl; | |
417 | if(!fNEtas) return; | |
418 | cout << "fLUTEta " << fNEtas << endl; | |
419 | for(Int_t i=0;i<fNEtas;i++) cout << "fLUTEta[" << i << "]=" << fLUTEta[i] << endl; | |
420 | if(!fNPhi0) return; | |
421 | cout << "fLUTphi0 " << fNPhi0 << endl; | |
422 | for(Int_t i=0;i<fNPhi0;i++) cout << "fLUTPhi0[" << i << "]=" << fLUTphi0[i] << endl; | |
423 | cout << "fLUT2sinphi0 " << fNPhi0 << endl; | |
424 | for(Int_t i=0;i<fNPhi0;i++) cout << "fLUT2sinphi0[" << i << "]=" << fLUT2sinphi0[i] << endl; | |
425 | cout << "fLUT2cosphi0 " << fNPhi0 << endl; | |
426 | for(Int_t i=0;i<fNPhi0;i++) cout << "fLUT2cosphi0[" << i << "]=" << fLUT2cosphi0[i] << endl; | |
427 | } | |
428 | ||
429 | //end vhdl version | |
430 | #else | |
431 | //standard version | |
432 | ||
433 | AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl() | |
434 | { | |
435 | fParamSpace=0; | |
436 | } | |
437 | ||
438 | AliL3HoughTransformerVhdl::AliL3HoughTransformerVhdl(Int_t slice,Int_t patch,Int_t n_eta_segments) | |
439 | : AliL3HoughBaseTransformer(slice,patch,n_eta_segments) | |
440 | { | |
441 | fParamSpace=0; | |
b46b53c1 | 442 | } |
443 | ||
444 | AliL3HoughTransformerVhdl::~AliL3HoughTransformerVhdl() | |
445 | { | |
446 | DeleteHistograms(); | |
447 | } | |
448 | ||
449 | void AliL3HoughTransformerVhdl::DeleteHistograms() | |
450 | { | |
451 | if(!fParamSpace) | |
452 | return; | |
453 | for(Int_t i=0; i<GetNEtaSegments(); i++) | |
454 | { | |
455 | if(!fParamSpace[i]) continue; | |
456 | delete fParamSpace[i]; | |
457 | } | |
6173606e | 458 | delete[] fParamSpace; |
b46b53c1 | 459 | } |
460 | ||
6173606e | 461 | void AliL3HoughTransformerVhdl::CreateHistograms(Int_t nxbin,Double_t pt_min,Int_t nybin,Double_t phimin,Double_t phimax) |
b46b53c1 | 462 | { |
463 | //Create the histograms (parameter space). | |
464 | //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis). | |
465 | //The arguments give the range and binning; | |
466 | //nxbin = #bins in kappa | |
467 | //nybin = #bins in phi0 | |
468 | //pt_min = mimium Pt of track (corresponding to maximum kappa) | |
469 | //phi_min = mimimum phi0 (degrees) | |
470 | //phi_max = maximum phi0 (degrees) | |
471 | ||
6173606e | 472 | Double_t x = AliL3Transform::GetBFieldValue()/pt_min; |
b46b53c1 | 473 | Double_t torad = AliL3Transform::Pi()/180; |
6173606e | 474 | |
b46b53c1 | 475 | CreateHistograms(nxbin,-1.*x,x,nybin,phimin*torad,phimax*torad); |
476 | } | |
477 | ||
478 | void AliL3HoughTransformerVhdl::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax, | |
6173606e | 479 | Int_t nybin,Double_t ymin,Double_t ymax) |
b46b53c1 | 480 | { |
6173606e | 481 | |
482 | AliL3FFloat xminf(xmin); | |
483 | AliL3FFloat xmaxf(xmax); | |
484 | AliL3FFloat yminf(ymin); | |
485 | AliL3FFloat ymaxf(ymax); | |
486 | /* | |
487 | cout << xminf << endl; | |
488 | cout << xmaxf << " " << ((xmaxf-xminf)/nxbin) << endl; | |
489 | cout << yminf << endl; | |
490 | cout << ymaxf << " " << ((ymaxf-yminf)/nybin) << endl; | |
491 | */ | |
b46b53c1 | 492 | |
493 | fParamSpace = new AliL3Histogram*[GetNEtaSegments()]; | |
494 | ||
495 | Char_t histname[256]; | |
496 | for(Int_t i=0; i<GetNEtaSegments(); i++) | |
497 | { | |
6173606e | 498 | sprintf(histname,"paramspace_vhdl_%d",i); |
499 | fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xminf,xmaxf,nybin,yminf,ymaxf); | |
b46b53c1 | 500 | } |
501 | } | |
502 | ||
503 | void AliL3HoughTransformerVhdl::Reset() | |
504 | { | |
505 | //Reset all the histograms | |
506 | ||
507 | if(!fParamSpace) | |
508 | { | |
509 | LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::Reset","Histograms") | |
510 | <<"No histograms to reset"<<ENDLOG; | |
511 | return; | |
512 | } | |
513 | ||
514 | for(Int_t i=0; i<GetNEtaSegments(); i++) | |
515 | fParamSpace[i]->Reset(); | |
516 | } | |
517 | ||
6173606e | 518 | inline AliL3Histogram *AliL3HoughTransformerVhdl::GetHistogram(Int_t eta_index) |
519 | { | |
520 | if(!fParamSpace || eta_index >= GetNEtaSegments() || eta_index < 0) return 0; | |
521 | if(!fParamSpace[eta_index]) return 0; | |
522 | return fParamSpace[eta_index]; | |
523 | } | |
b46b53c1 | 524 | |
525 | Int_t AliL3HoughTransformerVhdl::GetEtaIndex(Double_t eta) | |
526 | { | |
527 | //Return the histogram index of the corresponding eta. | |
6173606e | 528 | AliL3FFloat etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments(); |
529 | AliL3FFloat index = (eta-GetEtaMin())/etaslice; | |
b46b53c1 | 530 | |
6173606e | 531 | //if((Int_t)index==0) cout << index << " " << (Int_t) index << endl; |
b46b53c1 | 532 | return (Int_t)index; |
533 | } | |
534 | ||
6173606e | 535 | Double_t AliL3HoughTransformerVhdl::GetEta(Int_t eta_index) |
536 | { | |
537 | if(eta_index >= GetNEtaSegments() || eta_index < 0){ | |
538 | return 0; | |
539 | } | |
540 | Double_t eta_slice = (GetEtaMax()-GetEtaMin())/GetNEtaSegments(); | |
541 | Double_t eta=(Double_t)((eta_index+0.5)*eta_slice); | |
542 | if(GetSlice()>17) eta*=-1; | |
543 | return eta; | |
544 | } | |
545 | ||
b46b53c1 | 546 | void AliL3HoughTransformerVhdl::TransformCircle() |
547 | { | |
548 | //Transform the input data with a circle HT. | |
549 | //The function loops over all the data, and transforms each pixel with the equations: | |
550 | // | |
551 | //kappa = 2/R*sin(phi - phi0) | |
552 | // | |
553 | //where R = sqrt(x*x +y*y), and phi = arctan(y/x) | |
554 | // | |
555 | //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find | |
556 | //which histogram in which the pixel should be transformed, the eta-value is calcluated | |
557 | //and the proper histogram index is found by GetEtaIndex(eta). | |
558 | ||
559 | ||
560 | AliL3DigitRowData *tempPt = GetDataPointer(); | |
561 | if(!tempPt) | |
562 | { | |
563 | LOG(AliL3Log::kError,"AliL3HoughTransformerVhdl::TransformCircle","Data") | |
564 | <<"No input data "<<ENDLOG; | |
565 | return; | |
566 | } | |
567 | ||
568 | //Loop over the padrows: | |
569 | for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++) | |
570 | { | |
571 | //Get the data on this padrow: | |
572 | AliL3DigitData *digPt = tempPt->fDigitData; | |
573 | if(i != (Int_t)tempPt->fRow) | |
574 | { | |
6173606e | 575 | LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Padrows") |
576 | <<"Mismatching padrow numbering."<<ENDLOG; | |
b46b53c1 | 577 | continue; |
578 | } | |
579 | ||
6173606e | 580 | |
b46b53c1 | 581 | //Loop over the data on this padrow: |
582 | for(UInt_t j=0; j<tempPt->fNDigit; j++) | |
583 | { | |
584 | UShort_t charge = digPt[j].fCharge; | |
6173606e | 585 | if((Int_t)charge <= GetLowerThreshold()) continue; |
586 | ||
b46b53c1 | 587 | UChar_t pad = digPt[j].fPad; |
588 | UShort_t time = digPt[j].fTime; | |
6173606e | 589 | |
b46b53c1 | 590 | Int_t sector,row; |
591 | Float_t xyz[3]; | |
6173606e | 592 | AliL3FFloat fxyz[3]; |
593 | ||
b46b53c1 | 594 | //Transform data to local cartesian coordinates: |
595 | AliL3Transform::Slice2Sector(GetSlice(),i,sector,row); | |
596 | AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time); | |
6173606e | 597 | |
598 | //trunc to fixed format. | |
599 | for(int i=0;i<3;i++) { | |
600 | fxyz[i]=xyz[i]; | |
601 | //cout << fxyz[i]; | |
602 | xyz[i]=fxyz[i]; | |
603 | } | |
604 | //cout << endl; | |
605 | ||
b46b53c1 | 606 | //Calculate the eta: |
6173606e | 607 | AliL3FFloat eta = AliL3Transform::GetEta(xyz); |
b46b53c1 | 608 | |
609 | //Get the corresponding index, which determines which histogram to fill: | |
610 | Int_t eta_index = GetEtaIndex(eta); | |
6173606e | 611 | if(eta_index < 0 || eta_index >= GetNEtaSegments()){ |
612 | //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"No histograms corresponding to eta index value of "<<eta_index<<"."<<ENDLOG; | |
b46b53c1 | 613 | continue; |
6173606e | 614 | } |
b46b53c1 | 615 | //Get the correct histogrampointer: |
616 | AliL3Histogram *hist = fParamSpace[eta_index]; | |
617 | if(!hist) | |
618 | { | |
6173606e | 619 | //LOG(AliL3Log::kWarning,"AliL3HoughTransformerVhdl::TransformCircle","Histograms")<<"Error getting histogram in index "<<eta_index<<"."<<ENDLOG; |
b46b53c1 | 620 | continue; |
621 | } | |
622 | ||
623 | //Do the transformation: | |
6173606e | 624 | AliL3FFloat R = sqrt(fxyz[0]*fxyz[0] + fxyz[1]*fxyz[1]); |
625 | AliL3FFloat phi = AliL3Transform::GetPhi(xyz); | |
b46b53c1 | 626 | |
627 | //Fill the histogram along the phirange | |
628 | for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++) | |
629 | { | |
6173606e | 630 | AliL3FFloat phi0 = hist->GetBinCenterY(b); |
631 | AliL3FFloat kappa = 2*sin(phi - phi0)/R; | |
632 | //hist->Fill(kappa.GetExactVal(),phi0.GetExactVal(),charge); | |
b46b53c1 | 633 | hist->Fill(kappa,phi0,charge); |
634 | } | |
635 | } | |
636 | ||
637 | //Move the data pointer to the next padrow: | |
638 | AliL3MemHandler::UpdateRowPointer(tempPt); | |
639 | } | |
640 | } | |
641 | ||
6173606e | 642 | #endif |