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::Init(Int_t slice=0,Int_t patch=0,Int_t n_eta_segments=100){}
40 void AliL3HoughTransformer::DeleteHistograms()
44 for(Int_t i=0; i<GetNEtaSegments(); i++)
46 if(!fParamSpace[i]) continue;
47 delete fParamSpace[i];
49 delete [] fParamSpace;
52 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t pt_min,
53 Int_t nybin,Double_t phimin,Double_t phimax)
55 //Create the histograms (parameter space).
56 //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis).
57 //The arguments give the range and binning;
58 //nxbin = #bins in kappa
59 //nybin = #bins in phi0
60 //pt_min = mimium Pt of track (corresponding to maximum kappa)
61 //phi_min = mimimum phi0 (degrees)
62 //phi_max = maximum phi0 (degrees)
64 Double_t bfact = 0.0029980;
65 Double_t bfield = 0.2;
66 Double_t x = bfact*bfield/pt_min;
67 Double_t torad = AliL3Transform::Pi()/180;
68 CreateHistograms(nxbin,-1.*x,x,nybin,phimin*torad,phimax*torad);
71 void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
72 Int_t nybin,Double_t ymin,Double_t ymax)
75 fParamSpace = new AliL3Histogram*[GetNEtaSegments()];
78 for(Int_t i=0; i<GetNEtaSegments(); i++)
80 sprintf(histname,"paramspace_%d",i);
81 fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
85 void AliL3HoughTransformer::Reset()
87 //Reset all the histograms
91 LOG(AliL3Log::kWarning,"AliL3HoughTransformer::Reset","Histograms")
92 <<"No histograms to reset"<<ENDLOG;
96 for(Int_t i=0; i<GetNEtaSegments(); i++)
97 fParamSpace[i]->Reset();
100 Int_t AliL3HoughTransformer::GetEtaIndex(Double_t eta)
102 //Return the histogram index of the corresponding eta.
104 Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
105 Double_t index = (eta-GetEtaMin())/etaslice;
109 inline AliL3Histogram *AliL3HoughTransformer::GetHistogram(Int_t eta_index)
111 if(!fParamSpace || eta_index >= GetNEtaSegments() || eta_index < 0)
113 if(!fParamSpace[eta_index])
115 return fParamSpace[eta_index];
118 Double_t AliL3HoughTransformer::GetEta(Int_t eta_index)
120 Double_t eta_slice = (GetEtaMax()-GetEtaMin())/GetNEtaSegments();
121 Double_t eta=(Double_t)((eta_index+0.5)*eta_slice);
122 if(GetSlice()>17) eta*=-1;
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 = GetDataPointer();
143 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircle","Data")
144 <<"No input data "<<ENDLOG;
148 //Loop over the padrows:
149 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
151 //Get the data on this padrow:
152 AliL3DigitData *digPt = tempPt->fDigitData;
153 if(i != (Int_t)tempPt->fRow)
155 cerr<<"AliL3HoughTransform::TransformCircle : Mismatching padrow numbering "<<i<<" "<<(Int_t)tempPt->fRow<<endl;
159 //Loop over the data on this padrow:
160 for(UInt_t j=0; j<tempPt->fNDigit; j++)
162 UShort_t charge = digPt[j].fCharge;
163 UChar_t pad = digPt[j].fPad;
164 UShort_t time = digPt[j].fTime;
165 if((Int_t)charge <= GetLowerThreshold() || (Int_t)charge > GetUpperThreshold())
170 //Transform data to local cartesian coordinates:
171 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
172 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
175 Double_t eta = AliL3Transform::GetEta(xyz);
177 //Get the corresponding index, which determines which histogram to fill:
178 Int_t eta_index = GetEtaIndex(eta);
179 if(eta_index < 0 || eta_index >= GetNEtaSegments())
182 //Get the correct histogrampointer:
183 AliL3Histogram *hist = fParamSpace[eta_index];
186 printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
190 //Do the transformation:
191 Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
192 Float_t phi = AliL3Transform::GetPhi(xyz);
194 //Fill the histogram along the phirange
195 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
197 Float_t phi0 = hist->GetBinCenterY(b);
198 Float_t kappa = 2*sin(phi - phi0)/R;
199 hist->Fill(kappa,phi0,charge);
203 //Move the data pointer to the next padrow:
204 AliL3MemHandler::UpdateRowPointer(tempPt);
208 void AliL3HoughTransformer::TransformCircleC(Int_t row_range)
210 //Circle transform, using combinations of every 2 points lying
211 //on different padrows and within the same etaslice.
213 AliL3DigitRowData *tempPt = GetDataPointer();
215 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircleC","Data")
216 <<"No input data "<<ENDLOG;
219 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
221 counter += tempPt->fNDigit;
222 AliL3MemHandler::UpdateRowPointer(tempPt);
233 Digit *digits = new Digit[counter];
234 cout<<"Allocating "<<counter*sizeof(Digit)<<" bytes to digitsarray"<<endl;
236 Int_t total_digits=counter;
237 Int_t sector,row,tot_charge,pad,time,charge;
238 Double_t r1,r2,phi1,phi2,eta,kappa,phi_0;
242 tempPt = GetDataPointer();
244 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
246 AliL3DigitData *digPt = tempPt->fDigitData;
247 for(UInt_t di=0; di<tempPt->fNDigit; di++)
249 charge = digPt[di].fCharge;
250 pad = digPt[di].fPad;
251 time = digPt[di].fTime;
252 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
253 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
254 eta = AliL3Transform::GetEta(xyz);
255 digits[counter].row = i;
256 digits[counter].r = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
257 digits[counter].phi = atan2(xyz[1],xyz[0]);
258 digits[counter].eta_index = GetEtaIndex(eta);
259 digits[counter].charge = charge;
262 AliL3MemHandler::UpdateRowPointer(tempPt);
265 for(Int_t i=0; i<total_digits; i++)
267 if(digits[i].eta_index < 0 || digits[i].eta_index >= GetNEtaSegments()) continue;
268 Int_t ind = digits[i].eta_index;
270 for(Int_t j=i+1; j<total_digits; j++)
272 if(digits[i].row == digits[j].row) continue;
273 if(digits[i].eta_index != digits[j].eta_index) continue;
274 if(digits[i].row + row_range < digits[j].row) break;
276 //Get the correct histogrampointer:
277 AliL3Histogram *hist = fParamSpace[ind];
280 printf("AliL3HoughTransformer::TransformCircleC() : No histogram at index %d\n",ind);
285 phi1 = digits[i].phi;
287 phi2 = digits[j].phi;
288 phi_0 = atan( (r2*sin(phi1)-r1*sin(phi2))/(r2*cos(phi1)-r1*cos(phi2)) );
289 kappa = 2*sin(phi2-phi_0)/r2;
290 tot_charge = digits[i].charge + digits[j].charge;
291 hist->Fill(kappa,phi_0,tot_charge);
297 void AliL3HoughTransformer::TransformLine()
299 //Do a line transform on the data.
302 AliL3DigitRowData *tempPt = GetDataPointer();
305 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformLine","Data")
306 <<"No input data "<<ENDLOG;
310 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
312 AliL3DigitData *digPt = tempPt->fDigitData;
313 if(i != (Int_t)tempPt->fRow)
315 printf("AliL3HoughTransform::TransformLine : Mismatching padrow numbering\n");
318 for(UInt_t j=0; j<tempPt->fNDigit; j++)
320 UShort_t charge = digPt[j].fCharge;
321 UChar_t pad = digPt[j].fPad;
322 UShort_t time = digPt[j].fTime;
323 if(charge < GetLowerThreshold())
327 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
328 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
329 Float_t eta = AliL3Transform::GetEta(xyz);
330 Int_t eta_index = GetEtaIndex(eta);//(Int_t)(eta/etaslice);
331 if(eta_index < 0 || eta_index >= GetNEtaSegments())
334 //Get the correct histogram:
335 AliL3Histogram *hist = fParamSpace[eta_index];
338 printf("AliL3HoughTransformer::TransformLine : Error getting histogram in index %d\n",eta_index);
341 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
343 Double_t theta = hist->GetBinCenterX(xbin);
344 Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
345 hist->Fill(theta,rho,charge);
348 AliL3MemHandler::UpdateRowPointer(tempPt);