2 //***************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
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. *
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 //***************************************************************************
19 ///////////////////////////////////////////////////////////////////////////////
21 // a TPC tracker processing component for the HLT based on CA by Ivan Kisel //
23 ///////////////////////////////////////////////////////////////////////////////
30 #include "AliHLTTPCCATrackerComponent.h"
31 #include "AliHLTTPCTransform.h"
32 #include "AliHLTTPCCATracker.h"
33 #include "AliHLTTPCCAHit.h"
34 #include "AliHLTTPCCAOutTrack.h"
35 #include "AliHLTTPCCAParam.h"
37 #include "AliHLTTPCSpacePointData.h"
38 #include "AliHLTTPCClusterDataFormat.h"
39 #include "AliHLTTPCTransform.h"
40 #include "AliHLTTPCTrackSegmentData.h"
41 #include "AliHLTTPCTrackArray.h"
42 #include "AliHLTTPCTrackletDataFormat.h"
43 #include "AliHLTTPCDefinitions.h"
44 #include "AliExternalTrackParam.h"
45 #include "TStopwatch.h"
48 /** ROOT macro for the implementation of ROOT specific class methods */
49 ClassImp(AliHLTTPCCATrackerComponent)
51 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
55 fMinNTrackClusters(30),
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent(const AliHLTTPCCATrackerComponent&)
72 fMinNTrackClusters(30),
77 // see header file for class documentation
78 HLTFatal("copy constructor untested");
81 AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=(const AliHLTTPCCATrackerComponent&)
83 // see header file for class documentation
84 HLTFatal("assignment operator untested");
88 AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
90 // see header file for class documentation
95 // Public functions to implement AliHLTComponent's interface.
96 // These functions are required for the registration process
99 const char* AliHLTTPCCATrackerComponent::GetComponentID()
101 // see header file for class documentation
102 return "TPCCATracker";
105 void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
107 // see header file for class documentation
109 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
112 AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
114 // see header file for class documentation
115 return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
118 void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
120 // define guess for the output data size
121 constBase = 200; // minimum size
122 inputMultiplier = 0.5; // size relative to input
125 AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
127 // see header file for class documentation
128 return new AliHLTTPCCATrackerComponent;
131 int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
133 // Initialize the CA tracker component
135 // arguments could be:
136 // bfield - the magnetic field value
139 if ( fTracker ) return EINPROGRESS;
145 fTracker = new AliHLTTPCCATracker();
152 if ( !strcmp( argv[i], "bfield" ) ){
155 Logging( kHLTLogError, "HLT::TPCCATracker::DoInit", "Missing B-field", "Missing B-field specifier." );
158 fBField = strtod( argv[i+1], &cpErr );
161 Logging( kHLTLogError, "HLT::TPCCATracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
165 Logging( kHLTLogInfo, "HLT::TPCCATracker::DoInit", "Reading command line",
166 "Magnetic field value is set to %f kG", fBField );
172 if ( !strcmp( argv[i], "MinNTrackClusters" ) ){
175 Logging( kHLTLogError, "HLT::TPCCATracker::DoInit", "Missing MinNTrackClusters", "Missing MinNTrackClusters specifier." );
178 fMinNTrackClusters = (Int_t ) strtod( argv[i+1], &cpErr );
181 Logging( kHLTLogError, "HLT::TPCCATracker::DoInit", "Missing multiplicity", "Cannot convert MinNTrackClusters '%s'.", argv[i+1] );
185 Logging( kHLTLogInfo, "HLT::TPCCATracker::DoInit", "Reading command line",
186 "MinNTrackClusters is set to %i ", fMinNTrackClusters );
192 Logging(kHLTLogError, "HLT::TPCCATracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
199 int AliHLTTPCCATrackerComponent::DoDeinit()
201 // see header file for class documentation
202 if ( fTracker ) delete fTracker;
207 int AliHLTTPCCATrackerComponent::DoEvent
209 const AliHLTComponentEventData& evtData,
210 const AliHLTComponentBlockData* blocks,
211 AliHLTComponentTriggerData& /*trigData*/,
212 AliHLTUInt8_t* outputPtr,
213 AliHLTUInt32_t& size,
214 vector<AliHLTComponentBlockData>& outputBlocks )
217 AliHLTUInt32_t MaxBufferSize = size;
218 size = 0; // output size
222 // Event reconstruction in one TPC slice with CA Tracker
224 //Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA::DoEvent()" );
225 if ( evtData.fBlockCnt<=0 )
227 Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "no blocks in event" );
231 const AliHLTComponentBlockData* iter = NULL;
233 AliHLTTPCClusterData* inPtrSP;
235 // Determine the slice number
239 std::vector<Int_t> slices;
240 std::vector<Int_t>::iterator slIter;
241 std::vector<unsigned> sliceCnts;
242 std::vector<unsigned>::iterator slCntIter;
244 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
246 if ( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
248 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
251 slCntIter = sliceCnts.begin();
252 for( slIter = slices.begin(); slIter!=slices.end(); slIter++, slCntIter++ ){
253 if ( *slIter == slice ){
259 slices.push_back( slice );
260 sliceCnts.push_back( 1 );
265 // Determine slice number to really use.
266 if ( slices.size()>1 )
268 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
269 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
270 evtData.fEventID, evtData.fEventID );
271 unsigned maxCntSlice=0;
272 slCntIter = sliceCnts.begin();
273 for( slIter = slices.begin(); slIter != slices.end(); slIter++, slCntIter++ )
275 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
276 "Slice %lu found %lu times.", *slIter, *slCntIter );
277 if ( maxCntSlice<*slCntIter )
279 maxCntSlice = *slCntIter;
283 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
284 "Using slice %lu.", slice );
286 else if ( slices.size()>0 )
288 slice = *(slices.begin());
293 Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "CA:: no slices found in event" );
298 // Initialize the tracker
300 Double_t Bz = fBField;
303 if( !fTracker ) fTracker = new AliHLTTPCCATracker;
305 Double_t inRmin = 83.65;
306 // Double_t inRmax = 133.3;
307 // Double_t outRmin = 133.5;
308 Double_t outRmax = 247.7;
309 Double_t plusZmin = 0.0529937;
310 Double_t plusZmax = 249.778;
311 Double_t minusZmin = -249.645;
312 Double_t minusZmax = -0.0799937;
313 Double_t dalpha = 0.349066;
314 Double_t alpha = 0.174533 + dalpha*iSec;
316 Bool_t zPlus = (iSec<18 );
317 Double_t zMin = zPlus ?plusZmin :minusZmin;
318 Double_t zMax = zPlus ?plusZmax :minusZmax;
319 //TPCZmin = -249.645, ZMax = 249.778
320 // Double_t rMin = inRmin;
321 // Double_t rMax = outRmax;
322 Int_t NRows = AliHLTTPCTransform::GetNRows();
324 Double_t padPitch = 0.4;
325 Double_t sigmaZ = 0.228808;
327 Double_t *rowX = new Double_t [NRows];
328 for( Int_t irow=0; irow<NRows; irow++){
329 rowX[irow] = AliHLTTPCTransform::Row2X( irow );
332 AliHLTTPCCAParam param;
333 param.Initialize( iSec, NRows, rowX, alpha, dalpha,
334 inRmin, outRmax, zMin, zMax, padPitch, sigmaZ, Bz );
335 param.YErrorCorrection() = 1;
336 param.ZErrorCorrection() = 2;
338 fTracker->Initialize( param );
343 // min and max patch numbers and row numbers
345 Int_t row[2] = {0,0};
346 Int_t minPatch=INT_MAX, maxPatch = -1;
350 Int_t nHitsTotal = 0;
354 std::vector<unsigned long> patchIndices;
356 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ){
358 if( iter->fDataType != AliHLTTPCDefinitions::fgkClustersDataType ) continue;
359 if( slice!=AliHLTTPCDefinitions::GetMinSliceNr( *iter ) ) continue;
360 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
361 nHitsTotal+=inPtrSP->fSpacePointCnt;
362 Int_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
363 if ( minPatch>patch ){
365 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
367 if ( maxPatch<patch ){
369 row[1] = AliHLTTPCTransform::GetLastRow( patch );
371 std::vector<unsigned long>::iterator pIter = patchIndices.begin();
372 while( pIter!=patchIndices.end() && AliHLTTPCDefinitions::GetMinPatchNr( blocks[*pIter] ) < patch ){
375 patchIndices.insert( pIter, ndx );
379 // pass event to CA Tracker
381 fTracker->StartEvent();
383 AliHLTTPCCAHit *vHits = new AliHLTTPCCAHit [nHitsTotal]; // CA hit array
384 Double_t *vHitStoreX = new Double_t [nHitsTotal]; // hit X coordinates
385 Int_t *vHitStoreID = new Int_t [nHitsTotal]; // hit ID's
386 Int_t *vHitRowID = new Int_t [nHitsTotal]; // hit ID's
390 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
391 "Total %d hits to read for slice %d", nHitsTotal, slice );
395 for( std::vector<unsigned long>::iterator pIter = patchIndices.begin(); pIter!=patchIndices.end(); pIter++ ){
399 Int_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
400 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
402 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reading hits",
403 "Reading %d hits for slice %d - patch %d", inPtrSP->fSpacePointCnt, slice, patch );
405 // Read patch hits, row by row
409 Int_t firstRowHit = 0;
410 for (UInt_t i=0; i<inPtrSP->fSpacePointCnt; i++ ){
411 AliHLTTPCSpacePointData* pSP = &(inPtrSP->fSpacePoints[i]);
413 if( pSP->fPadRow != oldRow ){
414 if( oldRow>=0 ) fTracker->ReadHitRow( oldRow, vHits+firstRowHit, nRowHits );
415 oldRow = pSP->fPadRow;
419 AliHLTTPCCAHit &h = vHits[nHits];
420 if( TMath::Abs(pSP->fX- fTracker->Rows()[pSP->fPadRow].X() )>1.e-4 ) cout<<"row "<<(Int_t)pSP->fPadRow<<" "<<fTracker->Rows()[pSP->fPadRow].X()-pSP->fX <<endl;
424 if( TMath::Abs(h.Z())>230.) continue;
425 h.ErrY() = TMath::Sqrt(TMath::Abs(pSP->fSigmaY2));
426 h.ErrZ() = TMath::Sqrt(TMath::Abs(pSP->fSigmaZ2));
427 if( h.ErrY()<.1 ) h.ErrY() = .1;
428 if( h.ErrZ()<.1 ) h.ErrZ() = .1;
429 if( h.ErrY()>1. ) h.ErrY() = 1.;
430 if( h.ErrZ()>1. ) h.ErrZ() = 1.;
432 vHitStoreX[nHits] = pSP->fX;
433 vHitStoreID[nHits] = pSP->fID;
434 vHitRowID[nHits] = pSP->fPadRow;
439 if( oldRow>=0 ) fTracker->ReadHitRow( oldRow, vHits+firstRowHit, nRowHits );
442 // reconstruct the event
444 TStopwatch timerReco;
446 fTracker->Reconstruct();
452 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Reconstruct",
453 "%d tracks found for slice %d",fTracker->NOutTracks(), slice);
455 // write reconstructed tracks
457 AliHLTTPCTrackletData* outPtr = (AliHLTTPCTrackletData*)(outputPtr);
459 AliHLTTPCTrackSegmentData* currOutTracklet = outPtr->fTracklets;
461 Int_t ntracks = fTracker->NOutTracks();
463 UInt_t mySize = ((AliHLTUInt8_t *)currOutTracklet) - ((AliHLTUInt8_t *)outputPtr);
465 outPtr->fTrackletCnt = 0;
467 for( int itr=0; itr<ntracks; itr++ ){
469 AliHLTTPCCAOutTrack &t = fTracker->OutTracks()[itr];
471 //Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Wrtite output","track %d with %d hits", itr, t.NHits());
473 if( t.NHits()<fMinNTrackClusters ) continue;
475 // calculate output track size
477 UInt_t dSize = sizeof(AliHLTTPCTrackSegmentData) + t.NHits()*sizeof(UInt_t);
479 if( mySize + dSize > MaxBufferSize ){
480 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);
485 // convert CA track parameters to HLT Track Segment
487 Int_t iFirstHit = fTracker->OutTrackHits()[t.FirstHitRef()];
488 Int_t iLastHit = fTracker->OutTrackHits()[t.FirstHitRef()+t.NHits()-1];
490 AliHLTTPCCATrackParam par = t.StartPoint();
492 par.TransportToX( vHitStoreX[iFirstHit] );
494 AliExternalTrackParam tp;
495 par.GetExtParam( tp, 0, fBField );
497 currOutTracklet->fX = tp.GetX();
498 currOutTracklet->fY = tp.GetY();
499 currOutTracklet->fZ = tp.GetZ();
500 currOutTracklet->fCharge = (Int_t ) tp.GetSign();
501 currOutTracklet->fPt = TMath::Abs(tp.GetSignedPt());
502 Double_t snp = tp.GetSnp() ;
503 if( snp>.999 ) snp=.999;
504 if( snp>-.999 ) snp=-.999;
505 currOutTracklet->fPsi = TMath::ASin( snp );
506 currOutTracklet->fTgl = tp.GetTgl();
507 Double_t h = -currOutTracklet->fPt*currOutTracklet->fPt;
508 currOutTracklet->fPterr = h*h*tp.GetSigma1Pt2();
509 h = 1./TMath::Sqrt(1-snp*snp);
510 currOutTracklet->fPsierr = h*h*tp.GetSigmaSnp2();
511 currOutTracklet->fTglerr = tp.GetSigmaTgl2();
513 par.TransportToX( vHitStoreX[iLastHit] );
514 currOutTracklet->fLastX = par.GetX();
515 currOutTracklet->fLastY = par.GetY();
516 currOutTracklet->fLastZ = par.GetZ();
518 #ifdef INCLUDE_TPC_HOUGH
519 #ifdef ROWHOUGHPARAMS
520 currOutTracklet->fTrackID = 0;
521 currOutTracklet->fRowRange1 = vHitRowID[iFirstHit];
522 currOutTracklet->fRowRange2 = vHitRowID[iLastHit];
523 currOutTracklet->fSector = slice;
524 currOutTracklet->fPID = 211;
526 #endif // INCLUDE_TPC_HOUGH
529 currOutTracklet->fNPoints = t.NHits();
531 for( Int_t i=0; i<t.NHits(); i++ ){
532 currOutTracklet->fPointIDs[i] = vHitStoreID[fTracker->OutTrackHits()[t.FirstHitRef()+i]];
535 currOutTracklet = (AliHLTTPCTrackSegmentData*)( (Byte_t *)currOutTracklet + dSize );
537 outPtr->fTrackletCnt++;
542 delete[] vHitStoreID;
545 AliHLTComponentBlockData bd;
549 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
550 outputBlocks.push_back( bd );
556 fFullTime+= timer.CpuTime();
557 fRecoTime+= timerReco.CpuTime();
560 // Set log level to "Warning" for on-line system monitoring
562 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "Tracks",
563 "CATracker slice %d: output %d tracks; input %d clusters, patches %d..%d, rows %d..%d; reco time %d/%d us",
564 slice, ntracks, nClusters, minPatch, maxPatch, row[0], row[1], (Int_t) (fFullTime/fNEvents*1.e6), (Int_t) (fRecoTime/fNEvents*1.e6) );