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"
56 /** ROOT macro for the implementation of ROOT specific class methods */
57 ClassImp( AliHLTITSTrackerComponent )
58 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
66 // see header file for class documentation
68 // refer to README to build package
70 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
82 // see header file for class documentation
83 HLTFatal( "copy constructor untested" );
86 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
88 // see header file for class documentation
89 HLTFatal( "assignment operator untested" );
93 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
95 // see header file for class documentation
100 // Public functions to implement AliHLTComponent's interface.
101 // These functions are required for the registration process
104 const char* AliHLTITSTrackerComponent::GetComponentID()
106 // see header file for class documentation
110 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
112 // see header file for class documentation
114 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
115 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
116 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
117 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
120 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
122 // see header file for class documentation
123 return kAliHLTMultipleDataType;
126 int AliHLTITSTrackerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
128 // see header file for class documentation
130 tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
131 tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
132 return tgtList.size();
135 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
137 // define guess for the output data size
138 constBase = 200; // minimum size
139 inputMultiplier = 2.; // size relative to input
142 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
144 // see header file for class documentation
145 return new AliHLTITSTrackerComponent;
148 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
150 // Set default configuration for the CA tracker component
151 // Some parameters can be later overwritten from the OCDB
153 fSolenoidBz = -5.00668;
159 int AliHLTITSTrackerComponent::ReadConfigurationString( const char* arguments )
161 // Set configuration parameters for the CA tracker component from the string
164 if ( !arguments ) return iResult;
166 TString allArgs = arguments;
168 int bMissingParam = 0;
170 TObjArray* pTokens = allArgs.Tokenize( " " );
172 int nArgs = pTokens ? pTokens->GetEntries() : 0;
174 for ( int i = 0; i < nArgs; i++ ) {
175 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
176 if ( argument.IsNull() ) continue;
178 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
179 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
180 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
184 //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
185 //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
186 //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
187 //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
191 HLTError( "Unknown option \"%s\"", argument.Data() );
196 if ( bMissingParam ) {
197 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
205 int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
207 // see header file for class documentation
209 const char* defaultNotify = "";
212 return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
213 cdbEntry = "HLT/ConfigITS/ITSTracker";
214 defaultNotify = " (default)";
218 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
219 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
222 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
226 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
229 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
233 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
235 return ReadConfigurationString( pString->GetString().Data() );
239 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
241 // Configure the component
242 // There are few levels of configuration,
243 // parameters which are set on one step can be overwritten on the next step
245 //* read hard-coded values
247 SetDefaultConfiguration();
249 //* read the default CDB entry
251 int iResult1 = ReadCDBEntry( NULL, chainId );
253 //* read magnetic field
255 int iResult2 = 0; //ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
256 fSolenoidBz = GetBz();
258 //* read the actual CDB entry if required
260 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
262 //* read extra parameters from input (if they are)
266 if ( commandLine && commandLine[0] != '\0' ) {
267 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
268 iResult4 = ReadConfigurationString( commandLine );
271 // Initialise the tracker here
273 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
278 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
280 // Configure the ITS tracker component
282 if ( fTracker ) return -EINPROGRESS;
284 if(AliGeomManager::GetGeometry()==NULL){
285 AliGeomManager::LoadGeometry();
287 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
289 TString arguments = "";
290 for ( int i = 0; i < argc; i++ ) {
291 if ( !arguments.IsNull() ) arguments += " ";
292 arguments += argv[i];
295 int ret = Configure( NULL, NULL, arguments.Data() );
298 if (!TGeoGlobalMagField::Instance()) {
299 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
304 fTracker = new AliITStrackerHLT(0);
310 int AliHLTITSTrackerComponent::DoDeinit()
312 // see header file for class documentation
320 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
322 // Reconfigure the component from OCDB .
324 return Configure( cdbEntry, chainId, NULL );
329 int AliHLTITSTrackerComponent::DoEvent
331 const AliHLTComponentEventData& evtData,
332 const AliHLTComponentBlockData* blocks,
333 AliHLTComponentTriggerData& /*trigData*/,
334 AliHLTUInt8_t* outputPtr,
335 AliHLTUInt32_t& size,
336 vector<AliHLTComponentBlockData>& outputBlocks )
340 AliHLTUInt32_t maxBufferSize = size;
341 size = 0; // output size
343 if (!IsDataEvent()) return 0;
345 if ( evtData.fBlockCnt <= 0 ) {
346 HLTWarning( "no blocks in event" );
353 // Event reconstruction in ITS
357 int nBlocks = evtData.fBlockCnt;
360 vector< AliExternalTrackParam > tracksTPC;
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) )
373 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
374 nClustersTotal+=inPtr->fSpacePointCnt;
379 fTracker->StartLoadClusters(nClustersTotal);
381 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
383 const AliHLTComponentBlockData* iter = blocks+ndx;
387 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
388 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
389 int nTracks = dataPtr->fCount;
390 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
391 for( int itr=0; itr<nTracks; itr++ ){
392 AliHLTGlobalBarrelTrack t(*currOutTrack);
393 tracksTPC.push_back( t );
394 tracksTPCId.push_back( currOutTrack->fTrackID );
395 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
396 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
403 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
404 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
405 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) )
408 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
409 int nClusters = inPtr->fSpacePointCnt;
410 for( int icl=0; icl<nClusters; icl++ ){
411 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
413 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
414 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
415 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
416 if( d.fLayer==4 ) hit[5] = -hit[5];
417 fTracker->LoadCluster( AliITSRecPoint( lab, hit, info ) );
421 }// end read input blocks
423 // Reconstruct the event
425 TStopwatch timerReco;
427 fTracker->Reconstruct( &(tracksTPC[0]), tracksTPC.size() );
431 // Fill output tracks
435 for( int iOut=0; iOut<=1; iOut++ ){
437 unsigned int blockSize = 0;
439 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
440 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
442 blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outPtr );
444 if ( size + blockSize > maxBufferSize ) {
445 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, size + blockSize );
451 AliHLTITSTrack *tracks=0;
454 tracks = fTracker->Tracks();
455 nTracks = fTracker->NTracks();
457 tracks = fTracker->ITSOutTracks();
458 nTracks = fTracker->NITSOutTracks();
461 for ( int itr = 0; itr < nTracks; itr++ ) {
462 AliHLTITSTrack &t = tracks[itr];
463 int id = tracksTPCId[t.TPCtrackId()];
464 int nClusters = t.GetNumberOfClusters();
465 if( iOut==0 && nClusters>0 ) nITSUpdated++;
467 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
469 if ( size + blockSize + dSize > maxBufferSize ) {
470 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, size + blockSize + dSize, nTracks - itr + 1 );
475 currOutTrack->fAlpha = t.GetAlpha();
476 currOutTrack->fX = t.GetX();
477 currOutTrack->fY = t.GetY();
478 currOutTrack->fZ = t.GetZ();
479 currOutTrack->fLastX = 0;
480 currOutTrack->fLastY = 0;
481 currOutTrack->fLastZ = 0;
482 currOutTrack->fq1Pt = t.GetSigned1Pt();
483 currOutTrack->fSinPsi = t.GetSnp();
484 currOutTrack->fTgl = t.GetTgl();
485 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = t.GetCovariance()[i];
486 currOutTrack->fTrackID = id;
487 currOutTrack->fFlags = 0;
488 currOutTrack->fNPoints = nClusters;
489 for ( int i = 0; i < nClusters; i++ ) currOutTrack->fPointIDs[i] = t.GetClusterIndex( i );
490 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
496 AliHLTComponentBlockData resultData;
497 FillBlockData( resultData );
498 resultData.fOffset = 0;
499 resultData.fSize = blockSize;
501 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
503 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut;
505 outputBlocks.push_back( resultData );
506 size += resultData.fSize;
511 fFullTime += timer.RealTime();
512 fRecoTime += timerReco.RealTime();
515 // Set log level to "Warning" for on-line system monitoring
516 int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
517 int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
518 HLTInfo( "ITS Tracker: output %d tracks; input %d clusters, %d tracks; time: full %d / reco %d Hz",
519 nITSUpdated, nClustersTotal, tracksTPC.size(), hz, hz1 );