1 // **************************************************************************
2 // This file is property of and copyright by the ALICE HLT Project *
3 // ALICE Experiment at CERN, All rights reserved. *
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. *
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. *
17 //***************************************************************************
19 /// @file AliHLTITSSAPTrackerComponent.h
20 /// @author Ruben Shahoyan <ruben.shahoyan@cern.ch>
22 /// @brief An ITS standalone primaries tracker/vertexer processing component for the HLT
23 /// Adapted from HLT/ITS/tracking/AliHLTITSSAPTrackerComponent component
25 /////////////////////////////////////////////////////
27 // a ITS tracker processing component for the HLT //
29 /////////////////////////////////////////////////////
31 #include "AliHLTITSSAPTrackerComponent.h"
32 #include "AliHLTArray.h"
33 #include "AliExternalTrackParam.h"
34 #include "TStopwatch.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 "AliHLTSAPTrackerData.h"
51 #include "AliHLTMessage.h"
52 #include "AliFlatESDVertex.h"
57 /** ROOT macro for the implementation of ROOT specific class methods */
58 ClassImp( AliHLTITSSAPTrackerComponent )
59 AliHLTITSSAPTrackerComponent::AliHLTITSSAPTrackerComponent()
61 fBenchmark("ITSSAPTracker"),
66 // see header file for class documentation
68 // refer to README to build package
70 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
73 AliHLTITSSAPTrackerComponent::AliHLTITSSAPTrackerComponent( const AliHLTITSSAPTrackerComponent& )
76 fBenchmark("ITSSAPTracker"),
80 // see header file for class documentation
81 HLTFatal( "copy constructor untested" );
84 AliHLTITSSAPTrackerComponent& AliHLTITSSAPTrackerComponent::operator=( const AliHLTITSSAPTrackerComponent& )
86 // see header file for class documentation
87 HLTFatal( "assignment operator untested" );
91 AliHLTITSSAPTrackerComponent::~AliHLTITSSAPTrackerComponent()
93 // see header file for class documentation
99 // Public functions to implement AliHLTComponent's interface.
100 // These functions are required for the registration process
103 const char* AliHLTITSSAPTrackerComponent::GetComponentID()
105 // see header file for class documentation
106 return "ITSSAPTracker";
109 void AliHLTITSSAPTrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list )
111 // see header file for class documentation
113 list.push_back( kAliHLTDataTypeESDVertex|kAliHLTDataOriginITS );
114 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD );
115 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD );
116 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD );
117 list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITS );
120 AliHLTComponentDataType AliHLTITSSAPTrackerComponent::GetOutputDataType()
122 // see header file for class documentation
123 return kAliHLTMultipleDataType;
126 int AliHLTITSSAPTrackerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
128 // see header file for class documentation
130 tgtList.push_back(kAliHLTDataTypeITSSAPData|kAliHLTDataOriginITS);
131 tgtList.push_back(kAliHLTDataTypeFlatESDVertex|kAliHLTDataOriginITS ); // RS??: is this correct?
132 return tgtList.size();
135 void AliHLTITSSAPTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
137 // define guess for the output data size
138 constBase = 200; // minimum size
139 inputMultiplier = 2.; // size relative to input
142 AliHLTComponent* AliHLTITSSAPTrackerComponent::Spawn()
144 // see header file for class documentation
145 return new AliHLTITSSAPTrackerComponent;
148 void AliHLTITSSAPTrackerComponent::SetDefaultConfiguration()
150 // Set default configuration for the CA tracker component
151 // Some parameters can be later overwritten from the OCDB
153 fSolenoidBz = -5.00668;
157 int AliHLTITSSAPTrackerComponent::ReadConfigurationString( const char* arguments )
159 // Set configuration parameters for the CA tracker component from the string
162 if ( !arguments ) return iResult;
164 TString allArgs = arguments;
166 int bMissingParam = 0;
168 TObjArray* pTokens = allArgs.Tokenize( " " );
170 int nArgs = pTokens ? pTokens->GetEntries() : 0;
172 for ( int i = 0; i < nArgs; i++ ) {
173 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
174 if ( argument.IsNull() ) continue;
176 if ( argument.CompareTo( "-solenoidBz" ) == 0 ) {
177 if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break;
178 HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
182 HLTError( "Unknown option \"%s\"", argument.Data() );
187 if ( bMissingParam ) {
188 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
196 int AliHLTITSSAPTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
198 // see header file for class documentation
200 const char* defaultNotify = "";
203 return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!!
204 //cdbEntry = "HLT/ConfigITS/ITSTracker";
205 //defaultNotify = " (default)";
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());
213 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
217 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
220 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
224 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
226 return ReadConfigurationString( pString->GetString().Data() );
230 int AliHLTITSSAPTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
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
236 //* read hard-coded values
238 SetDefaultConfiguration();
240 //* read the default CDB entry
242 int iResult1 = ReadCDBEntry( NULL, chainId );
244 //* read magnetic field
246 fSolenoidBz = GetBz();
248 //* read the actual CDB entry if required
250 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
252 //* read extra parameters from input (if they are)
256 if ( commandLine && commandLine[0] != '\0' ) {
257 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
258 iResult3 = ReadConfigurationString( commandLine );
261 // Initialise the tracker here
263 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
268 int AliHLTITSSAPTrackerComponent::DoInit( int argc, const char** argv )
270 // Configure the ITS tracker component
272 if ( fTracker ) return -EINPROGRESS;
274 if(AliGeomManager::GetGeometry()==NULL){
275 AliGeomManager::LoadGeometry();
277 AliGeomManager::ApplyAlignObjsFromCDB("ITS");
279 TString arguments = "";
280 for ( int i = 0; i < argc; i++ ) {
281 if ( !arguments.IsNull() ) arguments += " ";
282 arguments += argv[i];
285 int ret = Configure( NULL, NULL, arguments.Data() );
288 if (!TGeoGlobalMagField::Instance()) {
289 HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF");
294 fTracker = new AliITSSAPTracker();
297 fBenchmark.SetTimer(0,"total");
298 fBenchmark.SetTimer(1,"reco");
303 int AliHLTITSSAPTrackerComponent::DoDeinit()
305 // see header file for class documentation
313 int AliHLTITSSAPTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
315 // Reconfigure the component from OCDB .
317 return Configure( cdbEntry, chainId, NULL );
322 int AliHLTITSSAPTrackerComponent::DoEvent
324 const AliHLTComponentEventData& evtData,
325 const AliHLTComponentBlockData* blocks,
326 AliHLTComponentTriggerData& /*trigData*/,
327 AliHLTUInt8_t* outputPtr,
328 AliHLTUInt32_t& size,
329 vector<AliHLTComponentBlockData>& outputBlocks )
333 AliHLTUInt32_t maxBufferSize = size;
334 size = 0; // output size
336 if (!IsDataEvent()) return 0;
338 if ( evtData.fBlockCnt <= 0 ) {
339 HLTWarning( "no blocks in event" );
343 fBenchmark.StartNewEvent();
346 // Event reconstruction in ITS
351 // Check if there is an SPD vertex
352 const AliESDVertex *vertexSPD = 0;
355 const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginITSSPD);
357 if( !( vertexSPD = dynamic_cast<AliESDVertex*>(const_cast<TObject*>( iter ) ) ) ){
358 HLTError("ITS SPD vertex object is corrupted");
363 HLTWarning("No SPD vertex, skip ITS standalone reconstruction");
368 int nBlocks = evtData.fBlockCnt;
369 if (!fClusters) fClusters = new TClonesArray("AliITSRecPoint",1000);
372 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
374 const AliHLTComponentBlockData* iter = blocks+ndx;
378 if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) ||
379 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) ||
380 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ||
381 (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITS) )
384 fBenchmark.AddInput(iter->fSize);
386 AliHLTITSClusterData *inPtr=reinterpret_cast<AliHLTITSClusterData*>( iter->fPtr );
387 int nClusters = inPtr->fSpacePointCnt;
388 for( int icl=0; icl<nClusters; icl++ ){
389 AliHLTITSSpacePointData &d = inPtr->fSpacePoints[icl];
391 Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex };
392 Int_t info[3] = { d.fNy, d.fNz, d.fLayer };
393 Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ };
394 if( d.fLayer==4 ) hit[5] = -hit[5];
395 // tracker does not out the clusters, add them to transient array
396 fTracker->AddCluster( new((*fClusters)[nClTotal++]) AliITSRecPoint(lab,hit,info) );
400 }// end read input blocks
402 // Reconstruct the event
405 fTracker->SetSPDVertex(vertexSPD);
406 fTracker->ProcessEvent();
410 // Fill output tracks
411 int nAddedTracks = 0;
413 int nFoundTracks = fTracker->GetNTracks();
414 AliHLTUInt32_t blockSize = sizeof(AliHLTITSSAPTrackerDataContainer) + nFoundTracks*sizeof(AliHLTITSSAPTrackerData);
415 if( size + blockSize + AliFlatESDVertex::GetSize() > maxBufferSize ){
416 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored",
417 maxBufferSize, size + blockSize, nFoundTracks);
421 blockSize = sizeof(AliHLTITSSAPTrackerDataContainer);
422 AliHLTITSSAPTrackerDataContainer *data = reinterpret_cast<AliHLTITSSAPTrackerDataContainer*>(outputPtr);
424 for (int itr=0;itr<nFoundTracks;itr++) {
425 const AliITSSAPTracker::ITStrack_t& track = fTracker->GetTrack(itr);
426 // the track is just a struct of 2 AliExternalTrackParams (params at vertex and at the outer ITS layer)
427 // + some extra info, see "struct ITStrack" in the AliITSSAPTracker.h
428 if ( track.paramOut.TestBit(AliITSSAPTracker::kInvalidBit) ||
429 track.paramInw.TestBit(AliITSSAPTracker::kInvalidBit)) continue;
430 // use only those tracks whose both inward and outward params are OK.
431 AliHLTITSSAPTrackerData &trcHLT = data->fTracks[data->fCount];
432 trcHLT.paramOut.SetExternalTrackParam(&track.paramOut);
433 trcHLT.paramInw.SetExternalTrackParam(&track.paramInw);
434 trcHLT.chi2 = track.chi2;
435 trcHLT.ncl = track.ncl;
436 trcHLT.label = track.label;
438 blockSize += sizeof(AliHLTITSSAPTrackerData);
442 AliHLTComponentBlockData resultData;
443 FillBlockData( resultData );
444 resultData.fOffset = size;
445 resultData.fSize = blockSize;
446 resultData.fDataType = kAliHLTDataTypeITSSAPData|kAliHLTDataOriginITS;
447 fBenchmark.AddOutput(resultData.fSize);
448 outputBlocks.push_back( resultData );
449 size += resultData.fSize;
453 Bool_t vtxOK = kFALSE;
454 { // Fill output vertexTracks
455 AliESDVertex& vtxTracks = fTracker->GetTrackVertex();
456 if ( iResult>=0 && vtxTracks.GetStatus()==1 ) {
457 AliFlatESDVertex *flatVtx = reinterpret_cast<AliFlatESDVertex*>( outputPtr + size );
458 flatVtx->SetFromESDVertex( vtxTracks );
459 AliHLTComponentBlockData resultData;
460 FillBlockData( resultData );
461 resultData.fOffset = size;
462 resultData.fSize = flatVtx->GetSize();
463 resultData.fDataType = kAliHLTDataTypeFlatESDVertex|kAliHLTDataOriginITS;
464 fBenchmark.AddOutput(resultData.fSize);
465 outputBlocks.push_back( resultData );
466 size += resultData.fSize;
476 // Set log level to "Warning" for on-line system monitoring
477 HLTInfo( "ITS SAP Tracker: output %d tracks; input %d clusters, VertexTracks: %s",
478 nAddedTracks, nClTotal, vtxOK ? "OK" : "Found" );
480 HLTBenchmark(fBenchmark.GetStatistics());