]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/hough/AliL3Hough.cxx
Faster init of the hough transformer
[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);
7e4eb453 341 if(fVersion!=4) {
342 fMerger = new AliL3HoughMerger(fNPatches);
343 fInterMerger = new AliL3HoughIntMerger();
344 }
345 else {
346 fMerger = 0;
347 fInterMerger = 0;
348 }
237d3f5c 349 fGlobalMerger = 0;
3e87ef69 350 fBenchmark = new AliL3Benchmark();
b2a02bce 351}
352
353void AliL3Hough::SetTransformerParams(Float_t ptres,Float_t ptmin,Float_t ptmax,Int_t ny,Int_t patch)
354{
917e711b 355 // Setup the parameters for the Hough Transformer
b2a02bce 356 Int_t mrow;
357 Float_t psi=0;
358 if(patch==-1)
359 mrow = 80;
360 else
361 mrow = AliL3Transform::GetLastRow(patch);
362 if(ptmin)
363 {
364 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
365 Double_t kappa = -1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
366 psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
367 cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
368 }
369
370 if(patch==-1)
371 {
372 Int_t i=0;
373 while(i < 6)
374 {
375 fPtRes[i] = ptres;
376 fLowPt[i] = ptmin;
377 fUpperPt[i] = ptmax;
378 fNBinY[i] = ny;
379 fPhi[i] = psi;
380 fNBinX[i]=0;
381 i++;
382 }
383 return;
384 }
385
386 fPtRes[patch] = ptres;
387 fLowPt[patch] = ptmin;
388 fUpperPt[patch] = ptmax;
389 fNBinY[patch] = ny;
390 fPhi[patch] = psi;
391}
de3c3890 392/*
b2a02bce 393void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t ptmin,Int_t patch)
394{
917e711b 395 // Setup the parameters for the Hough Transformer
b2a02bce 396
397 Int_t mrow=80;
398 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
399 Double_t kappa = -1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
400 Double_t psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
401 cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
402
403 Int_t i=0;
404 while(i < 6)
405 {
406 fLowPt[i] = ptmin;
407 fNBinY[i] = ny;
408 fNBinX[i] = nx;
409 fPhi[i] = psi;
410 i++;
411 }
412}
de3c3890 413*/
0615a438 414void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t ptmin,Int_t /*patch*/)
de3c3890 415{
917e711b 416 // Setup the parameters for the Hough Transformer
de3c3890 417
1e75562a 418 Double_t lineradius = 1.0/(AliL3HoughTransformerRow::GetBeta1()*sqrt(1.0+tan(AliL3Transform::Pi()*10/180)*tan(AliL3Transform::Pi()*10/180)));
419 Double_t alpha1 = AliL3HoughTransformerRow::GetBeta1()*tan(AliL3Transform::Pi()*10/180);
420 Double_t kappa = 1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/(ptmin*0.9);
de3c3890 421 Double_t psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
0fdf7509 422 // cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
1e75562a 423 Double_t alpha2 = alpha1 - (AliL3HoughTransformerRow::GetBeta1()-AliL3HoughTransformerRow::GetBeta2())*tan(psi);
0fdf7509 424 // cout<<"Calculated alphas range "<<alpha1<<" "<<alpha2<<" in patch "<<patch<<endl;
de3c3890 425
426 Int_t i=0;
427 while(i < 6)
428 {
1e75562a 429 fLowPt[i] = 1.1*alpha1;
430 fNBinY[i] = ny;
431 fNBinX[i] = nx;
432 fPhi[i] = alpha2;
433 i++;
434 }
435}
436
437void AliL3Hough::CalcTransformerParams(Float_t ptmin)
438{
439 // Setup the parameters for the Row Hough Transformer
440 // Automatically adjusts the number of bins in X and Y in a way
441 // that the size of the hough bin is 2x (in X) and 2.5 (in Y) the
442 // size of the tpc pads
443
444 Double_t lineradius = 1.0/(AliL3HoughTransformerRow::GetBeta1()*sqrt(1.0+tan(AliL3Transform::Pi()*10/180)*tan(AliL3Transform::Pi()*10/180)));
445 Double_t alpha1 = AliL3HoughTransformerRow::GetBeta1()*tan(AliL3Transform::Pi()*10/180);
446 Double_t kappa = 1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/(ptmin*0.9);
447 Double_t psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
448 // cout<<"Calculated psi range "<<psi<<endl;
449 Double_t alpha2 = alpha1 - (AliL3HoughTransformerRow::GetBeta1()-AliL3HoughTransformerRow::GetBeta2())*tan(psi);
450 alpha1 *= 1.1;
451 // cout<<"Calculated alphas range "<<alpha1<<" "<<alpha2<<endl;
452
453 Double_t sizex = 2.0*AliL3Transform::GetPadPitchWidthLow()*AliL3HoughTransformerRow::GetBeta1()*AliL3HoughTransformerRow::GetBeta1();
454 Double_t sizey = 2.5*AliL3Transform::GetPadPitchWidthUp()*AliL3HoughTransformerRow::GetBeta2()*AliL3HoughTransformerRow::GetBeta2();
455
456 Int_t nx = 2*(Int_t)(alpha1/sizex)+1;
457 Int_t ny = 2*(Int_t)(alpha2/sizey)+1;
458 // cout<<"Calculated number of bins "<<nx<<" "<<ny<<endl;
459
460 Int_t i=0;
461 while(i < 6)
462 {
463 fLowPt[i] = alpha1;
de3c3890 464 fNBinY[i] = ny;
465 fNBinX[i] = nx;
1e75562a 466 fPhi[i] = alpha2;
de3c3890 467 i++;
468 }
469}
b2a02bce 470
471void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t lpt,Float_t phi)
472{
473 Int_t i=0;
474 while(i < 6)
475 {
476 fLowPt[i] = lpt;
477 fNBinY[i] = ny;
478 fNBinX[i] = nx;
479 fPhi[i] = phi;
480 i++;
481 }
482}
483
484void AliL3Hough::SetThreshold(Int_t t3,Int_t patch)
485{
917e711b 486 // Set digits threshold
b2a02bce 487 if(patch==-1)
488 {
489 Int_t i=0;
490 while(i < 6)
491 fThreshold[i++]=t3;
492 return;
493 }
494 fThreshold[patch]=t3;
495}
3e87ef69 496
b2a02bce 497void AliL3Hough::SetPeakThreshold(Int_t threshold,Int_t patch)
498{
917e711b 499 // Set Peak Finder threshold
b2a02bce 500 if(patch==-1)
501 {
502 Int_t i=0;
503 while(i < 6)
504 fPeakThreshold[i++]=threshold;
505 return;
506 }
507 fPeakThreshold[patch]=threshold;
3e87ef69 508}
509
510void AliL3Hough::DoBench(Char_t *name)
511{
512 fBenchmark->Analyze(name);
a6008206 513}
514
515void AliL3Hough::Process(Int_t minslice,Int_t maxslice)
516{
517 //Process all slices [minslice,maxslice].
1c404dd5 518 fGlobalMerger = new AliL3HoughGlobalMerger(minslice,maxslice);
b1886074 519
a6008206 520 for(Int_t i=minslice; i<=maxslice; i++)
521 {
b1886074 522 ReadData(i);
523 Transform();
0bd0c1ef 524 if(fAddHistograms) {
525 if(fVersion != 4)
526 AddAllHistograms();
527 else
528 AddAllHistogramsRows();
529 }
a6008206 530 FindTrackCandidates();
3e87ef69 531 //Evaluate();
532 //fGlobalMerger->FillTracks(fTracks[0],i);
f80b98cb 533 }
4fc9a6a4 534}
f80b98cb 535
e06900d5 536void AliL3Hough::ReadData(Int_t slice,Int_t eventnr)
4fc9a6a4 537{
b1886074 538 //Read data from files, binary or root.
3bb06991 539
1f1942b8 540#ifdef use_aliroot
541 if(fEvent!=eventnr) //just be sure that index is empty for new event
542 AliL3FileHandler::CleanStaticIndex();
543#endif
3bb06991 544 fCurrentSlice = slice;
1f1942b8 545
1c404dd5 546 for(Int_t i=0; i<fNPatches; i++)
f80b98cb 547 {
4fc9a6a4 548 fMemHandler[i]->Free();
549 UInt_t ndigits=0;
550 AliL3DigitRowData *digits =0;
551 Char_t name[256];
3fe49b5b 552 fMemHandler[i]->Init(slice,i);
a6008206 553 if(fBinary)//take input data from binary files
4fc9a6a4 554 {
d96f6a4a 555 if(fUse8bits)
b2a02bce 556 sprintf(name,"%s/binaries/digits_c8_%d_%d_%d.raw",fPath,eventnr,slice,i);
d96f6a4a 557 else
b2a02bce 558 sprintf(name,"%s/binaries/digits_%d_%d_%d.raw",fPath,eventnr,slice,i);
636080ea 559
4fc9a6a4 560 fMemHandler[i]->SetBinaryInput(name);
561 digits = (AliL3DigitRowData *)fMemHandler[i]->CompBinary2Memory(ndigits);
562 fMemHandler[i]->CloseBinaryInput();
563 }
564 else //read data from root file
565 {
95a00d93 566#ifdef use_aliroot
5a31e9df 567 if(fEvent!=eventnr)
568 fMemHandler[i]->FreeDigitsTree();//or else the new event is not loaded
3e87ef69 569 digits=(AliL3DigitRowData *)fMemHandler[i]->AliAltroDigits2Memory(ndigits,eventnr);
95a00d93 570#else
571 cerr<<"You cannot read from rootfile now"<<endl;
572#endif
4fc9a6a4 573 }
aa641eb8 574
a8ffd46b 575 //Set the pointer to the TPCRawStream in case of fast raw data reading
576 fHoughTransformer[i]->SetTPCRawStream(fMemHandler[i]->GetTPCRawStream());
577
636080ea 578 //set input data and init transformer
579 fHoughTransformer[i]->SetInputData(ndigits,digits);
580 fHoughTransformer[i]->Init(slice,i,fNEtaSegments);
b1886074 581 }
5a31e9df 582
583 fEvent=eventnr;
b1886074 584}
585
917e711b 586void AliL3Hough::Transform(Int_t *rowrange)
b1886074 587{
588 //Transform all data given to the transformer within the given slice
589 //(after ReadData(slice))
0309a5ee 590
591 Double_t initTime,cpuTime;
592 initTime = GetCpuTime();
a8ffd46b 593 Int_t patchorder[6] = {5,2,0,1,3,4}; //The order in which patches are processed
594 // Int_t patchorder[6] = {0,1,2,3,4,5}; //The order in which patches are processed
595 // Int_t patchorder[6] = {5,4,3,2,1,0}; //The order in which patches are processed
596 // Int_t patchorder[6] = {5,2,4,3,1,0}; //The order in which patches are processed
597 fLastPatch=-1;
1c404dd5 598 for(Int_t i=0; i<fNPatches; i++)
b1886074 599 {
0bd0c1ef 600 // In case of Row transformer reset the arrays only once
a8ffd46b 601 if((fVersion != 4) || (i == 0)) {
602 fBenchmark->Start("Hough Reset");
603 fHoughTransformer[0]->Reset();//Reset the histograms
604 fBenchmark->Stop("Hough Reset");
605 }
3e87ef69 606 fBenchmark->Start("Hough Transform");
a8ffd46b 607 PrepareForNextPatch(patchorder[i]);
608 if(!rowrange) {
609 char buf[256];
610 sprintf(buf,"Patch %d",patchorder[i]);
611 fBenchmark->Start(buf);
612 fHoughTransformer[patchorder[i]]->SetLastPatch(fLastPatch);
613 fHoughTransformer[patchorder[i]]->TransformCircle();
614 fBenchmark->Stop(buf);
615 }
237d3f5c 616 else
917e711b 617 fHoughTransformer[i]->TransformCircleC(rowrange,1);
3e87ef69 618 fBenchmark->Stop("Hough Transform");
a8ffd46b 619 fLastPatch=patchorder[i];
b1886074 620 }
0309a5ee 621 cpuTime = GetCpuTime() - initTime;
622 LOG(AliL3Log::kInformational,"AliL3Hough::Transform()","Timing")
623 <<"Transform done in average per patch of "<<cpuTime*1000/fNPatches<<" ms"<<ENDLOG;
b1886074 624}
625
626void AliL3Hough::MergePatches()
627{
917e711b 628 // Merge patches if they are not summed
b1886074 629 if(fAddHistograms) //Nothing to merge here
630 return;
b1886074 631 fMerger->MergePatches(kTRUE);
b1886074 632}
633
634void AliL3Hough::MergeInternally()
635{
917e711b 636 // Merge patches internally
b1886074 637 if(fAddHistograms)
638 fInterMerger->FillTracks(fTracks[0]);
639 else
640 fInterMerger->FillTracks(fMerger->GetOutTracks());
641
642 fInterMerger->MMerge();
643}
644
645void AliL3Hough::ProcessSliceIter()
646{
647 //Process current slice (after ReadData(slice)) iteratively.
648
6c97129d 649 if(!fAddHistograms)
b1886074 650 {
6c97129d 651 for(Int_t i=0; i<fNPatches; i++)
652 {
653 ProcessPatchIter(i);
654 fMerger->FillTracks(fTracks[i],i); //Copy tracks to merger
655 }
656 }
657 else
658 {
659 for(Int_t i=0; i<10; i++)
660 {
661 Transform();
662 AddAllHistograms();
663 InitEvaluate();
664 AliL3HoughBaseTransformer *tr = fHoughTransformer[0];
665 for(Int_t j=0; j<fNEtaSegments; j++)
666 {
667 AliL3Histogram *hist = tr->GetHistogram(j);
668 if(hist->GetNEntries()==0) continue;
669 fPeakFinder->Reset();
670 fPeakFinder->SetHistogram(hist);
671 fPeakFinder->FindAbsMaxima();
672 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[0]->NextTrack();
673 track->SetTrackParameters(fPeakFinder->GetXPeak(0),fPeakFinder->GetYPeak(0),fPeakFinder->GetWeight(0));
674 track->SetEtaIndex(j);
675 track->SetEta(tr->GetEta(j,fCurrentSlice));
676 for(Int_t k=0; k<fNPatches; k++)
677 {
678 fEval[i]->SetNumOfPadsToLook(2);
679 fEval[i]->SetNumOfRowsToMiss(2);
680 fEval[i]->RemoveFoundTracks();
3e87ef69 681 /*
6c97129d 682 Int_t nrows=0;
683 if(!fEval[i]->LookInsideRoad(track,nrows))
684 {
685 fTracks[0]->Remove(fTracks[0]->GetNTracks()-1);
686 fTracks[0]->Compress();
687 }
3e87ef69 688 */
6c97129d 689 }
690 }
691
692 }
693
f80b98cb 694 }
4fc9a6a4 695}
696
b1886074 697void AliL3Hough::ProcessPatchIter(Int_t patch)
698{
699 //Process patch in a iterative way.
700 //transform + peakfinding + evaluation + transform +...
701
917e711b 702 Int_t numoftries = 5;
237d3f5c 703 AliL3HoughBaseTransformer *tr = fHoughTransformer[patch];
b1886074 704 AliL3TrackArray *tracks = fTracks[patch];
705 tracks->Reset();
706 AliL3HoughEval *ev = fEval[patch];
707 ev->InitTransformer(tr);
6c97129d 708 //ev->RemoveFoundTracks();
709 ev->SetNumOfRowsToMiss(3);
b5a207b4 710 ev->SetNumOfPadsToLook(2);
b1886074 711 AliL3Histogram *hist;
917e711b 712 for(Int_t t=0; t<numoftries; t++)
b1886074 713 {
714 tr->Reset();
715 tr->TransformCircle();
716 for(Int_t i=0; i<fNEtaSegments; i++)
717 {
718 hist = tr->GetHistogram(i);
719 if(hist->GetNEntries()==0) continue;
6c97129d 720 fPeakFinder->Reset();
b1886074 721 fPeakFinder->SetHistogram(hist);
6c97129d 722 fPeakFinder->FindAbsMaxima();
723 //fPeakFinder->FindPeak1();
b1886074 724 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->NextTrack();
6c97129d 725 track->SetTrackParameters(fPeakFinder->GetXPeak(0),fPeakFinder->GetYPeak(0),fPeakFinder->GetWeight(0));
726 track->SetEtaIndex(i);
727 track->SetEta(tr->GetEta(i,fCurrentSlice));
3e87ef69 728 /*
6c97129d 729 Int_t nrows=0;
730 if(!ev->LookInsideRoad(track,nrows))
b1886074 731 {
732 tracks->Remove(tracks->GetNTracks()-1);
733 tracks->Compress();
734 }
3e87ef69 735 */
b1886074 736 }
737 }
6c97129d 738 fTracks[0]->QSort();
b1886074 739 LOG(AliL3Log::kInformational,"AliL3Hough::ProcessPatch","NTracks")
740 <<AliL3Log::kDec<<"Found "<<tracks->GetNTracks()<<" tracks in patch "<<patch<<ENDLOG;
741}
742
a6008206 743void AliL3Hough::AddAllHistograms()
4fc9a6a4 744{
a6008206 745 //Add the histograms within one etaslice.
746 //Resulting histogram are in patch=0.
b1886074 747
0309a5ee 748 Double_t initTime,cpuTime;
749 initTime = GetCpuTime();
3e87ef69 750 fBenchmark->Start("Add Histograms");
a6008206 751 for(Int_t i=0; i<fNEtaSegments; i++)
752 {
753 AliL3Histogram *hist0 = fHoughTransformer[0]->GetHistogram(i);
1c404dd5 754 for(Int_t j=1; j<fNPatches; j++)
a6008206 755 {
756 AliL3Histogram *hist = fHoughTransformer[j]->GetHistogram(i);
757 hist0->Add(hist);
758 }
759 }
3e87ef69 760 fBenchmark->Stop("Add Histograms");
b1886074 761 fAddHistograms = kTRUE;
0309a5ee 762 cpuTime = GetCpuTime() - initTime;
763 LOG(AliL3Log::kInformational,"AliL3Hough::AddAllHistograms()","Timing")
764 <<"Adding histograms in "<<cpuTime*1000<<" ms"<<ENDLOG;
a6008206 765}
766
0bd0c1ef 767void AliL3Hough::AddAllHistogramsRows()
768{
769 //Add the histograms within one etaslice.
770 //Resulting histogram are in patch=0.
771
772 Double_t initTime,cpuTime;
773 initTime = GetCpuTime();
774 fBenchmark->Start("Add HistogramsRows");
775
a8ffd46b 776 UChar_t lastpatchlastrow = AliL3Transform::GetLastRowOnDDL(fLastPatch)+1;
777
de3c3890 778 UChar_t *tracklastrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackLastRow();
779
0bd0c1ef 780 for(Int_t i=0; i<fNEtaSegments; i++)
781 {
0bd0c1ef 782 UChar_t *gapcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetGapCount(i);
de3c3890 783 UChar_t *currentrowcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetCurrentRowCount(i);
0bd0c1ef 784
785 AliL3Histogram *hist = fHoughTransformer[0]->GetHistogram(i);
786 Int_t xmin = hist->GetFirstXbin();
787 Int_t xmax = hist->GetLastXbin();
788 Int_t ymin = hist->GetFirstYbin();
789 Int_t ymax = hist->GetLastYbin();
a8ffd46b 790 Int_t nxbins = hist->GetNbinsX()+2;
0bd0c1ef 791
792 for(Int_t ybin=ymin; ybin<=ymax; ybin++)
793 {
794 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
795 {
a8ffd46b 796 Int_t bin = xbin + ybin*nxbins; //Int_t bin = hist->GetBin(xbin,ybin);
797 if(gapcount[bin] < MAX_N_GAPS) {
798 if(tracklastrow[bin] > lastpatchlastrow) {
799 if(lastpatchlastrow > currentrowcount[bin])
800 gapcount[bin] += (lastpatchlastrow-currentrowcount[bin]-1);
801 }
802 else {
803 if(tracklastrow[bin] > currentrowcount[bin])
804 gapcount[bin] += (tracklastrow[bin]-currentrowcount[bin]-1);
805 }
806 if(gapcount[bin] < MAX_N_GAPS)
807 hist->AddBinContent(bin,(159-gapcount[bin]));
808 }
0bd0c1ef 809 }
810 }
811 }
812
813 fBenchmark->Stop("Add HistogramsRows");
814 fAddHistograms = kTRUE;
815 cpuTime = GetCpuTime() - initTime;
816 LOG(AliL3Log::kInformational,"AliL3Hough::AddAllHistogramsRows()","Timing")
817 <<"Adding histograms in "<<cpuTime*1000<<" ms"<<ENDLOG;
818}
819
a8ffd46b 820void AliL3Hough::PrepareForNextPatch(Int_t nextpatch)
821{
822 char buf[256];
823 sprintf(buf,"Prepare For Patch %d",nextpatch);
824 fBenchmark->Start(buf);
825
826 UChar_t lastpatchlastrow;
827 if(fLastPatch == -1)
828 lastpatchlastrow = 0;
829 else
830 lastpatchlastrow = AliL3Transform::GetLastRowOnDDL(fLastPatch)+1;
831 UChar_t nextpatchfirstrow;
832 if(nextpatch==0)
833 nextpatchfirstrow = 0;
834 else
835 nextpatchfirstrow = AliL3Transform::GetFirstRowOnDDL(nextpatch)-1;
836
837 UChar_t *trackfirstrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackFirstRow();
838 UChar_t *tracklastrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackLastRow();
839
840 for(Int_t i=0; i<fNEtaSegments; i++)
841 {
842 UChar_t *gapcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetGapCount(i);
843 UChar_t *currentrowcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetCurrentRowCount(i);
844 UChar_t *prevbin = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetPrevBin(i);
845 UChar_t *nextbin = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetNextBin(i);
846 UChar_t *nextrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetNextRow(i);
847
848 AliL3Histogram *hist = fHoughTransformer[0]->GetHistogram(i);
849 Int_t xmin = hist->GetFirstXbin();
850 Int_t xmax = hist->GetLastXbin();
851 Int_t ymin = hist->GetFirstYbin();
852 Int_t ymax = hist->GetLastYbin();
853 Int_t nxbins = hist->GetNbinsX()+2;
854
b2b60653 855 if(fLastPatch != -1) {
856 UChar_t lastyvalue = 0;
857 Int_t endybin = ymin - 1;
858 for(Int_t ybin=nextrow[ymin]; ybin<=ymax; ybin = nextrow[++ybin])
859 {
860 UChar_t lastxvalue = 0;
861 UChar_t maxvalue = 0;
862 Int_t endxbin = xmin - 1;
863 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
864 {
865 Int_t bin = xbin + ybin*nxbins;
866 UChar_t value = 0;
867 if(gapcount[bin] < MAX_N_GAPS) {
868 if(tracklastrow[bin] > lastpatchlastrow) {
869 if(lastpatchlastrow > currentrowcount[bin])
870 gapcount[bin] += (lastpatchlastrow-currentrowcount[bin]-1);
871 }
872 else {
873 if(tracklastrow[bin] > currentrowcount[bin])
874 gapcount[bin] += (tracklastrow[bin]-currentrowcount[bin]-1);
875 }
876 if(gapcount[bin] < MAX_N_GAPS) {
877 value = 1;
878 maxvalue = 1;
879 if(trackfirstrow[bin] < nextpatchfirstrow)
880 currentrowcount[bin] = nextpatchfirstrow;
881 else
882 currentrowcount[bin] = trackfirstrow[bin];
883 }
a8ffd46b 884 }
a8ffd46b 885 if(value > 0)
886 {
887 nextbin[xbin + ybin*nxbins] = (UChar_t)xbin;
888 prevbin[xbin + ybin*nxbins] = (UChar_t)xbin;
889 if(value > lastxvalue)
890 {
891 UChar_t *tempnextbin = nextbin + endxbin + 1 + ybin*nxbins;
892 memset(tempnextbin,(UChar_t)xbin,xbin-endxbin-1);
893 }
894 endxbin = xbin;
895 }
896 else
897 {
898 prevbin[xbin + ybin*nxbins] = (UChar_t)endxbin;
899 }
900 lastxvalue = value;
901 }
a8ffd46b 902 UChar_t *tempnextbin = nextbin + endxbin + 1 + ybin*nxbins;
903 memset(tempnextbin,(UChar_t)(xmax+1),xmax-endxbin);
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 }
b2b60653 916 UChar_t *tempnextrow = nextrow + endybin + 1;
1e75562a 917 memset(tempnextrow,(UChar_t)(ymax+1),ymax-endybin+1);
b2b60653 918 }
919 else {
920 UChar_t lastyvalue = 0;
921 Int_t endybin = ymin - 1;
922 for(Int_t ybin=ymin; ybin<=ymax; ybin++)
923 {
924 UChar_t maxvalue = 0;
925 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
926 {
927 Int_t bin = xbin + ybin*nxbins;
928 if(gapcount[bin] < MAX_N_GAPS) {
929 maxvalue = 1;
930 if(trackfirstrow[bin] < nextpatchfirstrow)
931 currentrowcount[bin] = nextpatchfirstrow;
932 else
933 currentrowcount[bin] = trackfirstrow[bin];
934 }
935 }
936 if(maxvalue > 0)
937 {
938 nextrow[ybin] = (UChar_t)ybin;
939 if(maxvalue > lastyvalue)
940 {
941 UChar_t *tempnextrow = nextrow + endybin + 1;
942 memset(tempnextrow,(UChar_t)ybin,ybin-endybin-1);
943 }
944 endybin = ybin;
945 }
946 lastyvalue = maxvalue;
947 }
a8ffd46b 948 UChar_t *tempnextrow = nextrow + endybin + 1;
1e75562a 949 memset(tempnextrow,(UChar_t)(ymax+1),ymax-endybin+1);
a8ffd46b 950 }
951 }
952
953 fBenchmark->Stop(buf);
954}
955
b2a02bce 956void AliL3Hough::AddTracks()
957{
917e711b 958 // Add current slice slice tracks to the global list of found tracks
b2a02bce 959 if(!fTracks[0])
960 {
961 cerr<<"AliL3Hough::AddTracks : No tracks"<<endl;
962 return;
963 }
964 AliL3TrackArray *tracks = fTracks[0];
965 for(Int_t i=0; i<tracks->GetNTracks(); i++)
966 {
967 AliL3Track *track = tracks->GetCheckedTrack(i);
968 if(!track) continue;
969 if(track->GetNHits()!=1) cerr<<"NHITS "<<track->GetNHits()<<endl;
970 UInt_t *ids = track->GetHitNumbers();
971 ids[0] = (fCurrentSlice&0x7f)<<25;
972 }
973
974 fGlobalTracks->AddTracks(fTracks[0],0,fCurrentSlice);
975}
976
de3c3890 977void AliL3Hough::FindTrackCandidatesRow()
a6008206 978{
917e711b 979 // Find AliL3HoughTransformerRow track candidates
de3c3890 980 if(fVersion != 4) {
981 LOG(AliL3Log::kError,"AliL3Hough::FindTrackCandidatesRow()","")
982 <<"Incompatible Peak Finder version!"<<ENDLOG;
983 return;
984 }
985
a6008206 986 //Look for peaks in histograms, and find the track candidates
917e711b 987 Int_t npatches;
de3c3890 988 if(fAddHistograms)
917e711b 989 npatches = 1; //Histograms have been added.
de3c3890 990 else
917e711b 991 npatches = fNPatches;
de3c3890 992
993 Double_t initTime,cpuTime;
994 initTime = GetCpuTime();
995 fBenchmark->Start("Find Maxima");
917e711b 996 for(Int_t i=0; i<npatches; i++)
de3c3890 997 {
998 AliL3HoughBaseTransformer *tr = fHoughTransformer[i];
999 fTracks[i]->Reset();
1000 fPeakFinder->Reset();
1001
1002 for(Int_t j=0; j<fNEtaSegments; j++)
1003 {
1004 AliL3Histogram *hist = tr->GetHistogram(j);
1005 if(hist->GetNEntries()==0) continue;
1006 fPeakFinder->SetHistogram(hist);
1007 fPeakFinder->SetEtaSlice(j);
1e75562a 1008 fPeakFinder->SetTrackLUTs(((AliL3HoughTransformerRow *)tr)->GetTrackNRows(),((AliL3HoughTransformerRow *)tr)->GetTrackFirstRow(),((AliL3HoughTransformerRow *)tr)->GetTrackLastRow(),((AliL3HoughTransformerRow *)tr)->GetNextRow(j));
de3c3890 1009#ifdef do_mc
1010 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","")
1011 <<"Starting "<<j<<" etaslice"<<ENDLOG;
1012#endif
1013 fPeakFinder->SetThreshold(fPeakThreshold[i]);
1014 fPeakFinder->FindAdaptedRowPeaks(1,0,0);//Maxima finder for HoughTransformerRow
1015
1016 //fPeakFinder->FindMaxima(fPeakThreshold[i]); //Simple maxima finder
1017 }
a6008206 1018
de3c3890 1019 for(Int_t k=0; k<fPeakFinder->GetEntries(); k++)
1020 {
b2b60653 1021 // if(fPeakFinder->GetWeight(k) < 0) continue;
de3c3890 1022 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[i]->NextTrack();
1023 Float_t psi = atan((fPeakFinder->GetXPeak(k)-fPeakFinder->GetYPeak(k))/(AliL3HoughTransformerRow::GetBeta1()-AliL3HoughTransformerRow::GetBeta2()));
1024 Float_t kappa = 2.0*(fPeakFinder->GetXPeak(k)*cos(psi)-AliL3HoughTransformerRow::GetBeta1()*sin(psi));
1025 // track->SetTrackParameters(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetWeight(k));
1026 track->SetTrackParameters(kappa,psi,fPeakFinder->GetWeight(k));
1027 track->SetBinXY(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetXPeakSize(k),fPeakFinder->GetYPeakSize(k));
1028 Int_t etaindex = (fPeakFinder->GetStartEta(k)+fPeakFinder->GetEndEta(k))/2;
1029 track->SetEtaIndex(etaindex);
1030 Float_t starteta = tr->GetEta(fPeakFinder->GetStartEta(k),fCurrentSlice);
1031 Float_t endeta = tr->GetEta(fPeakFinder->GetEndEta(k),fCurrentSlice);
1032 track->SetEta((starteta+endeta)/2.0);
1033 track->SetRowRange(AliL3Transform::GetFirstRow(0),AliL3Transform::GetLastRow(5));
1034 track->SetSector(fCurrentSlice);
1035 track->SetSlice(fCurrentSlice);
1036#ifdef do_mc
1037 Int_t label = tr->GetTrackID(etaindex,fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k));
1038 track->SetMCid(label);
1039 // cout<<"Track found with label "<<label<<" at "<<fPeakFinder->GetXPeak(k)<<" "<<fPeakFinder->GetYPeak(k)<<" with weight "<<fPeakFinder->GetWeight(k)<<endl;
1040#endif
1041 }
1042 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","")
a8ffd46b 1043 <<"Found "<<fTracks[i]->GetNTracks()<<" tracks in slice "<<fCurrentSlice<<ENDLOG;
de3c3890 1044 fTracks[i]->QSort();
1045 }
1046 fBenchmark->Stop("Find Maxima");
1047 cpuTime = GetCpuTime() - initTime;
1048 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","Timing")
1049 <<"Maxima finding done in "<<cpuTime*1000<<" ms"<<ENDLOG;
1050}
1051
1052void AliL3Hough::FindTrackCandidates()
1053{
917e711b 1054 // Find AliL3HoughTransformer track candidates
de3c3890 1055 if(fVersion == 4) {
1056 LOG(AliL3Log::kError,"AliL3Hough::FindTrackCandidatesRow()","")
1057 <<"Incompatible Peak Finder version!"<<ENDLOG;
1058 return;
1059 }
1060
917e711b 1061 Int_t npatches;
a6008206 1062 if(fAddHistograms)
917e711b 1063 npatches = 1; //Histograms have been added.
a6008206 1064 else
917e711b 1065 npatches = fNPatches;
b1886074 1066
0309a5ee 1067 Double_t initTime,cpuTime;
1068 initTime = GetCpuTime();
3e87ef69 1069 fBenchmark->Start("Find Maxima");
917e711b 1070 for(Int_t i=0; i<npatches; i++)
a6008206 1071 {
237d3f5c 1072 AliL3HoughBaseTransformer *tr = fHoughTransformer[i];
b1886074 1073 fTracks[i]->Reset();
6c97129d 1074
a6008206 1075 for(Int_t j=0; j<fNEtaSegments; j++)
1076 {
1077 AliL3Histogram *hist = tr->GetHistogram(j);
b1886074 1078 if(hist->GetNEntries()==0) continue;
3fe49b5b 1079 fPeakFinder->Reset();
a6008206 1080 fPeakFinder->SetHistogram(hist);
de3c3890 1081#ifdef do_mc
1082 cout<<"Starting "<<j<<" etaslice"<<endl;
1083#endif
b2a02bce 1084 fPeakFinder->SetThreshold(fPeakThreshold[i]);
de3c3890 1085 fPeakFinder->FindAdaptedPeaks(fKappaSpread,fPeakRatio);
b2a02bce 1086
3fe49b5b 1087 for(Int_t k=0; k<fPeakFinder->GetEntries(); k++)
a6008206 1088 {
b1886074 1089 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[i]->NextTrack();
3fe49b5b 1090 track->SetTrackParameters(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetWeight(k));
a6008206 1091 track->SetEtaIndex(j);
afd8fed4 1092 track->SetEta(tr->GetEta(j,fCurrentSlice));
26abc209 1093 track->SetRowRange(AliL3Transform::GetFirstRow(0),AliL3Transform::GetLastRow(5));
a6008206 1094 }
1095 }
b2a02bce 1096 cout<<"Found "<<fTracks[i]->GetNTracks()<<" tracks in patch "<<i<<endl;
b1886074 1097 fTracks[i]->QSort();
a6008206 1098 }
3e87ef69 1099 fBenchmark->Stop("Find Maxima");
0309a5ee 1100 cpuTime = GetCpuTime() - initTime;
1101 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","Timing")
1102 <<"Maxima finding done in "<<cpuTime*1000<<" ms"<<ENDLOG;
a6008206 1103}
1104
3fe49b5b 1105void AliL3Hough::InitEvaluate()
1106{
1107 //Pass the transformer objects to the AliL3HoughEval objects:
1108 //This will provide the evaluation objects with all the necessary
208b54c5 1109 //data and parameters it needs.
3fe49b5b 1110
1111 for(Int_t i=0; i<fNPatches; i++)
1112 fEval[i]->InitTransformer(fHoughTransformer[i]);
1113}
1114
917e711b 1115Int_t AliL3Hough::Evaluate(Int_t roadwidth,Int_t nrowstomiss)
a6008206 1116{
1117 //Evaluate the tracks, by looking along the road in the raw data.
3fe49b5b 1118 //If track does not cross all padrows - rows2miss, it is removed from the arrray.
0309a5ee 1119 //If histograms were not added, the check is done locally in patch,
1120 //meaning that nrowstomiss is the number of padrows the road can miss with respect
1121 //to the number of rows in the patch.
1122 //If the histograms were added, the comparison is done globally in the _slice_,
1123 //meaing that nrowstomiss is the number of padrows the road can miss with
1124 //respect to the total number of padrows in the slice.
1125 //
1126 //Return value = number of tracks which were removed (only in case of fAddHistograms)
a6008206 1127
b1886074 1128 if(!fTracks[0])
a6008206 1129 {
b1886074 1130 LOG(AliL3Log::kError,"AliL3Hough::Evaluate","Track Array")
1131 <<"No tracks to work with..."<<ENDLOG;
0309a5ee 1132 return 0;
a6008206 1133 }
1134
917e711b 1135 Int_t removedtracks=0;
0309a5ee 1136 AliL3TrackArray *tracks=0;
a4639de2 1137
0309a5ee 1138 if(fAddHistograms)
a4639de2 1139 {
0309a5ee 1140 tracks = fTracks[0];
0309a5ee 1141 for(Int_t i=0; i<tracks->GetNTracks(); i++)
a6008206 1142 {
a4639de2 1143 AliL3Track *track = tracks->GetCheckedTrack(i);
1144 if(!track) continue;
1145 track->SetNHits(0);
0309a5ee 1146 }
f80b98cb 1147 }
f000f8a5 1148
a4639de2 1149 for(Int_t i=0; i<fNPatches; i++)
917e711b 1150 EvaluatePatch(i,roadwidth,nrowstomiss);
a4639de2 1151
aa641eb8 1152 //Here we check the tracks globally;
1153 //how many good rows (padrows with signal)
1154 //did it cross in the slice
1155 if(fAddHistograms)
0309a5ee 1156 {
1157 for(Int_t j=0; j<tracks->GetNTracks(); j++)
1158 {
a4639de2 1159 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
1160
1161 if(track->GetNHits() < AliL3Transform::GetNRows() - nrowstomiss)
0309a5ee 1162 {
1163 tracks->Remove(j);
917e711b 1164 removedtracks++;
0309a5ee 1165 }
1166 }
1167 tracks->Compress();
1168 tracks->QSort();
1169 }
a4639de2 1170
917e711b 1171 return removedtracks;
a4639de2 1172}
1173
917e711b 1174void AliL3Hough::EvaluatePatch(Int_t i,Int_t roadwidth,Int_t nrowstomiss)
a4639de2 1175{
1176 //Evaluate patch i.
0309a5ee 1177
a4639de2 1178 fEval[i]->InitTransformer(fHoughTransformer[i]);
917e711b 1179 fEval[i]->SetNumOfPadsToLook(roadwidth);
a4639de2 1180 fEval[i]->SetNumOfRowsToMiss(nrowstomiss);
1181 //fEval[i]->RemoveFoundTracks();
0309a5ee 1182
a4639de2 1183 AliL3TrackArray *tracks=0;
1184
1185 if(!fAddHistograms)
1186 tracks = fTracks[i];
1187 else
1188 tracks = fTracks[0];
1189
1190 Int_t nrows=0;
1191 for(Int_t j=0; j<tracks->GetNTracks(); j++)
1192 {
1193 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
1194 if(!track)
1195 {
1196 LOG(AliL3Log::kWarning,"AliL3Hough::EvaluatePatch","Track array")
1197 <<"Track object missing!"<<ENDLOG;
1198 continue;
1199 }
1200 nrows=0;
3e87ef69 1201 Int_t rowrange[2] = {AliL3Transform::GetFirstRow(i),AliL3Transform::GetLastRow(i)};
1202 Bool_t result = fEval[i]->LookInsideRoad(track,nrows,rowrange);
a4639de2 1203 if(fAddHistograms)
1204 {
1205 Int_t pre=track->GetNHits();
1206 track->SetNHits(pre+nrows);
1207 }
3e87ef69 1208 else//the track crossed too few good padrows (padrows with signal) in the patch, so remove it
1209 {
1210 if(result == kFALSE)
1211 tracks->Remove(j);
1212 }
a4639de2 1213 }
1214
1215 tracks->Compress();
a4639de2 1216
a6008206 1217}
f80b98cb 1218
44c7f8de 1219void AliL3Hough::MergeEtaSlices()
b1886074 1220{
44c7f8de 1221 //Merge tracks found in neighbouring eta slices.
1222 //Removes the track with the lower weight.
1223
3e87ef69 1224 fBenchmark->Start("Merge Eta-slices");
44c7f8de 1225 AliL3TrackArray *tracks = fTracks[0];
1226 if(!tracks)
b1886074 1227 {
44c7f8de 1228 cerr<<"AliL3Hough::MergeEtaSlices : No tracks "<<endl;
b1886074 1229 return;
1230 }
44c7f8de 1231 for(Int_t j=0; j<tracks->GetNTracks(); j++)
b1886074 1232 {
44c7f8de 1233 AliL3HoughTrack *track1 = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
1234 if(!track1) continue;
1235 for(Int_t k=j+1; k<tracks->GetNTracks(); k++)
1236 {
1237 AliL3HoughTrack *track2 = (AliL3HoughTrack*)tracks->GetCheckedTrack(k);
1238 if(!track2) continue;
1239 if(abs(track1->GetEtaIndex() - track2->GetEtaIndex()) != 1) continue;
3e87ef69 1240 if(fabs(track1->GetKappa()-track2->GetKappa()) < 0.006 &&
1241 fabs(track1->GetPsi()- track2->GetPsi()) < 0.1)
44c7f8de 1242 {
3e87ef69 1243 //cout<<"Merging track in slices "<<track1->GetEtaIndex()<<" "<<track2->GetEtaIndex()<<endl;
1244 if(track1->GetWeight() > track2->GetWeight())
1245 tracks->Remove(k);
1246 else
1247 tracks->Remove(j);
44c7f8de 1248 }
1249 }
b1886074 1250 }
3e87ef69 1251 fBenchmark->Stop("Merge Eta-slices");
44c7f8de 1252 tracks->Compress();
b1886074 1253}
1254
b2a02bce 1255void AliL3Hough::WriteTracks(Char_t *path)
1256{
917e711b 1257 // Write found tracks into file
b2a02bce 1258 //cout<<"AliL3Hough::WriteTracks : Sorting the tracsk"<<endl;
1259 //fGlobalTracks->QSort();
1260
1261 Char_t filename[1024];
1262 sprintf(filename,"%s/tracks_%d.raw",path,fEvent);
1263 AliL3MemHandler mem;
1264 mem.SetBinaryOutput(filename);
1265 mem.TrackArray2Binary(fGlobalTracks);
1266 mem.CloseBinaryOutput();
1267 fGlobalTracks->Reset();
1268}
1269
3fe49b5b 1270void AliL3Hough::WriteTracks(Int_t slice,Char_t *path)
1c404dd5 1271{
917e711b 1272 // Write found tracks slice by slice into file
c2f25cd2 1273
3e87ef69 1274 AliL3MemHandler mem;
95a00d93 1275 Char_t fname[100];
b5a207b4 1276 if(fAddHistograms)
1277 {
b2a02bce 1278 sprintf(fname,"%s/tracks_ho_%d_%d.raw",path,fEvent,slice);
3e87ef69 1279 mem.SetBinaryOutput(fname);
1280 mem.TrackArray2Binary(fTracks[0]);
1281 mem.CloseBinaryOutput();
b5a207b4 1282 }
1283 else
1284 {
1285 for(Int_t i=0; i<fNPatches; i++)
1286 {
b2a02bce 1287 sprintf(fname,"%s/tracks_ho_%d_%d_%d.raw",path,fEvent,slice,i);
3e87ef69 1288 mem.SetBinaryOutput(fname);
1289 mem.TrackArray2Binary(fTracks[i]);
1290 mem.CloseBinaryOutput();
b5a207b4 1291 }
1292 }
1c404dd5 1293}
208b54c5 1294
a109e73e 1295#ifdef use_aliroot
1296Int_t AliL3Hough::FillESD(AliESD *esd)
1297{
1298 if(!fGlobalTracks) return 0;
1299 Int_t nglobaltracks = 0;
1300 for(Int_t i=0; i<fGlobalTracks->GetNTracks(); i++)
1301 {
1302 AliL3HoughTrack *tpt = (AliL3HoughTrack *)fGlobalTracks->GetCheckedTrack(i);
1303 if(!tpt) continue;
1304
1305 AliESDHLTtrack *esdtrack = new AliESDHLTtrack();
1306
1307 esdtrack->SetRowRange(tpt->GetFirstRow(),tpt->GetLastRow());
1308 esdtrack->SetNHits(tpt->GetNHits());
1309 esdtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ());
1310 esdtrack->SetLastPoint(tpt->GetLastPointX(),tpt->GetLastPointY(),tpt->GetLastPointZ());
1311 esdtrack->SetPt(tpt->GetPt());
1312 esdtrack->SetPsi(tpt->GetPsi());
1313 esdtrack->SetTgl(tpt->GetTgl());
1314 esdtrack->SetCharge(tpt->GetCharge());
1315 esdtrack->SetMCid(tpt->GetMCid());
1316 esdtrack->SetWeight(tpt->GetWeight());
1317 esdtrack->SetSector(tpt->GetSector());
1318 esdtrack->SetBinXY(tpt->GetBinX(),tpt->GetBinY(),tpt->GetSizeX(),tpt->GetSizeY());
1319 esdtrack->SetPID(tpt->GetPID());
1320 esdtrack->ComesFromMainVertex(tpt->ComesFromMainVertex());
1321
1322 esd->AddHLTHoughTrack(esdtrack);
1323 nglobaltracks++;
1324 delete esdtrack;
1325 }
1326 return nglobaltracks;
1327}
1328#endif
1329
a6008206 1330void AliL3Hough::WriteDigits(Char_t *outfile)
1331{
1332 //Write the current data to a new rootfile.
917e711b 1333#ifdef use_aliroot
a6008206 1334
1c404dd5 1335 for(Int_t i=0; i<fNPatches; i++)
a6008206 1336 {
1337 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fHoughTransformer[i]->GetDataPointer();
1338 fMemHandler[i]->AliDigits2RootFile(tempPt,outfile);
1339 }
208b54c5 1340#else
1341 cerr<<"AliL3Hough::WriteDigits : You need to compile with AliROOT!"<<endl;
1342 return;
1343#endif
4fc9a6a4 1344}
208b54c5 1345
0309a5ee 1346Double_t AliL3Hough::GetCpuTime()
1347{
1348 //Return the Cputime in seconds.
1349 struct timeval tv;
1350 gettimeofday( &tv, NULL );
1351 return tv.tv_sec+(((Double_t)tv.tv_usec)/1000000.);
0309a5ee 1352}
60a3d829 1353
a8ffd46b 1354void *AliL3Hough::ProcessInThread(void *args)
1355{
1356 AliL3Hough *instance = (AliL3Hough *)args;
1357 Int_t minslice = instance->GetMinSlice();
1358 Int_t maxslice = instance->GetMaxSlice();
1359 for(Int_t i=minslice; i<=maxslice; i++)
1360 {
1361 instance->ReadData(i,0);
1362 instance->Transform();
1363 instance->AddAllHistogramsRows();
1364 instance->FindTrackCandidatesRow();
1365 instance->AddTracks();
1366 }
1367 return (void *)0;
1368}
1369
1370void AliL3Hough::StartProcessInThread(Int_t minslice,Int_t maxslice)
1371{
1372 if(!fThread) {
1373 char buf[255];
1374 sprintf(buf,"houghtrans_%d_%d",minslice,maxslice);
1375 SetMinMaxSlices(minslice,maxslice);
1376 // fThread = new TThread(buf,(void (*) (void *))&ProcessInThread,(void *)this);
1377 fThread = new TThread(buf,&ProcessInThread,(void *)this);
1378 fThread->Run();
1379 }
1380 return;
1381}
1382
1383Int_t AliL3Hough::WaitForThreadFinish()
1384{
5b83f0b3 1385#if ROOT_VERSION_CODE < 262403
a8ffd46b 1386 return TThread::Join(fThread->GetId());
5b83f0b3 1387#else
1388 return fThread->Join(fThread->GetId());
1389#endif
a8ffd46b 1390}