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 "AliHLTGlobalBarrelTrack.h"
51 #include "AliGeomManager.h"
55 /** ROOT macro for the implementation of ROOT specific class methods */
56 ClassImp( AliHLTITSTrackerComponent )
57 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
65 // see header file for class documentation
67 // refer to README to build package
69 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
72 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
81 // see header file for class documentation
82 HLTFatal( "copy constructor untested" );
85 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
87 // see header file for class documentation
88 HLTFatal( "assignment operator untested" );
92 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
94 // see header file for class documentation
99 // Public functions to implement AliHLTComponent's interface.
100 // These functions are required for the registration process
103 const char* AliHLTITSTrackerComponent::GetComponentID()
105 // see header file for class documentation
109 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
111 // see header file for class documentation
113 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
114 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
115 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
116 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
119 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
121 // see header file for class documentation
122 return kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
125 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
127 // define guess for the output data size
128 constBase = 200; // minimum size
129 inputMultiplier = 0.5; // size relative to input
132 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
134 // see header file for class documentation
135 return new AliHLTITSTrackerComponent;
138 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
140 // Set default configuration for the CA tracker component
141 // 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 return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
204 cdbEntry = "HLT/ConfigITS/ITSTracker";
205 defaultNotify = " (default)";
209 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
210 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
213 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
217 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
220 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
224 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
226 return ReadConfigurationString( pString->GetString().Data() );
230 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
232 // Configure the component
233 // There are few levels of configuration,
234 // parameters which are set on one step can be overwritten on the next step
236 //* read hard-coded values
238 SetDefaultConfiguration();
240 //* read the default CDB entry
242 int iResult1 = ReadCDBEntry( NULL, chainId );
244 //* read magnetic field
246 int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
248 //* read the actual CDB entry if required
250 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
252 //* read extra parameters from input (if they are)
256 if ( commandLine && commandLine[0] != '\0' ) {
257 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
258 iResult4 = ReadConfigurationString( commandLine );
261 // Initialise the tracker here
263 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
268 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
270 // Configure the ITS tracker component
272 if ( fTracker ) return EINPROGRESS;
274 if(AliGeomManager::GetGeometry()==NULL){
275 AliGeomManager::LoadGeometry();
278 fTracker = new AliITStrackerHLT(0);
280 TString arguments = "";
281 for ( int i = 0; i < argc; i++ ) {
282 if ( !arguments.IsNull() ) arguments += " ";
283 arguments += argv[i];
286 return Configure( NULL, NULL, arguments.Data() );
290 int AliHLTITSTrackerComponent::DoDeinit()
292 // see header file for class documentation
300 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
302 // Reconfigure the component from OCDB .
304 return Configure( cdbEntry, chainId, NULL );
309 int AliHLTITSTrackerComponent::DoEvent
311 const AliHLTComponentEventData& evtData,
312 const AliHLTComponentBlockData* blocks,
313 AliHLTComponentTriggerData& /*trigData*/,
314 AliHLTUInt8_t* outputPtr,
315 AliHLTUInt32_t& size,
316 vector<AliHLTComponentBlockData>& outputBlocks )
320 AliHLTUInt32_t maxBufferSize = size;
321 size = 0; // output size
323 if (!IsDataEvent()) return 0;
325 if ( evtData.fBlockCnt <= 0 ) {
326 HLTWarning( "no blocks in event" );
333 // Event reconstruction in ITS
337 int nBlocks = evtData.fBlockCnt;
340 vector< AliExternalTrackParam > tracksTPC;
341 vector< int > tracksTPCId;
342 std::vector<AliITSRecPoint> clusters;
344 //int currentTrackID = 0;
346 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
348 const AliHLTComponentBlockData* iter = blocks+ndx;
352 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
353 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
354 int nTracks = dataPtr->fCount;
355 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
356 for( int itr=0; itr<nTracks; itr++ ){
357 AliHLTGlobalBarrelTrack t(*currOutTrack);
358 tracksTPC.push_back( t );
359 tracksTPCId.push_back( currOutTrack->fTrackID );
360 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
361 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
368 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
369 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
370 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) )
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];
378 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
379 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
380 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
381 if( d.fLayer==4 ) hit[5] = -hit[5];
383 AliITSRecPoint p( lab, hit, info );
384 clusters.push_back( p );
388 }// end read input blocks
390 // 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()];
424 if( fTracker->Tracks()[itr].GetNumberOfClusters()>0 ) nITSUpdated++;
426 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
428 if ( mySize + dSize > maxBufferSize ) {
429 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
434 currOutTrack->fAlpha = tp.GetAlpha();
435 currOutTrack->fX = tp.GetX();
436 currOutTrack->fY = tp.GetY();
437 currOutTrack->fZ = tp.GetZ();
438 currOutTrack->fLastX = 0;
439 currOutTrack->fLastY = 0;
440 currOutTrack->fLastZ = 0;
441 currOutTrack->fq1Pt = tp.GetSigned1Pt();
442 currOutTrack->fSinPsi = tp.GetSnp();
443 currOutTrack->fTgl = tp.GetTgl();
444 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
445 currOutTrack->fTrackID = id;
446 currOutTrack->fFlags = 0;
447 currOutTrack->fNPoints = nClusters;
448 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
454 AliHLTComponentBlockData resultData;
455 FillBlockData( resultData );
456 resultData.fOffset = 0;
457 resultData.fSize = mySize;
458 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
459 outputBlocks.push_back( resultData );
460 size = resultData.fSize;
465 fFullTime += timer.RealTime();
466 fRecoTime += timerReco.RealTime();
469 // Set log level to "Warning" for on-line system monitoring
470 int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
471 int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
472 HLTInfo( "ITS Tracker: output %d tracks; input %d clusters, %d tracks; time: full %d / reco %d Hz",
473 nITSUpdated, clusters.size(), tracksTPC.size(), hz, hz1 );