]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/tracking/AliHLTITSTrackerComponent.cxx
ITS tracker component added
[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
21 /////////////////////////////////////////////////////
22 //                                                 //
23 // a ITS tracker processing component for the HLT  //
24 //                                                 //
25 /////////////////////////////////////////////////////
26
27 #if __GNUC__>= 3
28 using namespace std;
29 #endif
30
31 #include "AliHLTITSTrackerComponent.h"
32 #include "AliHLTArray.h"
33 #include "AliExternalTrackParam.h"
34 #include "TStopwatch.h"
35 #include "TMath.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBManager.h"
38 #include "TObjString.h"
39 #include "TObjArray.h"
40 #include "AliHLTTPCDefinitions.h"
41 #include "AliITStrackerHLT.h"
42 #include "AliHLTITSTrackDataHeader.h"
43 #include "AliHLTTPCDefinitions.h"
44 #include "AliHLTTPCTrackArray.h"
45 #include "AliHLTTPCTrackletDataFormat.h"
46 #include "AliHLTTPCTrack.h"
47 #include "AliHLTITSSpacePointData.h"
48 #include "AliHLTITSClusterDataFormat.h"
49 #include "AliHLTDataTypes.h"
50
51
52
53 /** ROOT macro for the implementation of ROOT specific class methods */
54 ClassImp( AliHLTITSTrackerComponent )
55 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
56     :
57     fSolenoidBz( 0 ),
58     fFullTime( 0 ),
59     fRecoTime( 0 ),
60     fNEvents( 0 ),
61     fTracker(0)
62 {
63   // see header file for class documentation
64   // or
65   // refer to README to build package
66   // or
67   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 }
69
70 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
71     :
72     AliHLTProcessor(),
73     fSolenoidBz( 0 ),
74     fFullTime( 0 ),
75     fRecoTime( 0 ),
76     fNEvents( 0 ),
77     fTracker(0)
78 {
79   // see header file for class documentation
80   HLTFatal( "copy constructor untested" );
81 }
82
83 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
84 {
85   // see header file for class documentation
86   HLTFatal( "assignment operator untested" );
87   return *this;
88 }
89
90 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
91 {
92   // see header file for class documentation
93   delete fTracker;
94 }
95
96 //
97 // Public functions to implement AliHLTComponent's interface.
98 // These functions are required for the registration process
99 //
100
101 const char* AliHLTITSTrackerComponent::GetComponentID()
102 {
103   // see header file for class documentation
104   return "ITSTracker";
105 }
106
107 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
108 {
109   // see header file for class documentation
110   list.clear();
111   list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
112   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
113   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
114 }
115
116 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
117 {
118   // see header file for class documentation  
119   return fgkITSTracksDataType;
120 }
121
122 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
123 {
124   // define guess for the output data size
125   constBase = 200;       // minimum size
126   inputMultiplier = 0.5; // size relative to input
127 }
128
129 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
130 {
131   // see header file for class documentation
132   return new AliHLTITSTrackerComponent;
133 }
134
135 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
136 {
137   // Set default configuration for the CA tracker component
138   // Some parameters can be later overwritten from the OCDB
139
140   fSolenoidBz = 5.;
141   fFullTime = 0;
142   fRecoTime = 0;
143   fNEvents = 0;
144   fTracker = 0;
145 }
146
147 int AliHLTITSTrackerComponent::ReadConfigurationString(  const char* arguments )
148 {
149   // Set configuration parameters for the CA tracker component from the string
150
151   int iResult = 0;
152   if ( !arguments ) return iResult;
153
154   TString allArgs = arguments;
155   TString argument;
156   int bMissingParam = 0;
157
158   TObjArray* pTokens = allArgs.Tokenize( " " );
159
160   int nArgs =  pTokens ? pTokens->GetEntries() : 0;
161
162   for ( int i = 0; i < nArgs; i++ ) {
163     argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
164     if ( argument.IsNull() ) continue;
165
166     if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
167       if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
168       fSolenoidBz = ( ( TObjString* )pTokens->At( i ) )->GetString().Atof();
169       HLTInfo( "Magnetic Field set to: %f", fSolenoidBz );
170       continue;
171     }
172
173     //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) {
174     //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
175     //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi();
176     //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters );
177     //continue;
178     //}
179
180     HLTError( "Unknown option \"%s\"", argument.Data() );
181     iResult = -EINVAL;
182   }
183   delete pTokens;
184
185   if ( bMissingParam ) {
186     HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
187     iResult = -EINVAL;
188   }
189
190   return iResult;
191 }
192
193
194 int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
195 {
196   // see header file for class documentation
197
198   const char* defaultNotify = "";
199
200   if ( !cdbEntry ) {
201     cdbEntry = "HLT/ConfigITS/ITSTracker";
202     defaultNotify = " (default)";
203     chainId = 0;
204   }
205
206   HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
207   AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
208
209   if ( !pEntry ) {
210     HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
211     return -EINVAL;
212   }
213
214   TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
215
216   if ( !pString ) {
217     HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
218     return -EINVAL;
219   }
220
221   HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
222
223   return  ReadConfigurationString( pString->GetString().Data() );
224 }
225
226
227 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
228 {
229   // Configure the component
230   // There are few levels of configuration,
231   // parameters which are set on one step can be overwritten on the next step
232
233   //* read hard-coded values
234
235   SetDefaultConfiguration();
236
237   //* read the default CDB entry
238
239   int iResult1 = ReadCDBEntry( NULL, chainId );
240
241   //* read magnetic field
242
243   int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
244
245   //* read the actual CDB entry if required
246
247   int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
248
249   //* read extra parameters from input (if they are)
250
251   int iResult4 = 0;
252
253   if ( commandLine && commandLine[0] != '\0' ) {
254     HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
255     iResult4 = ReadConfigurationString( commandLine );
256   }
257
258   // Initialise the tracker here
259
260   return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
261 }
262
263
264
265 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
266 {
267   // Configure the ITS tracker component
268
269   if ( fTracker ) return EINPROGRESS;
270   fTracker = new AliITStrackerHLT();
271
272   TString arguments = "";
273   for ( int i = 0; i < argc; i++ ) {
274     if ( !arguments.IsNull() ) arguments += " ";
275     arguments += argv[i];
276   }
277
278   return Configure( NULL, NULL, arguments.Data() );
279 }
280
281
282 int AliHLTITSTrackerComponent::DoDeinit()
283 {
284   // see header file for class documentation
285   delete fTracker;
286   fTracker = 0;
287   return 0;
288 }
289
290
291
292 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
293 {
294   // Reconfigure the component from OCDB .
295
296   return Configure( cdbEntry, chainId, NULL );
297 }
298
299
300
301 int AliHLTITSTrackerComponent::DoEvent
302 (
303   const AliHLTComponentEventData& evtData,
304   const AliHLTComponentBlockData* blocks,
305   AliHLTComponentTriggerData& /*trigData*/,
306   AliHLTUInt8_t* outputPtr,
307   AliHLTUInt32_t& size,
308   vector<AliHLTComponentBlockData>& outputBlocks )
309 {
310   //* process event
311
312   AliHLTUInt32_t maxBufferSize = size;
313   size = 0; // output size
314
315   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
316     return 0;
317   }
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 == AliHLTTPCDefinitions::fgkTracksDataType ){
347       AliHLTTPCTrackArray tracks;
348       AliHLTTPCTrackletData *inPtr=(AliHLTTPCTrackletData*)iter->fPtr;
349       iResult=tracks.FillTracksChecked( inPtr->fTracklets, inPtr->fTrackletCnt, iter->fSize, -1, 0 );      
350       if ( iResult < 0 ){
351         HLTError("internal mismatch in array");
352         iResult=-EFAULT;
353         break;
354       }
355       for (int i=0; i<tracks.GetNTracks(); i++) {
356         AliHLTTPCTrack* pTrack = tracks[i];
357         if( !pTrack ) continue;
358         if( pTrack->Convert2AliKalmanTrack() ){   
359           //HLTError("conversion to AliKalmanTrack failed for track %d of %d", i, pTracks->GetNTracks());       
360           continue;
361         }
362         tracksTPC.push_back( *pTrack );
363         tracksTPCId.push_back(currentTrackID++);    
364       }
365     }
366
367     // Read ITS clusters
368
369     if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) || 
370          (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) 
371          ){
372
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];
377         AliITSRecPoint p;
378         p.SetY( d.fY );
379         p.SetZ( d.fZ );
380         p.SetSigmaY2( d.fSigmaY2 );
381         p.SetSigmaZ2( d.fSigmaZ2 );
382         p.SetSigmaYZ( d.fSigmaYZ );
383         p.SetQ( d.fQ );
384         p.SetNy( d.fNy );
385         p.SetNz( d.fNz );
386         p.SetLayer( d.fLayer );
387         p.SetDetectorIndex( d.fIndex );
388         p.SetLabel(0, d.fTracks[0] );
389         p.SetLabel(1, d.fTracks[1] );
390         p.SetLabel(2, d.fTracks[2] );
391         clusters.push_back( p );
392       }   
393     }
394     
395   }// end read input blocks
396   
397   // set clusters to tracker
398
399   fTracker->LoadClusters( clusters );
400
401   // Reconstruct the event
402
403   TStopwatch timerReco;
404   
405   fTracker->Reconstruct( tracksTPC );
406
407   timerReco.Stop();
408   
409   // Fill output tracks
410
411   {
412     unsigned int mySize = 0;
413   
414     // check if there was enough space in the output buffer
415     
416     int nTracks = fTracker->Tracks().size();
417     mySize =  sizeof( AliHLTITSTrackDataHeader ) + nTracks*sizeof( AliHLTITSTrackData );
418     if ( mySize > maxBufferSize ) {
419       mySize = 0;
420       iResult = -ENOSPC; 
421       nTracks=0;     
422     } else {
423       AliHLTITSTrackDataHeader *outPtr = ( AliHLTITSTrackDataHeader* )( outputPtr );
424       outPtr->fTrackletCnt = nTracks;
425       AliHLTITSTrackData *tr = outPtr->fTracks;
426       for( int itr=0; itr<nTracks; itr++ ){
427         tr->fTrackParam = fTracker->Tracks()[itr];
428         tr->fTPCId = tracksTPCId[fTracker->Tracks()[itr].TPCtrackId()];
429         tr->fClusterIds[0] = 0;
430         tr->fClusterIds[1] = 0;
431         tr->fClusterIds[2] = 0;
432         tr->fClusterIds[3] = 0;
433         tr->fClusterIds[4] = 0;
434         tr->fClusterIds[5] = 0;
435         tr++;
436       }
437     }
438
439     AliHLTComponentBlockData resultData;
440     FillBlockData( resultData );
441     resultData.fOffset = 0;
442     resultData.fSize = mySize;
443     resultData.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
444     outputBlocks.push_back( resultData );
445     size = resultData.fSize;
446
447     HLTInfo( "ITS tracker:: output %d tracks",nTracks );
448   }
449   return iResult;
450 }