default required tracklenght set from 60 to 50 hits (Kenneth, Gaute)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCSliceTrackerComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8  *                  Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
9  *                  for The ALICE HLT Project.                            *
10  *                                                                        *
11  * Permission to use, copy, modify and distribute this software and its   *
12  * documentation strictly for non-commercial purposes is hereby granted   *
13  * without fee, provided that the above copyright notice appears in all   *
14  * copies and that both the copyright notice and this permission notice   *
15  * appear in the supporting documentation. The authors make no claims     *
16  * about the suitability of this software for any purpose. It is          *
17  * provided "as is" without express or implied warranty.                  *
18  **************************************************************************/
19
20 /** @file   AliHLTTPCSliceTrackerComponent.cxx
21     @author Timm Steinbeck, Matthias Richter
22     @date   
23     @brief  The TPC conformal mapping tracker component.
24 */
25
26 #if __GNUC__>= 3
27 using namespace std;
28 #endif
29
30 #include "AliHLTTPCSliceTrackerComponent.h"
31 #include "AliHLTTPCTransform.h"
32 #include "AliHLTTPCConfMapper.h"
33 #include "AliHLTTPCVertex.h"
34 #include "AliHLTTPCVertexData.h"
35 #include "AliHLTTPCClusterDataFormat.h"
36 #include "AliHLTTPCTransform.h"
37 #include "AliHLTTPCTrackSegmentData.h"
38 #include "AliHLTTPCTrackArray.h"
39 #include "AliHLTTPCTrackletDataFormat.h"
40 #include "AliHLTTPCInterMerger.h"
41 #include "AliHLTTPCMemHandler.h"
42 #include "AliHLTTPCDefinitions.h"
43 //#include "AliHLTTPC.h"
44 //#include <stdlib.h>
45 //#include <cerrno>
46
47 // this is a global object used for automatic component registration, do not use this
48 AliHLTTPCSliceTrackerComponent gAliHLTTPCSliceTrackerComponent;
49
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTTPCSliceTrackerComponent)
52
53 AliHLTTPCSliceTrackerComponent::AliHLTTPCSliceTrackerComponent()
54   :
55   fTracker(NULL),
56   fVertex(NULL),
57   fDoNonVertex(false),
58   fDoPP(false),
59   fMultiplicity(4000),
60   fBField(0.4),
61   fnonvertextracking(kFALSE),
62   fmainvertextracking(kTRUE),
63   fpInterMerger(NULL)
64 {
65   // see header file for class documentation
66   // or
67   // refer to README to build package
68   // or
69   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70   fEta[0] = 0.;
71   fEta[1] = 1.1;
72 }
73
74 AliHLTTPCSliceTrackerComponent::AliHLTTPCSliceTrackerComponent(const AliHLTTPCSliceTrackerComponent& src)
75   :
76   fTracker(NULL),
77   fVertex(NULL),
78   fDoNonVertex(false),
79   fDoPP(false),
80   fMultiplicity(4000),
81   fBField(0.4),
82   fnonvertextracking(kFALSE),
83   fmainvertextracking(kTRUE),
84   fpInterMerger(NULL)
85 {
86   // see header file for class documentation
87   HLTFatal("copy constructor untested");
88 }
89
90 AliHLTTPCSliceTrackerComponent& AliHLTTPCSliceTrackerComponent::operator=(const AliHLTTPCSliceTrackerComponent& src)
91
92   // see header file for class documentation
93   HLTFatal("assignment operator untested");
94   return *this;
95 }
96
97 AliHLTTPCSliceTrackerComponent::~AliHLTTPCSliceTrackerComponent()
98 {
99   // see header file for class documentation
100 }
101
102 // Public functions to implement AliHLTComponent's interface.
103 // These functions are required for the registration process
104
105 const char* AliHLTTPCSliceTrackerComponent::GetComponentID()
106 {
107   // see header file for class documentation
108
109   return "TPCSliceTracker";
110 }
111
112 void AliHLTTPCSliceTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
113 {
114   // see header file for class documentation
115   list.clear();
116   list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
117   list.push_back( AliHLTTPCDefinitions::fgkVertexDataType );
118 }
119
120 AliHLTComponentDataType AliHLTTPCSliceTrackerComponent::GetOutputDataType()
121 {
122   // see header file for class documentation
123   return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
124 }
125
126 void AliHLTTPCSliceTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
127 {
128   // see header file for class documentation
129   // XXX TODO: Find more realistic values.
130   constBase = 0;
131   inputMultiplier = 0.2;
132 }
133
134 AliHLTComponent* AliHLTTPCSliceTrackerComponent::Spawn()
135 {
136   // see header file for class documentation
137   return new AliHLTTPCSliceTrackerComponent;
138 }
139
140 void AliHLTTPCSliceTrackerComponent::SetTrackerParam(Int_t phiSegments, Int_t etaSegments,
141                                    Int_t trackletlength, Int_t tracklength,
142                                    Int_t rowscopetracklet, Int_t rowscopetrack,
143                                    Double_t minPtFit, Double_t maxangle,
144                                    Double_t goodDist, Double_t hitChi2Cut,
145                                    Double_t goodHitChi2, Double_t trackChi2Cut,
146                                    Int_t maxdist, Double_t maxphi,Double_t maxeta, bool vertexConstraints )
147     {
148   // see header file for class documentation
149     //fTracker->SetClusterFinderParam( fXYClusterError, fZClusterError, kTRUE ); // ??
150     //Set parameters input to the tracker
151     //If no arguments are given, default parameters will be used
152     
153     fTracker->SetNSegments(phiSegments,etaSegments);
154     fTracker->SetMaxDca(minPtFit);
155     //   fTracker->MainVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack);
156
157     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "==============================" );
158
159     if ( fmainvertextracking == kTRUE && fnonvertextracking == kFALSE){
160         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kTRUE);
161         fTracker->SetTrackletCuts(maxangle,goodDist,kTRUE);
162
163         fTracker->MainVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack, maxphi, maxeta);    
164         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "MAINVERTEXTRACKING" );
165     }
166     else if ( fmainvertextracking == kTRUE && fnonvertextracking == kTRUE){
167         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kTRUE);
168         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kFALSE);
169         fTracker->SetTrackletCuts(maxangle,goodDist,kTRUE);
170         fTracker->SetTrackletCuts(maxangle,goodDist,kFALSE);
171
172         fTracker->MainVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack, maxphi, maxeta);
173         fTracker->NonVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack);     
174         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "MAINVERTEXTRACKING - NONVERTEXTRACKING" );
175     }
176     else if ( fmainvertextracking == kFALSE && fnonvertextracking == kTRUE){
177         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kFALSE);
178         fTracker->SetTrackletCuts(maxangle,goodDist,kFALSE);
179
180         fTracker->NonVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack);
181         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "NONVERTEXTRACKING" );
182     }
183     
184     //fTracker->SetParamDone(true);
185     /* Matthias 13.12.2006
186      * the global variable AliHLTTPCS::fgDoVertexFit has never been used so far
187      * and has always been kTRUE.
188      * In order to remove the AliHLTTPC class (which is the old steering class for
189      * HLT (TPC) tracking) from the compilation, this function can not be activated
190      * again. We have to think about a more elegant way to specify the parameters
191      * anyway. The following line was surely for some testing, but was never active
192      * in a tested release.
193      */
194     //AliHLTTPC::SetVertexFit( kFALSE );
195     
196     fTracker->InitVolumes();
197     }
198
199 void AliHLTTPCSliceTrackerComponent::SetTrackerParam( bool doPP, int multiplicity, double bField )
200     {
201     AliHLTTPCTransform::SetBField( bField );
202     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "BField", "Setting b field to %f T\n", bField );
203
204     if ( doPP )
205         {
206         //tracker->SetClusterFinderParam(xyerror,zerror,kTRUE); // ??
207         /* the old setup used during TPC
208         SetTrackerParam( 50, 100, 3, 10,
209                          2, 2,
210                          0, 0.1745, 5, 100,
211                          5, 50, 50, 0.1, 0.1, kTRUE);
212         */
213           SetTrackerParam( 50,        // phi_segments:     Devide the space into phi_segments                                      
214                            100,       // ets_segments:     Devide the space into eta_segments                                       
215                            3,         // trackletlength:   Number of hits a tracklet has to have                                   
216                            50,         // tracklength:      Number of hits a track has to have                                      
217                            60,         // tracklength:      Number of hits a track has to have                                      
218                            6,         // rowscopetracklet: Search range of rows for a tracklet                                     
219                            6,         // rowscopetrack:    Search range of rows for a track                                       
220                            0,         // min_pt_fit:       Cut for moment fit, use:SetMaxDca(min_pt_fit)                           
221                            AliHLTTPCTransform::Deg2Rad(10),
222                            // maxangle:         AliHLTTPCTransform::Deg2Rad(10), max angle for the three point look aheand         
223                            5,         // goodDist:         Threshold distancs between two hits when building tracklets             
224                            100,        // hitChi2Cut:       Max chi2 of added hit to track                                         
225                            5,         // goodHitChi2:      Stop looking for next hit to add if chi2 is less then goodHitChi2       
226                            50,        // trackChi2Cut:     Max chi2 for track after final fit                                      
227                            50,        // maxdist:          Maximum distance between two clusters when forming segments             
228                            0.1,       // maxphi:           Max phi difference for neighboring hits                                
229                            0.1,       // maxeta:           Max eta difference for neighboring hits                                 
230                            kTRUE);    // vertexConstrain:  False if one want to look for secondary vertex track           
231         }
232     else
233         {
234         int mults[] = { 1000, 2000, 4000, 8000 };
235         int multCount = 4;
236         int closestMult = 0;
237         int i;
238         int multDist, tmpMultDist;
239         if ( multiplicity>mults[closestMult] )
240             multDist = multiplicity-mults[closestMult];
241         else
242             multDist = mults[closestMult]-multiplicity;
243         for ( i = 1; i < multCount; i++ )
244             {
245             if ( multiplicity>mults[i] )
246                 tmpMultDist = multiplicity-mults[i];
247             else
248                 tmpMultDist = mults[i]-multiplicity;
249             if ( tmpMultDist < multDist )
250                 {
251                 closestMult = i;
252                 multDist = tmpMultDist;
253                 }
254             }
255         
256         double bfs[] = { 0.2, 0.4 };
257         int bfCount = 2;
258         int closestBf = 0;
259         double bfDist, tmpBFDist;
260         if ( bField>bfs[closestBf] )
261             bfDist = bField-bfs[closestBf];
262         else
263             bfDist = bfs[closestBf]-bField;
264         for ( i = 1; i < bfCount; i++ )
265             {
266             if ( bField>bfs[i] )
267                 tmpBFDist = bField-bfs[i];
268             else
269                 tmpBFDist = bfs[i]-bField;
270             if ( tmpBFDist < bfDist )
271                 {
272                 closestBf = i;
273                 bfDist = tmpBFDist;
274                 }
275             }
276
277         switch ( closestMult )
278             {
279             case 0: // 1000
280                 switch ( closestBf )
281                     {
282                     case 0: // 0.2
283                         SetTrackerParam( 50, 100, 3, 10,
284                                         2, 4,
285                                         0, 0.1745, 5, 100,
286                                         5, 50, 50, 0.1, 0.1, kTRUE );
287                         break;
288                     case 1: // 0.4
289                         SetTrackerParam( 50, 100, 3, 10,
290                                          2, 4,
291                                          0, 0.1745, 5, 100,
292                                          5, 50, 50, 0.1, 0.1, kTRUE );
293                         break;
294                     }
295                 break;
296             case 1: // 2000
297                 switch ( closestBf )
298                     {
299                     case 0: // 0.2
300                         SetTrackerParam( 50, 100, 3, 10,
301                                          2, 4,
302                                          0, 0.1745, 5, 30,
303                                          5, 20, 50, 0.1, 0.1, kTRUE );
304                         break;
305                     case 1: // 0.4
306                         SetTrackerParam( 50, 100, 3, 10,
307                                          2, 5,
308                                          0, 0.1745, 5, 30,
309                                          5, 20, 50, 0.1, 0.1, kTRUE );
310                         break;
311                     }
312                 break;
313             case 2: // 4000
314                 switch ( closestBf )
315                     {
316                     case 0: // 0.2
317                         SetTrackerParam( 50, 100, 3, 10,
318                                          2 , 10,
319                                          0, 0.1745, 5, 20,
320                                          5, 10 , 50, 0.1, 0.1, kTRUE );
321                         break;
322                     case 1: // 0.4
323                         SetTrackerParam( 50, 100, 3, 10,
324                                          2, 10,
325                                          0, 0.1745, 5, 20,
326                                          5, 10, 50, 0.1, 0.1, kTRUE );
327                         break;
328                     }
329                 break;
330             case 3: // 8000
331                 switch ( closestBf )
332                     {
333                     case 0: // 0.2
334                         SetTrackerParam( 50, 100, 3, 10,
335                                          3, 15,
336                                          0, 0.1745, 5, 10,
337                                          5, 5, 50, 0.1, 0.1, kTRUE );
338                         break;
339                     case 1: // 0.4
340                         SetTrackerParam( 50, 100, 3, 10,
341                                          2, 15,
342                                          0, 0.1745, 5, 15,
343                                          5, 5, 50, 0.1, 0.1, kTRUE );
344                         break;
345                     }
346                 break;
347             }
348 //      Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "BField", "Setting b field to %f\n", bfs[closestBf] );
349 //      AliHLTTPCTransform::SetBField( bfs[closestBf] );
350 //      AliHLTTPCTransform::SetBField( bField );
351 //      Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "BField", "Setting b field to %f\n", bField );
352         }
353     }
354
355
356         
357 int AliHLTTPCSliceTrackerComponent::DoInit( int argc, const char** argv )
358     {
359   // see header file for class documentation
360     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
361
362     if ( fTracker || fVertex )
363         return EINPROGRESS;
364     fTracker = new AliHLTTPCConfMapper();
365     fVertex = new AliHLTTPCVertex();
366     fEta[0] = 0.;
367     fEta[1] = 1.1;
368     fDoNonVertex = false;
369     Bool_t bDoMerger=kTRUE;
370     fMultiplicity = 4000;
371     fBField = 0.4;
372     fDoPP = false;
373
374     int i = 0;
375     char* cpErr;
376     while ( i < argc )
377         {
378         if ( !strcmp( argv[i], "disable-merger" ) ){
379             bDoMerger = kFALSE;
380             i++;
381             continue;       
382         }
383
384         if ( !strcmp( argv[i], "pp-run" ) )
385             {
386             fDoPP = true;
387             i++;
388             continue;
389             }
390         if ( !strcmp( argv[i], "multiplicity" ) )
391             {
392             if ( argc <= i+1 )
393                 {
394                 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Missing event multiplicity specifier." );
395                 return ENOTSUP;
396                 }
397             fMultiplicity = strtoul( argv[i+1], &cpErr, 0 );
398             if ( *cpErr )
399                 {
400                 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert event multiplicity specifier '%s'.", argv[i+1] );
401                 return EINVAL;
402                 }
403             i += 2;
404             continue;
405             }
406         if ( !strcmp( argv[i], "bfield" ) )
407             {
408             if ( argc <= i+1 )
409                 {
410                 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing B-field", "Missing B-field specifier." );
411                 return ENOTSUP;
412                 }
413             fBField = strtod( argv[i+1], &cpErr );
414             if ( *cpErr )
415                 {
416                 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
417                 return EINVAL;
418                 }
419             i += 2;
420             continue;
421             }
422
423         if ( !strcmp( argv[i], "nonvertextracking" ) ){
424           fnonvertextracking = kTRUE;
425           i++;
426           continue;         
427         }
428         
429         if ( !strcmp( argv[i], "mainvertextrackingoff" ) ){     
430           fmainvertextracking = kFALSE;
431           i++;
432           continue;         
433         }
434         
435         if ( !strcmp( argv[i], "etarange" ) ){  
436           if ( argc <= i+1 ){
437             Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing Eta range", "Missing Eta-range specifiers." );
438             return ENOTSUP;
439           }
440           fEta[1] = strtod( argv[i+1], &cpErr );
441           if ( *cpErr ){
442             Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing Eta range", "Cannot convert Eta-range specifier '%s'.", argv[i+1] );
443             return EINVAL;
444           }
445           
446           i += 2;
447           continue;
448         }
449         Logging(kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
450         return EINVAL;
451         }
452     if (fBField == 0.){
453       // parameter for B=0 T 
454       fDoPP = kTRUE;
455       fnonvertextracking = kTRUE;
456       fmainvertextracking = kFALSE;
457     }
458         
459     if (bDoMerger)
460       fpInterMerger = new AliHLTTPCInterMerger();
461
462     SetTrackerParam( fDoPP, fMultiplicity, fBField );
463     return 0;
464     }
465
466 int AliHLTTPCSliceTrackerComponent::DoDeinit()
467 {
468   // see header file for class documentation
469   if ( fTracker )
470     delete fTracker;
471   fTracker = NULL;
472   if ( fVertex )
473     delete fVertex;
474   fVertex = NULL;
475   if (fpInterMerger) {
476     delete fpInterMerger;
477   }
478   fpInterMerger=NULL;
479   return 0;
480 }
481
482 int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
483                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
484                                               AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
485     {
486   // see header file for class documentation
487     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "DoEvent", "DoEvent()" );
488     if ( evtData.fBlockCnt<=0 )
489       {
490         Logging( kHLTLogWarning, "HLT::TPCSliceTracker::DoEvent", "DoEvent", "no blocks in event" );
491         return 0;
492       }
493     const AliHLTComponentBlockData* iter = NULL;
494     unsigned long ndx;
495     AliHLTTPCClusterData* inPtrSP;
496     AliHLTTPCVertexData* inPtrV = NULL;
497     const AliHLTComponentBlockData* vertexIter=NULL;
498     AliHLTTPCTrackletData* outPtr;
499     AliHLTUInt8_t* outBPtr;
500     AliHLTUInt32_t vSize = 0;
501     UInt_t offset=0, mysize, tSize = 0;
502     outBPtr = outputPtr;
503     Int_t slice=-1, patch=-1, row[2];
504     Int_t minPatch=INT_MAX, maxPatch = 0;
505     offset = 0;
506     std::vector<Int_t> slices;
507     std::vector<Int_t>::iterator slIter, slEnd;
508     std::vector<unsigned> sliceCnts;
509     std::vector<unsigned>::iterator slCntIter;
510     Int_t vertexSlice=-1;
511
512     // Find min/max rows used in total and find and read out vertex if it is present
513     // also determine correct slice number, if multiple slice numbers are present in event
514     // (which should not happen in the first place) we use the one that occurs the most times
515     row[0] = 0;
516     row[1] = 0;
517     bool found;
518     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
519         {
520         iter = blocks+ndx;
521
522         slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
523         found = false;
524         slIter = slices.begin();
525         slEnd = slices.end();
526         slCntIter = sliceCnts.begin();
527         while ( slIter != slEnd )
528             {
529             if ( *slIter == slice )
530                 {
531                 found = true;
532                 break;
533                 }
534             slIter++;
535             slCntIter++;
536             }
537         if ( !found )
538             {
539             slices.insert( slices.end(), slice );
540             sliceCnts.insert( sliceCnts.end(), 1 );
541             }
542         else
543             *slCntIter++;
544
545         if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType )
546             {
547             inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
548             vertexIter = iter;
549             vSize = iter->fSize;
550             fVertex->Read( inPtrV );
551             vertexSlice = slice;
552             }
553         if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
554             {
555             patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
556             if ( minPatch>patch )
557                 {
558                 minPatch = patch;
559                 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
560                 }
561             if ( maxPatch<patch )
562                 {
563                 maxPatch = patch;
564                 row[1] = AliHLTTPCTransform::GetLastRow( patch );
565                 }
566             }
567         }
568
569     // Determine slice number to really use.
570     if ( slices.size()>1 )
571         {
572         Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
573                  "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
574                  evtData.fEventID, evtData.fEventID );
575         unsigned maxCntSlice=0;
576         slIter = slices.begin();
577         slEnd = slices.end();
578         slCntIter = sliceCnts.begin();
579         while ( slIter != slEnd )
580             {
581             Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
582                      "Slice %lu found %lu times.", *slIter, *slCntIter );
583             if ( maxCntSlice<*slCntIter )
584                 {
585                 maxCntSlice = *slCntIter;
586                 slice = *slIter;
587                 }
588             slIter++;
589             slCntIter++;
590             }
591         Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
592                  "Using slice %lu.", slice );
593         }
594     else if ( slices.size()>0 )
595       {
596         slice = *(slices.begin());
597       }
598     else
599       {
600         slice = -1;
601       }
602     
603     if ( vertexSlice != slice )
604         {
605         // multiple vertex blocks in event and we used the wrong one...
606         found = false;
607         for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
608             {
609             iter = blocks+ndx;
610             if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
611                 {
612                 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
613                 vertexIter = iter;
614                 vSize = iter->fSize;
615                 fVertex->Read( inPtrV );
616                 break;
617                 }
618             }
619         }
620
621     fTracker->InitSector( slice, row, fEta );
622     fTracker->SetVertex(fVertex);
623     mysize = 0;
624     // read in all hits
625     std::vector<unsigned long> patchIndices;
626     std::vector<unsigned long>::iterator pIter, pEnd;
627     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
628         {
629         iter = blocks+ndx;
630
631         if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
632             {
633             patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
634             pIter = patchIndices.begin();
635             pEnd = patchIndices.end();
636             while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
637                 pIter++;
638             patchIndices.insert( pIter, ndx );
639             }
640         }
641     pIter = patchIndices.begin();
642     pEnd = patchIndices.end();
643     while ( pIter!=pEnd )
644         {
645         ndx = *pIter;
646         iter = blocks+ndx;
647
648         patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
649         inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
650             
651         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
652                  "Reading hits for slice %d - patch %d", slice, patch );
653         fTracker->ReadHits( inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
654         pIter++;
655         }
656
657     outPtr = (AliHLTTPCTrackletData*)(outBPtr);
658
659     if ( fmainvertextracking == kTRUE && fnonvertextracking == kFALSE){ 
660       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---MAINVERTEXTRACKING---");
661       fTracker->MainVertexTrackingA();
662       fTracker->MainVertexTrackingB();
663       fTracker->FillTracks();
664     }
665     else if ( fmainvertextracking == kTRUE && fnonvertextracking == kTRUE){     
666       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---MAINVERTEXTRACKING---");
667       fTracker->MainVertexTrackingA();
668       fTracker->MainVertexTrackingB();
669       fTracker->FillTracks();   
670       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---NONVERTEXTRACKING---");
671       fTracker->NonVertexTracking();
672     }
673     else if ( fmainvertextracking == kFALSE && fnonvertextracking == kTRUE){
674       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---NONVERTEXTRACKING---");
675       fTracker->NonVertexTracking();    
676       fTracker->FillTracks();   
677     }
678
679     UInt_t ntracks0 =0;
680     if(fpInterMerger){
681       AliHLTTPCMemHandler memory;
682       AliHLTTPCTrackSegmentData *trackdata0  = 
683         (AliHLTTPCTrackSegmentData *) memory.Allocate(fTracker->GetTracks());
684       memory.TrackArray2Memory(ntracks0,trackdata0,fTracker->GetTracks());
685       fpInterMerger->Reset();
686       fpInterMerger->Init(row,patch);
687       fpInterMerger->FillTracks(ntracks0,trackdata0);
688       fpInterMerger->Merge();
689     } 
690     ntracks0=0;
691     AliHLTTPCTrackArray* pArray=fTracker->GetTracks();
692     mysize = pArray->WriteTracks( ntracks0, outPtr->fTracklets );
693     outPtr->fTrackletCnt = ntracks0;
694
695     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
696              "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.", 
697              ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
698
699     tSize += mysize+sizeof(AliHLTTPCTrackletData);
700     outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
701     
702     AliHLTComponentBlockData bd;
703     FillBlockData( bd );
704     bd.fOffset = offset;
705     bd.fSize = tSize;
706     bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
707     outputBlocks.push_back( bd );
708
709 #ifdef FORWARD_VERTEX_BLOCK
710     if ( vertexIter )
711         {
712         // Copy the descriptor block for the vertex information.
713         bd = *vertexIter;
714         outputBlocks.push_back( bd );
715         }
716 #endif // FORWARD_VERTEX_BLOCK
717
718     size = tSize;
719     return 0;
720     }
721
722 void AliHLTTPCSliceTrackerComponent::SetTrackerParam1()
723 {
724   SetTrackerParam( 10, 20, 5, 10, 2,2,
725                    0, 1.31, 5, 100,
726                    50, 100, 50, 0.1, 0.1,
727                    true );
728 }
729
730