]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3Hough.cxx
Optimization related to the filling of the Hough transform space arrays
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Hough.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
b1886074 2
3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
3e87ef69 4//*-- Copyright &copy ALICE HLT Group
b1886074 5
e06900d5 6#include "AliL3StandardIncludes.h"
0309a5ee 7#include <sys/time.h>
f000f8a5 8
e06900d5 9#include "AliL3Logging.h"
b1886074 10#include "AliL3HoughMerger.h"
11#include "AliL3HoughIntMerger.h"
12#include "AliL3HoughGlobalMerger.h"
f80b98cb 13#include "AliL3Histogram.h"
f000f8a5 14#include "AliL3Hough.h"
15#include "AliL3HoughTransformer.h"
6c97129d 16#include "AliL3HoughClusterTransformer.h"
636080ea 17#include "AliL3HoughTransformerLUT.h"
b46b53c1 18#include "AliL3HoughTransformerVhdl.h"
0bd0c1ef 19#include "AliL3HoughTransformerRow.h"
f000f8a5 20#include "AliL3HoughMaxFinder.h"
3e87ef69 21#include "AliL3Benchmark.h"
95a00d93 22#ifdef use_aliroot
f80b98cb 23#include "AliL3FileHandler.h"
95a00d93 24#else
25#include "AliL3MemHandler.h"
26#endif
d96f6a4a 27#include "AliL3DataHandler.h"
f80b98cb 28#include "AliL3DigitData.h"
29#include "AliL3HoughEval.h"
30#include "AliL3Transform.h"
f80b98cb 31#include "AliL3TrackArray.h"
32#include "AliL3HoughTrack.h"
b2a02bce 33#include "AliL3DDLDataFileHandler.h"
95a00d93 34
a8ffd46b 35#include "TThread.h"
36
0bd0c1ef 37#if __GNUC__ == 3
e06900d5 38using namespace std;
39#endif
b1886074 40
aa641eb8 41/** /class AliL3Hough
42//<pre>
b1886074 43//_____________________________________________________________
44// AliL3Hough
45//
237d3f5c 46// Interface class for the Hough transform
b1886074 47//
237d3f5c 48// Example how to use:
49//
50// AliL3Hough *hough = new AliL3Hough(path,kTRUE,NumberOfEtaSegments);
51// hough->ReadData(slice);
52// hough->Transform();
53// hough->FindTrackCandidates();
54//
55// AliL3TrackArray *tracks = hough->GetTracks(patch);
0bd0c1ef 56//
aa641eb8 57//</pre>
58*/
f000f8a5 59
60ClassImp(AliL3Hough)
61
62AliL3Hough::AliL3Hough()
63{
b1886074 64 //Constructor
65
6dbc57b4 66 fBinary = kFALSE;
a6008206 67 fAddHistograms = kFALSE;
6dbc57b4 68 fDoIterative = kFALSE;
69 fWriteDigits = kFALSE;
70 fUse8bits = kFALSE;
71
72 fMemHandler = 0;
237d3f5c 73 fHoughTransformer = 0;
6dbc57b4 74 fEval = 0;
75 fPeakFinder = 0;
76 fTracks = 0;
b2a02bce 77 fGlobalTracks = 0;
6dbc57b4 78 fMerger = 0;
79 fInterMerger = 0;
80 fGlobalMerger = 0;
3e87ef69 81 fBenchmark = 0;
82
6dbc57b4 83 fNEtaSegments = 0;
84 fNPatches = 0;
a8ffd46b 85 fLastPatch =-1;
6dbc57b4 86 fVersion = 0;
87 fCurrentSlice = 0;
b2a02bce 88 fEvent = 0;
5a31e9df 89
0bd0c1ef 90 fKappaSpread = 6;
91 fPeakRatio = 0.5;
92 fInputFile = 0;
93 fInputPtr = 0;
a109e73e 94 fRawEvent = 0;
5a31e9df 95
6dbc57b4 96 SetTransformerParams();
97 SetThreshold();
636080ea 98 SetNSaveIterations();
3e87ef69 99 SetPeakThreshold();
1f1942b8 100#ifdef use_aliroot
101 //just be sure that index is empty for new event
102 AliL3FileHandler::CleanStaticIndex();
de3c3890 103#ifdef use_newio
104 fRunLoader = 0;
105#endif
1f1942b8 106#endif
a8ffd46b 107 fThread = 0;
f000f8a5 108}
109
917e711b 110AliL3Hough::AliL3Hough(Char_t *path,Bool_t binary,Int_t netasegments,Bool_t bit8,Int_t tv,Char_t *infile,Char_t *ptr)
b46b53c1 111{
917e711b 112 //Normal constructor
b46b53c1 113 fBinary = binary;
114 strcpy(fPath,path);
917e711b 115 fNEtaSegments = netasegments;
b46b53c1 116 fAddHistograms = kFALSE;
6dbc57b4 117 fDoIterative = kFALSE;
118 fWriteDigits = kFALSE;
119 fUse8bits = bit8;
120 fVersion = tv;
5a31e9df 121 fKappaSpread=6;
122 fPeakRatio=0.5;
0bd0c1ef 123 if(!fBinary) {
124 if(infile) {
125 fInputFile = infile;
126 fInputPtr = 0;
127 }
128 else {
129 fInputFile = 0;
130 fInputPtr = ptr;
131 }
132 }
133 else {
b2a02bce 134 fInputFile = 0;
0bd0c1ef 135 fInputPtr = 0;
136 }
1f1942b8 137#ifdef use_aliroot
138 //just be sure that index is empty for new event
139 AliL3FileHandler::CleanStaticIndex();
de3c3890 140#ifdef use_newio
141 fRunLoader = 0;
142#endif
1f1942b8 143#endif
a8ffd46b 144 fThread = 0;
b46b53c1 145}
f000f8a5 146
f000f8a5 147AliL3Hough::~AliL3Hough()
148{
237d3f5c 149 //dtor
150
b1886074 151 CleanUp();
152 if(fMerger)
153 delete fMerger;
1f1942b8 154 //cout << "Cleaned class merger " << endl;
b1886074 155 if(fInterMerger)
156 delete fInterMerger;
1f1942b8 157 //cout << "Cleaned class inter " << endl;
a6008206 158 if(fPeakFinder)
159 delete fPeakFinder;
1f1942b8 160 //cout << "Cleaned class peak " << endl;
1c404dd5 161 if(fGlobalMerger)
162 delete fGlobalMerger;
1f1942b8 163 //cout << "Cleaned class global " << endl;
3e87ef69 164 if(fBenchmark)
165 delete fBenchmark;
1f1942b8 166 //cout << "Cleaned class bench " << endl;
b2a02bce 167 if(fGlobalTracks)
168 delete fGlobalTracks;
1f1942b8 169 //cout << "Cleaned class globaltracks " << endl;
a8ffd46b 170 if(fThread) {
171 // fThread->Delete();
172 delete fThread;
173 fThread = 0;
174 }
f000f8a5 175}
176
b1886074 177void AliL3Hough::CleanUp()
f000f8a5 178{
b1886074 179 //Cleanup memory
180
1c404dd5 181 for(Int_t i=0; i<fNPatches; i++)
4fc9a6a4 182 {
b1886074 183 if(fTracks[i]) delete fTracks[i];
1f1942b8 184 //cout << "Cleaned tracks " << i << endl;
b1886074 185 if(fEval[i]) delete fEval[i];
1f1942b8 186 //cout << "Cleaned eval " << i << endl;
b1886074 187 if(fHoughTransformer[i]) delete fHoughTransformer[i];
1f1942b8 188 //cout << "Cleaned traf " << i << endl;
b1886074 189 if(fMemHandler[i]) delete fMemHandler[i];
1f1942b8 190 //cout << "Cleaned mem " << i << endl;
4fc9a6a4 191 }
b1886074 192
3e87ef69 193 if(fTracks) delete [] fTracks;
1f1942b8 194 //cout << "Cleaned class tracks " << endl;
3e87ef69 195 if(fEval) delete [] fEval;
1f1942b8 196 //cout << "Cleaned class eval " << endl;
3e87ef69 197 if(fHoughTransformer) delete [] fHoughTransformer;
1f1942b8 198 //cout << "Cleaned cleass trafo " << endl;
3e87ef69 199 if(fMemHandler) delete [] fMemHandler;
1f1942b8 200 //cout << "Cleaned class mem " << endl;
f000f8a5 201}
202
a109e73e 203void AliL3Hough::Init(Int_t netasegments,Int_t tv,AliRawEvent *rawevent,Float_t zvertex)
204{
205 //Normal constructor
206 fNEtaSegments = netasegments;
207 fVersion = tv;
208 fRawEvent = rawevent;
209 fZVertex = zvertex;
210
211 Init();
212}
213
917e711b 214void AliL3Hough::Init(Char_t *path,Bool_t binary,Int_t netasegments,Bool_t bit8,Int_t tv,Char_t *infile,Char_t *ptr,Float_t zvertex)
f000f8a5 215{
917e711b 216 //Normal init of the AliL3Hough
d96f6a4a 217 fBinary = binary;
218 strcpy(fPath,path);
917e711b 219 fNEtaSegments = netasegments;
6dbc57b4 220 fWriteDigits = kFALSE;
221 fUse8bits = bit8;
222 fVersion = tv;
0bd0c1ef 223 if(!fBinary) {
224 if(infile) {
225 fInputFile = infile;
226 fInputPtr = 0;
227 }
228 else {
229 fInputFile = 0;
230 fInputPtr = ptr;
231 }
232 }
233 else {
b2a02bce 234 fInputFile = 0;
0bd0c1ef 235 fInputPtr = 0;
236 }
237 fZVertex = zvertex;
6dbc57b4 238
239 Init(); //do the rest
240}
241
e06900d5 242void AliL3Hough::Init(Bool_t doit, Bool_t addhists)
a4639de2 243{
917e711b 244 // Init
6dbc57b4 245 fDoIterative = doit;
246 fAddHistograms = addhists;
b46b53c1 247
26abc209 248 fNPatches = AliL3Transform::GetNPatches();
237d3f5c 249 fHoughTransformer = new AliL3HoughBaseTransformer*[fNPatches];
95a00d93 250 fMemHandler = new AliL3MemHandler*[fNPatches];
3e87ef69 251
1c404dd5 252 fTracks = new AliL3TrackArray*[fNPatches];
253 fEval = new AliL3HoughEval*[fNPatches];
b2a02bce 254
255 fGlobalTracks = new AliL3TrackArray("AliL3HoughTrack");
256
a8ffd46b 257 AliL3HoughBaseTransformer *lasttransformer = 0;
258
1c404dd5 259 for(Int_t i=0; i<fNPatches; i++)
f80b98cb 260 {
6dbc57b4 261 switch (fVersion){ //choose Transformer
b46b53c1 262 case 1:
636080ea 263 fHoughTransformer[i] = new AliL3HoughTransformerLUT(0,i,fNEtaSegments);
b46b53c1 264 break;
6c97129d 265 case 2:
266 fHoughTransformer[i] = new AliL3HoughClusterTransformer(0,i,fNEtaSegments);
267 break;
636080ea 268 case 3:
269 fHoughTransformer[i] = new AliL3HoughTransformerVhdl(0,i,fNEtaSegments,fNSaveIterations);
270 break;
5a31e9df 271 case 4:
0bd0c1ef 272 fHoughTransformer[i] = new AliL3HoughTransformerRow(0,i,fNEtaSegments,kFALSE,fZVertex);
5a31e9df 273 break;
b46b53c1 274 default:
3e87ef69 275 fHoughTransformer[i] = new AliL3HoughTransformer(0,i,fNEtaSegments,kFALSE,kFALSE);
b46b53c1 276 }
aa641eb8 277
a8ffd46b 278 fHoughTransformer[i]->SetLastTransformer(lasttransformer);
279 lasttransformer = fHoughTransformer[i];
de3c3890 280 // fHoughTransformer[i]->CreateHistograms(fNBinX[i],fLowPt[i],fNBinY[i],-fPhi[i],fPhi[i]);
281 fHoughTransformer[i]->CreateHistograms(fNBinX[i],-fLowPt[i],fLowPt[i],fNBinY[i],-fPhi[i],fPhi[i]);
b2a02bce 282 //fHoughTransformer[i]->CreateHistograms(fLowPt[i],fUpperPt[i],fPtRes[i],fNBinY[i],fPhi[i]);
1f1942b8 283
b2a02bce 284 fHoughTransformer[i]->SetLowerThreshold(fThreshold[i]);
285 fHoughTransformer[i]->SetUpperThreshold(100);
286
0309a5ee 287 LOG(AliL3Log::kInformational,"AliL3Hough::Init","Version")
6dbc57b4 288 <<"Initializing Hough transformer version "<<fVersion<<ENDLOG;
a4639de2 289
b1886074 290 fEval[i] = new AliL3HoughEval();
291 fTracks[i] = new AliL3TrackArray("AliL3HoughTrack");
d96f6a4a 292 if(fUse8bits)
293 fMemHandler[i] = new AliL3DataHandler();
294 else
95a00d93 295#ifdef use_aliroot
d96f6a4a 296 {
a109e73e 297 if(!fRawEvent) {
298 if(!fInputFile) {
299 if(!fInputPtr) {
300 /* In case of reading digits file */
301 fMemHandler[i] = new AliL3FileHandler(kTRUE); //use static index
302 if(!fBinary) {
de3c3890 303#if use_newio
a109e73e 304 if(!fRunLoader) {
de3c3890 305#endif
a109e73e 306 Char_t filename[1024];
307 sprintf(filename,"%s/digitfile.root",fPath);
308 fMemHandler[i]->SetAliInput(filename);
de3c3890 309#if use_newio
a109e73e 310 }
311 else {
312 fMemHandler[i]->SetAliInput(fRunLoader);
313 }
de3c3890 314#endif
a109e73e 315 }
316 }
317 else {
318 /* In case of reading from DATE */
319 fMemHandler[i] = new AliL3DDLDataFileHandler();
320 fMemHandler[i]->SetReaderInput(fInputPtr,-1);
0bd0c1ef 321 }
322 }
323 else {
a109e73e 324 /* In case of reading rawdata from ROOT file */
0bd0c1ef 325 fMemHandler[i] = new AliL3DDLDataFileHandler();
a109e73e 326 fMemHandler[i]->SetReaderInput(fInputFile);
3bb06991 327 }
b2a02bce 328 }
329 else {
a109e73e 330 /* In case of reading rawdata using AliRawEvent */
b2a02bce 331 fMemHandler[i] = new AliL3DDLDataFileHandler();
a109e73e 332 fMemHandler[i]->SetReaderInput(fRawEvent);
b2a02bce 333 }
d96f6a4a 334 }
95a00d93 335#else
336 fMemHandler[i] = new AliL3MemHandler();
337#endif
a6008206 338 }
6dbc57b4 339
de3c3890 340 fPeakFinder = new AliL3HoughMaxFinder("KappaPhi",50000);
1c404dd5 341 fMerger = new AliL3HoughMerger(fNPatches);
b1886074 342 fInterMerger = new AliL3HoughIntMerger();
237d3f5c 343 fGlobalMerger = 0;
3e87ef69 344 fBenchmark = new AliL3Benchmark();
b2a02bce 345}
346
347void AliL3Hough::SetTransformerParams(Float_t ptres,Float_t ptmin,Float_t ptmax,Int_t ny,Int_t patch)
348{
917e711b 349 // Setup the parameters for the Hough Transformer
b2a02bce 350 Int_t mrow;
351 Float_t psi=0;
352 if(patch==-1)
353 mrow = 80;
354 else
355 mrow = AliL3Transform::GetLastRow(patch);
356 if(ptmin)
357 {
358 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
359 Double_t kappa = -1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
360 psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
361 cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
362 }
363
364 if(patch==-1)
365 {
366 Int_t i=0;
367 while(i < 6)
368 {
369 fPtRes[i] = ptres;
370 fLowPt[i] = ptmin;
371 fUpperPt[i] = ptmax;
372 fNBinY[i] = ny;
373 fPhi[i] = psi;
374 fNBinX[i]=0;
375 i++;
376 }
377 return;
378 }
379
380 fPtRes[patch] = ptres;
381 fLowPt[patch] = ptmin;
382 fUpperPt[patch] = ptmax;
383 fNBinY[patch] = ny;
384 fPhi[patch] = psi;
385}
de3c3890 386/*
b2a02bce 387void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t ptmin,Int_t patch)
388{
917e711b 389 // Setup the parameters for the Hough Transformer
b2a02bce 390
391 Int_t mrow=80;
392 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
393 Double_t kappa = -1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
394 Double_t psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
395 cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
396
397 Int_t i=0;
398 while(i < 6)
399 {
400 fLowPt[i] = ptmin;
401 fNBinY[i] = ny;
402 fNBinX[i] = nx;
403 fPhi[i] = psi;
404 i++;
405 }
406}
de3c3890 407*/
0615a438 408void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t ptmin,Int_t /*patch*/)
de3c3890 409{
917e711b 410 // Setup the parameters for the Hough Transformer
de3c3890 411
412
413 Int_t mrow=79;
414 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
415 Double_t alpha1 = AliL3Transform::GetMaxY(mrow)/pow(lineradius,2);
416 Double_t kappa = 1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
417 Double_t psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
0fdf7509 418 // cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
de3c3890 419 AliL3HoughTrack track;
420 track.SetTrackParameters(kappa,psi,1);
421 Float_t hit[3];
422 Int_t mrow2 = 158;
423 track.GetCrossingPoint(mrow2,hit);
424 Double_t lineradius2 = sqrt(pow(AliL3Transform::Row2X(mrow2),2) + pow(AliL3Transform::GetMaxY(mrow2),2));
425 Double_t alpha2 = hit[1]/pow(lineradius2,2);
0fdf7509 426 // cout<<"Calculated alphas range "<<alpha1<<" "<<alpha2<<" in patch "<<patch<<endl;
de3c3890 427
428 Int_t i=0;
429 while(i < 6)
430 {
431 fLowPt[i] = 1.15*alpha1;
432 fNBinY[i] = ny;
433 fNBinX[i] = nx;
434 fPhi[i] = 1.15*alpha2;
435 i++;
436 }
437}
b2a02bce 438
439void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t lpt,Float_t phi)
440{
441 Int_t i=0;
442 while(i < 6)
443 {
444 fLowPt[i] = lpt;
445 fNBinY[i] = ny;
446 fNBinX[i] = nx;
447 fPhi[i] = phi;
448 i++;
449 }
450}
451
452void AliL3Hough::SetThreshold(Int_t t3,Int_t patch)
453{
917e711b 454 // Set digits threshold
b2a02bce 455 if(patch==-1)
456 {
457 Int_t i=0;
458 while(i < 6)
459 fThreshold[i++]=t3;
460 return;
461 }
462 fThreshold[patch]=t3;
463}
3e87ef69 464
b2a02bce 465void AliL3Hough::SetPeakThreshold(Int_t threshold,Int_t patch)
466{
917e711b 467 // Set Peak Finder threshold
b2a02bce 468 if(patch==-1)
469 {
470 Int_t i=0;
471 while(i < 6)
472 fPeakThreshold[i++]=threshold;
473 return;
474 }
475 fPeakThreshold[patch]=threshold;
3e87ef69 476}
477
478void AliL3Hough::DoBench(Char_t *name)
479{
480 fBenchmark->Analyze(name);
a6008206 481}
482
483void AliL3Hough::Process(Int_t minslice,Int_t maxslice)
484{
485 //Process all slices [minslice,maxslice].
1c404dd5 486 fGlobalMerger = new AliL3HoughGlobalMerger(minslice,maxslice);
b1886074 487
a6008206 488 for(Int_t i=minslice; i<=maxslice; i++)
489 {
b1886074 490 ReadData(i);
491 Transform();
0bd0c1ef 492 if(fAddHistograms) {
493 if(fVersion != 4)
494 AddAllHistograms();
495 else
496 AddAllHistogramsRows();
497 }
a6008206 498 FindTrackCandidates();
3e87ef69 499 //Evaluate();
500 //fGlobalMerger->FillTracks(fTracks[0],i);
f80b98cb 501 }
4fc9a6a4 502}
f80b98cb 503
e06900d5 504void AliL3Hough::ReadData(Int_t slice,Int_t eventnr)
4fc9a6a4 505{
b1886074 506 //Read data from files, binary or root.
3bb06991 507
1f1942b8 508#ifdef use_aliroot
509 if(fEvent!=eventnr) //just be sure that index is empty for new event
510 AliL3FileHandler::CleanStaticIndex();
511#endif
3bb06991 512 fCurrentSlice = slice;
1f1942b8 513
1c404dd5 514 for(Int_t i=0; i<fNPatches; i++)
f80b98cb 515 {
4fc9a6a4 516 fMemHandler[i]->Free();
517 UInt_t ndigits=0;
518 AliL3DigitRowData *digits =0;
519 Char_t name[256];
3fe49b5b 520 fMemHandler[i]->Init(slice,i);
a6008206 521 if(fBinary)//take input data from binary files
4fc9a6a4 522 {
d96f6a4a 523 if(fUse8bits)
b2a02bce 524 sprintf(name,"%s/binaries/digits_c8_%d_%d_%d.raw",fPath,eventnr,slice,i);
d96f6a4a 525 else
b2a02bce 526 sprintf(name,"%s/binaries/digits_%d_%d_%d.raw",fPath,eventnr,slice,i);
636080ea 527
4fc9a6a4 528 fMemHandler[i]->SetBinaryInput(name);
529 digits = (AliL3DigitRowData *)fMemHandler[i]->CompBinary2Memory(ndigits);
530 fMemHandler[i]->CloseBinaryInput();
531 }
532 else //read data from root file
533 {
95a00d93 534#ifdef use_aliroot
5a31e9df 535 if(fEvent!=eventnr)
536 fMemHandler[i]->FreeDigitsTree();//or else the new event is not loaded
3e87ef69 537 digits=(AliL3DigitRowData *)fMemHandler[i]->AliAltroDigits2Memory(ndigits,eventnr);
95a00d93 538#else
539 cerr<<"You cannot read from rootfile now"<<endl;
540#endif
4fc9a6a4 541 }
aa641eb8 542
a8ffd46b 543 //Set the pointer to the TPCRawStream in case of fast raw data reading
544 fHoughTransformer[i]->SetTPCRawStream(fMemHandler[i]->GetTPCRawStream());
545
636080ea 546 //set input data and init transformer
547 fHoughTransformer[i]->SetInputData(ndigits,digits);
548 fHoughTransformer[i]->Init(slice,i,fNEtaSegments);
b1886074 549 }
5a31e9df 550
551 fEvent=eventnr;
b1886074 552}
553
917e711b 554void AliL3Hough::Transform(Int_t *rowrange)
b1886074 555{
556 //Transform all data given to the transformer within the given slice
557 //(after ReadData(slice))
0309a5ee 558
559 Double_t initTime,cpuTime;
560 initTime = GetCpuTime();
a8ffd46b 561 Int_t patchorder[6] = {5,2,0,1,3,4}; //The order in which patches are processed
562 // Int_t patchorder[6] = {0,1,2,3,4,5}; //The order in which patches are processed
563 // Int_t patchorder[6] = {5,4,3,2,1,0}; //The order in which patches are processed
564 // Int_t patchorder[6] = {5,2,4,3,1,0}; //The order in which patches are processed
565 fLastPatch=-1;
1c404dd5 566 for(Int_t i=0; i<fNPatches; i++)
b1886074 567 {
0bd0c1ef 568 // In case of Row transformer reset the arrays only once
a8ffd46b 569 if((fVersion != 4) || (i == 0)) {
570 fBenchmark->Start("Hough Reset");
571 fHoughTransformer[0]->Reset();//Reset the histograms
572 fBenchmark->Stop("Hough Reset");
573 }
3e87ef69 574 fBenchmark->Start("Hough Transform");
a8ffd46b 575 PrepareForNextPatch(patchorder[i]);
576 if(!rowrange) {
577 char buf[256];
578 sprintf(buf,"Patch %d",patchorder[i]);
579 fBenchmark->Start(buf);
580 fHoughTransformer[patchorder[i]]->SetLastPatch(fLastPatch);
581 fHoughTransformer[patchorder[i]]->TransformCircle();
582 fBenchmark->Stop(buf);
583 }
237d3f5c 584 else
917e711b 585 fHoughTransformer[i]->TransformCircleC(rowrange,1);
3e87ef69 586 fBenchmark->Stop("Hough Transform");
a8ffd46b 587 fLastPatch=patchorder[i];
b1886074 588 }
0309a5ee 589 cpuTime = GetCpuTime() - initTime;
590 LOG(AliL3Log::kInformational,"AliL3Hough::Transform()","Timing")
591 <<"Transform done in average per patch of "<<cpuTime*1000/fNPatches<<" ms"<<ENDLOG;
b1886074 592}
593
594void AliL3Hough::MergePatches()
595{
917e711b 596 // Merge patches if they are not summed
b1886074 597 if(fAddHistograms) //Nothing to merge here
598 return;
b1886074 599 fMerger->MergePatches(kTRUE);
b1886074 600}
601
602void AliL3Hough::MergeInternally()
603{
917e711b 604 // Merge patches internally
b1886074 605 if(fAddHistograms)
606 fInterMerger->FillTracks(fTracks[0]);
607 else
608 fInterMerger->FillTracks(fMerger->GetOutTracks());
609
610 fInterMerger->MMerge();
611}
612
613void AliL3Hough::ProcessSliceIter()
614{
615 //Process current slice (after ReadData(slice)) iteratively.
616
6c97129d 617 if(!fAddHistograms)
b1886074 618 {
6c97129d 619 for(Int_t i=0; i<fNPatches; i++)
620 {
621 ProcessPatchIter(i);
622 fMerger->FillTracks(fTracks[i],i); //Copy tracks to merger
623 }
624 }
625 else
626 {
627 for(Int_t i=0; i<10; i++)
628 {
629 Transform();
630 AddAllHistograms();
631 InitEvaluate();
632 AliL3HoughBaseTransformer *tr = fHoughTransformer[0];
633 for(Int_t j=0; j<fNEtaSegments; j++)
634 {
635 AliL3Histogram *hist = tr->GetHistogram(j);
636 if(hist->GetNEntries()==0) continue;
637 fPeakFinder->Reset();
638 fPeakFinder->SetHistogram(hist);
639 fPeakFinder->FindAbsMaxima();
640 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[0]->NextTrack();
641 track->SetTrackParameters(fPeakFinder->GetXPeak(0),fPeakFinder->GetYPeak(0),fPeakFinder->GetWeight(0));
642 track->SetEtaIndex(j);
643 track->SetEta(tr->GetEta(j,fCurrentSlice));
644 for(Int_t k=0; k<fNPatches; k++)
645 {
646 fEval[i]->SetNumOfPadsToLook(2);
647 fEval[i]->SetNumOfRowsToMiss(2);
648 fEval[i]->RemoveFoundTracks();
3e87ef69 649 /*
6c97129d 650 Int_t nrows=0;
651 if(!fEval[i]->LookInsideRoad(track,nrows))
652 {
653 fTracks[0]->Remove(fTracks[0]->GetNTracks()-1);
654 fTracks[0]->Compress();
655 }
3e87ef69 656 */
6c97129d 657 }
658 }
659
660 }
661
f80b98cb 662 }
4fc9a6a4 663}
664
b1886074 665void AliL3Hough::ProcessPatchIter(Int_t patch)
666{
667 //Process patch in a iterative way.
668 //transform + peakfinding + evaluation + transform +...
669
917e711b 670 Int_t numoftries = 5;
237d3f5c 671 AliL3HoughBaseTransformer *tr = fHoughTransformer[patch];
b1886074 672 AliL3TrackArray *tracks = fTracks[patch];
673 tracks->Reset();
674 AliL3HoughEval *ev = fEval[patch];
675 ev->InitTransformer(tr);
6c97129d 676 //ev->RemoveFoundTracks();
677 ev->SetNumOfRowsToMiss(3);
b5a207b4 678 ev->SetNumOfPadsToLook(2);
b1886074 679 AliL3Histogram *hist;
917e711b 680 for(Int_t t=0; t<numoftries; t++)
b1886074 681 {
682 tr->Reset();
683 tr->TransformCircle();
684 for(Int_t i=0; i<fNEtaSegments; i++)
685 {
686 hist = tr->GetHistogram(i);
687 if(hist->GetNEntries()==0) continue;
6c97129d 688 fPeakFinder->Reset();
b1886074 689 fPeakFinder->SetHistogram(hist);
6c97129d 690 fPeakFinder->FindAbsMaxima();
691 //fPeakFinder->FindPeak1();
b1886074 692 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->NextTrack();
6c97129d 693 track->SetTrackParameters(fPeakFinder->GetXPeak(0),fPeakFinder->GetYPeak(0),fPeakFinder->GetWeight(0));
694 track->SetEtaIndex(i);
695 track->SetEta(tr->GetEta(i,fCurrentSlice));
3e87ef69 696 /*
6c97129d 697 Int_t nrows=0;
698 if(!ev->LookInsideRoad(track,nrows))
b1886074 699 {
700 tracks->Remove(tracks->GetNTracks()-1);
701 tracks->Compress();
702 }
3e87ef69 703 */
b1886074 704 }
705 }
6c97129d 706 fTracks[0]->QSort();
b1886074 707 LOG(AliL3Log::kInformational,"AliL3Hough::ProcessPatch","NTracks")
708 <<AliL3Log::kDec<<"Found "<<tracks->GetNTracks()<<" tracks in patch "<<patch<<ENDLOG;
709}
710
a6008206 711void AliL3Hough::AddAllHistograms()
4fc9a6a4 712{
a6008206 713 //Add the histograms within one etaslice.
714 //Resulting histogram are in patch=0.
b1886074 715
0309a5ee 716 Double_t initTime,cpuTime;
717 initTime = GetCpuTime();
3e87ef69 718 fBenchmark->Start("Add Histograms");
a6008206 719 for(Int_t i=0; i<fNEtaSegments; i++)
720 {
721 AliL3Histogram *hist0 = fHoughTransformer[0]->GetHistogram(i);
1c404dd5 722 for(Int_t j=1; j<fNPatches; j++)
a6008206 723 {
724 AliL3Histogram *hist = fHoughTransformer[j]->GetHistogram(i);
725 hist0->Add(hist);
726 }
727 }
3e87ef69 728 fBenchmark->Stop("Add Histograms");
b1886074 729 fAddHistograms = kTRUE;
0309a5ee 730 cpuTime = GetCpuTime() - initTime;
731 LOG(AliL3Log::kInformational,"AliL3Hough::AddAllHistograms()","Timing")
732 <<"Adding histograms in "<<cpuTime*1000<<" ms"<<ENDLOG;
a6008206 733}
734
0bd0c1ef 735void AliL3Hough::AddAllHistogramsRows()
736{
737 //Add the histograms within one etaslice.
738 //Resulting histogram are in patch=0.
739
740 Double_t initTime,cpuTime;
741 initTime = GetCpuTime();
742 fBenchmark->Start("Add HistogramsRows");
743
a8ffd46b 744 UChar_t lastpatchlastrow = AliL3Transform::GetLastRowOnDDL(fLastPatch)+1;
745
de3c3890 746 UChar_t *tracklastrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackLastRow();
747
0bd0c1ef 748 for(Int_t i=0; i<fNEtaSegments; i++)
749 {
0bd0c1ef 750 UChar_t *gapcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetGapCount(i);
de3c3890 751 UChar_t *currentrowcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetCurrentRowCount(i);
0bd0c1ef 752
753 AliL3Histogram *hist = fHoughTransformer[0]->GetHistogram(i);
754 Int_t xmin = hist->GetFirstXbin();
755 Int_t xmax = hist->GetLastXbin();
756 Int_t ymin = hist->GetFirstYbin();
757 Int_t ymax = hist->GetLastYbin();
a8ffd46b 758 Int_t nxbins = hist->GetNbinsX()+2;
0bd0c1ef 759
760 for(Int_t ybin=ymin; ybin<=ymax; ybin++)
761 {
762 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
763 {
a8ffd46b 764 Int_t bin = xbin + ybin*nxbins; //Int_t bin = hist->GetBin(xbin,ybin);
765 if(gapcount[bin] < MAX_N_GAPS) {
766 if(tracklastrow[bin] > lastpatchlastrow) {
767 if(lastpatchlastrow > currentrowcount[bin])
768 gapcount[bin] += (lastpatchlastrow-currentrowcount[bin]-1);
769 }
770 else {
771 if(tracklastrow[bin] > currentrowcount[bin])
772 gapcount[bin] += (tracklastrow[bin]-currentrowcount[bin]-1);
773 }
774 if(gapcount[bin] < MAX_N_GAPS)
775 hist->AddBinContent(bin,(159-gapcount[bin]));
776 }
0bd0c1ef 777 }
778 }
779 }
780
781 fBenchmark->Stop("Add HistogramsRows");
782 fAddHistograms = kTRUE;
783 cpuTime = GetCpuTime() - initTime;
784 LOG(AliL3Log::kInformational,"AliL3Hough::AddAllHistogramsRows()","Timing")
785 <<"Adding histograms in "<<cpuTime*1000<<" ms"<<ENDLOG;
786}
787
a8ffd46b 788void AliL3Hough::PrepareForNextPatch(Int_t nextpatch)
789{
790 char buf[256];
791 sprintf(buf,"Prepare For Patch %d",nextpatch);
792 fBenchmark->Start(buf);
793
794 UChar_t lastpatchlastrow;
795 if(fLastPatch == -1)
796 lastpatchlastrow = 0;
797 else
798 lastpatchlastrow = AliL3Transform::GetLastRowOnDDL(fLastPatch)+1;
799 UChar_t nextpatchfirstrow;
800 if(nextpatch==0)
801 nextpatchfirstrow = 0;
802 else
803 nextpatchfirstrow = AliL3Transform::GetFirstRowOnDDL(nextpatch)-1;
804
805 UChar_t *trackfirstrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackFirstRow();
806 UChar_t *tracklastrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackLastRow();
807
808 for(Int_t i=0; i<fNEtaSegments; i++)
809 {
810 UChar_t *gapcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetGapCount(i);
811 UChar_t *currentrowcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetCurrentRowCount(i);
812 UChar_t *prevbin = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetPrevBin(i);
813 UChar_t *nextbin = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetNextBin(i);
814 UChar_t *nextrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetNextRow(i);
815
816 AliL3Histogram *hist = fHoughTransformer[0]->GetHistogram(i);
817 Int_t xmin = hist->GetFirstXbin();
818 Int_t xmax = hist->GetLastXbin();
819 Int_t ymin = hist->GetFirstYbin();
820 Int_t ymax = hist->GetLastYbin();
821 Int_t nxbins = hist->GetNbinsX()+2;
822
b2b60653 823 if(fLastPatch != -1) {
824 UChar_t lastyvalue = 0;
825 Int_t endybin = ymin - 1;
826 for(Int_t ybin=nextrow[ymin]; ybin<=ymax; ybin = nextrow[++ybin])
827 {
828 UChar_t lastxvalue = 0;
829 UChar_t maxvalue = 0;
830 Int_t endxbin = xmin - 1;
831 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
832 {
833 Int_t bin = xbin + ybin*nxbins;
834 UChar_t value = 0;
835 if(gapcount[bin] < MAX_N_GAPS) {
836 if(tracklastrow[bin] > lastpatchlastrow) {
837 if(lastpatchlastrow > currentrowcount[bin])
838 gapcount[bin] += (lastpatchlastrow-currentrowcount[bin]-1);
839 }
840 else {
841 if(tracklastrow[bin] > currentrowcount[bin])
842 gapcount[bin] += (tracklastrow[bin]-currentrowcount[bin]-1);
843 }
844 if(gapcount[bin] < MAX_N_GAPS) {
845 value = 1;
846 maxvalue = 1;
847 if(trackfirstrow[bin] < nextpatchfirstrow)
848 currentrowcount[bin] = nextpatchfirstrow;
849 else
850 currentrowcount[bin] = trackfirstrow[bin];
851 }
a8ffd46b 852 }
a8ffd46b 853 if(value > 0)
854 {
855 nextbin[xbin + ybin*nxbins] = (UChar_t)xbin;
856 prevbin[xbin + ybin*nxbins] = (UChar_t)xbin;
857 if(value > lastxvalue)
858 {
859 UChar_t *tempnextbin = nextbin + endxbin + 1 + ybin*nxbins;
860 memset(tempnextbin,(UChar_t)xbin,xbin-endxbin-1);
861 }
862 endxbin = xbin;
863 }
864 else
865 {
866 prevbin[xbin + ybin*nxbins] = (UChar_t)endxbin;
867 }
868 lastxvalue = value;
869 }
a8ffd46b 870 UChar_t *tempnextbin = nextbin + endxbin + 1 + ybin*nxbins;
871 memset(tempnextbin,(UChar_t)(xmax+1),xmax-endxbin);
872 if(maxvalue > 0)
873 {
874 nextrow[ybin] = (UChar_t)ybin;
875 if(maxvalue > lastyvalue)
876 {
877 UChar_t *tempnextrow = nextrow + endybin + 1;
878 memset(tempnextrow,(UChar_t)ybin,ybin-endybin-1);
879 }
880 endybin = ybin;
881 }
882 lastyvalue = maxvalue;
883 }
b2b60653 884 UChar_t *tempnextrow = nextrow + endybin + 1;
885 memset(tempnextrow,(UChar_t)(ymax+1),ymax-endybin);
886 }
887 else {
888 UChar_t lastyvalue = 0;
889 Int_t endybin = ymin - 1;
890 for(Int_t ybin=ymin; ybin<=ymax; ybin++)
891 {
892 UChar_t maxvalue = 0;
893 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
894 {
895 Int_t bin = xbin + ybin*nxbins;
896 if(gapcount[bin] < MAX_N_GAPS) {
897 maxvalue = 1;
898 if(trackfirstrow[bin] < nextpatchfirstrow)
899 currentrowcount[bin] = nextpatchfirstrow;
900 else
901 currentrowcount[bin] = trackfirstrow[bin];
902 }
903 }
904 if(maxvalue > 0)
905 {
906 nextrow[ybin] = (UChar_t)ybin;
907 if(maxvalue > lastyvalue)
908 {
909 UChar_t *tempnextrow = nextrow + endybin + 1;
910 memset(tempnextrow,(UChar_t)ybin,ybin-endybin-1);
911 }
912 endybin = ybin;
913 }
914 lastyvalue = maxvalue;
915 }
a8ffd46b 916 UChar_t *tempnextrow = nextrow + endybin + 1;
917 memset(tempnextrow,(UChar_t)(ymax+1),ymax-endybin);
918 }
919 }
920
921 fBenchmark->Stop(buf);
922}
923
b2a02bce 924void AliL3Hough::AddTracks()
925{
917e711b 926 // Add current slice slice tracks to the global list of found tracks
b2a02bce 927 if(!fTracks[0])
928 {
929 cerr<<"AliL3Hough::AddTracks : No tracks"<<endl;
930 return;
931 }
932 AliL3TrackArray *tracks = fTracks[0];
933 for(Int_t i=0; i<tracks->GetNTracks(); i++)
934 {
935 AliL3Track *track = tracks->GetCheckedTrack(i);
936 if(!track) continue;
937 if(track->GetNHits()!=1) cerr<<"NHITS "<<track->GetNHits()<<endl;
938 UInt_t *ids = track->GetHitNumbers();
939 ids[0] = (fCurrentSlice&0x7f)<<25;
940 }
941
942 fGlobalTracks->AddTracks(fTracks[0],0,fCurrentSlice);
943}
944
de3c3890 945void AliL3Hough::FindTrackCandidatesRow()
a6008206 946{
917e711b 947 // Find AliL3HoughTransformerRow track candidates
de3c3890 948 if(fVersion != 4) {
949 LOG(AliL3Log::kError,"AliL3Hough::FindTrackCandidatesRow()","")
950 <<"Incompatible Peak Finder version!"<<ENDLOG;
951 return;
952 }
953
a6008206 954 //Look for peaks in histograms, and find the track candidates
917e711b 955 Int_t npatches;
de3c3890 956 if(fAddHistograms)
917e711b 957 npatches = 1; //Histograms have been added.
de3c3890 958 else
917e711b 959 npatches = fNPatches;
de3c3890 960
961 Double_t initTime,cpuTime;
962 initTime = GetCpuTime();
963 fBenchmark->Start("Find Maxima");
917e711b 964 for(Int_t i=0; i<npatches; i++)
de3c3890 965 {
966 AliL3HoughBaseTransformer *tr = fHoughTransformer[i];
967 fTracks[i]->Reset();
968 fPeakFinder->Reset();
969
970 for(Int_t j=0; j<fNEtaSegments; j++)
971 {
972 AliL3Histogram *hist = tr->GetHistogram(j);
973 if(hist->GetNEntries()==0) continue;
974 fPeakFinder->SetHistogram(hist);
975 fPeakFinder->SetEtaSlice(j);
a8ffd46b 976 fPeakFinder->SetTrackLUTs(((AliL3HoughTransformerRow *)tr)->fTrackNRows,((AliL3HoughTransformerRow *)tr)->fTrackFirstRow,((AliL3HoughTransformerRow *)tr)->fTrackLastRow);
de3c3890 977#ifdef do_mc
978 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","")
979 <<"Starting "<<j<<" etaslice"<<ENDLOG;
980#endif
981 fPeakFinder->SetThreshold(fPeakThreshold[i]);
982 fPeakFinder->FindAdaptedRowPeaks(1,0,0);//Maxima finder for HoughTransformerRow
983
984 //fPeakFinder->FindMaxima(fPeakThreshold[i]); //Simple maxima finder
985 }
a6008206 986
de3c3890 987 for(Int_t k=0; k<fPeakFinder->GetEntries(); k++)
988 {
b2b60653 989 // if(fPeakFinder->GetWeight(k) < 0) continue;
de3c3890 990 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[i]->NextTrack();
991 Float_t psi = atan((fPeakFinder->GetXPeak(k)-fPeakFinder->GetYPeak(k))/(AliL3HoughTransformerRow::GetBeta1()-AliL3HoughTransformerRow::GetBeta2()));
992 Float_t kappa = 2.0*(fPeakFinder->GetXPeak(k)*cos(psi)-AliL3HoughTransformerRow::GetBeta1()*sin(psi));
993 // track->SetTrackParameters(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetWeight(k));
994 track->SetTrackParameters(kappa,psi,fPeakFinder->GetWeight(k));
995 track->SetBinXY(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetXPeakSize(k),fPeakFinder->GetYPeakSize(k));
996 Int_t etaindex = (fPeakFinder->GetStartEta(k)+fPeakFinder->GetEndEta(k))/2;
997 track->SetEtaIndex(etaindex);
998 Float_t starteta = tr->GetEta(fPeakFinder->GetStartEta(k),fCurrentSlice);
999 Float_t endeta = tr->GetEta(fPeakFinder->GetEndEta(k),fCurrentSlice);
1000 track->SetEta((starteta+endeta)/2.0);
1001 track->SetRowRange(AliL3Transform::GetFirstRow(0),AliL3Transform::GetLastRow(5));
1002 track->SetSector(fCurrentSlice);
1003 track->SetSlice(fCurrentSlice);
1004#ifdef do_mc
1005 Int_t label = tr->GetTrackID(etaindex,fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k));
1006 track->SetMCid(label);
1007 // cout<<"Track found with label "<<label<<" at "<<fPeakFinder->GetXPeak(k)<<" "<<fPeakFinder->GetYPeak(k)<<" with weight "<<fPeakFinder->GetWeight(k)<<endl;
1008#endif
1009 }
1010 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","")
a8ffd46b 1011 <<"Found "<<fTracks[i]->GetNTracks()<<" tracks in slice "<<fCurrentSlice<<ENDLOG;
de3c3890 1012 fTracks[i]->QSort();
1013 }
1014 fBenchmark->Stop("Find Maxima");
1015 cpuTime = GetCpuTime() - initTime;
1016 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","Timing")
1017 <<"Maxima finding done in "<<cpuTime*1000<<" ms"<<ENDLOG;
1018}
1019
1020void AliL3Hough::FindTrackCandidates()
1021{
917e711b 1022 // Find AliL3HoughTransformer track candidates
de3c3890 1023 if(fVersion == 4) {
1024 LOG(AliL3Log::kError,"AliL3Hough::FindTrackCandidatesRow()","")
1025 <<"Incompatible Peak Finder version!"<<ENDLOG;
1026 return;
1027 }
1028
917e711b 1029 Int_t npatches;
a6008206 1030 if(fAddHistograms)
917e711b 1031 npatches = 1; //Histograms have been added.
a6008206 1032 else
917e711b 1033 npatches = fNPatches;
b1886074 1034
0309a5ee 1035 Double_t initTime,cpuTime;
1036 initTime = GetCpuTime();
3e87ef69 1037 fBenchmark->Start("Find Maxima");
917e711b 1038 for(Int_t i=0; i<npatches; i++)
a6008206 1039 {
237d3f5c 1040 AliL3HoughBaseTransformer *tr = fHoughTransformer[i];
b1886074 1041 fTracks[i]->Reset();
6c97129d 1042
a6008206 1043 for(Int_t j=0; j<fNEtaSegments; j++)
1044 {
1045 AliL3Histogram *hist = tr->GetHistogram(j);
b1886074 1046 if(hist->GetNEntries()==0) continue;
3fe49b5b 1047 fPeakFinder->Reset();
a6008206 1048 fPeakFinder->SetHistogram(hist);
de3c3890 1049#ifdef do_mc
1050 cout<<"Starting "<<j<<" etaslice"<<endl;
1051#endif
b2a02bce 1052 fPeakFinder->SetThreshold(fPeakThreshold[i]);
de3c3890 1053 fPeakFinder->FindAdaptedPeaks(fKappaSpread,fPeakRatio);
b2a02bce 1054
3fe49b5b 1055 for(Int_t k=0; k<fPeakFinder->GetEntries(); k++)
a6008206 1056 {
b1886074 1057 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[i]->NextTrack();
3fe49b5b 1058 track->SetTrackParameters(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetWeight(k));
a6008206 1059 track->SetEtaIndex(j);
afd8fed4 1060 track->SetEta(tr->GetEta(j,fCurrentSlice));
26abc209 1061 track->SetRowRange(AliL3Transform::GetFirstRow(0),AliL3Transform::GetLastRow(5));
a6008206 1062 }
1063 }
b2a02bce 1064 cout<<"Found "<<fTracks[i]->GetNTracks()<<" tracks in patch "<<i<<endl;
b1886074 1065 fTracks[i]->QSort();
a6008206 1066 }
3e87ef69 1067 fBenchmark->Stop("Find Maxima");
0309a5ee 1068 cpuTime = GetCpuTime() - initTime;
1069 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","Timing")
1070 <<"Maxima finding done in "<<cpuTime*1000<<" ms"<<ENDLOG;
a6008206 1071}
1072
3fe49b5b 1073void AliL3Hough::InitEvaluate()
1074{
1075 //Pass the transformer objects to the AliL3HoughEval objects:
1076 //This will provide the evaluation objects with all the necessary
208b54c5 1077 //data and parameters it needs.
3fe49b5b 1078
1079 for(Int_t i=0; i<fNPatches; i++)
1080 fEval[i]->InitTransformer(fHoughTransformer[i]);
1081}
1082
917e711b 1083Int_t AliL3Hough::Evaluate(Int_t roadwidth,Int_t nrowstomiss)
a6008206 1084{
1085 //Evaluate the tracks, by looking along the road in the raw data.
3fe49b5b 1086 //If track does not cross all padrows - rows2miss, it is removed from the arrray.
0309a5ee 1087 //If histograms were not added, the check is done locally in patch,
1088 //meaning that nrowstomiss is the number of padrows the road can miss with respect
1089 //to the number of rows in the patch.
1090 //If the histograms were added, the comparison is done globally in the _slice_,
1091 //meaing that nrowstomiss is the number of padrows the road can miss with
1092 //respect to the total number of padrows in the slice.
1093 //
1094 //Return value = number of tracks which were removed (only in case of fAddHistograms)
a6008206 1095
b1886074 1096 if(!fTracks[0])
a6008206 1097 {
b1886074 1098 LOG(AliL3Log::kError,"AliL3Hough::Evaluate","Track Array")
1099 <<"No tracks to work with..."<<ENDLOG;
0309a5ee 1100 return 0;
a6008206 1101 }
1102
917e711b 1103 Int_t removedtracks=0;
0309a5ee 1104 AliL3TrackArray *tracks=0;
a4639de2 1105
0309a5ee 1106 if(fAddHistograms)
a4639de2 1107 {
0309a5ee 1108 tracks = fTracks[0];
0309a5ee 1109 for(Int_t i=0; i<tracks->GetNTracks(); i++)
a6008206 1110 {
a4639de2 1111 AliL3Track *track = tracks->GetCheckedTrack(i);
1112 if(!track) continue;
1113 track->SetNHits(0);
0309a5ee 1114 }
f80b98cb 1115 }
f000f8a5 1116
a4639de2 1117 for(Int_t i=0; i<fNPatches; i++)
917e711b 1118 EvaluatePatch(i,roadwidth,nrowstomiss);
a4639de2 1119
aa641eb8 1120 //Here we check the tracks globally;
1121 //how many good rows (padrows with signal)
1122 //did it cross in the slice
1123 if(fAddHistograms)
0309a5ee 1124 {
1125 for(Int_t j=0; j<tracks->GetNTracks(); j++)
1126 {
a4639de2 1127 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
1128
1129 if(track->GetNHits() < AliL3Transform::GetNRows() - nrowstomiss)
0309a5ee 1130 {
1131 tracks->Remove(j);
917e711b 1132 removedtracks++;
0309a5ee 1133 }
1134 }
1135 tracks->Compress();
1136 tracks->QSort();
1137 }
a4639de2 1138
917e711b 1139 return removedtracks;
a4639de2 1140}
1141
917e711b 1142void AliL3Hough::EvaluatePatch(Int_t i,Int_t roadwidth,Int_t nrowstomiss)
a4639de2 1143{
1144 //Evaluate patch i.
0309a5ee 1145
a4639de2 1146 fEval[i]->InitTransformer(fHoughTransformer[i]);
917e711b 1147 fEval[i]->SetNumOfPadsToLook(roadwidth);
a4639de2 1148 fEval[i]->SetNumOfRowsToMiss(nrowstomiss);
1149 //fEval[i]->RemoveFoundTracks();
0309a5ee 1150
a4639de2 1151 AliL3TrackArray *tracks=0;
1152
1153 if(!fAddHistograms)
1154 tracks = fTracks[i];
1155 else
1156 tracks = fTracks[0];
1157
1158 Int_t nrows=0;
1159 for(Int_t j=0; j<tracks->GetNTracks(); j++)
1160 {
1161 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
1162 if(!track)
1163 {
1164 LOG(AliL3Log::kWarning,"AliL3Hough::EvaluatePatch","Track array")
1165 <<"Track object missing!"<<ENDLOG;
1166 continue;
1167 }
1168 nrows=0;
3e87ef69 1169 Int_t rowrange[2] = {AliL3Transform::GetFirstRow(i),AliL3Transform::GetLastRow(i)};
1170 Bool_t result = fEval[i]->LookInsideRoad(track,nrows,rowrange);
a4639de2 1171 if(fAddHistograms)
1172 {
1173 Int_t pre=track->GetNHits();
1174 track->SetNHits(pre+nrows);
1175 }
3e87ef69 1176 else//the track crossed too few good padrows (padrows with signal) in the patch, so remove it
1177 {
1178 if(result == kFALSE)
1179 tracks->Remove(j);
1180 }
a4639de2 1181 }
1182
1183 tracks->Compress();
a4639de2 1184
a6008206 1185}
f80b98cb 1186
44c7f8de 1187void AliL3Hough::MergeEtaSlices()
b1886074 1188{
44c7f8de 1189 //Merge tracks found in neighbouring eta slices.
1190 //Removes the track with the lower weight.
1191
3e87ef69 1192 fBenchmark->Start("Merge Eta-slices");
44c7f8de 1193 AliL3TrackArray *tracks = fTracks[0];
1194 if(!tracks)
b1886074 1195 {
44c7f8de 1196 cerr<<"AliL3Hough::MergeEtaSlices : No tracks "<<endl;
b1886074 1197 return;
1198 }
44c7f8de 1199 for(Int_t j=0; j<tracks->GetNTracks(); j++)
b1886074 1200 {
44c7f8de 1201 AliL3HoughTrack *track1 = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
1202 if(!track1) continue;
1203 for(Int_t k=j+1; k<tracks->GetNTracks(); k++)
1204 {
1205 AliL3HoughTrack *track2 = (AliL3HoughTrack*)tracks->GetCheckedTrack(k);
1206 if(!track2) continue;
1207 if(abs(track1->GetEtaIndex() - track2->GetEtaIndex()) != 1) continue;
3e87ef69 1208 if(fabs(track1->GetKappa()-track2->GetKappa()) < 0.006 &&
1209 fabs(track1->GetPsi()- track2->GetPsi()) < 0.1)
44c7f8de 1210 {
3e87ef69 1211 //cout<<"Merging track in slices "<<track1->GetEtaIndex()<<" "<<track2->GetEtaIndex()<<endl;
1212 if(track1->GetWeight() > track2->GetWeight())
1213 tracks->Remove(k);
1214 else
1215 tracks->Remove(j);
44c7f8de 1216 }
1217 }
b1886074 1218 }
3e87ef69 1219 fBenchmark->Stop("Merge Eta-slices");
44c7f8de 1220 tracks->Compress();
b1886074 1221}
1222
b2a02bce 1223void AliL3Hough::WriteTracks(Char_t *path)
1224{
917e711b 1225 // Write found tracks into file
b2a02bce 1226 //cout<<"AliL3Hough::WriteTracks : Sorting the tracsk"<<endl;
1227 //fGlobalTracks->QSort();
1228
1229 Char_t filename[1024];
1230 sprintf(filename,"%s/tracks_%d.raw",path,fEvent);
1231 AliL3MemHandler mem;
1232 mem.SetBinaryOutput(filename);
1233 mem.TrackArray2Binary(fGlobalTracks);
1234 mem.CloseBinaryOutput();
1235 fGlobalTracks->Reset();
1236}
1237
3fe49b5b 1238void AliL3Hough::WriteTracks(Int_t slice,Char_t *path)
1c404dd5 1239{
917e711b 1240 // Write found tracks slice by slice into file
c2f25cd2 1241
3e87ef69 1242 AliL3MemHandler mem;
95a00d93 1243 Char_t fname[100];
b5a207b4 1244 if(fAddHistograms)
1245 {
b2a02bce 1246 sprintf(fname,"%s/tracks_ho_%d_%d.raw",path,fEvent,slice);
3e87ef69 1247 mem.SetBinaryOutput(fname);
1248 mem.TrackArray2Binary(fTracks[0]);
1249 mem.CloseBinaryOutput();
b5a207b4 1250 }
1251 else
1252 {
1253 for(Int_t i=0; i<fNPatches; i++)
1254 {
b2a02bce 1255 sprintf(fname,"%s/tracks_ho_%d_%d_%d.raw",path,fEvent,slice,i);
3e87ef69 1256 mem.SetBinaryOutput(fname);
1257 mem.TrackArray2Binary(fTracks[i]);
1258 mem.CloseBinaryOutput();
b5a207b4 1259 }
1260 }
1c404dd5 1261}
208b54c5 1262
a109e73e 1263#ifdef use_aliroot
1264Int_t AliL3Hough::FillESD(AliESD *esd)
1265{
1266 if(!fGlobalTracks) return 0;
1267 Int_t nglobaltracks = 0;
1268 for(Int_t i=0; i<fGlobalTracks->GetNTracks(); i++)
1269 {
1270 AliL3HoughTrack *tpt = (AliL3HoughTrack *)fGlobalTracks->GetCheckedTrack(i);
1271 if(!tpt) continue;
1272
1273 AliESDHLTtrack *esdtrack = new AliESDHLTtrack();
1274
1275 esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
1276 esdtrack->SetNHits(tpt->GetNHits());
1277 esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
1278 esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
1279 esdtrack->SetPt(tpt->GetPt());
1280 esdtrack->SetPsi(tpt->GetPsi());
1281 esdtrack->SetTgl(tpt->GetTgl());
1282 esdtrack->SetCharge(tpt->GetCharge());
1283 esdtrack->SetMCid(tpt->GetMCid());
1284 esdtrack->SetWeight(tpt->GetWeight());
1285 esdtrack->SetSector(tpt->GetSector());
1286 esdtrack->SetBinXY(tpt->GetBinX(),tpt->GetBinY(),tpt->GetSizeX(),tpt->GetSizeY());
1287 esdtrack->SetPID(tpt->GetPID());
1288 esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
1289
1290 esd->AddHLTHoughTrack(esdtrack);
1291 nglobaltracks++;
1292 delete esdtrack;
1293 }
1294 return nglobaltracks;
1295}
1296#endif
1297
a6008206 1298void AliL3Hough::WriteDigits(Char_t *outfile)
1299{
1300 //Write the current data to a new rootfile.
917e711b 1301#ifdef use_aliroot
a6008206 1302
1c404dd5 1303 for(Int_t i=0; i<fNPatches; i++)
a6008206 1304 {
1305 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fHoughTransformer[i]->GetDataPointer();
1306 fMemHandler[i]->AliDigits2RootFile(tempPt,outfile);
1307 }
208b54c5 1308#else
1309 cerr<<"AliL3Hough::WriteDigits : You need to compile with AliROOT!"<<endl;
1310 return;
1311#endif
4fc9a6a4 1312}
208b54c5 1313
0309a5ee 1314Double_t AliL3Hough::GetCpuTime()
1315{
1316 //Return the Cputime in seconds.
1317 struct timeval tv;
1318 gettimeofday( &tv, NULL );
1319 return tv.tv_sec+(((Double_t)tv.tv_usec)/1000000.);
0309a5ee 1320}
60a3d829 1321
a8ffd46b 1322void *AliL3Hough::ProcessInThread(void *args)
1323{
1324 AliL3Hough *instance = (AliL3Hough *)args;
1325 Int_t minslice = instance->GetMinSlice();
1326 Int_t maxslice = instance->GetMaxSlice();
1327 for(Int_t i=minslice; i<=maxslice; i++)
1328 {
1329 instance->ReadData(i,0);
1330 instance->Transform();
1331 instance->AddAllHistogramsRows();
1332 instance->FindTrackCandidatesRow();
1333 instance->AddTracks();
1334 }
1335 return (void *)0;
1336}
1337
1338void AliL3Hough::StartProcessInThread(Int_t minslice,Int_t maxslice)
1339{
1340 if(!fThread) {
1341 char buf[255];
1342 sprintf(buf,"houghtrans_%d_%d",minslice,maxslice);
1343 SetMinMaxSlices(minslice,maxslice);
1344 // fThread = new TThread(buf,(void (*) (void *))&ProcessInThread,(void *)this);
1345 fThread = new TThread(buf,&ProcessInThread,(void *)this);
1346 fThread->Run();
1347 }
1348 return;
1349}
1350
1351Int_t AliL3Hough::WaitForThreadFinish()
1352{
1353 return TThread::Join(fThread->GetId());
1354}