]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCCATrackerComponent.cxx
documentation
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCCATrackerComponent.cxx
CommitLineData
21b6a334 1
2
3/**************************************************************************
9be2600f 4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
21b6a334 6 * *
9be2600f 7 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 * Ivan Kisel <kisel@kip.uni-heidelberg.de> *
9 * for The ALICE HLT Project. *
21b6a334 10 * *
11 * Permission to use, copy, modify and distribute this software and its *
12 * documentation strictly for non-commercial purposes is hereby granted *
13 * without fee, provided that the above copyright notice appears in all *
14 * copies and that both the copyright notice and this permission notice *
15 * appear in the supporting documentation. The authors make no claims *
16 * about the suitability of this software for any purpose. It is *
17 * provided "as is" without express or implied warranty. *
18 **************************************************************************/
19
20///////////////////////////////////////////////////////////////////////////////
21// //
22// a TPC tracker processing component for the HLT based on CA by Ivan Kisel //
23// //
24///////////////////////////////////////////////////////////////////////////////
25
26#if __GNUC__>= 3
27using namespace std;
28#endif
29
30#include "AliHLTTPCCATrackerComponent.h"
31#include "AliHLTTPCTransform.h"
32#include "AliHLTTPCCATracker.h"
33#include "AliHLTTPCVertex.h"
34#include "AliHLTTPCSpacePointData.h"
35#include "AliHLTTPCVertexData.h"
36#include "AliHLTTPCClusterDataFormat.h"
37#include "AliHLTTPCTransform.h"
38#include "AliHLTTPCTrackSegmentData.h"
39#include "AliHLTTPCTrackArray.h"
40#include "AliHLTTPCTrackletDataFormat.h"
96bda103 41#include "AliHLTTPCDefinitions.h"
5994547c 42//#include "AliHLTTPC.h"
21b6a334 43#include <stdlib.h>
44#include <iostream>
45#include <errno.h>
46
47//static bool ask = true;
48static bool ask = false;
49
50// this is a global object used for automatic component registration, do not use this
51AliHLTTPCCATrackerComponent gAliHLTTPCCATrackerComponent;
52
53ClassImp(AliHLTTPCCATrackerComponent)
54
55AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
96bda103 56 :
57 fTracker(NULL),
58 fVertex(NULL)
59{
60 // see header file for class documentation
61 // or
62 // refer to README to build package
63 // or
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
65}
66
67AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent(const AliHLTTPCCATrackerComponent&)
68 :
69 fTracker(NULL),
70 fVertex(NULL)
71{
72 // see header file for class documentation
73 HLTFatal("copy constructor untested");
74}
75
76AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=(const AliHLTTPCCATrackerComponent&)
77{
78 // see header file for class documentation
79 HLTFatal("assignment operator untested");
80 return *this;
81}
21b6a334 82
83AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
84 {
96bda103 85 // see header file for class documentation
21b6a334 86 }
87
88// Public functions to implement AliHLTComponent's interface.
89// These functions are required for the registration process
90
91const char* AliHLTTPCCATrackerComponent::GetComponentID()
92 {
96bda103 93 // see header file for class documentation
21b6a334 94 return "TPCCATracker";
95 }
96
96bda103 97void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
21b6a334 98 {
96bda103 99 // see header file for class documentation
21b6a334 100 list.clear();
96bda103 101 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
102 list.push_back( AliHLTTPCDefinitions::fgkVertexDataType );
21b6a334 103 }
104
96bda103 105AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
21b6a334 106 {
96bda103 107 // see header file for class documentation
108 return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
21b6a334 109 }
110
111void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
112 {
96bda103 113 // see header file for class documentation
21b6a334 114 // XXX TODO: Find more realistic values.
115 constBase = 0;
116 inputMultiplier = 0.2;
117 }
118
119AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
120 {
96bda103 121 // see header file for class documentation
21b6a334 122 return new AliHLTTPCCATrackerComponent;
123 }
124
125int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
126 {
96bda103 127 // see header file for class documentation
21b6a334 128 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
129
130 if ( fTracker || fVertex )
131 return EINPROGRESS;
132
133 fTracker = new AliHLTTPCCATracker();
134 fTracker->CACreateHistos();
135
136 fVertex = new AliHLTTPCVertex();
137
138
139/* ---------------------------------------------------------------------------------
140 * cmdline arguments not needed so far
141
142 int i = 0;
143 char* cpErr;
144
145 while ( i < argc )
146 {
147 if ( !strcmp( argv[i], "bfield" ) )
148 {
149 if ( argc <= i+1 )
150 {
151 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing B-field", "Missing B-field specifier." );
152 return ENOTSUP;
153 }
154 fBField = strtod( argv[i+1], &cpErr );
155 if ( *cpErr )
156 {
157 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
158 return EINVAL;
159 }
160 i += 2;
161 continue;
162 }
163
164 Logging(kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
165 return EINVAL;
166 }
167--------------------------------------------------------------------------------- */
168
169 return 0;
170 }
171
172int AliHLTTPCCATrackerComponent::DoDeinit()
173 {
96bda103 174 // see header file for class documentation
21b6a334 175 if ( fTracker )
176 delete fTracker;
177 fTracker = NULL;
178 if ( fVertex )
179 delete fVertex;
180 fVertex = NULL;
181 return 0;
182 }
183
96bda103 184int AliHLTTPCCATrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
185 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
186 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
21b6a334 187 {
96bda103 188 // see header file for class documentation
21b6a334 189 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "DoEvent", "DoEvent()" );
190 if ( evtData.fBlockCnt<=0 )
191 {
192 Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "no blocks in event" );
193 return 0;
194 }
195
96bda103 196 const AliHLTComponentBlockData* iter = NULL;
21b6a334 197 unsigned long ndx;
198 AliHLTTPCClusterData* inPtrSP;
199 AliHLTTPCVertexData* inPtrV = NULL;
96bda103 200 const AliHLTComponentBlockData* vertexIter=NULL;
21b6a334 201 AliHLTTPCTrackletData* outPtr;
202 AliHLTUInt8_t* outBPtr;
203
204 AliHLTUInt32_t vSize = 0;
205 UInt_t offset=0, mysize, tSize = 0;
206 outBPtr = outputPtr;
207
208 outPtr = (AliHLTTPCTrackletData*)(outBPtr);
209 fTracker->SetOutPtr( outPtr->fTracklets );
210
211 // ------------------------------------------
212
213 Int_t slice=-1, patch=-1, row[2];
214 Int_t minPatch=INT_MAX, maxPatch = 0;
215 offset = 0;
216 std::vector<Int_t> slices;
217 std::vector<Int_t>::iterator slIter, slEnd;
218 std::vector<unsigned> sliceCnts;
219 std::vector<unsigned>::iterator slCntIter;
220 Int_t vertexSlice=-1;
221
222 // Find min/max rows used in total and find and read out vertex if it is present
223 // also determine correct slice number, if multiple slice numbers are present in event
224 // (which should not happen in the first place) we use the one that occurs the most times
225 row[0] = 0;
226 row[1] = 0;
227 bool found;
228
229 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
230 {
231 iter = blocks+ndx;
232
233
234 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
235 found = false;
236 slIter = slices.begin();
237 slEnd = slices.end();
238 slCntIter = sliceCnts.begin();
239 while ( slIter != slEnd )
240 {
241 if ( *slIter == slice )
242 {
243 found = true;
244 break;
245 }
246 slIter++;
247 slCntIter++;
248 }
249 if ( !found )
250 {
251 slices.insert( slices.end(), slice );
252 sliceCnts.insert( sliceCnts.end(), 1 );
253 }
254 else
255 *slCntIter++;
256
96bda103 257 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType )
21b6a334 258 {
259 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
260 vertexIter = iter;
261 vSize = iter->fSize;
262 fVertex->Read( inPtrV );
263 vertexSlice = slice;
264 }
96bda103 265 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
21b6a334 266 {
267 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
268 if ( minPatch>patch )
269 {
270 minPatch = patch;
271 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
272 }
273 if ( maxPatch<patch )
274 {
275 maxPatch = patch;
276 row[1] = AliHLTTPCTransform::GetLastRow( patch );
277 }
278 }
279 }
280
281 // Determine slice number to really use.
282 if ( slices.size()>1 )
283 {
284 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
285 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
286 evtData.fEventID, evtData.fEventID );
287 unsigned maxCntSlice=0;
288 slIter = slices.begin();
289 slEnd = slices.end();
290 slCntIter = sliceCnts.begin();
291 while ( slIter != slEnd )
292 {
293 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
294 "Slice %lu found %lu times.", *slIter, *slCntIter );
295 if ( maxCntSlice<*slCntIter )
296 {
297 maxCntSlice = *slCntIter;
298 slice = *slIter;
299 }
300 slIter++;
301 slCntIter++;
302 }
303 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
304 "Using slice %lu.", slice );
305 }
306 else if ( slices.size()>0 )
307 {
308 slice = *(slices.begin());
309 }
310 else
311 {
312 slice = -1;
313 }
314
315 if ( vertexSlice != slice )
316 {
317 // multiple vertex blocks in event and we used the wrong one...
318 found = false;
319 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
320 {
321 iter = blocks+ndx;
96bda103 322 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
21b6a334 323 {
324 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
325 vertexIter = iter;
326 vSize = iter->fSize;
327 fVertex->Read( inPtrV );
328 break;
329 }
330 }
331 }
332
333 // fTracker->InitSector( slice, row, fEta );
334 // fTracker->SetVertex(fVertex);
335
336 mysize = 0;
337 // read in all hits
338 std::vector<unsigned long> patchIndices;
339 std::vector<unsigned long>::iterator pIter, pEnd;
340 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
341 {
342 iter = blocks+ndx;
343
96bda103 344 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
21b6a334 345 {
346 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
347 pIter = patchIndices.begin();
348 pEnd = patchIndices.end();
349 while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
350 pIter++;
351 patchIndices.insert( pIter, ndx );
352 }
353 }
354
355 fTracker->CAInitialize();
356
357 pIter = patchIndices.begin();
358 pEnd = patchIndices.end();
359 while ( pIter!=pEnd )
360 {
361 ndx = *pIter;
362 iter = blocks+ndx;
363
364 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
365 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
366
367 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
368 "Reading hits for slice %d - patch %d", slice, patch );
369
370 fTracker->CAReadPatchHits( patch, inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
371 fTracker->CAFindPatchTracks( patch );
372
373 pIter++;
374 }
375
376 fTracker->CAFindSliceTracks();
377
378 //#ifdef XXX
379 char symbol;
380 if (ask){
381 do{
382 std::cin.get(symbol);
383 if (symbol == 'r')
384 ask = false;
385 } while (symbol != '\n');
386 }
387 //#endif //XXX
388
389
390 UInt_t ntracks0=0;
391
392 mysize = fTracker->GetOutputSize();
393 ntracks0 = fTracker->GetOutputNTracks();
394 outPtr->fTrackletCnt = fTracker->GetOutputNTracks();
395
396 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
397 "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.",
398 ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
399
400 tSize += mysize+sizeof(AliHLTTPCTrackletData);
401 outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
402
96bda103 403 AliHLTComponentBlockData bd;
21b6a334 404 FillBlockData( bd );
405 bd.fOffset = offset;
406 bd.fSize = tSize;
407 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
408 outputBlocks.push_back( bd );
409
410#ifdef FORWARD_VERTEX_BLOCK
411 if ( vertexIter )
412 {
413 // Copy the descriptor block for the vertex information.
414 bd = *vertexIter;
415 outputBlocks.push_back( bd );
416 }
417#endif // FORWARD_VERTEX_BLOCK
418
419 size = tSize;
420
421 fTracker->CAWriteHistos();
422
423 return 0;
424 }
425
426