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 const int namelen=256;
148 char name[namelen] = "ntuple_t.root";
149 for(Int_t i=0;i<4;i++)
150 if(tracksin==GetInTracks(i))
151 snprintf(name,namelen,"ntuple_t_%d.root",i);
152 WriteNtuple(name,ntuple);
155 void AliHLTTPCTrackMerger::SlowMerge(){
160 void AliHLTTPCTrackMerger::InterMerge(){
162 // Merging of the tracks
163 // between readout patches
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);
175 t->CalculatePoint(xval);
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;
187 if(IsTrack(innertrack,outertrack)){
191 if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){
192 MultiMerge(tracks,tr,2);
200 Int_t nmerged = tracks->GetNTracks()-kNIn;
201 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::InterMerge","Result")
202 <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
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();
212 GetOutTracks()->AddTracks(GetInTracks(0));
213 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
214 <<AliHLTTPCLog::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent()
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)
237 for(Int_t in=0;in<tin->GetNTracks();in++){
238 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetTrack(in);
239 intrack->CalculateHelix();
240 intrack->CalculatePoint(xval);
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);
256 else if(intrack->CalculateEdgePoint(edge1)){
257 if(intrack->GetPointX()<xmax ){
258 AddTrack(ttt,intrack);
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);
272 } // end subsector loop
273 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
274 <<AliHLTTPCLog::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent()
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];
282 const Int_t kNOut=tracksout->GetNTracks();
283 const Int_t kNIn =tracksin->GetNTracks();
284 const Int_t kNMerged =mergedtrack->GetNTracks();
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;
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;