]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCATrackerComponent.cxx
cosmetical changes
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCATrackerComponent.cxx
1 // @(#) $Id$
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project          *
4 // ALICE Experiment at CERN, All rights reserved.                           *
5 //                                                                          *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 //                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
8 //                  for The ALICE HLT Project.                              *
9 //                                                                          *
10 // Permission to use, copy, modify and distribute this software and its     *
11 // documentation strictly for non-commercial purposes is hereby granted     *
12 // without fee, provided that the above copyright notice appears in all     *
13 // copies and that both the copyright notice and this permission notice     *
14 // appear in the supporting documentation. The authors make no claims       *
15 // about the suitability of this software for any purpose. It is            *
16 // provided "as is" without express or implied warranty.                    *
17 //                                                                          *
18 //***************************************************************************
19
20
21 ///////////////////////////////////////////////////////////////////////////////
22 //                                                                           //
23 // a TPC tracker processing component for the HLT based on CA by Ivan Kisel  //
24 //                                                                           //
25 ///////////////////////////////////////////////////////////////////////////////
26
27 #if __GNUC__>= 3
28 using namespace std;
29 #endif
30
31 #include "AliHLTTPCCATrackerComponent.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCCATracker.h"
34 #include "AliHLTTPCCAOutTrack.h"
35 #include "AliHLTTPCCAParam.h"
36 #include "AliHLTTPCCATrackConvertor.h"
37
38 #include "AliHLTTPCSpacePointData.h"
39 #include "AliHLTTPCClusterDataFormat.h"
40 #include "AliHLTTPCTransform.h"
41 #include "AliHLTTPCTrackSegmentData.h"
42 #include "AliHLTTPCTrackArray.h"
43 #include "AliHLTTPCTrackletDataFormat.h"
44 #include "AliHLTTPCDefinitions.h"
45 #include "AliExternalTrackParam.h"
46 #include "TStopwatch.h"
47 #include "TMath.h"
48 #include "AliCDBEntry.h"
49 #include "AliCDBManager.h"
50 #include "TObjString.h"
51 #include "TObjArray.h"
52 #include "AliHLTTPCCASliceOutput.h"
53
54 const AliHLTComponentDataType AliHLTTPCCADefinitions::fgkTrackletsDataType = AliHLTComponentDataTypeInitializer( "CATRACKL", kAliHLTDataOriginTPC );
55
56 /** ROOT macro for the implementation of ROOT specific class methods */
57 ClassImp( AliHLTTPCCATrackerComponent )
58
59 /** global object for registration
60  * Matthias 2009-01-13 temporarily using the global object approach again.
61  * CA cade had to be disabled because of various compilation problems, so
62  * the global object approach fits better for the moment.
63  */
64
65 AliHLTTPCCATrackerComponent gAliHLTTPCCATrackerComponent;
66
67 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
68     :
69     fTracker( NULL ),
70     fSolenoidBz( 0 ),
71     fMinNTrackClusters( 0 ),
72     fClusterZCut( 500. ),
73     fFullTime( 0 ),
74     fRecoTime( 0 ),
75     fNEvents( 0 ),
76     fNewOutputType( 0 )
77 {
78   // see header file for class documentation
79   // or
80   // refer to README to build package
81   // or
82   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
83 }
84
85 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent( const AliHLTTPCCATrackerComponent& )
86     :
87     AliHLTProcessor(),
88     fTracker( NULL ),
89     fSolenoidBz( 0 ),
90     fMinNTrackClusters( 30 ),
91     fClusterZCut( 500. ),
92     fFullTime( 0 ),
93     fRecoTime( 0 ),
94     fNEvents( 0 ),
95     fNewOutputType( 0 )
96 {
97   // see header file for class documentation
98   HLTFatal( "copy constructor untested" );
99 }
100
101 AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=( const AliHLTTPCCATrackerComponent& )
102 {
103   // see header file for class documentation
104   HLTFatal( "assignment operator untested" );
105   return *this;
106 }
107
108 AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
109 {
110   // see header file for class documentation
111   delete fTracker;
112 }
113
114 //
115 // Public functions to implement AliHLTComponent's interface.
116 // These functions are required for the registration process
117 //
118
119 const char* AliHLTTPCCATrackerComponent::GetComponentID()
120 {
121   // see header file for class documentation
122   return "TPCCATracker";
123 }
124
125 void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
126 {
127   // see header file for class documentation
128   list.clear();
129   list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
130 }
131
132 AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
133 {
134   // see header file for class documentation
135   if ( fNewOutputType ) return AliHLTTPCCADefinitions::fgkTrackletsDataType;
136   else return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
137 }
138
139 void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
140 {
141   // define guess for the output data size
142   constBase = 200;       // minimum size
143   inputMultiplier = 0.5; // size relative to input
144 }
145
146 AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
147 {
148   // see header file for class documentation
149   return new AliHLTTPCCATrackerComponent;
150 }
151
152 int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
153 {
154   // Configure the CA tracker component
155
156   fSolenoidBz = 5;
157   fMinNTrackClusters = 0;
158   fClusterZCut = 500.;
159   fFullTime = 0;
160   fRecoTime = 0;
161   fNEvents = 0;
162   fNewOutputType = 0;
163
164   if ( fTracker ) return EINPROGRESS;
165   fTracker = new AliHLTTPCCATracker();
166
167   int iResult = 0;
168
169   TString arguments = "";
170   for ( int i = 0; i < argc; i++ ) {
171     TString argument = argv[i];
172     if ( !arguments.IsNull() ) arguments += " ";
173     arguments += argument;
174   }
175   if ( !arguments.IsNull() ) {
176     iResult = Configure( arguments.Data() );
177   } else {
178     iResult = Reconfigure( NULL, NULL );
179   }
180   return iResult;
181 }
182
183
184 int AliHLTTPCCATrackerComponent::DoDeinit()
185 {
186   // see header file for class documentation
187   if ( fTracker ) delete fTracker;
188   fTracker = NULL;
189   return 0;
190 }
191
192 int AliHLTTPCCATrackerComponent::Reconfigure( const char* /*cdbEntry*/, const char* /*chainId*/ )
193 {
194   // see header file for class documentation
195
196   HLTWarning( "TODO: dummy Reconfigure() method" );
197
198   return 0;
199
200   /*
201
202   int iResult=0;
203   const char* path="HLT/ConfigTPC/CATrackerComponent";
204   const char* defaultNotify="";
205   if (cdbEntry) {
206     path=cdbEntry;
207     defaultNotify=" (default)";
208   }
209   if (path) {
210     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
211     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);//,GetRunNo());
212     if (pEntry) {
213       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
214       if (pString) {
215   HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
216   iResult=Configure(pString->GetString().Data());
217       } else {
218   HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
219       }
220     } else {
221       HLTError("cannot fetch object \"%s\" from CDB", path);
222     }
223   }
224
225   const char* pathBField=kAliHLTCDBSolenoidBz;
226
227   if (pathBField) {
228     HLTInfo("reconfigure B-Field from entry %s, chain id %s", path,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
229     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(pathBField);//,GetRunNo());
230     if (pEntry) {
231       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
232       if (pString) {
233   HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
234   iResult=Configure(pString->GetString().Data());
235       } else {
236   HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
237       }
238     } else {
239       HLTError("cannot fetch object \"%s\" from CDB", path);
240     }
241   }
242   return iResult;
243   */
244 }
245
246
247 bool AliHLTTPCCATrackerComponent::CompareClusters( AliHLTTPCSpacePointData *a, AliHLTTPCSpacePointData *b )
248 {
249   //* Comparison function for sorting clusters
250   if ( a->fPadRow < b->fPadRow ) return 1;
251   if ( a->fPadRow > b->fPadRow ) return 0;
252   return ( a->fZ < b->fZ );
253 }
254
255
256 int AliHLTTPCCATrackerComponent::Configure( const char* arguments )
257 {
258   //* Set parameters
259
260   int iResult = 0;
261   if ( !arguments ) return iResult;
262
263   TString allArgs = arguments;
264   TString argument;
265   int bMissingParam = 0;
266
267   TObjArray* pTokens = allArgs.Tokenize( " " );
268
269   int nArgs =  pTokens ? pTokens->GetEntries() : 0;
270
271   for ( int i = 0; i < nArgs; i++ ) {
272     argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
273     if ( argument.IsNull() ) {
274     } else if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
275       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
276       fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
277       HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
278     } else if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ||
279                 argument.CompareTo( "-minNTrackClusters" ) == 0 ) {
280       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
281       fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
282       HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
283     } else if ( argument.CompareTo( "-clusterZCut" ) == 0 ) {
284       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
285       fClusterZCut = TMath::Abs( ( ( TObjString* )pTokens->At( i ) )->GetString().Atof() );
286       HLTInfo( "ClusterZCut set to: %f", fClusterZCut );
287     } else if ( argument.CompareTo( "-newOutputType" ) == 0 ) {
288       fNewOutputType = 1;
289       HLTInfo( "NewOutputType is set" );
290     } else {
291       HLTError( "Unknown option %s ", argument.Data() );
292       iResult = -EINVAL;
293     }
294   }
295   delete pTokens;
296
297   if ( bMissingParam ) {
298     HLTError( "Specifier missed for %s", argument.Data() );
299     iResult = -EINVAL;
300   }
301
302   return iResult;
303 }
304
305
306
307
308 int AliHLTTPCCATrackerComponent::DoEvent
309 (
310   const AliHLTComponentEventData& evtData,
311   const AliHLTComponentBlockData* blocks,
312   AliHLTComponentTriggerData& /*trigData*/,
313   AliHLTUInt8_t* outputPtr,
314   AliHLTUInt32_t& size,
315   vector<AliHLTComponentBlockData>& outputBlocks )
316 {
317 //* process event
318   AliHLTUInt32_t maxBufferSize = size;
319   size = 0; // output size
320
321   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
322     return 0;
323   }
324
325   TStopwatch timer;
326
327   // Event reconstruction in one TPC slice with CA Tracker
328
329   //Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA::DoEvent()" );
330   if ( evtData.fBlockCnt <= 0 ) {
331     HLTWarning( "no blocks in event" );
332     return 0;
333   }
334
335   const AliHLTComponentBlockData* iter = NULL;
336   unsigned long ndx;
337   AliHLTTPCClusterData* inPtrSP;
338
339   // Determine the slice number
340
341   int slice = -1;
342   {
343     std::vector<int> slices;
344     std::vector<int>::iterator slIter;
345     std::vector<unsigned> sliceCnts;
346     std::vector<unsigned>::iterator slCntIter;
347
348     for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
349       iter = blocks + ndx;
350       if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
351
352       slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
353
354       bool found = 0;
355       slCntIter = sliceCnts.begin();
356       for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
357         if ( *slIter == slice ) {
358           found = kTRUE;
359           break;
360         }
361       }
362       if ( !found ) {
363         slices.push_back( slice );
364         sliceCnts.push_back( 1 );
365       } else *slCntIter++;
366     }
367
368
369     // Determine slice number to really use.
370     if ( slices.size() > 1 ) {
371       Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
372                "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
373                evtData.fEventID, evtData.fEventID );
374       unsigned maxCntSlice = 0;
375       slCntIter = sliceCnts.begin();
376       for ( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ ) {
377         Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
378                  "Slice %lu found %lu times.", *slIter, *slCntIter );
379         if ( maxCntSlice < *slCntIter ) {
380           maxCntSlice = *slCntIter;
381           slice = *slIter;
382         }
383       }
384       Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
385                "Using slice %lu.", slice );
386     } else if ( slices.size() > 0 ) {
387       slice = *( slices.begin() );
388     }
389   }
390
391   if ( slice < 0 ) {
392     HLTWarning( "no slices found in event" );
393     return 0;
394   }
395
396
397   // Initialize the tracker
398
399
400   {
401     if ( !fTracker ) fTracker = new AliHLTTPCCATracker;
402     int iSec = slice;
403     float inRmin = 83.65;
404     //    float inRmax = 133.3;
405     //    float outRmin = 133.5;
406     float outRmax = 247.7;
407     float plusZmin = 0.0529937;
408     float plusZmax = 249.778;
409     float minusZmin = -249.645;
410     float minusZmax = -0.0799937;
411     float dalpha = 0.349066;
412     float alpha = 0.174533 + dalpha * iSec;
413
414     bool zPlus = ( iSec < 18 );
415     float zMin =  zPlus ? plusZmin : minusZmin;
416     float zMax =  zPlus ? plusZmax : minusZmax;
417     //TPCZmin = -249.645, ZMax = 249.778
418     //    float rMin =  inRmin;
419     //    float rMax =  outRmax;
420     int nRows = AliHLTTPCTransform::GetNRows();
421
422     float padPitch = 0.4;
423     float sigmaZ = 0.228808;
424
425     float *rowX = new float [nRows];
426     for ( int irow = 0; irow < nRows; irow++ ) {
427       rowX[irow] = AliHLTTPCTransform::Row2X( irow );
428     }
429
430     AliHLTTPCCAParam param;
431     param.Initialize( iSec, nRows, rowX, alpha, dalpha,
432                       inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, fSolenoidBz );
433     param.SetHitPickUpFactor( 2 );
434     param.Update();
435     fTracker->Initialize( param );
436     delete[] rowX;
437   }
438
439
440   // min and max patch numbers and row numbers
441
442   int row[2] = {0, 0};
443   int minPatch = 100, maxPatch = -1;
444
445   // total n Hits
446
447   int nHitsTotal = 0;
448
449   // sort patches
450
451   std::vector<unsigned long> patchIndices;
452
453   for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
454     iter = blocks + ndx;
455     if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
456     if ( slice != AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) continue;
457     inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
458     nHitsTotal += inPtrSP->fSpacePointCnt;
459     int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
460     if ( minPatch > patch ) {
461       minPatch = patch;
462       row[0] = AliHLTTPCTransform::GetFirstRow( patch );
463     }
464     if ( maxPatch < patch ) {
465       maxPatch = patch;
466       row[1] = AliHLTTPCTransform::GetLastRow( patch );
467     }
468     std::vector<unsigned long>::iterator pIter = patchIndices.begin();
469     while ( pIter != patchIndices.end() && AliHLTTPCDefinitions::GetMinPatchNr( blocks[*pIter] ) < patch ) {
470       pIter++;
471     }
472     patchIndices.insert( pIter, ndx );
473   }
474
475
476   // pass event to CA Tracker
477
478   fTracker->StartEvent();
479
480   Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
481            "Total %d hits to read for slice %d", nHitsTotal, slice );
482
483
484   AliHLTTPCSpacePointData** vOrigClusters = new AliHLTTPCSpacePointData* [ nHitsTotal];
485
486   int nClusters = 0;
487
488   for ( std::vector<unsigned long>::iterator pIter = patchIndices.begin(); pIter != patchIndices.end(); pIter++ ) {
489     ndx = *pIter;
490     iter = blocks + ndx;
491
492     int patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
493     inPtrSP = ( AliHLTTPCClusterData* )( iter->fPtr );
494
495     Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
496              "Reading %d hits for slice %d - patch %d", inPtrSP->fSpacePointCnt, slice, patch );
497
498     for ( unsigned int i = 0; i < inPtrSP->fSpacePointCnt; i++ ) {
499       vOrigClusters[nClusters++] = &( inPtrSP->fSpacePoints[i] );
500     }
501   }
502
503   // sort clusters since they are not sorted fore some reason
504
505   sort( vOrigClusters, vOrigClusters + nClusters, CompareClusters );
506
507   float *vHitStoreX = new float [nHitsTotal];       // hit X coordinates
508   float *vHitStoreY = new float [nHitsTotal];       // hit Y coordinates
509   float *vHitStoreZ = new float [nHitsTotal];       // hit Z coordinates
510   int *vHitStoreIntID = new int [nHitsTotal];            // hit ID's
511   int *vHitStoreID = new int [nHitsTotal];            // hit ID's
512   int *vHitRowID = new int [nHitsTotal];            // hit ID's
513
514   int nHits = 0;
515
516   {
517     int rowNHits[200];
518     int rowFirstHits[200];
519     for ( int ir = 0; ir < 200; ir++ ) rowNHits[ir] = 0;
520     int oldRow = -1;
521     for ( int i = 0; i < nClusters; i++ ) {
522       AliHLTTPCSpacePointData* pSP = vOrigClusters[i];
523       if ( oldRow >= 0 && pSP->fPadRow < oldRow )
524         HLTError( "CA: clusters from row %d are readed twice", oldRow );
525
526       if ( TMath::Abs( pSP->fZ ) > fClusterZCut ) continue;
527
528       vHitStoreX[nHits] = pSP->fX;
529       vHitStoreY[nHits] = pSP->fY;
530       vHitStoreZ[nHits] = pSP->fZ;
531       vHitStoreIntID[nHits] = nHits;
532       vHitStoreID[nHits] = pSP->fID;
533       vHitRowID[nHits] = pSP->fPadRow;
534       nHits++;
535       rowNHits[pSP->fPadRow]++;
536     }
537
538     int firstRowHit = 0;
539     for ( int ir = 0; ir < 200; ir++ ) {
540       rowFirstHits[ir] = firstRowHit;
541       firstRowHit += rowNHits[ir];
542     }
543
544     fTracker->ReadEvent( rowFirstHits, rowNHits, vHitStoreX, vHitStoreY, vHitStoreZ, nHits );
545   }
546
547   if ( vOrigClusters ) delete[] vOrigClusters;
548
549   // reconstruct the event
550
551   TStopwatch timerReco;
552
553   fTracker->Reconstruct();
554
555   timerReco.Stop();
556
557   int ret = 0;
558
559   Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
560            "%d tracks found for slice %d", fTracker->NOutTracks(), slice );
561
562
563   // write reconstructed tracks
564
565   unsigned int mySize = 0;
566   int ntracks = *fTracker->NOutTracks();
567
568
569   if ( !fNewOutputType ) {
570
571     AliHLTTPCTrackletData* outPtr = ( AliHLTTPCTrackletData* )( outputPtr );
572
573     AliHLTTPCTrackSegmentData* currOutTracklet = outPtr->fTracklets;
574
575     mySize =   ( ( AliHLTUInt8_t * )currOutTracklet ) -  ( ( AliHLTUInt8_t * )outputPtr );
576
577     outPtr->fTrackletCnt = 0;
578
579     for ( int itr = 0; itr < ntracks; itr++ ) {
580
581       AliHLTTPCCAOutTrack &t = fTracker->OutTracks()[itr];
582
583       //Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Wrtite output","track %d with %d hits", itr, t.NHits());
584
585       if ( t.NHits() < fMinNTrackClusters ) continue;
586
587       // calculate output track size
588
589       unsigned int dSize = sizeof( AliHLTTPCTrackSegmentData ) + t.NHits() * sizeof( unsigned int );
590
591       if ( mySize + dSize > maxBufferSize ) {
592         HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, ntracks - itr + 1 );
593         ret = -ENOSPC;
594         break;
595       }
596
597       // convert CA track parameters to HLT Track Segment
598
599       int iFirstRow = 1000;
600       int iLastRow = -1;
601       int iFirstHit = fTracker->OutTrackHits()[t.FirstHitRef()];
602       int iLastHit = iFirstHit;
603       for ( int ih = 0; ih < t.NHits(); ih++ ) {
604         int hitID = fTracker->OutTrackHits()[t.FirstHitRef() + ih ];
605         int iRow = vHitRowID[hitID];
606         if ( iRow < iFirstRow ) {  iFirstRow = iRow; iFirstHit = hitID; }
607         if ( iRow > iLastRow ) { iLastRow = iRow; iLastHit = hitID; }
608       }
609
610       AliHLTTPCCATrackParam par = t.StartPoint();
611
612       par.TransportToX( vHitStoreX[iFirstHit], .99 );
613
614       AliExternalTrackParam tp;
615       AliHLTTPCCATrackConvertor::GetExtParam( par, tp, 0 );
616
617       currOutTracklet->fX = tp.GetX();
618       currOutTracklet->fY = tp.GetY();
619       currOutTracklet->fZ = tp.GetZ();
620       currOutTracklet->fCharge = ( int ) tp.GetSign();
621       currOutTracklet->fPt = TMath::Abs( tp.GetSignedPt() );
622       float snp =  tp.GetSnp() ;
623       if ( snp > .999 ) snp = .999;
624       if ( snp < -.999 ) snp = -.999;
625       currOutTracklet->fPsi = TMath::ASin( snp );
626       currOutTracklet->fTgl = tp.GetTgl();
627
628       currOutTracklet->fY0err = tp.GetSigmaY2();
629       currOutTracklet->fZ0err = tp.GetSigmaZ2();
630       float h = -currOutTracklet->fPt * currOutTracklet->fPt;
631       currOutTracklet->fPterr = h * h * tp.GetSigma1Pt2();
632       h = 1. / TMath::Sqrt( 1 - snp * snp );
633       currOutTracklet->fPsierr = h * h * tp.GetSigmaSnp2();
634       currOutTracklet->fTglerr = tp.GetSigmaTgl2();
635
636       if ( par.TransportToX( vHitStoreX[iLastHit], .99 ) ) {
637         currOutTracklet->fLastX = par.GetX();
638         currOutTracklet->fLastY = par.GetY();
639         currOutTracklet->fLastZ = par.GetZ();
640       } else {
641         currOutTracklet->fLastX = vHitStoreX[iLastHit];
642         currOutTracklet->fLastY = vHitStoreY[iLastHit];
643         currOutTracklet->fLastZ = vHitStoreZ[iLastHit];
644       }
645       //if( currOutTracklet->fLastX<10. ) {
646       //HLTError("CA last point: hitxyz=%f,%f,%f, track=%f,%f,%f, tracklet=%f,%f,%f, nhits=%d",vHitStoreX[iLastHit],vHitStoreY[iLastHit],vHitStoreZ[iLastHit],
647       //par.GetX(), par.GetY(),par.GetZ(),currOutTracklet->fLastX,currOutTracklet->fLastY ,currOutTracklet->fLastZ, t.NHits());
648       //}
649 #ifdef INCLUDE_TPC_HOUGH
650 #ifdef ROWHOUGHPARAMS
651       currOutTracklet->fTrackID = 0;
652       currOutTracklet->fRowRange1 = vHitRowID[iFirstHit];
653       currOutTracklet->fRowRange2 = vHitRowID[iLastHit];
654       currOutTracklet->fSector = slice;
655       currOutTracklet->fPID = 211;
656 #endif
657 #endif // INCLUDE_TPC_HOUGH
658
659
660       currOutTracklet->fNPoints = t.NHits();
661
662       for ( int i = 0; i < t.NHits(); i++ ) {
663         currOutTracklet->fPointIDs[i] = vHitStoreID[fTracker->OutTrackHits()[t.FirstHitRef()+i]];
664       }
665
666       currOutTracklet = ( AliHLTTPCTrackSegmentData* )( ( Byte_t * )currOutTracklet + dSize );
667       mySize += dSize;
668       outPtr->fTrackletCnt++;
669     }
670   } else { // new output type
671
672     mySize = fTracker->Output()->EstimateSize( fTracker->Output()->NTracks(),
673              fTracker->Output()->NTrackClusters() );
674     if ( mySize <= maxBufferSize ) {
675       const AliHLTUInt8_t* outputevent = reinterpret_cast<const AliHLTUInt8_t*>( fTracker->Output() );
676       for ( unsigned int i = 0; i < mySize; i++ ) outputPtr[i] = outputevent[i];
677     } else {
678       HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, mySize );
679       mySize = 0;
680       ret = -ENOSPC;
681     }
682   }
683
684   if ( vHitStoreX ) delete[] vHitStoreX;
685   if ( vHitStoreY ) delete[] vHitStoreY;
686   if ( vHitStoreZ ) delete[] vHitStoreZ;
687   if ( vHitStoreIntID ) delete[] vHitStoreIntID;
688   if ( vHitStoreID ) delete[] vHitStoreID;
689   if ( vHitRowID ) delete[] vHitRowID;
690
691   if ( mySize > 0 ) {
692     AliHLTComponentBlockData bd;
693     FillBlockData( bd );
694     bd.fOffset = 0;
695     bd.fSize = mySize;
696     bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
697     outputBlocks.push_back( bd );
698   }
699   size = mySize;
700
701   timer.Stop();
702
703   fFullTime += timer.RealTime();
704   fRecoTime += timerReco.RealTime();
705   fNEvents++;
706
707   // Set log level to "Warning" for on-line system monitoring
708   int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
709   int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
710   HLTWarning( "CATracker slice %d: output %d tracks;  input %d clusters, patches %d..%d, rows %d..%d; reco time %d/%d Hz",
711               slice, ntracks, nClusters, minPatch, maxPatch, row[0], row[1], hz, hz1 );
712
713   return ret;
714 }
715
716