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(){
50 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(Int_t nsubsectors) : AliHLTTPCMerger()
53 InitMerger(nsubsectors);
54 fNSubSector = nsubsectors;
58 fRowMin = new Int_t[nsubsectors];
59 fRowMax = new Int_t[nsubsectors];
63 AliHLTTPCTrackMerger::AliHLTTPCTrackMerger(const AliHLTTPCTrackMerger&)
65 // dummy copy constructor
66 //HLTFatal("copy constructor untested");
69 AliHLTTPCTrackMerger& AliHLTTPCTrackMerger::operator=(const AliHLTTPCTrackMerger&)
71 // dummy assignment operator
72 //HLTFatal("assignment operator untested");
76 AliHLTTPCTrackMerger::~AliHLTTPCTrackMerger(){
80 void AliHLTTPCTrackMerger::SetRows(Int_t *row){
81 //Set the indeces of the first and last
84 for(Int_t i=0;i<fNSubSector;i++){
85 fRowMin[i]=*(row+(2*i));
86 fRowMax[i]=*(row+(2*i+1));
90 void AliHLTTPCTrackMerger::InitSector(Int_t slice,Int_t subsector){
92 // Select Sector and subsector. The following FillTracks call will
93 // fill this subsector
96 fSubSector = subsector;
97 fCurrentTracks = fSubSector;
100 void AliHLTTPCTrackMerger::SlowMerge(AliHLTTPCTrackArray *mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout,Double_t xval){
102 // Slow merging of two AliHLTTPCTrackArrays
103 // at reference plane x=xval
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;
112 Int_t inmin=-1,outmin=-1;
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){
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();
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);
156 void AliHLTTPCTrackMerger::SlowMerge(){
161 void AliHLTTPCTrackMerger::InterMerge(){
163 // Merging of the tracks
164 // between readout patches
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);
176 t->CalculatePoint(xval);
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;
188 if(IsTrack(innertrack,outertrack)){
192 if(tr[0]->GetLastPointX()<tr[1]->GetFirstPointX()){
193 MultiMerge(tracks,tr,2);
201 Int_t nmerged = tracks->GetNTracks()-kNIn;
202 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::InterMerge","Result")
203 <<AliHLTTPCLog::kDec<<"Merged Tracks: "<<nmerged<<ENDLOG;
207 void 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();
213 GetOutTracks()->AddTracks(GetInTracks(0));
214 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
215 <<AliHLTTPCLog::kDec<<"Total Copied Tracks: "<<GetOutTracks()->GetNPresent()
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)
238 for(Int_t in=0;in<tin->GetNTracks();in++){
239 AliHLTTPCTrack *intrack=(AliHLTTPCTrack*)tin->GetTrack(in);
240 intrack->CalculateHelix();
241 intrack->CalculatePoint(xval);
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);
257 else if(intrack->CalculateEdgePoint(edge1)){
258 if(intrack->GetPointX()<xmax ){
259 AddTrack(ttt,intrack);
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);
273 } // end subsector loop
274 LOG(AliHLTTPCLog::kInformational,"AliHLTTPCTrackMerger::Merge","Result")
275 <<AliHLTTPCLog::kDec<<"Total Merged Tracks: "<<GetOutTracks()->GetNPresent()
279 Int_t AliHLTTPCTrackMerger::Merge(AliHLTTPCTrackArray* mergedtrack,AliHLTTPCTrackArray *tracksin,AliHLTTPCTrackArray *tracksout){
280 //Loop over tracks and pass them to the track merger.
281 AliHLTTPCTrack *tracks[2];
283 const Int_t kNOut=tracksout->GetNTracks();
284 const Int_t kNIn =tracksin->GetNTracks();
285 const Int_t kNMerged =mergedtrack->GetNTracks();
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;
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;