3 // Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4 //*-- Copyright © ALICE HLT Group
6 #include "AliL3StandardIncludes.h"
9 #include "AliL3Logging.h"
10 #include "AliL3HoughMerger.h"
11 #include "AliL3HoughIntMerger.h"
12 #include "AliL3HoughGlobalMerger.h"
13 #include "AliL3Histogram.h"
14 #include "AliL3Hough.h"
15 #include "AliL3HoughTransformer.h"
16 #include "AliL3HoughClusterTransformer.h"
17 #include "AliL3HoughTransformerLUT.h"
18 #include "AliL3HoughTransformerVhdl.h"
19 #include "AliL3HoughTransformerRow.h"
20 #include "AliL3HoughMaxFinder.h"
21 #include "AliL3Benchmark.h"
23 #include "AliL3FileHandler.h"
25 #include "AliL3MemHandler.h"
27 #include "AliL3DataHandler.h"
28 #include "AliL3DigitData.h"
29 #include "AliL3HoughEval.h"
30 #include "AliL3Transform.h"
31 #include "AliL3TrackArray.h"
32 #include "AliL3HoughTrack.h"
33 #include "AliL3DDLDataFileHandler.h"
41 //_____________________________________________________________
44 // Interface class for the Hough transform
46 // Example how to use:
48 // AliL3Hough *hough = new AliL3Hough(path,kTRUE,NumberOfEtaSegments);
49 // hough->ReadData(slice);
50 // hough->Transform();
51 // hough->FindTrackCandidates();
53 // AliL3TrackArray *tracks = hough->GetTracks(patch);
60 AliL3Hough::AliL3Hough()
65 fAddHistograms = kFALSE;
66 fDoIterative = kFALSE;
67 fWriteDigits = kFALSE;
71 fHoughTransformer = 0;
92 SetTransformerParams();
97 //just be sure that index is empty for new event
98 AliL3FileHandler::CleanStaticIndex();
105 AliL3Hough::AliL3Hough(Char_t *path,Bool_t binary,Int_t n_eta_segments,Bool_t bit8,Int_t tv,Char_t *infile,Char_t *ptr)
109 fNEtaSegments = n_eta_segments;
110 fAddHistograms = kFALSE;
111 fDoIterative = kFALSE;
112 fWriteDigits = kFALSE;
132 //just be sure that index is empty for new event
133 AliL3FileHandler::CleanStaticIndex();
140 AliL3Hough::~AliL3Hough()
147 //cout << "Cleaned class merger " << endl;
150 //cout << "Cleaned class inter " << endl;
153 //cout << "Cleaned class peak " << endl;
155 delete fGlobalMerger;
156 //cout << "Cleaned class global " << endl;
159 //cout << "Cleaned class bench " << endl;
161 delete fGlobalTracks;
162 //cout << "Cleaned class globaltracks " << endl;
165 void AliL3Hough::CleanUp()
169 for(Int_t i=0; i<fNPatches; i++)
171 if(fTracks[i]) delete fTracks[i];
172 //cout << "Cleaned tracks " << i << endl;
173 if(fEval[i]) delete fEval[i];
174 //cout << "Cleaned eval " << i << endl;
175 if(fHoughTransformer[i]) delete fHoughTransformer[i];
176 //cout << "Cleaned traf " << i << endl;
177 if(fMemHandler[i]) delete fMemHandler[i];
178 //cout << "Cleaned mem " << i << endl;
181 if(fTracks) delete [] fTracks;
182 //cout << "Cleaned class tracks " << endl;
183 if(fEval) delete [] fEval;
184 //cout << "Cleaned class eval " << endl;
185 if(fHoughTransformer) delete [] fHoughTransformer;
186 //cout << "Cleaned cleass trafo " << endl;
187 if(fMemHandler) delete [] fMemHandler;
188 //cout << "Cleaned class mem " << endl;
191 void AliL3Hough::Init(Char_t *path,Bool_t binary,Int_t n_eta_segments,Bool_t bit8,Int_t tv,Char_t *infile,Char_t *ptr,Float_t zvertex)
195 fNEtaSegments = n_eta_segments;
196 fWriteDigits = kFALSE;
215 Init(); //do the rest
218 void AliL3Hough::Init(Bool_t doit, Bool_t addhists)
221 fAddHistograms = addhists;
223 fNPatches = AliL3Transform::GetNPatches();
225 fHoughTransformer = new AliL3HoughBaseTransformer*[fNPatches];
226 fMemHandler = new AliL3MemHandler*[fNPatches];
228 fTracks = new AliL3TrackArray*[fNPatches];
229 fEval = new AliL3HoughEval*[fNPatches];
231 fGlobalTracks = new AliL3TrackArray("AliL3HoughTrack");
233 for(Int_t i=0; i<fNPatches; i++)
235 switch (fVersion){ //choose Transformer
237 fHoughTransformer[i] = new AliL3HoughTransformerLUT(0,i,fNEtaSegments);
240 fHoughTransformer[i] = new AliL3HoughClusterTransformer(0,i,fNEtaSegments);
243 fHoughTransformer[i] = new AliL3HoughTransformerVhdl(0,i,fNEtaSegments,fNSaveIterations);
246 fHoughTransformer[i] = new AliL3HoughTransformerRow(0,i,fNEtaSegments,kFALSE,fZVertex);
249 fHoughTransformer[i] = new AliL3HoughTransformer(0,i,fNEtaSegments,kFALSE,kFALSE);
252 // fHoughTransformer[i]->CreateHistograms(fNBinX[i],fLowPt[i],fNBinY[i],-fPhi[i],fPhi[i]);
253 fHoughTransformer[i]->CreateHistograms(fNBinX[i],-fLowPt[i],fLowPt[i],fNBinY[i],-fPhi[i],fPhi[i]);
254 //fHoughTransformer[i]->CreateHistograms(fLowPt[i],fUpperPt[i],fPtRes[i],fNBinY[i],fPhi[i]);
256 fHoughTransformer[i]->SetLowerThreshold(fThreshold[i]);
257 fHoughTransformer[i]->SetUpperThreshold(100);
259 LOG(AliL3Log::kInformational,"AliL3Hough::Init","Version")
260 <<"Initializing Hough transformer version "<<fVersion<<ENDLOG;
262 fEval[i] = new AliL3HoughEval();
263 fTracks[i] = new AliL3TrackArray("AliL3HoughTrack");
265 fMemHandler[i] = new AliL3DataHandler();
271 /* In case of reading digits file */
272 fMemHandler[i] = new AliL3FileHandler(kTRUE); //use static index
277 Char_t filename[1024];
278 sprintf(filename,"%s/digitfile.root",fPath);
279 fMemHandler[i]->SetAliInput(filename);
283 fMemHandler[i]->SetAliInput(fRunLoader);
289 /* In case of reading from DATE */
290 fMemHandler[i] = new AliL3DDLDataFileHandler();
291 fMemHandler[i]->SetReaderInput(fInputPtr,-1);
295 /* In case of reading rawdata from ROOT file */
296 fMemHandler[i] = new AliL3DDLDataFileHandler();
297 fMemHandler[i]->SetReaderInput(fInputFile);
301 fMemHandler[i] = new AliL3MemHandler();
305 fPeakFinder = new AliL3HoughMaxFinder("KappaPhi",50000);
306 fMerger = new AliL3HoughMerger(fNPatches);
307 fInterMerger = new AliL3HoughIntMerger();
309 fBenchmark = new AliL3Benchmark();
312 void AliL3Hough::SetTransformerParams(Float_t ptres,Float_t ptmin,Float_t ptmax,Int_t ny,Int_t patch)
320 mrow = AliL3Transform::GetLastRow(patch);
323 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
324 Double_t kappa = -1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
325 psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
326 cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
345 fPtRes[patch] = ptres;
346 fLowPt[patch] = ptmin;
347 fUpperPt[patch] = ptmax;
352 void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t ptmin,Int_t patch)
356 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
357 Double_t kappa = -1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
358 Double_t psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
359 cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
372 void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t ptmin,Int_t patch)
377 Double_t lineradius = sqrt(pow(AliL3Transform::Row2X(mrow),2) + pow(AliL3Transform::GetMaxY(mrow),2));
378 Double_t alpha1 = AliL3Transform::GetMaxY(mrow)/pow(lineradius,2);
379 Double_t kappa = 1*AliL3Transform::GetBField()*AliL3Transform::GetBFact()/ptmin;
380 Double_t psi = AliL3Transform::Deg2Rad(10) - asin(lineradius*kappa/2);
381 cout<<"Calculated psi range "<<psi<<" in patch "<<patch<<endl;
382 AliL3HoughTrack track;
383 track.SetTrackParameters(kappa,psi,1);
386 track.GetCrossingPoint(mrow2,hit);
387 Double_t lineradius2 = sqrt(pow(AliL3Transform::Row2X(mrow2),2) + pow(AliL3Transform::GetMaxY(mrow2),2));
388 Double_t alpha2 = hit[1]/pow(lineradius2,2);
389 cout<<"Calculated alphas range "<<alpha1<<" "<<alpha2<<" in patch "<<patch<<endl;
394 fLowPt[i] = 1.15*alpha1;
397 fPhi[i] = 1.15*alpha2;
402 void AliL3Hough::SetTransformerParams(Int_t nx,Int_t ny,Float_t lpt,Float_t phi)
415 void AliL3Hough::SetThreshold(Int_t t3,Int_t patch)
424 fThreshold[patch]=t3;
427 void AliL3Hough::SetPeakThreshold(Int_t threshold,Int_t patch)
433 fPeakThreshold[i++]=threshold;
436 fPeakThreshold[patch]=threshold;
439 void AliL3Hough::DoBench(Char_t *name)
441 fBenchmark->Analyze(name);
444 void AliL3Hough::Process(Int_t minslice,Int_t maxslice)
446 //Process all slices [minslice,maxslice].
447 fGlobalMerger = new AliL3HoughGlobalMerger(minslice,maxslice);
449 for(Int_t i=minslice; i<=maxslice; i++)
457 AddAllHistogramsRows();
459 FindTrackCandidates();
461 //fGlobalMerger->FillTracks(fTracks[0],i);
465 void AliL3Hough::ReadData(Int_t slice,Int_t eventnr)
467 //Read data from files, binary or root.
470 if(fEvent!=eventnr) //just be sure that index is empty for new event
471 AliL3FileHandler::CleanStaticIndex();
473 fCurrentSlice = slice;
475 for(Int_t i=0; i<fNPatches; i++)
477 fMemHandler[i]->Free();
479 AliL3DigitRowData *digits =0;
481 fMemHandler[i]->Init(slice,i);
482 if(fBinary)//take input data from binary files
485 sprintf(name,"%s/binaries/digits_c8_%d_%d_%d.raw",fPath,eventnr,slice,i);
487 sprintf(name,"%s/binaries/digits_%d_%d_%d.raw",fPath,eventnr,slice,i);
489 fMemHandler[i]->SetBinaryInput(name);
490 digits = (AliL3DigitRowData *)fMemHandler[i]->CompBinary2Memory(ndigits);
491 fMemHandler[i]->CloseBinaryInput();
493 else //read data from root file
497 fMemHandler[i]->FreeDigitsTree();//or else the new event is not loaded
498 digits=(AliL3DigitRowData *)fMemHandler[i]->AliAltroDigits2Memory(ndigits,eventnr);
500 cerr<<"You cannot read from rootfile now"<<endl;
504 //set input data and init transformer
505 fHoughTransformer[i]->SetInputData(ndigits,digits);
506 fHoughTransformer[i]->Init(slice,i,fNEtaSegments);
512 void AliL3Hough::Transform(Int_t *row_range)
514 //Transform all data given to the transformer within the given slice
515 //(after ReadData(slice))
517 Double_t initTime,cpuTime;
518 initTime = GetCpuTime();
519 for(Int_t i=0; i<fNPatches; i++)
521 // In case of Row transformer reset the arrays only once
522 if((fVersion != 4) || (i == 0))
523 fHoughTransformer[i]->Reset();//Reset the histograms
524 fBenchmark->Start("Hough Transform");
526 fHoughTransformer[i]->TransformCircle();
528 fHoughTransformer[i]->TransformCircleC(row_range,1);
529 fBenchmark->Stop("Hough Transform");
531 cpuTime = GetCpuTime() - initTime;
532 LOG(AliL3Log::kInformational,"AliL3Hough::Transform()","Timing")
533 <<"Transform done in average per patch of "<<cpuTime*1000/fNPatches<<" ms"<<ENDLOG;
536 void AliL3Hough::MergePatches()
538 if(fAddHistograms) //Nothing to merge here
540 fMerger->MergePatches(kTRUE);
543 void AliL3Hough::MergeInternally()
546 fInterMerger->FillTracks(fTracks[0]);
548 fInterMerger->FillTracks(fMerger->GetOutTracks());
550 fInterMerger->MMerge();
553 void AliL3Hough::ProcessSliceIter()
555 //Process current slice (after ReadData(slice)) iteratively.
559 for(Int_t i=0; i<fNPatches; i++)
562 fMerger->FillTracks(fTracks[i],i); //Copy tracks to merger
567 for(Int_t i=0; i<10; i++)
572 AliL3HoughBaseTransformer *tr = fHoughTransformer[0];
573 for(Int_t j=0; j<fNEtaSegments; j++)
575 AliL3Histogram *hist = tr->GetHistogram(j);
576 if(hist->GetNEntries()==0) continue;
577 fPeakFinder->Reset();
578 fPeakFinder->SetHistogram(hist);
579 fPeakFinder->FindAbsMaxima();
580 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[0]->NextTrack();
581 track->SetTrackParameters(fPeakFinder->GetXPeak(0),fPeakFinder->GetYPeak(0),fPeakFinder->GetWeight(0));
582 track->SetEtaIndex(j);
583 track->SetEta(tr->GetEta(j,fCurrentSlice));
584 for(Int_t k=0; k<fNPatches; k++)
586 fEval[i]->SetNumOfPadsToLook(2);
587 fEval[i]->SetNumOfRowsToMiss(2);
588 fEval[i]->RemoveFoundTracks();
591 if(!fEval[i]->LookInsideRoad(track,nrows))
593 fTracks[0]->Remove(fTracks[0]->GetNTracks()-1);
594 fTracks[0]->Compress();
605 void AliL3Hough::ProcessPatchIter(Int_t patch)
607 //Process patch in a iterative way.
608 //transform + peakfinding + evaluation + transform +...
610 Int_t num_of_tries = 5;
611 AliL3HoughBaseTransformer *tr = fHoughTransformer[patch];
612 AliL3TrackArray *tracks = fTracks[patch];
614 AliL3HoughEval *ev = fEval[patch];
615 ev->InitTransformer(tr);
616 //ev->RemoveFoundTracks();
617 ev->SetNumOfRowsToMiss(3);
618 ev->SetNumOfPadsToLook(2);
619 AliL3Histogram *hist;
620 for(Int_t t=0; t<num_of_tries; t++)
623 tr->TransformCircle();
624 for(Int_t i=0; i<fNEtaSegments; i++)
626 hist = tr->GetHistogram(i);
627 if(hist->GetNEntries()==0) continue;
628 fPeakFinder->Reset();
629 fPeakFinder->SetHistogram(hist);
630 fPeakFinder->FindAbsMaxima();
631 //fPeakFinder->FindPeak1();
632 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->NextTrack();
633 track->SetTrackParameters(fPeakFinder->GetXPeak(0),fPeakFinder->GetYPeak(0),fPeakFinder->GetWeight(0));
634 track->SetEtaIndex(i);
635 track->SetEta(tr->GetEta(i,fCurrentSlice));
638 if(!ev->LookInsideRoad(track,nrows))
640 tracks->Remove(tracks->GetNTracks()-1);
647 LOG(AliL3Log::kInformational,"AliL3Hough::ProcessPatch","NTracks")
648 <<AliL3Log::kDec<<"Found "<<tracks->GetNTracks()<<" tracks in patch "<<patch<<ENDLOG;
651 void AliL3Hough::AddAllHistograms()
653 //Add the histograms within one etaslice.
654 //Resulting histogram are in patch=0.
656 Double_t initTime,cpuTime;
657 initTime = GetCpuTime();
658 fBenchmark->Start("Add Histograms");
659 for(Int_t i=0; i<fNEtaSegments; i++)
661 AliL3Histogram *hist0 = fHoughTransformer[0]->GetHistogram(i);
662 for(Int_t j=1; j<fNPatches; j++)
664 AliL3Histogram *hist = fHoughTransformer[j]->GetHistogram(i);
668 fBenchmark->Stop("Add Histograms");
669 fAddHistograms = kTRUE;
670 cpuTime = GetCpuTime() - initTime;
671 LOG(AliL3Log::kInformational,"AliL3Hough::AddAllHistograms()","Timing")
672 <<"Adding histograms in "<<cpuTime*1000<<" ms"<<ENDLOG;
675 void AliL3Hough::AddAllHistogramsRows()
677 //Add the histograms within one etaslice.
678 //Resulting histogram are in patch=0.
680 Double_t initTime,cpuTime;
681 initTime = GetCpuTime();
682 fBenchmark->Start("Add HistogramsRows");
684 UChar_t *tracknrows = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackNRows();
685 UChar_t *trackfirstrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackFirstRow();
686 UChar_t *tracklastrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackLastRow();
688 for(Int_t i=0; i<fNEtaSegments; i++)
690 UChar_t *rowcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetRowCount(i);
691 UChar_t *gapcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetGapCount(i);
692 UChar_t *currentrowcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetCurrentRowCount(i);
694 AliL3Histogram *hist = fHoughTransformer[0]->GetHistogram(i);
695 Int_t xmin = hist->GetFirstXbin();
696 Int_t xmax = hist->GetLastXbin();
697 Int_t ymin = hist->GetFirstYbin();
698 Int_t ymax = hist->GetLastYbin();
700 for(Int_t ybin=ymin; ybin<=ymax; ybin++)
702 for(Int_t xbin=xmin; xbin<=xmax; xbin++)
704 Int_t bin = hist->GetBin(xbin,ybin);
705 if(tracklastrow[bin] > (currentrowcount[bin] + 1))
707 if(gapcount[bin] < MAX_N_GAPS)
708 if(rowcount[bin] >= MIN_TRACK_LENGTH)
709 if(((Int_t)rowcount[bin] + (Int_t)gapcount[bin])>=((Int_t)tracknrows[bin]-MAX_MISS_ROWS))
710 hist->AddBinContent(bin,(rowcount[bin]+trackfirstrow[bin]+159-tracklastrow[bin]));
715 fBenchmark->Stop("Add HistogramsRows");
716 fAddHistograms = kTRUE;
717 cpuTime = GetCpuTime() - initTime;
718 LOG(AliL3Log::kInformational,"AliL3Hough::AddAllHistogramsRows()","Timing")
719 <<"Adding histograms in "<<cpuTime*1000<<" ms"<<ENDLOG;
722 void AliL3Hough::AddTracks()
726 cerr<<"AliL3Hough::AddTracks : No tracks"<<endl;
729 AliL3TrackArray *tracks = fTracks[0];
730 for(Int_t i=0; i<tracks->GetNTracks(); i++)
732 AliL3Track *track = tracks->GetCheckedTrack(i);
734 if(track->GetNHits()!=1) cerr<<"NHITS "<<track->GetNHits()<<endl;
735 UInt_t *ids = track->GetHitNumbers();
736 ids[0] = (fCurrentSlice&0x7f)<<25;
739 fGlobalTracks->AddTracks(fTracks[0],0,fCurrentSlice);
742 void AliL3Hough::FindTrackCandidatesRow()
745 LOG(AliL3Log::kError,"AliL3Hough::FindTrackCandidatesRow()","")
746 <<"Incompatible Peak Finder version!"<<ENDLOG;
750 //Look for peaks in histograms, and find the track candidates
753 n_patches = 1; //Histograms have been added.
755 n_patches = fNPatches;
757 Double_t initTime,cpuTime;
758 initTime = GetCpuTime();
759 fBenchmark->Start("Find Maxima");
760 for(Int_t i=0; i<n_patches; i++)
762 AliL3HoughBaseTransformer *tr = fHoughTransformer[i];
764 fPeakFinder->Reset();
766 for(Int_t j=0; j<fNEtaSegments; j++)
768 AliL3Histogram *hist = tr->GetHistogram(j);
769 if(hist->GetNEntries()==0) continue;
770 fPeakFinder->SetHistogram(hist);
771 fPeakFinder->SetEtaSlice(j);
773 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","")
774 <<"Starting "<<j<<" etaslice"<<ENDLOG;
776 fPeakFinder->SetThreshold(fPeakThreshold[i]);
777 fPeakFinder->FindAdaptedRowPeaks(1,0,0);//Maxima finder for HoughTransformerRow
779 //fPeakFinder->FindMaxima(fPeakThreshold[i]); //Simple maxima finder
782 for(Int_t k=0; k<fPeakFinder->GetEntries(); k++)
784 if(fPeakFinder->GetWeight(k) < 0) continue;
785 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[i]->NextTrack();
786 Float_t psi = atan((fPeakFinder->GetXPeak(k)-fPeakFinder->GetYPeak(k))/(AliL3HoughTransformerRow::GetBeta1()-AliL3HoughTransformerRow::GetBeta2()));
787 Float_t kappa = 2.0*(fPeakFinder->GetXPeak(k)*cos(psi)-AliL3HoughTransformerRow::GetBeta1()*sin(psi));
788 // track->SetTrackParameters(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetWeight(k));
789 track->SetTrackParameters(kappa,psi,fPeakFinder->GetWeight(k));
790 track->SetBinXY(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetXPeakSize(k),fPeakFinder->GetYPeakSize(k));
791 Int_t etaindex = (fPeakFinder->GetStartEta(k)+fPeakFinder->GetEndEta(k))/2;
792 track->SetEtaIndex(etaindex);
793 Float_t starteta = tr->GetEta(fPeakFinder->GetStartEta(k),fCurrentSlice);
794 Float_t endeta = tr->GetEta(fPeakFinder->GetEndEta(k),fCurrentSlice);
795 track->SetEta((starteta+endeta)/2.0);
796 track->SetRowRange(AliL3Transform::GetFirstRow(0),AliL3Transform::GetLastRow(5));
797 track->SetSector(fCurrentSlice);
798 track->SetSlice(fCurrentSlice);
800 Int_t label = tr->GetTrackID(etaindex,fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k));
801 track->SetMCid(label);
802 // cout<<"Track found with label "<<label<<" at "<<fPeakFinder->GetXPeak(k)<<" "<<fPeakFinder->GetYPeak(k)<<" with weight "<<fPeakFinder->GetWeight(k)<<endl;
805 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","")
806 <<"Found "<<fTracks[i]->GetNTracks()<<" tracks in patch "<<i<<ENDLOG;
809 fBenchmark->Stop("Find Maxima");
810 cpuTime = GetCpuTime() - initTime;
811 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","Timing")
812 <<"Maxima finding done in "<<cpuTime*1000<<" ms"<<ENDLOG;
815 void AliL3Hough::FindTrackCandidates()
818 LOG(AliL3Log::kError,"AliL3Hough::FindTrackCandidatesRow()","")
819 <<"Incompatible Peak Finder version!"<<ENDLOG;
825 n_patches = 1; //Histograms have been added.
827 n_patches = fNPatches;
829 Double_t initTime,cpuTime;
830 initTime = GetCpuTime();
831 fBenchmark->Start("Find Maxima");
832 for(Int_t i=0; i<n_patches; i++)
834 AliL3HoughBaseTransformer *tr = fHoughTransformer[i];
837 for(Int_t j=0; j<fNEtaSegments; j++)
839 AliL3Histogram *hist = tr->GetHistogram(j);
840 if(hist->GetNEntries()==0) continue;
841 fPeakFinder->Reset();
842 fPeakFinder->SetHistogram(hist);
844 cout<<"Starting "<<j<<" etaslice"<<endl;
846 fPeakFinder->SetThreshold(fPeakThreshold[i]);
847 fPeakFinder->FindAdaptedPeaks(fKappaSpread,fPeakRatio);
849 for(Int_t k=0; k<fPeakFinder->GetEntries(); k++)
851 AliL3HoughTrack *track = (AliL3HoughTrack*)fTracks[i]->NextTrack();
852 track->SetTrackParameters(fPeakFinder->GetXPeak(k),fPeakFinder->GetYPeak(k),fPeakFinder->GetWeight(k));
853 track->SetEtaIndex(j);
854 track->SetEta(tr->GetEta(j,fCurrentSlice));
855 track->SetRowRange(AliL3Transform::GetFirstRow(0),AliL3Transform::GetLastRow(5));
858 cout<<"Found "<<fTracks[i]->GetNTracks()<<" tracks in patch "<<i<<endl;
861 fBenchmark->Stop("Find Maxima");
862 cpuTime = GetCpuTime() - initTime;
863 LOG(AliL3Log::kInformational,"AliL3Hough::FindTrackCandidates()","Timing")
864 <<"Maxima finding done in "<<cpuTime*1000<<" ms"<<ENDLOG;
867 void AliL3Hough::InitEvaluate()
869 //Pass the transformer objects to the AliL3HoughEval objects:
870 //This will provide the evaluation objects with all the necessary
871 //data and parameters it needs.
873 for(Int_t i=0; i<fNPatches; i++)
874 fEval[i]->InitTransformer(fHoughTransformer[i]);
877 Int_t AliL3Hough::Evaluate(Int_t road_width,Int_t nrowstomiss)
879 //Evaluate the tracks, by looking along the road in the raw data.
880 //If track does not cross all padrows - rows2miss, it is removed from the arrray.
881 //If histograms were not added, the check is done locally in patch,
882 //meaning that nrowstomiss is the number of padrows the road can miss with respect
883 //to the number of rows in the patch.
884 //If the histograms were added, the comparison is done globally in the _slice_,
885 //meaing that nrowstomiss is the number of padrows the road can miss with
886 //respect to the total number of padrows in the slice.
888 //Return value = number of tracks which were removed (only in case of fAddHistograms)
892 LOG(AliL3Log::kError,"AliL3Hough::Evaluate","Track Array")
893 <<"No tracks to work with..."<<ENDLOG;
897 Int_t removed_tracks=0;
898 AliL3TrackArray *tracks=0;
903 for(Int_t i=0; i<tracks->GetNTracks(); i++)
905 AliL3Track *track = tracks->GetCheckedTrack(i);
911 for(Int_t i=0; i<fNPatches; i++)
912 EvaluatePatch(i,road_width,nrowstomiss);
914 //Here we check the tracks globally;
915 //how many good rows (padrows with signal)
916 //did it cross in the slice
919 for(Int_t j=0; j<tracks->GetNTracks(); j++)
921 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
923 if(track->GetNHits() < AliL3Transform::GetNRows() - nrowstomiss)
933 return removed_tracks;
936 void AliL3Hough::EvaluatePatch(Int_t i,Int_t road_width,Int_t nrowstomiss)
940 fEval[i]->InitTransformer(fHoughTransformer[i]);
941 fEval[i]->SetNumOfPadsToLook(road_width);
942 fEval[i]->SetNumOfRowsToMiss(nrowstomiss);
943 //fEval[i]->RemoveFoundTracks();
945 AliL3TrackArray *tracks=0;
953 for(Int_t j=0; j<tracks->GetNTracks(); j++)
955 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
958 LOG(AliL3Log::kWarning,"AliL3Hough::EvaluatePatch","Track array")
959 <<"Track object missing!"<<ENDLOG;
963 Int_t rowrange[2] = {AliL3Transform::GetFirstRow(i),AliL3Transform::GetLastRow(i)};
964 Bool_t result = fEval[i]->LookInsideRoad(track,nrows,rowrange);
967 Int_t pre=track->GetNHits();
968 track->SetNHits(pre+nrows);
970 else//the track crossed too few good padrows (padrows with signal) in the patch, so remove it
981 void AliL3Hough::MergeEtaSlices()
983 //Merge tracks found in neighbouring eta slices.
984 //Removes the track with the lower weight.
986 fBenchmark->Start("Merge Eta-slices");
987 AliL3TrackArray *tracks = fTracks[0];
990 cerr<<"AliL3Hough::MergeEtaSlices : No tracks "<<endl;
993 for(Int_t j=0; j<tracks->GetNTracks(); j++)
995 AliL3HoughTrack *track1 = (AliL3HoughTrack*)tracks->GetCheckedTrack(j);
996 if(!track1) continue;
997 for(Int_t k=j+1; k<tracks->GetNTracks(); k++)
999 AliL3HoughTrack *track2 = (AliL3HoughTrack*)tracks->GetCheckedTrack(k);
1000 if(!track2) continue;
1001 if(abs(track1->GetEtaIndex() - track2->GetEtaIndex()) != 1) continue;
1002 if(fabs(track1->GetKappa()-track2->GetKappa()) < 0.006 &&
1003 fabs(track1->GetPsi()- track2->GetPsi()) < 0.1)
1005 //cout<<"Merging track in slices "<<track1->GetEtaIndex()<<" "<<track2->GetEtaIndex()<<endl;
1006 if(track1->GetWeight() > track2->GetWeight())
1013 fBenchmark->Stop("Merge Eta-slices");
1017 void AliL3Hough::WriteTracks(Char_t *path)
1019 //cout<<"AliL3Hough::WriteTracks : Sorting the tracsk"<<endl;
1020 //fGlobalTracks->QSort();
1022 Char_t filename[1024];
1023 sprintf(filename,"%s/tracks_%d.raw",path,fEvent);
1024 AliL3MemHandler mem;
1025 mem.SetBinaryOutput(filename);
1026 mem.TrackArray2Binary(fGlobalTracks);
1027 mem.CloseBinaryOutput();
1028 fGlobalTracks->Reset();
1031 void AliL3Hough::WriteTracks(Int_t slice,Char_t *path)
1034 AliL3MemHandler mem;
1038 sprintf(fname,"%s/tracks_ho_%d_%d.raw",path,fEvent,slice);
1039 mem.SetBinaryOutput(fname);
1040 mem.TrackArray2Binary(fTracks[0]);
1041 mem.CloseBinaryOutput();
1045 for(Int_t i=0; i<fNPatches; i++)
1047 sprintf(fname,"%s/tracks_ho_%d_%d_%d.raw",path,fEvent,slice,i);
1048 mem.SetBinaryOutput(fname);
1049 mem.TrackArray2Binary(fTracks[i]);
1050 mem.CloseBinaryOutput();
1055 void AliL3Hough::WriteDigits(Char_t *outfile)
1058 //Write the current data to a new rootfile.
1060 for(Int_t i=0; i<fNPatches; i++)
1062 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fHoughTransformer[i]->GetDataPointer();
1063 fMemHandler[i]->AliDigits2RootFile(tempPt,outfile);
1066 cerr<<"AliL3Hough::WriteDigits : You need to compile with AliROOT!"<<endl;
1071 Double_t AliL3Hough::GetCpuTime()
1073 //Return the Cputime in seconds.
1075 gettimeofday( &tv, NULL );
1076 return tv.tv_sec+(((Double_t)tv.tv_usec)/1000000.);