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 "AliHLTTPC.h"
47 //static bool ask = true;
48 static bool ask = false;
50 // this is a global object used for automatic component registration, do not use this
51 AliHLTTPCCATrackerComponent gAliHLTTPCCATrackerComponent;
53 ClassImp(AliHLTTPCCATrackerComponent)
55 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent()
61 AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
65 // Public functions to implement AliHLTComponent's interface.
66 // These functions are required for the registration process
68 const char* AliHLTTPCCATrackerComponent::GetComponentID()
70 return "TPCCATracker";
73 void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
76 list.push_back( AliHLTTPCDefinitions::gkClustersDataType );
77 list.push_back( AliHLTTPCDefinitions::gkVertexDataType );
80 AliHLTComponent_DataType AliHLTTPCCATrackerComponent::GetOutputDataType()
82 return AliHLTTPCDefinitions::gkTrackSegmentsDataType;
85 void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
87 // XXX TODO: Find more realistic values.
89 inputMultiplier = 0.2;
92 AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
94 return new AliHLTTPCCATrackerComponent;
97 int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
99 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
101 if ( fTracker || fVertex )
104 fTracker = new AliHLTTPCCATracker();
105 fTracker->CACreateHistos();
107 fVertex = new AliHLTTPCVertex();
110 /* ---------------------------------------------------------------------------------
111 * cmdline arguments not needed so far
118 if ( !strcmp( argv[i], "bfield" ) )
122 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing B-field", "Missing B-field specifier." );
125 fBField = strtod( argv[i+1], &cpErr );
128 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
135 Logging(kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
138 --------------------------------------------------------------------------------- */
143 int AliHLTTPCCATrackerComponent::DoDeinit()
154 int AliHLTTPCCATrackerComponent::DoEvent( const AliHLTComponent_EventData& evtData, const AliHLTComponent_BlockData* blocks,
155 AliHLTComponent_TriggerData& trigData, AliHLTUInt8_t* outputPtr,
156 AliHLTUInt32_t& size, vector<AliHLTComponent_BlockData>& outputBlocks )
158 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "DoEvent", "DoEvent()" );
159 if ( evtData.fBlockCnt<=0 )
161 Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "no blocks in event" );
165 const AliHLTComponent_BlockData* iter = NULL;
167 AliHLTTPCClusterData* inPtrSP;
168 AliHLTTPCVertexData* inPtrV = NULL;
169 const AliHLTComponent_BlockData* vertexIter=NULL;
170 AliHLTTPCTrackletData* outPtr;
171 AliHLTUInt8_t* outBPtr;
173 AliHLTUInt32_t vSize = 0;
174 UInt_t offset=0, mysize, tSize = 0;
177 outPtr = (AliHLTTPCTrackletData*)(outBPtr);
178 fTracker->SetOutPtr( outPtr->fTracklets );
180 // ------------------------------------------
182 Int_t slice=-1, patch=-1, row[2];
183 Int_t minPatch=INT_MAX, maxPatch = 0;
185 std::vector<Int_t> slices;
186 std::vector<Int_t>::iterator slIter, slEnd;
187 std::vector<unsigned> sliceCnts;
188 std::vector<unsigned>::iterator slCntIter;
189 Int_t vertexSlice=-1;
191 // Find min/max rows used in total and find and read out vertex if it is present
192 // also determine correct slice number, if multiple slice numbers are present in event
193 // (which should not happen in the first place) we use the one that occurs the most times
198 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
203 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
205 slIter = slices.begin();
206 slEnd = slices.end();
207 slCntIter = sliceCnts.begin();
208 while ( slIter != slEnd )
210 if ( *slIter == slice )
220 slices.insert( slices.end(), slice );
221 sliceCnts.insert( sliceCnts.end(), 1 );
226 if ( iter->fDataType == AliHLTTPCDefinitions::gkVertexDataType )
228 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
231 fVertex->Read( inPtrV );
234 if ( iter->fDataType == AliHLTTPCDefinitions::gkClustersDataType )
236 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
237 if ( minPatch>patch )
240 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
242 if ( maxPatch<patch )
245 row[1] = AliHLTTPCTransform::GetLastRow( patch );
250 // Determine slice number to really use.
251 if ( slices.size()>1 )
253 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
254 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
255 evtData.fEventID, evtData.fEventID );
256 unsigned maxCntSlice=0;
257 slIter = slices.begin();
258 slEnd = slices.end();
259 slCntIter = sliceCnts.begin();
260 while ( slIter != slEnd )
262 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
263 "Slice %lu found %lu times.", *slIter, *slCntIter );
264 if ( maxCntSlice<*slCntIter )
266 maxCntSlice = *slCntIter;
272 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
273 "Using slice %lu.", slice );
275 else if ( slices.size()>0 )
277 slice = *(slices.begin());
284 if ( vertexSlice != slice )
286 // multiple vertex blocks in event and we used the wrong one...
288 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
291 if ( iter->fDataType == AliHLTTPCDefinitions::gkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
293 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
296 fVertex->Read( inPtrV );
302 // fTracker->InitSector( slice, row, fEta );
303 // fTracker->SetVertex(fVertex);
307 std::vector<unsigned long> patchIndices;
308 std::vector<unsigned long>::iterator pIter, pEnd;
309 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
313 if ( iter->fDataType == AliHLTTPCDefinitions::gkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
315 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
316 pIter = patchIndices.begin();
317 pEnd = patchIndices.end();
318 while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
320 patchIndices.insert( pIter, ndx );
324 fTracker->CAInitialize();
326 pIter = patchIndices.begin();
327 pEnd = patchIndices.end();
328 while ( pIter!=pEnd )
333 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
334 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
336 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
337 "Reading hits for slice %d - patch %d", slice, patch );
339 fTracker->CAReadPatchHits( patch, inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
340 fTracker->CAFindPatchTracks( patch );
345 fTracker->CAFindSliceTracks();
351 std::cin.get(symbol);
354 } while (symbol != '\n');
361 mysize = fTracker->GetOutputSize();
362 ntracks0 = fTracker->GetOutputNTracks();
363 outPtr->fTrackletCnt = fTracker->GetOutputNTracks();
365 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
366 "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.",
367 ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
369 tSize += mysize+sizeof(AliHLTTPCTrackletData);
370 outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
372 AliHLTComponent_BlockData bd;
376 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
377 outputBlocks.push_back( bd );
379 #ifdef FORWARD_VERTEX_BLOCK
382 // Copy the descriptor block for the vertex information.
384 outputBlocks.push_back( bd );
386 #endif // FORWARD_VERTEX_BLOCK
390 fTracker->CAWriteHistos();