fixes in standalone tracker code
[u/mrichter/AliRoot.git] / HLT / ITS / trackingSAP / AliHLTITSSAPTrackerComponent.cxx
CommitLineData
c9598e1c 1// **************************************************************************
2// This file is property of and copyright by the ALICE HLT Project *
3// ALICE Experiment at CERN, All rights reserved. *
4// *
5// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
6// Ivan Kisel <kisel@kip.uni-heidelberg.de> *
7// for The ALICE HLT Project. *
8// *
9// Permission to use, copy, modify and distribute this software and its *
10// documentation strictly for non-commercial purposes is hereby granted *
11// without fee, provided that the above copyright notice appears in all *
12// copies and that both the copyright notice and this permission notice *
13// appear in the supporting documentation. The authors make no claims *
14// about the suitability of this software for any purpose. It is *
15// provided "as is" without express or implied warranty. *
16// *
17//***************************************************************************
18
19/// @file AliHLTITSSAPTrackerComponent.h
20/// @author Ruben Shahoyan <ruben.shahoyan@cern.ch>
21/// @date August 2014
22/// @brief An ITS standalone primaries tracker/vertexer processing component for the HLT
23/// Adapted from HLT/ITS/tracking/AliHLTITSSAPTrackerComponent component
24
25/////////////////////////////////////////////////////
26// //
27// a ITS tracker processing component for the HLT //
28// //
29/////////////////////////////////////////////////////
30
31#include "AliHLTITSSAPTrackerComponent.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 "AliGeomManager.h"
39#include "TObjString.h"
40#include <TClonesArray.h>
41#include <TGeoGlobalMagField.h>
42#include "AliITSSAPTracker.h"
43#include "AliHLTITSSpacePointData.h"
44#include "AliHLTITSClusterDataFormat.h"
45#include "AliHLTDataTypes.h"
46#include "AliHLTExternalTrackParam.h"
47#include "AliGeomManager.h"
48#include "AliHLTTrackMCLabel.h"
49#include "AliITSRecPoint.h"
50#include <map>
51
52using namespace std;
53
54/** ROOT macro for the implementation of ROOT specific class methods */
55ClassImp( AliHLTITSSAPTrackerComponent )
56AliHLTITSSAPTrackerComponent::AliHLTITSSAPTrackerComponent()
57: fSolenoidBz( 0 ),
58 fBenchmark("ITSSAPTracker"),
59 fTracker(0),
60 fClusters(0)
61
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
70AliHLTITSSAPTrackerComponent::AliHLTITSSAPTrackerComponent( const AliHLTITSSAPTrackerComponent& )
71 :AliHLTProcessor(),
72 fSolenoidBz( 0 ),
73 fBenchmark("ITSSAPTracker"),
74 fTracker(0),
75 fClusters(0)
76{
77 // see header file for class documentation
78 HLTFatal( "copy constructor untested" );
79}
80
81AliHLTITSSAPTrackerComponent& AliHLTITSSAPTrackerComponent::operator=( const AliHLTITSSAPTrackerComponent& )
82{
83 // see header file for class documentation
84 HLTFatal( "assignment operator untested" );
85 return *this;
86}
87
88AliHLTITSSAPTrackerComponent::~AliHLTITSSAPTrackerComponent()
89{
90 // see header file for class documentation
91 delete fTracker;
92 delete fClusters;
93}
94
95//
96// Public functions to implement AliHLTComponent's interface.
97// These functions are required for the registration process
98//
99
100const char* AliHLTITSSAPTrackerComponent::GetComponentID()
101{
102 // see header file for class documentation
103 return "ITSTracker";
104}
105
106void AliHLTITSSAPTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
107{
108 // see header file for class documentation
109 list.clear();
110 list.push_back( kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS );
111 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
112 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
113 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
114 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITS );
115}
116
117AliHLTComponentDataType AliHLTITSSAPTrackerComponent::GetOutputDataType()
118{
119 // see header file for class documentation
120 return kAliHLTMultipleDataType;
121}
122
123int AliHLTITSSAPTrackerComponent::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 tgtList.push_back(kAliHLTDataTypeTrackMC|kAliHLTDataOriginITS );
130 tgtList.push_back(kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut ); // RS??: is this correct?
131 return tgtList.size();
132}
133
134void AliHLTITSSAPTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
135{
136 // define guess for the output data size
137 constBase = 200; // minimum size
138 inputMultiplier = 2.; // size relative to input
139}
140
141AliHLTComponent* AliHLTITSSAPTrackerComponent::Spawn()
142{
143 // see header file for class documentation
144 return new AliHLTITSSAPTrackerComponent;
145}
146
147void AliHLTITSSAPTrackerComponent::SetDefaultConfiguration()
148{
149 // Set default configuration for the CA tracker component
150 // Some parameters can be later overwritten from the OCDB
151
152 fSolenoidBz = -5.00668;
153
154}
155
156int AliHLTITSSAPTrackerComponent::ReadConfigurationString( const char* arguments )
157{
158 // Set configuration parameters for the CA tracker component from the string
159
160 int iResult = 0;
161 if ( !arguments ) return iResult;
162
163 TString allArgs = arguments;
164 TString argument;
165 int bMissingParam = 0;
166
167 TObjArray* pTokens = allArgs.Tokenize( " " );
168
169 int nArgs = pTokens ? pTokens->GetEntries() : 0;
170
171 for ( int i = 0; i < nArgs; i++ ) {
172 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
173 if ( argument.IsNull() ) continue;
174
175 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
176 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
177 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
178 continue;
179 }
180
181 HLTError( "Unknown option \"%s\"", argument.Data() );
182 iResult = -EINVAL;
183 }
184 delete pTokens;
185
186 if ( bMissingParam ) {
187 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
188 iResult = -EINVAL;
189 }
190
191 return iResult;
192}
193
194
195int AliHLTITSSAPTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
196{
197 // see header file for class documentation
198
199 const char* defaultNotify = "";
200
201 if ( !cdbEntry ) {
202 return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
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
229int AliHLTITSSAPTrackerComponent::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 fSolenoidBz = GetBz();
246
247 //* read the actual CDB entry if required
248
249 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
250
251 //* read extra parameters from input (if they are)
252
253 int iResult3 = 0;
254
255 if ( commandLine && commandLine[0] != '\0' ) {
256 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
257 iResult3 = ReadConfigurationString( commandLine );
258 }
259
260 // Initialise the tracker here
261
262 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
263}
264
265
266
267int AliHLTITSSAPTrackerComponent::DoInit( int argc, const char** argv )
268{
269 // Configure the ITS tracker component
270
271 if ( fTracker ) return -EINPROGRESS;
272
273 if(AliGeomManager::GetGeometry()==NULL){
274 AliGeomManager::LoadGeometry();
275 }
276 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
277
278 TString arguments = "";
279 for ( int i = 0; i < argc; i++ ) {
280 if ( !arguments.IsNull() ) arguments += " ";
281 arguments += argv[i];
282 }
283
284 int ret = Configure( NULL, NULL, arguments.Data() );
285
286 // Check field
287 if (!TGeoGlobalMagField::Instance()) {
288 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
289 return -ENODEV;
290 }
291 fSolenoidBz=GetBz();
292
293 fTracker = new AliITSSAPTracker();
294 fTracker->Init();
295 fBenchmark.Reset();
296 fBenchmark.SetTimer(0,"total");
297 fBenchmark.SetTimer(1,"reco");
298 return ret;
299}
300
301
302int AliHLTITSSAPTrackerComponent::DoDeinit()
303{
304 // see header file for class documentation
305 delete fTracker;
306 fTracker = 0;
307 return 0;
308}
309
310
311
312int AliHLTITSSAPTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
313{
314 // Reconfigure the component from OCDB .
315
316 return Configure( cdbEntry, chainId, NULL );
317}
318
319
320
321int AliHLTITSSAPTrackerComponent::DoEvent
322(
323 const AliHLTComponentEventData& evtData,
324 const AliHLTComponentBlockData* blocks,
325 AliHLTComponentTriggerData& /*trigData*/,
326 AliHLTUInt8_t* /*outputPtr*/,
327 AliHLTUInt32_t& size,
328 vector<AliHLTComponentBlockData>& /*outputBlocks*/ )
329{
330 //* process event
331
332 // AliHLTUInt32_t maxBufferSize = size;
333 size = 0; // output size
334
335 if (!IsDataEvent()) return 0;
336
337 if ( evtData.fBlockCnt <= 0 ) {
338 HLTWarning( "no blocks in event" );
339 return 0;
340 }
341
342 fBenchmark.StartNewEvent();
343 fBenchmark.Start(0);
344
345 // Event reconstruction in ITS
346
347 int iResult=0;
348
349
350 // Check if there is an SPD vertex
351 const AliESDVertex *vertexSPD = 0;
352
353 {
354 const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS);
355 if( iter != NULL ) {
356 if( !( vertexSPD = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) ) ) ){
357 HLTError("ITS SPD vertex object is corrupted");
358 iResult = -EINVAL;
359 }
360 }
361 else {
362 HLTWarning("No SPD vertex, skip ITS standalone reconstruction");
363 return 0;
364 }
365 }
366
367 int nBlocks = evtData.fBlockCnt;
368 if (!fClusters) fClusters = new TClonesArray("AliITSRecPoint",1000);
369 //
370 int nClTotal = 0;
371 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
372
373 const AliHLTComponentBlockData* iter = blocks+ndx;
374
375 // Read ITS clusters
376
377 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
378 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
379 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ||
380 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITS) )
381 ){
382
383 fBenchmark.AddInput(iter->fSize);
384
385 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
386 int nClusters = inPtr->fSpacePointCnt;
387 for( int icl=0; icl<nClusters; icl++ ){
388 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
389
390 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
391 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
392 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
393 if( d.fLayer==4 ) hit[5] = -hit[5];
394 // tracker does not out the clusters, add them to transient array
395 fTracker->AddCluster( new((*fClusters)[nClTotal++]) AliITSRecPoint(lab,hit,info) );
396 }
397 }
398
399 }// end read input blocks
400
401 // Reconstruct the event
402
403 fBenchmark.Start(1);
404 fTracker->SetSPDVertex(vertexSPD);
405 fTracker->ProcessEvent();
406 fBenchmark.Stop(1);
407
408
409 // Fill output tracks
410
411 // RS??: HERE I AM NOT SURE WHAT TO DO
412 int nFoundTracks = fTracker->GetNTracks();
413 int nAddedTracks = 0;
414 for (int itr=0;itr<nFoundTracks;itr++) {
415 const AliITSSAPTracker::ITStrack_t& track = fTracker->GetTrack(itr);
416 // the track is just a struct of 2 AliExternalTrackParams (params at vertex and at the outer ITS layer)
417 // + some extra info, see "struct ITStrack" in the AliITSSAPTracker.h
418 if ( track.paramOut.TestBit(AliITSSAPTracker::kInvalidBit) ||
419 track.paramInw.TestBit(AliITSSAPTracker::kInvalidBit)) continue;
420 // use only those tracks whose both inward and outward params are OK.
421
422 nAddedTracks++;
423 // RS??:
424
425 // I don't know if it should be passes as it is or converted to ESDtrack?
426 }
427
428 // Fill output vertexTracks
429
430 // RS: HERE I AM NOT SURE WHAT TO DO
431
432 Bool_t vtxOK = kFALSE;
433 AliESDVertex& vtxTracks = fTracker->GetTrackVertex();
434 if (vtxTracks.GetStatus()==1) {
435 // here we should add the vertex to the output
436
437 // RS??: ADD TO THE OUTPUT
438 PushBack( (TObject*) &vtxTracks, kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut,0 );
439 vtxOK = kTRUE;
440 }
441 //
442 fTracker->Clear();
443 fClusters->Clear();
444 //
445 fBenchmark.Stop(0);
446
447 // Set log level to "Warning" for on-line system monitoring
448 HLTInfo( "ITS SAP Tracker: output %d tracks; input %d clusters, VertexTracks: %s",
449 nAddedTracks, nClTotal, vtxOK ? "OK" : "Found" );
450
451 HLTInfo(fBenchmark.GetStatistics());
452 return iResult;
453}