3 // **************************************************************************
4 // This file is property of and copyright by the ALICE HLT Project *
5 // ALICE Experiment at CERN, All rights reserved. *
7 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
8 // for The ALICE HLT Project. *
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. *
18 //***************************************************************************
20 /// @file AliHLTTPCTrackMCMarkerComponent.cxx
21 /// @author Matthias Kretz
23 /// @brief Marker component for TPC cluster mc labels.
26 #include "AliHLTTPCTrackMCMarkerComponent.h"
27 #include "AliHLTTPCTransform.h"
28 #include "AliHLTTPCTrackletDataFormat.h"
29 #include "AliHLTTPCCADef.h"
30 #include "AliHLTTPCDefinitions.h"
31 #include "AliHLTTPCSpacePointData.h"
32 #include "AliHLTTPCClusterMCData.h"
34 #include "AliCDBEntry.h"
35 #include "AliCDBManager.h"
36 #include "TObjString.h"
37 #include "TObjArray.h"
38 #include "AliHLTExternalTrackParam.h"
39 #include "AliHLTTrackMCLabel.h"
45 // ROOT macro for the implementation of ROOT specific class methods
46 ClassImp( AliHLTTPCTrackMCMarkerComponent )
49 AliHLTTPCTrackMCMarkerComponent::AliHLTTPCTrackMCMarkerComponent()
51 // see header file for class documentation
52 for( int i=0; i<36*6; i++ ){
53 fClusterLabels[i] = 0;
57 // Public functions to implement AliHLTComponent's interface.
58 // These functions are required for the registration process
60 const char *AliHLTTPCTrackMCMarkerComponent::GetComponentID()
62 // see header file for class documentation
63 return "TPCTrackMCMarker";
66 void AliHLTTPCTrackMCMarkerComponent::GetInputDataTypes( AliHLTComponentDataTypeList &list )
68 // see header file for class documentation
70 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
71 list.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo);
74 AliHLTComponentDataType AliHLTTPCTrackMCMarkerComponent::GetOutputDataType()
76 // see header file for class documentation
77 return kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC;
80 void AliHLTTPCTrackMCMarkerComponent::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier )
82 // see header file for class documentation
84 inputMultiplier = 1.0;
87 AliHLTComponent *AliHLTTPCTrackMCMarkerComponent::Spawn()
89 // see header file for class documentation
90 return new AliHLTTPCTrackMCMarkerComponent;
96 void AliHLTTPCTrackMCMarkerComponent::SetDefaultConfiguration()
98 // Set default configuration for the CA merger component
99 // Some parameters can be later overwritten from the OCDB
102 int AliHLTTPCTrackMCMarkerComponent::ReadConfigurationString( const char* arguments )
104 // Set configuration parameters for the CA merger component from the string
107 if ( !arguments ) return iResult;
109 TString allArgs = arguments;
111 int bMissingParam = 0;
113 TObjArray* pTokens = allArgs.Tokenize( " " );
115 int nArgs = pTokens ? pTokens->GetEntries() : 0;
117 for ( int i = 0; i < nArgs; i++ ) {
118 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
119 if ( argument.IsNull() ) continue;
121 HLTError( "Unknown option \"%s\"", argument.Data() );
126 if ( bMissingParam ) {
127 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
135 int AliHLTTPCTrackMCMarkerComponent::ReadCDBEntry( const char* /*cdbEntry*/, const char* /*chainId*/ )
137 // see header file for class documentation
139 // no settings for a moment, no CDB path, threfore return
143 const char* defaultNotify = "";
146 cdbEntry = "HLT/ConfigTPC/TPCTrackMCMarker";
147 defaultNotify = " (default)";
151 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
152 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
155 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
159 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
162 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
166 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
168 return ReadConfigurationString( pString->GetString().Data() );
174 int AliHLTTPCTrackMCMarkerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
176 // Configure the component
177 // There are few levels of configuration,
178 // parameters which are set on one step can be overwritten on the next step
180 //* read hard-coded values
182 SetDefaultConfiguration();
184 //* read the default CDB entry
186 int iResult1 = ReadCDBEntry( NULL, chainId );
188 //* read the actual CDB entry if required
190 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
192 //* read extra parameters from input (if they are)
196 if ( commandLine && commandLine[0] != '\0' ) {
197 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
198 iResult3 = ReadConfigurationString( commandLine );
201 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
207 int AliHLTTPCTrackMCMarkerComponent::DoInit( int argc, const char** argv )
209 // see header file for class documentation
211 TString arguments = "";
212 for ( int i = 0; i < argc; i++ ) {
213 if ( !arguments.IsNull() ) arguments += " ";
214 arguments += argv[i];
217 return Configure( NULL, NULL, arguments.Data() );
221 int AliHLTTPCTrackMCMarkerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
223 // Reconfigure the component from OCDB
225 return Configure( cdbEntry, chainId, NULL );
230 int AliHLTTPCTrackMCMarkerComponent::DoDeinit()
232 // see header file for class documentation
237 Int_t AliHLTTPCTrackMCMarkerComponent::GetTrackMCLabel( unsigned int *hits, int nHits )
239 // get MC label for the track
243 std::vector<int> labels;
245 for( Int_t ih=0; ih<nHits; ih++){
246 UInt_t id = hits[ih];
247 int iSlice = AliHLTTPCSpacePointData::GetSlice(id);
248 int iPatch = AliHLTTPCSpacePointData::GetPatch(id);
249 unsigned int iCluster = AliHLTTPCSpacePointData::GetNumber(id);
250 if( iSlice<0 || iSlice>=36 || iPatch<0 || iPatch>5 ){
251 HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d",
252 iSlice, iPatch,iCluster );
255 AliHLTTPCClusterMCData *patchLabels = fClusterLabels[iSlice*6 + iPatch];
256 if( !patchLabels ) continue;
257 if( iCluster >= patchLabels->fCount ){
258 HLTError("TPC slice %d, patch %d: ClusterID==%d >= N MC labels==%d ",
259 iSlice, iPatch,iCluster, patchLabels->fCount);
262 AliHLTTPCClusterMCLabel &lab = patchLabels->fLabels[iCluster];
263 if ( lab.fClusterID[0].fMCID >= 0 ) labels.push_back( lab.fClusterID[0].fMCID );
264 if ( lab.fClusterID[1].fMCID >= 0 ) labels.push_back( lab.fClusterID[1].fMCID );
265 if ( lab.fClusterID[2].fMCID >= 0 ) labels.push_back( lab.fClusterID[2].fMCID );
268 std::sort( labels.begin(), labels.end() );
270 labels.push_back( -1 ); // put -1 to the end
272 int labelMax = -1, labelCur = -1, nLabelsMax = 0, nLabelsCurr = 0;
273 for ( unsigned int iLab = 0; iLab < labels.size(); iLab++ ) {
274 if ( labels[iLab] != labelCur ) {
275 if ( labelCur >= 0 && nLabelsMax< nLabelsCurr ) {
276 nLabelsMax = nLabelsCurr;
279 labelCur = labels[iLab];
285 if( labelMax>=0 && nLabelsMax < 0.9 * nHits ) labelMax = -labelMax;
293 int AliHLTTPCTrackMCMarkerComponent::DoEvent( const AliHLTComponentEventData &evtData,
294 const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
295 AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
297 // see header file for class documentation
300 unsigned int maxBufferSize = size;
307 if ( !IsDataEvent() ) {
311 for( int i=0; i<36*6; i++ ){
312 fClusterLabels[i] = 0;
315 int nBlocks = (int)evtData.fBlockCnt;
317 int nInputMCLabels = 0;
318 int nInputTracks = 0;
320 // first read all the MC information
321 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
322 const AliHLTComponentBlockData* iter = blocks+ndx;
323 if(iter->fDataType == AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo ) {
324 Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
325 Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
326 fClusterLabels[ slice*6 + patch] = (AliHLTTPCClusterMCData*)iter->fPtr;
327 nInputMCLabels+=fClusterLabels[ slice*6 + patch]->fCount;
331 // read tracks and write output
334 unsigned int mySize = 0;
336 AliHLTTrackMCData* outPtr = ( AliHLTTrackMCData* )( outputPtr );
337 AliHLTTrackMCLabel* currOutLabel = outPtr->fLabels;
339 mySize = ( ( AliHLTUInt8_t * )currOutLabel ) - ( ( AliHLTUInt8_t * )outPtr );
343 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
344 const AliHLTComponentBlockData* iter = blocks+ndx;
346 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
347 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
348 int nTracks = dataPtr->fCount;
349 AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets;
350 for( int itr=0; itr<nTracks; itr++ ){
352 Int_t mcLabel = GetTrackMCLabel( currTrack->fPointIDs, currTrack->fNPoints );
354 currOutLabel->fTrackID = currTrack->fTrackID;
355 currOutLabel->fMCLabel = mcLabel;
357 if ( mySize + sizeof(AliHLTTrackMCLabel) > maxBufferSize ) {
358 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d mc labels are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
362 mySize += sizeof(AliHLTTrackMCLabel);
366 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
367 currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + dSize );
373 AliHLTComponentBlockData resultData;
374 FillBlockData( resultData );
375 resultData.fOffset = 0;
376 resultData.fSize = mySize;
377 resultData.fDataType = kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC;
378 resultData.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
379 outputBlocks.push_back( resultData );
380 size = resultData.fSize;
382 HLTInfo( "TrackMCMarker:: input %d labels, %d tracks, output %d labels", nInputMCLabels, nInputTracks,outPtr->fCount );