Added support for NEWIO, merged cern-hlt tree, updated to latest track candidate...
[u/mrichter/AliRoot.git] / HLT / src / AliLevel3.cxx
CommitLineData
3e87ef69 1// @(#) $Id$
532bd2d0 2
3e87ef69 3// Author: Anders Vestbo <mailto:vestbo@fi.uib.no>, Uli Frankenfeld <mailto:franken@fi.uib.no>
4//*-- Copyright &copy ALICE HLT Group
108615fc 5
118c26c3 6#include "AliL3StandardIncludes.h"
7
73d9267f 8#ifndef no_root
108615fc 9#include <TFile.h>
10#include <TDirectory.h>
11#include <TClonesArray.h>
12#include <TStopwatch.h>
73d9267f 13#endif
108615fc 14
2e1fe9ef 15#include "AliL3Logging.h"
108615fc 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"
f3e63a47 26#include "AliL3ClustFinderNew.h"
108615fc 27#include "AliL3DigitData.h"
28#include "AliL3TrackArray.h"
29#include "AliL3MemHandler.h"
3e87ef69 30#include "AliL3Fitter.h"
2e1fe9ef 31#ifdef use_aliroot
108615fc 32#include "AliL3FileHandler.h"
2e1fe9ef 33#endif
108615fc 34#include "AliL3Benchmark.h"
108615fc 35#include "AliL3DigitData.h"
36#include "AliL3TrackSegmentData.h"
37#include "AliL3SpacePointData.h"
38#include "AliL3VertexData.h"
b2a02bce 39#include "AliL3DDLDataFileHandler.h"
108615fc 40
3e87ef69 41/** \class AliLevel3
42<pre>
82bd465a 43//_____________________________________________________________
108615fc 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);
3e87ef69 53// level3->SetTrackerParam(); //Sets default tracking parameters
108615fc 54// level3->ProcessSector(2,2); //Does tracking on sector 2 (actually 2+38)
3e87ef69 55//Begin_Html
56//<img src="tpcsectorsnb.gif">
82bd465a 57//End_Html
3e87ef69 58</pre>
59*/
108615fc 60
61ClassImp(AliLevel3)
62
f59eed2d 63AliLevel3::AliLevel3()
64{
108615fc 65 fInputFile=0;
108615fc 66}
67
73d9267f 68#ifdef no_root
69AliLevel3::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
f59eed2d 83AliLevel3::AliLevel3(Char_t *infile)
84{
108615fc 85 //Constructor. Calls constructor of the tracker, vertexfinder and merger classes.
108615fc 86
a27af97b 87 fInputFile = infile;
b2a02bce 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
108615fc 99}
73d9267f 100#endif
108615fc 101
b2a02bce 102#ifdef nonono_root
103AliLevel3::AliLevel3(TFile *in)
f59eed2d 104{
b2a02bce 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
02f030e3 120
b2a02bce 121void AliLevel3::Init(Char_t *path,EFileType filetype,Int_t npatches)
122{
a27af97b 123 if((filetype!=kBinary) && !fInputFile)
f59eed2d 124 {
125 LOG(AliL3Log::kError,"AliLevel3::Init","Files")
126 <<"You have not supplied the input rootfile; use the appropriate ctor!"<<ENDLOG;
127 return;
128 }
494fad94 129
108615fc 130 fWriteOut = kFALSE;
3e87ef69 131 fPileUp = kFALSE;
132 fNoCF=kFALSE;
a27af97b 133 fUseBinary = (filetype==kBinary);
eeddc64d 134 SetPath(path);
3e87ef69 135
108615fc 136 fDoRoi = kFALSE;
532bd2d0 137 fDoNonVertex = kFALSE;
eeddc64d 138 fFindVertex = kFALSE;
139 SetClusterFinderParam();
140
697056ae 141 fEta[0] = 0.;
e968605e 142 fEta[1] = 1.1;
eeddc64d 143
532bd2d0 144 fEvent=0;
986840b3 145
146 switch(npatches){
3e87ef69 147 case 0:
148 fNPatch = 1;
149 fRow[0][0] = AliL3Transform::GetFirstRow(3);
150 fRow[0][1] = AliL3Transform::GetLastRow(5);
151 break;
986840b3 152 case 1:
153 fNPatch = 1; //number of patches change row in process
68a27388 154 fRow[0][0] = 0;
3e87ef69 155 fRow[0][1] = AliL3Transform::GetLastRow(-1);
986840b3 156 break;
157 case 2:
158 fNPatch = 2; //number of patches change row in process
21896bc6 159 fRow[0][0] = 0; // first row
68a27388 160 fRow[0][1] = AliL3Transform::GetLastRow(1);
161 fRow[1][0] = AliL3Transform::GetFirstRow(2);
162 fRow[1][1] = AliL3Transform::GetLastRow(5);
986840b3 163 break;
68a27388 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);
88d19ba2 178 }
986840b3 179
108615fc 180 fVertexFinder = new AliL3VertexFinder();
181 fVertex = new AliL3Vertex();
182 fTracker = new AliL3ConfMapper();
183 fTrackMerger = new AliL3TrackMerger(fNPatch);
184 fInterMerger = new AliL3InterMerger();
0a86fbb7 185 fGlobalMerger = new AliL3GlobalMerger();
186 SetMergerParameters();//Set default merger parameters
f59eed2d 187#ifdef use_aliroot
a27af97b 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 }
f59eed2d 197#else
b2a02bce 198 if(filetype==kRaw){
199 fFileHandler = new AliL3DDLDataFileHandler();
200 fFileHandler->SetReaderInput(fInputFile);
201 }else{
202 fFileHandler = new AliL3MemHandler();
203 }
f59eed2d 204#endif
108615fc 205 fBenchmark = new AliL3Benchmark();
206}
207
208void AliLevel3::DoBench(char* name){
209 fBenchmark->Analyze(name);
3e87ef69 210 delete fBenchmark;
211 fBenchmark = new AliL3Benchmark();
108615fc 212}
213
214void AliLevel3::DoMc(char* file){
82bd465a 215#ifdef use_aliroot
68a27388 216 if(!fFileHandler->IsDigit(fEvent))
108615fc 217 fFileHandler->SetMCOutput(file);
82bd465a 218#endif
108615fc 219}
220
221AliLevel3::~AliLevel3(){
222 //Destructor
eeddc64d 223 if(fVertexFinder) delete fVertexFinder;
224 if(fVertex) delete fVertex;
108615fc 225 if(fTracker) delete fTracker;
108615fc 226 if(fTrackMerger) delete fTrackMerger;
227 if(fInterMerger) delete fInterMerger;
228 if(fFileHandler) delete fFileHandler;
0a86fbb7 229 if(fGlobalMerger) delete fGlobalMerger;
108615fc 230}
231
eeddc64d 232void AliLevel3::SetClusterFinderParam(Float_t fXYError, Float_t fZError, Bool_t deconv)
233{
234 fXYClusterError=fXYError;
235 fZClusterError=fZError;
236 fClusterDeconv=deconv;
237}
238
108615fc 239void AliLevel3::SetTrackerParam(Int_t phi_segments, Int_t eta_segments,
83f458e3 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)
108615fc 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);
108615fc 251 fTracker->SetMaxDca(min_pt_fit);
532bd2d0 252 fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,vertexconstraint);
253 fTracker->SetTrackletCuts(maxangle,goodDist,vertexconstraint);
254 if(vertexconstraint)
83f458e3 255 fTracker->MainVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack,maxphi,maxeta);
532bd2d0 256 else
257 fTracker->NonVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack);
4ce675df 258 fTracker->InitVolumes();
108615fc 259}
260
0a86fbb7 261void 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
532bd2d0 266void AliLevel3::ProcessEvent(Int_t first,Int_t last,Int_t event){
108615fc 267 //Do tracking on all slices in region [first,last]
eeddc64d 268 //Slices numbering in TPC goes from 0-35, which means that one slice
108615fc 269 //corresponds to inner+outer sector.E.g. slice 2 corresponds to
270 //inner=2 + outer=38.
0a86fbb7 271
272 fGlobalMerger->Setup(first,last);
532bd2d0 273 fEvent=event;
108615fc 274 for(Int_t i=first; i<=last; i++){
275 ProcessSlice(i);
276 fGlobalMerger->SetVertex(fVertex);
108615fc 277 fGlobalMerger->InitSlice(i);
108615fc 278 fGlobalMerger->FillTracks(fNTrackData,fTrackData);
108615fc 279 fFileHandler->Free(); //free the memory
280 fNTrackData=0;
281 fTrackData=0;
282 }
3e87ef69 283 fBenchmark->Start("Global track merger");
284 //fGlobalMerger->AddAllTracks();
3e87ef69 285 fGlobalMerger->Merge();
0a86fbb7 286 //fGlobalMerger->SlowMerge(fWriteOutPath);
3e87ef69 287 fBenchmark->Stop("Global track merger");
288
289 FitGlobalTracks();
290
108615fc 291 if(fWriteOut) WriteResults();
3e87ef69 292 fFileHandler->FreeDigitsTree();
108615fc 293}
294
295void AliLevel3::ProcessSlice(Int_t slice){
296 char name[256];
91f3257c 297 Bool_t UseCF = kFALSE;
e0ea9951 298#ifdef use_aliroot
68a27388 299 UseCF = fFileHandler->IsDigit(fEvent);
a27af97b 300#endif
95a00d93 301 if(fUseBinary)
b2a02bce 302 UseCF = kTRUE; //In case you are not using aliroot
3e87ef69 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;
108615fc 307 const Int_t pointsize = maxpoints * sizeof(AliL3SpacePointData);
308 AliL3MemHandler *memory = new AliL3MemHandler();
eeddc64d 309
108615fc 310 fTrackMerger->Reset();
e0ea9951 311 fTrackMerger->SetRows(fRow[0]);
e968605e 312
108615fc 313 for(Int_t patch=fNPatch-1;patch>=0;patch--){
eeddc64d 314 fFileHandler->Init(slice,patch,&fRow[patch][0]);
108615fc 315 UInt_t npoints=0;
316 AliL3SpacePointData *points =0;
317 UInt_t ndigits=0;
318 AliL3DigitRowData *digits =0;
91f3257c 319 if(UseCF){
320 if(fUseBinary){
321 if(!fDoRoi){
6e32a12a 322 if(1){ //Binary to Memory
95a00d93 323 fFileHandler->Free();
e968605e 324 if(fNPatch == 1)
3e87ef69 325 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,-1);
e968605e 326 else
3e87ef69 327 sprintf(name,"%sdigits_%d_%d_%d.raw",fPath,fEvent,slice,patch);
95a00d93 328 if(!fFileHandler->SetBinaryInput(name)) return;
3e87ef69 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
e968605e 337 fFileHandler->CloseBinaryInput();
91f3257c 338 }
339
6e32a12a 340 if(0){ //Binary to Memory with Benchmark
3e87ef69 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);
1c5eccbd 346 if(!memory->SetBinaryInput(name)) return;
91f3257c 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
88d19ba2 359 if(0){ //Binary to Memory with Random
91f3257c 360 fFileHandler->Free();
361 fFileHandler->ResetRandom();
362 fFileHandler->SetRandomCluster(100);
363 fFileHandler->SetNGenerate(100);
3e87ef69 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);
1c5eccbd 368 if(!memory->SetBinaryInput(name)) return;
91f3257c 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 }
108615fc 381 }
382
91f3257c 383 else{ //Binary to Memory with Roi
108615fc 384 fFileHandler->Free();
91f3257c 385 Int_t sli[2]={0,0};
386 fFileHandler->SetROI(fEta,sli);
3e87ef69 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);
1c5eccbd 391 if(!memory->SetBinaryInput(name)) return;
108615fc 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");
91f3257c 399 datasize = fFileHandler->CompMemory2Memory(ndigits,digits,comp);
400 fBenchmark->Stop("Unpacker");
108615fc 401 memory->Free();
108615fc 402 }
91f3257c 403 }//end UseBinary
404 else{
2e1fe9ef 405#ifdef use_aliroot
21896bc6 406 fBenchmark->Start("Dummy Unpacker");
3e87ef69 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);
21896bc6 411 fBenchmark->Stop("Dummy Unpacker");
2e1fe9ef 412
02f030e3 413 if(0){ //Ali to Binary
108615fc 414 fFileHandler->SetBinaryOutput(name);
415 fFileHandler->AliDigits2CompBinary();
416 fFileHandler->CloseBinaryOutput();
417 }
418
b2a02bce 419 if(1){ //Ali to Memory
3e87ef69 420 digits=(AliL3DigitRowData *)fFileHandler->AliAltroDigits2Memory(ndigits,fEvent);
02f030e3 421 if(0){ //Memory to Binary
108615fc 422 fFileHandler->SetBinaryOutput(name);
423 fFileHandler->Memory2CompBinary(ndigits,digits);
424 fFileHandler->CloseBinaryOutput();
425 }
426 }
2e1fe9ef 427#endif
91f3257c 428 }//end else UseBinary
108615fc 429
e0ea9951 430 points = (AliL3SpacePointData *) memory->Allocate(pointsize);
494fad94 431 fClusterFinder = new AliL3ClustFinderNew();
eeddc64d 432 fClusterFinder->InitSlice(slice,patch,fRow[patch][0],fRow[patch][1],maxpoints);
532bd2d0 433 fClusterFinder->SetDeconv(fClusterDeconv);
eeddc64d 434 fClusterFinder->SetXYError(fXYClusterError);
435 fClusterFinder->SetZError(fZClusterError);
c3dd27a3 436 if((fXYClusterError>0)&&(fZClusterError>0))
437 fClusterFinder->SetCalcErr(kFALSE);
e0ea9951 438 fClusterFinder->SetOutputArray(points);
3e87ef69 439 fBenchmark->Start("Cluster finder");
e968605e 440 fClusterFinder->Read(ndigits,digits);
e0ea9951 441 fClusterFinder->ProcessDigits();
3e87ef69 442 fBenchmark->Stop("Cluster finder");
e0ea9951 443 npoints = fClusterFinder->GetNumberOfClusters();
444 delete fClusterFinder;
c3dd27a3 445 fClusterFinder = 0;
e0ea9951 446 fFileHandler->Free();
91f3257c 447 LOG(AliL3Log::kInformational,"AliLevel3::ProcessSlice","Cluster Finder")
448 <<AliL3Log::kDec<<"Found "<<npoints<<" Points"<<ENDLOG;
91f3257c 449 }//end UseCF
450 else{// if not use Clusterfinder
451 if(fUseBinary){//Binary to Memory
452 memory->Free();
3e87ef69 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);
1c5eccbd 457 if(!memory->SetBinaryInput(name)) return;
91f3257c 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 }
e0ea9951 464#ifdef use_aliroot
91f3257c 465 else{
466 points = fFileHandler->AliPoints2Memory(npoints);
467 }
e0ea9951 468#endif
91f3257c 469 fBenchmark->Start("Dummy Unpacker");
470 fBenchmark->Stop("Dummy Unpacker");
471 fBenchmark->Start("Dummy CF");
472 fBenchmark->Stop("Dummy CF");
473 }
e0ea9951 474
108615fc 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 }
3e87ef69 497
e968605e 498 fTracker->InitSector(slice,fRow[patch],fEta);
108615fc 499 fTracker->SetVertex(fVertex);
3e87ef69 500 fBenchmark->Start("Tracker setup");
108615fc 501 fTracker->ReadHits(npoints,points);
3e87ef69 502 fTracker->MainVertexTracking_a();
503 fBenchmark->Stop("Tracker setup");
504 fBenchmark->Start("Track follower");
505 fTracker->MainVertexTracking_b();
506 fBenchmark->Stop("Track follower");
532bd2d0 507 if(fDoNonVertex)
508 fTracker->NonVertexTracking();//Do a second pass for nonvertex tracks
3e87ef69 509 fBenchmark->Start("Sector track fitting");
108615fc 510 fTracker->FillTracks();
3e87ef69 511 fBenchmark->Stop("Sector track fitting");
108615fc 512
513 if(fWriteOut)
514 WriteSpacePoints(npoints, points, slice, patch); //do after Tracking
e0ea9951 515
516 //free memory
517 if(UseCF)
518 memory->Free();
519 else
520 fFileHandler->Free();
108615fc 521
522 UInt_t ntracks0 =0;
523 AliL3TrackSegmentData *trackdata0 =
524 (AliL3TrackSegmentData *) memory->Allocate(fTracker->GetTracks());
525 memory->TrackArray2Memory(ntracks0,trackdata0,fTracker->GetTracks());
e968605e 526
108615fc 527 //write tracks
528 if(fWriteOut){
3e87ef69 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);
108615fc 533 memory->SetBinaryOutput(name);
534 memory->Memory2Binary(ntracks0,trackdata0);
535 memory->CloseBinaryOutput();
536 }
e968605e 537
108615fc 538 fInterMerger->Reset();
e0ea9951 539 fInterMerger->Init(fRow[patch],patch);
108615fc 540
108615fc 541 fInterMerger->FillTracks(ntracks0,trackdata0);
4baac26f 542
543 //fBenchmark->Start("Inter Merger");
82bd465a 544 // fInterMerger->Merge();
4baac26f 545 // fInterMerger->SlowMerge();
108615fc 546
4baac26f 547 //fBenchmark->Stop("Inter Merger");
6e32a12a 548 /*
108615fc 549 //write inter merged tracks
550 if(fWriteOut){
6e32a12a 551 sprintf(name,"%stracks_im_%d_%d.raw",fWriteOutPath,slice,patch);
108615fc 552 WriteTracks(name,fInterMerger,'i'); //write output of intermerger
6e32a12a 553 }
554 */
108615fc 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);
108615fc 563 fTrackMerger->FillTracks(ntracks1,trackdata1);
108615fc 564
565 memory->Free();
566 }
3e87ef69 567 //fBenchmark->Start("Patch Merger");
68a27388 568 //fTrackMerger->SlowMerge();
e968605e 569 fTrackMerger->AddAllTracks();
570 //fTrackMerger->Merge();
3e87ef69 571 //fBenchmark->Stop("Patch Merger");
6e32a12a 572 /*
108615fc 573 //write merged tracks
574 if(fWriteOut){
6e32a12a 575 sprintf(name,"%stracks_tm_%d.raw",fWriteOutPath,slice);
108615fc 576 WriteTracks(name,fTrackMerger,'o'); //write output of trackmerger
577 }
6e32a12a 578 */
108615fc 579 fTrackData = (AliL3TrackSegmentData *)
580 fFileHandler->Allocate(fTrackMerger->GetOutTracks());
581
582 fFileHandler->TrackArray2Memory(fNTrackData,fTrackData,
583 fTrackMerger->GetOutTracks());
584
585 delete memory;
586}
587
3e87ef69 588void 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);
0a86fbb7 603 fitter->UpdateTrack(tr);
3e87ef69 604 }
605 fBenchmark->Stop("Global track fitter");
606 delete fitter;
607}
608
108615fc 609void AliLevel3::WriteSpacePoints(UInt_t npoints,AliL3SpacePointData *points,
3e87ef69 610 Int_t slice,Int_t patch)
611{
108615fc 612 char name[256];
3e87ef69 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);
108615fc 617 AliL3MemHandler * memory = new AliL3MemHandler();
618 memory->SetBinaryOutput(name);
c51c6aaa 619 memory->Transform(npoints,points,slice);
108615fc 620 memory->Memory2Binary(npoints,points);
621 memory->CloseBinaryOutput();
622 delete memory;
623}
624
3e87ef69 625Int_t AliLevel3::WriteTracks(char *filename,AliL3Merger *merger,char opt)
626{
2e1fe9ef 627 AliL3MemHandler *memory = new AliL3MemHandler();
108615fc 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
646void AliLevel3::WriteResults()
647{
648 //Write the resulting tracks to outputfile
6e32a12a 649 Char_t fname[256];
3e87ef69 650 sprintf(fname,"%s/tracks_%d.raw",fWriteOutPath,fEvent);
6e32a12a 651 WriteTracks(fname,fGlobalMerger,'a');
652 //WriteTracks("tracks.raw",fGlobalMerger,'a');
3e87ef69 653 sprintf(fname,"%s/tracks_gl_%d.raw",fWriteOutPath,fEvent);
6e32a12a 654 WriteTracks(fname,fGlobalMerger,'o');
655 //WriteTracks("tracks_gl.raw",fGlobalMerger,'o');
108615fc 656}