]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
2 | ||
b1886074 | 3 | // Author: Anders Vestbo <mailto:vestbo@fi.uib.no> |
3e87ef69 | 4 | //*-- Copyright © ALICE HLT Group |
a1855560 | 5 | |
e06900d5 | 6 | #include "AliL3StandardIncludes.h" |
7 | ||
a1855560 | 8 | #include "AliL3Logging.h" |
b1886074 | 9 | #include "AliL3Transform.h" |
a1855560 | 10 | #include "AliL3TrackArray.h" |
11 | #include "AliL3HoughTrack.h" | |
12 | #include "AliL3HoughMerger.h" | |
13 | #include "AliL3HoughTransformer.h" | |
14 | ||
e06900d5 | 15 | #if GCCVERSION == 3 |
16 | using namespace std; | |
17 | #endif | |
18 | ||
b1886074 | 19 | //_____________________________________________________________ |
20 | // AliL3HoughMerger | |
21 | // | |
22 | // Patch merging class for Hough tracklets | |
23 | ||
a1855560 | 24 | ClassImp(AliL3HoughMerger) |
25 | ||
26 | ||
27 | AliL3HoughMerger::AliL3HoughMerger() | |
28 | { | |
29 | //Default constructor | |
a1855560 | 30 | } |
31 | ||
32 | ||
b1886074 | 33 | AliL3HoughMerger::AliL3HoughMerger(Int_t nsubsectors) : AliL3Merger(nsubsectors,"AliL3HoughTrack") |
a1855560 | 34 | { |
35 | //Constructor | |
b1886074 | 36 | Is2Global(kFALSE); |
37 | SetParameters(0.001,0.1,0.05); | |
a1855560 | 38 | } |
39 | ||
40 | ||
41 | AliL3HoughMerger::~AliL3HoughMerger() | |
42 | { | |
b1886074 | 43 | |
a1855560 | 44 | } |
45 | ||
b1886074 | 46 | void AliL3HoughMerger::FillTracks(AliL3TrackArray *tracks,Int_t patch) |
a1855560 | 47 | { |
b1886074 | 48 | if(tracks->GetNTracks()==0) |
49 | LOG(AliL3Log::kWarning,"AliL3HoughMerger::FillTracks","Track Array") | |
50 | <<"Adding empty track array"<<ENDLOG; | |
51 | ||
52 | GetInTracks(patch)->AddTracks(tracks,kFALSE);//Copy tracks | |
53 | printf("Filling %d tracks to merger\n",tracks->GetNTracks()); | |
a1855560 | 54 | } |
55 | ||
b1886074 | 56 | void AliL3HoughMerger::SetParameters(Double_t maxkappa,Double_t maxpsi,Double_t maxphi0) |
a1855560 | 57 | { |
b1886074 | 58 | fMaxKappa = maxkappa; |
59 | fMaxPsi = maxpsi; | |
60 | fMaxPhi0 = maxphi0; | |
a1855560 | 61 | } |
62 | ||
b1886074 | 63 | Bool_t AliL3HoughMerger::IsTrack(AliL3Track *innertrack,AliL3Track *outertrack) |
a1855560 | 64 | { |
b1886074 | 65 | //Check if the tracks can be merged, called by the track merger |
66 | ||
67 | AliL3HoughTrack *tr1 = (AliL3HoughTrack*)innertrack; | |
68 | AliL3HoughTrack *tr2 = (AliL3HoughTrack*)outertrack; | |
69 | ||
70 | if( (!tr1->IsPoint()) || (!tr2->IsPoint()) ) return kFALSE; | |
71 | if(abs(tr1->GetEtaIndex() - tr2->GetEtaIndex()) > 1) return kFALSE; | |
72 | if(tr1->GetCharge() != tr2->GetCharge()) return kFALSE; | |
73 | if(fabs(tr1->GetPhi0() - tr2->GetPhi0()) > fMaxPhi0) return kFALSE; | |
74 | if(fabs(tr1->GetKappa() - tr2->GetKappa()) > fMaxKappa) return kFALSE; | |
75 | ||
76 | /* | |
77 | if( (!tr1->IsPoint()) || (!tr2->IsPoint()) ) return kFALSE; | |
78 | if(fabs(innertrack->GetPointY()-outertrack->GetPointY()) >fMaxY) return kFALSE; | |
79 | if(fabs(innertrack->GetPointZ()-outertrack->GetPointZ()) >fMaxZ) return kFALSE; | |
80 | if(fabs(innertrack->GetKappa()-outertrack->GetKappa()) >fMaxKappa) return kFALSE; | |
81 | if(GetAngle(innertrack->GetPointPsi(),outertrack->GetPointPsi()) >fMaxPsi) return kFALSE; | |
82 | if(fabs(innertrack->GetTgl()-outertrack->GetTgl()) >fMaxTgl) return kFALSE; | |
83 | */ | |
84 | ||
85 | return kTRUE;//Tracks could be merged | |
a1855560 | 86 | } |
87 | ||
b1886074 | 88 | void AliL3HoughMerger::AddTrack(AliL3TrackArray *mergedtrack,AliL3Track *track) |
a1855560 | 89 | { |
b1886074 | 90 | AliL3Track *t[1]; |
91 | t[0] = track; | |
92 | MultiMerge(mergedtrack,t,1); | |
93 | } | |
94 | ||
95 | AliL3Track *AliL3HoughMerger::MultiMerge(AliL3TrackArray *mergedtrack,AliL3Track **tracks, Int_t ntrack) | |
96 | { | |
97 | //Called by the track merger | |
98 | ||
99 | AliL3HoughTrack *newtrack = (AliL3HoughTrack*)mergedtrack->NextTrack(); | |
100 | AliL3HoughTrack **trs = (AliL3HoughTrack**)tracks; | |
101 | Int_t weight=0; | |
102 | ||
103 | //Sum up the total weight: | |
104 | for(Int_t i=ntrack-1; i>=0; i--) | |
105 | weight += trs[i]->GetWeight(); | |
a1855560 | 106 | |
b1886074 | 107 | AliL3HoughTrack *tpt=trs[0];//This is the innermost track |
108 | AliL3HoughTrack *tpl=trs[ntrack-1]; | |
109 | newtrack->SetTrackParameters(tpt->GetKappa(),tpt->GetPhi0(),weight); | |
110 | newtrack->SetEtaIndex(tpt->GetEtaIndex()); | |
111 | newtrack->SetEta(tpt->GetEta()); | |
112 | newtrack->SetPsi(tpt->GetPsi()); | |
113 | newtrack->SetCenterX(tpt->GetCenterX()); | |
114 | newtrack->SetCenterY(tpt->GetCenterY()); | |
115 | newtrack->SetFirstPoint(tpt->GetFirstPointX(),tpt->GetFirstPointY(),tpt->GetFirstPointZ()); | |
116 | newtrack->SetLastPoint(tpl->GetLastPointX(),tpl->GetLastPointY(),tpl->GetLastPointZ()); | |
117 | newtrack->SetCharge(tpt->GetCharge()); | |
118 | newtrack->SetRowRange(tpt->GetFirstRow(),tpl->GetLastRow()); | |
a1855560 | 119 | |
b1886074 | 120 | return (AliL3Track*)newtrack; |
121 | ||
a1855560 | 122 | } |
123 | ||
b1886074 | 124 | void AliL3HoughMerger::MergePatches(Bool_t slow) |
a1855560 | 125 | { |
b1886074 | 126 | //Merge tracks from across the patches. |
127 | ||
128 | fSlow = slow; | |
129 | AliL3TrackArray *tracks; | |
130 | AliL3HoughTrack *track; | |
131 | for(Int_t i=0; i<GetNIn(); i++) | |
a1855560 | 132 | { |
b1886074 | 133 | tracks = GetInTracks(i); |
134 | for(Int_t j=0; j<tracks->GetNTracks(); j++) | |
a1855560 | 135 | { |
b1886074 | 136 | track = (AliL3HoughTrack*)tracks->GetCheckedTrack(j); |
137 | if(!track) continue; | |
138 | track->UpdateToFirstRow(); | |
a1855560 | 139 | } |
140 | } | |
b1886074 | 141 | Merge(); |
a1855560 | 142 | |
b1886074 | 143 | } |
144 | ||
145 | void AliL3HoughMerger::Merge() | |
146 | { | |
147 | Double_t edge0 = PI/18.; | |
3e87ef69 | 148 | //Double_t edge1 = 2*PI - edge0; |
b1886074 | 149 | AliL3TrackArray *ttt = GetOutTracks(); |
150 | ||
151 | Int_t subsec = GetNIn() - 2; | |
152 | for(Int_t i=subsec;i>=0;i--){ | |
153 | AliL3TrackArray *tout = GetOutTracks(); | |
154 | if(i==subsec) tout = GetInTracks(subsec+1); | |
155 | AliL3TrackArray *tin = GetInTracks(i); | |
26abc209 | 156 | Double_t xval = AliL3Transform::Row2X(AliL3Transform::GetLastRow(i)); |
3e87ef69 | 157 | //Double_t xmax = AliL3Transform::Row2X(AliL3Transform::GetLastRow(i+1)); |
b1886074 | 158 | Double_t ymax = xval*tan(edge0); |
159 | for(Int_t out=0;out<tout->GetNTracks();out++){ | |
160 | AliL3Track *outtrack=tout->GetCheckedTrack(out); | |
161 | if(!outtrack) continue; | |
162 | //outtrack->CalculateHelix(); | |
163 | outtrack->CalculatePoint(xval); | |
164 | if(outtrack->IsPoint()&&fabs(outtrack->GetPointY())>ymax){ | |
165 | tout->Remove(out); | |
166 | } | |
a1855560 | 167 | } |
b1886074 | 168 | // tout->Compress(); |
169 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
170 | AliL3Track *intrack=(AliL3Track*)tin->GetTrack(in); | |
171 | //intrack->CalculateHelix(); | |
172 | intrack->CalculatePoint(xval); | |
173 | } | |
174 | tin->QSort(); | |
175 | tout->QSort(); | |
176 | ||
177 | if(fSlow) SlowMerge(ttt,tin,tout,xval); | |
178 | else Merge(ttt,tin,tout); | |
179 | ||
180 | /* | |
181 | //Add the tracks that cross the sector boundary: | |
182 | for(Int_t in=0;in<tin->GetNTracks();in++){ | |
183 | AliL3Track *intrack=(AliL3Track*)tin->GetCheckedTrack(in); | |
184 | if(!intrack) continue; | |
185 | if(intrack->CalculateEdgePoint(edge0)){ | |
186 | if(intrack->GetPointX()<xmax ){ | |
187 | AddTrack(ttt,intrack); | |
188 | tin->Remove(in); | |
189 | } | |
190 | } | |
191 | else if(intrack->CalculateEdgePoint(edge1)){ | |
192 | if(intrack->GetPointX()<xmax ){ | |
193 | AddTrack(ttt,intrack); | |
194 | tin->Remove(in); | |
195 | } | |
196 | } | |
197 | } | |
198 | */ | |
199 | } // end subsector loop | |
200 | LOG(AliL3Log::kInformational,"AliL3HoughMerger::Merge","Result") | |
201 | <<AliL3Log::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent() | |
202 | <<ENDLOG; | |
a1855560 | 203 | } |
204 | ||
b1886074 | 205 | Int_t AliL3HoughMerger::Merge(AliL3TrackArray* mergedtrack,AliL3TrackArray *tracksin,AliL3TrackArray *tracksout) |
a1855560 | 206 | { |
b1886074 | 207 | |
208 | AliL3Track *tracks[2]; | |
209 | const Int_t kNOut=tracksout->GetNTracks(); | |
210 | const Int_t kNIn =tracksin->GetNTracks(); | |
211 | const Int_t kNMerged =mergedtrack->GetNTracks(); | |
212 | ||
213 | Bool_t *ismatchedin = new Bool_t[kNIn]; | |
214 | for(Int_t in =0;in<kNIn;in++) | |
215 | ismatchedin[in]=kFALSE; | |
216 | Bool_t *ismatchedout = new Bool_t[kNOut]; | |
217 | for(Int_t out =0;out<kNOut;out++) | |
218 | ismatchedout[out] = kFALSE; | |
219 | for(Int_t out =0;out<kNOut;out++){ | |
220 | AliL3Track *outertrack=(AliL3Track*)tracksout->GetCheckedTrack(out); | |
221 | if(!outertrack) continue; | |
222 | for(Int_t in =0;in<kNIn;in++){ | |
223 | if(ismatchedin[in]) continue; | |
224 | AliL3Track *innertrack=(AliL3Track*)tracksin->GetCheckedTrack(in); | |
225 | if(!innertrack) continue; | |
226 | if(outertrack==innertrack) continue; | |
227 | ||
228 | if(IsTrack(innertrack,outertrack)) //They can be merged | |
229 | { | |
230 | tracks[0]=innertrack; tracks[1]=outertrack; | |
231 | SortTracks(tracks,2); //Sort the tracks according to minimum x-point | |
232 | //if(tracks[0]->GetLastPointX()<tracks[1]->GetFirstPointX()){ | |
233 | MultiMerge(mergedtrack,tracks,2); | |
234 | tracksout->Remove(out); | |
235 | tracksin->Remove(in); | |
236 | ismatchedin[in]=kTRUE; | |
237 | ismatchedout[out]=kTRUE; | |
238 | break; | |
239 | // } | |
240 | } | |
a1855560 | 241 | } |
b1886074 | 242 | } |
a1855560 | 243 | |
b1886074 | 244 | Int_t nmerged = mergedtrack->GetNTracks()-kNMerged; |
245 | LOG(AliL3Log::kInformational,"AliL3HoughMerger::Merge","Result") | |
246 | <<AliL3Log::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG; | |
247 | delete[] ismatchedin; | |
248 | delete[] ismatchedout; | |
249 | return nmerged; | |
250 | } | |
251 | ||
252 | void AliL3HoughMerger::SlowMerge(AliL3TrackArray *mergedtrack,AliL3TrackArray *tracksin,AliL3TrackArray *tracksout,Double_t xval) | |
253 | { | |
254 | void *ntuple=GetNtuple(); | |
255 | const Int_t kNOut=tracksout->GetNTracks(); | |
256 | const Int_t kNIn =tracksin->GetNTracks(); | |
257 | const Int_t kNMerged =mergedtrack->GetNTracks(); | |
258 | AliL3Track *tracks[2]; | |
259 | Bool_t merge = kTRUE; | |
260 | while(merge){ | |
261 | Int_t inmin=-1,outmin=-1; | |
262 | Double_t min=10; | |
263 | for(Int_t out=0;out<kNOut;out++){ | |
264 | AliL3Track *outertrack=tracksout->GetCheckedTrack(out); | |
265 | if(!outertrack) continue; | |
266 | for(Int_t in=0;in<kNIn;in++){ | |
267 | AliL3Track *innertrack=tracksin->GetCheckedTrack(in); | |
268 | if(!innertrack) continue; | |
269 | Double_t diff = TrackDiff(innertrack,outertrack); | |
270 | if(diff>=0&&diff<min){ | |
271 | min=diff; | |
272 | inmin=in; | |
273 | outmin=out; | |
274 | } | |
275 | } | |
276 | } | |
277 | if(inmin>=0&&outmin>=0){ | |
278 | AliL3Track *outertrack=tracksout->GetTrack(outmin); | |
279 | AliL3Track *innertrack=tracksin->GetTrack(inmin); | |
280 | tracks[0]=innertrack; | |
281 | tracks[1]=outertrack; | |
282 | SortTracks(tracks,2); | |
283 | Print(tracks); | |
284 | MultiMerge(mergedtrack,tracks,2); | |
285 | outertrack->CalculatePoint(xval); | |
286 | innertrack->CalculatePoint(xval); | |
287 | FillNtuple(ntuple,innertrack,outertrack); | |
288 | tracksout->Remove(outmin); | |
289 | tracksin->Remove(inmin); | |
290 | // tracksout->Compress(); | |
291 | // tracksin->Compress(); | |
292 | } | |
293 | else merge = kFALSE; | |
294 | } | |
295 | LOG(AliL3Log::kInformational,"AliL3HoughMerger::SlowMerge","Result") | |
296 | <<AliL3Log::kDec<<"Merged Tracks: " | |
297 | <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG; | |
298 | char name[256] = "ntuple_t.root"; | |
299 | for(Int_t i=0;i<GetNIn();i++) | |
300 | if(tracksin==GetInTracks(i)) | |
301 | sprintf(name,"ntuple_t_%d.root",i); | |
302 | WriteNtuple(name,ntuple); | |
303 | } | |
304 | ||
305 | void AliL3HoughMerger::Print(AliL3Track **tracks) | |
306 | { | |
307 | AliL3HoughTrack *tr1 = (AliL3HoughTrack*)tracks[0]; | |
308 | AliL3HoughTrack *tr2 = (AliL3HoughTrack*)tracks[1]; | |
309 | Double_t kappadiff = fabs(tr1->GetKappa()-tr2->GetKappa()); | |
310 | Double_t phi0diff = fabs(tr1->GetPhi0()-tr2->GetPhi0()); | |
311 | cout << "---------Difference in merged tracks---------"<<endl; | |
312 | cout << "Kappa: "<<kappadiff<<" Phi0 : "<<phi0diff<<endl; | |
a1855560 | 313 | |
314 | } |