]>
Commit | Line | Data |
---|---|---|
78001a73 | 1 | // @(#) $Id$ |
2 | ||
3 | // Author: Uli Frankenfeld <mailto:franken@fi.uib.no> | |
4 | //*-- Copyright © ALICE HLT Group | |
5 | ||
6 | #include "AliHLTTPCStandardIncludes.h" | |
7 | ||
8 | #include "AliHLTTPCLogging.h" | |
9 | #include "AliHLTTPCTrackMerger.h" | |
10 | #include "AliHLTTPCTrack.h" | |
11 | #include "AliHLTTPCTrackSegmentData.h" | |
12 | #include "AliHLTTPCTransform.h" | |
13 | #include "AliHLTTPCTrackArray.h" | |
14 | ||
15 | /** \class AliHLTTPCTrackMerger | |
16 | <pre> | |
17 | //_____________________________________________________________ | |
18 | // AliHLTTPCTrackMerger | |
19 | // | |
20 | // The L3 track segment merger | |
21 | // | |
22 | </pre | |
23 | */ | |
24 | ||
25 | ClassImp(AliHLTTPCTrackMerger) | |
26 | ||
27 | AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(){ | |
28 | //Default constructor | |
29 | Is2Global(kFALSE); | |
30 | fSlow = kFALSE; | |
31 | SetParameter(); | |
32 | fRowMin = 0; | |
33 | fRowMax = 0; | |
34 | } | |
35 | ||
36 | ||
37 | AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(Int_t nsubsectors) : AliHLTTPCMerger() | |
38 | { | |
39 | //Constructor. | |
40 | InitMerger(nsubsectors); | |
41 | fNSubSector = nsubsectors; | |
42 | Is2Global(kFALSE); | |
43 | fSlow = kFALSE; | |
44 | SetParameter(); | |
45 | fRowMin = new Int_t[nsubsectors]; | |
46 | fRowMax = new Int_t[nsubsectors]; | |
47 | ||
48 | } | |
49 | ||
50 | AliHLTTPCTrackMerger::~AliHLTTPCTrackMerger(){ | |
51 | //Destructor | |
52 | } | |
53 | ||
54 | void AliHLTTPCTrackMerger::SetRows(Int_t *row){ | |
55 | for(Int_t i=0;i<fNSubSector;i++){ | |
56 | fRowMin[i]=*(row+(2*i)); | |
57 | fRowMax[i]=*(row+(2*i+1)); | |
58 | } | |
59 | } | |
60 | ||
61 | void AliHLTTPCTrackMerger::InitSector(Int_t slice,Int_t subsector){ | |
62 | // | |
63 | // Select Sector and subsector. The following FillTracks call will | |
64 | // fill this subsector | |
65 | // | |
66 | fSlice = slice; | |
67 | fSubSector = subsector; | |
68 | fCurrentTracks = fSubSector; | |
69 | } | |
70 | ||
71 | void AliHLTTPCTrackMerger::SlowMerge(AliHLTTPCTrackArray *mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout,Double_t xval){ | |
72 | void *ntuple=GetNtuple(); | |
73 | const Int_t kNOut=tracksout->GetNTracks(); | |
74 | const Int_t kNIn =tracksin->GetNTracks(); | |
75 | const Int_t kNMerged =mergedtrack->GetNTracks(); | |
76 | AliHLTTPCTrack *tracks[2]; | |
77 | Bool_t merge = kTRUE; | |
78 | while(merge){ | |
79 | Int_t inmin=-1,outmin=-1; | |
80 | Double_t min=10; | |
81 | for(Int_t out=0;out<kNOut;out++){ | |
82 | AliHLTTPCTrack *outertrack=tracksout->GetCheckedTrack(out); | |
83 | if(!outertrack) continue; | |
84 | for(Int_t in=0;in<kNIn;in++){ | |
85 | AliHLTTPCTrack *innertrack=tracksin->GetCheckedTrack(in); | |
86 | if(!innertrack) continue; | |
87 | Double_t diff = TrackDiff(innertrack,outertrack); | |
88 | if(diff>=0&&diff<min){ | |
89 | min=diff; | |
90 | inmin=in; | |
91 | outmin=out; | |
92 | } | |
93 | } | |
94 | } | |
95 | if(inmin>=0&&outmin>=0){ | |
96 | AliHLTTPCTrack *outertrack=tracksout->GetTrack(outmin); | |
97 | AliHLTTPCTrack *innertrack=tracksin->GetTrack(inmin); | |
98 | tracks[0]=innertrack; | |
99 | tracks[1]=outertrack; | |
100 | SortTracks(tracks,2); | |
101 | MultiMerge(mergedtrack,tracks,2); | |
102 | outertrack->CalculatePoint(xval); | |
103 | innertrack->CalculatePoint(xval); | |
104 | PrintDiff(innertrack,outertrack); | |
105 | //FillNtuple(ntuple,innertrack,outertrack); | |
106 | tracksout->Remove(outmin); | |
107 | tracksin->Remove(inmin); | |
108 | // tracksout->Compress(); | |
109 | // tracksin->Compress(); | |
110 | } | |
111 | else merge = kFALSE; | |
112 | } | |
113 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::SlowMerge","Result") | |
114 | <<AliHLTTPCLog::kDec<<"Merged Tracks: " | |
115 | <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG; | |
116 | char name[256] = "ntuple_t.root"; | |
117 | for(Int_t i=0;i<4;i++) | |
118 | if(tracksin==GetInTracks(i)) | |
119 | sprintf(name,"ntuple_t_%d.root",i); | |
120 | WriteNtuple(name,ntuple); | |
121 | } | |
122 | ||
123 | void AliHLTTPCTrackMerger::SlowMerge(){ | |
124 | fSlow = kTRUE; | |
125 | Merge(); | |
126 | } | |
127 | ||
128 | void AliHLTTPCTrackMerger::InterMerge(){ | |
129 | ||
130 | for(Int_t patch=0;patch< GetNIn();patch++){ | |
131 | AliHLTTPCTrackArray * tracks = GetInTracks(patch); | |
132 | Double_t xval = AliHLTTPCTransform::Row2X((fRowMax[patch]+fRowMin[patch])/2); | |
133 | Int_t nrow= fRowMax[patch]-fRowMin[patch]+1; | |
134 | const Int_t kNIn =tracks->GetNTracks(); | |
135 | AliHLTTPCTrack *tr[2]; | |
136 | for(Int_t in=0;in<kNIn;in++){ | |
137 | AliHLTTPCTrack *t = tracks->GetCheckedTrack(in); | |
138 | if(t){ | |
139 | t->CalculateHelix(); | |
140 | t->CalculatePoint(xval); | |
141 | } | |
142 | } | |
143 | for(Int_t out=0;out<kNIn;out++){ | |
144 | AliHLTTPCTrack *outertrack=tracks->GetCheckedTrack(out); | |
145 | if(!outertrack) continue; | |
146 | for(Int_t in=0;in<kNIn;in++){ | |
147 | if(in==out) continue; | |
148 | AliHLTTPCTrack *innertrack=tracks->GetCheckedTrack(in); | |
149 | if(!innertrack) continue; | |
150 | if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue; | |
151 | ||
152 | if(IsTrack(innertrack,outertrack)){ | |
153 | tr[0]=innertrack; | |
154 | tr[1]=outertrack; | |
155 | SortTracks(tr,2); | |
156 | if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){ | |
157 | MultiMerge(tracks,tr,2); | |
158 | tracks->Remove(out); | |
159 | tracks->Remove(in); | |
160 | break; | |
161 | } | |
162 | } | |
163 | } | |
164 | } | |
165 | Int_t nmerged = tracks->GetNTracks()-kNIn; | |
166 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::InterMerge","Result") | |
167 | <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG; | |
168 | } | |
169 | } | |
170 | ||
171 | void AliHLTTPCTrackMerger::Merge(){ | |
172 | //Loop over tracks and pass them to the track merger. | |
173 | Double_t edge0 = PI/18.; | |
174 | Double_t edge1 = 2*PI - edge0; | |
175 | AliHLTTPCTrackArray *ttt = GetOutTracks(); | |
176 | if(fNSubSector==1) { | |
177 | GetOutTracks()->AddTracks(GetInTracks(0)); | |
178 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result") | |
179 | <<AliHLTTPCLog::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent() | |
180 | <<ENDLOG; | |
181 | return; | |
182 | } | |
183 | Int_t subsec = fNSubSector -2; | |
184 | for(Int_t i=subsec;i>=0;i--){ | |
185 | AliHLTTPCTrackArray *tout = GetOutTracks(); | |
186 | if(i==subsec) tout = GetInTracks(subsec+1); | |
187 | AliHLTTPCTrackArray *tin = GetInTracks(i); | |
188 | Double_t xval = AliHLTTPCTransform::Row2X(fRowMax[i]); | |
189 | Double_t xmax = AliHLTTPCTransform::Row2X(fRowMax[i+1]); | |
190 | Double_t ymax = xval*tan(edge0); | |
191 | for(Int_t out=0;out<tout->GetNTracks();out++){ | |
192 | AliHLTTPCTrack *outtrack=tout->GetCheckedTrack(out); | |
193 | if(!outtrack) continue; | |
194 | outtrack->CalculateHelix(); | |
195 | outtrack->CalculatePoint(xval); | |
196 | if(outtrack->IsPoint()&&fabs(outtrack->GetPointY())>ymax){ | |
197 | if(outtrack->GetNHits()<10) | |
198 | tout->Remove(out); | |
199 | } | |
200 | } | |
201 | // tout->Compress(); | |
202 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
203 | AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetTrack(in); | |
204 | intrack->CalculateHelix(); | |
205 | intrack->CalculatePoint(xval); | |
206 | } | |
207 | tin->QSort(); | |
208 | tout->QSort(); | |
209 | ||
210 | if(fSlow) SlowMerge(ttt,tin,tout,xval); | |
211 | else Merge(ttt,tin,tout); | |
212 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
213 | AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in); | |
214 | if(!intrack) continue; | |
215 | if(intrack->CalculateEdgePoint(edge0)){ | |
216 | if(intrack->GetPointX()<xmax ){ | |
217 | AddTrack(ttt,intrack); | |
218 | tin->Remove(in); | |
219 | } | |
220 | } | |
221 | else if(intrack->CalculateEdgePoint(edge1)){ | |
222 | if(intrack->GetPointX()<xmax ){ | |
223 | AddTrack(ttt,intrack); | |
224 | tin->Remove(in); | |
225 | } | |
226 | } | |
227 | } | |
228 | /* | |
229 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
230 | AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in); | |
231 | if(!intrack) continue; | |
232 | if(intrack->GetNHits()<10) continue; | |
233 | AddTrack(ttt,intrack); | |
234 | tin->Remove(in); | |
235 | } | |
236 | */ | |
237 | } // end subsector loop | |
238 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result") | |
239 | <<AliHLTTPCLog::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent() | |
240 | <<ENDLOG; | |
241 | } | |
242 | ||
243 | Int_t AliHLTTPCTrackMerger::Merge(AliHLTTPCTrackArray* mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout){ | |
244 | //Loop over tracks and pass them to the track merger. | |
245 | AliHLTTPCTrack *tracks[2]; | |
246 | ||
247 | const Int_t kNOut=tracksout->GetNTracks(); | |
248 | const Int_t kNIn =tracksin->GetNTracks(); | |
249 | const Int_t kNMerged =mergedtrack->GetNTracks(); | |
250 | ||
251 | Bool_t *ismatchedin = new Bool_t[kNIn]; | |
252 | for(Int_t in =0;in<kNIn;in++) | |
253 | ismatchedin[in]=kFALSE; | |
254 | Bool_t *ismatchedout = new Bool_t[kNOut]; | |
255 | for(Int_t out =0;out<kNOut;out++) | |
256 | ismatchedout[out] = kFALSE; | |
257 | for(Int_t out =0;out<kNOut;out++){ | |
258 | AliHLTTPCTrack *outertrack=(AliHLTTPCTrack*)tracksout->GetCheckedTrack(out); | |
259 | if(!outertrack) continue; | |
260 | for(Int_t in =0;in<kNIn;in++){ | |
261 | if(ismatchedin[in]) continue; | |
262 | AliHLTTPCTrack *innertrack=(AliHLTTPCTrack*)tracksin->GetCheckedTrack(in); | |
263 | if(!innertrack) continue; | |
264 | if(outertrack==innertrack) continue; | |
265 | if(outertrack->GetCharge()!=innertrack->GetCharge()) continue; | |
266 | if(IsTrack(innertrack,outertrack)){ | |
267 | tracks[0]=innertrack; tracks[1]=outertrack; | |
268 | SortTracks(tracks,2); | |
269 | if(tracks[0]->GetLastPointX()<tracks[1]->GetFirstPointX()){ | |
270 | MultiMerge(mergedtrack,tracks,2); | |
271 | tracksout->Remove(out); | |
272 | tracksin->Remove(in); | |
273 | ismatchedin[in]=kTRUE; | |
274 | ismatchedout[out]=kTRUE; | |
275 | break; | |
276 | } | |
277 | } | |
278 | } | |
279 | } | |
280 | ||
281 | Int_t nmerged = mergedtrack->GetNTracks()-kNMerged; | |
282 | LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result") | |
283 | <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG; | |
284 | delete[] ismatchedin; | |
285 | delete[] ismatchedout; | |
286 | return nmerged; | |
287 | } | |
288 | ||
289 |