3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ASV
6 #include "AliL3MemHandler.h"
7 #include "AliL3Logging.h"
8 #include "AliL3HoughTransformer.h"
9 #include "AliL3Transform.h"
10 #include "AliL3DigitData.h"
11 #include "AliL3Histogram.h"
13 //_____________________________________________________________
14 // AliL3HoughTransformer
16 // Hough transformation class
19 ClassImp(AliL3HoughTransformer)
21 AliL3HoughTransformer::AliL3HoughTransformer()
30 AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Int_t n_eta_segments) : AliL3HoughBaseTransformer(slice,patch,n_eta_segments)
39 AliL3HoughTransformer::~AliL3HoughTransformer()
45 for(Int_t i=0; i<GetNEtaSegments(); i++)
47 if(!fTrackID[i]) continue;
55 //void AliL3HoughTransformer::Init(Int_t slice=0,Int_t patch=0,Int_t n_eta_segments=100){}
57 void AliL3HoughTransformer::DeleteHistograms()
61 for(Int_t i=0; i<GetNEtaSegments(); i++)
63 if(!fParamSpace[i]) continue;
64 delete fParamSpace[i];
66 delete [] fParamSpace;
69 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t pt_min,
70 Int_t nybin,Double_t phimin,Double_t phimax)
72 //Create the histograms (parameter space).
73 //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis).
74 //The arguments give the range and binning;
75 //nxbin = #bins in kappa
76 //nybin = #bins in phi0
77 //pt_min = mimium Pt of track (corresponding to maximum kappa)
78 //phi_min = mimimum phi0 (degrees)
79 //phi_max = maximum phi0 (degrees)
81 Double_t x = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/pt_min;
82 Double_t torad = AliL3Transform::Pi()/180;
83 CreateHistograms(nxbin,-1.*x,x,nybin,phimin*torad,phimax*torad);
86 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
87 Int_t nybin,Double_t ymin,Double_t ymax)
90 fParamSpace = new AliL3Histogram*[GetNEtaSegments()];
93 for(Int_t i=0; i<GetNEtaSegments(); i++)
95 sprintf(histname,"paramspace_%d",i);
96 fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
100 Int_t ncells = (nxbin+2)*(nybin+2);
101 cout<<"Allocating "<<GetNEtaSegments()*ncells*sizeof(TrackIndex)<<" bytes to fTrackID"<<endl;
102 fTrackID = new TrackIndex*[GetNEtaSegments()];
103 for(Int_t i=0; i<GetNEtaSegments(); i++)
104 fTrackID[i] = new TrackIndex[ncells];
108 void AliL3HoughTransformer::Reset()
110 //Reset all the histograms
114 LOG(AliL3Log::kWarning,"AliL3HoughTransformer::Reset","Histograms")
115 <<"No histograms to reset"<<ENDLOG;
119 for(Int_t i=0; i<GetNEtaSegments(); i++)
120 fParamSpace[i]->Reset();
122 AliL3Histogram *hist = fParamSpace[0];
123 Int_t ncells = (hist->GetNbinsX()+2)*(hist->GetNbinsY()+2);
124 for(Int_t i=0; i<GetNEtaSegments(); i++)
125 memset(fTrackID[i],0,ncells*sizeof(TrackIndex));
129 Int_t AliL3HoughTransformer::GetEtaIndex(Double_t eta)
131 //Return the histogram index of the corresponding eta.
133 Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
134 Double_t index = (eta-GetEtaMin())/etaslice;
138 inline AliL3Histogram *AliL3HoughTransformer::GetHistogram(Int_t eta_index)
140 if(!fParamSpace || eta_index >= GetNEtaSegments() || eta_index < 0)
142 if(!fParamSpace[eta_index])
144 return fParamSpace[eta_index];
147 Double_t AliL3HoughTransformer::GetEta(Int_t eta_index,Int_t slice)
149 Double_t eta_slice = (GetEtaMax()-GetEtaMin())/GetNEtaSegments();
150 Double_t eta=(Double_t)((eta_index+0.5)*eta_slice);
151 if(slice>17) eta*=-1;
155 void AliL3HoughTransformer::TransformCircle()
157 //Transform the input data with a circle HT.
158 //The function loops over all the data, and transforms each pixel with the equations:
160 //kappa = 2/R*sin(phi - phi0)
162 //where R = sqrt(x*x +y*y), and phi = arctan(y/x)
164 //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find
165 //which histogram in which the pixel should be transformed, the eta-value is calcluated
166 //and the proper histogram index is found by GetEtaIndex(eta).
169 AliL3DigitRowData *tempPt = GetDataPointer();
172 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircle","Data")
173 <<"No input data "<<ENDLOG;
177 //Loop over the padrows:
178 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
180 //Get the data on this padrow:
181 AliL3DigitData *digPt = tempPt->fDigitData;
182 if(i != (Int_t)tempPt->fRow)
184 cerr<<"AliL3HoughTransform::TransformCircle : Mismatching padrow numbering "<<i<<" "<<(Int_t)tempPt->fRow<<endl;
188 //Loop over the data on this padrow:
189 for(UInt_t j=0; j<tempPt->fNDigit; j++)
191 UShort_t charge = digPt[j].fCharge;
192 UChar_t pad = digPt[j].fPad;
193 UShort_t time = digPt[j].fTime;
194 if((Int_t)charge <= GetLowerThreshold() || (Int_t)charge > GetUpperThreshold())
199 //Transform data to local cartesian coordinates:
200 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
201 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
204 Double_t eta = AliL3Transform::GetEta(xyz);
206 //Get the corresponding index, which determines which histogram to fill:
207 Int_t eta_index = GetEtaIndex(eta);
208 if(eta_index < 0 || eta_index >= GetNEtaSegments())
211 //Get the correct histogrampointer:
212 AliL3Histogram *hist = fParamSpace[eta_index];
215 printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
219 //Do the transformation:
220 Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
221 Float_t phi = AliL3Transform::GetPhi(xyz);
223 //Fill the histogram along the phirange
224 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
226 Float_t phi0 = hist->GetBinCenterY(b);
227 Float_t kappa = 2*sin(phi - phi0)/R;
228 hist->Fill(kappa,phi0,charge);
230 Int_t bin = hist->FindBin(kappa,phi0);
231 for(Int_t t=0; t<3; t++)
233 Int_t label = digPt[j].fTrackID[t];
236 for(c=0; c<MaxTrack; c++)
237 if(fTrackID[eta_index][bin].fLabel[c] == label || fTrackID[eta_index][bin].fNHits[c] == 0)
239 if(c == MaxTrack-1) cerr<<"AliL3HoughTransformer::TransformCircle : Array reached maximum!! "<<c<<endl;
240 fTrackID[eta_index][bin].fLabel[c] = label;
241 fTrackID[eta_index][bin].fNHits[c]++;
247 //Move the data pointer to the next padrow:
248 AliL3MemHandler::UpdateRowPointer(tempPt);
252 void AliL3HoughTransformer::TransformCircleC(Int_t row_range)
254 //Circle transform, using combinations of every 2 points lying
255 //on different padrows and within the same etaslice.
257 AliL3DigitRowData *tempPt = GetDataPointer();
259 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircleC","Data")
260 <<"No input data "<<ENDLOG;
263 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
265 counter += tempPt->fNDigit;
266 AliL3MemHandler::UpdateRowPointer(tempPt);
278 Digit *digits = new Digit[counter];
279 cout<<"Allocating "<<counter*sizeof(Digit)<<" bytes to digitsarray"<<endl;
281 Int_t total_digits=counter;
282 Int_t sector,row,tot_charge,pad,time,charge;
283 Double_t r1,r2,phi1,phi2,eta,kappa,phi_0;
287 tempPt = GetDataPointer();
289 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
291 AliL3DigitData *digPt = tempPt->fDigitData;
292 for(UInt_t di=0; di<tempPt->fNDigit; di++)
294 charge = digPt[di].fCharge;
295 pad = digPt[di].fPad;
296 time = digPt[di].fTime;
297 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
298 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
299 eta = AliL3Transform::GetEta(xyz);
300 digits[counter].row = i;
301 digits[counter].r = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
302 digits[counter].phi = atan2(xyz[1],xyz[0]);
303 digits[counter].eta_index = GetEtaIndex(eta);
304 digits[counter].charge = charge;
305 digits[counter].trackID[0] = digPt[di].fTrackID[0];
306 digits[counter].trackID[1] = digPt[di].fTrackID[1];
307 digits[counter].trackID[2] = digPt[di].fTrackID[2];
310 AliL3MemHandler::UpdateRowPointer(tempPt);
313 for(Int_t i=0; i<total_digits; i++)
315 if(digits[i].eta_index < 0 || digits[i].eta_index >= GetNEtaSegments()) continue;
316 Int_t ind = digits[i].eta_index;
318 for(Int_t j=i+1; j<total_digits; j++)
320 if(digits[i].row == digits[j].row) continue;
321 if(digits[i].eta_index != digits[j].eta_index) continue;
322 if(digits[i].row + row_range < digits[j].row) break;
324 //Get the correct histogrampointer:
325 AliL3Histogram *hist = fParamSpace[ind];
328 printf("AliL3HoughTransformer::TransformCircleC() : No histogram at index %d\n",ind);
333 phi1 = digits[i].phi;
335 phi2 = digits[j].phi;
336 phi_0 = atan( (r2*sin(phi1)-r1*sin(phi2))/(r2*cos(phi1)-r1*cos(phi2)) );
337 kappa = 2*sin(phi2-phi_0)/r2;
338 tot_charge = digits[i].charge + digits[j].charge;
339 hist->Fill(kappa,phi_0,tot_charge);
341 Int_t bin = hist->FindBin(kappa,phi_0);
342 for(Int_t l=0; l<3; l++)
344 for(Int_t m=0; m<3; m++)
346 if(digits[i].trackID[l] == digits[j].trackID[m])
348 Int_t label = digits[i].trackID[l];
349 if(label < 0) continue;
351 for(c=0; c<MaxTrack; c++)
352 if(fTrackID[ind][bin].fLabel[c] == label || fTrackID[ind][bin].fNHits[c] == 0)
354 if(c == MaxTrack-1) cerr<<"AliL3HoughTransformer::TransformCircleC : Array reached maximum!! "<<c<<endl;
355 fTrackID[ind][bin].fLabel[c] = label;
356 fTrackID[ind][bin].fNHits[c]++;
366 void AliL3HoughTransformer::TransformLine()
368 //Do a line transform on the data.
371 AliL3DigitRowData *tempPt = GetDataPointer();
374 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformLine","Data")
375 <<"No input data "<<ENDLOG;
379 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
381 AliL3DigitData *digPt = tempPt->fDigitData;
382 if(i != (Int_t)tempPt->fRow)
384 printf("AliL3HoughTransform::TransformLine : Mismatching padrow numbering\n");
387 for(UInt_t j=0; j<tempPt->fNDigit; j++)
389 UShort_t charge = digPt[j].fCharge;
390 UChar_t pad = digPt[j].fPad;
391 UShort_t time = digPt[j].fTime;
392 if(charge < GetLowerThreshold())
396 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
397 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
398 Float_t eta = AliL3Transform::GetEta(xyz);
399 Int_t eta_index = GetEtaIndex(eta);//(Int_t)(eta/etaslice);
400 if(eta_index < 0 || eta_index >= GetNEtaSegments())
403 //Get the correct histogram:
404 AliL3Histogram *hist = fParamSpace[eta_index];
407 printf("AliL3HoughTransformer::TransformLine : Error getting histogram in index %d\n",eta_index);
410 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
412 Double_t theta = hist->GetBinCenterX(xbin);
413 Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
414 hist->Fill(theta,rho,charge);
417 AliL3MemHandler::UpdateRowPointer(tempPt);
422 Int_t AliL3HoughTransformer::GetTrackID(Int_t eta_index,Double_t kappa,Double_t psi)
426 if(eta_index < 0 || eta_index > GetNEtaSegments())
428 cerr<<"AliL3HoughTransformer::GetTrackID : Wrong etaindex "<<eta_index<<endl;
431 AliL3Histogram *hist = fParamSpace[eta_index];
432 Int_t bin = hist->FindBin(kappa,psi);
435 for(UInt_t i=0; i<MaxTrack; i++)
437 Int_t nhits=fTrackID[eta_index][bin].fNHits[i];
438 if(nhits == 0) break;
442 label = fTrackID[eta_index][bin].fLabel[i];
447 cout<<"AliL3HoughTransformer::GetTrackID : Compile with do_mc flag!"<<endl;