]>
Commit | Line | Data |
---|---|---|
e8f5ab18 | 1 | // $Id$ |
2 | ||
a6fb14f5 | 3 | // ************************************************************************** |
4 | // This file is property of and copyright by the ALICE HLT Project * | |
5 | // ALICE Experiment at CERN, All rights reserved. * | |
6 | // * | |
7 | // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> * | |
8 | // for The ALICE HLT Project. * | |
9 | // * | |
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. * | |
17 | // * | |
18 | //*************************************************************************** | |
19 | ||
e8f5ab18 | 20 | /// @file AliHLTTPCTrackMCMarkerComponent.cxx |
21 | /// @author Matthias Kretz | |
22 | /// @date | |
23 | /// @brief Marker component for TPC cluster mc labels. | |
24 | /// | |
a6fb14f5 | 25 | |
26 | #include "AliHLTTPCTrackMCMarkerComponent.h" | |
27 | #include "AliHLTTPCTransform.h" | |
a6fb14f5 | 28 | #include "AliHLTTPCTrackletDataFormat.h" |
29 | #include "AliHLTTPCCADef.h" | |
30 | #include "AliHLTTPCDefinitions.h" | |
a371a266 | 31 | #include "AliHLTTPCSpacePointData.h" |
d29671e2 | 32 | #include "AliHLTTPCClusterMCData.h" |
a6fb14f5 | 33 | |
34 | #include "AliCDBEntry.h" | |
35 | #include "AliCDBManager.h" | |
36 | #include "TObjString.h" | |
37 | #include "TObjArray.h" | |
38 | #include "AliHLTExternalTrackParam.h" | |
39 | #include "AliHLTTrackMCLabel.h" | |
a6fb14f5 | 40 | #include <climits> |
41 | #include <cstdlib> | |
42 | #include <cerrno> | |
e8f5ab18 | 43 | #include <algorithm> |
a6fb14f5 | 44 | |
45 | // ROOT macro for the implementation of ROOT specific class methods | |
46 | ClassImp( AliHLTTPCTrackMCMarkerComponent ) | |
47 | ||
48 | ||
49 | AliHLTTPCTrackMCMarkerComponent::AliHLTTPCTrackMCMarkerComponent() | |
50 | { | |
51 | // see header file for class documentation | |
8668fb4b | 52 | for( int i=0; i<36*6; i++ ){ |
d29671e2 | 53 | fClusterLabels[i] = 0; |
8668fb4b | 54 | } |
a6fb14f5 | 55 | } |
56 | ||
57 | // Public functions to implement AliHLTComponent's interface. | |
58 | // These functions are required for the registration process | |
59 | ||
60 | const char *AliHLTTPCTrackMCMarkerComponent::GetComponentID() | |
61 | { | |
62 | // see header file for class documentation | |
63 | return "TPCTrackMCMarker"; | |
64 | } | |
65 | ||
66 | void AliHLTTPCTrackMCMarkerComponent::GetInputDataTypes( AliHLTComponentDataTypeList &list ) | |
67 | { | |
68 | // see header file for class documentation | |
69 | list.clear(); | |
70 | list.push_back( kAliHLTDataTypeTrack|kAliHLTDataOriginTPC ); | |
71 | list.push_back(AliHLTTPCDefinitions::fgkAliHLTDataTypeClusterMCInfo); | |
72 | } | |
73 | ||
74 | AliHLTComponentDataType AliHLTTPCTrackMCMarkerComponent::GetOutputDataType() | |
75 | { | |
76 | // see header file for class documentation | |
77 | return kAliHLTDataTypeTrackMC|kAliHLTDataOriginTPC; | |
78 | } | |
79 | ||
80 | void AliHLTTPCTrackMCMarkerComponent::GetOutputDataSize( unsigned long &constBase, double &inputMultiplier ) | |
81 | { | |
82 | // see header file for class documentation | |
83 | constBase = 0; | |
84 | inputMultiplier = 1.0; | |
85 | } | |
86 | ||
87 | AliHLTComponent *AliHLTTPCTrackMCMarkerComponent::Spawn() | |
88 | { | |
89 | // see header file for class documentation | |
90 | return new AliHLTTPCTrackMCMarkerComponent; | |
91 | } | |
92 | ||
93 | ||
94 | ||
95 | ||
96 | void AliHLTTPCTrackMCMarkerComponent::SetDefaultConfiguration() | |
97 | { | |
98 | // Set default configuration for the CA merger component | |
99 | // Some parameters can be later overwritten from the OCDB | |
100 | } | |
101 | ||
102 | int AliHLTTPCTrackMCMarkerComponent::ReadConfigurationString( const char* arguments ) | |
103 | { | |
104 | // Set configuration parameters for the CA merger component from the string | |
105 | ||
106 | int iResult = 0; | |
107 | if ( !arguments ) return iResult; | |
108 | ||
109 | TString allArgs = arguments; | |
110 | TString argument; | |
111 | int bMissingParam = 0; | |
112 | ||
113 | TObjArray* pTokens = allArgs.Tokenize( " " ); | |
114 | ||
115 | int nArgs = pTokens ? pTokens->GetEntries() : 0; | |
116 | ||
117 | for ( int i = 0; i < nArgs; i++ ) { | |
118 | argument = ( ( TObjString* )pTokens->At( i ) )->GetString(); | |
119 | if ( argument.IsNull() ) continue; | |
120 | ||
a6fb14f5 | 121 | HLTError( "Unknown option \"%s\"", argument.Data() ); |
122 | iResult = -EINVAL; | |
123 | } | |
124 | delete pTokens; | |
125 | ||
126 | if ( bMissingParam ) { | |
127 | HLTError( "Specifier missed for parameter \"%s\"", argument.Data() ); | |
128 | iResult = -EINVAL; | |
129 | } | |
130 | ||
131 | return iResult; | |
132 | } | |
133 | ||
134 | ||
135 | int AliHLTTPCTrackMCMarkerComponent::ReadCDBEntry( const char* /*cdbEntry*/, const char* /*chainId*/ ) | |
136 | { | |
137 | // see header file for class documentation | |
138 | ||
139 | // no settings for a moment, no CDB path, threfore return | |
140 | ||
141 | return 0; | |
142 | /* | |
143 | const char* defaultNotify = ""; | |
144 | ||
145 | if ( !cdbEntry ) { | |
146 | cdbEntry = "HLT/ConfigTPC/TPCTrackMCMarker"; | |
147 | defaultNotify = " (default)"; | |
148 | chainId = 0; | |
149 | } | |
150 | ||
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()); | |
153 | ||
154 | if ( !pEntry ) { | |
155 | HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry ); | |
156 | return -EINVAL; | |
157 | } | |
158 | ||
159 | TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() ); | |
160 | ||
161 | if ( !pString ) { | |
162 | HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry ); | |
163 | return -EINVAL; | |
164 | } | |
165 | ||
166 | HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() ); | |
167 | ||
168 | return ReadConfigurationString( pString->GetString().Data() ); | |
169 | */ | |
170 | } | |
171 | ||
172 | ||
173 | ||
174 | int AliHLTTPCTrackMCMarkerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine ) | |
175 | { | |
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 | |
179 | ||
180 | //* read hard-coded values | |
181 | ||
182 | SetDefaultConfiguration(); | |
183 | ||
184 | //* read the default CDB entry | |
185 | ||
186 | int iResult1 = ReadCDBEntry( NULL, chainId ); | |
187 | ||
188 | //* read the actual CDB entry if required | |
189 | ||
190 | int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0; | |
191 | ||
192 | //* read extra parameters from input (if they are) | |
193 | ||
194 | int iResult3 = 0; | |
195 | ||
196 | if ( commandLine && commandLine[0] != '\0' ) { | |
197 | HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine ); | |
198 | iResult3 = ReadConfigurationString( commandLine ); | |
199 | } | |
200 | ||
201 | return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 ); | |
202 | } | |
203 | ||
204 | ||
205 | ||
206 | ||
207 | int AliHLTTPCTrackMCMarkerComponent::DoInit( int argc, const char** argv ) | |
208 | { | |
209 | // see header file for class documentation | |
210 | ||
211 | TString arguments = ""; | |
212 | for ( int i = 0; i < argc; i++ ) { | |
213 | if ( !arguments.IsNull() ) arguments += " "; | |
214 | arguments += argv[i]; | |
215 | } | |
216 | ||
217 | return Configure( NULL, NULL, arguments.Data() ); | |
218 | } | |
219 | ||
220 | ||
221 | int AliHLTTPCTrackMCMarkerComponent::Reconfigure( const char* cdbEntry, const char* chainId ) | |
222 | { | |
223 | // Reconfigure the component from OCDB | |
224 | ||
225 | return Configure( cdbEntry, chainId, NULL ); | |
226 | } | |
227 | ||
228 | ||
229 | ||
230 | int AliHLTTPCTrackMCMarkerComponent::DoDeinit() | |
231 | { | |
232 | // see header file for class documentation | |
233 | ||
234 | return 0; | |
235 | } | |
236 | ||
237 | Int_t AliHLTTPCTrackMCMarkerComponent::GetTrackMCLabel( unsigned int *hits, int nHits ) | |
238 | { | |
239 | // get MC label for the track | |
240 | ||
241 | Int_t mcLabel = -1; | |
242 | ||
243 | std::vector<int> labels; | |
244 | ||
245 | for( Int_t ih=0; ih<nHits; ih++){ | |
246 | UInt_t id = hits[ih]; | |
a371a266 | 247 | int iSlice = AliHLTTPCSpacePointData::GetSlice(id); |
248 | int iPatch = AliHLTTPCSpacePointData::GetPatch(id); | |
d29671e2 | 249 | unsigned int iCluster = AliHLTTPCSpacePointData::GetNumber(id); |
8668fb4b | 250 | if( iSlice<0 || iSlice>=36 || iPatch<0 || iPatch>5 ){ |
a6fb14f5 | 251 | HLTError("Corrupted TPC cluster Id: slice %d, patch %d, cluster %d", |
252 | iSlice, iPatch,iCluster ); | |
253 | continue; | |
254 | } | |
d29671e2 | 255 | AliHLTTPCClusterMCData *patchLabels = fClusterLabels[iSlice*6 + iPatch]; |
a6fb14f5 | 256 | if( !patchLabels ) continue; |
d29671e2 | 257 | if( iCluster >= patchLabels->fCount ){ |
a6fb14f5 | 258 | HLTError("TPC slice %d, patch %d: ClusterID==%d >= N MC labels==%d ", |
d29671e2 | 259 | iSlice, iPatch,iCluster, patchLabels->fCount); |
a6fb14f5 | 260 | continue; |
261 | } | |
d29671e2 | 262 | AliHLTTPCClusterMCLabel &lab = patchLabels->fLabels[iCluster]; |
a6fb14f5 | 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 ); | |
266 | } | |
267 | ||
268 | std::sort( labels.begin(), labels.end() ); | |
269 | ||
270 | labels.push_back( -1 ); // put -1 to the end | |
271 | ||
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; | |
277 | labelMax = labelCur; | |
278 | } | |
279 | labelCur = labels[iLab]; | |
280 | nLabelsCurr = 0; | |
281 | } | |
282 | nLabelsCurr++; | |
283 | } | |
284 | ||
285 | if( labelMax>=0 && nLabelsMax < 0.9 * nHits ) labelMax = -labelMax; | |
286 | ||
287 | mcLabel = labelMax; | |
288 | ||
289 | return mcLabel; | |
290 | } | |
291 | ||
292 | ||
293 | int AliHLTTPCTrackMCMarkerComponent::DoEvent( const AliHLTComponentEventData &evtData, | |
294 | const AliHLTComponentBlockData *blocks, AliHLTComponentTriggerData &/*trigData*/, | |
295 | AliHLTUInt8_t *outputPtr, AliHLTUInt32_t &size, AliHLTComponentBlockDataList &outputBlocks ) | |
296 | { | |
297 | // see header file for class documentation | |
298 | ||
299 | int iResult = 0; | |
300 | unsigned int maxBufferSize = size; | |
301 | ||
302 | size = 0; | |
303 | ||
304 | if ( !outputPtr ) { | |
305 | return -ENOSPC; | |
306 | } | |
307 | if ( !IsDataEvent() ) { | |
308 | return 0; | |
309 | } | |
310 | ||
311 | for( int i=0; i<36*6; i++ ){ | |
312 | fClusterLabels[i] = 0; | |
a6fb14f5 | 313 | } |
314 | ||
315 | int nBlocks = (int)evtData.fBlockCnt; | |
316 | ||
317 | int nInputMCLabels = 0; | |
318 | int nInputTracks = 0; | |
319 | ||
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); | |
d29671e2 | 326 | fClusterLabels[ slice*6 + patch] = (AliHLTTPCClusterMCData*)iter->fPtr; |
327 | nInputMCLabels+=fClusterLabels[ slice*6 + patch]->fCount; | |
a6fb14f5 | 328 | } |
329 | } | |
330 | ||
331 | // read tracks and write output | |
332 | ||
333 | ||
334 | unsigned int mySize = 0; | |
335 | ||
336 | AliHLTTrackMCData* outPtr = ( AliHLTTrackMCData* )( outputPtr ); | |
337 | AliHLTTrackMCLabel* currOutLabel = outPtr->fLabels; | |
338 | ||
339 | mySize = ( ( AliHLTUInt8_t * )currOutLabel ) - ( ( AliHLTUInt8_t * )outPtr ); | |
340 | ||
341 | outPtr->fCount = 0; | |
342 | ||
343 | for (int ndx=0; ndx<nBlocks && iResult>=0; ndx++) { | |
344 | const AliHLTComponentBlockData* iter = blocks+ndx; | |
345 | ||
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++ ){ | |
351 | nInputTracks++; | |
352 | Int_t mcLabel = GetTrackMCLabel( currTrack->fPointIDs, currTrack->fNPoints ); | |
353 | ||
354 | currOutLabel->fTrackID = currTrack->fTrackID; | |
355 | currOutLabel->fMCLabel = mcLabel; | |
356 | ||
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 ); | |
359 | iResult = -ENOSPC; | |
360 | break; | |
361 | } | |
362 | mySize += sizeof(AliHLTTrackMCLabel); | |
363 | currOutLabel++; | |
364 | outPtr->fCount++; | |
365 | ||
366 | unsigned int dSize = sizeof( AliHLTExternalTrackParam ) + currTrack->fNPoints * sizeof( unsigned int ); | |
367 | currTrack = ( AliHLTExternalTrackParam* )( (( Byte_t * )currTrack) + dSize ); | |
368 | } | |
369 | } | |
370 | } | |
371 | ||
372 | ||
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; | |
381 | ||
382 | HLTInfo( "TrackMCMarker:: input %d labels, %d tracks, output %d labels", nInputMCLabels, nInputTracks,outPtr->fCount ); | |
383 | ||
384 | return iResult; | |
385 | } | |
386 |