]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/tracking/AliHLTITSTrackerComponent.cxx
- code cleanup and starting component documentation
[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 "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 "AliHLTKalmanTrack.h"
51
52
53
54 /** ROOT macro for the implementation of ROOT specific class methods */
55 ClassImp( AliHLTITSTrackerComponent )
56 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
57     :
58     fSolenoidBz( 0 ),
59     fFullTime( 0 ),
60     fRecoTime( 0 ),
61     fNEvents( 0 ),
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
71 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
72     :
73     AliHLTProcessor(),
74     fSolenoidBz( 0 ),
75     fFullTime( 0 ),
76     fRecoTime( 0 ),
77     fNEvents( 0 ),
78     fTracker(0)
79 {
80   // see header file for class documentation
81   HLTFatal( "copy constructor untested" );
82 }
83
84 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
85 {
86   // see header file for class documentation
87   HLTFatal( "assignment operator untested" );
88   return *this;
89 }
90
91 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
92 {
93   // see header file for class documentation
94   delete fTracker;
95 }
96
97 //
98 // Public functions to implement AliHLTComponent's interface.
99 // These functions are required for the registration process
100 //
101
102 const char* AliHLTITSTrackerComponent::GetComponentID()
103 {
104   // see header file for class documentation
105   return "ITSTracker";
106 }
107
108 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
109 {
110   // see header file for class documentation
111   list.clear();
112   list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
113   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
114   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
115   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
116 }
117
118 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
119 {
120   // see header file for class documentation  
121   return kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
122 }
123
124 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
125 {
126   // define guess for the output data size
127   constBase = 200;       // minimum size
128   inputMultiplier = 0.5; // size relative to input
129 }
130
131 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
132 {
133   // see header file for class documentation
134   return new AliHLTITSTrackerComponent;
135 }
136
137 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
138 {
139   // Set default configuration for the CA tracker component
140   // Some parameters can be later overwritten from the OCDB
141
142   fSolenoidBz = 5.;
143   fFullTime = 0;
144   fRecoTime = 0;
145   fNEvents = 0;
146   fTracker = 0;
147 }
148
149 int AliHLTITSTrackerComponent::ReadConfigurationString(  const char* arguments )
150 {
151   // Set configuration parameters for the CA tracker component from the string
152
153   int iResult = 0;
154   if ( !arguments ) return iResult;
155
156   TString allArgs = arguments;
157   TString argument;
158   int bMissingParam = 0;
159
160   TObjArray* pTokens = allArgs.Tokenize( " " );
161
162   int nArgs =  pTokens ? pTokens->GetEntries() : 0;
163
164   for ( int i = 0; i < nArgs; i++ ) {
165     argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
166     if ( argument.IsNull() ) continue;
167
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 );
172       continue;
173     }
174
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 );
179     //continue;
180     //}
181
182     HLTError( "Unknown option \"%s\"", argument.Data() );
183     iResult = -EINVAL;
184   }
185   delete pTokens;
186
187   if ( bMissingParam ) {
188     HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
189     iResult = -EINVAL;
190   }
191
192   return iResult;
193 }
194
195
196 int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
197 {
198   // see header file for class documentation
199
200   const char* defaultNotify = "";
201
202   if ( !cdbEntry ) {
203     cdbEntry = "HLT/ConfigITS/ITSTracker";
204     defaultNotify = " (default)";
205     chainId = 0;
206   }
207
208   HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
209   AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
210
211   if ( !pEntry ) {
212     HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
213     return -EINVAL;
214   }
215
216   TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
217
218   if ( !pString ) {
219     HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
220     return -EINVAL;
221   }
222
223   HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
224
225   return  ReadConfigurationString( pString->GetString().Data() );
226 }
227
228
229 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
230 {
231   // Configure the component
232   // There are few levels of configuration,
233   // parameters which are set on one step can be overwritten on the next step
234
235   //* read hard-coded values
236
237   SetDefaultConfiguration();
238
239   //* read the default CDB entry
240
241   int iResult1 = ReadCDBEntry( NULL, chainId );
242
243   //* read magnetic field
244
245   int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
246
247   //* read the actual CDB entry if required
248
249   int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
250
251   //* read extra parameters from input (if they are)
252
253   int iResult4 = 0;
254
255   if ( commandLine && commandLine[0] != '\0' ) {
256     HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
257     iResult4 = ReadConfigurationString( commandLine );
258   }
259
260   // Initialise the tracker here
261
262   return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
263 }
264
265
266
267 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
268 {
269   // Configure the ITS tracker component
270
271   if ( fTracker ) return EINPROGRESS;
272   fTracker = new AliITStrackerHLT(0);
273
274   TString arguments = "";
275   for ( int i = 0; i < argc; i++ ) {
276     if ( !arguments.IsNull() ) arguments += " ";
277     arguments += argv[i];
278   }
279
280   return Configure( NULL, NULL, arguments.Data() );
281 }
282
283
284 int AliHLTITSTrackerComponent::DoDeinit()
285 {
286   // see header file for class documentation
287   delete fTracker;
288   fTracker = 0;
289   return 0;
290 }
291
292
293
294 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
295 {
296   // Reconfigure the component from OCDB .
297
298   return Configure( cdbEntry, chainId, NULL );
299 }
300
301
302
303 int AliHLTITSTrackerComponent::DoEvent
304 (
305   const AliHLTComponentEventData& evtData,
306   const AliHLTComponentBlockData* blocks,
307   AliHLTComponentTriggerData& /*trigData*/,
308   AliHLTUInt8_t* outputPtr,
309   AliHLTUInt32_t& size,
310   vector<AliHLTComponentBlockData>& outputBlocks )
311 {
312   //* process event
313
314   AliHLTUInt32_t maxBufferSize = size;
315   size = 0; // output size
316
317   if (!IsDataEvent()) return 0;
318
319   if ( evtData.fBlockCnt <= 0 ) {
320     HLTWarning( "no blocks in event" );
321     return 0;
322   }
323
324
325   TStopwatch timer;
326
327   // Event reconstruction in ITS
328
329   int iResult=0;
330
331   int nBlocks = evtData.fBlockCnt;
332
333   
334   vector< AliExternalTrackParam > tracksTPC;
335   vector< int > tracksTPCId;
336   std::vector<AliITSRecPoint> clusters;
337
338   //int currentTrackID = 0;
339
340   for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
341
342     const AliHLTComponentBlockData* iter = blocks+ndx;
343  
344     // Read TPC tracks
345     
346     if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){       
347       AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
348       int nTracks = dataPtr->fCount;
349       AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
350       for( int itr=0; itr<nTracks; itr++ ){
351         AliHLTKalmanTrack t(*currOutTrack);
352         tracksTPC.push_back( t );
353         tracksTPCId.push_back( currOutTrack->fTrackID );
354         unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
355         currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
356       }
357     }
358
359
360     // Read ITS clusters
361
362     if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) || 
363          (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
364          (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) 
365          ){
366
367       AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
368       int nClusters = inPtr->fSpacePointCnt;
369       for( int icl=0; icl<nClusters; icl++ ){
370         AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
371         AliITSRecPoint p;
372         p.SetY( d.fY );
373         p.SetZ( d.fZ );
374         p.SetSigmaY2( d.fSigmaY2 );
375         p.SetSigmaZ2( d.fSigmaZ2 );
376         p.SetSigmaYZ( d.fSigmaYZ );
377         p.SetQ( d.fQ );
378         p.SetNy( d.fNy );
379         p.SetNz( d.fNz );
380         p.SetLayer( d.fLayer );
381         p.SetDetectorIndex( d.fIndex );
382         p.SetLabel(0, d.fTracks[0] );
383         p.SetLabel(1, d.fTracks[1] );
384         p.SetLabel(2, d.fTracks[2] );
385         clusters.push_back( p );
386       }   
387     }
388     
389   }// end read input blocks
390   
391   // set clusters to tracker
392
393   fTracker->LoadClusters( clusters );
394
395   // Reconstruct the event
396
397   TStopwatch timerReco;
398   
399   fTracker->Reconstruct( tracksTPC );
400
401   timerReco.Stop();
402   
403   // Fill output tracks
404
405   {
406     unsigned int mySize = 0;    
407      
408     AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr );
409
410     AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets;
411
412     mySize =   ( ( AliHLTUInt8_t * )currOutTrack ) -  ( ( AliHLTUInt8_t * )outputPtr );
413
414     outPtr->fCount = 0;
415     
416     int nTracks = fTracker->Tracks().size();
417
418     for ( int itr = 0; itr < nTracks; itr++ ) {
419
420       const AliExternalTrackParam &tp = fTracker->Tracks()[itr];
421       int id =  tracksTPCId[fTracker->Tracks()[itr].TPCtrackId()];
422
423       int nClusters = 0;
424
425       unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
426
427       if ( mySize + dSize > maxBufferSize ) {
428         HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
429         iResult = -ENOSPC;
430         break;
431       }
432
433       currOutTrack->fAlpha = tp.GetAlpha();
434       currOutTrack->fX = tp.GetX();
435       currOutTrack->fY = tp.GetY();
436       currOutTrack->fZ = tp.GetZ();            
437       currOutTrack->fLastX = 0;
438       currOutTrack->fLastY = 0;
439       currOutTrack->fLastZ = 0;      
440       currOutTrack->fq1Pt = tp.GetSigned1Pt();
441       currOutTrack->fSinPsi = tp.GetSnp();
442       currOutTrack->fTgl = tp.GetTgl();
443       for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
444       currOutTrack->fTrackID = id;
445       currOutTrack->fFlags = 0;
446       currOutTrack->fNPoints = nClusters;    
447       currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
448       mySize += dSize;
449       outPtr->fCount++;
450     }
451   
452
453     AliHLTComponentBlockData resultData;
454     FillBlockData( resultData );
455     resultData.fOffset = 0;
456     resultData.fSize = mySize;
457     resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
458     outputBlocks.push_back( resultData );
459     size = resultData.fSize;  
460     
461     HLTInfo( "ITS tracker:: output %d tracks",nTracks );
462   }
463   return iResult;
464 }