3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Ivan Kisel <kisel@kip.uni-heidelberg.de> *
7 * Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 * Matthias Richter <Matthias.Richter@ift.uib.no> *
9 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
10 * for The ALICE Off-line Project. *
12 * Permission to use, copy, modify and distribute this software and its *
13 * documentation strictly for non-commercial purposes is hereby granted *
14 * without fee, provided that the above copyright notice appears in all *
15 * copies and that both the copyright notice and this permission notice *
16 * appear in the supporting documentation. The authors make no claims *
17 * about the suitability of this software for any purpose. It is *
18 * provided "as is" without express or implied warranty. *
19 **************************************************************************/
21 ///////////////////////////////////////////////////////////////////////////////
23 // a TPC tracker processing component for the HLT based on CA by Ivan Kisel //
25 ///////////////////////////////////////////////////////////////////////////////
31 #include "AliHLTTPCCATrackerComponent.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCCATracker.h"
34 #include "AliHLTTPCVertex.h"
35 #include "AliHLTTPCSpacePointData.h"
36 #include "AliHLTTPCVertexData.h"
37 #include "AliHLTTPCClusterDataFormat.h"
38 #include "AliHLTTPCTransform.h"
39 #include "AliHLTTPCTrackSegmentData.h"
40 #include "AliHLTTPCTrackArray.h"
41 #include "AliHLTTPCTrackletDataFormat.h"
42 #include "AliHLTTPCDefinitions.h"
43 //#include "AliHLTTPC.h"
48 //static bool ask = true;
49 static bool ask = false;
51 // this is a global object used for automatic component registration, do not use this
52 AliHLTTPCCATrackerComponent gAliHLTTPCCATrackerComponent;
54 ClassImp(AliHLTTPCCATrackerComponent)
56 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
61 // see header file for class documentation
63 // refer to README to build package
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent(const AliHLTTPCCATrackerComponent&)
73 // see header file for class documentation
74 HLTFatal("copy constructor untested");
77 AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=(const AliHLTTPCCATrackerComponent&)
79 // see header file for class documentation
80 HLTFatal("assignment operator untested");
84 AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
86 // see header file for class documentation
89 // Public functions to implement AliHLTComponent's interface.
90 // These functions are required for the registration process
92 const char* AliHLTTPCCATrackerComponent::GetComponentID()
94 // see header file for class documentation
95 return "TPCCATracker";
98 void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
100 // see header file for class documentation
102 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
103 list.push_back( AliHLTTPCDefinitions::fgkVertexDataType );
106 AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
108 // see header file for class documentation
109 return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
112 void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
114 // see header file for class documentation
115 // XXX TODO: Find more realistic values.
117 inputMultiplier = 0.2;
120 AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
122 // see header file for class documentation
123 return new AliHLTTPCCATrackerComponent;
126 int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
128 // see header file for class documentation
129 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
131 if ( fTracker || fVertex )
134 fTracker = new AliHLTTPCCATracker();
135 fTracker->CACreateHistos();
137 fVertex = new AliHLTTPCVertex();
140 /* ---------------------------------------------------------------------------------
141 * cmdline arguments not needed so far
148 if ( !strcmp( argv[i], "bfield" ) )
152 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing B-field", "Missing B-field specifier." );
155 fBField = strtod( argv[i+1], &cpErr );
158 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
165 Logging(kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
168 --------------------------------------------------------------------------------- */
173 int AliHLTTPCCATrackerComponent::DoDeinit()
175 // see header file for class documentation
185 int AliHLTTPCCATrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
186 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
187 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
189 // see header file for class documentation
190 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "DoEvent", "DoEvent()" );
191 if ( evtData.fBlockCnt<=0 )
193 Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "no blocks in event" );
197 const AliHLTComponentBlockData* iter = NULL;
199 AliHLTTPCClusterData* inPtrSP;
200 AliHLTTPCVertexData* inPtrV = NULL;
201 const AliHLTComponentBlockData* vertexIter=NULL;
202 AliHLTTPCTrackletData* outPtr;
203 AliHLTUInt8_t* outBPtr;
205 AliHLTUInt32_t vSize = 0;
206 UInt_t offset=0, mysize, tSize = 0;
209 outPtr = (AliHLTTPCTrackletData*)(outBPtr);
210 fTracker->SetOutPtr( outPtr->fTracklets );
212 // ------------------------------------------
214 Int_t slice=-1, patch=-1, row[2];
215 Int_t minPatch=INT_MAX, maxPatch = 0;
217 std::vector<Int_t> slices;
218 std::vector<Int_t>::iterator slIter, slEnd;
219 std::vector<unsigned> sliceCnts;
220 std::vector<unsigned>::iterator slCntIter;
221 Int_t vertexSlice=-1;
223 // Find min/max rows used in total and find and read out vertex if it is present
224 // also determine correct slice number, if multiple slice numbers are present in event
225 // (which should not happen in the first place) we use the one that occurs the most times
230 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
235 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
237 slIter = slices.begin();
238 slEnd = slices.end();
239 slCntIter = sliceCnts.begin();
240 while ( slIter != slEnd )
242 if ( *slIter == slice )
252 slices.insert( slices.end(), slice );
253 sliceCnts.insert( sliceCnts.end(), 1 );
258 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType )
260 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
263 fVertex->Read( inPtrV );
266 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
268 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
269 if ( minPatch>patch )
272 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
274 if ( maxPatch<patch )
277 row[1] = AliHLTTPCTransform::GetLastRow( patch );
282 // Determine slice number to really use.
283 if ( slices.size()>1 )
285 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
286 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
287 evtData.fEventID, evtData.fEventID );
288 unsigned maxCntSlice=0;
289 slIter = slices.begin();
290 slEnd = slices.end();
291 slCntIter = sliceCnts.begin();
292 while ( slIter != slEnd )
294 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
295 "Slice %lu found %lu times.", *slIter, *slCntIter );
296 if ( maxCntSlice<*slCntIter )
298 maxCntSlice = *slCntIter;
304 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
305 "Using slice %lu.", slice );
307 else if ( slices.size()>0 )
309 slice = *(slices.begin());
316 if ( vertexSlice != slice )
318 // multiple vertex blocks in event and we used the wrong one...
320 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
323 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
325 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
328 fVertex->Read( inPtrV );
334 // fTracker->InitSector( slice, row, fEta );
335 // fTracker->SetVertex(fVertex);
339 std::vector<unsigned long> patchIndices;
340 std::vector<unsigned long>::iterator pIter, pEnd;
341 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
345 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
347 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
348 pIter = patchIndices.begin();
349 pEnd = patchIndices.end();
350 while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
352 patchIndices.insert( pIter, ndx );
356 fTracker->CAInitialize();
358 pIter = patchIndices.begin();
359 pEnd = patchIndices.end();
360 while ( pIter!=pEnd )
365 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
366 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
368 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
369 "Reading hits for slice %d - patch %d", slice, patch );
371 fTracker->CAReadPatchHits( patch, inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
372 fTracker->CAFindPatchTracks( patch );
377 fTracker->CAFindSliceTracks();
383 std::cin.get(symbol);
386 } while (symbol != '\n');
393 mysize = fTracker->GetOutputSize();
394 ntracks0 = fTracker->GetOutputNTracks();
395 outPtr->fTrackletCnt = fTracker->GetOutputNTracks();
397 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
398 "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.",
399 ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
401 tSize += mysize+sizeof(AliHLTTPCTrackletData);
402 outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
404 AliHLTComponentBlockData bd;
408 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
409 outputBlocks.push_back( bd );
411 #ifdef FORWARD_VERTEX_BLOCK
414 // Copy the descriptor block for the vertex information.
416 outputBlocks.push_back( bd );
418 #endif // FORWARD_VERTEX_BLOCK
422 fTracker->CAWriteHistos();