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 "TObjString.h"
44 #include "TObjArray.h"
45 #include "AliITStrackerHLT.h"
46 #include "AliHLTITSSpacePointData.h"
47 #include "AliHLTITSClusterDataFormat.h"
48 #include "AliHLTDataTypes.h"
49 #include "AliHLTExternalTrackParam.h"
50 #include "AliHLTKalmanTrack.h"
54 /** ROOT macro for the implementation of ROOT specific class methods */
55 ClassImp( AliHLTITSTrackerComponent )
56 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
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& )
80 // see header file for class documentation
81 HLTFatal( "copy constructor untested" );
84 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
86 // see header file for class documentation
87 HLTFatal( "assignment operator untested" );
91 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
93 // see header file for class documentation
98 // Public functions to implement AliHLTComponent's interface.
99 // These functions are required for the registration process
102 const char* AliHLTITSTrackerComponent::GetComponentID()
104 // see header file for class documentation
108 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
110 // see header file for class documentation
112 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
113 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
114 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
115 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
118 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
120 // see header file for class documentation
121 return kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
124 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
126 // define guess for the output data size
127 constBase = 200; // minimum size
128 inputMultiplier = 0.5; // size relative to input
131 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
133 // see header file for class documentation
134 return new AliHLTITSTrackerComponent;
137 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
139 // Set default configuration for the CA tracker component
140 // Some parameters can be later overwritten from the OCDB
149 int AliHLTITSTrackerComponent::ReadConfigurationString( const char* arguments )
151 // Set configuration parameters for the CA tracker component from the string
154 if ( !arguments ) return iResult;
156 TString allArgs = arguments;
158 int bMissingParam = 0;
160 TObjArray* pTokens = allArgs.Tokenize( " " );
162 int nArgs = pTokens ? pTokens->GetEntries() : 0;
164 for ( int i = 0; i < nArgs; i++ ) {
165 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
166 if ( argument.IsNull() ) continue;
168 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
169 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
170 fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
171 HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
175 //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
176 //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
177 //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
178 //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
182 HLTError( "Unknown option \"%s\"", argument.Data() );
187 if ( bMissingParam ) {
188 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
196 int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
198 // see header file for class documentation
200 const char* defaultNotify = "";
203 cdbEntry = "HLT/ConfigITS/ITSTracker";
204 defaultNotify = " (default)";
208 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
209 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
212 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
216 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
219 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
223 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
225 return ReadConfigurationString( pString->GetString().Data() );
229 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
231 // Configure the component
232 // There are few levels of configuration,
233 // parameters which are set on one step can be overwritten on the next step
235 //* read hard-coded values
237 SetDefaultConfiguration();
239 //* read the default CDB entry
241 int iResult1 = ReadCDBEntry( NULL, chainId );
243 //* read magnetic field
245 int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
247 //* read the actual CDB entry if required
249 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
251 //* read extra parameters from input (if they are)
255 if ( commandLine && commandLine[0] != '\0' ) {
256 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
257 iResult4 = ReadConfigurationString( commandLine );
260 // Initialise the tracker here
262 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
267 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
269 // Configure the ITS tracker component
271 if ( fTracker ) return EINPROGRESS;
272 fTracker = new AliITStrackerHLT(0);
274 TString arguments = "";
275 for ( int i = 0; i < argc; i++ ) {
276 if ( !arguments.IsNull() ) arguments += " ";
277 arguments += argv[i];
280 return Configure( NULL, NULL, arguments.Data() );
284 int AliHLTITSTrackerComponent::DoDeinit()
286 // see header file for class documentation
294 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
296 // Reconfigure the component from OCDB .
298 return Configure( cdbEntry, chainId, NULL );
303 int AliHLTITSTrackerComponent::DoEvent
305 const AliHLTComponentEventData& evtData,
306 const AliHLTComponentBlockData* blocks,
307 AliHLTComponentTriggerData& /*trigData*/,
308 AliHLTUInt8_t* outputPtr,
309 AliHLTUInt32_t& size,
310 vector<AliHLTComponentBlockData>& outputBlocks )
314 AliHLTUInt32_t maxBufferSize = size;
315 size = 0; // output size
317 if (!IsDataEvent()) return 0;
319 if ( evtData.fBlockCnt <= 0 ) {
320 HLTWarning( "no blocks in event" );
327 // Event reconstruction in ITS
331 int nBlocks = evtData.fBlockCnt;
334 vector< AliExternalTrackParam > tracksTPC;
335 vector< int > tracksTPCId;
336 std::vector<AliITSRecPoint> clusters;
338 //int currentTrackID = 0;
340 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
342 const AliHLTComponentBlockData* iter = blocks+ndx;
346 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
347 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
348 int nTracks = dataPtr->fCount;
349 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
350 for( int itr=0; itr<nTracks; itr++ ){
351 AliHLTKalmanTrack t(*currOutTrack);
352 tracksTPC.push_back( t );
353 tracksTPCId.push_back( currOutTrack->fTrackID );
354 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
355 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
362 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
363 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
364 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) )
367 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
368 int nClusters = inPtr->fSpacePointCnt;
369 for( int icl=0; icl<nClusters; icl++ ){
370 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
374 p.SetSigmaY2( d.fSigmaY2 );
375 p.SetSigmaZ2( d.fSigmaZ2 );
376 p.SetSigmaYZ( d.fSigmaYZ );
380 p.SetLayer( d.fLayer );
381 p.SetDetectorIndex( d.fIndex );
382 p.SetLabel(0, d.fTracks[0] );
383 p.SetLabel(1, d.fTracks[1] );
384 p.SetLabel(2, d.fTracks[2] );
385 clusters.push_back( p );
389 }// end read input blocks
391 // set clusters to tracker
393 fTracker->LoadClusters( clusters );
395 // Reconstruct the event
397 TStopwatch timerReco;
399 fTracker->Reconstruct( tracksTPC );
403 // Fill output tracks
406 unsigned int mySize = 0;
408 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr );
410 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
412 mySize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outputPtr );
416 int nTracks = fTracker->Tracks().size();
418 for ( int itr = 0; itr < nTracks; itr++ ) {
420 const AliExternalTrackParam &tp = fTracker->Tracks()[itr];
421 int id = tracksTPCId[fTracker->Tracks()[itr].TPCtrackId()];
425 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
427 if ( mySize + dSize > maxBufferSize ) {
428 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
433 currOutTrack->fAlpha = tp.GetAlpha();
434 currOutTrack->fX = tp.GetX();
435 currOutTrack->fY = tp.GetY();
436 currOutTrack->fZ = tp.GetZ();
437 currOutTrack->fLastX = 0;
438 currOutTrack->fLastY = 0;
439 currOutTrack->fLastZ = 0;
440 currOutTrack->fq1Pt = tp.GetSigned1Pt();
441 currOutTrack->fSinPsi = tp.GetSnp();
442 currOutTrack->fTgl = tp.GetTgl();
443 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
444 currOutTrack->fTrackID = id;
445 currOutTrack->fFlags = 0;
446 currOutTrack->fNPoints = nClusters;
447 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
453 AliHLTComponentBlockData resultData;
454 FillBlockData( resultData );
455 resultData.fOffset = 0;
456 resultData.fSize = mySize;
457 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
458 outputBlocks.push_back( resultData );
459 size = resultData.fSize;
461 HLTInfo( "ITS tracker:: output %d tracks",nTracks );