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