3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ASV
6 #include "AliL3MemHandler.h"
7 #include "AliL3Logging.h"
8 #include "AliL3HoughTransformer.h"
10 #include "AliL3Transform.h"
11 #include "AliL3DigitData.h"
12 #include "AliL3Histogram.h"
14 //_____________________________________________________________
15 // AliL3HoughTransformer
17 // Hough transformation class
20 ClassImp(AliL3HoughTransformer)
22 AliL3HoughTransformer::AliL3HoughTransformer()
28 AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Int_t n_eta_segments)
34 fNEtaSegments = n_eta_segments;
36 fEtaMax = fSlice < 18 ? 0.9 : -0.9;
37 fTransform = new AliL3Transform();
43 AliL3HoughTransformer::~AliL3HoughTransformer()
50 void AliL3HoughTransformer::DeleteHistograms()
54 for(Int_t i=0; i<fNEtaSegments; i++)
56 if(!fParamSpace[i]) continue;
57 delete fParamSpace[i];
59 delete [] fParamSpace;
62 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t pt_min,
63 Int_t nybin,Double_t phimin,Double_t phimax)
65 //Create the histograms (parameter space).
66 //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis).
67 //The arguments give the range and binning;
68 //nxbin = #bins in kappa
69 //nybin = #bins in phi0
70 //pt_min = mimium Pt of track (corresponding to maximum kappa)
71 //phi_min = mimimum phi0 (degrees)
72 //phi_max = maximum phi0 (degrees)
74 Double_t bfact = 0.0029980;
75 Double_t bfield = 0.2;
76 Double_t x = bfact*bfield/pt_min;
77 CreateHistograms(nxbin,-1.*x,x,nybin,phimin*ToRad,phimax*ToRad);
80 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
81 Int_t nybin,Double_t ymin,Double_t ymax)
84 fParamSpace = new AliL3Histogram*[fNEtaSegments];
87 for(Int_t i=0; i<fNEtaSegments; i++)
89 sprintf(histname,"paramspace_%d",i);
90 fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
94 void AliL3HoughTransformer::Reset()
96 //Reset all the histograms
100 LOG(AliL3Log::kWarning,"AliL3HoughTransformer::Reset","Histograms")
101 <<"No histograms to reset"<<ENDLOG;
105 for(Int_t i=0; i<fNEtaSegments; i++)
106 fParamSpace[i]->Reset();
109 void AliL3HoughTransformer::SetInputData(UInt_t ndigits,AliL3DigitRowData *ptr)
111 //Give the pointer to the data.
113 fNDigitRowData = ndigits;
117 Int_t AliL3HoughTransformer::GetEtaIndex(Double_t eta)
119 //Return the histogram index of the corresponding eta.
121 Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
122 Double_t index = (eta-fEtaMin)/etaslice;
126 void AliL3HoughTransformer::TransformCircle()
128 //Transform the input data with a circle HT.
129 //The function loops over all the data, and transforms each pixel with the equations:
131 //kappa = 2/R*sin(phi - phi0)
133 //where R = sqrt(x*x +y*y), and phi = arctan(y/x)
135 //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find
136 //which histogram in which the pixel should be transformed, the eta-value is calcluated
137 //and the proper histogram index is found by GetEtaIndex(eta).
140 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
141 if(!tempPt || fNDigitRowData==0)
143 printf("\nAliL3HoughTransformer::TransformCircle : No input data!!!\n\n");
147 //Loop over the padrows:
148 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
150 //Get the data on this padrow:
151 AliL3DigitData *digPt = tempPt->fDigitData;
152 if(i != (Int_t)tempPt->fRow)
154 printf("AliL3HoughTransform::TransformCircle : Mismatching padrow numbering\n");
158 //Loop over the data on this padrow:
159 for(UInt_t j=0; j<tempPt->fNDigit; j++)
161 UShort_t charge = digPt[j].fCharge;
162 UChar_t pad = digPt[j].fPad;
163 UShort_t time = digPt[j].fTime;
164 if(charge <= fThreshold)
169 //Transform data to local cartesian coordinates:
170 fTransform->Slice2Sector(fSlice,i,sector,row);
171 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
174 Double_t eta = fTransform->GetEta(xyz);
176 //Get the corresponding index, which determines which histogram to fill:
177 Int_t eta_index = GetEtaIndex(eta);//(Int_t)((eta-fEtaMin)/etaslice);
178 if(eta_index < 0 || eta_index >= fNEtaSegments)
181 //Get the correct histogrampointer:
182 AliL3Histogram *hist = fParamSpace[eta_index];
185 printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
189 //Do the transformation:
190 Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
191 Float_t phi = fTransform->GetPhi(xyz);
193 //Fill the histogram along the phirange
194 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
196 Float_t phi0 = hist->GetBinCenterY(b);
197 Float_t kappa = 2*sin(phi - phi0)/R;
198 hist->Fill(kappa,phi0,charge);
202 //Move the data pointer to the next padrow:
203 AliL3MemHandler::UpdateRowPointer(tempPt);
207 void AliL3HoughTransformer::TransformCircleC(Int_t row_range)
209 //Circle transform, using combinations of every 2 points lying
210 //on different padrows and within the same etaslice.
212 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
214 printf("\nAliL3HoughTransformer::TransformCircleC() : Zero data pointer\n");
217 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
219 counter += tempPt->fNDigit;
220 AliL3MemHandler::UpdateRowPointer(tempPt);
231 Digit *digits = new Digit[counter];
232 cout<<"Allocating "<<counter*sizeof(Digit)<<" bytes to digitsarray"<<endl;
234 Int_t total_digits=counter;
235 Int_t sector,row,tot_charge,pad,time,charge;
236 Double_t r1,r2,phi1,phi2,eta,kappa,phi_0;
240 tempPt = (AliL3DigitRowData*)fDigitRowData;
242 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
244 AliL3DigitData *digPt = tempPt->fDigitData;
245 for(UInt_t di=0; di<tempPt->fNDigit; di++)
247 charge = digPt[di].fCharge;
248 pad = digPt[di].fPad;
249 time = digPt[di].fTime;
250 fTransform->Slice2Sector(fSlice,i,sector,row);
251 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
252 eta = fTransform->GetEta(xyz);
253 digits[counter].row = i;
254 digits[counter].r = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
255 digits[counter].phi = atan2(xyz[1],xyz[0]);
256 digits[counter].eta_index = GetEtaIndex(eta);
257 digits[counter].charge = charge;
260 AliL3MemHandler::UpdateRowPointer(tempPt);
263 for(Int_t i=0; i<total_digits; i++)
265 if(digits[i].eta_index < 0 || digits[i].eta_index >= fNEtaSegments) continue;
266 Int_t ind = digits[i].eta_index;
268 for(Int_t j=i+1; j<total_digits; j++)
270 if(digits[i].row == digits[j].row) continue;
271 if(digits[i].eta_index != digits[j].eta_index) continue;
272 if(digits[i].row + row_range < digits[j].row) break;
274 //Get the correct histogrampointer:
275 AliL3Histogram *hist = fParamSpace[ind];
278 printf("AliL3HoughTransformer::TransformCircleC() : No histogram at index %d\n",ind);
283 phi1 = digits[i].phi;
285 phi2 = digits[j].phi;
286 phi_0 = atan( (r2*sin(phi1)-r1*sin(phi2))/(r2*cos(phi1)-r1*cos(phi2)) );
287 kappa = 2*sin(phi2-phi_0)/r2;
288 tot_charge = digits[i].charge + digits[j].charge;
289 hist->Fill(kappa,phi_0,tot_charge);
295 void AliL3HoughTransformer::TransformLine()
297 //Do a line transform on the data.
300 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
301 if(!tempPt || fNDigitRowData==0)
303 printf("\nAliL3HoughTransformer::TransformLine : No input data!!!\n\n");
307 //Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
308 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
310 AliL3DigitData *digPt = tempPt->fDigitData;
311 if(i != (Int_t)tempPt->fRow)
313 printf("AliL3HoughTransform::TransformLine : Mismatching padrow numbering\n");
316 for(UInt_t j=0; j<tempPt->fNDigit; j++)
318 UShort_t charge = digPt[j].fCharge;
319 UChar_t pad = digPt[j].fPad;
320 UShort_t time = digPt[j].fTime;
321 if(charge < fThreshold)
325 fTransform->Slice2Sector(fSlice,i,sector,row);
326 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
327 Float_t eta = fTransform->GetEta(xyz);
328 Int_t eta_index = GetEtaIndex(eta);//(Int_t)(eta/etaslice);
329 if(eta_index < 0 || eta_index >= fNEtaSegments)
332 //Get the correct histogram:
333 AliL3Histogram *hist = fParamSpace[eta_index];
336 printf("AliL3HoughTransformer::TransformLine : Error getting histogram in index %d\n",eta_index);
339 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
341 Double_t theta = hist->GetBinCenterX(xbin);
342 Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
343 hist->Fill(theta,rho,charge);
346 AliL3MemHandler::UpdateRowPointer(tempPt);