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