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