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 // for The ALICE HLT Project. *
8 // Permission to use, copy, modify and distribute this software and its *
9 // documentation strictly for non-commercial purposes is hereby granted *
10 // without fee, provided that the above copyright notice appears in all *
11 // copies and that both the copyright notice and this permission notice *
12 // appear in the supporting documentation. The authors make no claims *
13 // about the suitability of this software for any purpose. It is *
14 // provided "as is" without express or implied warranty. *
16 //***************************************************************************
23 #include "AliHLTTPCTrackMCMarkerComponent.h"
24 #include "AliHLTTPCTransform.h"
25 #include "AliHLTTPCTrackSegmentData.h"
26 #include "AliHLTTPCTrack.h"
27 #include "AliHLTTPCTrackArray.h"
28 #include "AliHLTTPCTrackletDataFormat.h"
29 #include "AliHLTTPCCADef.h"
30 #include "AliHLTTPCDefinitions.h"
32 #include "AliCDBEntry.h"
33 #include "AliCDBManager.h"
34 #include "TObjString.h"
35 #include "TObjArray.h"
36 #include "AliHLTExternalTrackParam.h"
37 #include "AliHLTTrackMCLabel.h"
38 #include "AliHLTTPCClusterFinder.h"
44 // ROOT macro for the implementation of ROOT specific class methods
45 ClassImp( AliHLTTPCTrackMCMarkerComponent )
48 AliHLTTPCTrackMCMarkerComponent::AliHLTTPCTrackMCMarkerComponent()
50 // see header file for class documentation
53 // Public functions to implement AliHLTComponent's interface.
54 // These functions are required for the registration process
56 const char *AliHLTTPCTrackMCMarkerComponent::GetComponentID()
58 // see header file for class documentation
59 return "TPCTrackMCMarker";
62 void AliHLTTPCTrackMCMarkerComponent::GetInputDataTypes( AliHLTComponentDataTypeList &list )
64 // see header file for class documentation
66 list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC );
67 list.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo);
70 AliHLTComponentDataType AliHLTTPCTrackMCMarkerComponent::GetOutputDataType()
72 // see header file for class documentation
73 return kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC;
76 void AliHLTTPCTrackMCMarkerComponent::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier )
78 // see header file for class documentation
80 inputMultiplier = 1.0;
83 AliHLTComponent *AliHLTTPCTrackMCMarkerComponent::Spawn()
85 // see header file for class documentation
86 return new AliHLTTPCTrackMCMarkerComponent;
92 void AliHLTTPCTrackMCMarkerComponent::SetDefaultConfiguration()
94 // Set default configuration for the CA merger component
95 // Some parameters can be later overwritten from the OCDB
98 int AliHLTTPCTrackMCMarkerComponent::ReadConfigurationString( const char* arguments )
100 // Set configuration parameters for the CA merger component from the string
103 if ( !arguments ) return iResult;
105 TString allArgs = arguments;
107 int bMissingParam = 0;
109 TObjArray* pTokens = allArgs.Tokenize( " " );
111 int nArgs = pTokens ? pTokens->GetEntries() : 0;
113 for ( int i = 0; i < nArgs; i++ ) {
114 argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
115 if ( argument.IsNull() ) continue;
117 HLTError( "Unknown option \"%s\"", argument.Data() );
122 if ( bMissingParam ) {
123 HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
131 int AliHLTTPCTrackMCMarkerComponent::ReadCDBEntry( const char* /*cdbEntry*/, const char* /*chainId*/ )
133 // see header file for class documentation
135 // no settings for a moment, no CDB path, threfore return
139 const char* defaultNotify = "";
142 cdbEntry = "HLT/ConfigTPC/TPCTrackMCMarker";
143 defaultNotify = " (default)";
147 HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
148 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
151 HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
155 TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
158 HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
162 HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
164 return ReadConfigurationString( pString->GetString().Data() );
170 int AliHLTTPCTrackMCMarkerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
172 // Configure the component
173 // There are few levels of configuration,
174 // parameters which are set on one step can be overwritten on the next step
176 //* read hard-coded values
178 SetDefaultConfiguration();
180 //* read the default CDB entry
182 int iResult1 = ReadCDBEntry( NULL, chainId );
184 //* read the actual CDB entry if required
186 int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
188 //* read extra parameters from input (if they are)
192 if ( commandLine && commandLine[0] != '\0' ) {
193 HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
194 iResult3 = ReadConfigurationString( commandLine );
197 return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
203 int AliHLTTPCTrackMCMarkerComponent::DoInit( int argc, const char** argv )
205 // see header file for class documentation
207 TString arguments = "";
208 for ( int i = 0; i < argc; i++ ) {
209 if ( !arguments.IsNull() ) arguments += " ";
210 arguments += argv[i];
213 return Configure( NULL, NULL, arguments.Data() );
217 int AliHLTTPCTrackMCMarkerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
219 // Reconfigure the component from OCDB
221 return Configure( cdbEntry, chainId, NULL );
226 int AliHLTTPCTrackMCMarkerComponent::DoDeinit()
228 // see header file for class documentation
233 Int_t AliHLTTPCTrackMCMarkerComponent::GetTrackMCLabel( unsigned int *hits, int nHits )
235 // get MC label for the track
239 std::vector<int> labels;
241 for( Int_t ih=0; ih<nHits; ih++){
242 UInt_t id = hits[ih];
244 int iPatch = (id>>22)&0x7;
245 int iCluster = id&0x3fffff;
246 if( iSlice<0 || iSlice>36 || iPatch<0 || iPatch>5 ){
247 HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d",
248 iSlice, iPatch,iCluster );
251 AliHLTTPCClusterFinder::ClusterMCInfo *patchLabels = fClusterLabels[iSlice*6 + iPatch];
252 if( !patchLabels ) continue;
253 if( iCluster >= fNClusterLabels[iSlice*6 + iPatch] ){
254 HLTError("TPC slice %d, patch %d: ClusterID==%d >= N MC labels==%d ",
255 iSlice, iPatch,iCluster, fNClusterLabels[iSlice*6 + iPatch] );
258 AliHLTTPCClusterFinder::ClusterMCInfo &lab = patchLabels[iCluster];
259 if ( lab.fClusterID[0].fMCID >= 0 ) labels.push_back( lab.fClusterID[0].fMCID );
260 if ( lab.fClusterID[1].fMCID >= 0 ) labels.push_back( lab.fClusterID[1].fMCID );
261 if ( lab.fClusterID[2].fMCID >= 0 ) labels.push_back( lab.fClusterID[2].fMCID );
264 std::sort( labels.begin(), labels.end() );
266 labels.push_back( -1 ); // put -1 to the end
268 int labelMax = -1, labelCur = -1, nLabelsMax = 0, nLabelsCurr = 0;
269 for ( unsigned int iLab = 0; iLab < labels.size(); iLab++ ) {
270 if ( labels[iLab] != labelCur ) {
271 if ( labelCur >= 0 && nLabelsMax< nLabelsCurr ) {
272 nLabelsMax = nLabelsCurr;
275 labelCur = labels[iLab];
281 if( labelMax>=0 && nLabelsMax < 0.9 * nHits ) labelMax = -labelMax;
289 int AliHLTTPCTrackMCMarkerComponent::DoEvent( const AliHLTComponentEventData &evtData,
290 const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/,
291 AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks )
293 // see header file for class documentation
296 unsigned int maxBufferSize = size;
303 if ( !IsDataEvent() ) {
307 for( int i=0; i<36*6; i++ ){
308 fClusterLabels[i] = 0;
309 fNClusterLabels[i] = 0;
312 int nBlocks = (int)evtData.fBlockCnt;
314 int nInputMCLabels = 0;
315 int nInputTracks = 0;
317 // first read all the MC information
318 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
319 const AliHLTComponentBlockData* iter = blocks+ndx;
320 if(iter->fDataType == AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo ) {
321 Int_t slice=AliHLTTPCDefinitions::GetMinSliceNr(iter->fSpecification);
322 Int_t patch=AliHLTTPCDefinitions::GetMinPatchNr(iter->fSpecification);
323 fClusterLabels[ slice*6 + patch] = (AliHLTTPCClusterFinder::ClusterMCInfo *)iter->fPtr;
324 fNClusterLabels[ slice*6 + patch] = iter->fSize/sizeof(AliHLTTPCClusterFinder::ClusterMCInfo);
325 nInputMCLabels+=fNClusterLabels[ slice*6 + patch];
329 // read tracks and write output
332 unsigned int mySize = 0;
334 AliHLTTrackMCData* outPtr = ( AliHLTTrackMCData* )( outputPtr );
335 AliHLTTrackMCLabel* currOutLabel = outPtr->fLabels;
337 mySize = ( ( AliHLTUInt8_t * )currOutLabel ) - ( ( AliHLTUInt8_t * )outPtr );
341 for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) {
342 const AliHLTComponentBlockData* iter = blocks+ndx;
344 if( iter->fDataType == ( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ) ){
345 AliHLTTracksData* dataPtr = ( AliHLTTracksData* ) iter->fPtr;
346 int nTracks = dataPtr->fCount;
347 AliHLTExternalTrackParam* currTrack = dataPtr->fTracklets;
348 for( int itr=0; itr<nTracks; itr++ ){
350 Int_t mcLabel = GetTrackMCLabel( currTrack->fPointIDs, currTrack->fNPoints );
352 currOutLabel->fTrackID = currTrack->fTrackID;
353 currOutLabel->fMCLabel = mcLabel;
355 if ( mySize + sizeof(AliHLTTrackMCLabel) > maxBufferSize ) {
356 HLTWarning( "Output buffer size exceed (buffer size %d, current size %d), %d mc labels are not stored", maxBufferSize, mySize, nTracks - itr + 1 );
360 mySize += sizeof(AliHLTTrackMCLabel);
364 unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int );
365 currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + dSize );
371 AliHLTComponentBlockData resultData;
372 FillBlockData( resultData );
373 resultData.fOffset = 0;
374 resultData.fSize = mySize;
375 resultData.fDataType = kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC;
376 resultData.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
377 outputBlocks.push_back( resultData );
378 size = resultData.fSize;
380 HLTInfo( "TrackMCMarker:: input %d labels, %d tracks, output %d labels", nInputMCLabels, nInputTracks,outPtr->fCount );