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()
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
67 AliHLTTPCCATrackerComponent::AliHLTTPCCATrackerComponent(const AliHLTTPCCATrackerComponent&)
72 // see header file for class documentation
73 HLTFatal("copy constructor untested");
76 AliHLTTPCCATrackerComponent& AliHLTTPCCATrackerComponent::operator=(const AliHLTTPCCATrackerComponent&)
78 // see header file for class documentation
79 HLTFatal("assignment operator untested");
83 AliHLTTPCCATrackerComponent::~AliHLTTPCCATrackerComponent()
85 // see header file for class documentation
88 // Public functions to implement AliHLTComponent's interface.
89 // These functions are required for the registration process
91 const char* AliHLTTPCCATrackerComponent::GetComponentID()
93 // see header file for class documentation
94 return "TPCCATracker";
97 void AliHLTTPCCATrackerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
99 // see header file for class documentation
101 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
102 list.push_back( AliHLTTPCDefinitions::fgkVertexDataType );
105 AliHLTComponentDataType AliHLTTPCCATrackerComponent::GetOutputDataType()
107 // see header file for class documentation
108 return AliHLTTPCDefinitions::fgkTrackSegmentsDataType;
111 void AliHLTTPCCATrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
113 // see header file for class documentation
114 // XXX TODO: Find more realistic values.
116 inputMultiplier = 0.2;
119 AliHLTComponent* AliHLTTPCCATrackerComponent::Spawn()
121 // see header file for class documentation
122 return new AliHLTTPCCATrackerComponent;
125 int AliHLTTPCCATrackerComponent::DoInit( int argc, const char** argv )
127 // see header file for class documentation
128 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoInit", "DoInit", "DoInit()" );
130 if ( fTracker || fVertex )
133 fTracker = new AliHLTTPCCATracker();
134 fTracker->CACreateHistos();
136 fVertex = new AliHLTTPCVertex();
139 /* ---------------------------------------------------------------------------------
140 * cmdline arguments not needed so far
147 if ( !strcmp( argv[i], "bfield" ) )
151 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing B-field", "Missing B-field specifier." );
154 fBField = strtod( argv[i+1], &cpErr );
157 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Missing multiplicity", "Cannot convert B-field specifier '%s'.", argv[i+1] );
164 Logging(kHLTLogError, "HLT::TPCSliceTracker::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
167 --------------------------------------------------------------------------------- */
172 int AliHLTTPCCATrackerComponent::DoDeinit()
174 // see header file for class documentation
184 int AliHLTTPCCATrackerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
185 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr,
186 AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
188 // see header file for class documentation
189 Logging( kHLTLogDebug, "HLT::TPCCATracker::DoEvent", "DoEvent", "DoEvent()" );
190 if ( evtData.fBlockCnt<=0 )
192 Logging( kHLTLogWarning, "HLT::TPCCATracker::DoEvent", "DoEvent", "no blocks in event" );
196 const AliHLTComponentBlockData* iter = NULL;
198 AliHLTTPCClusterData* inPtrSP;
199 AliHLTTPCVertexData* inPtrV = NULL;
200 const AliHLTComponentBlockData* vertexIter=NULL;
201 AliHLTTPCTrackletData* outPtr;
202 AliHLTUInt8_t* outBPtr;
204 AliHLTUInt32_t vSize = 0;
205 UInt_t offset=0, mysize, tSize = 0;
208 outPtr = (AliHLTTPCTrackletData*)(outBPtr);
209 fTracker->SetOutPtr( outPtr->fTracklets );
211 // ------------------------------------------
213 Int_t slice=-1, patch=-1, row[2];
214 Int_t minPatch=INT_MAX, maxPatch = 0;
216 std::vector<Int_t> slices;
217 std::vector<Int_t>::iterator slIter, slEnd;
218 std::vector<unsigned> sliceCnts;
219 std::vector<unsigned>::iterator slCntIter;
220 Int_t vertexSlice=-1;
222 // Find min/max rows used in total and find and read out vertex if it is present
223 // also determine correct slice number, if multiple slice numbers are present in event
224 // (which should not happen in the first place) we use the one that occurs the most times
229 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
234 slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
236 slIter = slices.begin();
237 slEnd = slices.end();
238 slCntIter = sliceCnts.begin();
239 while ( slIter != slEnd )
241 if ( *slIter == slice )
251 slices.insert( slices.end(), slice );
252 sliceCnts.insert( sliceCnts.end(), 1 );
257 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType )
259 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
262 fVertex->Read( inPtrV );
265 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType )
267 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
268 if ( minPatch>patch )
271 row[0] = AliHLTTPCTransform::GetFirstRow( patch );
273 if ( maxPatch<patch )
276 row[1] = AliHLTTPCTransform::GetLastRow( patch );
281 // Determine slice number to really use.
282 if ( slices.size()>1 )
284 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
285 "Multiple slice numbers found in event 0x%08lX (%lu). Determining maximum occuring slice number...",
286 evtData.fEventID, evtData.fEventID );
287 unsigned maxCntSlice=0;
288 slIter = slices.begin();
289 slEnd = slices.end();
290 slCntIter = sliceCnts.begin();
291 while ( slIter != slEnd )
293 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
294 "Slice %lu found %lu times.", *slIter, *slCntIter );
295 if ( maxCntSlice<*slCntIter )
297 maxCntSlice = *slCntIter;
303 Logging( kHLTLogError, "HLT::TPCSliceTracker::DoEvent", "Multiple slices found in event",
304 "Using slice %lu.", slice );
306 else if ( slices.size()>0 )
308 slice = *(slices.begin());
315 if ( vertexSlice != slice )
317 // multiple vertex blocks in event and we used the wrong one...
319 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
322 if ( iter->fDataType == AliHLTTPCDefinitions::fgkVertexDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
324 inPtrV = (AliHLTTPCVertexData*)(iter->fPtr);
327 fVertex->Read( inPtrV );
333 // fTracker->InitSector( slice, row, fEta );
334 // fTracker->SetVertex(fVertex);
338 std::vector<unsigned long> patchIndices;
339 std::vector<unsigned long>::iterator pIter, pEnd;
340 for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
344 if ( iter->fDataType == AliHLTTPCDefinitions::fgkClustersDataType && slice==AliHLTTPCDefinitions::GetMinSliceNr( *iter ) )
346 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
347 pIter = patchIndices.begin();
348 pEnd = patchIndices.end();
349 while ( pIter!=pEnd && AliHLTTPCDefinitions::GetMinSliceNr( blocks[*pIter] ) < patch )
351 patchIndices.insert( pIter, ndx );
355 fTracker->CAInitialize();
357 pIter = patchIndices.begin();
358 pEnd = patchIndices.end();
359 while ( pIter!=pEnd )
364 patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
365 inPtrSP = (AliHLTTPCClusterData*)(iter->fPtr);
367 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Reading hits",
368 "Reading hits for slice %d - patch %d", slice, patch );
370 fTracker->CAReadPatchHits( patch, inPtrSP->fSpacePointCnt, inPtrSP->fSpacePoints );
371 fTracker->CAFindPatchTracks( patch );
376 fTracker->CAFindSliceTracks();
382 std::cin.get(symbol);
385 } while (symbol != '\n');
392 mysize = fTracker->GetOutputSize();
393 ntracks0 = fTracker->GetOutputNTracks();
394 outPtr->fTrackletCnt = fTracker->GetOutputNTracks();
396 Logging( kHLTLogDebug, "HLT::TPCSliceTracker::DoEvent", "Tracks",
397 "Input: Number of tracks: %lu Slice/MinPatch/MaxPatch/RowMin/RowMax: %lu/%lu/%lu/%lu/%lu.",
398 ntracks0, slice, minPatch, maxPatch, row[0], row[1] );
400 tSize += mysize+sizeof(AliHLTTPCTrackletData);
401 outBPtr += mysize+sizeof(AliHLTTPCTrackletData);
403 AliHLTComponentBlockData bd;
407 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, minPatch, maxPatch );
408 outputBlocks.push_back( bd );
410 #ifdef FORWARD_VERTEX_BLOCK
413 // Copy the descriptor block for the vertex information.
415 outputBlocks.push_back( bd );
417 #endif // FORWARD_VERTEX_BLOCK
421 fTracker->CAWriteHistos();