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