// $Id: AliHLTITSTrackerComponent.cxx 32659 2009-06-02 16:08:40Z sgorbuno $ // ************************************************************************** // This file is property of and copyright by the ALICE HLT Project * // ALICE Experiment at CERN, All rights reserved. * // * // Primary Authors: Sergey Gorbunov * // Ivan Kisel * // for The ALICE HLT Project. * // * // Permission to use, copy, modify and distribute this software and its * // documentation strictly for non-commercial purposes is hereby granted * // without fee, provided that the above copyright notice appears in all * // copies and that both the copyright notice and this permission notice * // appear in the supporting documentation. The authors make no claims * // about the suitability of this software for any purpose. It is * // provided "as is" without express or implied warranty. * // * //*************************************************************************** /// @file AliHLTITSTrackerComponent.cxx /// @author Sergey Gorbunov /// @date June 2009 /// @brief An ITS tracker processing component for the HLT ///////////////////////////////////////////////////// // // // a ITS tracker processing component for the HLT // // // ///////////////////////////////////////////////////// #if __GNUC__>= 3 using namespace std; #endif #include "AliHLTITSTrackerComponent.h" #include "AliHLTArray.h" #include "AliExternalTrackParam.h" #include "TStopwatch.h" #include "TMath.h" #include "AliCDBEntry.h" #include "AliCDBManager.h" #include "AliGeomManager.h" #include "TObjString.h" #include "TObjArray.h" #include "AliITStrackerHLT.h" #include "AliHLTITSSpacePointData.h" #include "AliHLTITSClusterDataFormat.h" #include "AliHLTDataTypes.h" #include "AliHLTExternalTrackParam.h" #include "AliHLTGlobalBarrelTrack.h" #include "AliGeomManager.h" /** ROOT macro for the implementation of ROOT specific class methods */ ClassImp( AliHLTITSTrackerComponent ) AliHLTITSTrackerComponent::AliHLTITSTrackerComponent() : fSolenoidBz( 0 ), fFullTime( 0 ), fRecoTime( 0 ), fNEvents( 0 ), fTracker(0) { // see header file for class documentation // or // refer to README to build package // or // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt } AliHLTITSTrackerComponent::AliHLTITSTrackerComponent( const AliHLTITSTrackerComponent& ) : AliHLTProcessor(), fSolenoidBz( 0 ), fFullTime( 0 ), fRecoTime( 0 ), fNEvents( 0 ), fTracker(0) { // see header file for class documentation HLTFatal( "copy constructor untested" ); } AliHLTITSTrackerComponent& AliHLTITSTrackerComponent::operator=( const AliHLTITSTrackerComponent& ) { // see header file for class documentation HLTFatal( "assignment operator untested" ); return *this; } AliHLTITSTrackerComponent::~AliHLTITSTrackerComponent() { // see header file for class documentation delete fTracker; } // // Public functions to implement AliHLTComponent's interface. // These functions are required for the registration process // const char* AliHLTITSTrackerComponent::GetComponentID() { // see header file for class documentation return "ITSTracker"; } void AliHLTITSTrackerComponent::GetInputDataTypes( vector& list ) { // see header file for class documentation list.clear(); list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ); list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD ); list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD ); list.push_back( kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD ); } AliHLTComponentDataType AliHLTITSTrackerComponent::GetOutputDataType() { // see header file for class documentation return kAliHLTMultipleDataType; } int AliHLTITSTrackerComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { // see header file for class documentation tgtList.clear(); tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITS); tgtList.push_back(kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut); return tgtList.size(); } void AliHLTITSTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { // define guess for the output data size constBase = 200; // minimum size inputMultiplier = 2.; // size relative to input } AliHLTComponent* AliHLTITSTrackerComponent::Spawn() { // see header file for class documentation return new AliHLTITSTrackerComponent; } void AliHLTITSTrackerComponent::SetDefaultConfiguration() { // Set default configuration for the CA tracker component // Some parameters can be later overwritten from the OCDB fSolenoidBz = -5.00668; fFullTime = 0; fRecoTime = 0; fNEvents = 0; } int AliHLTITSTrackerComponent::ReadConfigurationString( const char* arguments ) { // Set configuration parameters for the CA tracker component from the string int iResult = 0; if ( !arguments ) return iResult; TString allArgs = arguments; TString argument; int bMissingParam = 0; TObjArray* pTokens = allArgs.Tokenize( " " ); int nArgs = pTokens ? pTokens->GetEntries() : 0; for ( int i = 0; i < nArgs; i++ ) { argument = ( ( TObjString* )pTokens->At( i ) )->GetString(); if ( argument.IsNull() ) continue; if ( argument.CompareTo( "-solenoidBz" ) == 0 ) { if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break; HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz()); continue; } //if ( argument.CompareTo( "-minNClustersOnTrack" ) == 0 ) { //if ( ( bMissingParam = ( ++i >= pTokens->GetEntries() ) ) ) break; //fMinNTrackClusters = ( ( TObjString* )pTokens->At( i ) )->GetString().Atoi(); //HLTInfo( "minNClustersOnTrack set to: %d", fMinNTrackClusters ); //continue; //} HLTError( "Unknown option \"%s\"", argument.Data() ); iResult = -EINVAL; } delete pTokens; if ( bMissingParam ) { HLTError( "Specifier missed for parameter \"%s\"", argument.Data() ); iResult = -EINVAL; } return iResult; } int AliHLTITSTrackerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId ) { // see header file for class documentation const char* defaultNotify = ""; if ( !cdbEntry ) { return 0;// need to add the HLT/ConfigITS/ITSTracker directory to cdb SG!!! cdbEntry = "HLT/ConfigITS/ITSTracker"; defaultNotify = " (default)"; chainId = 0; } HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "" ); AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo()); if ( !pEntry ) { HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry ); return -EINVAL; } TObjString* pString = dynamic_cast( pEntry->GetObject() ); if ( !pString ) { HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry ); return -EINVAL; } HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() ); return ReadConfigurationString( pString->GetString().Data() ); } int AliHLTITSTrackerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine ) { // Configure the component // There are few levels of configuration, // parameters which are set on one step can be overwritten on the next step //* read hard-coded values SetDefaultConfiguration(); //* read the default CDB entry int iResult1 = ReadCDBEntry( NULL, chainId ); //* read magnetic field int iResult2 = true; //ReadCDBEntry( kAliHLTCDBSolenoidBz, chainId ); fSolenoidBz = GetBz(); //* read the actual CDB entry if required int iResult3 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0; //* read extra parameters from input (if they are) int iResult4 = 0; if ( commandLine && commandLine[0] != '\0' ) { HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine ); iResult4 = ReadConfigurationString( commandLine ); } // Initialise the tracker here return iResult1 ? iResult1 : ( iResult2 ? iResult2 : ( iResult3 ? iResult3 : iResult4 ) ); } int AliHLTITSTrackerComponent::DoInit( int argc, const char** argv ) { // Configure the ITS tracker component if ( fTracker ) return -EINPROGRESS; if(AliGeomManager::GetGeometry()==NULL){ AliGeomManager::LoadGeometry(); } AliGeomManager::ApplyAlignObjsFromCDB("ITS"); TString arguments = ""; for ( int i = 0; i < argc; i++ ) { if ( !arguments.IsNull() ) arguments += " "; arguments += argv[i]; } int ret = Configure( NULL, NULL, arguments.Data() ); // Check field if (!TGeoGlobalMagField::Instance()) { HLTError("magnetic field not initialized, please set up TGeoGlobalMagField and AliMagF"); return -ENODEV; } fSolenoidBz=GetBz(); fTracker = new AliITStrackerHLT(0); return ret; } int AliHLTITSTrackerComponent::DoDeinit() { // see header file for class documentation delete fTracker; fTracker = 0; return 0; } int AliHLTITSTrackerComponent::Reconfigure( const char* cdbEntry, const char* chainId ) { // Reconfigure the component from OCDB . return Configure( cdbEntry, chainId, NULL ); } int AliHLTITSTrackerComponent::DoEvent ( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector& outputBlocks ) { //* process event AliHLTUInt32_t maxBufferSize = size; size = 0; // output size if (!IsDataEvent()) return 0; if ( evtData.fBlockCnt <= 0 ) { HLTWarning( "no blocks in event" ); return 0; } TStopwatch timer; // Event reconstruction in ITS int iResult=0; int nBlocks = evtData.fBlockCnt; vector< AliExternalTrackParam > tracksTPC; vector< int > tracksTPCId; int nClustersTotal = 0; for (int ndx=0; ndx=0; ndx++) { const AliHLTComponentBlockData* iter = blocks+ndx; if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) || (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) || (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ){ AliHLTITSClusterData *inPtr=reinterpret_cast( iter->fPtr ); nClustersTotal+=inPtr->fSpacePointCnt; } } fTracker->StartLoadClusters(nClustersTotal); for (int ndx=0; ndx=0; ndx++) { const AliHLTComponentBlockData* iter = blocks+ndx; // Read TPC tracks if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){ AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr; int nTracks = dataPtr->fCount; AliHLTExternalTrackParam* currOutTrack = dataPtr->fTracklets; for( int itr=0; itrfTrackID ); unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currOutTrack->fNPoints * sizeof( unsigned int ); currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize ); } } // Read ITS clusters if ( (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD) ) || (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSPD) ) || (iter->fDataType == (kAliHLTDataTypeClusters|kAliHLTDataOriginITSSDD) ) ){ AliHLTITSClusterData *inPtr=reinterpret_cast( iter->fPtr ); int nClusters = inPtr->fSpacePointCnt; for( int icl=0; iclfSpacePoints[icl]; Int_t lab[4] = { d.fTracks[0], d.fTracks[1], d.fTracks[2], d.fIndex }; Int_t info[3] = { d.fNy, d.fNz, d.fLayer }; Float_t hit[6] = { d.fY, d.fZ, d.fSigmaY2, d.fSigmaZ2, d.fQ, d.fSigmaYZ }; if( d.fLayer==4 ) hit[5] = -hit[5]; fTracker->LoadCluster( AliITSRecPoint( lab, hit, info ) ); } } }// end read input blocks // Reconstruct the event TStopwatch timerReco; fTracker->Reconstruct( &(tracksTPC[0]), tracksTPC.size() ); timerReco.Stop(); // Fill output tracks int nITSUpdated = 0; { for( int iOut=0; iOut<=1; iOut++ ){ unsigned int blockSize = 0; AliHLTTracksData* outPtr = ( AliHLTTracksData* )( outputPtr + size ); AliHLTExternalTrackParam* currOutTrack = outPtr->fTracklets; blockSize = ( ( AliHLTUInt8_t * )currOutTrack ) - ( ( AliHLTUInt8_t * )outPtr ); if ( size + blockSize > maxBufferSize ) { HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), tracks are not stored", maxBufferSize, size + blockSize ); iResult = -ENOSPC; break; } outPtr->fCount = 0; AliHLTITSTrack *tracks=0; int nTracks = 0; if( iOut==0 ){ tracks = fTracker->Tracks(); nTracks = fTracker->NTracks(); } else{ tracks = fTracker->ITSOutTracks(); nTracks = fTracker->NITSOutTracks(); } for ( int itr = 0; itr < nTracks; itr++ ) { AliHLTITSTrack &t = tracks[itr]; int id = tracksTPCId[t.TPCtrackId()]; int nClusters = t.GetNumberOfClusters(); if( iOut==0 && nClusters>0 ) nITSUpdated++; unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + nClusters * sizeof( unsigned int ); if ( size + blockSize + dSize > maxBufferSize ) { HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d tracks are not stored", maxBufferSize, size + blockSize + dSize, nTracks - itr + 1 ); iResult = -ENOSPC; break; } currOutTrack->fAlpha = t.GetAlpha(); currOutTrack->fX = t.GetX(); currOutTrack->fY = t.GetY(); currOutTrack->fZ = t.GetZ(); currOutTrack->fLastX = 0; currOutTrack->fLastY = 0; currOutTrack->fLastZ = 0; currOutTrack->fq1Pt = t.GetSigned1Pt(); currOutTrack->fSinPsi = t.GetSnp(); currOutTrack->fTgl = t.GetTgl(); for( int i=0; i<15; i++ ) currOutTrack->fC[i] = t.GetCovariance()[i]; currOutTrack->fTrackID = id; currOutTrack->fFlags = 0; currOutTrack->fNPoints = nClusters; for ( int i = 0; i < nClusters; i++ ) currOutTrack->fPointIDs[i] = t.GetClusterIndex( i ); currOutTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currOutTrack) + dSize ); blockSize += dSize; outPtr->fCount++; } AliHLTComponentBlockData resultData; FillBlockData( resultData ); resultData.fOffset = 0; resultData.fSize = blockSize; if( iOut==0 ){ resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITS; } else { resultData.fDataType = kAliHLTDataTypeTrack|kAliHLTDataOriginITSOut; } outputBlocks.push_back( resultData ); size += resultData.fSize; } } timer.Stop(); fFullTime += timer.RealTime(); fRecoTime += timerReco.RealTime(); fNEvents++; // Set log level to "Warning" for on-line system monitoring int hz = ( int ) ( fFullTime > 1.e-10 ? fNEvents / fFullTime : 100000 ); int hz1 = ( int ) ( fRecoTime > 1.e-10 ? fNEvents / fRecoTime : 100000 ); HLTInfo( "ITS Tracker: output %d tracks; input %d clusters, %d tracks; time: full %d / reco %d Hz", nITSUpdated, nClustersTotal, tracksTPC.size(), hz, hz1 ); return iResult; }