]>
Commit | Line | Data |
---|---|---|
0128a907 | 1 | // $Id$ |
4aa41877 | 2 | // Original: AliHLTTrackMerger.cxx,v 1.12 2005/06/14 10:55:21 cvetan |
a6c02c85 | 3 | |
0128a907 | 4 | //************************************************************************** |
5 | //* This file is property of and copyright by the ALICE HLT Project * | |
6 | //* ALICE Experiment at CERN, All rights reserved. * | |
7 | //* * | |
8 | //* Primary Authors: Uli Frankenfeld, maintained by * | |
9 | //* Matthias Richter <Matthias.Richter@ift.uib.no> * | |
10 | //* for The ALICE HLT Project. * | |
11 | //* * | |
12 | //* Permission to use, copy, modify and distribute this software and its * | |
13 | //* documentation strictly for non-commercial purposes is hereby granted * | |
14 | //* without fee, provided that the above copyright notice appears in all * | |
15 | //* copies and that both the copyright notice and this permission notice * | |
16 | //* appear in the supporting documentation. The authors make no claims * | |
17 | //* about the suitability of this software for any purpose. It is * | |
18 | //* provided "as is" without express or implied warranty. * | |
19 | //************************************************************************** | |
2a083ac4 | 20 | |
0128a907 | 21 | /// @file AliHLTTPCTrackMerger.cxx |
22 | /// @author Uli Frankenfeld, maintained by Matthias Richter | |
23 | /// @date | |
24 | /// @brief The HLT TPC track segment merger | |
25 | /// | |
a6c02c85 | 26 | |
a6c02c85 | 27 | #include "AliHLTTPCLogging.h" |
28 | #include "AliHLTTPCTrackMerger.h" | |
29 | #include "AliHLTTPCTrack.h" | |
30 | #include "AliHLTTPCTrackSegmentData.h" | |
31 | #include "AliHLTTPCTransform.h" | |
32 | #include "AliHLTTPCTrackArray.h" | |
33 | ||
34 | #if __GNUC__ >= 3 | |
35 | using namespace std; | |
36 | #endif | |
37 | ||
38 | ClassImp(AliHLTTPCTrackMerger) | |
39 | ||
1204d026 | 40 | AliHLTTPCTrackMerger::AliHLTTPCTrackMerger() |
41 | : | |
42 | AliHLTTPCMerger(), | |
43 | fSubSector(0), | |
44 | fNSubSector(0), | |
45 | fRowMin(NULL), | |
46 | fRowMax(NULL), | |
47 | fSlow(0) | |
5d2abf3b | 48 | { |
a6c02c85 | 49 | //Default constructor |
50 | Is2Global(kFALSE); | |
a6c02c85 | 51 | SetParameter(); |
a6c02c85 | 52 | } |
53 | ||
54 | ||
1204d026 | 55 | AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(Int_t nsubsectors) |
56 | : | |
57 | AliHLTTPCMerger(), | |
58 | fSubSector(0), | |
59 | fNSubSector(nsubsectors), | |
60 | fRowMin(new Int_t[nsubsectors]), | |
61 | fRowMax(new Int_t[nsubsectors]), | |
62 | fSlow(0) | |
a6c02c85 | 63 | { |
64 | //Constructor. | |
65 | InitMerger(nsubsectors); | |
a6c02c85 | 66 | Is2Global(kFALSE); |
67 | fSlow = kFALSE; | |
68 | SetParameter(); | |
2a083ac4 | 69 | } |
70 | ||
0128a907 | 71 | AliHLTTPCTrackMerger::~AliHLTTPCTrackMerger() |
72 | { | |
a6c02c85 | 73 | //Destructor |
0128a907 | 74 | if (fRowMin) delete[] fRowMin; |
75 | if (fRowMax) delete[] fRowMax; | |
a6c02c85 | 76 | } |
77 | ||
78 | void AliHLTTPCTrackMerger::SetRows(Int_t *row){ | |
79 | //Set the indeces of the first and last | |
80 | //TPC padrows | |
81 | // | |
82 | for(Int_t i=0;i<fNSubSector;i++){ | |
83 | fRowMin[i]=*(row+(2*i)); | |
84 | fRowMax[i]=*(row+(2*i+1)); | |
85 | } | |
86 | } | |
87 | ||
88 | void AliHLTTPCTrackMerger::InitSector(Int_t slice,Int_t subsector){ | |
89 | // | |
90 | // Select Sector and subsector. The following FillTracks call will | |
91 | // fill this subsector | |
92 | // | |
93 | fSlice = slice; | |
94 | fSubSector = subsector; | |
95 | fCurrentTracks = fSubSector; | |
96 | } | |
97 | ||
98 | void AliHLTTPCTrackMerger::SlowMerge(AliHLTTPCTrackArray *mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout,Double_t xval){ | |
99 | // | |
100 | // Slow merging of two AliHLTTPCTrackArrays | |
101 | // at reference plane x=xval | |
102 | // | |
103 | void *ntuple=GetNtuple(); | |
104 | const Int_t kNOut=tracksout->GetNTracks(); | |
105 | const Int_t kNIn =tracksin->GetNTracks(); | |
106 | const Int_t kNMerged =mergedtrack->GetNTracks(); | |
107 | AliHLTTPCTrack *tracks[2]; | |
108 | Bool_t merge = kTRUE; | |
109 | while(merge){ | |
110 | Int_t inmin=-1,outmin=-1; | |
111 | Double_t min=10; | |
112 | for(Int_t out=0;out<kNOut;out++){ | |
113 | AliHLTTPCTrack *outertrack=tracksout->GetCheckedTrack(out); | |
114 | if(!outertrack) continue; | |
115 | for(Int_t in=0;in<kNIn;in++){ | |
116 | AliHLTTPCTrack *innertrack=tracksin->GetCheckedTrack(in); | |
117 | if(!innertrack) continue; | |
118 | Double_t diff = TrackDiff(innertrack,outertrack); | |
119 | if(diff>=0&&diff<min){ | |
120 | min=diff; | |
121 | inmin=in; | |
122 | outmin=out; | |
123 | } | |
124 | } | |
125 | } | |
126 | if(inmin>=0&&outmin>=0){ | |
127 | AliHLTTPCTrack *outertrack=tracksout->GetTrack(outmin); | |
128 | AliHLTTPCTrack *innertrack=tracksin->GetTrack(inmin); | |
129 | tracks[0]=innertrack; | |
130 | tracks[1]=outertrack; | |
131 | SortTracks(tracks,2); | |
132 | MultiMerge(mergedtrack,tracks,2); | |
133 | outertrack->CalculatePoint(xval); | |
134 | innertrack->CalculatePoint(xval); | |
135 | PrintDiff(innertrack,outertrack); | |
136 | //FillNtuple(ntuple,innertrack,outertrack); | |
137 | tracksout->Remove(outmin); | |
138 | tracksin->Remove(inmin); | |
139 | // tracksout->Compress(); | |
140 | // tracksin->Compress(); | |
141 | } | |
142 | else merge = kFALSE; | |
143 | } | |
144 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::SlowMerge","Result") | |
145 | <<AliHLTTPCLog::kDec<<"Merged Tracks: " | |
146 | <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG; | |
1c9853d3 | 147 | const int namelen=256; |
148 | char name[namelen] = "ntuple_t.root"; | |
a6c02c85 | 149 | for(Int_t i=0;i<4;i++) |
150 | if(tracksin==GetInTracks(i)) | |
1c9853d3 | 151 | snprintf(name,namelen,"ntuple_t_%d.root",i); |
a6c02c85 | 152 | WriteNtuple(name,ntuple); |
153 | } | |
154 | ||
155 | void AliHLTTPCTrackMerger::SlowMerge(){ | |
156 | fSlow = kTRUE; | |
157 | Merge(); | |
158 | } | |
159 | ||
160 | void AliHLTTPCTrackMerger::InterMerge(){ | |
161 | // | |
162 | // Merging of the tracks | |
163 | // between readout patches | |
164 | // | |
165 | for(Int_t patch=0;patch< GetNIn();patch++){ | |
166 | AliHLTTPCTrackArray * tracks = GetInTracks(patch); | |
167 | Double_t xval = AliHLTTPCTransform::Row2X((fRowMax[patch]+fRowMin[patch])/2); | |
168 | Int_t nrow= fRowMax[patch]-fRowMin[patch]+1; | |
169 | const Int_t kNIn =tracks->GetNTracks(); | |
170 | AliHLTTPCTrack *tr[2]; | |
171 | for(Int_t in=0;in<kNIn;in++){ | |
172 | AliHLTTPCTrack *t = tracks->GetCheckedTrack(in); | |
173 | if(t){ | |
174 | t->CalculateHelix(); | |
175 | t->CalculatePoint(xval); | |
176 | } | |
177 | } | |
178 | for(Int_t out=0;out<kNIn;out++){ | |
179 | AliHLTTPCTrack *outertrack=tracks->GetCheckedTrack(out); | |
180 | if(!outertrack) continue; | |
181 | for(Int_t in=0;in<kNIn;in++){ | |
182 | if(in==out) continue; | |
183 | AliHLTTPCTrack *innertrack=tracks->GetCheckedTrack(in); | |
184 | if(!innertrack) continue; | |
185 | if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue; | |
186 | ||
187 | if(IsTrack(innertrack,outertrack)){ | |
188 | tr[0]=innertrack; | |
189 | tr[1]=outertrack; | |
190 | SortTracks(tr,2); | |
191 | if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){ | |
192 | MultiMerge(tracks,tr,2); | |
193 | tracks->Remove(out); | |
194 | tracks->Remove(in); | |
195 | break; | |
196 | } | |
197 | } | |
198 | } | |
199 | } | |
200 | Int_t nmerged = tracks->GetNTracks()-kNIn; | |
201 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::InterMerge","Result") | |
202 | <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG; | |
203 | } | |
204 | } | |
205 | ||
206 | void AliHLTTPCTrackMerger::Merge(){ | |
207 | //Loop over tracks and pass them to the track merger. | |
208 | Double_t edge0 = AliHLTTPCTransform::Pi()/18; | |
209 | Double_t edge1 = AliHLTTPCTransform::TwoPi() - edge0; | |
210 | AliHLTTPCTrackArray *ttt = GetOutTracks(); | |
211 | if(fNSubSector==1) { | |
212 | GetOutTracks()->AddTracks(GetInTracks(0)); | |
213 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result") | |
214 | <<AliHLTTPCLog::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent() | |
215 | <<ENDLOG; | |
216 | return; | |
217 | } | |
218 | Int_t subsec = fNSubSector -2; | |
219 | for(Int_t i=subsec;i>=0;i--){ | |
220 | AliHLTTPCTrackArray *tout = GetOutTracks(); | |
221 | if(i==subsec) tout = GetInTracks(subsec+1); | |
222 | AliHLTTPCTrackArray *tin = GetInTracks(i); | |
223 | Double_t xval = AliHLTTPCTransform::Row2X(fRowMax[i]); | |
224 | Double_t xmax = AliHLTTPCTransform::Row2X(fRowMax[i+1]); | |
225 | Double_t ymax = xval*tan(edge0); | |
226 | for(Int_t out=0;out<tout->GetNTracks();out++){ | |
227 | AliHLTTPCTrack *outtrack=tout->GetCheckedTrack(out); | |
228 | if(!outtrack) continue; | |
229 | outtrack->CalculateHelix(); | |
230 | outtrack->CalculatePoint(xval); | |
231 | if(outtrack->IsPoint()&&fabs(outtrack->GetPointY())>ymax){ | |
232 | if(outtrack->GetNHits()<10) | |
233 | tout->Remove(out); | |
234 | } | |
235 | } | |
236 | // tout->Compress(); | |
237 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
238 | AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetTrack(in); | |
239 | intrack->CalculateHelix(); | |
240 | intrack->CalculatePoint(xval); | |
241 | } | |
242 | tin->QSort(); | |
243 | tout->QSort(); | |
244 | ||
245 | if(fSlow) SlowMerge(ttt,tin,tout,xval); | |
246 | else Merge(ttt,tin,tout); | |
247 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
248 | AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in); | |
249 | if(!intrack) continue; | |
250 | if(intrack->CalculateEdgePoint(edge0)){ | |
251 | if(intrack->GetPointX()<xmax ){ | |
252 | AddTrack(ttt,intrack); | |
253 | tin->Remove(in); | |
254 | } | |
255 | } | |
256 | else if(intrack->CalculateEdgePoint(edge1)){ | |
257 | if(intrack->GetPointX()<xmax ){ | |
258 | AddTrack(ttt,intrack); | |
259 | tin->Remove(in); | |
260 | } | |
261 | } | |
262 | } | |
263 | /* | |
264 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
265 | AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in); | |
266 | if(!intrack) continue; | |
267 | if(intrack->GetNHits()<10) continue; | |
268 | AddTrack(ttt,intrack); | |
269 | tin->Remove(in); | |
270 | } | |
271 | */ | |
272 | } // end subsector loop | |
273 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result") | |
274 | <<AliHLTTPCLog::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent() | |
275 | <<ENDLOG; | |
276 | } | |
277 | ||
278 | Int_t AliHLTTPCTrackMerger::Merge(AliHLTTPCTrackArray* mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout){ | |
279 | //Loop over tracks and pass them to the track merger. | |
280 | AliHLTTPCTrack *tracks[2]; | |
281 | ||
282 | const Int_t kNOut=tracksout->GetNTracks(); | |
283 | const Int_t kNIn =tracksin->GetNTracks(); | |
284 | const Int_t kNMerged =mergedtrack->GetNTracks(); | |
285 | ||
286 | Bool_t *ismatchedin = new Bool_t[kNIn]; | |
287 | for(Int_t in =0;in<kNIn;in++) | |
288 | ismatchedin[in]=kFALSE; | |
289 | Bool_t *ismatchedout = new Bool_t[kNOut]; | |
290 | for(Int_t out =0;out<kNOut;out++) | |
291 | ismatchedout[out] = kFALSE; | |
292 | for(Int_t out =0;out<kNOut;out++){ | |
293 | AliHLTTPCTrack *outertrack=(AliHLTTPCTrack*)tracksout->GetCheckedTrack(out); | |
294 | if(!outertrack) continue; | |
295 | for(Int_t in =0;in<kNIn;in++){ | |
296 | if(ismatchedin[in]) continue; | |
297 | AliHLTTPCTrack *innertrack=(AliHLTTPCTrack*)tracksin->GetCheckedTrack(in); | |
298 | if(!innertrack) continue; | |
299 | if(outertrack==innertrack) continue; | |
300 | if(outertrack->GetCharge()!=innertrack->GetCharge()) continue; | |
301 | if(IsTrack(innertrack,outertrack)){ | |
302 | tracks[0]=innertrack; tracks[1]=outertrack; | |
303 | SortTracks(tracks,2); | |
304 | if(tracks[0]->GetLastPointX()<tracks[1]->GetFirstPointX()){ | |
305 | MultiMerge(mergedtrack,tracks,2); | |
306 | tracksout->Remove(out); | |
307 | tracksin->Remove(in); | |
308 | ismatchedin[in]=kTRUE; | |
309 | ismatchedout[out]=kTRUE; | |
310 | break; | |
311 | } | |
312 | } | |
313 | } | |
314 | } | |
315 | ||
316 | Int_t nmerged = mergedtrack->GetNTracks()-kNMerged; | |
317 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result") | |
318 | <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG; | |
319 | delete[] ismatchedin; | |
320 | delete[] ismatchedout; | |
321 | return nmerged; | |
322 | } | |
323 | ||
324 |