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