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 //***************************************************************************
21 /////////////////////////////////////////////////////
23 // a ITS tracker processing component for the HLT //
25 /////////////////////////////////////////////////////
31 #include "AliHLTITSTrackerComponent.h"
32 #include "AliHLTArray.h"
33 #include "AliExternalTrackParam.h"
34 #include "TStopwatch.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBManager.h"
38 #include "TObjString.h"
39 #include "TObjArray.h"
40 #include "AliITStrackerHLT.h"
41 #include "AliHLTITSSpacePointData.h"
42 #include "AliHLTITSClusterDataFormat.h"
43 #include "AliHLTDataTypes.h"
44 #include "AliHLTExternalTrackParam.h"
45 #include "AliHLTKalmanTrack.h"
49 /** ROOT macro for the implementation of ROOT specific class methods */
50 ClassImp( AliHLTITSTrackerComponent )
51 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
59 // see header file for class documentation
61 // refer to README to build package
63 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
75 // see header file for class documentation
76 HLTFatal( "copy constructor untested" );
79 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
81 // see header file for class documentation
82 HLTFatal( "assignment operator untested" );
86 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
88 // see header file for class documentation
93 // Public functions to implement AliHLTComponent's interface.
94 // These functions are required for the registration process
97 const char* AliHLTITSTrackerComponent::GetComponentID()
99 // see header file for class documentation
103 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
105 // see header file for class documentation
107 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
108 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
109 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
112 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
114 // see header file for class documentation
115 return kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
118 void AliHLTITSTrackerComponent::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* AliHLTITSTrackerComponent::Spawn()
127 // see header file for class documentation
128 return new AliHLTITSTrackerComponent;
131 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
133 // Set default configuration for the CA tracker component
134 // Some parameters can be later overwritten from the OCDB
143 int AliHLTITSTrackerComponent::ReadConfigurationString( const char* arguments )
145 // Set configuration parameters for the CA tracker component from the string
148 if ( !arguments ) return iResult;
150 TString allArgs = arguments;
152 int bMissingParam = 0;
154 TObjArray* pTokens = allArgs.Tokenize( " " );
156 int nArgs = pTokens ? pTokens->GetEntries() : 0;
158 for ( int i = 0; i < nArgs; i++ ) {
159 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
160 if ( argument.IsNull() ) continue;
162 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
163 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
164 fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
165 HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
169 //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
170 //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
171 //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
172 //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
176 HLTError( "Unknown option \"%s\"", argument.Data() );
181 if ( bMissingParam ) {
182 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
190 int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
192 // see header file for class documentation
194 const char* defaultNotify = "";
197 cdbEntry = "HLT/ConfigITS/ITSTracker";
198 defaultNotify = " (default)";
202 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
203 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
206 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
210 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
213 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
217 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
219 return ReadConfigurationString( pString->GetString().Data() );
223 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
225 // Configure the component
226 // There are few levels of configuration,
227 // parameters which are set on one step can be overwritten on the next step
229 //* read hard-coded values
231 SetDefaultConfiguration();
233 //* read the default CDB entry
235 int iResult1 = ReadCDBEntry( NULL, chainId );
237 //* read magnetic field
239 int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
241 //* read the actual CDB entry if required
243 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
245 //* read extra parameters from input (if they are)
249 if ( commandLine && commandLine[0] != '\0' ) {
250 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
251 iResult4 = ReadConfigurationString( commandLine );
254 // Initialise the tracker here
256 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
261 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
263 // Configure the ITS tracker component
265 if ( fTracker ) return EINPROGRESS;
266 fTracker = new AliITStrackerHLT(0);
268 TString arguments = "";
269 for ( int i = 0; i < argc; i++ ) {
270 if ( !arguments.IsNull() ) arguments += " ";
271 arguments += argv[i];
274 return Configure( NULL, NULL, arguments.Data() );
278 int AliHLTITSTrackerComponent::DoDeinit()
280 // see header file for class documentation
288 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
290 // Reconfigure the component from OCDB .
292 return Configure( cdbEntry, chainId, NULL );
297 int AliHLTITSTrackerComponent::DoEvent
299 const AliHLTComponentEventData& evtData,
300 const AliHLTComponentBlockData* blocks,
301 AliHLTComponentTriggerData& /*trigData*/,
302 AliHLTUInt8_t* outputPtr,
303 AliHLTUInt32_t& size,
304 vector<AliHLTComponentBlockData>& outputBlocks )
308 AliHLTUInt32_t maxBufferSize = size;
309 size = 0; // output size
311 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
315 if ( evtData.fBlockCnt <= 0 ) {
316 HLTWarning( "no blocks in event" );
323 // Event reconstruction in ITS
327 int nBlocks = evtData.fBlockCnt;
330 vector< AliExternalTrackParam > tracksTPC;
331 vector< int > tracksTPCId;
332 std::vector<AliITSRecPoint> clusters;
334 //int currentTrackID = 0;
336 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
338 const AliHLTComponentBlockData* iter = blocks+ndx;
342 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
343 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
344 int nTracks = dataPtr->fCount;
345 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
346 for( int itr=0; itr<nTracks; itr++ ){
347 AliHLTKalmanTrack t(*currOutTrack);
348 tracksTPC.push_back( t );
349 tracksTPCId.push_back( currOutTrack->fTrackID );
350 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
351 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
358 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
359 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) )
362 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
363 int nClusters = inPtr->fSpacePointCnt;
364 for( int icl=0; icl<nClusters; icl++ ){
365 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
369 p.SetSigmaY2( d.fSigmaY2 );
370 p.SetSigmaZ2( d.fSigmaZ2 );
371 p.SetSigmaYZ( d.fSigmaYZ );
375 p.SetLayer( d.fLayer );
376 p.SetDetectorIndex( d.fIndex );
377 p.SetLabel(0, d.fTracks[0] );
378 p.SetLabel(1, d.fTracks[1] );
379 p.SetLabel(2, d.fTracks[2] );
380 clusters.push_back( p );
384 }// end read input blocks
386 // set clusters to tracker
388 fTracker->LoadClusters( clusters );
390 // Reconstruct the event
392 TStopwatch timerReco;
394 fTracker->Reconstruct( tracksTPC );
398 // Fill output tracks
401 unsigned int mySize = 0;
403 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr );
405 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
407 mySize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outputPtr );
411 int nTracks = fTracker->Tracks().size();
413 for ( int itr = 0; itr < nTracks; itr++ ) {
415 const AliExternalTrackParam &tp = fTracker->Tracks()[itr];
416 int id = tracksTPCId[fTracker->Tracks()[itr].TPCtrackId()];
420 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
422 if ( mySize + dSize > maxBufferSize ) {
423 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
428 currOutTrack->fAlpha = tp.GetAlpha();
429 currOutTrack->fX = tp.GetX();
430 currOutTrack->fY = tp.GetY();
431 currOutTrack->fZ = tp.GetZ();
432 currOutTrack->fLastX = 0;
433 currOutTrack->fLastY = 0;
434 currOutTrack->fLastZ = 0;
435 currOutTrack->fq1Pt = tp.GetSigned1Pt();
436 currOutTrack->fSinPsi = tp.GetSnp();
437 currOutTrack->fTgl = tp.GetTgl();
438 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
439 currOutTrack->fTrackID = id;
440 currOutTrack->fFlags = 0;
441 currOutTrack->fNPoints = nClusters;
442 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
448 AliHLTComponentBlockData resultData;
449 FillBlockData( resultData );
450 resultData.fOffset = 0;
451 resultData.fSize = mySize;
452 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
453 outputBlocks.push_back( resultData );
454 size = resultData.fSize;
456 HLTInfo( "ITS tracker:: output %d tracks",nTracks );