]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCSliceTrackerComponent.cxx
first steps to set the covariance matrix from the errors calculated in conformal...
[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 // see header file for class documentation
27 // or
28 // refer to README to build package
29 // or
30 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31
32 #if __GNUC__>= 3
33 using namespace std;
34 #endif
35
36 #include <climits>
37 #include "AliHLTTPCSliceTrackerComponent.h"
38 #include "AliHLTTPCTransform.h"
39 #include "AliHLTTPCConfMapper.h"
40 #include "AliHLTTPCVertex.h"
41 #include "AliHLTTPCVertexData.h"
42 #include "AliHLTTPCClusterDataFormat.h"
43 #include "AliHLTTPCTransform.h"
44 #include "AliHLTTPCTrackSegmentData.h"
45 #include "AliHLTTPCTrackArray.h"
46 #include "AliHLTTPCTrackletDataFormat.h"
47 #include "AliHLTTPCInterMerger.h"
48 #include "AliHLTTPCMemHandler.h"
49 #include "AliHLTTPCDefinitions.h"
50 #include "AliHLTCommonCDBEntries.h"
51 #include "TString.h"
52 #include "TObjString.h"
53 #include "TObjArray.h"
54 #include "AliCDBEntry.h"
55 #include "AliCDBManager.h"
56 //#include "AliHLTTPC.h"
57 //#include <stdlib.h>
58 //#include <cerrno>
59
60 /** ROOT macro for the implementation of ROOT specific class methods */
61 ClassImp(AliHLTTPCSliceTrackerComponent)
62
63 AliHLTTPCSliceTrackerComponent::AliHLTTPCSliceTrackerComponent()
64   :
65   fTracker(NULL),
66   fVertex(NULL),
67   fDoNonVertex(false),
68   fDoPP(false),
69   fDoPbPb(false),
70   fMultiplicity(4000),
71   fBField(0.4),
72   fnonvertextracking(kFALSE),
73   fmainvertextracking(kTRUE),
74   fPhisegment(50),
75   fEtasegment(100),
76   fTrackletlength(3),
77   fTracklength(60),
78   fRowscopetracklet(6),
79   fRowscopetrack(6),
80   fMinPtFit(0),
81   fMaxangle(0.1745),
82   fGoodDist(5),
83   fHitChi2Cut(100),
84   fGoodHitChi2(5),
85   fTrackChi2Cut(50),
86   fMaxdist(50),
87   fMaxphi(0.1),
88   fMaxeta(0.1),
89   fpInterMerger(NULL)
90 {
91   // see header file for class documentation
92   // or
93   // refer to README to build package
94   // or
95   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
96   fEta[0] = 0.;
97   fEta[1] = 1.1;
98 }
99
100 AliHLTTPCSliceTrackerComponent::~AliHLTTPCSliceTrackerComponent()
101 {
102   // see header file for class documentation
103 }
104
105 // Public functions to implement AliHLTComponent's interface.
106 // These functions are required for the registration process
107
108 const char* AliHLTTPCSliceTrackerComponent::GetComponentID()
109 {
110   // see header file for class documentation
111
112   return "TPCSliceTracker";
113 }
114
115 void AliHLTTPCSliceTrackerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
116 {
117   // see header file for class documentation
118   list.clear();
119   list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
120   list.push_back( AliHLTTPCDefinitions::fgkVertexDataType );
121 }
122
123 AliHLTComponentDataType AliHLTTPCSliceTrackerComponent::GetOutputDataType()
124 {
125   // see header file for class documentation
126   return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
127 }
128
129 void AliHLTTPCSliceTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
130 {
131   // see header file for class documentation
132   // XXX TODO: Find more realistic values.
133   constBase = 0;
134   inputMultiplier = 1;
135 }
136
137 AliHLTComponent* AliHLTTPCSliceTrackerComponent::Spawn()
138 {
139   // see header file for class documentation
140   return new AliHLTTPCSliceTrackerComponent;
141 }
142
143 void AliHLTTPCSliceTrackerComponent::SetTrackerParam(Int_t phiSegments, Int_t etaSegments,
144                                    Int_t trackletlength, Int_t tracklength,
145                                    Int_t rowscopetracklet, Int_t rowscopetrack,
146                                    Double_t minPtFit, Double_t maxangle,
147                                    Double_t goodDist, Double_t hitChi2Cut,
148                                    Double_t goodHitChi2, Double_t trackChi2Cut,
149                                    Int_t maxdist, Double_t maxphi,Double_t maxeta)
150 {
151   // see header file for class documentation
152     //fTracker->SetClusterFinderParam( fXYClusterError, fZClusterError, kTRUE ); // ??
153     //Set parameters input to the tracker
154     //If no arguments are given, default parameters will be used
155     
156     fTracker->SetNSegments(phiSegments,etaSegments);
157     fTracker->SetMaxDca(minPtFit);
158     //   fTracker->MainVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack);
159
160     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "==============================" );
161
162     if ( fmainvertextracking == kTRUE && fnonvertextracking == kFALSE){
163         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kTRUE);
164         fTracker->SetTrackletCuts(maxangle,goodDist,kTRUE);
165
166         fTracker->MainVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack, maxphi, maxeta);    
167         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "MAINVERTEXTRACKING" );
168     }
169     else if ( fmainvertextracking == kTRUE && fnonvertextracking == kTRUE){
170         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kTRUE);
171         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kFALSE);
172         fTracker->SetTrackletCuts(maxangle,goodDist,kTRUE);
173         fTracker->SetTrackletCuts(maxangle,goodDist,kFALSE);
174
175         fTracker->MainVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack, maxphi, maxeta);
176         fTracker->NonVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack);     
177         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "MAINVERTEXTRACKING - NONVERTEXTRACKING" );
178     }
179     else if ( fmainvertextracking == kFALSE && fnonvertextracking == kTRUE){
180         fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,kFALSE);
181         fTracker->SetTrackletCuts(maxangle,goodDist,kFALSE);
182
183         fTracker->NonVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack);
184         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::SetTrackerParam", "Tracking", "NONVERTEXTRACKING" );
185     }
186     
187     //fTracker->SetParamDone(true);
188     /* Matthias 13.12.2006
189      * the global variable AliHLTTPCS::fgDoVertexFit has never been used so far
190      * and has always been kTRUE.
191      * In order to remove the AliHLTTPC class (which is the old steering class for
192      * HLT (TPC) tracking) from the compilation, this function can not be activated
193      * again. We have to think about a more elegant way to specify the parameters
194      * anyway. The following line was surely for some testing, but was never active
195      * in a tested release.
196      */
197     //AliHLTTPC::SetVertexFit( kFALSE );
198     
199     fTracker->InitVolumes();
200     }
201
202
203 void AliHLTTPCSliceTrackerComponent::SetTrackerParam( Bool_t doPP, Bool_t doPbPb, Int_t multiplicity, 
204                                                       Double_t bField, Int_t etasegment, Double_t hitchi2cut, 
205                                                       Int_t rowscopetracklet, Int_t rowscopetrack, 
206                                                       Int_t trackletlength, Int_t tracklength )
207 {
208   // see header file for class documentation
209   AliHLTTPCTransform::SetBField( bField );
210   Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "BField", "Setting b field to %f T\n", bField );
211   
212   if ( doPP )
213     {
214       //tracker->SetClusterFinderParam(xyerror,zerror,kTRUE); // ??
215       
216       SetTrackerParam( 50, 100, 3, 60,
217                        2, 2,
218                        0, 0.1745, 5, 100,
219                        5, 50, 50, 0.1, 0.1);
220     }
221   else if(doPbPb)
222     {
223       int mults[] = { 1000, 2000, 4000, 8000 };
224       int multCount = 4;
225       int closestMult = 0;
226       int i;
227       int multDist, tmpMultDist;
228       if ( multiplicity>mults[closestMult] )
229         multDist = multiplicity-mults[closestMult];
230       else
231         multDist = mults[closestMult]-multiplicity;
232       for ( i = 1; i < multCount; i++ )
233         {
234           if ( multiplicity>mults[i] )
235             tmpMultDist = multiplicity-mults[i];
236           else
237             tmpMultDist = mults[i]-multiplicity;
238           if ( tmpMultDist < multDist )
239             {
240               closestMult = i;
241               multDist = tmpMultDist;
242             }
243         }
244       
245       double bfs[] = { 0.2, 0.4 };
246       int bfCount = 2;
247       int closestBf = 0;
248       double bfDist, tmpBFDist;
249       if ( bField>bfs[closestBf] )
250         bfDist = bField-bfs[closestBf];
251       else
252         bfDist = bfs[closestBf]-bField;
253       for ( i = 1; i < bfCount; i++ )
254         {
255           if ( bField>bfs[i] )
256             tmpBFDist = bField-bfs[i];
257           else
258             tmpBFDist = bfs[i]-bField;
259           if ( tmpBFDist < bfDist )
260             {
261               closestBf = i;
262               bfDist = tmpBFDist;
263             }
264         }
265       
266       switch ( closestMult )
267         {
268         case 0: // 1000
269           switch ( closestBf )
270             {
271             case 0: // 0.2
272               SetTrackerParam( 50, 100, 3, 10,
273                                2, 4,
274                                0, 0.1745, 5, 100,
275                                5, 50, 50, 0.1, 0.1);
276               break;
277             case 1: // 0.4
278               SetTrackerParam( 50, 100, 3, 10,
279                                2, 4,
280                                0, 0.1745, 5, 100,
281                                5, 50, 50, 0.1, 0.1);
282               break;
283             }
284           break;
285         case 1: // 2000
286           switch ( closestBf )
287             {
288             case 0: // 0.2
289               SetTrackerParam( 50, 100, 3, 10,
290                                2, 4,
291                                0, 0.1745, 5, 30,
292                                5, 20, 50, 0.1, 0.1);
293               break;
294             case 1: // 0.4
295               SetTrackerParam( 50, 100, 3, 10,
296                                2, 5,
297                                0, 0.1745, 5, 30,
298                                5, 20, 50, 0.1, 0.1);
299               break;
300             }
301           break;
302         case 2: // 4000
303           switch ( closestBf )
304             {
305             case 0: // 0.2
306               SetTrackerParam( 50, 100, 3, 10,
307                                2 , 10,
308                                0, 0.1745, 5, 20,
309                                5, 10 , 50, 0.1, 0.1);
310               break;
311             case 1: // 0.4
312               SetTrackerParam( 50, 100, 3, 10,
313                                2, 10,
314                                0, 0.1745, 5, 20,
315                                5, 10, 50, 0.1, 0.1);
316               break;
317             }
318           break;
319         case 3: // 8000
320           switch ( closestBf )
321             {
322             case 0: // 0.2
323               SetTrackerParam( 50, 100, 3, 10,
324                                3, 15,
325                                0, 0.1745, 5, 10,
326                                5, 5, 50, 0.1, 0.1);
327               break;
328             case 1: // 0.4
329               SetTrackerParam( 50, 100, 3, 10,
330                                2, 15,
331                                0, 0.1745, 5, 15,
332                                5, 5, 50, 0.1, 0.1);
333               break;
334             }
335           break;
336         }
337       //        Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "BField", "Setting b field to %f\n", bfs[closestBf] );
338       //        AliHLTTPCTransform::SetBField( bfs[closestBf] );
339       //        AliHLTTPCTransform::SetBField( bField );
340       //        Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "BField", "Setting b field to %f\n", bField );
341     }
342   else
343     {
344       SetTrackerParam( 50, etasegment, trackletlength, tracklength,
345                        rowscopetracklet, rowscopetrack,
346                        0, 0.1745, 5, hitchi2cut,
347                        5, 50, 50, 0.1, 0.1);
348     }
349 }
350         
351 int AliHLTTPCSliceTrackerComponent::DoInit( int argc, const char** argv )
352     {
353   // see header file for class documentation
354     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
355
356     if ( fTracker || fVertex )
357         return EINPROGRESS;
358     fTracker = new AliHLTTPCConfMapper();
359     fVertex = new AliHLTTPCVertex();
360     fEta[0] = 0.;
361     fEta[1] = 1.1;
362     fDoNonVertex = false;
363     fMultiplicity = 4000;
364     fBField = 0.5;
365     fDoPP = false;
366     fDoPbPb = false;
367     fPhisegment=50;
368     fEtasegment=100;
369     fTrackletlength=3;
370     fTracklength=60;
371     fRowscopetracklet=6;
372     fRowscopetrack=6;
373     fMinPtFit=0;
374     fMaxangle=0.1745;
375     fGoodDist=5;
376     fHitChi2Cut=100;
377     fGoodHitChi2=5;
378     fTrackChi2Cut=50;
379     fMaxdist=50;
380     fMaxphi=0.1;
381     fMaxeta=0.1;
382     int iResult=0;
383         
384     TString configuration="";
385     TString argument="";
386     for (int i=0; i<argc && iResult>=0; i++) {
387       argument=argv[i];
388       if (!configuration.IsNull()) configuration+=" ";
389       configuration+=argument;
390     }
391
392     if (!configuration.IsNull()) {
393       iResult=Configure(configuration.Data());
394     } else {
395       iResult=Reconfigure(NULL, NULL);
396     }
397     
398     return iResult;
399     }
400
401 int AliHLTTPCSliceTrackerComponent::DoDeinit()
402 {
403   // see header file for class documentation
404   if ( fTracker )
405     delete fTracker;
406   fTracker = NULL;
407   if ( fVertex )
408     delete fVertex;
409   fVertex = NULL;
410   if (fpInterMerger) {
411     delete fpInterMerger;
412   }
413   fpInterMerger=NULL;
414   return 0;
415 }
416
417 int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
418                                               AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, 
419                                               AliHLTUInt32_t& size, AliHLTComponentBlockDataList& outputBlocks )
420     {
421   // see header file for class documentation
422     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "DoEvent", "DoEvent()" );
423     if ( evtData.fBlockCnt<=0 )
424       {
425         Logging( kHLTLogWarning, "HLT::TPCSliceTracker::DoEvent", "DoEvent", "no blocks in event" );
426         return 0;
427       }
428     const AliHLTComponentBlockData* iter = NULL;
429     unsigned long ndx;
430     AliHLTTPCClusterData* inPtrSP;
431     AliHLTTPCVertexData* inPtrV = NULL;
432     const AliHLTComponentBlockData* vertexIter=NULL;
433     AliHLTTPCTrackletData* outPtr;
434     AliHLTUInt8_t* outBPtr;
435     AliHLTUInt32_t vSize = 0;
436     UInt_t offset=0, mysize, tSize = 0;
437     outBPtr = outputPtr;
438     Int_t slice=-1, patch=-1, row[2];
439     Int_t minPatch=INT_MAX, maxPatch = 0;
440     offset = 0;
441     std::vector<Int_t> slices;
442     std::vector<Int_t>::iterator slIter, slEnd;
443     std::vector<unsigned> sliceCnts;
444     std::vector<unsigned>::iterator slCntIter;
445     Int_t vertexSlice=-1;
446
447     // Find min/max rows used in total and find and read out vertex if it is present
448     // also determine correct slice number, if multiple slice numbers are present in event
449     // (which should not happen in the first place) we use the one that occurs the most times
450     row[0] = 0;
451     row[1] = 0;
452     bool found;
453     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
454         {
455         iter = blocks+ndx;
456
457         if(iter->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType){
458           HLTDebug("Data block type is not of type AliHLTTPCDefinitions::fgkClustersDataType");
459           continue;
460         }
461
462         slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
463         found = false;
464         slIter = slices.begin();
465         slEnd = slices.end();
466         slCntIter = sliceCnts.begin();
467         while ( slIter != slEnd )
468             {
469             if ( *slIter == slice )
470                 {
471                 found = true;
472                 break;
473                 }
474             slIter++;
475             slCntIter++;
476             }
477         if ( !found )
478             {
479             slices.insert( slices.end(), slice );
480             sliceCnts.insert( sliceCnts.end(), 1 );
481             }
482         else
483             *slCntIter++;
484
485         if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType )
486             {
487             inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
488             vertexIter = iter;
489             vSize = iter->fSize;
490             fVertex->Read( inPtrV );
491             vertexSlice = slice;
492             }
493         if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
494             {
495             patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
496             if ( minPatch>patch )
497                 {
498                 minPatch = patch;
499                 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
500                 }
501             if ( maxPatch<patch )
502                 {
503                 maxPatch = patch;
504                 row[1] = AliHLTTPCTransform::GetLastRow( patch );
505                 }
506             }
507         }
508
509     // Determine slice number to really use.
510     if ( slices.size()>1 )
511         {
512         Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
513                  "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
514                  evtData.fEventID, evtData.fEventID );
515         unsigned maxCntSlice=0;
516         slIter = slices.begin();
517         slEnd = slices.end();
518         slCntIter = sliceCnts.begin();
519         while ( slIter != slEnd )
520             {
521             Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
522                      "Slice %lu found %lu times.", *slIter, *slCntIter );
523             if ( maxCntSlice<*slCntIter )
524                 {
525                 maxCntSlice = *slCntIter;
526                 slice = *slIter;
527                 }
528             slIter++;
529             slCntIter++;
530             }
531         Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
532                  "Using slice %lu.", slice );
533         }
534     else if ( slices.size()>0 )
535       {
536         slice = *(slices.begin());
537       }
538     else
539       {
540         slice = -1;
541       }
542     
543     if ( vertexSlice != slice )
544         {
545         // multiple vertex blocks in event and we used the wrong one...
546         found = false;
547         for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
548             {
549             iter = blocks+ndx;
550             if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
551                 {
552                 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
553                 vertexIter = iter;
554                 vSize = iter->fSize;
555                 fVertex->Read( inPtrV );
556                 break;
557                 }
558             }
559         }
560
561     fTracker->InitSector( slice, row, fEta );
562     fTracker->SetVertex(fVertex);
563     mysize = 0;
564     // read in all hits
565     std::vector<unsigned long> patchIndices;
566     std::vector<unsigned long>::iterator pIter, pEnd;
567     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
568         {
569         iter = blocks+ndx;
570
571         if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
572             {
573             patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
574             pIter = patchIndices.begin();
575             pEnd = patchIndices.end();
576             while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
577                 pIter++;
578             patchIndices.insert( pIter, ndx );
579             }
580         }
581     pIter = patchIndices.begin();
582     pEnd = patchIndices.end();
583     while ( pIter!=pEnd )
584         {
585         ndx = *pIter;
586         iter = blocks+ndx;
587
588         patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
589         inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
590             
591         Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
592                  "Reading hits for slice %d - patch %d", slice, patch );
593         fTracker->ReadHits( inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
594         pIter++;
595         }
596
597     outPtr = (AliHLTTPCTrackletData*)(outBPtr);
598
599     if ( fmainvertextracking == kTRUE && fnonvertextracking == kFALSE){ 
600       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---MAINVERTEXTRACKING---");
601       fTracker->MainVertexTrackingA();
602       fTracker->MainVertexTrackingB();
603       fTracker->FillTracks();
604     }
605     else if ( fmainvertextracking == kTRUE && fnonvertextracking == kTRUE){     
606       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---MAINVERTEXTRACKING---");
607       fTracker->MainVertexTrackingA();
608       fTracker->MainVertexTrackingB();
609       fTracker->FillTracks();   
610       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---NONVERTEXTRACKING---");
611       fTracker->NonVertexTracking();
612     }
613     else if ( fmainvertextracking == kFALSE && fnonvertextracking == kTRUE){
614       Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracking", " ---NONVERTEXTRACKING---");
615       fTracker->NonVertexTracking();    
616       fTracker->FillTracks();   
617     }
618
619     UInt_t ntracks0 =0;
620     if(fpInterMerger){
621       AliHLTTPCMemHandler memory;
622       AliHLTTPCTrackSegmentData *trackdata0  = 
623         (AliHLTTPCTrackSegmentData *) memory.Allocate(fTracker->GetTracks());
624       memory.TrackArray2Memory(ntracks0,trackdata0,fTracker->GetTracks());
625       fpInterMerger->Reset();
626       fpInterMerger->Init(row,patch);
627       fpInterMerger->FillTracks(ntracks0,trackdata0);
628       fpInterMerger->Merge();
629     } 
630     ntracks0=0;
631     AliHLTTPCTrackArray* pArray=fTracker->GetTracks();
632     mysize = pArray->WriteTracks( ntracks0, outPtr->fTracklets );
633     outPtr->fTrackletCnt = ntracks0;
634
635     Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
636              "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.", 
637              ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
638
639     fTracker->Reset();
640
641     tSize += mysize+sizeof(AliHLTTPCTrackletData);
642     outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
643     
644     AliHLTComponentBlockData bd;
645     FillBlockData( bd );
646     bd.fOffset = offset;
647     bd.fSize = tSize;
648     bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
649     outputBlocks.push_back( bd );
650
651 #ifdef FORWARD_VERTEX_BLOCK
652     if ( vertexIter )
653         {
654         // Copy the descriptor block for the vertex information.
655         bd = *vertexIter;
656         outputBlocks.push_back( bd );
657         }
658 #endif // FORWARD_VERTEX_BLOCK
659
660     size = tSize;
661     return 0;
662     }
663
664 int AliHLTTPCSliceTrackerComponent::Configure(const char* arguments)
665 {
666   // see header file for class documentation
667   int iResult=0;
668   if (!arguments) return iResult;
669   
670   TString allArgs=arguments;
671   TString argument;
672   int bMissingParam=0;
673   Bool_t bDoMerger=kTRUE;
674
675   TObjArray* pTokens=allArgs.Tokenize(" ");
676   if (pTokens) {
677     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
678       argument=((TObjString*)pTokens->At(i))->GetString();
679       if (argument.IsNull()) continue;
680       
681       if (argument.CompareTo("-disable-merger")==0) {
682         HLTInfo("Disabled Inter Merger");
683         bDoMerger = kFALSE;
684         continue;
685       }
686       else if (argument.CompareTo("-pp-run")==0) {
687         HLTInfo("Using Trackparameters for pp-run");
688         fDoPP = true;
689         continue;
690       }
691       else if (argument.CompareTo("-PbPb-run")==0) {
692         HLTInfo("Using Trackparameters for Pb-Pb-run");
693         fDoPbPb = true;
694         continue;
695       }
696       else if (argument.CompareTo("-nonvertextracking")==0) {
697         HLTInfo("Doing Nonvertex Tracking");
698         fnonvertextracking = kTRUE;
699         continue;
700       }     
701       else if (argument.CompareTo("-mainvertextrackingoff")==0) {
702         HLTInfo("Mainvertex Tracking off");
703         fmainvertextracking = kFALSE;
704         continue;
705       }
706       else if (argument.CompareTo("-multiplicity")==0) {
707         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
708         HLTInfo("Multiplicity set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
709         fMultiplicity=((TObjString*)pTokens->At(i))->GetString().Atoi();
710         continue;
711       } 
712       else if (argument.CompareTo("-bfield")==0) {
713         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
714         HLTInfo("Magnetic Field set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
715         fBField=((TObjString*)pTokens->At(i))->GetString().Atof();
716         continue;
717       } 
718       else if (argument.CompareTo("-etarange")==0) {
719         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
720         HLTInfo("Etarange set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
721         fEta[1]=((TObjString*)pTokens->At(i))->GetString().Atof();
722         continue;
723       }
724       else if (argument.CompareTo("-etasegment")==0) {
725         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
726         HLTInfo("Number of Etasegment: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
727         fEtasegment=((TObjString*)pTokens->At(i))->GetString().Atoi();
728         continue;
729       }
730       else if (argument.CompareTo("-chi2cut")==0) {
731         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
732         HLTInfo("chi2cut set to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
733         fHitChi2Cut=((TObjString*)pTokens->At(i))->GetString().Atof();
734         continue;
735       }
736       else if (argument.CompareTo("-rowscopetracklet")==0) {
737         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
738         HLTInfo("Number of row to look for next cluster for tracklet: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
739         fRowscopetracklet=((TObjString*)pTokens->At(i))->GetString().Atoi();
740         continue;
741       }
742       else if (argument.CompareTo("-rowscopetrack")==0) {
743         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
744         HLTInfo("Number of row to look for next cluster for track: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
745         fRowscopetrack=((TObjString*)pTokens->At(i))->GetString().Atoi();
746         continue;
747       }
748       else if (argument.CompareTo("-trackletlength")==0) {
749         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
750         HLTInfo("Minimum number of clusters on a Tracklet: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
751         fTrackletlength=((TObjString*)pTokens->At(i))->GetString().Atoi();
752         continue;
753       }
754       else if (argument.CompareTo("-tracklength")==0) {
755         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
756         HLTInfo("Minimum number of clusters on a Track: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
757         fTracklength=((TObjString*)pTokens->At(i))->GetString().Atoi();
758         continue;
759       }
760       else if (argument.CompareTo("-clusterZ")==0) {
761         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
762         HLTInfo("Minimum number of clusters on a Track: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
763         fTracker->SetClusterCutZ(((TObjString*)pTokens->At(i))->GetString().Atoi());
764         continue;
765       }
766       else {
767         HLTError("unknown argument %s", argument.Data());
768         iResult=-EINVAL;
769         break;
770       }
771     }
772     delete pTokens;
773   }
774   if (bMissingParam) {
775     HLTError("missing parameter for argument %s", argument.Data());
776     iResult=-EINVAL;
777   }
778   if (fBField == 0.){
779     // parameter for B=0 T 
780     fDoPP = kTRUE;
781     fnonvertextracking = kTRUE;
782     fmainvertextracking = kFALSE;
783   }
784  
785   if (bDoMerger)
786     fpInterMerger = new AliHLTTPCInterMerger();
787   else
788     fpInterMerger = NULL;
789
790   SetTrackerParam(fDoPP,fDoPbPb,fMultiplicity,fBField,fEtasegment,fHitChi2Cut,fRowscopetracklet,fRowscopetrack,fTrackletlength,fTracklength);
791   
792   return iResult;
793 }
794
795 int AliHLTTPCSliceTrackerComponent::Reconfigure(const char* cdbEntry, const char* chainId)
796 {
797   // see header file for class documentation
798   int iResult=0;
799   const char* path="HLT/ConfigTPC/SliceTrackerComponent";
800   const char* defaultNotify="";
801   if (cdbEntry) {
802     path=cdbEntry;
803     defaultNotify=" (default)";
804   }
805   if (path) {
806     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
807     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
808     if (pEntry) {
809       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
810       if (pString) {
811         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
812         iResult=Configure(pString->GetString().Data());
813       } else {
814         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
815       }
816     } else {
817       HLTError("can not fetch object \"%s\" from CDB", path);
818     }
819   }
820
821   const char* pathBField=kAliHLTCDBSolenoidBz;
822
823   if (pathBField) {
824     HLTInfo("reconfigure B-Field from entry %s, chain id %s", path,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
825     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField/*,GetRunNo()*/);
826     if (pEntry) {
827       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
828       if (pString) {
829         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
830         iResult=Configure(pString->GetString().Data());
831       } else {
832         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
833       }
834     } else {
835       HLTError("can not fetch object \"%s\" from CDB", path);
836     }
837   }
838   
839   return iResult;
840 }
841
842 void AliHLTTPCSliceTrackerComponent::SetTrackerParam1()
843 {
844   // see header file for class documentation
845   SetTrackerParam( 10, 20, 5, 10, 2,2,
846                    0, 1.31, 5, 100,
847                    50, 100, 50, 0.1, 0.1);
848 }
849
850