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 x = AliL3Transform::GetBFact()*AliL3Transform::GetBField()/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();
98 Int_t AliL3HoughTransformer::GetEtaIndex(Double_t eta)
100 //Return the histogram index of the corresponding eta.
102 Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
103 Double_t index = (eta-GetEtaMin())/etaslice;
107 inline AliL3Histogram *AliL3HoughTransformer::GetHistogram(Int_t eta_index)
109 if(!fParamSpace || eta_index >= GetNEtaSegments() || eta_index < 0)
111 if(!fParamSpace[eta_index])
113 return fParamSpace[eta_index];
116 Double_t AliL3HoughTransformer::GetEta(Int_t eta_index,Int_t slice)
118 Double_t eta_slice = (GetEtaMax()-GetEtaMin())/GetNEtaSegments();
119 Double_t eta=(Double_t)((eta_index+0.5)*eta_slice);
120 if(slice>17) eta*=-1;
124 void AliL3HoughTransformer::TransformCircle()
126 //Transform the input data with a circle HT.
127 //The function loops over all the data, and transforms each pixel with the equations:
129 //kappa = 2/R*sin(phi - phi0)
131 //where R = sqrt(x*x +y*y), and phi = arctan(y/x)
133 //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find
134 //which histogram in which the pixel should be transformed, the eta-value is calcluated
135 //and the proper histogram index is found by GetEtaIndex(eta).
138 AliL3DigitRowData *tempPt = GetDataPointer();
141 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircle","Data")
142 <<"No input data "<<ENDLOG;
146 //Loop over the padrows:
147 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); i++)
149 //Get the data on this padrow:
150 AliL3DigitData *digPt = tempPt->fDigitData;
151 if(i != (Int_t)tempPt->fRow)
153 cerr<<"AliL3HoughTransform::TransformCircle : Mismatching padrow numbering "<<i<<" "<<(Int_t)tempPt->fRow<<endl;
157 //Loop over the data on this padrow:
158 for(UInt_t j=0; j<tempPt->fNDigit; j++)
160 UShort_t charge = digPt[j].fCharge;
161 UChar_t pad = digPt[j].fPad;
162 UShort_t time = digPt[j].fTime;
163 if((Int_t)charge <= GetLowerThreshold() || (Int_t)charge > GetUpperThreshold())
168 //Transform data to local cartesian coordinates:
169 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
170 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
173 Double_t eta = AliL3Transform::GetEta(xyz);
175 //Get the corresponding index, which determines which histogram to fill:
176 Int_t eta_index = GetEtaIndex(eta);
177 if(eta_index < 0 || eta_index >= GetNEtaSegments())
180 //Get the correct histogrampointer:
181 AliL3Histogram *hist = fParamSpace[eta_index];
184 printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
188 //Do the transformation:
189 Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
190 Float_t phi = AliL3Transform::GetPhi(xyz);
192 //Fill the histogram along the phirange
193 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
195 Float_t phi0 = hist->GetBinCenterY(b);
196 Float_t kappa = 2*sin(phi - phi0)/R;
197 hist->Fill(kappa,phi0,charge);
201 //Move the data pointer to the next padrow:
202 AliL3MemHandler::UpdateRowPointer(tempPt);
206 void AliL3HoughTransformer::TransformCircleC(Int_t row_range)
208 //Circle transform, using combinations of every 2 points lying
209 //on different padrows and within the same etaslice.
211 AliL3DigitRowData *tempPt = GetDataPointer();
213 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformCircleC","Data")
214 <<"No input data "<<ENDLOG;
217 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); 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 = GetDataPointer();
242 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); 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 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
251 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
252 eta = AliL3Transform::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 >= GetNEtaSegments()) 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 = GetDataPointer();
303 LOG(AliL3Log::kError,"AliL3HoughTransformer::TransformLine","Data")
304 <<"No input data "<<ENDLOG;
308 for(Int_t i=AliL3Transform::GetFirstRow(GetPatch()); i<=AliL3Transform::GetLastRow(GetPatch()); 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 < GetLowerThreshold())
325 AliL3Transform::Slice2Sector(GetSlice(),i,sector,row);
326 AliL3Transform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
327 Float_t eta = AliL3Transform::GetEta(xyz);
328 Int_t eta_index = GetEtaIndex(eta);//(Int_t)(eta/etaslice);
329 if(eta_index < 0 || eta_index >= GetNEtaSegments())
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);