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