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