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