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 int iResult2 = 0; //ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
253 fSolenoidBz = GetBz();
255 //* read the actual CDB entry if required
257 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
259 //* read extra parameters from input (if they are)
263 if ( commandLine && commandLine[0] != '\0' ) {
264 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
265 iResult4 = ReadConfigurationString( commandLine );
268 // Initialise the tracker here
270 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
275 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
277 // Configure the ITS tracker component
279 if ( fTracker ) return -EINPROGRESS;
281 if(AliGeomManager::GetGeometry()==NULL){
282 AliGeomManager::LoadGeometry();
284 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
286 TString arguments = "";
287 for ( int i = 0; i < argc; i++ ) {
288 if ( !arguments.IsNull() ) arguments += " ";
289 arguments += argv[i];
292 int ret = Configure( NULL, NULL, arguments.Data() );
295 if (!TGeoGlobalMagField::Instance()) {
296 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
301 fTracker = new AliITStrackerHLT(0);
303 fBenchmark.SetTimer(0,"total");
304 fBenchmark.SetTimer(1,"reco");
309 int AliHLTITSTrackerComponent::DoDeinit()
311 // see header file for class documentation
319 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
321 // Reconfigure the component from OCDB .
323 return Configure( cdbEntry, chainId, NULL );
328 int AliHLTITSTrackerComponent::DoEvent
330 const AliHLTComponentEventData& evtData,
331 const AliHLTComponentBlockData* blocks,
332 AliHLTComponentTriggerData& /*trigData*/,
333 AliHLTUInt8_t* outputPtr,
334 AliHLTUInt32_t& size,
335 vector<AliHLTComponentBlockData>& outputBlocks )
339 AliHLTUInt32_t maxBufferSize = size;
340 size = 0; // output size
342 if (!IsDataEvent()) return 0;
344 if ( evtData.fBlockCnt <= 0 ) {
345 HLTWarning( "no blocks in event" );
349 fBenchmark.StartNewEvent();
352 // Event reconstruction in ITS
356 int nBlocks = evtData.fBlockCnt;
359 vector< AliExternalTrackParam > tracksTPC;
360 vector< int > tracksTPCLab;
361 vector< int > tracksTPCId;
363 int nClustersTotal = 0;
365 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
367 const AliHLTComponentBlockData* iter = blocks+ndx;
369 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
370 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
371 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ||
372 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITS) )
374 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
375 nClustersTotal+=inPtr->fSpacePointCnt;
380 fTracker->StartLoadClusters(nClustersTotal);
382 // first read MC information (if present)
384 std::map<int,int> mcLabels;
386 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC);
387 pBlock!=NULL; pBlock=GetNextInputBlock()) {
389 fBenchmark.AddInput(pBlock->fSize);
391 AliHLTTrackMCData* dataPtr = reinterpret_cast<AliHLTTrackMCData*>( pBlock->fPtr );
392 if (sizeof(AliHLTTrackMCData)+dataPtr->fCount*sizeof(AliHLTTrackMCLabel)==pBlock->fSize) {
393 for( unsigned int il=0; il<dataPtr->fCount; il++ ){
394 AliHLTTrackMCLabel &lab = dataPtr->fLabels[il];
395 mcLabels[lab.fTrackID] = lab.fMCLabel;
398 HLTWarning("data mismatch in block %s (0x%08x): count %d, size %d -> ignoring track MC information",
399 DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification,
400 dataPtr->fCount, pBlock->fSize);
406 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
408 const AliHLTComponentBlockData* iter = blocks+ndx;
412 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
413 fBenchmark.AddInput(iter->fSize);
414 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
415 int nTracks = dataPtr->fCount;
416 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
417 for( int itr=0; itr<nTracks; itr++ ){
418 AliHLTGlobalBarrelTrack t(*currOutTrack);
420 if( mcLabels.find(currOutTrack->fTrackID)!=mcLabels.end() )
421 mcLabel = mcLabels[currOutTrack->fTrackID];
423 tracksTPC.push_back( t );
424 tracksTPCLab.push_back(mcLabel);
425 tracksTPCId.push_back( currOutTrack->fTrackID );
426 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
427 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
434 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
435 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
436 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ||
437 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITS) )
440 fBenchmark.AddInput(iter->fSize);
442 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
443 int nClusters = inPtr->fSpacePointCnt;
444 for( int icl=0; icl<nClusters; icl++ ){
445 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
447 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
448 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
449 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
450 if( d.fLayer==4 ) hit[5] = -hit[5];
451 fTracker->LoadCluster( AliITSRecPoint( lab, hit, info ) );
452 //cout<<"SG "<<d.fLayer<<" "<<d.fTracks[0]<<endl;
456 }// end read input blocks
458 // Reconstruct the event
461 fTracker->Reconstruct( &(tracksTPC[0]), &(tracksTPCLab[0]), tracksTPC.size() );
465 // Fill output tracks
469 for( int iOut=0; iOut<=1; iOut++ ){
471 unsigned int blockSize = 0;
473 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
474 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
476 blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outPtr );
478 if ( size + blockSize > maxBufferSize ) {
479 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, size + blockSize );
485 AliHLTITSTrack *tracks=0;
488 tracks = fTracker->Tracks();
489 nTracks = fTracker->NTracks();
491 tracks = fTracker->ITSOutTracks();
492 nTracks = fTracker->NITSOutTracks();
495 for ( int itr = 0; itr < nTracks; itr++ ) {
496 AliHLTITSTrack &t = tracks[itr];
497 int id = tracksTPCId[t.TPCtrackId()];
498 int nClusters = t.GetNumberOfClusters();
499 if( iOut==0 && nClusters>0 ) nITSUpdated++;
501 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
503 if ( size + blockSize + dSize > maxBufferSize ) {
504 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, size + blockSize + dSize, nTracks - itr + 1 );
509 currOutTrack->fAlpha = t.GetAlpha();
510 currOutTrack->fX = t.GetX();
511 currOutTrack->fY = t.GetY();
512 currOutTrack->fZ = t.GetZ();
513 currOutTrack->fLastX = 0;
514 currOutTrack->fLastY = 0;
515 currOutTrack->fLastZ = 0;
516 currOutTrack->fq1Pt = t.GetSigned1Pt();
517 currOutTrack->fSinPsi = t.GetSnp();
518 currOutTrack->fTgl = t.GetTgl();
519 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = t.GetCovariance()[i];
520 currOutTrack->fTrackID = id;
521 currOutTrack->fFlags = 0;
522 currOutTrack->fNPoints = nClusters;
523 for ( int i = 0; i < nClusters; i++ ) currOutTrack->fPointIDs[i] = t.GetClusterIndex( i );
524 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
530 AliHLTComponentBlockData resultData;
531 FillBlockData( resultData );
532 resultData.fOffset = size;
533 resultData.fSize = blockSize;
535 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
537 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut;
539 fBenchmark.AddOutput(resultData.fSize);
540 outputBlocks.push_back( resultData );
541 size += resultData.fSize;
547 unsigned int blockSize = 0;
549 AliHLTTrackMCData* outPtr = ( AliHLTTrackMCData* )( outputPtr +size );
550 AliHLTTrackMCLabel* currOutLabel = outPtr->fLabels;
552 blockSize = ( ( AliHLTUInt8_t * )currOutLabel ) - ( ( AliHLTUInt8_t * )outPtr );
556 AliHLTITSTrack *tracks= fTracker->Tracks();
557 int nTracks = fTracker->NTracks();
559 for ( int itr = 0; itr < nTracks; itr++ ) {
560 AliHLTITSTrack &t = tracks[itr];
561 //cout<<"SG out:"<<tracksTPCId[t.TPCtrackId()]<<" "<<t.GetLabel()<<endl;
562 if( t.GetLabel()<0 ) continue;
563 int id = tracksTPCId[t.TPCtrackId()];
565 if ( blockSize + sizeof(AliHLTTrackMCLabel) > maxBufferSize ) {
566 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d mc labels are not stored", maxBufferSize, blockSize, nTracks - itr + 1 );
570 currOutLabel->fTrackID = id;
571 currOutLabel->fMCLabel = t.GetLabel();
572 blockSize += sizeof(AliHLTTrackMCLabel);
577 AliHLTComponentBlockData resultData;
578 FillBlockData( resultData );
579 resultData.fOffset = size;
580 resultData.fSize = blockSize;
581 resultData.fDataType = kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS;
582 outputBlocks.push_back( resultData );
583 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());