StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AliHLTTPCCATracker.cxx
1 // @(#) $Id: AliHLTTPCCATracker.cxx,v 1.3 2016/07/15 14:43:33 fisyak Exp $
2 // **************************************************************************
3 // This file is property of and copyright by the ALICE HLT Project *
4 // ALICE Experiment at CERN, All rights reserved. *
5 // *
6 // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
7 // Ivan Kisel <kisel@kip.uni-heidelberg.de> *
8 // for The ALICE HLT Project. *
9 // *
10 // Developed by: Igor Kulakov <I.Kulakov@gsi.de> *
11 // Maksym Zyzak <M.Zyzak@gsi.de> *
12 // *
13 // Permission to use, copy, modify and distribute this software and its *
14 // documentation strictly for non-commercial purposes is hereby granted *
15 // without fee, provided that the above copyright notice appears in all *
16 // copies and that both the copyright notice and this permission notice *
17 // appear in the supporting documentation. The authors make no claims *
18 // about the suitability of this software for any purpose. It is *
19 // provided "as is" without express or implied warranty. *
20 // *
21 //***************************************************************************
22 
23 #include "AliHLTTPCCATracker.h"
24 #include "AliHLTTPCCAOutTrack.h"
25 #include "AliHLTTPCCAGrid.h"
26 #include "AliHLTTPCCARow.h"
27 #include "AliHLTTPCCATrack.h"
28 #include "AliHLTTPCCATrackletVector.h"
29 #include "AliHLTTPCCAMath.h"
30 #include "AliHLTTPCCAHit.h"
31 #include "Reconstructor.h"
32 #include "MemoryAssignmentHelpers.h"
33 
34 #include "Stopwatch.h"
35 #include "AliHLTTPCCASliceOutput.h"
36 #include "AliHLTTPCCADataCompressor.h"
37 #include "AliHLTTPCCAClusterData.h"
38 
39 #include "AliHLTTPCCATrackParam.h"
40 
41 #include <iostream>
42 
43 #ifdef HLTCA_INTERNAL_PERFORMANCE
44 #include "AliHLTTPCCAPerformance.h"
45 #endif
46 
47 using std::endl;
48 
49 AliHLTTPCCATracker::AliHLTTPCCATracker()
50  :
51 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
52  fNOutTracks1( 0 ),
53  fOutTracks1( 0 ),
54 #endif //DO_TPCCATRACKER_EFF_PERFORMANCE
55  fParam(),
56  fClusterData( 0 ),
57  fData(),
58  fHitMemory( 0 ),
59  fHitMemorySize( 0 ),
60  fTrackMemory( 0 ),
61  fTrackMemorySize( 0 ),
62  fTrackletStartHits( 0 ),
63  fNTracklets( 0 ),
64  fTrackletVectors(),
65  fNumberOfTracks(0),
66  fTracks(0),
67  fNTrackHits( 0 ),
68  fOutput( 0 )
69 {
70  // constructor
71 }
72 
73 AliHLTTPCCATracker::~AliHLTTPCCATracker()
74 {
75  // destructor
76 #ifdef DO_TPCCATRACKER_EFF_PERFORMANCE
77  if (fOutTracks1) delete[] fOutTracks1;
78 #endif
79  if (fHitMemory) delete[] fHitMemory;
80  if (fTrackMemory) delete[] fTrackMemory;
81 }
82 
83 
84 
85 // ----------------------------------------------------------------------------------
86 void AliHLTTPCCATracker::Initialize( const AliHLTTPCCAParam &param )
87 {
88  // initialisation
89  fParam = param;
90  fParam.Update();
91  fData.InitializeRows( fParam );
92 
93  StartEvent();
94 }
95 
96 void AliHLTTPCCATracker::StartEvent()
97 {
98  // start new event and fresh the memory
99 
100  SetupCommonMemory();
101  fNTrackHits = 0;
102 }
103 
104 void AliHLTTPCCATracker::SetupCommonMemory()
105 {
106 // std::cout << " SetupCommonMemory0 " << std::endl; //iklm debug
107  if (fHitMemory) delete[] fHitMemory;
108 // std::cout << " SetupCommonMemory1 " << std::endl; //iklm debug
109  fHitMemory = 0;
110  if (fTrackMemory) delete[] fTrackMemory;
111 // std::cout << " SetupCommonMemory2 " << std::endl; //iklm debug
112  fTrackMemory = 0;
113 
114  fData.Clear();
115  fNTracklets = 0;
116 }
117 
118 void AliHLTTPCCATracker::RecalculateHitsSize( int MaxNHits )
119 {
120  fHitMemorySize = 0;
121  fHitMemorySize += RequiredMemory( fTrackletStartHits, MaxNHits );
122 }
123 
124 void AliHLTTPCCATracker::SetPointersHits( int MaxNHits )
125 {
126  assert( fHitMemory );
127  assert( fHitMemorySize > 0 );
128 
129  // set all pointers to the event memory
130 
131  char *mem = fHitMemory;
132 
133  // extra arrays for tpc clusters
134 
135  AssignMemory( fTrackletStartHits, mem, MaxNHits );
136 
137  // arrays for track hits
138  assert( fHitMemorySize >= mem - fHitMemory );
139 }
140 
141 void AliHLTTPCCATracker::RecalculateTrackMemorySize( int MaxNTracks, int MaxNHits )
142 {
143  debugWO() << "RecalculateTrackMemorySize( " << MaxNTracks << ", " << MaxNHits << ")" << endl;
144  fTrackMemorySize = 0;
145  fTrackMemorySize += sizeof( void * ); // alignment
146  fTrackMemorySize += sizeof(AliHLTTPCCASliceOutput);
147  fTrackMemorySize += AliHLTTPCCASliceOutput::EstimateSize( MaxNTracks, MaxNHits );
148 }
149 
150 void AliHLTTPCCATracker::SetPointersTracks( int MaxNTracks, int MaxNHits )
151 {
152  debugWO() << "SetPointersTracks( " << MaxNTracks << ", " << MaxNHits << ")" << endl;
153  assert( fTrackMemory );
154  assert( fTrackMemorySize > 0 );
155 
156  // set all pointers to the tracks memory
157 
158  char *mem = fTrackMemory;
159 
160  // memory for output
161 
162  AlignTo<sizeof( void * )>( mem );
163  fOutput = new( mem ) AliHLTTPCCASliceOutput;
164  mem += sizeof(AliHLTTPCCASliceOutput);
165  mem += AliHLTTPCCASliceOutput::EstimateSize( MaxNTracks, MaxNHits );
166 
167  // memory for output tracks
168  assert( fTrackMemorySize >= mem - fTrackMemory );
169 }
170 
171 
172 void AliHLTTPCCATracker::ReadEvent( AliHLTTPCCAClusterData *clusterData )
173 {
174  fClusterData = clusterData;
175 // std::cout << " cat0 " << std::endl; //iklm debug
176  StartEvent();
177 // std::cout << " cat1 " << std::endl; //iklm debug
178  //* Convert input hits, create grids, etc.
179  fData.InitFromClusterData( *clusterData );
180 // std::cout << " cat2 " << std::endl; //iklm debug
181  {
182  RecalculateHitsSize( fData.NumberOfHits() ); // to calculate the size
183  fHitMemory = new char[fHitMemorySize + 1600];
184  SetPointersHits( fData.NumberOfHits() ); // set pointers for hits
185  fNTracklets = 0;
186  }
187 }
188 
189 void AliHLTTPCCATracker::Reconstruct()
190 {
191 #ifdef USE_TBB
192  tbb::task::spawn_root_and_wait( *new( tbb::task::allocate_root() ) Reconstructor( this ) );
193 #else //USE_TBB
194  Reconstructor R(this);
195  R.execute();
196 #endif //USE_TBB
197 }
198 
199 void AliHLTTPCCATracker::WriteOutput()
200 {
201  // write output
202 #ifdef USE_TIMERS
203  Stopwatch timer;
204  timer.Start();
205 #endif // USE_TIMERS
206 
207  //cout<<"output: nTracks = "<< fTracks.size() <<", nHitsTotal="<<fData.NumberOfHits()<<std::endl;
208 
209  debugWO() << "numberOfTracks = " << fNumberOfTracks << std::endl;
210  fOutput->SetNTracks( fNumberOfTracks );
211  fOutput->SetNTrackClusters( fNTrackHits );
212  fOutput->SetPointers();
213 
214  debugWO() << "WriteOutput| "
215  << fNumberOfTracks << " tracks found, "
216  << fTrackletVectors.Size() << " TrackletVectors, "
217  << fNTrackHits << " track hits "
218  << std::endl;
219 
220  int hitStoreIndex = 0;
221  int nStoredHits = 0;
222  int iTr = 0;
223  const int tracksSize = fTracks.size();
224  for ( int trackIndex = 0; trackIndex < tracksSize; ++trackIndex ) {
225  // if (!fTracks[trackIndex]) continue;
226  const Track &track = *fTracks[trackIndex];
227  const short numberOfHits = track.NumberOfHits();
228  if ( numberOfHits <= 0 ) {
229  // might happen. See TrackletSelector.
230  if (fTracks[trackIndex]) delete fTracks[trackIndex];
231  continue;
232  }
233 
234  {
236  hitStoreIndex = nStoredHits;
237  out.SetFirstClusterRef( nStoredHits );
238  nStoredHits += numberOfHits;
239  out.SetNClusters( numberOfHits );
240  out.SetParam( track.Param() );
241  fOutput->SetTrack( iTr, out );
242  }
243  ++iTr;
244 
245  for ( int hitIdIndex = 0; hitIdIndex < numberOfHits; ++hitIdIndex ) {
246  const HitId &hitId = track.HitId( hitIdIndex );
247  const short rowIndex = hitId.RowIndex();
248  const unsigned short hitIndex = hitId.HitIndex();
249  const AliHLTTPCCARow &row = fData.Row( rowIndex );
250 
251  const int inpIdOffset = fClusterData->RowOffset( rowIndex );
252  const int inpIdtot = fData.ClusterDataIndex( row, hitIndex );
253  const int inpId = inpIdtot - inpIdOffset;
254 
255  const float origX = fClusterData->X( inpIdtot );
256  const float origY = fClusterData->Y( inpIdtot );
257  const float origZ = fClusterData->Z( inpIdtot );
258 
259  const DataCompressor::RowCluster rc( rowIndex, inpId );
260  unsigned short hPackedYZ = 0;
261  UChar_t hPackedAmp = 0;
262  float2 hUnpackedYZ;
263  hUnpackedYZ.x = origY;
264  hUnpackedYZ.y = origZ;
265  float hUnpackedX = origX;
266 
267  fOutput->SetClusterIDrc( hitStoreIndex, rc );
268  fOutput->SetClusterPackedYZ( hitStoreIndex, hPackedYZ );
269  fOutput->SetClusterPackedAmp( hitStoreIndex, hPackedAmp );
270  fOutput->SetClusterUnpackedYZ( hitStoreIndex, hUnpackedYZ );
271  fOutput->SetClusterUnpackedX( hitStoreIndex, hUnpackedX );
272  ++hitStoreIndex;
273  }
274  if (fTracks[trackIndex]) delete fTracks[trackIndex];
275  }
276 
277  fOutput->SortTracks();
278 #ifdef USE_TIMERS
279  timer.Stop();
280  fTimers[5] += timer.RealTime();
281 #endif // USE_TIMERS
282 
283 }
284 
285 void AliHLTTPCCATracker::GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float *Err2Y, float *Err2Z ) const
286 {
287  //
288  // Use calibrated cluster error from OCDB
289  //
290 
291  fParam.GetClusterErrors2( iRow, t, *Err2Y, *Err2Z );
292 }
293 
294 void AliHLTTPCCATracker::WriteTracks( std::ostream &out )
295 {
296  //* Write tracks to file
297 
298  out << fTimers[0] << std::endl;
299 #if 0
300  out << fNOutTrackHits << std::endl;
301  for ( int hitIndex = 0; hitIndex < fNOutTrackHits; ++hitIndex ) {
302  out << fOutTrackHits[hitIndex] << " ";
303  }
304  out << std::endl;
305 
306  out << fNOutTracks << std::endl;
307 
308  for ( int itr = 0; itr < fNOutTracks; itr++ ) {
309  out << fOutTracks[itr];
310  }
311 #endif //DO_TPCCATRACKER_EFF_PERFORMANCE
312 }
313 
314 void AliHLTTPCCATracker::ReadTracks( std::istream &in )
315 {
316  //* Read tracks from file
317  in >> fTimers[0];
318 #if 0
319  in >> fNOutTrackHits;
320 
321  for ( int hitIndex = 0; hitIndex < fNOutTrackHits; ++hitIndex ) {
322  in >> fOutTrackHits[hitIndex];
323  }
324  in >> fNOutTracks;
325 
326  for ( int itr = 0; itr < fNOutTracks; itr++ ) {
327  in >> fOutTracks[itr];
328  }
329 #endif //DO_TPCCATRACKER_EFF_PERFORMANCE
330 }
331 
332 #include "BinaryStoreHelper.h"
333 
334 void AliHLTTPCCATracker::StoreToFile( FILE *f ) const
335 {
336  fParam.StoreToFile( f );
337  fData.StoreToFile( f );
338 
339  BinaryStoreWrite( fTimers, 10, f );
340 
341  //BinaryStoreWrite( fLinkUpData , startPointer, f );
342  //BinaryStoreWrite( fLinkDownData, startPointer, f );
343  //BinaryStoreWrite( fHitDataY , startPointer, f );
344  //BinaryStoreWrite( fHitDataZ , startPointer, f );
345 
346  //BinaryStoreWrite( fHitWeights, startPointer, f );
347 
348  BinaryStoreWrite( fNTracklets, f );
349  //BinaryStoreWrite( fTrackletStartHits, startPointer, f );
350  // TODO BinaryStoreWrite( fTracklets, startPointer, f );
351 
352  //BinaryStoreWrite( fTracks, startPointer, f );
353  //BinaryStoreWrite( fNTrackHits, startPointer, f );
354 #if 0
355  BinaryStoreWrite( fNOutTracks, f );
356  //BinaryStoreWrite( fOutTracks, startPointer, f );
357  BinaryStoreWrite( fNOutTrackHits, f );
358  //BinaryStoreWrite( fOutTrackHits, startPointer, f );
359 #endif //DO_TPCCATRACKER_EFF_PERFORMANCE
360 }
361 
362 void AliHLTTPCCATracker::RestoreFromFile( FILE *f )
363 {
364  fParam.RestoreFromFile( f );
365  fData.RestoreFromFile( f );
366 
367  BinaryStoreRead( fTimers, 10, f );
368 
369  Byte_t alignment;
370  BinaryStoreRead( alignment, f );
371 
372  //BinaryStoreRead( fLinkUpData , startPointer, f );
373  //BinaryStoreRead( fLinkDownData , startPointer, f );
374  //BinaryStoreRead( fHitDataY , startPointer, f );
375  //BinaryStoreRead( fHitDataZ , startPointer, f );
376 
377  //BinaryStoreRead( fHitWeights , startPointer, f );
378 
379  BinaryStoreRead( fNTracklets, f );
380  //BinaryStoreRead( fTrackletStartHits, startPointer, f );
381  // TODO BinaryStoreRead( fTracklets , startPointer, f );
382 
383  //BinaryStoreRead( fTracks , startPointer, f );
384  //BinaryStoreRead( fNTrackHits , startPointer, f );
385 #if 0
386  BinaryStoreRead( fNOutTracks , f );
387  //BinaryStoreRead( fOutTracks , startPointer, f );
388  BinaryStoreRead( fNOutTrackHits, f );
389  //BinaryStoreRead( fOutTrackHits , startPointer, f );
390 #endif //DO_TPCCATRACKER_EFF_PERFORMANCE
391 }
float Y(int index) const
int RowOffset(unsigned int rowIndex) const
float X(int index) const
void InitFromClusterData(const AliHLTTPCCAClusterData &data)
const AliHLTTPCCARow & Row(int rowIndex) const
float Z(int index) const
int ClusterDataIndex(const AliHLTTPCCARow &row, int hitIndex) const
void GetClusterErrors2(int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z) const
mvz start 20.01.2010
C++ STL includes.
Definition: AgUStep.h:47