2 // Original: AliHLTTrackMerger.cxx,v 1.12 2005/06/14 10:55:21 cvetan
4 //**************************************************************************
5 //* This file is property of and copyright by the ALICE HLT Project *
6 //* ALICE Experiment at CERN, All rights reserved. *
8 //* Primary Authors: Uli Frankenfeld, maintained by *
9 //* Matthias Richter <Matthias.Richter@ift.uib.no> *
10 //* for The ALICE HLT Project. *
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 //**************************************************************************
21 /// @file AliHLTTPCTrackMerger.cxx
22 /// @author Uli Frankenfeld, maintained by Matthias Richter
24 /// @brief The HLT TPC track segment merger
27 #include "AliHLTTPCLogging.h"
28 #include "AliHLTTPCTrackMerger.h"
29 #include "AliHLTTPCTrack.h"
30 #include "AliHLTTPCTrackSegmentData.h"
31 #include "AliHLTTPCTransform.h"
32 #include "AliHLTTPCTrackArray.h"
38 ClassImp(AliHLTTPCTrackMerger)
40 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger()
55 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(Int_t nsubsectors)
59 fNSubSector(nsubsectors),
60 fRowMin(new Int_t[nsubsectors]),
61 fRowMax(new Int_t[nsubsectors]),
65 InitMerger(nsubsectors);
71 AliHLTTPCTrackMerger::~AliHLTTPCTrackMerger()
74 if (fRowMin) delete[] fRowMin;
75 if (fRowMax) delete[] fRowMax;
78 void AliHLTTPCTrackMerger::SetRows(Int_t *row){
79 //Set the indeces of the first and last
82 for(Int_t i=0;i<fNSubSector;i++){
83 fRowMin[i]=*(row+(2*i));
84 fRowMax[i]=*(row+(2*i+1));
88 void AliHLTTPCTrackMerger::InitSector(Int_t slice,Int_t subsector){
90 // Select Sector and subsector. The following FillTracks call will
91 // fill this subsector
94 fSubSector = subsector;
95 fCurrentTracks = fSubSector;
98 void AliHLTTPCTrackMerger::SlowMerge(AliHLTTPCTrackArray *mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout,Double_t xval){
100 // Slow merging of two AliHLTTPCTrackArrays
101 // at reference plane x=xval
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;
110 Int_t inmin=-1,outmin=-1;
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){
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();
144 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::SlowMerge","Result")
145 <<AliHLTTPCLog::kDec<<"Merged Tracks: "
146 <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG;
147 char name[256] = "ntuple_t.root";
148 for(Int_t i=0;i<4;i++)
149 if(tracksin==GetInTracks(i))
150 sprintf(name,"ntuple_t_%d.root",i);
151 WriteNtuple(name,ntuple);
154 void AliHLTTPCTrackMerger::SlowMerge(){
159 void AliHLTTPCTrackMerger::InterMerge(){
161 // Merging of the tracks
162 // between readout patches
164 for(Int_t patch=0;patch< GetNIn();patch++){
165 AliHLTTPCTrackArray * tracks = GetInTracks(patch);
166 Double_t xval = AliHLTTPCTransform::Row2X((fRowMax[patch]+fRowMin[patch])/2);
167 Int_t nrow= fRowMax[patch]-fRowMin[patch]+1;
168 const Int_t kNIn =tracks->GetNTracks();
169 AliHLTTPCTrack *tr[2];
170 for(Int_t in=0;in<kNIn;in++){
171 AliHLTTPCTrack *t = tracks->GetCheckedTrack(in);
174 t->CalculatePoint(xval);
177 for(Int_t out=0;out<kNIn;out++){
178 AliHLTTPCTrack *outertrack=tracks->GetCheckedTrack(out);
179 if(!outertrack) continue;
180 for(Int_t in=0;in<kNIn;in++){
181 if(in==out) continue;
182 AliHLTTPCTrack *innertrack=tracks->GetCheckedTrack(in);
183 if(!innertrack) continue;
184 if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue;
186 if(IsTrack(innertrack,outertrack)){
190 if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){
191 MultiMerge(tracks,tr,2);
199 Int_t nmerged = tracks->GetNTracks()-kNIn;
200 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::InterMerge","Result")
201 <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
205 void AliHLTTPCTrackMerger::Merge(){
206 //Loop over tracks and pass them to the track merger.
207 Double_t edge0 = AliHLTTPCTransform::Pi()/18;
208 Double_t edge1 = AliHLTTPCTransform::TwoPi() - edge0;
209 AliHLTTPCTrackArray *ttt = GetOutTracks();
211 GetOutTracks()->AddTracks(GetInTracks(0));
212 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
213 <<AliHLTTPCLog::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent()
217 Int_t subsec = fNSubSector -2;
218 for(Int_t i=subsec;i>=0;i--){
219 AliHLTTPCTrackArray *tout = GetOutTracks();
220 if(i==subsec) tout = GetInTracks(subsec+1);
221 AliHLTTPCTrackArray *tin = GetInTracks(i);
222 Double_t xval = AliHLTTPCTransform::Row2X(fRowMax[i]);
223 Double_t xmax = AliHLTTPCTransform::Row2X(fRowMax[i+1]);
224 Double_t ymax = xval*tan(edge0);
225 for(Int_t out=0;out<tout->GetNTracks();out++){
226 AliHLTTPCTrack *outtrack=tout->GetCheckedTrack(out);
227 if(!outtrack) continue;
228 outtrack->CalculateHelix();
229 outtrack->CalculatePoint(xval);
230 if(outtrack->IsPoint()&&fabs(outtrack->GetPointY())>ymax){
231 if(outtrack->GetNHits()<10)
236 for(Int_t in=0;in<tin->GetNTracks();in++){
237 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetTrack(in);
238 intrack->CalculateHelix();
239 intrack->CalculatePoint(xval);
244 if(fSlow) SlowMerge(ttt,tin,tout,xval);
245 else Merge(ttt,tin,tout);
246 for(Int_t in=0;in<tin->GetNTracks();in++){
247 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in);
248 if(!intrack) continue;
249 if(intrack->CalculateEdgePoint(edge0)){
250 if(intrack->GetPointX()<xmax ){
251 AddTrack(ttt,intrack);
255 else if(intrack->CalculateEdgePoint(edge1)){
256 if(intrack->GetPointX()<xmax ){
257 AddTrack(ttt,intrack);
263 for(Int_t in=0;in<tin->GetNTracks();in++){
264 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in);
265 if(!intrack) continue;
266 if(intrack->GetNHits()<10) continue;
267 AddTrack(ttt,intrack);
271 } // end subsector loop
272 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
273 <<AliHLTTPCLog::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent()
277 Int_t AliHLTTPCTrackMerger::Merge(AliHLTTPCTrackArray* mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout){
278 //Loop over tracks and pass them to the track merger.
279 AliHLTTPCTrack *tracks[2];
281 const Int_t kNOut=tracksout->GetNTracks();
282 const Int_t kNIn =tracksin->GetNTracks();
283 const Int_t kNMerged =mergedtrack->GetNTracks();
285 Bool_t *ismatchedin = new Bool_t[kNIn];
286 for(Int_t in =0;in<kNIn;in++)
287 ismatchedin[in]=kFALSE;
288 Bool_t *ismatchedout = new Bool_t[kNOut];
289 for(Int_t out =0;out<kNOut;out++)
290 ismatchedout[out] = kFALSE;
291 for(Int_t out =0;out<kNOut;out++){
292 AliHLTTPCTrack *outertrack=(AliHLTTPCTrack*)tracksout->GetCheckedTrack(out);
293 if(!outertrack) continue;
294 for(Int_t in =0;in<kNIn;in++){
295 if(ismatchedin[in]) continue;
296 AliHLTTPCTrack *innertrack=(AliHLTTPCTrack*)tracksin->GetCheckedTrack(in);
297 if(!innertrack) continue;
298 if(outertrack==innertrack) continue;
299 if(outertrack->GetCharge()!=innertrack->GetCharge()) continue;
300 if(IsTrack(innertrack,outertrack)){
301 tracks[0]=innertrack; tracks[1]=outertrack;
302 SortTracks(tracks,2);
303 if(tracks[0]->GetLastPointX()<tracks[1]->GetFirstPointX()){
304 MultiMerge(mergedtrack,tracks,2);
305 tracksout->Remove(out);
306 tracksin->Remove(in);
307 ismatchedin[in]=kTRUE;
308 ismatchedout[out]=kTRUE;
315 Int_t nmerged = mergedtrack->GetNTracks()-kNMerged;
316 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
317 <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
318 delete[] ismatchedin;
319 delete[] ismatchedout;