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