]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliHLTHoughTransformer.cxx
L3 becomes HLT
[u/mrichter/AliRoot.git] / HLT / hough / AliHLTHoughTransformer.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
b5a207b4 2
b1886074 3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
4cafa5fc 5
4aa41877 6/** \class AliHLTHoughTransformer
bd5675d4 7<pre>
8//_____________________________________________________________
4aa41877 9// AliHLTHoughTransformer
bd5675d4 10//
11// Hough transformation class
12//
13</pre>
14*/
15
4aa41877 16#include "AliHLTStandardIncludes.h"
e06900d5 17
4aa41877 18#include "AliHLTLogging.h"
19#include "AliHLTHoughTransformer.h"
20#include "AliHLTMemHandler.h"
21#include "AliHLTTransform.h"
22#include "AliHLTDigitData.h"
23#include "AliHLTHistogramAdaptive.h"
4de874d1 24
c6747af6 25#if __GNUC__ >= 3
e06900d5 26using namespace std;
27#endif
28
4aa41877 29ClassImp(AliHLTHoughTransformer)
4de874d1 30
4aa41877 31AliHLTHoughTransformer::AliHLTHoughTransformer()
4de874d1 32{
33 //Default constructor
c52cf5d8 34 fParamSpace = 0;
44c7f8de 35 fDoMC = kFALSE;;
3e87ef69 36 fEtaOverlap=kFALSE;
1eef4efc 37#ifdef do_mc
38 fTrackID = 0;
39#endif
4de874d1 40}
41
4aa41877 42AliHLTHoughTransformer::AliHLTHoughTransformer(Int_t slice,Int_t patch,Int_t netasegments,Bool_t DoEtaOverlap,Bool_t /*DoMC*/) : AliHLTHoughBaseTransformer(slice,patch,netasegments)
52a2a604 43{
3ef466c5 44 //Normal constructor
237d3f5c 45 fParamSpace = 0;
3e87ef69 46 fDoMC = kFALSE;
47 fEtaOverlap = DoEtaOverlap;
48 fDoMC=kFALSE;
1eef4efc 49#ifdef do_mc
50 fTrackID = 0;
51#endif
52a2a604 52}
53
4aa41877 54AliHLTHoughTransformer::~AliHLTHoughTransformer()
4de874d1 55{
917e711b 56 // Dtor
99e7186b 57 DeleteHistograms();
1eef4efc 58#ifdef do_mc
59 if(fTrackID)
60 {
61 for(Int_t i=0; i<GetNEtaSegments(); i++)
62 {
63 if(!fTrackID[i]) continue;
64 delete fTrackID[i];
65 }
66 delete [] fTrackID;
67 }
68#endif
4cafa5fc 69}
70
4aa41877 71void AliHLTHoughTransformer::DeleteHistograms()
4cafa5fc 72{
917e711b 73 // Clean up
99e7186b 74 if(!fParamSpace)
75 return;
c52cf5d8 76 for(Int_t i=0; i<GetNEtaSegments(); i++)
4fc9a6a4 77 {
78 if(!fParamSpace[i]) continue;
79 delete fParamSpace[i];
80 }
99e7186b 81 delete [] fParamSpace;
bd5675d4 82 fParamSpace = 0;
4cafa5fc 83}
84
4aa41877 85void AliHLTHoughTransformer::CreateHistograms(Float_t ptmin,Float_t ptmax,Float_t ptres,
b2a02bce 86 Int_t nybin,Float_t psi)
87{
88 //Create histograms.
89 //_Only_ to be used in case of the adaptive histograms!
90 //phimax is given in radians!!
91
92 if(ptmin > ptmax)
93 {
4aa41877 94 cerr<<"AliHLTHoughTransformer::CreateHistograms: Error in ptrange "<<ptmin<<" "<<ptmax<<endl;
b2a02bce 95 return;
96 }
97 if(psi < 0)
98 {
4aa41877 99 cerr<<"AliHLTHoughTransformer::CreateHistograms: Wrong psi-angle "<<psi<<endl;
b2a02bce 100 return;
101 }
102
4aa41877 103 fParamSpace = new AliHLTHistogram*[GetNEtaSegments()];
b2a02bce 104 Char_t histname[256];
105 Int_t i;
106 for(i=0; i<GetNEtaSegments(); i++)
107 {
108 sprintf(histname,"paramspace_%d",i);
4aa41877 109 fParamSpace[i] = new AliHLTHistogramAdaptive(histname,ptmin,ptmax,ptres,nybin,-psi,psi);
b2a02bce 110 }
b2a02bce 111}
112
4aa41877 113void AliHLTHoughTransformer::CreateHistograms(Int_t nxbin,Float_t ptmin,
b2a02bce 114 Int_t nybin,Float_t phimin,Float_t phimax)
e26acabd 115{
3ef466c5 116 //Create the histograms (parameter space).
117 //These are 2D histograms, span by kappa (curvature of track) and phi0 (emission angle with x-axis).
118 //The arguments give the range and binning;
119 //nxbin = #bins in kappa
120 //nybin = #bins in phi0
917e711b 121 //ptmin = mimium Pt of track (corresponding to maximum kappa)
122 //phimin = mimimum phi0
123 //phimax = maximum phi0
3ef466c5 124
4aa41877 125 Double_t x = AliHLTTransform::GetBFact()*AliHLTTransform::GetBField()/ptmin;
126 //Double_t torad = AliHLTTransform::Pi()/180;
b2a02bce 127
128 CreateHistograms(nxbin,-1.*x,x,nybin,phimin/**torad*/,phimax/**torad*/);
e26acabd 129}
130
4aa41877 131void AliHLTHoughTransformer::CreateHistograms(Int_t nxbin,Float_t xmin,Float_t xmax,
b2a02bce 132 Int_t nybin,Float_t ymin,Float_t ymax)
4cafa5fc 133{
917e711b 134 //Create the histograms (parameter space).
135 //nxbin = #bins in X
136 //nybin = #bins in Y
137 //xmin xmax ymin ymax = histogram limits in X and Y
4fc9a6a4 138
4aa41877 139 fParamSpace = new AliHLTHistogram*[GetNEtaSegments()];
4cafa5fc 140
99e7186b 141 Char_t histname[256];
c52cf5d8 142 for(Int_t i=0; i<GetNEtaSegments(); i++)
4de874d1 143 {
99e7186b 144 sprintf(histname,"paramspace_%d",i);
4aa41877 145 //fParamSpace[i] = new AliHLTHistogramAdaptive(histname,0.5,1.5,0.05,nybin,ymin,ymax);
146 fParamSpace[i] = new AliHLTHistogram(histname,"",nxbin,xmin,xmax,nybin,ymin,ymax);
4de874d1 147 }
1eef4efc 148
149#ifdef do_mc
c980a70c 150 if(fDoMC)
151 {
4aa41877 152 AliHLTHistogram *hist = fParamSpace[0];
88905d4d 153 Int_t ncells = (hist->GetNbinsX()+2)*(hist->GetNbinsY()+2);
4aa41877 154 cout<<"Transformer: Allocating "<<GetNEtaSegments()*ncells*sizeof(AliHLTTrackIndex)<<" bytes to fTrackID"<<endl;
155 fTrackID = new AliHLTTrackIndex*[GetNEtaSegments()];
c980a70c 156 for(Int_t i=0; i<GetNEtaSegments(); i++)
4aa41877 157 fTrackID[i] = new AliHLTTrackIndex[ncells];
c980a70c 158 }
1eef4efc 159#endif
4cafa5fc 160}
161
4aa41877 162void AliHLTHoughTransformer::Reset()
e26acabd 163{
48f3c46f 164 //Reset all the histograms
e26acabd 165
166 if(!fParamSpace)
167 {
4aa41877 168 LOG(AliHLTLog::kWarning,"AliHLTHoughTransformer::Reset","Histograms")
e26acabd 169 <<"No histograms to reset"<<ENDLOG;
170 return;
171 }
172
c52cf5d8 173 for(Int_t i=0; i<GetNEtaSegments(); i++)
e26acabd 174 fParamSpace[i]->Reset();
b2a02bce 175
1eef4efc 176#ifdef do_mc
c980a70c 177 if(fDoMC)
178 {
4aa41877 179 AliHLTHistogram *hist = fParamSpace[0];
c980a70c 180 Int_t ncells = (hist->GetNbinsX()+2)*(hist->GetNbinsY()+2);
181 for(Int_t i=0; i<GetNEtaSegments(); i++)
4aa41877 182 memset(fTrackID[i],0,ncells*sizeof(AliHLTTrackIndex));
c980a70c 183 }
1eef4efc 184#endif
e26acabd 185}
186
4aa41877 187Int_t AliHLTHoughTransformer::GetEtaIndex(Double_t eta) const
b5a207b4 188{
3ef466c5 189 //Return the histogram index of the corresponding eta.
190
c52cf5d8 191 Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
192 Double_t index = (eta-GetEtaMin())/etaslice;
b5a207b4 193 return (Int_t)index;
194}
195
4aa41877 196void AliHLTHoughTransformer::GetEtaIndexes(Double_t eta,Int_t *indexes) const
3e87ef69 197{
198 //Return histogram indexes in case of overlapping etaslices.
199
200 Double_t etaslice = (GetEtaMax() - GetEtaMin())/GetNEtaSegments();
201 Int_t index = (Int_t)((eta-GetEtaMin())/etaslice);
202 if(index%2 == 0)
203 {
204 indexes[0] = index;
205 indexes[1] = index - 1;
206 }
207 else
208 {
209 indexes[0] = index - 1;
210 indexes[1] = index;
211 }
212}
213
4aa41877 214AliHLTHistogram *AliHLTHoughTransformer::GetHistogram(Int_t etaindex)
7646f3c3 215{
917e711b 216 // Return a pointer to the histogram which contains etaindex eta slice
217 if(!fParamSpace || etaindex >= GetNEtaSegments() || etaindex < 0)
7646f3c3 218 return 0;
917e711b 219 if(!fParamSpace[etaindex])
7646f3c3 220 return 0;
917e711b 221 return fParamSpace[etaindex];
7646f3c3 222}
223
4aa41877 224Double_t AliHLTHoughTransformer::GetEta(Int_t etaindex,Int_t /*slice*/) const
7646f3c3 225{
917e711b 226 // Return eta calculated in the middle of the eta slice
227 Double_t etaslice = (GetEtaMax()-GetEtaMin())/GetNEtaSegments();
3e87ef69 228 Double_t eta=0;
229 if(fEtaOverlap)
230 {
917e711b 231 Int_t index = etaindex + 1;
232 eta=(Double_t)((index)*etaslice);
3e87ef69 233 }
234 else
917e711b 235 eta=(Double_t)((etaindex+0.5)*etaslice);
7646f3c3 236 return eta;
237}
238
4aa41877 239void AliHLTHoughTransformer::TransformCircle()
4de874d1 240{
99e7186b 241 //Transform the input data with a circle HT.
3ef466c5 242 //The function loops over all the data, and transforms each pixel with the equations:
243 //
917e711b 244 //kappa = 2/r*sin(phi - phi0)
3ef466c5 245 //
917e711b 246 //where r = sqrt(x*x +y*y), and phi = arctan(y/x)
3ef466c5 247 //
248 //Each pixel then transforms into a curve in the (kappa,phi0)-space. In order to find
3e87ef69 249 //which histogram in which the pixel should be transformed, the eta-value is calculated
3ef466c5 250 //and the proper histogram index is found by GetEtaIndex(eta).
251
52a2a604 252
4aa41877 253 AliHLTDigitRowData *tempPt = GetDataPointer();
c52cf5d8 254 if(!tempPt)
4de874d1 255 {
4aa41877 256 LOG(AliHLTLog::kError,"AliHLTHoughTransformer::TransformCircle","Data")
237d3f5c 257 <<"No input data "<<ENDLOG;
258 return;
259 }
99e7186b 260
3ef466c5 261 //Loop over the padrows:
4aa41877 262 for(Int_t i=AliHLTTransform::GetFirstRow(GetPatch()); i<=AliHLTTransform::GetLastRow(GetPatch()); i++)
4cafa5fc 263 {
3ef466c5 264 //Get the data on this padrow:
4aa41877 265 AliHLTDigitData *digPt = tempPt->fDigitData;
99e7186b 266 if(i != (Int_t)tempPt->fRow)
4cafa5fc 267 {
4aa41877 268 cerr<<"AliHLTHoughTransform::TransformCircle : Mismatching padrow numbering "<<i<<" "<<(Int_t)tempPt->fRow<<endl;
99e7186b 269 continue;
270 }
44c7f8de 271
3ef466c5 272 //Loop over the data on this padrow:
99e7186b 273 for(UInt_t j=0; j<tempPt->fNDigit; j++)
274 {
275 UShort_t charge = digPt[j].fCharge;
276 UChar_t pad = digPt[j].fPad;
277 UShort_t time = digPt[j].fTime;
b2a02bce 278 if((Int_t)charge <= GetLowerThreshold())
99e7186b 279 continue;
44c7f8de 280
b2a02bce 281 if((Int_t)charge > GetUpperThreshold())
282 charge = GetUpperThreshold();
283
4cafa5fc 284 Int_t sector,row;
99e7186b 285 Float_t xyz[3];
3e87ef69 286
3ef466c5 287 //Transform data to local cartesian coordinates:
4aa41877 288 AliHLTTransform::Slice2Sector(GetSlice(),i,sector,row);
289 AliHLTTransform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
3e87ef69 290
3ef466c5 291 //Calculate the eta:
4aa41877 292 Double_t eta = AliHLTTransform::GetEta(xyz);
3ef466c5 293
294 //Get the corresponding index, which determines which histogram to fill:
917e711b 295 Int_t etaindex = GetEtaIndex(eta);
3e87ef69 296
917e711b 297 if(etaindex < 0 || etaindex >= GetNEtaSegments())
99e7186b 298 continue;
4cafa5fc 299
e26acabd 300 //Get the correct histogrampointer:
4aa41877 301 AliHLTHistogram *hist = fParamSpace[etaindex];
99e7186b 302 if(!hist)
4cafa5fc 303 {
4aa41877 304 cerr<<"AliHLTHoughTransformer::TransformCircle : Error getting histogram in index "<<etaindex<<endl;
99e7186b 305 continue;
4cafa5fc 306 }
3e87ef69 307
3ef466c5 308 //Do the transformation:
917e711b 309 Float_t r = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
4aa41877 310 Float_t phi = AliHLTTransform::GetPhi(xyz);
4de874d1 311
b2a02bce 312
99e7186b 313 //Fill the histogram along the phirange
314 for(Int_t b=hist->GetFirstYbin(); b<=hist->GetLastYbin(); b++)
4de874d1 315 {
99e7186b 316 Float_t phi0 = hist->GetBinCenterY(b);
917e711b 317 Float_t kappa = 2*sin(phi - phi0)/r;
b2a02bce 318 //hist->Fill(kappa,phi0,(int)rint(log((Float_t)charge)));
3e87ef69 319 hist->Fill(kappa,phi0,charge);
320 //hist->Fill(kappa,phi0,1);
1eef4efc 321#ifdef do_mc
c980a70c 322 if(fDoMC)
1eef4efc 323 {
c980a70c 324 Int_t bin = hist->FindBin(kappa,phi0);
325 for(Int_t t=0; t<3; t++)
326 {
327 Int_t label = digPt[j].fTrackID[t];
328 if(label < 0) break;
329 UInt_t c;
330 for(c=0; c<MaxTrack; c++)
917e711b 331 if(fTrackID[etaindex][bin].fLabel[c] == label || fTrackID[etaindex][bin].fNHits[c] == 0)
c980a70c 332 break;
4aa41877 333 if(c == MaxTrack-1) cerr<<"AliHLTHoughTransformer::TransformCircle : Array reached maximum!! "<<c<<endl;
917e711b 334 fTrackID[etaindex][bin].fLabel[c] = label;
335 fTrackID[etaindex][bin].fNHits[c]++;
c980a70c 336 }
1eef4efc 337 }
338#endif
4de874d1 339 }
4de874d1 340 }
3ef466c5 341
342 //Move the data pointer to the next padrow:
4aa41877 343 AliHLTMemHandler::UpdateRowPointer(tempPt);
4de874d1 344 }
4de874d1 345}
346
4aa41877 347struct AliHLTDigit {
917e711b 348 Int_t fRow; // Digit padrow
349 Double_t fR; // Digit radius in local coordinate system
350 Double_t fPhi; // Digit Phi angle in local coordinate system
351 Int_t fCharge; // Digit charge
4aa41877 352 AliHLTDigit *fNext; // Next digit
3e87ef69 353};
1f1942b8 354
4aa41877 355struct AliHLTEtaContainer {
356 AliHLTDigit *fFirst; //First digit
357 AliHLTDigit *fLast; //Last digit
3e87ef69 358};
1f1942b8 359
4aa41877 360void AliHLTHoughTransformer::TransformCircleC(Int_t *rowrange,Int_t every)
b1886074 361{
362 //Circle transform, using combinations of every 2 points lying
363 //on different padrows and within the same etaslice.
364
4aa41877 365 AliHLTDigitRowData *tempPt = GetDataPointer();
b1886074 366 if(!tempPt)
4aa41877 367 LOG(AliHLTLog::kError,"AliHLTHoughTransformer::TransformCircleC","Data")
237d3f5c 368 <<"No input data "<<ENDLOG;
3e87ef69 369
4aa41877 370 Int_t minrow = AliHLTTransform::GetFirstRow(GetPatch());
371 Int_t maxrow = AliHLTTransform::GetLastRow(GetPatch());
917e711b 372 if(rowrange)
3e87ef69 373 {
917e711b 374 minrow = rowrange[0];
375 maxrow = rowrange[1];
4aa41877 376 if(minrow < AliHLTTransform::GetFirstRow(GetPatch()) || minrow >= AliHLTTransform::GetLastRow(GetPatch()))
377 minrow = AliHLTTransform::GetFirstRow(GetPatch());
378 if(maxrow < AliHLTTransform::GetFirstRow(GetPatch()) || maxrow >= AliHLTTransform::GetLastRow(GetPatch()))
379 maxrow = AliHLTTransform::GetLastRow(GetPatch());
3e87ef69 380 if(minrow > maxrow || maxrow==minrow)
381 {
4aa41877 382 cerr<<"AliHLTHoughTransformer::TransformCircleC : Bad row range "<<minrow<<" "<<maxrow<<endl;
3e87ef69 383 return;
384 }
385 }
386 else
387 {
4aa41877 388 minrow = AliHLTTransform::GetFirstRow(GetPatch());
389 maxrow = AliHLTTransform::GetLastRow(GetPatch());
3e87ef69 390 }
391
3ef466c5 392 Int_t counter=0;
4aa41877 393 for(Int_t i=AliHLTTransform::GetFirstRow(GetPatch()); i<=AliHLTTransform::GetLastRow(GetPatch()); i++)
b1886074 394 {
3ef466c5 395 counter += tempPt->fNDigit;
4aa41877 396 AliHLTMemHandler::UpdateRowPointer(tempPt);
b1886074 397 }
3ef466c5 398
4aa41877 399 Int_t bound = (GetNEtaSegments()+1)*(AliHLTTransform::GetNRows(GetPatch())+1);
400 AliHLTEtaContainer *etaPt = new AliHLTEtaContainer[bound];
401 memset(etaPt,0,bound*sizeof(AliHLTEtaContainer));
3ef466c5 402
4aa41877 403 AliHLTDigit *digits = new AliHLTDigit[counter];
404 cout<<"Allocating "<<counter*sizeof(AliHLTDigit)<<" bytes to digitsarray"<<endl;
405 memset(digits,0,counter*sizeof(AliHLTDigit));
3e87ef69 406
917e711b 407 Int_t sector,row,totcharge,pad,time,charge;
408 Double_t r1,r2,phi1,phi2,eta,kappa,phi0;
b1886074 409 Float_t xyz[3];
3ef466c5 410
411 counter=0;
c52cf5d8 412 tempPt = GetDataPointer();
3ef466c5 413
3e87ef69 414 cout<<"Calculating digits in patch "<<GetPatch()<<endl;
4aa41877 415 for(Int_t i=AliHLTTransform::GetFirstRow(GetPatch()); i<=AliHLTTransform::GetLastRow(GetPatch()); i++)
b1886074 416 {
4aa41877 417 AliHLTDigitData *digPt = tempPt->fDigitData;
3ef466c5 418 for(UInt_t di=0; di<tempPt->fNDigit; di++)
b1886074 419 {
3ef466c5 420 charge = digPt[di].fCharge;
b1886074 421 pad = digPt[di].fPad;
422 time = digPt[di].fTime;
4aa41877 423 AliHLTTransform::Slice2Sector(GetSlice(),i,sector,row);
424 AliHLTTransform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
425 eta = AliHLTTransform::GetEta(xyz);
3e87ef69 426
917e711b 427 digits[counter].fRow = i;
428 digits[counter].fR = sqrt(xyz[0]*xyz[0] + xyz[1]*xyz[1]);
429 digits[counter].fPhi = atan2(xyz[1],xyz[0]);
430 digits[counter].fCharge = charge;
3e87ef69 431
432 if(!fEtaOverlap)
c980a70c 433 {
917e711b 434 Int_t etaindex = GetEtaIndex(eta);
3e87ef69 435
4aa41877 436 Int_t index = (GetNEtaSegments()+1)*(i-AliHLTTransform::GetFirstRow(GetPatch())) + etaindex;
3e87ef69 437
438 if(index > 0 && index < bound)
439 {
917e711b 440 if(etaPt[index].fFirst == 0)
441 etaPt[index].fFirst = &digits[counter];
3e87ef69 442 else
917e711b 443 (etaPt[index].fLast)->fNext = &digits[counter];
444 etaPt[index].fLast = &digits[counter];
3e87ef69 445 }
c980a70c 446 }
3e87ef69 447 else
448 {
917e711b 449 Int_t etaindex[2];
450 GetEtaIndexes(eta,etaindex);
3e87ef69 451 Int_t index[2];
4aa41877 452 index[0] = (GetNEtaSegments()+1)*(i-AliHLTTransform::GetFirstRow(GetPatch())) + etaindex[0];
453 index[1] = (GetNEtaSegments()+1)*(i-AliHLTTransform::GetFirstRow(GetPatch())) + etaindex[1];
3e87ef69 454 if(index[0] == index[1])
455 {
456 cerr<<"Same etaindexes "<<index[0]<<" "<<index[1]<<endl;
457 exit(5);
458 }
459
460 Int_t ind = index[0];
461 if(ind > 0 && ind < bound)
462 {
917e711b 463 if(etaPt[ind].fFirst == 0)
464 etaPt[ind].fFirst = &digits[counter];
3e87ef69 465 else
917e711b 466 (etaPt[ind].fLast)->fNext = &digits[counter];
467 etaPt[ind].fLast = &digits[counter];
3e87ef69 468 }
469
470 ind = index[1];
471 if(ind > 0 && ind < bound)
472 {
917e711b 473 if(etaPt[ind].fFirst == 0)
474 etaPt[ind].fFirst = &digits[counter];
3e87ef69 475 else
917e711b 476 (etaPt[ind].fLast)->fNext = &digits[counter];
477 etaPt[ind].fLast = &digits[counter];
3e87ef69 478 }
479 }
480
3ef466c5 481 counter++;
482 }
4aa41877 483 AliHLTMemHandler::UpdateRowPointer(tempPt);
3ef466c5 484 }
485
3e87ef69 486 cout<<"Doing the combinatorics"<<endl;
487
4aa41877 488 AliHLTDigit *dPt1,*dPt2;
3e87ef69 489
490 for(Int_t e=0; e<GetNEtaSegments(); e++)
3ef466c5 491 {
3e87ef69 492 for(Int_t i=minrow; i<=maxrow; i+=every)
3ef466c5 493 {
4aa41877 494 Int_t index1 = (GetNEtaSegments()+1)*(i-AliHLTTransform::GetFirstRow(GetPatch())) + e;
3ef466c5 495
4aa41877 496 for(dPt1 = (AliHLTDigit*)etaPt[index1].fFirst; dPt1 != 0; dPt1 = (AliHLTDigit*)dPt1->fNext)
1eef4efc 497 {
3e87ef69 498 for(Int_t j=i+every; j<=maxrow; j+=every)
1eef4efc 499 {
4aa41877 500 Int_t index2 = (GetNEtaSegments()+1)*(j-AliHLTTransform::GetFirstRow(GetPatch())) + e;
3e87ef69 501
4aa41877 502 for(dPt2 = (AliHLTDigit*)etaPt[index2].fFirst; dPt2 != 0; dPt2 = (AliHLTDigit*)dPt2->fNext)
1eef4efc 503 {
917e711b 504 if(dPt1->fRow == dPt2->fRow)
c980a70c 505 {
3e87ef69 506 cerr<<"same row; indexes "<<index1<<" "<<index2<<endl;
507 exit(5);
c980a70c 508 }
3e87ef69 509
510 //Get the correct histogrampointer:
4aa41877 511 AliHLTHistogram *hist = fParamSpace[e];
3e87ef69 512 if(!hist)
513 {
4aa41877 514 printf("AliHLTHoughTransformer::TransformCircleC() : No histogram at index %d\n",i);
3e87ef69 515 continue;
516 }
517
518 //Do the transform:
917e711b 519 r1 = dPt1->fR;
520 phi1 = dPt1->fPhi;
521 r2 = dPt2->fR;
522 phi2 = dPt2->fPhi;
523 phi0 = atan( (r2*sin(phi1)-r1*sin(phi2))/(r2*cos(phi1)-r1*cos(phi2)) );
524 kappa = 2*sin(phi2-phi0)/r2;
525 totcharge = dPt1->fCharge + dPt2->fCharge;
526 hist->Fill(kappa,phi0,totcharge);
3e87ef69 527
1eef4efc 528 }
529 }
530 }
b1886074 531 }
532 }
3e87ef69 533
534 cout<<"done"<<endl;
535 delete [] etaPt;
3ef466c5 536 delete [] digits;
3e87ef69 537
b1886074 538}
539
4aa41877 540void AliHLTHoughTransformer::TransformLine(Int_t *rowrange,Float_t *phirange)
4fc9a6a4 541{
542 //Do a line transform on the data.
543
3e87ef69 544
4aa41877 545 AliHLTDigitRowData *tempPt = GetDataPointer();
c52cf5d8 546 if(!tempPt)
4fc9a6a4 547 {
4aa41877 548 LOG(AliHLTLog::kError,"AliHLTHoughTransformer::TransformLine","Data")
237d3f5c 549 <<"No input data "<<ENDLOG;
550 return;
551 }
3e87ef69 552
4aa41877 553 Int_t minrow = AliHLTTransform::GetFirstRow(GetPatch());
554 Int_t maxrow = AliHLTTransform::GetLastRow(GetPatch());
917e711b 555 if(rowrange)
3e87ef69 556 {
917e711b 557 minrow = rowrange[0];
558 maxrow = rowrange[1];
4aa41877 559 if(minrow < AliHLTTransform::GetFirstRow(GetPatch()) || minrow >= AliHLTTransform::GetLastRow(GetPatch()))
560 minrow = AliHLTTransform::GetFirstRow(GetPatch());
561 if(maxrow < AliHLTTransform::GetFirstRow(GetPatch()) || maxrow >= AliHLTTransform::GetLastRow(GetPatch()))
562 maxrow = AliHLTTransform::GetLastRow(GetPatch());
3e87ef69 563 if(minrow > maxrow || maxrow==minrow)
564 {
4aa41877 565 cerr<<"AliHLTHoughTransformer::TransformCircleC : Bad row range "<<minrow<<" "<<maxrow<<endl;
3e87ef69 566 return;
567 }
568 }
569
570 for(Int_t i=minrow; i<=maxrow; i++)
4fc9a6a4 571 {
4aa41877 572 AliHLTDigitData *digPt = tempPt->fDigitData;
4fc9a6a4 573 if(i != (Int_t)tempPt->fRow)
574 {
4aa41877 575 printf("AliHLTHoughTransform::TransformLine : Mismatching padrow numbering\n");
4fc9a6a4 576 continue;
577 }
578 for(UInt_t j=0; j<tempPt->fNDigit; j++)
579 {
580 UShort_t charge = digPt[j].fCharge;
581 UChar_t pad = digPt[j].fPad;
582 UShort_t time = digPt[j].fTime;
3bb06991 583 if(charge < GetLowerThreshold())
4fc9a6a4 584 continue;
585 Int_t sector,row;
586 Float_t xyz[3];
4aa41877 587 AliHLTTransform::Slice2Sector(GetSlice(),i,sector,row);
588 AliHLTTransform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
3e87ef69 589
590 if(phirange)
591 {
4aa41877 592 Float_t phi = AliHLTTransform::GetPhi(xyz);
3e87ef69 593 if(phi < phirange[0] || phi > phirange[1])
594 continue;
595 }
4aa41877 596 Float_t eta = AliHLTTransform::GetEta(xyz);
917e711b 597 Int_t etaindex = GetEtaIndex(eta);//(Int_t)(eta/etaslice);
598 if(etaindex < 0 || etaindex >= GetNEtaSegments())
4fc9a6a4 599 continue;
600
4aa41877 601 xyz[0] = xyz[0] - AliHLTTransform::Row2X(minrow);
3e87ef69 602
4fc9a6a4 603 //Get the correct histogram:
4aa41877 604 AliHLTHistogram *hist = fParamSpace[etaindex];
4fc9a6a4 605 if(!hist)
606 {
4aa41877 607 printf("AliHLTHoughTransformer::TransformLine : Error getting histogram in index %d\n",etaindex);
4fc9a6a4 608 continue;
609 }
610 for(Int_t xbin=hist->GetFirstXbin(); xbin<hist->GetLastXbin(); xbin++)
611 {
612 Double_t theta = hist->GetBinCenterX(xbin);
613 Double_t rho = xyz[0]*cos(theta) + xyz[1]*sin(theta);
614 hist->Fill(theta,rho,charge);
615 }
616 }
4aa41877 617 AliHLTMemHandler::UpdateRowPointer(tempPt);
4fc9a6a4 618 }
619
620}
1eef4efc 621
4aa41877 622struct AliHLTLDigit {
917e711b 623 Int_t fRow; // Digit rowpad
624 Int_t fCharge; // Digit charge
625 Float_t fY; // Y position of the digit in the local coor system
4aa41877 626 AliHLTLDigit *fNext; // Next digit
3e87ef69 627};
4aa41877 628struct AliHLTLEtaContainer {
629 AliHLTLDigit *fFirst; //First digit
630 AliHLTLDigit *fLast; //Last digit
3e87ef69 631};
4aa41877 632void AliHLTHoughTransformer::TransformLineC(Int_t *rowrange,Float_t *phirange)
3e87ef69 633{
917e711b 634 //Circle transform ??
4aa41877 635 AliHLTDigitRowData *tempPt = GetDataPointer();
3e87ef69 636 if(!tempPt)
4aa41877 637 LOG(AliHLTLog::kError,"AliHLTHoughTransformer::TransformCircleC","Data")
3e87ef69 638 <<"No input data "<<ENDLOG;
639
640
641 Int_t counter=0;
4aa41877 642 for(Int_t i=AliHLTTransform::GetFirstRow(GetPatch()); i<=AliHLTTransform::GetLastRow(GetPatch()); i++)
3e87ef69 643 {
644 counter += tempPt->fNDigit;
4aa41877 645 AliHLTMemHandler::UpdateRowPointer(tempPt);
3e87ef69 646 }
647
4aa41877 648 Int_t bound = (GetNEtaSegments()+1)*(AliHLTTransform::GetNRows(GetPatch())+1);
649 AliHLTLEtaContainer *etaPt = new AliHLTLEtaContainer[bound];
650 memset(etaPt,0,bound*sizeof(AliHLTLEtaContainer));
3e87ef69 651
4aa41877 652 AliHLTLDigit *digits = new AliHLTLDigit[counter];
653 cout<<"Allocating "<<counter*sizeof(AliHLTLDigit)<<" bytes to digitsarray"<<endl;
654 memset(digits,0,counter*sizeof(AliHLTLDigit));
3e87ef69 655
656 Int_t sector,row;
657 Float_t xyz[3];
658
659 counter=0;
660 tempPt = GetDataPointer();
661
662 cout<<"Calculating digits in patch "<<GetPatch()<<endl;
4aa41877 663 for(Int_t i=AliHLTTransform::GetFirstRow(GetPatch()); i<=AliHLTTransform::GetLastRow(GetPatch()); i++)
3e87ef69 664 {
4aa41877 665 AliHLTDigitData *digPt = tempPt->fDigitData;
3e87ef69 666 for(UInt_t di=0; di<tempPt->fNDigit; di++)
667 {
668 Int_t charge = digPt[di].fCharge;
669 Int_t pad = digPt[di].fPad;
670 Int_t time = digPt[di].fTime;
4aa41877 671 AliHLTTransform::Slice2Sector(GetSlice(),i,sector,row);
672 AliHLTTransform::Raw2Local(xyz,sector,row,(Int_t)pad,(Int_t)time);
673 Double_t eta = AliHLTTransform::GetEta(xyz);
3e87ef69 674
675 Float_t phi = atan2(xyz[1],xyz[0]);
676 if(phi < phirange[0] || phi > phirange[1]) continue;
677
917e711b 678 digits[counter].fRow = i;
679 digits[counter].fY = xyz[1];
680 digits[counter].fCharge = charge;
3e87ef69 681
917e711b 682 Int_t etaindex = GetEtaIndex(eta);
4aa41877 683 Int_t index = (GetNEtaSegments()+1)*(i-AliHLTTransform::GetFirstRow(GetPatch())) + etaindex;
3e87ef69 684
685 if(index > 0 && index < bound)
686 {
917e711b 687 if(etaPt[index].fFirst == 0)
688 etaPt[index].fFirst = &digits[counter];
3e87ef69 689 else
917e711b 690 (etaPt[index].fLast)->fNext = &digits[counter];
691 etaPt[index].fLast = &digits[counter];
3e87ef69 692 }
693 counter++;
694 }
4aa41877 695 AliHLTMemHandler::UpdateRowPointer(tempPt);
3e87ef69 696 }
697
698 cout<<"Doing the combinatorics"<<endl;
699
4aa41877 700 AliHLTLDigit *dPt1,*dPt2;
3e87ef69 701
702 for(Int_t e=0; e<GetNEtaSegments(); e++)
703 {
704 for(Int_t i=rowrange[0]; i<=rowrange[1]; i++)
705 {
4aa41877 706 Int_t index1 = (GetNEtaSegments()+1)*(i-AliHLTTransform::GetFirstRow(GetPatch())) + e;
3e87ef69 707
4aa41877 708 for(dPt1 = (AliHLTLDigit*)etaPt[index1].fFirst; dPt1 != 0; dPt1 = (AliHLTLDigit*)dPt1->fNext)
3e87ef69 709 {
710 for(Int_t j=i+1; j<=rowrange[1]; j++)
711 {
4aa41877 712 Int_t index2 = (GetNEtaSegments()+1)*(j-AliHLTTransform::GetFirstRow(GetPatch())) + e;
3e87ef69 713
4aa41877 714 for(dPt2 = (AliHLTLDigit*)etaPt[index2].fFirst; dPt2 != 0; dPt2 = (AliHLTLDigit*)dPt2->fNext)
3e87ef69 715 {
917e711b 716 if(dPt1->fRow == dPt2->fRow)
3e87ef69 717 {
718 cerr<<"same row; indexes "<<index1<<" "<<index2<<endl;
719 exit(5);
720 }
721
722 //Get the correct histogrampointer:
4aa41877 723 AliHLTHistogram *hist = fParamSpace[e];
3e87ef69 724 if(!hist)
725 {
4aa41877 726 printf("AliHLTHoughTransformer::TransformCircleC() : No histogram at index %d\n",i);
3e87ef69 727 continue;
728 }
729
730 //Do the transform:
4aa41877 731 float x1 = AliHLTTransform::Row2X(dPt1->fRow) - AliHLTTransform::Row2X(rowrange[0]);
732 float x2 = AliHLTTransform::Row2X(dPt2->fRow) - AliHLTTransform::Row2X(rowrange[0]);
917e711b 733 float y1 = dPt1->fY;
734 float y2 = dPt2->fY;
3e87ef69 735 float theta = atan2(x2-x1,y1-y2);
736 float rho = x1*cos(theta)+y1*sin(theta);
737 hist->Fill(theta,rho,1);//dPt1->charge+dPt2->charge);
738 }
739 }
740 }
741 }
742 }
743
744 cout<<"done"<<endl;
745 delete [] etaPt;
746 delete [] digits;
747}
748
3cb5c013 749#ifdef do_mc
4aa41877 750Int_t AliHLTHoughTransformer::GetTrackID(Int_t etaindex,Double_t kappa,Double_t psi) const
1eef4efc 751{
917e711b 752 // Returns the MC label for a given peak found in the Hough space
c980a70c 753 if(!fDoMC)
754 {
4aa41877 755 cerr<<"AliHLTHoughTransformer::GetTrackID : Flag switched off"<<endl;
c980a70c 756 return -1;
757 }
758
917e711b 759 if(etaindex < 0 || etaindex > GetNEtaSegments())
1eef4efc 760 {
4aa41877 761 cerr<<"AliHLTHoughTransformer::GetTrackID : Wrong etaindex "<<etaindex<<endl;
1eef4efc 762 return -1;
763 }
4aa41877 764 AliHLTHistogram *hist = fParamSpace[etaindex];
1eef4efc 765 Int_t bin = hist->FindBin(kappa,psi);
766 Int_t label=-1;
767 Int_t max=0;
768 for(UInt_t i=0; i<MaxTrack; i++)
769 {
917e711b 770 Int_t nhits=fTrackID[etaindex][bin].fNHits[i];
1eef4efc 771 if(nhits == 0) break;
772 if(nhits > max)
773 {
774 max = nhits;
917e711b 775 label = fTrackID[etaindex][bin].fLabel[i];
1eef4efc 776 }
777 }
3e87ef69 778 //nhits = max;
1eef4efc 779 return label;
3cb5c013 780#else
4aa41877 781 Int_t AliHLTHoughTransformer::GetTrackID(Int_t /*etaindex*/,Double_t /*kappa*/,Double_t /*psi*/) const
3cb5c013 782{
783 // Returns the MC label for a given peak found in the Hough space
784 if(!fDoMC)
785 {
4aa41877 786 cerr<<"AliHLTHoughTransformer::GetTrackID : Flag switched off"<<endl;
3cb5c013 787 return -1;
788 }
789
4aa41877 790 cout<<"AliHLTHoughTransformer::GetTrackID : Compile with do_mc flag!"<<endl;
1eef4efc 791 return -1;
3cb5c013 792#endif
1eef4efc 793}
794