3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
8 * Ivan Kisel <kisel@kip.uni-heidelberg.de> *
9 * for The ALICE HLT Project. *
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 **************************************************************************/
20 ///////////////////////////////////////////////////////////////////////////////
22 // a TPC tracker processing component for the HLT based on CA by Ivan Kisel //
24 ///////////////////////////////////////////////////////////////////////////////
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"
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 // 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&)
74 // see header file for class documentation
75 HLTFatal("copy constructor untested");
78 AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=(const AliHLTTPCCATrackerComponent&)
80 // see header file for class documentation
81 HLTFatal("assignment operator untested");
85 AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
87 // see header file for class documentation
90 // Public functions to implement AliHLTComponent's interface.
91 // These functions are required for the registration process
93 const char* AliHLTTPCCATrackerComponent::GetComponentID()
95 // see header file for class documentation
96 return "TPCCATracker";
99 void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
101 // see header file for class documentation
103 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
104 list.push_back( AliHLTTPCDefinitions::fgkVertexDataType );
107 AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
109 // see header file for class documentation
110 return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
113 void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
115 // see header file for class documentation
116 // XXX TODO: Find more realistic values.
118 inputMultiplier = 0.2;
121 AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
123 // see header file for class documentation
124 return new AliHLTTPCCATrackerComponent;
127 int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
129 // see header file for class documentation
130 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
132 if ( fTracker || fVertex )
135 fTracker = new AliHLTTPCCATracker();
136 fTracker->CACreateHistos();
138 fVertex = new AliHLTTPCVertex();
141 /* ---------------------------------------------------------------------------------
142 * cmdline arguments not needed so far
149 if ( !strcmp( argv[i], "bfield" ) )
153 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing B-field", "Missing B-field specifier." );
156 fBField = strtod( argv[i+1], &cpErr );
159 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
166 Logging(kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
169 --------------------------------------------------------------------------------- */
174 int AliHLTTPCCATrackerComponent::DoDeinit()
176 // see header file for class documentation
186 int AliHLTTPCCATrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
187 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
188 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
190 // see header file for class documentation
191 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "DoEvent", "DoEvent()" );
192 if ( evtData.fBlockCnt<=0 )
194 Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "no blocks in event" );
198 const AliHLTComponentBlockData* iter = NULL;
200 AliHLTTPCClusterData* inPtrSP;
201 AliHLTTPCVertexData* inPtrV = NULL;
202 const AliHLTComponentBlockData* vertexIter=NULL;
203 AliHLTTPCTrackletData* outPtr;
204 AliHLTUInt8_t* outBPtr;
206 AliHLTUInt32_t vSize = 0;
207 UInt_t offset=0, mysize, tSize = 0;
210 outPtr = (AliHLTTPCTrackletData*)(outBPtr);
211 fTracker->SetOutPtr( outPtr->fTracklets );
213 // ------------------------------------------
215 Int_t slice=-1, patch=-1, row[2];
216 Int_t minPatch=INT_MAX, maxPatch = 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;
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
231 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
236 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
238 slIter = slices.begin();
239 slEnd = slices.end();
240 slCntIter = sliceCnts.begin();
241 while ( slIter != slEnd )
243 if ( *slIter == slice )
253 slices.insert( slices.end(), slice );
254 sliceCnts.insert( sliceCnts.end(), 1 );
259 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType )
261 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
264 fVertex->Read( inPtrV );
267 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
269 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
270 if ( minPatch>patch )
273 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
275 if ( maxPatch<patch )
278 row[1] = AliHLTTPCTransform::GetLastRow( patch );
283 // Determine slice number to really use.
284 if ( slices.size()>1 )
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 )
295 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
296 "Slice %lu found %lu times.", *slIter, *slCntIter );
297 if ( maxCntSlice<*slCntIter )
299 maxCntSlice = *slCntIter;
305 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
306 "Using slice %lu.", slice );
308 else if ( slices.size()>0 )
310 slice = *(slices.begin());
317 if ( vertexSlice != slice )
319 // multiple vertex blocks in event and we used the wrong one...
321 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
324 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
326 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
329 fVertex->Read( inPtrV );
335 // fTracker->InitSector( slice, row, fEta );
336 // fTracker->SetVertex(fVertex);
340 std::vector<unsigned long> patchIndices;
341 std::vector<unsigned long>::iterator pIter, pEnd;
342 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
346 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
348 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
349 pIter = patchIndices.begin();
350 pEnd = patchIndices.end();
351 while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
353 patchIndices.insert( pIter, ndx );
357 fTracker->CAInitialize();
359 pIter = patchIndices.begin();
360 pEnd = patchIndices.end();
361 while ( pIter!=pEnd )
366 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
367 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
369 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
370 "Reading hits for slice %d - patch %d", slice, patch );
372 fTracker->CAReadPatchHits( patch, inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
373 fTracker->CAFindPatchTracks( patch );
378 fTracker->CAFindSliceTracks();
384 std::cin.get(symbol);
387 } while (symbol != '\n');
394 mysize = fTracker->GetOutputSize();
395 ntracks0 = fTracker->GetOutputNTracks();
396 outPtr->fTrackletCnt = fTracker->GetOutputNTracks();
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] );
402 tSize += mysize+sizeof(AliHLTTPCTrackletData);
403 outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
405 AliHLTComponentBlockData bd;
409 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
410 outputBlocks.push_back( bd );
412 #ifdef FORWARD_VERTEX_BLOCK
415 // Copy the descriptor block for the vertex information.
417 outputBlocks.push_back( bd );
419 #endif // FORWARD_VERTEX_BLOCK
423 fTracker->CAWriteHistos();