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