]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/ITS/tracking/AliHLTITSTrackerComponent.cxx
extra benchmarks are added
[u/mrichter/AliRoot.git] / HLT / ITS / tracking / AliHLTITSTrackerComponent.cxx
CommitLineData
21de9ddd 1// $Id: AliHLTITSTrackerComponent.cxx 32659 2009-06-02 16:08:40Z sgorbuno $
6edb0fb5 2// **************************************************************************
3// This file is property of and copyright by the ALICE HLT Project *
4// ALICE Experiment at CERN, All rights reserved. *
5// *
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. *
9// *
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. *
17// *
18//***************************************************************************
19
21de9ddd 20/// @file AliHLTITSTrackerComponent.cxx
21/// @author Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de>
22/// @date June 2009
23/// @brief An ITS tracker processing component for the HLT
24
6edb0fb5 25
26/////////////////////////////////////////////////////
27// //
28// a ITS tracker processing component for the HLT //
29// //
30/////////////////////////////////////////////////////
31
32#if __GNUC__>= 3
33using namespace std;
34#endif
35
36#include "AliHLTITSTrackerComponent.h"
37#include "AliHLTArray.h"
38#include "AliExternalTrackParam.h"
39#include "TStopwatch.h"
40#include "TMath.h"
41#include "AliCDBEntry.h"
42#include "AliCDBManager.h"
1b4a9c5a 43#include "AliGeomManager.h"
6edb0fb5 44#include "TObjString.h"
45#include "TObjArray.h"
6edb0fb5 46#include "AliITStrackerHLT.h"
6edb0fb5 47#include "AliHLTITSSpacePointData.h"
48#include "AliHLTITSClusterDataFormat.h"
49#include "AliHLTDataTypes.h"
9af5a71c 50#include "AliHLTExternalTrackParam.h"
0cd1ba6e 51#include "AliHLTGlobalBarrelTrack.h"
31822224 52#include "AliGeomManager.h"
6edb0fb5 53
54
55
56/** ROOT macro for the implementation of ROOT specific class methods */
57ClassImp( AliHLTITSTrackerComponent )
58AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
59 :
60 fSolenoidBz( 0 ),
57a4102f 61 fBenchmark("ITSTracker"),
6edb0fb5 62 fTracker(0)
63{
64 // see header file for class documentation
65 // or
66 // refer to README to build package
67 // or
68 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
69}
70
71AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
72 :
73 AliHLTProcessor(),
74 fSolenoidBz( 0 ),
57a4102f 75 fBenchmark("ITSTracker"),
6edb0fb5 76 fTracker(0)
77{
78 // see header file for class documentation
79 HLTFatal( "copy constructor untested" );
80}
81
82AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
83{
84 // see header file for class documentation
85 HLTFatal( "assignment operator untested" );
86 return *this;
87}
88
89AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
90{
91 // see header file for class documentation
92 delete fTracker;
93}
94
95//
96// Public functions to implement AliHLTComponent's interface.
97// These functions are required for the registration process
98//
99
100const char* AliHLTITSTrackerComponent::GetComponentID()
101{
102 // see header file for class documentation
103 return "ITSTracker";
104}
105
106void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
107{
108 // see header file for class documentation
109 list.clear();
9af5a71c 110 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
6edb0fb5 111 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
112 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
21de9ddd 113 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
6edb0fb5 114}
115
116AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
117{
118 // see header file for class documentation
b7ed2eb4 119 return kAliHLTMultipleDataType;
120}
121
122int AliHLTITSTrackerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
123{
124 // see header file for class documentation
125 tgtList.clear();
126 tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
127 tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut);
128 return tgtList.size();
6edb0fb5 129}
130
131void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
132{
133 // define guess for the output data size
134 constBase = 200; // minimum size
04652fd8 135 inputMultiplier = 2.; // size relative to input
6edb0fb5 136}
137
138AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
139{
140 // see header file for class documentation
141 return new AliHLTITSTrackerComponent;
142}
143
144void AliHLTITSTrackerComponent::SetDefaultConfiguration()
145{
146 // Set default configuration for the CA tracker component
147 // Some parameters can be later overwritten from the OCDB
148
a8714ffa 149 fSolenoidBz = -5.00668;
57a4102f 150
6edb0fb5 151}
152
153int AliHLTITSTrackerComponent::ReadConfigurationString( const char* arguments )
154{
155 // Set configuration parameters for the CA tracker component from the string
156
157 int iResult = 0;
158 if ( !arguments ) return iResult;
159
160 TString allArgs = arguments;
161 TString argument;
162 int bMissingParam = 0;
163
164 TObjArray* pTokens = allArgs.Tokenize( " " );
165
166 int nArgs = pTokens ? pTokens->GetEntries() : 0;
167
168 for ( int i = 0; i < nArgs; i++ ) {
169 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
170 if ( argument.IsNull() ) continue;
171
172 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
173 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
75970b8d 174 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
6edb0fb5 175 continue;
176 }
177
178 //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
179 //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
180 //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
181 //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
182 //continue;
183 //}
184
185 HLTError( "Unknown option \"%s\"", argument.Data() );
186 iResult = -EINVAL;
187 }
188 delete pTokens;
189
190 if ( bMissingParam ) {
191 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
192 iResult = -EINVAL;
193 }
194
195 return iResult;
196}
197
198
199int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
200{
201 // see header file for class documentation
202
203 const char* defaultNotify = "";
204
205 if ( !cdbEntry ) {
9eee44f6 206 return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
6edb0fb5 207 cdbEntry = "HLT/ConfigITS/ITSTracker";
208 defaultNotify = " (default)";
209 chainId = 0;
210 }
211
212 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
213 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
214
215 if ( !pEntry ) {
216 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
217 return -EINVAL;
218 }
219
220 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
221
222 if ( !pString ) {
223 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
224 return -EINVAL;
225 }
226
227 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
228
229 return ReadConfigurationString( pString->GetString().Data() );
230}
231
232
233int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
234{
235 // Configure the component
236 // There are few levels of configuration,
237 // parameters which are set on one step can be overwritten on the next step
238
239 //* read hard-coded values
240
241 SetDefaultConfiguration();
242
243 //* read the default CDB entry
244
245 int iResult1 = ReadCDBEntry( NULL, chainId );
246
247 //* read magnetic field
248
a098ab46 249 int iResult2 = 0; //ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
75970b8d 250 fSolenoidBz = GetBz();
6edb0fb5 251
252 //* read the actual CDB entry if required
253
254 int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
255
256 //* read extra parameters from input (if they are)
257
258 int iResult4 = 0;
259
260 if ( commandLine && commandLine[0] != '\0' ) {
261 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
262 iResult4 = ReadConfigurationString( commandLine );
263 }
264
265 // Initialise the tracker here
266
267 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
268}
269
270
271
272int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
273{
274 // Configure the ITS tracker component
275
75970b8d 276 if ( fTracker ) return -EINPROGRESS;
fb015741 277
278 if(AliGeomManager::GetGeometry()==NULL){
279 AliGeomManager::LoadGeometry();
280 }
24a9f989 281 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
fb015741 282
6edb0fb5 283 TString arguments = "";
284 for ( int i = 0; i < argc; i++ ) {
285 if ( !arguments.IsNull() ) arguments += " ";
286 arguments += argv[i];
287 }
288
b55698e6 289 int ret = Configure( NULL, NULL, arguments.Data() );
290
75970b8d 291 // Check field
292 if (!TGeoGlobalMagField::Instance()) {
293 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
294 return -ENODEV;
b55698e6 295 }
75970b8d 296 fSolenoidBz=GetBz();
297
b55698e6 298 fTracker = new AliITStrackerHLT(0);
57a4102f 299 fBenchmark.Reset();
300 fBenchmark.SetTimer(0,"total");
301 fBenchmark.SetTimer(1,"reco");
b55698e6 302 return ret;
6edb0fb5 303}
304
305
306int AliHLTITSTrackerComponent::DoDeinit()
307{
308 // see header file for class documentation
309 delete fTracker;
310 fTracker = 0;
311 return 0;
312}
313
314
315
316int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
317{
318 // Reconfigure the component from OCDB .
319
320 return Configure( cdbEntry, chainId, NULL );
321}
322
323
324
325int AliHLTITSTrackerComponent::DoEvent
326(
327 const AliHLTComponentEventData& evtData,
328 const AliHLTComponentBlockData* blocks,
329 AliHLTComponentTriggerData& /*trigData*/,
330 AliHLTUInt8_t* outputPtr,
331 AliHLTUInt32_t& size,
332 vector<AliHLTComponentBlockData>& outputBlocks )
333{
334 //* process event
335
336 AliHLTUInt32_t maxBufferSize = size;
337 size = 0; // output size
365eee5d 338
21de9ddd 339 if (!IsDataEvent()) return 0;
6edb0fb5 340
341 if ( evtData.fBlockCnt <= 0 ) {
342 HLTWarning( "no blocks in event" );
343 return 0;
344 }
345
57a4102f 346 fBenchmark.StartNewEvent();
347 fBenchmark.Start(0);
6edb0fb5 348
349 // Event reconstruction in ITS
350
351 int iResult=0;
352
353 int nBlocks = evtData.fBlockCnt;
354
355
356 vector< AliExternalTrackParam > tracksTPC;
357 vector< int > tracksTPCId;
ef6e2aa2 358
ef6e2aa2 359 int nClustersTotal = 0;
6edb0fb5 360
365eee5d 361 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
362
363 const AliHLTComponentBlockData* iter = blocks+ndx;
364
365 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
366 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
367 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) )
368 ){
369 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
370 nClustersTotal+=inPtr->fSpacePointCnt;
371 }
372 }
373
374
375 fTracker->StartLoadClusters(nClustersTotal);
6edb0fb5 376
377 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
378
379 const AliHLTComponentBlockData* iter = blocks+ndx;
380
381 // Read TPC tracks
9af5a71c 382
383 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
57a4102f 384 fBenchmark.AddInput(iter->fSize);
9af5a71c 385 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
386 int nTracks = dataPtr->fCount;
387 AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
388 for( int itr=0; itr<nTracks; itr++ ){
0cd1ba6e 389 AliHLTGlobalBarrelTrack t(*currOutTrack);
9af5a71c 390 tracksTPC.push_back( t );
391 tracksTPCId.push_back( currOutTrack->fTrackID );
392 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
393 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
6edb0fb5 394 }
395 }
396
9af5a71c 397
6edb0fb5 398 // Read ITS clusters
399
400 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
21de9ddd 401 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
402 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) )
6edb0fb5 403 ){
57a4102f 404
405 fBenchmark.AddInput(iter->fSize);
6edb0fb5 406
407 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
408 int nClusters = inPtr->fSpacePointCnt;
409 for( int icl=0; icl<nClusters; icl++ ){
410 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
87cc43e1 411
412 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
413 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
414 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
415 if( d.fLayer==4 ) hit[5] = -hit[5];
ef6e2aa2 416 fTracker->LoadCluster( AliITSRecPoint( lab, hit, info ) );
6edb0fb5 417 }
418 }
419
420 }// end read input blocks
421
6edb0fb5 422 // Reconstruct the event
423
57a4102f 424 fBenchmark.Start(1);
425 fTracker->Reconstruct( &(tracksTPC[0]), tracksTPC.size() );
426 fBenchmark.Stop(1);
427
6edb0fb5 428
429 // Fill output tracks
9eee44f6 430 int nITSUpdated = 0;
6edb0fb5 431 {
b7ed2eb4 432
433 for( int iOut=0; iOut<=1; iOut++ ){
9af5a71c 434
b7ed2eb4 435 unsigned int blockSize = 0;
9af5a71c 436
b7ed2eb4 437 AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size );
438 AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
9af5a71c 439
b7ed2eb4 440 blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outPtr );
9af5a71c 441
b3a48f51 442 if ( size + blockSize > maxBufferSize ) {
443 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, size + blockSize );
444 iResult = -ENOSPC;
445 break;
446 }
447
b7ed2eb4 448 outPtr->fCount = 0;
365eee5d 449 AliHLTITSTrack *tracks=0;
450 int nTracks = 0;
451 if( iOut==0 ){
452 tracks = fTracker->Tracks();
453 nTracks = fTracker->NTracks();
454 } else{
455 tracks = fTracker->ITSOutTracks();
456 nTracks = fTracker->NITSOutTracks();
457 }
b7ed2eb4 458
459 for ( int itr = 0; itr < nTracks; itr++ ) {
460 AliHLTITSTrack &t = tracks[itr];
461 int id = tracksTPCId[t.TPCtrackId()];
462 int nClusters = t.GetNumberOfClusters();
463 if( iOut==0 && nClusters>0 ) nITSUpdated++;
464
465 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
466
467 if ( size + blockSize + dSize > maxBufferSize ) {
468 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, size + blockSize + dSize, nTracks - itr + 1 );
469 iResult = -ENOSPC;
470 break;
471 }
472
473 currOutTrack->fAlpha = t.GetAlpha();
474 currOutTrack->fX = t.GetX();
475 currOutTrack->fY = t.GetY();
476 currOutTrack->fZ = t.GetZ();
477 currOutTrack->fLastX = 0;
478 currOutTrack->fLastY = 0;
479 currOutTrack->fLastZ = 0;
480 currOutTrack->fq1Pt = t.GetSigned1Pt();
481 currOutTrack->fSinPsi = t.GetSnp();
482 currOutTrack->fTgl = t.GetTgl();
483 for( int i=0; i<15; i++ ) currOutTrack->fC[i] = t.GetCovariance()[i];
484 currOutTrack->fTrackID = id;
485 currOutTrack->fFlags = 0;
486 currOutTrack->fNPoints = nClusters;
487 for ( int i = 0; i < nClusters; i++ ) currOutTrack->fPointIDs[i] = t.GetClusterIndex( i );
488 currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
489 blockSize += dSize;
490 outPtr->fCount++;
6edb0fb5 491 }
9af5a71c 492
6edb0fb5 493
b7ed2eb4 494 AliHLTComponentBlockData resultData;
495 FillBlockData( resultData );
496 resultData.fOffset = 0;
497 resultData.fSize = blockSize;
498 if( iOut==0 ){
499 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
500 } else {
501 resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut;
502 }
57a4102f 503 fBenchmark.AddOutput(resultData.fSize);
b7ed2eb4 504 outputBlocks.push_back( resultData );
505 size += resultData.fSize;
506 }
6edb0fb5 507 }
b7ed2eb4 508
57a4102f 509 fBenchmark.Stop(0);
9eee44f6 510
511 // Set log level to "Warning" for on-line system monitoring
57a4102f 512 HLTInfo( "ITS Tracker: output %d tracks; input %d clusters, %d tracks",
513 nITSUpdated, nClustersTotal, tracksTPC.size() );
9eee44f6 514
57a4102f 515 HLTInfo(fBenchmark.GetStatistics());
6edb0fb5 516 return iResult;
517}