Merged version. Bug still remains. New implementation started with AliL3HoughTransfor...
[u/mrichter/AliRoot.git] / HLT / hough / AliL3HoughEval.cxx
CommitLineData
95a00d93 1//$Id$
2
b1886074 3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>
4//*-- Copyright &copy ASV
f80b98cb 5
162e2e5a 6#include <math.h>
95a00d93 7#include <iostream.h>
8#ifdef use_root
b46b21a5 9#include <TH1.h>
162e2e5a 10#include <TFile.h>
95a00d93 11#endif
b46b21a5 12#include "AliL3MemHandler.h"
162e2e5a 13#include "AliL3TrackArray.h"
14#include "AliL3Logging.h"
99e7186b 15#include "AliL3HoughEval.h"
237d3f5c 16#include "AliL3HoughBaseTransformer.h"
99e7186b 17#include "AliL3DigitData.h"
4de874d1 18#include "AliL3HoughTrack.h"
99e7186b 19#include "AliL3Transform.h"
20#include "AliL3Histogram.h"
b46b21a5 21#include "AliL3Histogram1D.h"
4de874d1 22
b1886074 23//_____________________________________________________________
24// AliL3HoughEval
25//
26// Evaluation class for tracklets produced by the Hough transform.
27
4de874d1 28ClassImp(AliL3HoughEval)
29
4de874d1 30AliL3HoughEval::AliL3HoughEval()
4de874d1 31{
4fc9a6a4 32
99e7186b 33 fRemoveFoundTracks = kFALSE;
f80b98cb 34 fNumOfPadsToLook = 1;
99e7186b 35 fNumOfRowsToMiss = 1;
b46b21a5 36 fEtaHistos=0;
b1886074 37 fRowPointers = 0;
4de874d1 38}
39
b46b21a5 40
4de874d1 41AliL3HoughEval::~AliL3HoughEval()
42{
b46b21a5 43 fHoughTransformer = 0;
99e7186b 44 if(fRowPointers)
b1886074 45 {
46 for(Int_t i=0; i<fNrows; i++)
47 fRowPointers[i] = 0;
48 delete [] fRowPointers;
49 }
4de874d1 50}
51
237d3f5c 52void AliL3HoughEval::InitTransformer(AliL3HoughBaseTransformer *transformer)
b46b21a5 53{
54 fHoughTransformer = transformer;
55 fSlice = fHoughTransformer->GetSlice();
56 fPatch = fHoughTransformer->GetPatch();
26abc209 57 fNrows = AliL3Transform::GetLastRow(fPatch) - AliL3Transform::GetFirstRow(fPatch) + 1;
b46b21a5 58 fNEtaSegments = fHoughTransformer->GetNEtaSegments();
59 fEtaMin = fHoughTransformer->GetEtaMin();
60 fEtaMax = fHoughTransformer->GetEtaMax();
61 GenerateLUT();
62}
63
99e7186b 64void AliL3HoughEval::GenerateLUT()
4de874d1 65{
b46b21a5 66 //Generate a Look-up table, to limit the access to raw data
99e7186b 67
b1886074 68 if(!fRowPointers)
69 fRowPointers = new AliL3DigitRowData*[fNrows];
99e7186b 70
71 AliL3DigitRowData *tempPt = (AliL3DigitRowData*)fHoughTransformer->GetDataPointer();
72 if(!tempPt)
b46b21a5 73 printf("\nAliL3HoughEval::GenerateLUT : Zero data pointer\n");
f80b98cb 74
26abc209 75 for(Int_t i=AliL3Transform::GetFirstRow(fPatch); i<=AliL3Transform::GetLastRow(fPatch); i++)
f80b98cb 76 {
26abc209 77 Int_t prow = i - AliL3Transform::GetFirstRow(fPatch);
99e7186b 78 fRowPointers[prow] = tempPt;
b46b21a5 79 AliL3MemHandler::UpdateRowPointer(tempPt);
f80b98cb 80 }
81
99e7186b 82}
f80b98cb 83
0309a5ee 84Bool_t AliL3HoughEval::LookInsideRoad(AliL3HoughTrack *track,Int_t &nrows_crossed,Bool_t remove)
99e7186b 85{
86 //Look at rawdata along the road specified by the track candidates.
87 //If track is good, return true, if not return false.
162e2e5a 88
f80b98cb 89 Int_t sector,row;
99e7186b 90
0309a5ee 91 Int_t nrow=0,npixs=0;//,rows_crossed=0;
f80b98cb 92 Float_t xyz[3];
99e7186b 93
b46b21a5 94 Int_t total_charge=0;//total charge along the road
0309a5ee 95
26abc209 96 for(Int_t padrow = AliL3Transform::GetFirstRow(fPatch); padrow <= AliL3Transform::GetLastRow(fPatch); padrow++)
f80b98cb 97 {
26abc209 98 Int_t prow = padrow - AliL3Transform::GetFirstRow(fPatch);
f80b98cb 99 if(!track->GetCrossingPoint(padrow,xyz))
100 {
f80b98cb 101 continue;
102 }
103
4ab9f8f0 104 AliL3Transform::Slice2Sector(fSlice,padrow,sector,row);
105 AliL3Transform::Local2Raw(xyz,sector,row);
6c97129d 106
f80b98cb 107 npixs=0;
99e7186b 108
109 //Get the timebins for this pad
110 AliL3DigitRowData *tempPt = fRowPointers[prow];
111 if(!tempPt)
f80b98cb 112 {
99e7186b 113 printf("AliL3HoughEval::LookInsideRoad : Zero data pointer\n");
114 continue;
f80b98cb 115 }
116
99e7186b 117 //Look at both sides of the pad:
162e2e5a 118 for(Int_t p=(Int_t)rint(xyz[1])-fNumOfPadsToLook; p<=(Int_t)rint(xyz[1])+fNumOfPadsToLook; p++)
99e7186b 119 {
120 AliL3DigitData *digPt = tempPt->fDigitData;
121 for(UInt_t j=0; j<tempPt->fNDigit; j++)
122 {
123 UChar_t pad = digPt[j].fPad;
0309a5ee 124 Int_t charge = digPt[j].fCharge;
125 if(charge <= fHoughTransformer->GetLowerThreshold()) continue;
99e7186b 126 if(pad < p) continue;
127 if(pad > p) break;
128 UShort_t time = digPt[j].fTime;
4ab9f8f0 129 Double_t eta = AliL3Transform::GetEta(padrow,pad,time);
3fe49b5b 130 Int_t pixel_index = fHoughTransformer->GetEtaIndex(eta);
a4639de2 131 if(pixel_index != track->GetEtaIndex()) continue;
b46b21a5 132 total_charge += digPt[j].fCharge;
99e7186b 133 if(remove)
b46b53c1 134 digPt[j].fCharge = 0; //Erase the track from image
99e7186b 135 npixs++;
136 }
137 }
138
162e2e5a 139 if(npixs > 1)//At least 2 digits on this padrow
f80b98cb 140 {
141 nrow++;
142 }
143 }
99e7186b 144 if(remove)
145 return kTRUE;
146
0309a5ee 147 nrows_crossed += nrow; //Update the number of rows crossed.
148
149 if(nrow >= AliL3Transform::GetNRows(fPatch) - fNumOfRowsToMiss)//this was a good track
f80b98cb 150 {
99e7186b 151 if(fRemoveFoundTracks)
0309a5ee 152 {
153 Int_t dummy=0;
154 LookInsideRoad(track,dummy,kTRUE);
155 }
f80b98cb 156 return kTRUE;
157 }
158 else
159 return kFALSE;
160}
161
b46b21a5 162void AliL3HoughEval::FindEta(AliL3TrackArray *tracks)
163{
164
165 Int_t sector,row;
166 Float_t xyz[3];
167
168 Int_t ntracks = tracks->GetNTracks();
169 fEtaHistos = new AliL3Histogram1D*[ntracks];
170
171 Char_t hname[100];
172 for(Int_t i=0; i<ntracks; i++)
173 {
174 sprintf(hname,"etahist_%d",i);
175 fEtaHistos[i] = new AliL3Histogram1D(hname,hname,100,0,1);
176 }
177 Double_t etaslice = (fEtaMax - fEtaMin)/fNEtaSegments;
178
179 for(Int_t ntr=0; ntr<ntracks; ntr++)
180 {
181 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(ntr);
182 if(!track) continue;
26abc209 183 for(Int_t padrow = AliL3Transform::GetFirstRow(fPatch); padrow <= AliL3Transform::GetLastRow(fPatch); padrow++)
b46b21a5 184 {
26abc209 185 Int_t prow = padrow - AliL3Transform::GetFirstRow(fPatch);
b46b21a5 186
187 if(!track->GetCrossingPoint(padrow,xyz))
188 {
189 printf("AliL3HoughEval::LookInsideRoad : Track does not cross line!!\n");
190 continue;
191 }
192
4ab9f8f0 193 AliL3Transform::Slice2Sector(fSlice,padrow,sector,row);
194 AliL3Transform::Local2Raw(xyz,sector,row);
b46b21a5 195
196 //Get the timebins for this pad
197 AliL3DigitRowData *tempPt = fRowPointers[prow];
198 if(!tempPt)
199 {
200 printf("AliL3HoughEval::LookInsideRoad : Zero data pointer\n");
201 continue;
202 }
203
204 //Look at both sides of the pad:
205 for(Int_t p=(Int_t)rint(xyz[1])-fNumOfPadsToLook; p<=(Int_t)rint(xyz[1])+fNumOfPadsToLook; p++)
206 {
207 AliL3DigitData *digPt = tempPt->fDigitData;
208 for(UInt_t j=0; j<tempPt->fNDigit; j++)
209 {
210 UChar_t pad = digPt[j].fPad;
0309a5ee 211 Int_t charge = digPt[j].fCharge;
212 if(charge <= fHoughTransformer->GetLowerThreshold()) continue;
b46b21a5 213 if(pad < p) continue;
214 if(pad > p) break;
215 UShort_t time = digPt[j].fTime;
4ab9f8f0 216 Double_t eta = AliL3Transform::GetEta(padrow,pad,time);
b46b21a5 217 Int_t pixel_index = (Int_t)(eta/etaslice);
218 if(pixel_index > track->GetEtaIndex()+1) continue;
219 if(pixel_index < track->GetEtaIndex()-1) break;
220 fEtaHistos[ntr]->Fill(eta,digPt[j].fCharge);
221 }
222 }
223 }
224 }
225
226 for(Int_t i=0; i<ntracks; i++)
227 {
228 AliL3Histogram1D *hist = fEtaHistos[i];
229 Int_t max_bin = hist->GetMaximumBin();
230 Double_t max_value = hist->GetBinContent(max_bin);
231 AliL3HoughTrack *track = (AliL3HoughTrack*)tracks->GetCheckedTrack(i);
232 if(!track) continue;
233 if(hist->GetBinContent(max_bin-1)<max_value && hist->GetBinContent(max_bin+1)<max_value)
234 {
235 track->SetWeight((Int_t)max_value,kTRUE);
236 track->SetEta(hist->GetBinCenter(max_bin));
237 track->SetNHits(track->GetWeight());
238 }
239 else
240 {
241 track->SetWeight(0);
242 tracks->Remove(i); //remove this track, because it was not a peak
243 }
244 }
245 tracks->Compress();
246
247 //for(Int_t i=0; i<ntracks; i++)
248 //delete fEtaHistos[i];
249