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