Heavily modified the AliHLTTPCDisplay class for better usage in the new
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPC.cxx
CommitLineData
a6c02c85 1// @(#) $Id$
2
3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4//*-- Copyright &copy ALICE HLT Group
5
6#include "AliHLTTPCStandardIncludes.h"
7
8#ifndef no_root
9#include <TFile.h>
10#include <TDirectory.h>
11#include <TClonesArray.h>
12#include <TStopwatch.h>
13#endif
14
15#ifdef use_newio
16#include <AliRunLoader.h>
17#endif
18
19#include "AliHLTTPCLogging.h"
20#include "AliHLTTPC.h"
21#include "AliHLTTPCConfMapper.h"
22#include "AliHLTTPCVertex.h"
23#include "AliHLTTPCVertexFinder.h"
24#include "AliHLTTPCTrackMerger.h"
25#include "AliHLTTPCGlobalMerger.h"
26#include "AliHLTTPCInterMerger.h"
27#include "AliHLTTPCConfMapPoint.h"
28#include "AliHLTTPCConfMapTrack.h"
29#include "AliHLTTPCTransform.h"
30#include "AliHLTTPCClustFinderNew.h"
31#include "AliHLTTPCDigitData.h"
32#include "AliHLTTPCTrackArray.h"
33#include "AliHLTTPCMemHandler.h"
34#include "AliHLTTPCFitter.h"
35#ifdef use_aliroot
36#include "AliHLTTPCFileHandler.h"
37#endif
38#include "AliHLTTPCBenchmark.h"
39#include "AliHLTTPCDigitData.h"
40#include "AliHLTTPCTrackSegmentData.h"
41#include "AliHLTTPCSpacePointData.h"
42#include "AliHLTTPCVertexData.h"
43#include "AliHLTTPCDDLDataFileHandler.h"
44
45/** \class AliHLTTPC
46<pre>
47//_____________________________________________________________
48//
49// AliHLTTPC
50//
51// Interface class for HLTTPC tracker.
52// For example how to use, see exa/runtracker.C (root)
53// or programs/runtracker.cxx (standalone program).
54//Begin_Html
55//<img src="tpcsectorsnb.gif">
56//End_Html
57</pre>
58*/
59
60ClassImp(AliHLTTPC)
61
62Bool_t AliHLTTPC::fgDoVertexFit = kTRUE;//Include the vertex in the final track fit
63
64AliHLTTPC::AliHLTTPC()
65{
66 //Default constructor. Should also be used when input is from binary files.
67 //In that case the path to where the binary files are located has to be
68 //passed to the AliLevel::Init function.
69
70 fVertexFinder=0;
71 fVertex=0;
72 fTracker=0;
73 fTrackMerger=0;
74 fInterMerger=0;
75 fFileHandler=0;
76 fGlobalMerger=0;
77 fInputFile=0;
78#ifdef use_newio
79 fRunLoader=0;
80#endif
81}
82
83AliHLTTPC::AliHLTTPC(Char_t *infile)
84{
85 //Constructor to use for when input is anything else but binary files,
86 //meaning rootfiles or raw files.
87
88 fVertexFinder=0;
89 fVertex=0;
90 fTracker=0;
91 fTrackMerger=0;
92 fInterMerger=0;
93 fFileHandler=0;
94 fGlobalMerger=0;
95 fInputFile = infile;
96#ifdef use_newio
97 fRunLoader=0;
98#endif
99}
100
101#ifdef use_newio
102AliHLTTPC::AliHLTTPC(AliRunLoader *rl)
103{
104 //Constructor to use when input is aliroot runloader
105 fVertexFinder=0;
106 fVertex=0;
107 fTracker=0;
108 fTrackMerger=0;
109 fInterMerger=0;
110 fFileHandler=0;
111 fGlobalMerger=0;
112 fInputFile=0;
113 fRunLoader = rl;
114}
115#endif
116
117void AliHLTTPC::Init(Char_t *path,EFileType filetype,Int_t npatches)
118{
119 //Init the whole standard tracker chain
120#ifndef use_newio
121 if (filetype==kRunLoader){
122 LOG(AliHLTTPCLog::kError,"AliHLTTPC::Init","Files")
123 <<"You have not supplied the input rootfile; if you want "
124 <<"to run with RunLoader use -Duse_newio for compiling!"<<ENDLOG;
125 }
126#endif
127
128 if((filetype!=kBinary) && (filetype!=kDate)
129 && (filetype!=kRunLoader)&& !fInputFile)
130 {
131 LOG(AliHLTTPCLog::kError,"AliHLTTPC::Init","Files")
132 <<"You have not supplied the input rootfile; use the appropriate ctor!"<<ENDLOG;
133 return;
134 }
135#if use_newio
136 if((filetype==kRunLoader) && !fRunLoader)
137 {
138 LOG(AliHLTTPCLog::kError,"AliHLTTPC::Init","Files")
139 <<"You have not supplied the input runloader; use the appropriate ctor!"<<ENDLOG;
140 return;
141 }
142#endif
143
144 fWriteOut = kFALSE;
145 fPileUp = kFALSE;
146 fNoCF=kFALSE;
147 fUseBinary = (filetype==kBinary);
148 SetPath(path);
149
150 fDoRoi = kFALSE;
151 fDoNonVertex = kFALSE;
152 fFindVertex = kFALSE;
153 SetClusterFinderParam();
154
155 fEta[0] = 0.;
156 fEta[1] = 1.1;
157
158 fEvent=0;
159#ifdef use_aliroot /*just to be sure*/
160 AliHLTTPCFileHandler::CleanStaticIndex();
161#endif
162
163 switch(npatches){
164 case 0:
165 fNPatch = 1;
166 fRow[0][0] = AliHLTTPCTransform::GetFirstRow(3);
167 fRow[0][1] = AliHLTTPCTransform::GetLastRow(5);
168 break;
169 case 1:
170 fNPatch = 1; //number of patches change row in process
171 fRow[0][0] = 0;
172 fRow[0][1] = AliHLTTPCTransform::GetLastRow(-1);
173 break;
174 case 2:
175 fNPatch = 2; //number of patches change row in process
176 fRow[0][0] = 0; // first row
177 fRow[0][1] = AliHLTTPCTransform::GetLastRow(1);
178 fRow[1][0] = AliHLTTPCTransform::GetFirstRow(2);
179 fRow[1][1] = AliHLTTPCTransform::GetLastRow(5);
180 break;
181 default:
182 fNPatch = 6;
183 fRow[0][0] = AliHLTTPCTransform::GetFirstRow(0);
184 fRow[0][1] = AliHLTTPCTransform::GetLastRow(0);
185 fRow[1][0] = AliHLTTPCTransform::GetFirstRow(1);
186 fRow[1][1] = AliHLTTPCTransform::GetLastRow(1);
187 fRow[2][0] = AliHLTTPCTransform::GetFirstRow(2);
188 fRow[2][1] = AliHLTTPCTransform::GetLastRow(2);
189 fRow[3][0] = AliHLTTPCTransform::GetFirstRow(3);
190 fRow[3][1] = AliHLTTPCTransform::GetLastRow(3);
191 fRow[4][0] = AliHLTTPCTransform::GetFirstRow(4);
192 fRow[4][1] = AliHLTTPCTransform::GetLastRow(4);
193 fRow[5][0] = AliHLTTPCTransform::GetFirstRow(5);
194 fRow[5][1] = AliHLTTPCTransform::GetLastRow(5);
195 }
196
197 fVertexFinder = new AliHLTTPCVertexFinder();
198 fVertex = new AliHLTTPCVertex();
199 fTracker = new AliHLTTPCConfMapper();
200 fTrackMerger = new AliHLTTPCTrackMerger(fNPatch);
201 fInterMerger = new AliHLTTPCInterMerger();
202 fGlobalMerger = new AliHLTTPCGlobalMerger();
203 SetMergerParameters();//Set default merger parameters
204#ifdef use_aliroot
205 if(filetype==kRoot){
206 fFileHandler = new AliHLTTPCFileHandler(kTRUE); //static version
207 fFileHandler->SetAliInput(fInputFile);
208 }else if(filetype==kRaw){
209 fFileHandler = new AliHLTTPCDDLDataFileHandler();
210 fFileHandler->SetReaderInput(fInputFile);
211 }else if(filetype==kDate){
212 fFileHandler = new AliHLTTPCDDLDataFileHandler();
213 fFileHandler->SetReaderInput(fInputFile,-1);
214 }
215#if use_newio
216 else if(filetype==kRunLoader){
217 fFileHandler = new AliHLTTPCFileHandler(kTRUE); //static version
218 fFileHandler->SetAliInput(fRunLoader);
219 }
220#endif
221 else{
222 fFileHandler = new AliHLTTPCMemHandler();
223 }
224#else
225 if(filetype==kRaw){
226 fFileHandler = new AliHLTTPCDDLDataFileHandler();
227 fFileHandler->SetReaderInput(fInputFile);
228 }else{
229 fFileHandler = new AliHLTTPCMemHandler();
230 }
231#endif
232 fBenchmark = new AliHLTTPCBenchmark();
233}
234
235void AliHLTTPC::DoBench(char* name)
236{
237 //dobench
238 fBenchmark->Analyze(name);
239 delete fBenchmark;
240 fBenchmark = new AliHLTTPCBenchmark();
241}
242
243void AliHLTTPC::DoMc(char* file)
244{
245 //domc
246#ifdef use_aliroot
247 if(!fFileHandler->IsDigit(fEvent))
248 fFileHandler->SetMCOutput(file);
249#endif
250}
251
252AliHLTTPC::~AliHLTTPC()
253{
254 //Destructor
255 if(fVertexFinder) delete fVertexFinder;
256 if(fVertex) delete fVertex;
257 if(fTracker) delete fTracker;
258 if(fTrackMerger) delete fTrackMerger;
259 if(fInterMerger) delete fInterMerger;
260 if(fFileHandler) delete fFileHandler;
261 if(fGlobalMerger) delete fGlobalMerger;
262}
263
264void AliHLTTPC::SetClusterFinderParam(Float_t fXYError, Float_t fZError, Bool_t deconv)
265{
266 //set cluster finder parameter
267 fXYClusterError=fXYError;
268 fZClusterError=fZError;
269 fClusterDeconv=deconv;
270}
271
272void AliHLTTPC::SetTrackerParam(Int_t phi_segments, Int_t eta_segments,
273 Int_t trackletlength, Int_t tracklength,
274 Int_t rowscopetracklet, Int_t rowscopetrack,
275 Double_t min_pt_fit, Double_t maxangle,
276 Double_t goodDist, Double_t hitChi2Cut,
277 Double_t goodHitChi2, Double_t trackChi2Cut,
278 Int_t maxdist,Double_t maxphi,Double_t maxeta,
279 Bool_t vertexconstraint)
280{
281 //Set parameters input to the tracker
282 //If no arguments are given, default parameters will be used
283
284 fTracker->SetNSegments(phi_segments,eta_segments);
285 fTracker->SetMaxDca(min_pt_fit);
286 fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,vertexconstraint);
287 fTracker->SetTrackletCuts(maxangle,goodDist,vertexconstraint);
288 if(vertexconstraint)
289 fTracker->MainVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack,maxphi,maxeta);
290 else
291 fTracker->NonVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack);
292 fTracker->InitVolumes();
293}
294
295void AliHLTTPC::SetMergerParameters(Double_t maxy,Double_t maxz,Double_t maxkappa,Double_t maxpsi,Double_t maxtgl)
296{
297 //set global merger parameter
298 fGlobalMerger->SetParameter(maxy,maxz,maxkappa,maxpsi,maxtgl);
299}
300
301void AliHLTTPC::ProcessEvent(Int_t first,Int_t last,Int_t event)
302{
303 //Do tracking on all slices in region [first,last]
304 //Slices numbering in TPC goes from 0-35, which means that one slice
305 //corresponds to inner+outer sector.E.g. slice 2 corresponds to
306 //inner=2 + outer=38.
307
308 fGlobalMerger->Setup(first,last);
309#ifdef use_aliroot
310 if(fEvent!=event) AliHLTTPCFileHandler::CleanStaticIndex();
311#endif
312 fEvent=event;
313 for(Int_t i=first; i<=last; i++){
314 ProcessSlice(i);
315 fGlobalMerger->SetVertex(fVertex);
316 fGlobalMerger->InitSlice(i);
317 fGlobalMerger->FillTracks(fNTrackData,fTrackData);
318 fFileHandler->Free(); //free the memory
319 fNTrackData=0;
320 fTrackData=0;
321 }
322 fBenchmark->Start("Global track merger");
323 //fGlobalMerger->AddAllTracks();
324 fGlobalMerger->Merge();
325 //fGlobalMerger->SlowMerge(fWriteOutPath);
326 fBenchmark->Stop("Global track merger");
327
328 FitGlobalTracks();
329
330 if(fWriteOut) WriteResults();
331 fFileHandler->FreeDigitsTree();
332}
333
334void AliHLTTPC::ProcessSlice(Int_t slice)
335{
336 //process slice
337 char name[256];
338 Bool_t UseCF = kFALSE;
339#ifdef use_aliroot
340 UseCF = fFileHandler->IsDigit(fEvent);
341#endif
342 if(fUseBinary)
343 UseCF = kTRUE; //In case you are not using aliroot
344 if(fNoCF == kTRUE) //In case you don't want to run with cluster finder
345 UseCF = kFALSE;
346
347 const Int_t kmaxpoints=120000;
348 const Int_t kpointsize = kmaxpoints * sizeof(AliHLTTPCSpacePointData);
349 AliHLTTPCMemHandler *memory = new AliHLTTPCMemHandler();
350
351 fTrackMerger->Reset();
352 fTrackMerger->SetRows(fRow[0]);
353
354 for(Int_t patch=fNPatch-1;patch>=0;patch--){
355 fFileHandler->Init(slice,patch,&fRow[patch][0]);
356 UInt_t npoints=0;
357 AliHLTTPCSpacePointData *points =0;
358 UInt_t ndigits=0;
359 AliHLTTPCDigitRowData *digits =0;
360 if(UseCF){
361 if(fUseBinary){
362 if(!fDoRoi){
363 if(1){ //Binary to Memory
364 fFileHandler->Free();
365 if(fNPatch == 1)
366 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,-1);
367 else
368 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,patch);
369 if(!fFileHandler->SetBinaryInput(name)) return;
370 if(fPileUp)
371 { //Read binary files which are not RLE
372 digits = (AliHLTTPCDigitRowData*)fFileHandler->Allocate();
373 fFileHandler->Binary2Memory(ndigits,digits);
374 }
375 else //Read RLE binary files
376 digits= (AliHLTTPCDigitRowData *)fFileHandler->CompBinary2Memory(ndigits);
377
378 fFileHandler->CloseBinaryInput();
379 }
380
381 if(0){ //Binary to Memory with Benchmark
382 fFileHandler->Free();
383 if(fNPatch == 1)
384 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,-1);
385 else
386 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,patch);
387 if(!memory->SetBinaryInput(name)) return;
388 UInt_t compsize=memory->GetFileSize();
389 UInt_t *comp=(UInt_t *)memory->Allocate(compsize);
390 memory->CompBinary2CompMemory(ndigits,comp);
391 memory->CloseBinaryInput();
392 UInt_t datasize=memory->GetMemorySize(ndigits,comp);
393 digits=(AliHLTTPCDigitRowData *)fFileHandler->Allocate(datasize);
394 fBenchmark->Start("Unpacker");
395 fFileHandler->CompMemory2Memory(ndigits,digits,comp);
396 fBenchmark->Stop("Unpacker");
397 memory->Free();
398 }
399
400 if(0){ //Binary to Memory with Random
401 fFileHandler->Free();
402 fFileHandler->ResetRandom();
403 fFileHandler->SetRandomCluster(100);
404 fFileHandler->SetNGenerate(100);
405 if(fNPatch == 1)
406 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,-1);
407 else
408 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,patch);
409 if(!memory->SetBinaryInput(name)) return;
410 UInt_t compsize=memory->GetFileSize();
411 UInt_t *comp=(UInt_t *)memory->Allocate(compsize);
412 memory->CompBinary2CompMemory(ndigits,comp);
413 memory->CloseBinaryInput();
414 UInt_t dsize=memory->GetMemorySize(ndigits,comp);
415 UInt_t rsize=fFileHandler->GetRandomSize();
416 digits=(AliHLTTPCDigitRowData*)fFileHandler->Allocate(dsize+rsize);
417 fBenchmark->Start("Unpacker");
418 fFileHandler->CompMemory2Memory(ndigits,digits,comp);
419 fBenchmark->Stop("Unpacker");
420 memory->Free();
421 }
422 }
423
424 else{ //Binary to Memory with Roi
425 fFileHandler->Free();
426 Int_t sli[2]={0,0};
427 fFileHandler->SetROI(fEta,sli);
428 if(fNPatch==1)
429 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,-1);
430 else
431 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,patch);
432 if(!memory->SetBinaryInput(name)) return;
433 UInt_t compsize=memory->GetFileSize();
434 UInt_t *comp=(UInt_t *)memory->Allocate(compsize);
435 memory->CompBinary2CompMemory(ndigits,comp);
436 memory->CloseBinaryInput();
437 UInt_t datasize=memory->GetMemorySize(ndigits,comp);
438 digits=(AliHLTTPCDigitRowData *)fFileHandler->Allocate(datasize);
439 fBenchmark->Start("Unpacker");
440 datasize = fFileHandler->CompMemory2Memory(ndigits,digits,comp);
441 fBenchmark->Stop("Unpacker");
442 memory->Free();
443 }
444 }//end UseBinary
445 else{
446#ifdef use_aliroot
447 fBenchmark->Start("Dummy Unpacker");
448 if(fNPatch==1)
449 sprintf(name,"digits_%d_%d_%d.raw",fEvent,slice,-1);
450 else
451 sprintf(name,"digits_%d_%d_%d.raw",fEvent,slice,patch);
452 fBenchmark->Stop("Dummy Unpacker");
453
454 if(0){ //Ali to Binary
455 fFileHandler->SetBinaryOutput(name);
456 fFileHandler->AliDigits2CompBinary();
457 fFileHandler->CloseBinaryOutput();
458 }
459
460 if(1){ //Ali to Memory
461 digits=(AliHLTTPCDigitRowData *)fFileHandler->AliAltroDigits2Memory(ndigits,fEvent);
462 if(0){ //Memory to Binary
463 fFileHandler->SetBinaryOutput(name);
464 fFileHandler->Memory2CompBinary(ndigits,digits);
465 fFileHandler->CloseBinaryOutput();
466 }
467 }
468#endif
469 }//end else UseBinary
470
471 points = (AliHLTTPCSpacePointData *) memory->Allocate(kpointsize);
472 fClusterFinder = new AliHLTTPCClustFinderNew();
473 fClusterFinder->InitSlice(slice,patch,fRow[patch][0],fRow[patch][1],kmaxpoints);
474 fClusterFinder->SetDeconv(fClusterDeconv);
475 fClusterFinder->SetXYError(fXYClusterError);
476 fClusterFinder->SetZError(fZClusterError);
477 if((fXYClusterError>0)&&(fZClusterError>0))
478 fClusterFinder->SetCalcErr(kFALSE);
479 fClusterFinder->SetOutputArray(points);
480 fBenchmark->Start("Cluster finder");
481 fClusterFinder->Read(ndigits,digits);
482 fClusterFinder->ProcessDigits();
483 fBenchmark->Stop("Cluster finder");
484 npoints = fClusterFinder->GetNumberOfClusters();
485 delete fClusterFinder;
486 fClusterFinder = 0;
487 fFileHandler->Free();
488 LOG(AliHLTTPCLog::kInformational,"AliHLTTPC::ProcessSlice","Cluster Finder")
489 <<AliHLTTPCLog::kDec<<"Found "<<npoints<<" Points"<<ENDLOG;
490 }//end UseCF
491 else{// if not use Clusterfinder
492 if(fUseBinary){//Binary to Memory
493 memory->Free();
494 if(fNPatch==1)
495 sprintf(name,"%s/points_%d_%d_%d.raw",fPath,fEvent,slice,-1);
496 else
497 sprintf(name,"%s/points_%d_%d_%d.raw",fPath,fEvent,slice,patch);
498 if(!memory->SetBinaryInput(name)) return;
499 points = (AliHLTTPCSpacePointData *) memory->Allocate();
500 memory->Binary2Memory(npoints,points);
501 memory->CloseBinaryInput();
502 LOG(AliHLTTPCLog::kInformational,"AliHLTTPC::ProcessSlice","Read Cluster")
503 <<AliHLTTPCLog::kDec<<"Found "<<npoints<<" Points in File"<<ENDLOG;
504 }
505#ifdef use_aliroot
506 else{
507 points = fFileHandler->AliPoints2Memory(npoints);
508 }
509#endif
510 fBenchmark->Start("Dummy Unpacker");
511 fBenchmark->Stop("Dummy Unpacker");
512 fBenchmark->Start("Dummy CF");
513 fBenchmark->Stop("Dummy CF");
514 }
515
516 if(patch == fNPatch-1){
517 // Vertex
518 if(fFindVertex){
519 // Vertex Finder
520
521 fBenchmark->Start("Vertex Finder Read");
522 fVertexFinder->Reset();
523 fVertexFinder->Read(npoints,points);
524 fBenchmark->Stop("Vertex Finder Read");
525 fBenchmark->Start("Vertex Finder");
526 fVertexFinder->Analyze();
527 AliHLTTPCVertexData vertex[1];
528 fVertexFinder->Write(vertex);
529 fVertex->Read(vertex);
530 fBenchmark->Stop("Vertex Finder");
531 }
532 else{
533 //use 0,0,0 for vertex
534 fVertex->SetZero();
535 }
536 fTrackMerger->SetVertex(fVertex);
537 }
538
539 fTracker->InitSector(slice,fRow[patch],fEta);
540 fTracker->SetVertex(fVertex);
541 fBenchmark->Start("Tracker setup");
542 fTracker->ReadHits(npoints,points);
543 fTracker->MainVertexTracking_a();
544 fBenchmark->Stop("Tracker setup");
545 fBenchmark->Start("Track follower");
546 fTracker->MainVertexTracking_b();
547 fBenchmark->Stop("Track follower");
548 if(fDoNonVertex)
549 fTracker->NonVertexTracking();//Do a second pass for nonvertex tracks
550 fBenchmark->Start("Sector track fitting");
551 fTracker->FillTracks();
552 fBenchmark->Stop("Sector track fitting");
553
554 if(fWriteOut)
555 WriteSpacePoints(npoints, points, slice, patch); //do after Tracking
556
557 //free memory
558 if(UseCF)
559 memory->Free();
560 else
561 fFileHandler->Free();
562
563 UInt_t ntracks0 =0;
564 AliHLTTPCTrackSegmentData *trackdata0 =
565 (AliHLTTPCTrackSegmentData *) memory->Allocate(fTracker->GetTracks());
566 memory->TrackArray2Memory(ntracks0,trackdata0,fTracker->GetTracks());
567
568 //write tracks
569 if(fWriteOut){
570 if(fNPatch==1)
571 sprintf(name,"%s/tracks_tr_%d_%d_%d.raw",fWriteOutPath,fEvent,slice,-1);
572 else
573 sprintf(name,"%s/tracks_tr_%d_%d_%d.raw",fWriteOutPath,fEvent,slice,patch);
574 memory->SetBinaryOutput(name);
575 memory->Memory2Binary(ntracks0,trackdata0);
576 memory->CloseBinaryOutput();
577 }
578
579 fInterMerger->Reset();
580 fInterMerger->Init(fRow[patch],patch);
581
582 fInterMerger->FillTracks(ntracks0,trackdata0);
583
584 //fBenchmark->Start("Inter Merger");
585 // fInterMerger->Merge();
586 // fInterMerger->SlowMerge();
587
588 //fBenchmark->Stop("Inter Merger");
589 /*
590 //write inter merged tracks
591 if(fWriteOut){
592 sprintf(name,"%stracks_im_%d_%d.raw",fWriteOutPath,slice,patch);
593 WriteTracks(name,fInterMerger,'i'); //write output of intermerger
594 }
595 */
596 memory->Free();
597
598 UInt_t ntracks1 =0;
599 AliHLTTPCTrackSegmentData *trackdata1 =
600 (AliHLTTPCTrackSegmentData *) memory->Allocate(fInterMerger->GetInTracks(0));
601 memory->TrackArray2Memory(ntracks1,trackdata1,fInterMerger->GetInTracks(0));
602
603 fTrackMerger->InitSector(slice,patch);
604 fTrackMerger->FillTracks(ntracks1,trackdata1);
605
606 memory->Free();
607 }
608 //fBenchmark->Start("Patch Merger");
609 //fTrackMerger->SlowMerge();
610 fTrackMerger->AddAllTracks();
611 //fTrackMerger->Merge();
612 //fBenchmark->Stop("Patch Merger");
613 /*
614 //write merged tracks
615 if(fWriteOut){
616 sprintf(name,"%stracks_tm_%d.raw",fWriteOutPath,slice);
617 WriteTracks(name,fTrackMerger,'o'); //write output of trackmerger
618 }
619 */
620 fTrackData = (AliHLTTPCTrackSegmentData *)
621 fFileHandler->Allocate(fTrackMerger->GetOutTracks());
622
623 fFileHandler->TrackArray2Memory(fNTrackData,fTrackData,
624 fTrackMerger->GetOutTracks());
625
626 delete memory;
627}
628
629void AliHLTTPC::FitGlobalTracks()
630{
631 //fit global tracks
632 AliHLTTPCFitter *fitter = new AliHLTTPCFitter(fVertex,AliHLTTPC::DoVertexFit());
633 if(fNPatch==1)
634 fitter->LoadClusters(fWriteOutPath,fEvent,kTRUE);
635 else
636 fitter->LoadClusters(fWriteOutPath,fEvent,kFALSE);
637
638 fBenchmark->Start("Global track fitter");
639 AliHLTTPCTrackArray *tracks = fGlobalMerger->GetOutTracks();
640 for(Int_t i=0; i<tracks->GetNTracks(); i++)
641 {
642 AliHLTTPCTrack *tr = tracks->GetCheckedTrack(i);
643 if(!tr) continue;
644 fitter->FitHelix(tr);
645 tr->UpdateToFirstPoint();
646 }
647 fBenchmark->Stop("Global track fitter");
648 delete fitter;
649}
650
651void AliHLTTPC::WriteSpacePoints(UInt_t npoints,AliHLTTPCSpacePointData *points,
652 Int_t slice,Int_t patch) const
653{
654 //write space points
655 char name[256];
656 if(fNPatch==1)
657 sprintf(name,"%s/points_%d_%d_%d.raw",fWriteOutPath,fEvent,slice,-1);
658 else
659 sprintf(name,"%s/points_%d_%d_%d.raw",fWriteOutPath,fEvent,slice,patch);
660 AliHLTTPCMemHandler * memory = new AliHLTTPCMemHandler();
661 memory->SetBinaryOutput(name);
662 memory->Transform(npoints,points,slice);
663 memory->Memory2Binary(npoints,points);
664 memory->CloseBinaryOutput();
665 delete memory;
666}
667
668Int_t AliHLTTPC::WriteTracks(char *filename,AliHLTTPCMerger *merger,char opt) const
669{
670 //write tracks
671 AliHLTTPCMemHandler *memory = new AliHLTTPCMemHandler();
672 memory->SetBinaryOutput(filename);
673 if(opt=='a'||opt=='i'){ //add intracks
674 for(Int_t i=0;i<merger->GetNIn();i++){
675 AliHLTTPCTrackArray *tr=merger->GetInTracks(i);
676 memory->TrackArray2Binary(tr);
677 }
678 }
679
680 if(opt=='o'||opt=='a'){
681 AliHLTTPCTrackArray *tr=merger->GetOutTracks();
682 memory->TrackArray2Binary(tr);
683 }
684
685 memory->CloseBinaryOutput();
686 delete memory;
687 return 1;
688}
689
690void AliHLTTPC::WriteResults()
691{
692 //Write the resulting tracks to outputfile
693 Char_t fname[256];
694 sprintf(fname,"%s/tracks_%d.raw",fWriteOutPath,fEvent);
695 WriteTracks(fname,fGlobalMerger,'a');
696 //WriteTracks("tracks.raw",fGlobalMerger,'a');
697 sprintf(fname,"%s/tracks_gl_%d.raw",fWriteOutPath,fEvent);
698 WriteTracks(fname,fGlobalMerger,'o');
699 //WriteTracks("tracks_gl.raw",fGlobalMerger,'o');
700}