]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/ITS/tracking/AliHLTITSTrackerComponent.cxx
bugfix (partially) #54670
[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 "AliHLTGlobalBarrelTrack.h"
51 #include "AliGeomManager.h"
52
53
54
55 /** ROOT macro for the implementation of ROOT specific class methods */
56 ClassImp( AliHLTITSTrackerComponent )
57 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent()
58     :
59     fSolenoidBz( 0 ),
60     fFullTime( 0 ),
61     fRecoTime( 0 ),
62     fNEvents( 0 ),
63     fTracker(0)
64 {
65   // see header file for class documentation
66   // or
67   // refer to README to build package
68   // or
69   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
70 }
71
72 AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& )
73     :
74     AliHLTProcessor(),
75     fSolenoidBz( 0 ),
76     fFullTime( 0 ),
77     fRecoTime( 0 ),
78     fNEvents( 0 ),
79     fTracker(0)
80 {
81   // see header file for class documentation
82   HLTFatal( "copy constructor untested" );
83 }
84
85 AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& )
86 {
87   // see header file for class documentation
88   HLTFatal( "assignment operator untested" );
89   return *this;
90 }
91
92 AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent()
93 {
94   // see header file for class documentation
95   delete fTracker;
96 }
97
98 //
99 // Public functions to implement AliHLTComponent's interface.
100 // These functions are required for the registration process
101 //
102
103 const char* AliHLTITSTrackerComponent::GetComponentID()
104 {
105   // see header file for class documentation
106   return "ITSTracker";
107 }
108
109 void AliHLTITSTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
110 {
111   // see header file for class documentation
112   list.clear();
113   list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
114   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
115   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
116   list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
117 }
118
119 AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType()
120 {
121   // see header file for class documentation  
122   return kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
123 }
124
125 void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
126 {
127   // define guess for the output data size
128   constBase = 200;       // minimum size
129   inputMultiplier = 0.5; // size relative to input
130 }
131
132 AliHLTComponent* AliHLTITSTrackerComponent::Spawn()
133 {
134   // see header file for class documentation
135   return new AliHLTITSTrackerComponent;
136 }
137
138 void AliHLTITSTrackerComponent::SetDefaultConfiguration()
139 {
140   // Set default configuration for the CA tracker component
141   // Some parameters can be later overwritten from the OCDB
142
143   fSolenoidBz = 5.;
144   fFullTime = 0;
145   fRecoTime = 0;
146   fNEvents = 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     return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
204     cdbEntry = "HLT/ConfigITS/ITSTracker";
205     defaultNotify = " (default)";
206     chainId = 0;
207   }
208
209   HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
210   AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
211
212   if ( !pEntry ) {
213     HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
214     return -EINVAL;
215   }
216
217   TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
218
219   if ( !pString ) {
220     HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
221     return -EINVAL;
222   }
223
224   HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
225
226   return  ReadConfigurationString( pString->GetString().Data() );
227 }
228
229
230 int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
231 {
232   // Configure the component
233   // There are few levels of configuration,
234   // parameters which are set on one step can be overwritten on the next step
235
236   //* read hard-coded values
237
238   SetDefaultConfiguration();
239
240   //* read the default CDB entry
241
242   int iResult1 = ReadCDBEntry( NULL, chainId );
243
244   //* read magnetic field
245
246   int iResult2 = ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId );
247
248   //* read the actual CDB entry if required
249
250   int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
251
252   //* read extra parameters from input (if they are)
253
254   int iResult4 = 0;
255
256   if ( commandLine && commandLine[0] != '\0' ) {
257     HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
258     iResult4 = ReadConfigurationString( commandLine );
259   }
260
261   // Initialise the tracker here
262
263   return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) );
264 }
265
266
267
268 int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv )
269 {
270   // Configure the ITS tracker component
271
272   if ( fTracker ) return EINPROGRESS;
273
274   if(AliGeomManager::GetGeometry()==NULL){
275     AliGeomManager::LoadGeometry();
276   }
277
278   fTracker = new AliITStrackerHLT(0);
279
280   TString arguments = "";
281   for ( int i = 0; i < argc; i++ ) {
282     if ( !arguments.IsNull() ) arguments += " ";
283     arguments += argv[i];
284   }
285
286   return Configure( NULL, NULL, arguments.Data() );
287 }
288
289
290 int AliHLTITSTrackerComponent::DoDeinit()
291 {
292   // see header file for class documentation
293   delete fTracker;
294   fTracker = 0;
295   return 0;
296 }
297
298
299
300 int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
301 {
302   // Reconfigure the component from OCDB .
303
304   return Configure( cdbEntry, chainId, NULL );
305 }
306
307
308
309 int AliHLTITSTrackerComponent::DoEvent
310 (
311   const AliHLTComponentEventData& evtData,
312   const AliHLTComponentBlockData* blocks,
313   AliHLTComponentTriggerData& /*trigData*/,
314   AliHLTUInt8_t* outputPtr,
315   AliHLTUInt32_t& size,
316   vector<AliHLTComponentBlockData>& outputBlocks )
317 {
318   //* process event
319
320   AliHLTUInt32_t maxBufferSize = size;
321   size = 0; // output size
322
323   if (!IsDataEvent()) return 0;
324
325   if ( evtData.fBlockCnt <= 0 ) {
326     HLTWarning( "no blocks in event" );
327     return 0;
328   }
329
330
331   TStopwatch timer;
332
333   // Event reconstruction in ITS
334
335   int iResult=0;
336
337   int nBlocks = evtData.fBlockCnt;
338
339   
340   vector< AliExternalTrackParam > tracksTPC;
341   vector< int > tracksTPCId;
342   std::vector<AliITSRecPoint> clusters;
343
344   //int currentTrackID = 0;
345
346   for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
347
348     const AliHLTComponentBlockData* iter = blocks+ndx;
349  
350     // Read TPC tracks
351     
352     if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){       
353       AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
354       int nTracks = dataPtr->fCount;
355       AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets;
356       for( int itr=0; itr<nTracks; itr++ ){
357         AliHLTGlobalBarrelTrack t(*currOutTrack);
358         tracksTPC.push_back( t );
359         tracksTPCId.push_back( currOutTrack->fTrackID );
360         unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int );
361         currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
362       }
363     }
364
365
366     // Read ITS clusters
367
368     if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) || 
369          (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
370          (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) 
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
378         Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
379         Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
380         Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
381         if( d.fLayer==4 ) hit[5] = -hit[5];
382
383         AliITSRecPoint p( lab, hit, info );
384         clusters.push_back( p );
385       }   
386     }
387     
388   }// end read input blocks
389   
390   // set clusters to tracker
391
392
393   fTracker->LoadClusters( clusters );
394   //timer.Stop();
395   // Reconstruct the event
396
397   TStopwatch timerReco;
398   
399   fTracker->Reconstruct( tracksTPC );
400
401   timerReco.Stop();
402   
403   // Fill output tracks
404   int nITSUpdated = 0;
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       if( fTracker->Tracks()[itr].GetNumberOfClusters()>0 ) nITSUpdated++;
425
426       unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int );
427
428       if ( mySize + dSize > maxBufferSize ) {
429         HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
430         iResult = -ENOSPC;
431         break;
432       }
433
434       currOutTrack->fAlpha = tp.GetAlpha();
435       currOutTrack->fX = tp.GetX();
436       currOutTrack->fY = tp.GetY();
437       currOutTrack->fZ = tp.GetZ();            
438       currOutTrack->fLastX = 0;
439       currOutTrack->fLastY = 0;
440       currOutTrack->fLastZ = 0;      
441       currOutTrack->fq1Pt = tp.GetSigned1Pt();
442       currOutTrack->fSinPsi = tp.GetSnp();
443       currOutTrack->fTgl = tp.GetTgl();
444       for( int i=0; i<15; i++ ) currOutTrack->fC[i] = tp.GetCovariance()[i];
445       currOutTrack->fTrackID = id;
446       currOutTrack->fFlags = 0;
447       currOutTrack->fNPoints = nClusters;    
448       currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize );
449       mySize += dSize;
450       outPtr->fCount++;
451     }
452   
453
454     AliHLTComponentBlockData resultData;
455     FillBlockData( resultData );
456     resultData.fOffset = 0;
457     resultData.fSize = mySize;
458     resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS;
459     outputBlocks.push_back( resultData );
460     size = resultData.fSize;  
461     
462   }
463
464   timer.Stop();
465   fFullTime += timer.RealTime();
466   fRecoTime += timerReco.RealTime();
467   fNEvents++;
468
469   // Set log level to "Warning" for on-line system monitoring
470   int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 );
471   int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 );
472   HLTInfo( "ITS Tracker: output %d tracks;  input %d clusters, %d tracks; time: full %d / reco %d Hz",
473               nITSUpdated, clusters.size(), tracksTPC.size(), hz, hz1 );
474
475   return iResult;
476 }