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