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()
27 AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Int_t n_eta_segments) : AliL3HoughBaseTransformer(slice,patch,n_eta_segments)
33 AliL3HoughTransformer::~AliL3HoughTransformer()
38 void AliL3HoughTransformer::DeleteHistograms()
42 for(Int_t i=0; i<GetNEtaSegments(); i++)
44 if(!fParamSpace[i]) continue;
45 delete fParamSpace[i];
47 delete [] fParamSpace;
50 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t pt_min,
51 Int_t nybin,Double_t phimin,Double_t phimax)
53 //Create the histograms (parameter space).
54 //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis).
55 //The arguments give the range and binning;
56 //nxbin = #bins in kappa
57 //nybin = #bins in phi0
58 //pt_min = mimium Pt of track (corresponding to maximum kappa)
59 //phi_min = mimimum phi0 (degrees)
60 //phi_max = maximum phi0 (degrees)
62 Double_t bfact = 0.0029980;
63 Double_t bfield = 0.2;
64 Double_t x = bfact*bfield/pt_min;
65 Double_t torad = AliL3Transform::Pi()/180;
66 CreateHistograms(nxbin,-1.*x,x,nybin,phimin*torad,phimax*torad);
69 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
70 Int_t nybin,Double_t ymin,Double_t ymax)
73 fParamSpace = new AliL3Histogram*[GetNEtaSegments()];
76 for(Int_t i=0; i<GetNEtaSegments(); i++)
78 sprintf(histname,"paramspace_%d",i);
79 fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
83 void AliL3HoughTransformer::Reset()
85 //Reset all the histograms
89 LOG(AliL3Log::kWarning,"AliL3HoughTransformer::Reset","Histograms")
90 <<"No histograms to reset"<<ENDLOG;
94 for(Int_t i=0; i<GetNEtaSegments(); i++)
95 fParamSpace[i]->Reset();
99 Int_t AliL3HoughTransformer::GetEtaIndex(Double_t eta)
101 //Return the histogram index of the corresponding eta.
103 Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
104 Double_t index = (eta-GetEtaMin())/etaslice;
108 void AliL3HoughTransformer::TransformCircle()
110 //Transform the input data with a circle HT.
111 //The function loops over all the data, and transforms each pixel with the equations:
113 //kappa = 2/R*sin(phi - phi0)
115 //where R = sqrt(x*x +y*y), and phi = arctan(y/x)
117 //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find
118 //which histogram in which the pixel should be transformed, the eta-value is calcluated
119 //and the proper histogram index is found by GetEtaIndex(eta).
122 AliL3DigitRowData *tempPt = GetDataPointer();
125 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircle","Data")
126 <<"No input data "<<ENDLOG;
130 //Loop over the padrows:
131 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
133 //Get the data on this padrow:
134 AliL3DigitData *digPt = tempPt->fDigitData;
135 if(i != (Int_t)tempPt->fRow)
137 printf("AliL3HoughTransform::TransformCircle : Mismatching padrow numbering\n");
141 //Loop over the data on this padrow:
142 for(UInt_t j=0; j<tempPt->fNDigit; j++)
144 UShort_t charge = digPt[j].fCharge;
145 UChar_t pad = digPt[j].fPad;
146 UShort_t time = digPt[j].fTime;
147 if(charge <= GetThreshold())
152 //Transform data to local cartesian coordinates:
153 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
154 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
157 Double_t eta = AliL3Transform::GetEta(xyz);
159 //Get the corresponding index, which determines which histogram to fill:
160 Int_t eta_index = GetEtaIndex(eta);
161 if(eta_index < 0 || eta_index >= GetNEtaSegments())
164 //Get the correct histogrampointer:
165 AliL3Histogram *hist = fParamSpace[eta_index];
168 printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
172 //Do the transformation:
173 Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
174 Float_t phi = AliL3Transform::GetPhi(xyz);
176 //Fill the histogram along the phirange
177 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
179 Float_t phi0 = hist->GetBinCenterY(b);
180 Float_t kappa = 2*sin(phi - phi0)/R;
181 hist->Fill(kappa,phi0,charge);
185 //Move the data pointer to the next padrow:
186 AliL3MemHandler::UpdateRowPointer(tempPt);
190 void AliL3HoughTransformer::TransformCircleC(Int_t row_range)
192 //Circle transform, using combinations of every 2 points lying
193 //on different padrows and within the same etaslice.
195 AliL3DigitRowData *tempPt = GetDataPointer();
197 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircleC","Data")
198 <<"No input data "<<ENDLOG;
201 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
203 counter += tempPt->fNDigit;
204 AliL3MemHandler::UpdateRowPointer(tempPt);
215 Digit *digits = new Digit[counter];
216 cout<<"Allocating "<<counter*sizeof(Digit)<<" bytes to digitsarray"<<endl;
218 Int_t total_digits=counter;
219 Int_t sector,row,tot_charge,pad,time,charge;
220 Double_t r1,r2,phi1,phi2,eta,kappa,phi_0;
224 tempPt = GetDataPointer();
226 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
228 AliL3DigitData *digPt = tempPt->fDigitData;
229 for(UInt_t di=0; di<tempPt->fNDigit; di++)
231 charge = digPt[di].fCharge;
232 pad = digPt[di].fPad;
233 time = digPt[di].fTime;
234 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
235 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
236 eta = AliL3Transform::GetEta(xyz);
237 digits[counter].row = i;
238 digits[counter].r = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
239 digits[counter].phi = atan2(xyz[1],xyz[0]);
240 digits[counter].eta_index = GetEtaIndex(eta);
241 digits[counter].charge = charge;
244 AliL3MemHandler::UpdateRowPointer(tempPt);
247 for(Int_t i=0; i<total_digits; i++)
249 if(digits[i].eta_index < 0 || digits[i].eta_index >= GetNEtaSegments()) continue;
250 Int_t ind = digits[i].eta_index;
252 for(Int_t j=i+1; j<total_digits; j++)
254 if(digits[i].row == digits[j].row) continue;
255 if(digits[i].eta_index != digits[j].eta_index) continue;
256 if(digits[i].row + row_range < digits[j].row) break;
258 //Get the correct histogrampointer:
259 AliL3Histogram *hist = fParamSpace[ind];
262 printf("AliL3HoughTransformer::TransformCircleC() : No histogram at index %d\n",ind);
267 phi1 = digits[i].phi;
269 phi2 = digits[j].phi;
270 phi_0 = atan( (r2*sin(phi1)-r1*sin(phi2))/(r2*cos(phi1)-r1*cos(phi2)) );
271 kappa = 2*sin(phi2-phi_0)/r2;
272 tot_charge = digits[i].charge + digits[j].charge;
273 hist->Fill(kappa,phi_0,tot_charge);
279 void AliL3HoughTransformer::TransformLine()
281 //Do a line transform on the data.
284 AliL3DigitRowData *tempPt = GetDataPointer();
287 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformLine","Data")
288 <<"No input data "<<ENDLOG;
292 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
294 AliL3DigitData *digPt = tempPt->fDigitData;
295 if(i != (Int_t)tempPt->fRow)
297 printf("AliL3HoughTransform::TransformLine : Mismatching padrow numbering\n");
300 for(UInt_t j=0; j<tempPt->fNDigit; j++)
302 UShort_t charge = digPt[j].fCharge;
303 UChar_t pad = digPt[j].fPad;
304 UShort_t time = digPt[j].fTime;
305 if(charge < GetThreshold())
309 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
310 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
311 Float_t eta = AliL3Transform::GetEta(xyz);
312 Int_t eta_index = GetEtaIndex(eta);//(Int_t)(eta/etaslice);
313 if(eta_index < 0 || eta_index >= GetNEtaSegments())
316 //Get the correct histogram:
317 AliL3Histogram *hist = fParamSpace[eta_index];
320 printf("AliL3HoughTransformer::TransformLine : Error getting histogram in index %d\n",eta_index);
323 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
325 Double_t theta = hist->GetBinCenterX(xbin);
326 Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
327 hist->Fill(theta,rho,charge);
330 AliL3MemHandler::UpdateRowPointer(tempPt);