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 "AliHLTTPCDefinitions.h"
41 #include "AliITStrackerHLT.h"
42 #include "AliHLTITSTrackDataHeader.h"
43 #include "AliHLTTPCDefinitions.h"
44 #include "AliHLTTPCTrackArray.h"
45 #include "AliHLTTPCTrackletDataFormat.h"
46 #include "AliHLTTPCTrack.h"
47 #include "AliHLTITSSpacePointData.h"
48 #include "AliHLTITSClusterDataFormat.h"
49 #include "AliHLTDataTypes.h"
53 /** ROOT macro for the implementation of ROOT specific class methods */
54 ClassImp( AliHLTITSTrackerComponent )
55 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
63 // see header file for class documentation
65 // refer to README to build package
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
79 // see header file for class documentation
80 HLTFatal( "copy constructor untested" );
83 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
85 // see header file for class documentation
86 HLTFatal( "assignment operator untested" );
90 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
92 // see header file for class documentation
97 // Public functions to implement AliHLTComponent's interface.
98 // These functions are required for the registration process
101 const char* AliHLTITSTrackerComponent::GetComponentID()
103 // see header file for class documentation
107 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
109 // see header file for class documentation
111 list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
112 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
113 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
116 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
118 // see header file for class documentation
119 return fgkITSTracksDataType;
122 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
124 // define guess for the output data size
125 constBase = 200; // minimum size
126 inputMultiplier = 0.5; // size relative to input
129 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
131 // see header file for class documentation
132 return new AliHLTITSTrackerComponent;
135 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
137 // Set default configuration for the CA tracker component
138 // Some parameters can be later overwritten from the OCDB
147 int AliHLTITSTrackerComponent::ReadConfigurationString( const char* arguments )
149 // Set configuration parameters for the CA tracker component from the string
152 if ( !arguments ) return iResult;
154 TString allArgs = arguments;
156 int bMissingParam = 0;
158 TObjArray* pTokens = allArgs.Tokenize( " " );
160 int nArgs = pTokens ? pTokens->GetEntries() : 0;
162 for ( int i = 0; i < nArgs; i++ ) {
163 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
164 if ( argument.IsNull() ) continue;
166 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
167 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
168 fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
169 HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
173 //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
174 //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
175 //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
176 //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
180 HLTError( "Unknown option \"%s\"", argument.Data() );
185 if ( bMissingParam ) {
186 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
194 int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
196 // see header file for class documentation
198 const char* defaultNotify = "";
201 cdbEntry = "HLT/ConfigITS/ITSTracker";
202 defaultNotify = " (default)";
206 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
207 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
210 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
214 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
217 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
221 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
223 return ReadConfigurationString( pString->GetString().Data() );
227 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
229 // Configure the component
230 // There are few levels of configuration,
231 // parameters which are set on one step can be overwritten on the next step
233 //* read hard-coded values
235 SetDefaultConfiguration();
237 //* read the default CDB entry
239 int iResult1 = ReadCDBEntry( NULL, chainId );
241 //* read magnetic field
243 int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
245 //* read the actual CDB entry if required
247 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
249 //* read extra parameters from input (if they are)
253 if ( commandLine && commandLine[0] != '\0' ) {
254 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
255 iResult4 = ReadConfigurationString( commandLine );
258 // Initialise the tracker here
260 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
265 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
267 // Configure the ITS tracker component
269 if ( fTracker ) return EINPROGRESS;
270 fTracker = new AliITStrackerHLT();
272 TString arguments = "";
273 for ( int i = 0; i < argc; i++ ) {
274 if ( !arguments.IsNull() ) arguments += " ";
275 arguments += argv[i];
278 return Configure( NULL, NULL, arguments.Data() );
282 int AliHLTITSTrackerComponent::DoDeinit()
284 // see header file for class documentation
292 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
294 // Reconfigure the component from OCDB .
296 return Configure( cdbEntry, chainId, NULL );
301 int AliHLTITSTrackerComponent::DoEvent
303 const AliHLTComponentEventData& evtData,
304 const AliHLTComponentBlockData* blocks,
305 AliHLTComponentTriggerData& /*trigData*/,
306 AliHLTUInt8_t* outputPtr,
307 AliHLTUInt32_t& size,
308 vector<AliHLTComponentBlockData>& outputBlocks )
312 AliHLTUInt32_t maxBufferSize = size;
313 size = 0; // output size
315 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
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 == AliHLTTPCDefinitions::fgkTracksDataType ){
347 AliHLTTPCTrackArray tracks;
348 AliHLTTPCTrackletData *inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
349 iResult=tracks.FillTracksChecked( inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, -1, 0 );
351 HLTError("internal mismatch in array");
355 for (int i=0; i<tracks.GetNTracks(); i++) {
356 AliHLTTPCTrack* pTrack = tracks[i];
357 if( !pTrack ) continue;
358 if( pTrack->Convert2AliKalmanTrack() ){
359 //HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());
362 tracksTPC.push_back( *pTrack );
363 tracksTPCId.push_back(currentTrackID++);
369 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
370 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) )
373 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
374 int nClusters = inPtr->fSpacePointCnt;
375 for( int icl=0; icl<nClusters; icl++ ){
376 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
380 p.SetSigmaY2( d.fSigmaY2 );
381 p.SetSigmaZ2( d.fSigmaZ2 );
382 p.SetSigmaYZ( d.fSigmaYZ );
386 p.SetLayer( d.fLayer );
387 p.SetDetectorIndex( d.fIndex );
388 p.SetLabel(0, d.fTracks[0] );
389 p.SetLabel(1, d.fTracks[1] );
390 p.SetLabel(2, d.fTracks[2] );
391 clusters.push_back( p );
395 }// end read input blocks
397 // set clusters to tracker
399 fTracker->LoadClusters( clusters );
401 // Reconstruct the event
403 TStopwatch timerReco;
405 fTracker->Reconstruct( tracksTPC );
409 // Fill output tracks
412 unsigned int mySize = 0;
414 // check if there was enough space in the output buffer
416 int nTracks = fTracker->Tracks().size();
417 mySize = sizeof( AliHLTITSTrackDataHeader ) + nTracks*sizeof( AliHLTITSTrackData );
418 if ( mySize > maxBufferSize ) {
423 AliHLTITSTrackDataHeader *outPtr = ( AliHLTITSTrackDataHeader* )( outputPtr );
424 outPtr->fTrackletCnt = nTracks;
425 AliHLTITSTrackData *tr = outPtr->fTracks;
426 for( int itr=0; itr<nTracks; itr++ ){
427 tr->fTrackParam = fTracker->Tracks()[itr];
428 tr->fTPCId = tracksTPCId[fTracker->Tracks()[itr].TPCtrackId()];
429 tr->fClusterIds[0] = 0;
430 tr->fClusterIds[1] = 0;
431 tr->fClusterIds[2] = 0;
432 tr->fClusterIds[3] = 0;
433 tr->fClusterIds[4] = 0;
434 tr->fClusterIds[5] = 0;
439 AliHLTComponentBlockData resultData;
440 FillBlockData( resultData );
441 resultData.fOffset = 0;
442 resultData.fSize = mySize;
443 resultData.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
444 outputBlocks.push_back( resultData );
445 size = resultData.fSize;
447 HLTInfo( "ITS tracker:: output %d tracks",nTracks );