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() : AliHLTTPCMerger()
51 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(Int_t nsubsectors) : AliHLTTPCMerger()
54 InitMerger(nsubsectors);
55 fNSubSector = nsubsectors;
59 fRowMin = new Int_t[nsubsectors];
60 fRowMax = new Int_t[nsubsectors];
64 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(const AliHLTTPCTrackMerger&) : AliHLTTPCMerger()
66 // dummy copy constructor
67 //HLTFatal("copy constructor untested");
70 AliHLTTPCTrackMerger& AliHLTTPCTrackMerger::operator=(const AliHLTTPCTrackMerger&)
72 // dummy assignment operator
73 //HLTFatal("assignment operator untested");
77 AliHLTTPCTrackMerger::~AliHLTTPCTrackMerger(){
81 void AliHLTTPCTrackMerger::SetRows(Int_t *row){
82 //Set the indeces of the first and last
85 for(Int_t i=0;i<fNSubSector;i++){
86 fRowMin[i]=*(row+(2*i));
87 fRowMax[i]=*(row+(2*i+1));
91 void AliHLTTPCTrackMerger::InitSector(Int_t slice,Int_t subsector){
93 // Select Sector and subsector. The following FillTracks call will
94 // fill this subsector
97 fSubSector = subsector;
98 fCurrentTracks = fSubSector;
101 void AliHLTTPCTrackMerger::SlowMerge(AliHLTTPCTrackArray *mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout,Double_t xval){
103 // Slow merging of two AliHLTTPCTrackArrays
104 // at reference plane x=xval
106 void *ntuple=GetNtuple();
107 const Int_t kNOut=tracksout->GetNTracks();
108 const Int_t kNIn =tracksin->GetNTracks();
109 const Int_t kNMerged =mergedtrack->GetNTracks();
110 AliHLTTPCTrack *tracks[2];
111 Bool_t merge = kTRUE;
113 Int_t inmin=-1,outmin=-1;
115 for(Int_t out=0;out<kNOut;out++){
116 AliHLTTPCTrack *outertrack=tracksout->GetCheckedTrack(out);
117 if(!outertrack) continue;
118 for(Int_t in=0;in<kNIn;in++){
119 AliHLTTPCTrack *innertrack=tracksin->GetCheckedTrack(in);
120 if(!innertrack) continue;
121 Double_t diff = TrackDiff(innertrack,outertrack);
122 if(diff>=0&&diff<min){
129 if(inmin>=0&&outmin>=0){
130 AliHLTTPCTrack *outertrack=tracksout->GetTrack(outmin);
131 AliHLTTPCTrack *innertrack=tracksin->GetTrack(inmin);
132 tracks[0]=innertrack;
133 tracks[1]=outertrack;
134 SortTracks(tracks,2);
135 MultiMerge(mergedtrack,tracks,2);
136 outertrack->CalculatePoint(xval);
137 innertrack->CalculatePoint(xval);
138 PrintDiff(innertrack,outertrack);
139 //FillNtuple(ntuple,innertrack,outertrack);
140 tracksout->Remove(outmin);
141 tracksin->Remove(inmin);
142 // tracksout->Compress();
143 // tracksin->Compress();
147 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::SlowMerge","Result")
148 <<AliHLTTPCLog::kDec<<"Merged Tracks: "
149 <<mergedtrack->GetNTracks()-kNMerged<<ENDLOG;
150 char name[256] = "ntuple_t.root";
151 for(Int_t i=0;i<4;i++)
152 if(tracksin==GetInTracks(i))
153 sprintf(name,"ntuple_t_%d.root",i);
154 WriteNtuple(name,ntuple);
157 void AliHLTTPCTrackMerger::SlowMerge(){
162 void AliHLTTPCTrackMerger::InterMerge(){
164 // Merging of the tracks
165 // between readout patches
167 for(Int_t patch=0;patch< GetNIn();patch++){
168 AliHLTTPCTrackArray * tracks = GetInTracks(patch);
169 Double_t xval = AliHLTTPCTransform::Row2X((fRowMax[patch]+fRowMin[patch])/2);
170 Int_t nrow= fRowMax[patch]-fRowMin[patch]+1;
171 const Int_t kNIn =tracks->GetNTracks();
172 AliHLTTPCTrack *tr[2];
173 for(Int_t in=0;in<kNIn;in++){
174 AliHLTTPCTrack *t = tracks->GetCheckedTrack(in);
177 t->CalculatePoint(xval);
180 for(Int_t out=0;out<kNIn;out++){
181 AliHLTTPCTrack *outertrack=tracks->GetCheckedTrack(out);
182 if(!outertrack) continue;
183 for(Int_t in=0;in<kNIn;in++){
184 if(in==out) continue;
185 AliHLTTPCTrack *innertrack=tracks->GetCheckedTrack(in);
186 if(!innertrack) continue;
187 if(outertrack->GetNHits()+innertrack->GetNHits()>nrow) continue;
189 if(IsTrack(innertrack,outertrack)){
193 if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){
194 MultiMerge(tracks,tr,2);
202 Int_t nmerged = tracks->GetNTracks()-kNIn;
203 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::InterMerge","Result")
204 <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
208 void AliHLTTPCTrackMerger::Merge(){
209 //Loop over tracks and pass them to the track merger.
210 Double_t edge0 = AliHLTTPCTransform::Pi()/18;
211 Double_t edge1 = AliHLTTPCTransform::TwoPi() - edge0;
212 AliHLTTPCTrackArray *ttt = GetOutTracks();
214 GetOutTracks()->AddTracks(GetInTracks(0));
215 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
216 <<AliHLTTPCLog::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent()
220 Int_t subsec = fNSubSector -2;
221 for(Int_t i=subsec;i>=0;i--){
222 AliHLTTPCTrackArray *tout = GetOutTracks();
223 if(i==subsec) tout = GetInTracks(subsec+1);
224 AliHLTTPCTrackArray *tin = GetInTracks(i);
225 Double_t xval = AliHLTTPCTransform::Row2X(fRowMax[i]);
226 Double_t xmax = AliHLTTPCTransform::Row2X(fRowMax[i+1]);
227 Double_t ymax = xval*tan(edge0);
228 for(Int_t out=0;out<tout->GetNTracks();out++){
229 AliHLTTPCTrack *outtrack=tout->GetCheckedTrack(out);
230 if(!outtrack) continue;
231 outtrack->CalculateHelix();
232 outtrack->CalculatePoint(xval);
233 if(outtrack->IsPoint()&&fabs(outtrack->GetPointY())>ymax){
234 if(outtrack->GetNHits()<10)
239 for(Int_t in=0;in<tin->GetNTracks();in++){
240 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetTrack(in);
241 intrack->CalculateHelix();
242 intrack->CalculatePoint(xval);
247 if(fSlow) SlowMerge(ttt,tin,tout,xval);
248 else Merge(ttt,tin,tout);
249 for(Int_t in=0;in<tin->GetNTracks();in++){
250 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in);
251 if(!intrack) continue;
252 if(intrack->CalculateEdgePoint(edge0)){
253 if(intrack->GetPointX()<xmax ){
254 AddTrack(ttt,intrack);
258 else if(intrack->CalculateEdgePoint(edge1)){
259 if(intrack->GetPointX()<xmax ){
260 AddTrack(ttt,intrack);
266 for(Int_t in=0;in<tin->GetNTracks();in++){
267 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetCheckedTrack(in);
268 if(!intrack) continue;
269 if(intrack->GetNHits()<10) continue;
270 AddTrack(ttt,intrack);
274 } // end subsector loop
275 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
276 <<AliHLTTPCLog::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent()
280 Int_t AliHLTTPCTrackMerger::Merge(AliHLTTPCTrackArray* mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout){
281 //Loop over tracks and pass them to the track merger.
282 AliHLTTPCTrack *tracks[2];
284 const Int_t kNOut=tracksout->GetNTracks();
285 const Int_t kNIn =tracksin->GetNTracks();
286 const Int_t kNMerged =mergedtrack->GetNTracks();
288 Bool_t *ismatchedin = new Bool_t[kNIn];
289 for(Int_t in =0;in<kNIn;in++)
290 ismatchedin[in]=kFALSE;
291 Bool_t *ismatchedout = new Bool_t[kNOut];
292 for(Int_t out =0;out<kNOut;out++)
293 ismatchedout[out] = kFALSE;
294 for(Int_t out =0;out<kNOut;out++){
295 AliHLTTPCTrack *outertrack=(AliHLTTPCTrack*)tracksout->GetCheckedTrack(out);
296 if(!outertrack) continue;
297 for(Int_t in =0;in<kNIn;in++){
298 if(ismatchedin[in]) continue;
299 AliHLTTPCTrack *innertrack=(AliHLTTPCTrack*)tracksin->GetCheckedTrack(in);
300 if(!innertrack) continue;
301 if(outertrack==innertrack) continue;
302 if(outertrack->GetCharge()!=innertrack->GetCharge()) continue;
303 if(IsTrack(innertrack,outertrack)){
304 tracks[0]=innertrack; tracks[1]=outertrack;
305 SortTracks(tracks,2);
306 if(tracks[0]->GetLastPointX()<tracks[1]->GetFirstPointX()){
307 MultiMerge(mergedtrack,tracks,2);
308 tracksout->Remove(out);
309 tracksin->Remove(in);
310 ismatchedin[in]=kTRUE;
311 ismatchedout[out]=kTRUE;
318 Int_t nmerged = mergedtrack->GetNTracks()-kNMerged;
319 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
320 <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
321 delete[] ismatchedin;
322 delete[] ismatchedout;