1 // $Id: AliHLTITSTrackerComponent.cxx 32659 2009-06-02 16:08:40Z sgorbuno $
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. *
18 //***************************************************************************
20 /// @file AliHLTITSTrackerComponent.cxx
21 /// @author Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de>
23 /// @brief An ITS tracker processing component for the HLT
26 /////////////////////////////////////////////////////
28 // a ITS tracker processing component for the HLT //
30 /////////////////////////////////////////////////////
36 #include "AliHLTITSTrackerComponent.h"
37 #include "AliHLTArray.h"
38 #include "AliExternalTrackParam.h"
39 #include "TStopwatch.h"
41 #include "AliCDBEntry.h"
42 #include "AliCDBManager.h"
43 #include "AliGeomManager.h"
44 #include "TObjString.h"
45 #include "TObjArray.h"
46 #include "AliITStrackerHLT.h"
47 #include "AliHLTITSSpacePointData.h"
48 #include "AliHLTITSClusterDataFormat.h"
49 #include "AliHLTDataTypes.h"
50 #include "AliHLTExternalTrackParam.h"
51 #include "AliHLTGlobalBarrelTrack.h"
52 #include "AliGeomManager.h"
53 #include "AliHLTTrackMCLabel.h"
56 /** ROOT macro for the implementation of ROOT specific class methods */
57 ClassImp( AliHLTITSTrackerComponent )
58 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
61 fBenchmark("ITSTracker"),
64 // see header file for class documentation
66 // refer to README to build package
68 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
71 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
75 fBenchmark("ITSTracker"),
78 // see header file for class documentation
79 HLTFatal( "copy constructor untested" );
82 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
84 // see header file for class documentation
85 HLTFatal( "assignment operator untested" );
89 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
91 // see header file for class documentation
96 // Public functions to implement AliHLTComponent's interface.
97 // These functions are required for the registration process
100 const char* AliHLTITSTrackerComponent::GetComponentID()
102 // see header file for class documentation
106 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
108 // see header file for class documentation
110 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
111 list.push_back( kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC );
112 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
113 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
114 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
115 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITS );
118 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
120 // see header file for class documentation
121 return kAliHLTMultipleDataType;
124 int AliHLTITSTrackerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
126 // see header file for class documentation
128 tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
129 tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
130 tgtList.push_back( kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS );
131 return tgtList.size();
134 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
136 // define guess for the output data size
137 constBase = 200; // minimum size
138 inputMultiplier = 2.; // size relative to input
141 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
143 // see header file for class documentation
144 return new AliHLTITSTrackerComponent;
147 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
149 // Set default configuration for the CA tracker component
150 // Some parameters can be later overwritten from the OCDB
152 fSolenoidBz = -5.00668;
156 int AliHLTITSTrackerComponent::ReadConfigurationString( const char* arguments )
158 // Set configuration parameters for the CA tracker component from the string
161 if ( !arguments ) return iResult;
163 TString allArgs = arguments;
165 int bMissingParam = 0;
167 TObjArray* pTokens = allArgs.Tokenize( " " );
169 int nArgs = pTokens ? pTokens->GetEntries() : 0;
171 for ( int i = 0; i < nArgs; i++ ) {
172 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
173 if ( argument.IsNull() ) continue;
175 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
176 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
177 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
181 //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
182 //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
183 //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
184 //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
188 HLTError( "Unknown option \"%s\"", argument.Data() );
193 if ( bMissingParam ) {
194 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
202 int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
204 // see header file for class documentation
206 const char* defaultNotify = "";
209 return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
210 //cdbEntry = "HLT/ConfigITS/ITSTracker";
211 //defaultNotify = " (default)";
215 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
216 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
219 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
223 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
226 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
230 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
232 return ReadConfigurationString( pString->GetString().Data() );
236 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
238 // Configure the component
239 // There are few levels of configuration,
240 // parameters which are set on one step can be overwritten on the next step
242 //* read hard-coded values
244 SetDefaultConfiguration();
246 //* read the default CDB entry
248 int iResult1 = ReadCDBEntry( NULL, chainId );
250 //* read magnetic field
252 fSolenoidBz = GetBz();
254 //* read the actual CDB entry if required
256 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
258 //* read extra parameters from input (if they are)
262 if ( commandLine && commandLine[0] != '\0' ) {
263 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
264 iResult3 = ReadConfigurationString( commandLine );
267 // Initialise the tracker here
269 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
274 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
276 // Configure the ITS tracker component
278 if ( fTracker ) return -EINPROGRESS;
280 if(AliGeomManager::GetGeometry()==NULL){
281 AliGeomManager::LoadGeometry();
283 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
285 TString arguments = "";
286 for ( int i = 0; i < argc; i++ ) {
287 if ( !arguments.IsNull() ) arguments += " ";
288 arguments += argv[i];
291 int ret = Configure( NULL, NULL, arguments.Data() );
294 if (!TGeoGlobalMagField::Instance()) {
295 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
300 fTracker = new AliITStrackerHLT(0);
302 fBenchmark.SetTimer(0,"total");
303 fBenchmark.SetTimer(1,"reco");
308 int AliHLTITSTrackerComponent::DoDeinit()
310 // see header file for class documentation
318 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
320 // Reconfigure the component from OCDB .
322 return Configure( cdbEntry, chainId, NULL );
327 int AliHLTITSTrackerComponent::DoEvent
329 const AliHLTComponentEventData& evtData,
330 const AliHLTComponentBlockData* blocks,
331 AliHLTComponentTriggerData& /*trigData*/,
332 AliHLTUInt8_t* outputPtr,
333 AliHLTUInt32_t& size,
334 vector<AliHLTComponentBlockData>& outputBlocks )
338 AliHLTUInt32_t maxBufferSize = size;
339 size = 0; // output size
341 if (!IsDataEvent()) return 0;
343 if ( evtData.fBlockCnt <= 0 ) {
344 HLTWarning( "no blocks in event" );
348 fBenchmark.StartNewEvent();
351 // Event reconstruction in ITS
355 int nBlocks = evtData.fBlockCnt;
358 vector< AliExternalTrackParam > tracksTPC;
359 vector< int > tracksTPCLab;
360 vector< int > tracksTPCId;
362 int nClustersTotal = 0;
364 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
366 const AliHLTComponentBlockData* iter = blocks+ndx;
368 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
369 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
370 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ||
371 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITS) )
373 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
374 nClustersTotal+=inPtr->fSpacePointCnt;
379 fTracker->StartLoadClusters(nClustersTotal);
381 // first read MC information (if present)
383 std::map<int,int> mcLabels;
385 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
386 pBlock!=NULL; pBlock=GetNextInputBlock()) {
388 fBenchmark.AddInput(pBlock->fSize);
390 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
391 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
392 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
393 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
394 mcLabels[lab.fTrackID] = lab.fMCLabel;
397 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
398 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
399 dataPtr->fCount, pBlock->fSize);
405 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
407 const AliHLTComponentBlockData* iter = blocks+ndx;
411 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
412 fBenchmark.AddInput(iter->fSize);
413 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
414 int nTracks = dataPtr->fCount;
415 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
416 for( int itr=0; itr<nTracks; itr++ ){
417 AliHLTGlobalBarrelTrack t(*currOutTrack);
419 if( mcLabels.find(currOutTrack->fTrackID)!=mcLabels.end() )
420 mcLabel = mcLabels[currOutTrack->fTrackID];
422 tracksTPC.push_back( t );
423 tracksTPCLab.push_back(mcLabel);
424 tracksTPCId.push_back( currOutTrack->fTrackID );
425 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
426 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
433 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
434 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
435 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ||
436 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITS) )
439 fBenchmark.AddInput(iter->fSize);
441 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
442 int nClusters = inPtr->fSpacePointCnt;
443 for( int icl=0; icl<nClusters; icl++ ){
444 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
446 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
447 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
448 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
449 if( d.fLayer==4 ) hit[5] = -hit[5];
450 fTracker->LoadCluster( AliITSRecPoint( lab, hit, info ) );
451 //cout<<"SG "<<d.fLayer<<" "<<d.fTracks[0]<<endl;
455 }// end read input blocks
457 // Reconstruct the event
460 fTracker->Reconstruct( &(tracksTPC[0]), &(tracksTPCLab[0]), tracksTPC.size() );
464 // Fill output tracks
468 for( int iOut=0; iOut<=1; iOut++ ){
470 unsigned int blockSize = 0;
472 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
473 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
475 blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outPtr );
477 if ( size + blockSize > maxBufferSize ) {
478 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, size + blockSize );
484 AliHLTITSTrack *tracks=0;
487 tracks = fTracker->Tracks();
488 nTracks = fTracker->NTracks();
490 tracks = fTracker->ITSOutTracks();
491 nTracks = fTracker->NITSOutTracks();
494 for ( int itr = 0; itr < nTracks; itr++ ) {
495 AliHLTITSTrack &t = tracks[itr];
496 int id = tracksTPCId[t.TPCtrackId()];
497 int nClusters = t.GetNumberOfClusters();
498 if( iOut==0 && nClusters>0 ) nITSUpdated++;
500 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
502 if ( size + blockSize + dSize > maxBufferSize ) {
503 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, size + blockSize + dSize, nTracks - itr + 1 );
508 currOutTrack->fAlpha = t.GetAlpha();
509 currOutTrack->fX = t.GetX();
510 currOutTrack->fY = t.GetY();
511 currOutTrack->fZ = t.GetZ();
512 currOutTrack->fLastX = 0;
513 currOutTrack->fLastY = 0;
514 currOutTrack->fLastZ = 0;
515 currOutTrack->fq1Pt = t.GetSigned1Pt();
516 currOutTrack->fSinPsi = t.GetSnp();
517 currOutTrack->fTgl = t.GetTgl();
518 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = t.GetCovariance()[i];
519 currOutTrack->fTrackID = id;
520 currOutTrack->fFlags = 0;
521 currOutTrack->fNPoints = nClusters;
522 for ( int i = 0; i < nClusters; i++ ) currOutTrack->fPointIDs[i] = t.GetClusterIndex( i );
523 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
529 AliHLTComponentBlockData resultData;
530 FillBlockData( resultData );
531 resultData.fOffset = size;
532 resultData.fSize = blockSize;
534 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
536 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut;
538 fBenchmark.AddOutput(resultData.fSize);
539 outputBlocks.push_back( resultData );
540 size += resultData.fSize;
546 unsigned int blockSize = 0;
548 AliHLTTrackMCData* outPtr = ( AliHLTTrackMCData* )( outputPtr +size );
549 AliHLTTrackMCLabel* currOutLabel = outPtr->fLabels;
551 blockSize = ( ( AliHLTUInt8_t * )currOutLabel ) - ( ( AliHLTUInt8_t * )outPtr );
555 AliHLTITSTrack *tracks= fTracker->Tracks();
556 int nTracks = fTracker->NTracks();
558 for ( int itr = 0; itr < nTracks; itr++ ) {
559 AliHLTITSTrack &t = tracks[itr];
560 //cout<<"SG out:"<<tracksTPCId[t.TPCtrackId()]<<" "<<t.GetLabel()<<endl;
561 if( t.GetLabel()<0 ) continue;
562 int id = tracksTPCId[t.TPCtrackId()];
564 if ( blockSize + sizeof(AliHLTTrackMCLabel) > maxBufferSize ) {
565 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d mc labels are not stored", maxBufferSize, blockSize, nTracks - itr + 1 );
569 currOutLabel->fTrackID = id;
570 currOutLabel->fMCLabel = t.GetLabel();
571 blockSize += sizeof(AliHLTTrackMCLabel);
575 if( iResult>=0 && outPtr->fCount>0 ){
576 AliHLTComponentBlockData resultData;
577 FillBlockData( resultData );
578 resultData.fOffset = size;
579 resultData.fSize = blockSize;
580 resultData.fDataType = kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS;
581 outputBlocks.push_back( resultData );
582 size+= resultData.fSize;
588 // Set log level to "Warning" for on-line system monitoring
589 HLTInfo( "ITS Tracker: output %d tracks; input %d clusters, %d tracks",
590 nITSUpdated, nClustersTotal, tracksTPC.size() );
592 HLTInfo(fBenchmark.GetStatistics());