]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCSliceTrackerComponent.cxx
Fixing memory leak (Christian)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCSliceTrackerComponent.cxx
CommitLineData
71d7c760 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line 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///////////////////////////////////////////////////////////////////////////////
20// //
21// a TPC sector tracker processing component for the HLT //
22// //
23///////////////////////////////////////////////////////////////////////////////
24
25#if __GNUC__== 3
26using namespace std;
27#endif
28
29#include "AliHLTTPCSliceTrackerComponent.h"
a6c02c85 30#include "AliHLTTPCTransform.h"
31#include "AliHLTTPCConfMapper.h"
32#include "AliHLTTPCVertex.h"
33#include "AliHLTTPCSpacePointData.h"
34#include "AliHLTTPCVertexData.h"
71d7c760 35#include "AliHLTTPCClusterDataFormat.h"
a6c02c85 36#include "AliHLTTPCTransform.h"
37#include "AliHLTTPCTrackSegmentData.h"
38#include "AliHLTTPCTrackArray.h"
71d7c760 39#include "AliHLTTPCTrackletDataFormat.h"
a6c02c85 40#include "AliHLTTPC.h"
71d7c760 41#include <stdlib.h>
42#include <errno.h>
43
44// this is a global object used for automatic component registration, do not use this
45AliHLTTPCSliceTrackerComponent gAliHLTTPCSliceTrackerComponent;
46
47ClassImp(AliHLTTPCSliceTrackerComponent)
48
49AliHLTTPCSliceTrackerComponent::AliHLTTPCSliceTrackerComponent()
50 {
51 fTracker = NULL;
52 fVertex = NULL;
53 fEta[0] = 0.;
54 fEta[1] = 1.1;
55 fDoNonVertex = false;
a6c02c85 56 fMultiplicity = 4000;
57 fBField = 0.4;
58 fDoPP = false;
71d7c760 59 }
60
61AliHLTTPCSliceTrackerComponent::~AliHLTTPCSliceTrackerComponent()
62 {
63 }
64
65// Public functions to implement AliHLTComponent's interface.
66// These functions are required for the registration process
67
68const char* AliHLTTPCSliceTrackerComponent::GetComponentID()
69 {
70 return "TPCSliceTracker";
71 }
72
73void AliHLTTPCSliceTrackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
74 {
75 list.clear();
76 list.push_back( AliHLTTPCDefinitions::gkClustersDataType );
77 list.push_back( AliHLTTPCDefinitions::gkVertexDataType );
78 }
79
80AliHLTComponent_DataType AliHLTTPCSliceTrackerComponent::GetOutputDataType()
81 {
82 return AliHLTTPCDefinitions::gkTrackSegmentsDataType;
83 }
84
85void AliHLTTPCSliceTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
86 {
87 // XXX TODO: Find more realistic values.
88 constBase = 0;
89 inputMultiplier = 0.2;
90 }
91
92AliHLTComponent* AliHLTTPCSliceTrackerComponent::Spawn()
93 {
94 return new AliHLTTPCSliceTrackerComponent;
95 }
96
97void AliHLTTPCSliceTrackerComponent::SetTrackerParam(Int_t phi_segments, Int_t eta_segments,
98 Int_t trackletlength, Int_t tracklength,
99 Int_t rowscopetracklet, Int_t rowscopetrack,
100 Double_t min_pt_fit, Double_t maxangle,
101 Double_t goodDist, Double_t hitChi2Cut,
102 Double_t goodHitChi2, Double_t trackChi2Cut,
103 Int_t maxdist, Double_t maxphi,Double_t maxeta, bool vertexConstraints )
104 {
105 //fTracker->SetClusterFinderParam( fXYClusterError, fZClusterError, kTRUE ); // ??
106 //Set parameters input to the tracker
107 //If no arguments are given, default parameters will be used
108
109 fTracker->SetNSegments(phi_segments,eta_segments);
110 fTracker->SetMaxDca(min_pt_fit);
111 // fTracker->MainVertexSettings(trackletlength,tracklength,rowscopetracklet,rowscopetrack);
112 fTracker->SetTrackCuts(hitChi2Cut,goodHitChi2,trackChi2Cut,maxdist,vertexConstraints);
113 fTracker->SetTrackletCuts(maxangle,goodDist,vertexConstraints);
114
115 if( vertexConstraints )
116 fTracker->MainVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack, maxphi, maxeta);
117 else
118 fTracker->NonVertexSettings( trackletlength, tracklength, rowscopetracklet, rowscopetrack);
119 //fTracker->SetParamDone(true);
a6c02c85 120
121 //AliHLTTPC::SetVertexFit( kFALSE );
71d7c760 122
123 fTracker->InitVolumes();
124 }
125
126void AliHLTTPCSliceTrackerComponent::SetTrackerParam( bool doPP, int multiplicity, double bField )
127 {
128 if ( doPP )
129 {
130 //tracker->SetClusterFinderParam(xyerror,zerror,kTRUE); // ??
131 SetTrackerParam( 50, 100, 3, 10,
132 2, 2,
133 0, 0.1745, 5, 100,
134 5, 50, 50, 0.1, 0.1, kTRUE);
135 }
136 else
137 {
138 int mults[] = { 1000, 2000, 4000, 8000 };
139 int multCount = 4;
140 int closestMult = 0;
141 int i;
142 int multDist, tmpMultDist;
143 if ( multiplicity>mults[closestMult] )
144 multDist = multiplicity-mults[closestMult];
145 else
146 multDist = mults[closestMult]-multiplicity;
147 for ( i = 1; i < multCount; i++ )
148 {
149 if ( multiplicity>mults[i] )
150 tmpMultDist = multiplicity-mults[i];
151 else
152 tmpMultDist = mults[i]-multiplicity;
153 if ( tmpMultDist < multDist )
154 {
155 closestMult = i;
156 multDist = tmpMultDist;
157 }
158 }
159
160 double bfs[] = { 0.2, 0.4 };
161 int bfCount = 2;
162 int closestBf = 0;
163 double bfDist, tmpBFDist;
164 if ( bField>bfs[closestBf] )
165 bfDist = bField-bfs[closestBf];
166 else
167 bfDist = bfs[closestBf]-bField;
168 for ( i = 1; i < bfCount; i++ )
169 {
170 if ( bField>bfs[i] )
171 tmpBFDist = bField-bfs[i];
172 else
173 tmpBFDist = bfs[i]-bField;
174 if ( tmpBFDist < bfDist )
175 {
176 closestBf = i;
177 bfDist = tmpBFDist;
178 }
179 }
180
181 switch ( closestMult )
182 {
183 case 0: // 1000
184 switch ( closestBf )
185 {
186 case 0: // 0.2
187 SetTrackerParam( 50, 100, 3, 10,
188 2, 4,
189 0, 0.1745, 5, 100,
190 5, 50, 50, 0.1, 0.1, kTRUE );
191 break;
192 case 1: // 0.4
193 SetTrackerParam( 50, 100, 3, 10,
194 2, 4,
195 0, 0.1745, 5, 100,
196 5, 50, 50, 0.1, 0.1, kTRUE );
197 break;
198 }
199 break;
200 case 1: // 2000
201 switch ( closestBf )
202 {
203 case 0: // 0.2
204 SetTrackerParam( 50, 100, 3, 10,
205 2, 4,
206 0, 0.1745, 5, 30,
207 5, 20, 50, 0.1, 0.1, kTRUE );
208 break;
209 case 1: // 0.4
210 SetTrackerParam( 50, 100, 3, 10,
211 2, 5,
212 0, 0.1745, 5, 30,
213 5, 20, 50, 0.1, 0.1, kTRUE );
214 break;
215 }
216 break;
217 case 2: // 4000
218 switch ( closestBf )
219 {
220 case 0: // 0.2
221 SetTrackerParam( 50, 100, 3, 10,
222 2 , 10,
223 0, 0.1745, 5, 20,
224 5, 10 , 50, 0.1, 0.1, kTRUE );
225 break;
226 case 1: // 0.4
227 SetTrackerParam( 50, 100, 3, 10,
228 2, 10,
229 0, 0.1745, 5, 20,
230 5, 10, 50, 0.1, 0.1, kTRUE );
231 break;
232 }
233 break;
234 case 3: // 8000
235 switch ( closestBf )
236 {
237 case 0: // 0.2
238 SetTrackerParam( 50, 100, 3, 10,
239 3, 15,
240 0, 0.1745, 5, 10,
241 5, 5, 50, 0.1, 0.1, kTRUE );
242 break;
243 case 1: // 0.4
244 SetTrackerParam( 50, 100, 3, 10,
245 2, 15,
246 0, 0.1745, 5, 15,
247 5, 5, 50, 0.1, 0.1, kTRUE );
248 break;
249 }
250 break;
251 }
a6c02c85 252 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "BField", "Setting b field to %f\n", bfs[closestBf] );
253 AliHLTTPCTransform::SetBField( bfs[closestBf] );
71d7c760 254
255 }
256 }
257
258
259
260int AliHLTTPCSliceTrackerComponent::DoInit( int argc, const char** argv )
261 {
a6c02c85 262 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
263 fprintf( stderr, "sizeof(AliHLTTPCTrackSegmentData): %d\n", sizeof(AliHLTTPCTrackSegmentData) );
264
71d7c760 265 if ( fTracker || fVertex )
266 return EINPROGRESS;
a6c02c85 267 fTracker = new AliHLTTPCConfMapper();
268 fVertex = new AliHLTTPCVertex();
71d7c760 269 fEta[0] = 0.;
270 fEta[1] = 1.1;
271 fDoNonVertex = false;
a6c02c85 272 fMultiplicity = 4000;
273 fBField = 0.4;
274 fDoPP = false;
71d7c760 275
276 int i = 0;
277 char* cpErr;
278 while ( i < argc )
279 {
a6c02c85 280 if ( !strcmp( argv[i], "pp-run" ) )
71d7c760 281 {
282 fDoPP = true;
283 i++;
284 continue;
285 }
a6c02c85 286 if ( !strcmp( argv[i], "multiplicity" ) )
71d7c760 287 {
288 if ( argc <= i+1 )
289 {
290 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Missing event multiplicity specifier." );
291 return ENOTSUP;
292 }
293 fMultiplicity = strtoul( argv[i+1], &cpErr, 0 );
294 if ( *cpErr )
295 {
296 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert event multiplicity specifier '%s'.", argv[i+1] );
297 return EINVAL;
298 }
299 i += 2;
300 continue;
301 }
a6c02c85 302 if ( !strcmp( argv[i], "bfield" ) )
71d7c760 303 {
304 if ( argc <= i+1 )
305 {
306 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing B-field", "Missing B-field specifier." );
307 return ENOTSUP;
308 }
309 fBField = strtod( argv[i+1], &cpErr );
310 if ( *cpErr )
311 {
312 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
313 return EINVAL;
314 }
315 i += 2;
316 continue;
317 }
318 Logging(kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
319 return EINVAL;
320 }
321 SetTrackerParam( fDoPP, fMultiplicity, fBField );
322 return 0;
323 }
324
325int AliHLTTPCSliceTrackerComponent::DoDeinit()
326 {
327 if ( fTracker )
328 delete fTracker;
329 fTracker = NULL;
330 if ( fVertex )
331 delete fVertex;
332 fVertex = NULL;
333 return 0;
334 }
335
336int AliHLTTPCSliceTrackerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
337 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
338 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
339 {
a6c02c85 340 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "DoEvent", "DoEvent()" );
71d7c760 341 const AliHLTComponent_BlockData* iter = NULL;
342 unsigned long ndx;
343 AliHLTTPCClusterData* inPtrSP;
a6c02c85 344 AliHLTTPCVertexData* inPtrV = NULL;
71d7c760 345 const AliHLTComponent_BlockData* vertexIter=NULL;
346 AliHLTTPCTrackletData* outPtr;
347 AliHLTUInt8_t* outBPtr;
348 AliHLTUInt32_t vSize = 0;
349 UInt_t offset=0, mysize, tSize = 0;
350 outBPtr = outputPtr;
351 Int_t slice, patch, row[2];
352 Int_t minPatch=INT_MAX, maxPatch = 0;
353 offset = 0;
354 std::vector<Int_t> slices;
355 std::vector<Int_t>::iterator slIter, slEnd;
356 std::vector<unsigned> sliceCnts;
357 std::vector<unsigned>::iterator slCntIter;
358 Int_t vertexSlice=0;
359
360 // Find min/max rows used in total and find and read out vertex if it is present
361 // also determine correct slice number, if multiple slice numbers are present in event
362 // (which should not happen in the first place) we use the one that occurs the most times
363 row[0] = 0;
364 row[1] = 0;
365 bool found;
366 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
367 {
368 iter = blocks+ndx;
369
370 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
371 found = false;
372 slIter = slices.begin();
373 slEnd = slices.end();
374 slCntIter = sliceCnts.begin();
375 while ( slIter != slEnd )
376 {
377 if ( *slIter == slice )
378 {
379 found = true;
380 break;
381 }
382 slIter++;
383 slCntIter++;
384 }
385 if ( !found )
386 {
387 slices.insert( slices.end(), slice );
388 sliceCnts.insert( sliceCnts.end(), 1 );
389 }
390 else
391 *slCntIter++;
392
393 if ( iter->fDataType == AliHLTTPCDefinitions::gkVertexDataType )
394 {
a6c02c85 395 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
71d7c760 396 vertexIter = iter;
397 vSize = iter->fSize;
398 fVertex->Read( inPtrV );
399 vertexSlice = slice;
400 }
401 if ( iter->fDataType == AliHLTTPCDefinitions::gkClustersDataType )
402 {
403 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
404 if ( minPatch>patch )
405 {
406 minPatch = patch;
a6c02c85 407 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
71d7c760 408 }
409 if ( maxPatch<patch )
410 {
411 maxPatch = patch;
a6c02c85 412 row[1] = AliHLTTPCTransform::GetLastRow( patch );
71d7c760 413 }
414 }
415 }
416
417 // Determine slice number to really use.
418 if ( slices.size()>1 )
419 {
420 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
421 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
422 evtData.fEventID, evtData.fEventID );
423 unsigned maxCntSlice=0;
424 slIter = slices.begin();
425 slEnd = slices.end();
426 slCntIter = sliceCnts.begin();
427 while ( slIter != slEnd )
428 {
429 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
430 "Slice %lu found %lu times.", *slIter, *slCntIter );
431 if ( maxCntSlice<*slCntIter )
432 {
433 maxCntSlice = *slCntIter;
434 slice = *slIter;
435 }
436 slIter++;
437 slCntIter++;
438 }
439 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
440 "Using slice %lu.", slice );
441 }
442 else
443 slice = *(slices.begin());
444
445 if ( vertexSlice != slice )
446 {
447 // multiple vertex blocks in event and we used the wrong one...
448 found = false;
449 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
450 {
451 iter = blocks+ndx;
452 if ( iter->fDataType == AliHLTTPCDefinitions::gkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
453 {
a6c02c85 454 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
71d7c760 455 vertexIter = iter;
456 vSize = iter->fSize;
457 fVertex->Read( inPtrV );
458 break;
459 }
460 }
461 }
462
463 fTracker->InitSector( slice, row, fEta );
464 fTracker->SetVertex(fVertex);
465 mysize = 0;
466 // read in all hits
a6c02c85 467 std::vector<unsigned long> patchIndices;
468 std::vector<unsigned long>::iterator pIter, pEnd;
71d7c760 469 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
470 {
471 iter = blocks+ndx;
472
473 if ( iter->fDataType == AliHLTTPCDefinitions::gkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
474 {
475 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
a6c02c85 476 pIter = patchIndices.begin();
477 pEnd = patchIndices.end();
478 while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
479 pIter++;
480 patchIndices.insert( pIter, ndx );
71d7c760 481 }
482 }
a6c02c85 483 pIter = patchIndices.begin();
484 pEnd = patchIndices.end();
485 while ( pIter!=pEnd )
486 {
487 ndx = *pIter;
488 iter = blocks+ndx;
489
490 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
491 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
492
493 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
494 "Reading hits for slice %d - patch %d", slice, patch );
495 fTracker->ReadHits( inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
496 pIter++;
497 }
71d7c760 498
499 outPtr = (AliHLTTPCTrackletData*)(outBPtr);
500 fTracker->MainVertexTracking_a();
501 fTracker->MainVertexTracking_b();
502 fTracker->FillTracks();
503
504 if ( fDoNonVertex )
505 fTracker->NonVertexTracking();//Do a second pass for nonvertex tracks
506
507 // XXX Do track merging??
508
509 UInt_t ntracks0=0;
510 mysize = fTracker->GetTracks()->WriteTracks( ntracks0, outPtr->fTracklets );
511 outPtr->fTrackletCnt = ntracks0;
512
513 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
514 "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.",
515 ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
516
517 tSize += mysize+sizeof(AliHLTTPCTrackletData);
518 outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
519
520 AliHLTComponent_BlockData bd;
521 FillBlockData( bd );
522 bd.fOffset = offset;
523 bd.fSize = tSize;
524 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
525 outputBlocks.push_back( bd );
526
527#ifdef FORWARD_VERTEX_BLOCK
528 if ( vertexIter )
529 {
530 // Copy the descriptor block for the vertex information.
531 bd = *vertexIter;
532 outputBlocks.push_back( bd );
533 }
534#endif // FORWARD_VERTEX_BLOCK
535
536 size = tSize;
537 return 0;
538 }
539
540