]>
Commit | Line | Data |
---|---|---|
a6c02c85 | 1 | // @(#) $Id$ |
4aa41877 | 2 | // Original: AliHLTTrackMerger.cxx,v 1.12 2005/06/14 10:55:21 cvetan |
a6c02c85 | 3 | |
2a083ac4 | 4 | /************************************************************************** |
5 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
6 | * * | |
7 | * Authors: Uli Frankenfeld * | |
8 | * Matthias Richter <Matthias.Richter@ift.uib.no> * | |
9 | * for The ALICE Off-line Project. * | |
10 | * * | |
11 | * Permission to use, copy, modify and distribute this software and its * | |
12 | * documentation strictly for non-commercial purposes is hereby granted * | |
13 | * without fee, provided that the above copyright notice appears in all * | |
14 | * copies and that both the copyright notice and this permission notice * | |
15 | * appear in the supporting documentation. The authors make no claims * | |
16 | * about the suitability of this software for any purpose. It is * | |
17 | * provided "as is" without express or implied warranty. * | |
18 | **************************************************************************/ | |
19 | ||
20 | /** @file AliHLTTPCTrackMerger.cxx | |
21 | @author Uli Frankenfeld, maintained by Matthias Richter | |
22 | @date | |
23 | @brief The HLT TPC track segment merger | |
a6c02c85 | 24 | */ |
25 | ||
a6c02c85 | 26 | #include "AliHLTTPCLogging.h" |
27 | #include "AliHLTTPCTrackMerger.h" | |
28 | #include "AliHLTTPCTrack.h" | |
29 | #include "AliHLTTPCTrackSegmentData.h" | |
30 | #include "AliHLTTPCTransform.h" | |
31 | #include "AliHLTTPCTrackArray.h" | |
32 | ||
33 | #if __GNUC__ >= 3 | |
34 | using namespace std; | |
35 | #endif | |
36 | ||
37 | ClassImp(AliHLTTPCTrackMerger) | |
38 | ||
39 | AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(){ | |
40 | //Default constructor | |
41 | Is2Global(kFALSE); | |
42 | fSlow = kFALSE; | |
43 | SetParameter(); | |
44 | fRowMin = 0; | |
45 | fRowMax = 0; | |
46 | } | |
47 | ||
48 | ||
49 | AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(Int_t nsubsectors) : AliHLTTPCMerger() | |
50 | { | |
51 | //Constructor. | |
52 | InitMerger(nsubsectors); | |
53 | fNSubSector = nsubsectors; | |
54 | Is2Global(kFALSE); | |
55 | fSlow = kFALSE; | |
56 | SetParameter(); | |
57 | fRowMin = new Int_t[nsubsectors]; | |
58 | fRowMax = new Int_t[nsubsectors]; | |
59 | ||
60 | } | |
61 | ||
2a083ac4 | 62 | AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(const AliHLTTPCTrackMerger&) |
63 | { | |
64 | // dummy copy constructor | |
65 | //HLTFatal("copy constructor untested"); | |
66 | } | |
67 | ||
68 | AliHLTTPCTrackMerger& AliHLTTPCTrackMerger::operator=(const AliHLTTPCTrackMerger&) | |
69 | { | |
70 | // dummy assignment operator | |
71 | //HLTFatal("assignment operator untested"); | |
72 | return *this; | |
73 | } | |
74 | ||
a6c02c85 | 75 | AliHLTTPCTrackMerger::~AliHLTTPCTrackMerger(){ |
76 | //Destructor | |
77 | } | |
78 | ||
79 | void AliHLTTPCTrackMerger::SetRows(Int_t *row){ | |
80 | //Set the indeces of the first and last | |
81 | //TPC padrows | |
82 | // | |
83 | for(Int_t i=0;i<fNSubSector;i++){ | |
84 | fRowMin[i]=*(row+(2*i)); | |
85 | fRowMax[i]=*(row+(2*i+1)); | |
86 | } | |
87 | } | |
88 | ||
89 | void AliHLTTPCTrackMerger::InitSector(Int_t slice,Int_t subsector){ | |
90 | // | |
91 | // Select Sector and subsector. The following FillTracks call will | |
92 | // fill this subsector | |
93 | // | |
94 | fSlice = slice; | |
95 | fSubSector = subsector; | |
96 | fCurrentTracks = fSubSector; | |
97 | } | |
98 | ||
99 | void AliHLTTPCTrackMerger::SlowMerge(AliHLTTPCTrackArray *mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout,Double_t xval){ | |
100 | // | |
101 | // Slow merging of two AliHLTTPCTrackArrays | |
102 | // at reference plane x=xval | |
103 | // | |
104 | void *ntuple=GetNtuple(); | |
105 | const Int_t kNOut=tracksout->GetNTracks(); | |
106 | const Int_t kNIn =tracksin->GetNTracks(); | |
107 | const Int_t kNMerged =mergedtrack->GetNTracks(); | |
108 | AliHLTTPCTrack *tracks[2]; | |
109 | Bool_t merge = kTRUE; | |
110 | while(merge){ | |
111 | Int_t inmin=-1,outmin=-1; | |
112 | Double_t min=10; | |
113 | for(Int_t out=0;out<kNOut;out++){ | |
114 | AliHLTTPCTrack *outertrack=tracksout->GetCheckedTrack(out); | |
115 | if(!outertrack) continue; | |
116 | for(Int_t in=0;in<kNIn;in++){ | |
117 | AliHLTTPCTrack *innertrack=tracksin->GetCheckedTrack(in); | |
118 | if(!innertrack) continue; | |
119 | Double_t diff = TrackDiff(innertrack,outertrack); | |
120 | if(diff>=0&&diff<min){ | |
121 | min=diff; | |
122 | inmin=in; | |
123 | outmin=out; | |
124 | } | |
125 | } | |
126 | } | |
127 | if(inmin>=0&&outmin>=0){ | |
128 | AliHLTTPCTrack *outertrack=tracksout->GetTrack(outmin); | |
129 | AliHLTTPCTrack *innertrack=tracksin->GetTrack(inmin); | |
130 | tracks[0]=innertrack; | |
131 | tracks[1]=outertrack; | |
132 | SortTracks(tracks,2); | |
133 | MultiMerge(mergedtrack,tracks,2); | |
134 | outertrack->CalculatePoint(xval); | |
135 | innertrack->CalculatePoint(xval); | |
136 | PrintDiff(innertrack,outertrack); | |
137 | //FillNtuple(ntuple,innertrack,outertrack); | |
138 | tracksout->Remove(outmin); | |
139 | tracksin->Remove(inmin); | |
140 | // tracksout->Compress(); | |
141 | // tracksin->Compress(); | |
142 | } | |
143 | else merge = kFALSE; | |
144 | } | |
145 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::SlowMerge","Result") | |
146 | <<AliHLTTPCLog::kDec<<"Merged Tracks: " | |
147 | <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG; | |
148 | char name[256] = "ntuple_t.root"; | |
149 | for(Int_t i=0;i<4;i++) | |
150 | if(tracksin==GetInTracks(i)) | |
151 | sprintf(name,"ntuple_t_%d.root",i); | |
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 |