Added #include<stdlib.h> and log
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughTransformer.cxx
CommitLineData
b1886074 1// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
2//*-- Copyright &copy ASV
4cafa5fc 3
48f3c46f 4#include "AliL3MemHandler.h"
e26acabd 5#include "AliL3Logging.h"
99e7186b 6#include "AliL3HoughTransformer.h"
4de874d1 7#include "AliL3Defs.h"
8#include "AliL3Transform.h"
4cafa5fc 9#include "AliL3DigitData.h"
99e7186b 10#include "AliL3Histogram.h"
4de874d1 11
b1886074 12//_____________________________________________________________
13// AliL3HoughTransformer
14//
15// Hough transformation class
16
4de874d1 17ClassImp(AliL3HoughTransformer)
18
19AliL3HoughTransformer::AliL3HoughTransformer()
20{
21 //Default constructor
4cafa5fc 22
4de874d1 23}
24
99e7186b 25AliL3HoughTransformer::AliL3HoughTransformer(Int_t slice,Int_t patch,Int_t n_eta_segments)
52a2a604 26{
52a2a604 27 fSlice = slice;
28 fPatch = patch;
99e7186b 29 fNEtaSegments = n_eta_segments;
30 fEtaMin = 0;
31 fEtaMax = fSlice < 18 ? 0.9 : -0.9;
32 fTransform = new AliL3Transform();
33 fThreshold = 0;
48f3c46f 34 fNDigitRowData=0;
35 fDigitRowData=0;
52a2a604 36}
37
4de874d1 38AliL3HoughTransformer::~AliL3HoughTransformer()
39{
4de874d1 40 if(fTransform)
41 delete fTransform;
99e7186b 42 DeleteHistograms();
4cafa5fc 43}
44
99e7186b 45void AliL3HoughTransformer::DeleteHistograms()
4cafa5fc 46{
99e7186b 47 if(!fParamSpace)
48 return;
49 for(Int_t i=0; i<fNEtaSegments; i++)
4fc9a6a4 50 {
51 if(!fParamSpace[i]) continue;
52 delete fParamSpace[i];
53 }
99e7186b 54 delete [] fParamSpace;
4cafa5fc 55}
56
e26acabd 57void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t pt_min,
58 Int_t nybin,Double_t phimin,Double_t phimax)
59{
60 //Set the minimum absolute pt value, and phi0 angles given in degrees.
61
62 Double_t torad = 3.1415/180;
63 Double_t bfact = 0.0029980;
64 Double_t bfield = 0.2;
65 Double_t x = bfact*bfield/pt_min;
66 CreateHistograms(nxbin,-1.*x,x,nybin,phimin*torad,phimax*torad);
67}
68
99e7186b 69void AliL3HoughTransformer::CreateHistograms(Int_t nxbin,Double_t xmin,Double_t xmax,
70 Int_t nybin,Double_t ymin,Double_t ymax)
4cafa5fc 71{
4fc9a6a4 72
99e7186b 73 fParamSpace = new AliL3Histogram*[fNEtaSegments];
4cafa5fc 74
99e7186b 75 Char_t histname[256];
76 for(Int_t i=0; i<fNEtaSegments; i++)
4de874d1 77 {
99e7186b 78 sprintf(histname,"paramspace_%d",i);
79 fParamSpace[i] = new AliL3Histogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
4de874d1 80 }
4cafa5fc 81}
82
e26acabd 83void AliL3HoughTransformer::Reset()
84{
48f3c46f 85 //Reset all the histograms
e26acabd 86
87 if(!fParamSpace)
88 {
89 LOG(AliL3Log::kWarning,"AliL3HoughTransformer::Reset","Histograms")
90 <<"No histograms to reset"<<ENDLOG;
91 return;
92 }
93
94 for(Int_t i=0; i<fNEtaSegments; i++)
95 fParamSpace[i]->Reset();
e26acabd 96}
97
99e7186b 98void AliL3HoughTransformer::SetInputData(UInt_t ndigits,AliL3DigitRowData *ptr)
9f33a1db 99{
99e7186b 100 fNDigitRowData = ndigits;
101 fDigitRowData = ptr;
4de874d1 102}
103
4fc9a6a4 104void AliL3HoughTransformer::TransformCircle()
4de874d1 105{
99e7186b 106 //Transform the input data with a circle HT.
107
52a2a604 108
99e7186b 109 //Set pointer to the data
110 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
111 if(!tempPt || fNDigitRowData==0)
4de874d1 112 {
4fc9a6a4 113 printf("\nAliL3HoughTransformer::TransformCircle : No input data!!!\n\n");
99e7186b 114 return;
4de874d1 115 }
99e7186b 116
117 Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
4cafa5fc 118 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
119 {
99e7186b 120 AliL3DigitData *digPt = tempPt->fDigitData;
121 if(i != (Int_t)tempPt->fRow)
4cafa5fc 122 {
4fc9a6a4 123 printf("AliL3HoughTransform::TransformCircle : Mismatching padrow numbering\n");
99e7186b 124 continue;
125 }
126 for(UInt_t j=0; j<tempPt->fNDigit; j++)
127 {
128 UShort_t charge = digPt[j].fCharge;
129 UChar_t pad = digPt[j].fPad;
130 UShort_t time = digPt[j].fTime;
48f3c46f 131 if(charge <= fThreshold)
99e7186b 132 continue;
4cafa5fc 133 Int_t sector,row;
99e7186b 134 Float_t xyz[3];
4cafa5fc 135 fTransform->Slice2Sector(fSlice,i,sector,row);
99e7186b 136 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
4fc9a6a4 137 Double_t eta = fTransform->GetEta(xyz);
48f3c46f 138 Int_t eta_index = (Int_t)((eta-fEtaMin)/etaslice);
99e7186b 139 if(eta_index < 0 || eta_index >= fNEtaSegments)
140 continue;
4cafa5fc 141
e26acabd 142 //Get the correct histogrampointer:
99e7186b 143 AliL3Histogram *hist = fParamSpace[eta_index];
144 if(!hist)
4cafa5fc 145 {
4fc9a6a4 146 printf("AliL3HoughTransformer::TransformCircle : Error getting histogram in index %d\n",eta_index);
99e7186b 147 continue;
4cafa5fc 148 }
4cafa5fc 149
99e7186b 150 //Start transformation
e26acabd 151 Float_t R = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]); // + xyz[2]*xyz[2]);
99e7186b 152 Float_t phi = fTransform->GetPhi(xyz);
4de874d1 153
99e7186b 154 //Fill the histogram along the phirange
155 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
4de874d1 156 {
99e7186b 157 Float_t phi0 = hist->GetBinCenterY(b);
158 Float_t kappa = 2*sin(phi - phi0)/R;
159 hist->Fill(kappa,phi0,charge);
4de874d1 160 }
4de874d1 161 }
48f3c46f 162 AliL3MemHandler::UpdateRowPointer(tempPt);
4de874d1 163 }
4de874d1 164}
165
b1886074 166void AliL3HoughTransformer::TransformCircleC()
167{
168 //Circle transform, using combinations of every 2 points lying
169 //on different padrows and within the same etaslice.
170
171
172 Int_t nrows = NRows[fPatch][1] - NRows[fPatch][0] + 1;
173 AliL3DigitRowData **rowPt = new AliL3DigitRowData*[nrows];
174
175 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
176 if(!tempPt)
177 printf("\nAliL3HoughTransformer::TransformCircleC() : Zero data pointer\n");
178
179 Int_t prow;
180 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
181 {
182 prow = i - NRows[fPatch][0];
183 rowPt[prow] = tempPt;
184 AliL3MemHandler::UpdateRowPointer(tempPt);
185 }
186 Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
187
188 AliL3DigitData *digPt;
189 Double_t r1,r2,phi1,phi2,eta,kappa,phi_0;
190 UShort_t charge1,charge2,time;
191 UChar_t pad;
192 Float_t xyz[3];
193 Int_t sector,row,eta_index1,eta_index2,tot_charge;
194 for(Int_t i=NRows[fPatch][0]; i<NRows[fPatch][1]; i++)
195 {
196 prow = i - NRows[fPatch][0];
197 digPt = rowPt[prow]->fDigitData;
198 for(UInt_t di=0; di<rowPt[prow]->fNDigit; di++)
199 {
200 charge1 = digPt[di].fCharge;
201 pad = digPt[di].fPad;
202 time = digPt[di].fTime;
203 if(charge1 <= fThreshold)
204 continue;
205 fTransform->Slice2Sector(fSlice,i,sector,row);
206 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
207 eta = fTransform->GetEta(xyz);
208 eta_index1 = (Int_t)((eta-fEtaMin)/etaslice);
209 if(eta_index1 < 0 || eta_index1 >= fNEtaSegments)
210 continue;
211 r1 = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
212 phi1 = atan2(xyz[1],xyz[0]);
213
214 //Get the correct histogrampointer:
215 AliL3Histogram *hist = fParamSpace[eta_index1];
216 if(!hist)
217 {
218 printf("AliL3HoughTransformer::TransformCircleC() : No histogram at index %d\n",eta_index1);
219 continue;
220 }
221
222 for(Int_t j=i+1; j<NRows[fPatch][1]; j++)
223 {
224 prow = j - NRows[fPatch][0];
225 digPt = rowPt[prow]->fDigitData;
226 for(UInt_t ni=0; ni<rowPt[prow]->fNDigit; ni++)
227 {
228 charge2 = digPt[ni].fCharge;
229 pad = digPt[ni].fPad;
230 time = digPt[ni].fTime;
231 if(charge2 <= fThreshold)
232 continue;
233 fTransform->Slice2Sector(fSlice,j,sector,row);
234 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
235 eta = fTransform->GetEta(xyz);
236 eta_index2 = (Int_t)((eta-fEtaMin)/etaslice);
237 if(eta_index2 != eta_index1)
238 continue;
239 r2 = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
240 phi2 = atan2(xyz[1],xyz[0]);
241
242 phi_0 = atan( (r2*sin(phi1)-r1*sin(phi2))/(r2*cos(phi1)-r1*cos(phi2)) );
243 kappa = 2*sin(phi2-phi_0)/r2;
244 tot_charge = charge1+charge2;
245 //printf("Filling kappa %f phi %f charge %d\n",kappa,phi_0,tot_charge);
246 hist->Fill(kappa,phi_0,tot_charge);
247 }
248 }
249 }
250 }
251
252 delete [] rowPt;
253}
254
4fc9a6a4 255void AliL3HoughTransformer::TransformLine()
256{
257 //Do a line transform on the data.
258
259
260 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fDigitRowData;
261 if(!tempPt || fNDigitRowData==0)
262 {
263 printf("\nAliL3HoughTransformer::TransformLine : No input data!!!\n\n");
264 return;
265 }
266
267 Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
268 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
269 {
270 AliL3DigitData *digPt = tempPt->fDigitData;
271 if(i != (Int_t)tempPt->fRow)
272 {
273 printf("AliL3HoughTransform::TransformLine : Mismatching padrow numbering\n");
274 continue;
275 }
276 for(UInt_t j=0; j<tempPt->fNDigit; j++)
277 {
278 UShort_t charge = digPt[j].fCharge;
279 UChar_t pad = digPt[j].fPad;
280 UShort_t time = digPt[j].fTime;
281 if(charge < fThreshold)
282 continue;
283 Int_t sector,row;
284 Float_t xyz[3];
285 fTransform->Slice2Sector(fSlice,i,sector,row);
286 fTransform->Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
287 Float_t eta = fTransform->GetEta(xyz);
288 Int_t eta_index = (Int_t)(eta/etaslice);
289 if(eta_index < 0 || eta_index >= fNEtaSegments)
290 continue;
291
292 //Get the correct histogram:
293 AliL3Histogram *hist = fParamSpace[eta_index];
294 if(!hist)
295 {
296 printf("AliL3HoughTransformer::TransformLine : Error getting histogram in index %d\n",eta_index);
297 continue;
298 }
299 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
300 {
301 Double_t theta = hist->GetBinCenterX(xbin);
302 Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
303 hist->Fill(theta,rho,charge);
304 }
305 }
48f3c46f 306 AliL3MemHandler::UpdateRowPointer(tempPt);
4fc9a6a4 307 }
308
309}