Some changes
[u/mrichter/AliRoot.git] / HLT / hough / AliL3Hough.cxx
1 //Author:        Anders Strand Vestbo
2 //Last Modified: 28.6.01
3
4 #include <string.h>
5 #include <TCanvas.h>
6 #include <TFile.h>
7
8 #include "AliL3Histogram.h"
9 #include "AliL3Hough.h"
10 #include "AliL3HoughTransformer.h"
11 #include "AliL3HoughMaxFinder.h"
12 #include "AliL3FileHandler.h"
13 #include "AliL3DigitData.h"
14 #include "AliL3HoughEval.h"
15 #include "AliL3Transform.h"
16 #include "AliL3Defs.h"
17 #include "AliL3TrackArray.h"
18 #include "AliL3HoughTrack.h"
19
20 ClassImp(AliL3Hough)
21
22 AliL3Hough::AliL3Hough()
23 {
24
25
26
27 }
28
29
30 AliL3Hough::AliL3Hough(Int_t n_eta_segments,Int_t xbin,Double_t *xrange,Int_t ybin,Double_t *yrange)
31 {
32   
33   fNEtaSegments = n_eta_segments;
34   fNxbin = xbin;
35   fNybin = ybin;
36   fXmin = xrange[0];
37   fXmax = xrange[1];
38   fYmin = yrange[0];
39   fYmax = yrange[1];
40
41   fMemHandler = new AliL3FileHandler();
42   fMaxFinder = new AliL3HoughMaxFinder("KappaPhi");
43   fEval = new AliL3HoughEval();
44   fTransform = new AliL3Transform();
45   fDeleteTrack = kTRUE;
46   fTracks = new AliL3TrackArray("AliL3HoughTrack");
47 }
48
49
50 AliL3Hough::~AliL3Hough()
51 {
52   
53   if(fHoughTransformer)
54     delete fHoughTransformer;
55   if(fMemHandler)
56     delete fMemHandler;
57   if(fMaxFinder)
58     delete fMaxFinder;
59   if(fEval)
60     delete fEval;
61   if(fTransform)
62     delete fTransform;
63 }
64
65 void AliL3Hough::SetInput(Char_t *input,Bool_t binary)
66 {
67   if(binary)
68     {
69       strcpy(fPath,input);
70       fUseBinary = kTRUE;
71     }
72   else
73     {
74       TFile *file = new TFile(input);
75       fMemHandler->SetAliInput(file);
76       fUseBinary = kFALSE;
77     }
78   
79 }
80
81 void AliL3Hough::ProcessSlice(Int_t slice)
82 {
83   
84 }
85
86 void AliL3Hough::ProcessPatch(Int_t slice,Int_t patch)
87 {
88   
89   Char_t histname[50];
90   Int_t i;
91   
92   if(fHoughTransformer)
93     delete fHoughTransformer;
94   fHoughTransformer = new AliL3HoughTransformer(slice,patch);//,0,fNEtaSegments);
95   
96   fHistos = new AliL3Histogram*[fNEtaSegments];
97   printf("Allocating %d bytes to histograms\n",fNEtaSegments*sizeof(AliL3Histogram));
98   for(i=0; i<fNEtaSegments; i++)
99     {
100       sprintf(histname,"hist%d",i);
101       fHistos[i] = new AliL3Histogram(histname,"",fNxbin,fXmin,fXmax,fNybin,fYmin,fYmax);
102     }
103
104   Char_t name[256];
105   
106   UInt_t ndigits=0;
107   AliL3DigitRowData *digits =0;
108   // fMemHandler->Init(slice,patch,NRows[patch]);
109   //fMemHandler->Init(fTransform);
110   if(fUseBinary)
111     {
112       fMemHandler->Free();
113       sprintf(name,"%sdigits_%d_%d.raw",fPath,slice,patch);
114       fMemHandler->SetBinaryInput(name);
115       digits = (AliL3DigitRowData *)fMemHandler->CompBinary2Memory(ndigits);
116       fMemHandler->CloseBinaryInput();
117     }
118   else
119     {
120       digits=(AliL3DigitRowData *)fMemHandler->AliDigits2Memory(ndigits); 
121     }
122   printf("Setting up tables\n");
123   fHoughTransformer->SetHistogram(fHistos[0]);
124   fHoughTransformer->InitTables();
125   fHoughTransformer->SetInputData(ndigits,digits);
126   fEval->SetTransformer(fHoughTransformer);
127   
128   AliL3HoughTrack *track;
129   Int_t good_count;
130   while(1)
131     {
132       fHoughTransformer->TransformTables(fHistos);
133       
134       good_count=0;
135       for(Int_t e=0; e<fNEtaSegments; e++)
136         {
137           fMaxFinder->SetHistogram(fHistos[e]);
138           track = (AliL3HoughTrack*)fMaxFinder->FindPeak(3,0.95,5);
139           if(fEval->LookInsideRoad(track,e,fDeleteTrack))
140             {
141               //Found a good track here
142               fTracks->AddLast(track);
143               good_count++;
144             }
145         }
146       break;
147       if(good_count==0)
148         break;
149     }
150   printf("good_count %d\n",good_count);
151   
152 }
153