Cleaning up a lot
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughEval.cxx
1 //Author:        Anders Strand Vestbo
2 //Last Modified: 28.6.01
3
4 #include "AliL3HoughEval.h"
5 #include "AliL3HoughTransformer.h"
6 #include "AliL3DigitData.h"
7 #include "AliL3HoughTrack.h"
8 #include "AliL3Transform.h"
9 #include "AliL3Histogram.h"
10 #include "AliL3Defs.h"
11
12 ClassImp(AliL3HoughEval)
13
14 AliL3HoughEval::AliL3HoughEval()
15 {
16
17 }
18
19 AliL3HoughEval::AliL3HoughEval(AliL3HoughTransformer *transformer)
20 {
21
22   fHoughTransformer = transformer;
23   fTransform = new AliL3Transform();
24   
25   fSlice = fHoughTransformer->GetSlice();
26   fPatch = fHoughTransformer->GetPatch();
27   fNrows = NRows[fPatch][1] - NRows[fPatch][0] + 1;
28   fNEtaSegments = fHoughTransformer->GetNEtaSegments();
29   fEtaMin = fHoughTransformer->GetEtaMin();
30   fEtaMax = fHoughTransformer->GetEtaMax();
31   fRemoveFoundTracks = kFALSE;
32   fNumOfPadsToLook = 1;
33   fNumOfRowsToMiss = 1;
34   GenerateLUT();
35 }
36
37 AliL3HoughEval::~AliL3HoughEval()
38 {
39   if(fTransform)
40     delete fTransform;
41   if(fRowPointers)
42     delete [] fRowPointers;
43 }
44
45 void AliL3HoughEval::GenerateLUT()
46 {
47   //Generate a LUT, to limit the access to raw data
48   
49   fRowPointers = new AliL3DigitRowData*[fNrows];
50
51   AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fHoughTransformer->GetDataPointer();
52   if(!tempPt)
53     printf("AliL3HoughEval::GenerateLUT : Zero data pointer\n");
54   
55   for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
56     {
57       Int_t prow = i - NRows[fPatch][0];
58       fRowPointers[prow] = tempPt;
59       tempPt = fHoughTransformer->UpdateDataPointer(tempPt);
60     }
61   
62 }
63
64 Bool_t AliL3HoughEval::LookInsideRoad(AliL3HoughTrack *track,Int_t eta_index,Bool_t remove)
65 {
66   //Look at rawdata along the road specified by the track candidates.
67   //If track is good, return true, if not return false.
68     
69   Int_t sector,row;
70   
71   Int_t nrow=0,npixs=0;
72   Float_t xyz[3];
73   
74   Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
75   for(Int_t padrow = NRows[fPatch][0]; padrow <= NRows[fPatch][1]; padrow++)
76     {
77       Int_t prow = padrow - NRows[fPatch][0];
78       
79       if(!track->GetCrossingPoint(padrow,xyz))  
80         {
81           printf("AliL3HoughEval::LookInsideRoad : Track does not cross line!!\n");
82           continue;
83         }
84       
85       fTransform->Slice2Sector(fSlice,padrow,sector,row);
86       fTransform->Local2Raw(xyz,sector,row);
87       npixs=0;
88       
89       //Get the timebins for this pad
90       AliL3DigitRowData *tempPt = fRowPointers[prow];
91       if(!tempPt) 
92         {
93           printf("AliL3HoughEval::LookInsideRoad : Zero data pointer\n");
94           continue;
95         }
96       
97       //Look at both sides of the pad:
98       for(Int_t p=(Int_t)xyz[1]-fNumOfPadsToLook; p<=(Int_t)xyz[1]+fNumOfPadsToLook; p++)
99         {
100           AliL3DigitData *digPt = tempPt->fDigitData;
101           for(UInt_t j=0; j<tempPt->fNDigit; j++)
102             {
103               UChar_t pad = digPt[j].fPad;
104               if(pad < p) continue;
105               if(pad > p) break;
106               UShort_t time = digPt[j].fTime;
107               Double_t eta = fTransform->GetEta(row,pad,time);
108               Int_t pixel_index = (Int_t)(eta/etaslice);
109               if(pixel_index > eta_index) continue;
110               if(pixel_index != eta_index) break;
111               if(remove)
112                 digPt[j].fCharge = 0; //Delete the track from image
113               npixs++;
114             }
115         }
116             
117       if(npixs > 0)
118         {
119           nrow++;
120         }         
121     }
122   if(remove)
123     return kTRUE;
124   
125   if(nrow >= fNrows - fNumOfRowsToMiss)//this was a good track
126     {
127       track->SetEtaIndex(eta_index);
128       if(fRemoveFoundTracks)
129         LookInsideRoad(track,eta_index,kTRUE);
130       return kTRUE;
131     }
132   else
133     return kFALSE;
134 }
135
136 void AliL3HoughEval::DisplayEtaSlice(Int_t eta_index,AliL3Histogram *hist)
137 {
138   //Display the current raw data inside the slice
139
140   if(!hist)
141     {
142       printf("AliL3HoughEval::DisplayEtaSlice : No input histogram!\n");
143       return;
144     }
145   
146   Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
147   for(Int_t padrow = NRows[fPatch][0]; padrow <= NRows[fPatch][1]; padrow++)
148     {
149       Int_t prow = padrow - NRows[fPatch][0];
150                   
151       AliL3DigitRowData *tempPt = fRowPointers[prow];
152       if(!tempPt) 
153         {
154           printf("AliL3HoughEval::DisplayEtaSlice : Zero data pointer\n");
155           continue;
156         }
157       
158       AliL3DigitData *digPt = tempPt->fDigitData;
159       for(UInt_t j=0; j<tempPt->fNDigit; j++)
160         {
161           UChar_t pad = digPt[j].fPad;
162           UChar_t charge = digPt[j].fCharge;
163           UShort_t time = digPt[j].fTime;
164           Float_t xyz[3];
165           Int_t sector,row;
166           fTransform->Slice2Sector(fSlice,padrow,sector,row);
167           fTransform->Raw2Local(xyz,sector,row,pad,time);
168           Double_t eta = fTransform->GetEta(xyz);
169           Int_t pixel_index = (Int_t)(eta/etaslice);
170           if(pixel_index != eta_index) continue;
171           hist->Fill(xyz[0],xyz[1],charge);
172         }
173     }
174   
175 }