// @(#) $Id$
-//***************************************************************************
-// This file is property of and copyright by the ALICE HLT Project *
+// **************************************************************************
+// This file is property of and copyright by the ALICE HLT Project *
// ALICE Experiment at CERN, All rights reserved. *
// *
// Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
// appear in the supporting documentation. The authors make no claims *
// about the suitability of this software for any purpose. It is *
// provided "as is" without express or implied warranty. *
+// *
//***************************************************************************
#include "AliHLTTPCCATracker.h"
#include "AliHLTTPCCAOutTrack.h"
-#include "AliHLTTPCCAGrid.h"
#include "AliHLTTPCCARow.h"
#include "AliHLTTPCCATrack.h"
+#include "AliHLTTPCCATracklet.h"
#include "AliHLTTPCCAMath.h"
-#include "AliHLTTPCCAHit.h"
+#include "MemoryAssignmentHelpers.h"
#include "TStopwatch.h"
#include "AliHLTTPCCAHitArea.h"
#include "AliHLTTPCCATrackletConstructor.h"
#include "AliHLTTPCCATrackletSelector.h"
#include "AliHLTTPCCAProcess.h"
-#include "AliHLTTPCCALinksWriter.h"
-#include "AliHLTTPCCAUsedHitsInitialiser.h"
+#include "AliHLTTPCCASliceTrack.h"
+#include "AliHLTTPCCASliceOutput.h"
+#include "AliHLTTPCCAClusterData.h"
#include "AliHLTTPCCATrackParam.h"
-#include "AliHLTTPCCATrackParam1.h"
+
+#include "AliHLTTPCCAGPUConfig.h"
#if !defined(HLTCA_GPUCODE)
-#if defined( HLTCA_STANDALONE )
-#include <iostream.h>
-#else
-#include "Riostream.h"
+#include <iostream>
+#include <iomanip>
+#include <string.h>
+#endif
+
+//#define DRAW1
+
+#ifdef DRAW1
+#include "AliHLTTPCCADisplay.h"
+#endif //DRAW1
+
+#ifdef HLTCA_INTERNAL_PERFORMANCE
+//#include "AliHLTTPCCAPerformance.h"
#endif
+
+#ifdef HLTCA_STANDALONE
+#include "AliHLTTPCCAStandaloneFramework.h"
#endif
-//#define DRAW
-
-#ifdef DRAW
- #include "AliHLTTPCCADisplay.h"
- #include "TApplication.h"
-#endif //DRAW
-
-ClassImp(AliHLTTPCCATracker)
-
-#if !defined(HLTCA_GPUCODE)
-
-AliHLTTPCCATracker::AliHLTTPCCATracker()
- :
- fParam(),
- fNHitsTotal(0),
- fGridSizeTotal(0),
- fGrid1SizeTotal(0),
- fHits(0),
- fHits1(0),
- fGridContents(0),
- fGrid1Contents(0),
- fHitsID(0),
- fHitLinkUp(0),
- fHitLinkDown(0),
- fHitIsUsed(0),
- fStartHits(0),
- fTracklets(0),
- fNTracks(0),
- fTracks(0),
- fTrackHits(0),
- fNOutTracks(0),
- fNOutTrackHits(0),
- fOutTracks(0),
- fOutTrackHits(0),
- fEventMemory(0),
- fEventMemSize(0),
- fTexHitsFullData(0),
- fTexHitsFullSize(0)
-{
- // constructor
- //fRows = new AliHLTTPCCARow[fParam.NRows()];
- //Initialize( fParam );
-}
-
-AliHLTTPCCATracker::AliHLTTPCCATracker( const AliHLTTPCCATracker& )
- :
- fParam(),
- fNHitsTotal(0),
- fGridSizeTotal(0),
- fGrid1SizeTotal(0),
- fHits(0),
- fHits1(0),
- fGridContents(0),
- fGrid1Contents(0),
- fHitsID(0),
- fHitLinkUp(0),
- fHitLinkDown(0),
- fHitIsUsed(0),
- fStartHits(0),
- fTracklets(0),
- fNTracks(0),
- fTracks(0),
- fTrackHits(0),
- fNOutTracks(0),
- fNOutTrackHits(0),
- fOutTracks(0),
- fOutTrackHits(0),
- fEventMemory(0),
- fEventMemSize(0),
- fTexHitsFullData(0),
- fTexHitsFullSize(0)
-{
- // dummy
-}
-
-AliHLTTPCCATracker &AliHLTTPCCATracker::operator=( const AliHLTTPCCATracker& )
-{
- // dummy
- fOutTrackHits=0;
- fOutTracks=0;
- fNOutTracks=0;
- fTrackHits = 0;
- fEventMemory = 0;
- return *this;
-}
-
-GPUd() AliHLTTPCCATracker::~AliHLTTPCCATracker()
+ClassImp( AliHLTTPCCATracker )
+
+
+#if !defined(HLTCA_GPUCODE)
+
+AliHLTTPCCATracker::~AliHLTTPCCATracker()
{
// destructor
+ if (!fIsGPUTracker)
+ {
+ if (fCommonMem) delete fCommonMem;
+ if (fHitMemory) delete[] fHitMemory;
+ if (fTrackletMemory) delete[] fTrackletMemory;
+ if (fTrackMemory) delete[] fTrackMemory;
+ fCommonMem = NULL;
+ fHitMemory = fTrackMemory = NULL;
+ }
+}
+
+// ----------------------------------------------------------------------------------
+void AliHLTTPCCATracker::Initialize( const AliHLTTPCCAParam ¶m )
+{
+ // initialisation
+ fParam = param;
+ fParam.Update();
+ fData.InitializeRows( fParam );
+
StartEvent();
}
-#endif
+void AliHLTTPCCATracker::StartEvent()
+{
+ // start new event and fresh the memory
+
+ SetupCommonMemory();
+}
-GPUd() UChar_t AliHLTTPCCATracker::GetGridContent( UInt_t i ) const
+void AliHLTTPCCATracker::SetGPUTracker()
{
- //* get grid content
-#if defined(HLTCA_GPUSTEP)
- return (UChar_t) tex1Dfetch(texGrid,i).x;
-#else
- return fGridContents[i];
-#endif
+ //Make this a GPU Tracker
+ fIsGPUTracker = true;
+ fData.SetGpuSliceData();
+}
+
+char* AliHLTTPCCATracker::SetGPUTrackerCommonMemory(char* const pGPUMemory)
+{
+ //Set up common Memory Pointer for GPU Tracker
+ fCommonMem = (commonMemoryStruct*) pGPUMemory;
+ return(pGPUMemory + sizeof(commonMemoryStruct));
}
-GPUd() AliHLTTPCCAHit AliHLTTPCCATracker::GetHit( UInt_t i ) const
+char* AliHLTTPCCATracker::SetGPUTrackerHitsMemory(char* pGPUMemory, int MaxNHits)
{
- //* get hit
-#if defined(HLTCA_USE_GPU)
- AliHLTTPCCAHit h;
- float2 f = tex1Dfetch(texHits,i);
- h.Y() = f.x;
- h.Z() = f.y;
- return h;
-#else
- return fHits[i];
+ //Set up Hits Memory Pointers for GPU Tracker
+ fHitMemory = (char*) pGPUMemory;
+ SetPointersHits(MaxNHits);
+ pGPUMemory += fHitMemorySize;
+ AssignMemory(fTrackletTmpStartHits, pGPUMemory, NHitsTotal());
+ AssignMemory(fRowStartHitCountOffset, pGPUMemory, Param().NRows());
+
+ return(pGPUMemory);
+}
+
+char* AliHLTTPCCATracker::SetGPUTrackerTrackletsMemory(char* pGPUMemory, int MaxNTracks)
+{
+ //Set up Tracklet Memory Pointers for GPU Tracker
+ fTrackletMemory = (char*) pGPUMemory;
+ SetPointersTracklets(MaxNTracks);
+ pGPUMemory += fTrackletMemorySize;
+ AssignMemory(fGPUTrackletTemp, pGPUMemory, MaxNTracks);
+ AssignMemory(fRowBlockTracklets, pGPUMemory, MaxNTracks * 2 * (Param().NRows() / HLTCA_GPU_SCHED_ROW_STEP + 1));
+ AssignMemory(fRowBlockPos, pGPUMemory, 2 * (Param().NRows() / HLTCA_GPU_SCHED_ROW_STEP + 1));
+ AssignMemory(fBlockStartingTracklet, pGPUMemory, HLTCA_GPU_BLOCK_COUNT);
+
+ return(pGPUMemory);
+}
+
+char* AliHLTTPCCATracker::SetGPUTrackerTracksMemory(char* pGPUMemory, int MaxNTracks, int MaxNHits )
+{
+ //Set up Tracks Memory Pointer for GPU Tracker
+ fTrackMemory = (char*) pGPUMemory;
+ SetPointersTracks(MaxNTracks, MaxNHits);
+ pGPUMemory += fTrackMemorySize;
+
+ return(pGPUMemory);
+}
+
+void AliHLTTPCCATracker::DumpSliceData(std::ostream &out)
+{
+ //Dump Slice Input Data to File
+ out << "Slice Data:" << std::endl;
+ for (int i = 0;i < Param().NRows();i++)
+ {
+ out << "Row: " << i << std::endl;
+ for (int j = 0;j < Row(i).NHits();j++)
+ {
+ if (j && j % 16 == 0) out << std::endl;
+ out << j << '-' << Data().HitDataY(Row(i), j) << '-' << Data().HitDataZ(Row(i), j) << ", ";
+ }
+ out << std::endl;
+ }
+}
+
+void AliHLTTPCCATracker::DumpLinks(std::ostream &out)
+{
+ //Dump Links (after Neighbours Finder / Cleaner) to file
+ out << "Hit Links:" << std::endl;
+ for (int i = 0;i < Param().NRows();i++)
+ {
+ out << "Row: " << i << std::endl;
+ for (int j = 0;j < Row(i).NHits();j++)
+ {
+ if (j && j % 32 == 0) out << std::endl;
+ out << HitLinkUpData(Row(i), j) << "/" << HitLinkDownData(Row(i), j) << ", ";
+ }
+ out << std::endl;
+ }
+}
+
+void AliHLTTPCCATracker::DumpHitWeights(std::ostream &out)
+{
+ //dump hit weights to file
+ out << "Hit Weights:" << std::endl;
+ for (int i = 0;i < Param().NRows();i++)
+ {
+ out << "Row: " << i << ":" << std::endl;
+ for (int j = 0;j < Row(i).NHits();j++)
+ {
+ if (j && j % 32 == 0) out << std::endl;
+ out << HitWeight(Row(i), j) << ", ";
+ }
+ out << std::endl;
+ }
+}
+
+int AliHLTTPCCATracker::StarthitSortComparison(const void*a, const void* b)
+{
+ //qsort helper function to sort start hits
+ AliHLTTPCCAHitId* aa = (AliHLTTPCCAHitId*) a;
+ AliHLTTPCCAHitId* bb = (AliHLTTPCCAHitId*) b;
+
+ if (aa->RowIndex() != bb->RowIndex()) return(aa->RowIndex() - bb->RowIndex());
+ return(aa->HitIndex() - bb->HitIndex());
+}
+
+void AliHLTTPCCATracker::DumpStartHits(std::ostream &out)
+{
+ //sort start hits and dump to file
+ out << "Start Hits: (" << *NTracklets() << ")" << std::endl;
+#ifdef HLTCA_GPU_SORT_DUMPDATA
+ qsort(TrackletStartHits(), *NTracklets(), sizeof(AliHLTTPCCAHitId), StarthitSortComparison);
#endif
+ for (int i = 0;i < *NTracklets();i++)
+ {
+ out << TrackletStartHit(i).RowIndex() << "-" << TrackletStartHit(i).HitIndex() << std::endl;
+ }
+ out << std::endl;
}
+void AliHLTTPCCATracker::DumpTrackHits(std::ostream &out)
+{
+ //dump tracks to file
+ out << "Tracks: (" << *NTracks() << ")" << std::endl;
+#ifdef HLTCA_GPU_SORT_DUMPDATA
+ for (int k = 0;k < Param().NRows();k++)
+ {
+ for (int l = 0;l < Row(k).NHits();l++)
+ {
+#endif
+ for (int j = 0;j < *NTracks();j++)
+ {
+ if (Tracks()[j].NHits() == 0 || !Tracks()[j].Alive()) continue;
+#ifdef HLTCA_GPU_SORT_DUMPDATA
+ if (TrackHits()[Tracks()[j].FirstHitID()].RowIndex() == k && TrackHits()[Tracks()[j].FirstHitID()].HitIndex() == l)
+ {
+#endif
+ for (int i = 0;i < Tracks()[j].NHits();i++)
+ {
+ out << TrackHits()[Tracks()[j].FirstHitID() + i].RowIndex() << "-" << TrackHits()[Tracks()[j].FirstHitID() + i].HitIndex() << ", ";
+ }
+ out << "(Track: " << j << ")" << std::endl;
+#ifdef HLTCA_GPU_SORT_DUMPDATA
+ }
+ }
+#endif
+ }
+#ifdef HLTCA_GPU_SORT_DUMPDATA
+ }
+#endif
+}
+void AliHLTTPCCATracker::DumpTrackletHits(std::ostream &out)
+{
+ //dump tracklets to file
+ out << "Tracklets: (" << *NTracklets() << ")" << std::endl;
+#ifdef HLTCA_GPU_SORT_DUMPDATA
+ AliHLTTPCCAHitId* tmpIds = new AliHLTTPCCAHitId[*NTracklets()];
+ AliHLTTPCCATracklet* tmpTracklets = new AliHLTTPCCATracklet[*NTracklets()];
+ memcpy(tmpIds, TrackletStartHits(), *NTracklets() * sizeof(AliHLTTPCCAHitId));
+ memcpy(tmpTracklets, Tracklets(), *NTracklets() * sizeof(AliHLTTPCCATracklet));
+#ifdef EXTERN_ROW_HITS
+ int* tmpHits = new int[*NTracklets() * Param().NRows()];
+ memcpy(tmpHits, TrackletRowHits(), *NTracklets() * Param().NRows() * sizeof(int));
+#endif
+ qsort(TrackletStartHits(), *NTracklets(), sizeof(AliHLTTPCCAHitId), StarthitSortComparison);
+ for (int i = 0;i < *NTracklets();i++)
+ {
+ for (int j = 0;j < *NTracklets();j++)
+ {
+ if (tmpIds[i].RowIndex() == TrackletStartHit(j).RowIndex() && tmpIds[i].HitIndex() == TrackletStartHit(j).HitIndex())
+ {
+ memcpy(&Tracklets()[j], &tmpTracklets[i], sizeof(AliHLTTPCCATracklet));
+#ifdef EXTERN_ROW_HITS
+ if (tmpTracklets[i].NHits())
+ {
+ for (int k = tmpTracklets[i].FirstRow();k <= tmpTracklets[i].LastRow();k++)
+ {
+ fTrackletRowHits[k * *NTracklets() + j] = tmpHits[k * *NTracklets() + i];
+ }
+ }
+#endif
+ break;
+ }
+ }
+ }
+ delete[] tmpIds;
+ delete[] tmpTracklets;
+#ifdef EXTERN_ROW_HITS
+ delete[] tmpHits;
+#endif
+#endif
+ for (int j = 0;j < *NTracklets();j++)
+ {
+ out << "Tracklet " << j << " (Hits: " << std::setw(3) << Tracklets()[j].NHits() << ", Start: " << std::setw(3) << TrackletStartHit(j).RowIndex() << "-" << std::setw(3) << TrackletStartHit(j).HitIndex() << ") ";
+ if (Tracklets()[j].NHits() == 0);
+ else if (Tracklets()[j].LastRow() > Tracklets()[j].FirstRow() && (Tracklets()[j].FirstRow() >= Param().NRows() || Tracklets()[j].LastRow() >= Param().NRows()))
+ {
+#ifdef HLTCA_STANDALONE
+ printf("\nError: First %d Last %d Num %d", Tracklets()[j].FirstRow(), Tracklets()[j].LastRow(), Tracklets()[j].NHits());
+#endif
+ }
+ else if (Tracklets()[j].NHits() && Tracklets()[j].LastRow() > Tracklets()[j].FirstRow())
+ {
+ for (int i = Tracklets()[j].FirstRow();i <= Tracklets()[j].LastRow();i++)
+ {
+ //if (Tracklets()[j].RowHit(i) != -1)
+#ifdef EXTERN_ROW_HITS
+ out << i << "-" << fTrackletRowHits[i * fCommonMem->fNTracklets + j] << ", ";
+#else
+ out << i << "-" << Tracklets()[j].RowHit(i) << ", ";
+#endif
+ }
+ }
+ out << std::endl;
+ }
+}
-// ----------------------------------------------------------------------------------
-GPUd() void AliHLTTPCCATracker::Initialize( AliHLTTPCCAParam ¶m )
+void AliHLTTPCCATracker::SetupCommonMemory()
{
- // initialisation
- StartEvent();
- fParam = param;
- fParam.Update();
- for( Int_t irow=0; irow<fParam.NRows(); irow++ ){
- fRows[irow].X() = fParam.RowX(irow);
- fRows[irow].MaxY() = CAMath::Tan( fParam.DAlpha()/2.)*fRows[irow].X();
+ // set up common memory
+
+ if (!fIsGPUTracker)
+ {
+ if ( !fCommonMem ) {
+ // the 1600 extra bytes are not used unless fCommonMemorySize increases with a later event
+ //fCommonMemory = reinterpret_cast<char*> ( new uint4 [ fCommonMemorySize/sizeof( uint4 ) + 100] );
+ fCommonMem = new commonMemoryStruct;
+ }
+
+ if (fHitMemory) delete[] fHitMemory;
+ if (fTrackletMemory) delete[] fTrackletMemory;
+ if (fTrackMemory) delete[] fTrackMemory;
}
- StartEvent();
+
+ fHitMemory = fTrackletMemory = fTrackMemory = 0;
+
+ fData.Clear();
+ fCommonMem->fNTracklets = 0;
+ fCommonMem->fNTracks = 0 ;
+ fCommonMem->fNTrackHits = 0;
}
-GPUd() void AliHLTTPCCATracker::StartEvent()
+void AliHLTTPCCATracker::ReadEvent( AliHLTTPCCAClusterData *clusterData )
{
- // start new event and fresh the memory
+ // read event
+
+ fClusterData = clusterData;
- if( fEventMemory ) delete[] fEventMemory;
- if( fOutTracks ) delete[] fOutTracks;
- if( fOutTrackHits ) delete[] fOutTrackHits;
- fEventMemory = 0;
- fHits = 0;
- fHits1 = 0;
- fHitsID = 0;
- fTrackHits = 0;
- fTracks = 0;
- fOutTrackHits = 0;
- fOutTracks = 0;
- fNTracks = 0;
- fNOutTrackHits = 0;
- fNOutTracks = 0;
- fNHitsTotal = 0;
+ StartEvent();
+
+ //* Convert input hits, create grids, etc.
+ fData.InitFromClusterData( *clusterData );
+ {
+ if (!fIsGPUTracker)
+ {
+ SetPointersHits( fData.NumberOfHits() ); // to calculate the size
+ fHitMemory = reinterpret_cast<char*> ( new uint4 [ fHitMemorySize/sizeof( uint4 ) + 100] );
+ }
+ SetPointersHits( fData.NumberOfHits() ); // set pointers for hits
+ }
}
-GPUhd() void AliHLTTPCCATracker::SetPointers()
+GPUhd() void AliHLTTPCCATracker::SetPointersHits( int MaxNHits )
{
// set all pointers to the event memory
- fEventMemSize = 0;
- UInt_t &size = fEventMemSize;
- fHits = (AliHLTTPCCAHit*) (fEventMemory+ size);
- size+= sizeof(AliHLTTPCCAHit)*fNHitsTotal;
- fHits1 = (ushort2*) (fEventMemory+ size);
- size+= sizeof(ushort2)*fNHitsTotal;
- fGridContents = (UChar_t *) (fEventMemory + size);
- size+= sizeof(Int_t)*fGridSizeTotal;
- fGrid1Contents = (UInt_t *) (fEventMemory + size);
- size+= sizeof(UInt_t)*fGrid1SizeTotal;
- fHitsID = (Int_t *) (fEventMemory + size);
- size+= sizeof(Int_t) * fNHitsTotal;
- fHitLinkUp = (Short_t *) (fEventMemory + size);
- size+= sizeof(Int_t) * fNHitsTotal;
- fHitLinkDown = (Short_t *) (fEventMemory + size);
- size+= sizeof(Int_t) * fNHitsTotal;
- fHitIsUsed = (Int_t *) (fEventMemory + size);
- size+= sizeof(Int_t) * fNHitsTotal;
- fStartHits = (Int_t *) (fEventMemory + size);
- size+= sizeof(Int_t) * (fNHitsTotal+1);
- size = (size/16+1)*16;
- fTexHitsFullData = (uint4*)(fEventMemory+ size);
- size+= ((sizeof(UShort_t)*6*fNHitsTotal + sizeof(UShort_t)*2*fGrid1SizeTotal )/16+1)*16;
-
- fTracklets = (Int_t *) (fEventMemory + size);
- size+= sizeof(Int_t) * (1 + fNHitsTotal*(5+ sizeof(AliHLTTPCCATrackParam)/4 + 160 ));
- fNTracks = (Int_t *) (fEventMemory + size);
- size+= sizeof(Int_t);
- fTracks = (AliHLTTPCCATrack* )(fEventMemory + size);
- size+= sizeof(AliHLTTPCCATrack) * (fNHitsTotal+1);
- fTrackHits = ( Int_t *)(fEventMemory + size);
- size+= sizeof(Int_t) * (10*fNHitsTotal+1);
-
- fOutTrackHits = 0;
- fOutTracks = 0;
-}
-
-GPUd() void AliHLTTPCCATracker::ReadEvent( Int_t *RowFirstHit, Int_t *RowNHits, Float_t *Y, Float_t *Z, Int_t NHits )
-{
- //* Read event
-
- fNHitsTotal = NHits;
- fGridSizeTotal = 0;
- fGrid1SizeTotal = 0;
- fTexHitsFullSize = 0;
-
- //cout<<"event mem = "<<fEventMemory<<endl;
- for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
- //cout<<"row, nhits="<<iRow<<" "<<RowNHits[iRow]<<endl;
- //cout<<"row, firsthit="<<iRow<<" "<<RowFirstHit[iRow]<<endl;
- AliHLTTPCCARow &row = fRows[iRow];
- row.FirstHit() = RowFirstHit[iRow];
- row.NHits() = RowNHits[iRow];
- Float_t yMin=1.e3, yMax=-1.e3, zMin=1.e3, zMax=-1.e3;
- Int_t nGrid = row.NHits();
- for( Int_t i=0; i<row.NHits(); i++ ){
- Int_t j = RowFirstHit[iRow]+i;
- if( yMax < Y[j] ) yMax = Y[j];
- if( yMin > Y[j] ) yMin = Y[j];
- if( zMax < Z[j] ) zMax = Z[j];
- if( zMin > Z[j] ) zMin = Z[j];
- }
- if( nGrid == 0 ){
- yMin = yMax = zMin = zMax = 0;
- nGrid = 1;
- }
+ char *mem = fHitMemory;
- row.Grid().Create( yMin, yMax, zMin, zMax, nGrid );
+ // extra arrays for tpc clusters
- float sy = ( CAMath::Abs( row.Grid().StepYInv() ) >1.e-4 ) ?1./row.Grid().StepYInv() :1;
- float sz = ( CAMath::Abs( row.Grid().StepZInv() ) >1.e-4 ) ?1./row.Grid().StepZInv() :1;
+#ifdef HLTCA_GPU_SORT_STARTHITS_2
+ AssignMemory( fTrackletStartHits, mem, MaxNHits + 32);
+#else
+ AssignMemory( fTrackletStartHits, mem, MaxNHits);
+#endif
- //cout<<"grid n = "<<row.Grid().N()<<" "<<sy<<" "<<sz<<" "<<yMin<<" "<<yMax<<" "<<zMin<<" "<<zMax<<endl;
-
- bool recreate=0;
- if( sy < 2. ) { recreate = 1; sy = 2; }
- if( sz < 2. ) { recreate = 1; sz = 2; }
- if( recreate ) row.Grid().Create( yMin, yMax, zMin, zMax, sy, sz );
+ // calculate the size
- fGridSizeTotal+=row.Grid().N()+3+10;
- //cout<<"grid n = "<<row.Grid().N()<<endl;
- }
-
- fGrid1SizeTotal = fGridSizeTotal+10;
+ fHitMemorySize = mem - fHitMemory;
+}
- SetPointers();
+GPUhd() void AliHLTTPCCATracker::SetPointersTracklets( int MaxNTracklets )
+{
+ // set all pointers to the tracklets memory
+ char *mem = fTrackletMemory;
- fEventMemory = (char*) ( new uint4 [ fEventMemSize/sizeof(uint4) + 100]);
- SetPointers();
+ // memory for tracklets
- fGridSizeTotal = 0;
- fGrid1SizeTotal = 0;
+ AssignMemory( fTracklets, mem, MaxNTracklets );
+#ifdef EXTERN_ROW_HITS
+ AssignMemory( fTrackletRowHits, mem, MaxNTracklets * Param().NRows());
+#endif
- for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ ){
- AliHLTTPCCARow &row = fRows[iRow];
- AliHLTTPCCAGrid &grid = row.Grid();
+ fTrackletMemorySize = mem - fTrackletMemory;
+}
- Int_t c[grid.N()+3+10];
- Int_t bins[row.NHits()];
- Int_t filled[ row.Grid().N() +3+10 ];
- for( UInt_t bin=0; bin<row.Grid().N()+3; bin++ ) filled[bin] = 0;
+GPUhd() void AliHLTTPCCATracker::SetPointersTracks( int MaxNTracks, int MaxNHits )
+{
+ // set all pointers to the tracks memory
+ char *mem = fTrackMemory;
- for( Int_t i=0; i<row.NHits(); i++ ){
- Int_t j = RowFirstHit[iRow]+i;
- Int_t bin = row.Grid().GetBin( Y[j], Z[j] );
- bins[i] = bin;
- filled[bin]++;
- }
+ // memory for selected tracks
- {
- Int_t n=0;
- for( UInt_t bin=0; bin<row.Grid().N()+3; bin++ ){
- c[bin] = n;
- n+=filled[bin];
- }
- }
- for( Int_t i=0; i<row.NHits(); i++ ){
- Int_t bin = bins[i];
- Int_t ind = c[bin] + filled[bin]-1;
- AliHLTTPCCAHit &h = fHits[RowFirstHit[iRow]+ind];
- fHitsID[RowFirstHit[iRow]+ind] = RowFirstHit[iRow]+i;
- h.Y() = Y[row.FirstHit()+i];
- h.Z() = Z[row.FirstHit()+i];
- filled[bin]--;
- }
+ AssignMemory( fTracks, mem, MaxNTracks );
+ AssignMemory( fTrackHits, mem, 2 * MaxNHits );
- grid.Offset() = fGridSizeTotal;
- Int_t off= grid.N()+3+10;
- fGridSizeTotal+=off;
- Int_t n2 = grid.N()/2;
- grid.Content2() = c[n2];
- UChar_t *cnew = fGridContents + grid.Offset();
-
- for( Int_t i=0; i<n2; i++ ){
- Int_t v = c[i];
- if( v>=256 ){
- cout<<" ERROR!!! "<<v<<endl;
- v = 255;
- }else if( v<0 ){
- cout<<" ERROR!!! "<<v<<endl;
- v = 0;
- }
- cnew[i] = (UChar_t ) v;
- }
- for( UInt_t i=n2; i<grid.N()+3; i++ ){
- Int_t v = c[i] - grid.Content2();
- if( v>=256 ){
- cout<<" ERROR 1 !!! "<<v<<endl;
- v = 255;
- }else if( v<0 ){
- cout<<" ERROR 1 !!! "<<v<<endl;
- v = 0;
- }
- cnew[i] = (UChar_t) v;
- }
+ // calculate the size
-
- UInt_t *cnew1 = fGrid1Contents + grid.Offset();
-
- for( UInt_t i=0; i<grid.N()+1; i++ ){
- UInt_t g0n = 0;
- UInt_t g1n = 0;
- UInt_t g1 = 0;
- UInt_t g0 = c[i];// max [gN]
- UInt_t g0e = c[i+2]; //max[gN+2]
- g0n = g0e - g0;
- if( i+grid.Ny()< grid.N()+1 ){// max [gN-gNy]
- g1 = c[i+grid.Ny()]; // max [gN]
- UInt_t g1e = c[i+grid.Ny()+2];//max [gN+2]
- g1n = g1e - g1;
- }
-
- if( g0n > 63 ) g0n = 63;
- if( g1n > 63 ) g1n = 63;
- cnew1[i] = (g1n<<26) + (g1<<16) + (g0n<<10) + g0;
- }
+ fTrackMemorySize = mem - fTrackMemory;
+}
+
+GPUh() int AliHLTTPCCATracker::CheckEmptySlice() const
+{
+ //Check if the Slice is empty, if so set the output apropriate and tell the reconstuct procesdure to terminate
+ if ( NHitsTotal() < 1 ) {
{
- float y0 = row.Grid().YMin();
- float stepY = (row.Grid().YMax() - y0)*(1./65535.);
- float z0 = row.Grid().ZMin();
- float stepZ = (row.Grid().ZMax() - z0)*(1./65535.);
- float stepYi = 1./stepY;
- float stepZi = 1./stepZ;
-
- row.Hy0() = y0;
- row.Hz0() = z0;
- row.HstepY() = stepY;
- row.HstepZ() = stepZ;
- row.HstepYi() = stepYi;
- row.HstepZi() = stepZi;
-
- for( Int_t ih=0; ih<row.NHits(); ih++ ){
- Int_t ihTot = RowFirstHit[iRow]+ih;
- AliHLTTPCCAHit &hh = fHits[ihTot];
- ushort2 &h = fHits1[ihTot];
- float xx = ((hh.Y() - y0)*stepYi); //SG!!!
- float yy = ((hh.Z() - z0)*stepZi);
- if( xx<0 || yy<0 || xx>=65536 || yy>= 65536 ){
- cout<<"!!!! hit packing error!!! "<<xx<<" "<<yy<<" "<<endl;
- }
- h.x = (UShort_t) xx;//((hh.Y() - y0)*stepYi);
- h.y = (UShort_t) yy;//((hh.Z() - z0)*stepZi);
- }
+ AliHLTTPCCASliceOutput::Allocate(*fOutput, 0, 0, fOutputControl);
+ AliHLTTPCCASliceOutput* useOutput = *fOutput;
+ if (useOutput == NULL) return(1);
+ useOutput->SetNTracks( 0 );
+ useOutput->SetNTrackClusters( 0 );
+ useOutput->SetNOutTracks(0);
+ useOutput->SetNOutTrackHits(0);
}
- if(1){
- row.FullOffset() = fTexHitsFullSize;
- ushort2 *p= (ushort2*)(fTexHitsFullData+row.FullOffset());
- for( Int_t ih=0; ih<row.NHits(); ih++ ){
- Int_t ihTot = RowFirstHit[iRow]+ih;
- p[ih] = fHits1[ihTot];
- }
- Int_t size = row.NHits()*sizeof(ushort2);
-
- row.FullGridOffset() = row.NHits()*2;
- UShort_t *p1 = ((UShort_t *)p) + row.FullGridOffset();
-
- Int_t n = grid.N();
- for( Int_t i=0; i<n; i++ ){
- p1[i] = c[i];
- }
- UShort_t a = c[n-1];
- Int_t nn = n+grid.Ny()+2;
- for( Int_t i=n; i<nn; i++ ) p1[i] = a;
-
- size+= (nn)*sizeof(UShort_t);
- row.FullLinkOffset() = row.NHits()*2 + nn;
- size+= row.NHits()*2*sizeof(Short_t);
- if( size%16 ) size = size/16+1;
- else size = size/16;
- row.FullSize()=size;
- //cout<<iRow<<", "<<row.fNHits<<"= "<<size*16<<"b: "<<row.fFullOffset<<" "<<row.fFullSize<<" "<<row.fFullGridOffset<<" "<<row.fFullLinkOffset<<endl;
-
- fTexHitsFullSize+=size;
- }
+ return 1;
}
- fGrid1SizeTotal = fGridSizeTotal+10;
+ return 0;
}
+void AliHLTTPCCATracker::RunNeighboursFinder()
+{
+ //Run the CPU Neighbours Finder
+ AliHLTTPCCAProcess<AliHLTTPCCANeighboursFinder>( Param().NRows(), 1, *this );
+}
-GPUh() void AliHLTTPCCATracker::Reconstruct()
+void AliHLTTPCCATracker::RunNeighboursCleaner()
{
- //* reconstruction of event
-
-#ifdef DRAW
- if( !gApplication ){
- TApplication *myapp = new TApplication("myapp",0,0);
+ //Run the CPU Neighbours Cleaner
+ AliHLTTPCCAProcess<AliHLTTPCCANeighboursCleaner>( Param().NRows() - 2, 1, *this );
+}
+
+void AliHLTTPCCATracker::RunStartHitsFinder()
+{
+ //Run the CPU Start Hits Finder
+ AliHLTTPCCAProcess<AliHLTTPCCAStartHitsFinder>( Param().NRows() - 4, 1, *this );
+}
+
+void AliHLTTPCCATracker::RunTrackletConstructor()
+{
+ //Run CPU Tracklet Constructor
+ AliHLTTPCCATrackletConstructor::AliHLTTPCCATrackletConstructorNewCPU(*this);
+}
+
+void AliHLTTPCCATracker::RunTrackletSelector()
+{
+ //Run CPU Tracklet Selector
+ AliHLTTPCCAProcess<AliHLTTPCCATrackletSelector>( 1, fCommonMem->fNTracklets, *this );
+}
+
+#ifdef HLTCA_STANDALONE
+void AliHLTTPCCATracker::StandalonePerfTime(int i)
+{
+ //Query Performance Timer for Standalone Version of Tracker
+ if (fGPUDebugLevel >= 1)
+ {
+ AliHLTTPCCAStandaloneFramework::StandaloneQueryTime(&fPerfTimers[i]);
}
- //AliHLTTPCCADisplay::Instance().Init();
-
- AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
- AliHLTTPCCADisplay::Instance().SetSliceView();
- AliHLTTPCCADisplay::Instance().DrawSlice( this );
- //for( Int_t iRow=0; iRow<fParam.NRows(); iRow++ )
- //for (Int_t i = 0; i<fRows[iRow].NHits(); i++)
- //AliHLTTPCCADisplay::Instance().DrawHit( iRow, i );
- //AliHLTTPCCADisplay::Instance().Ask();
+}
+#else
+void AliHLTTPCCATracker::StandalonePerfTime(int /*i*/) {}
#endif
+GPUh() void AliHLTTPCCATracker::Reconstruct()
+{
+ //* reconstruction of event
+ //std::cout<<"Reconstruct slice "<<fParam.ISlice()<<", nHits="<<NHitsTotal()<<std::endl;
+
fTimers[0] = 0; // find neighbours
fTimers[1] = 0; // construct tracklets
fTimers[2] = 0; // fit tracklets
fTimers[6] = 0;
fTimers[7] = 0;
- if( fNHitsTotal < 1 ) return;
- //if( fParam.ISlice()!=3 ) return;
+ //if( fParam.ISlice()<1 ) return; //SG!!!
+
TStopwatch timer0;
- *fNTracks = 0;
-#if !defined(HLTCA_GPUCODE)
- AliHLTTPCCAProcess<AliHLTTPCCANeighboursFinder>( Param().NRows(), 1, *this );
- AliHLTTPCCAProcess<AliHLTTPCCANeighboursCleaner>( Param().NRows()-2, 1, *this );
- AliHLTTPCCAProcess<AliHLTTPCCAStartHitsFinder>( Param().NRows()-4, 1, *this );
+ StandalonePerfTime(0);
- Int_t nStartHits = *fStartHits;
-
- Int_t nThreads = 128;
- Int_t nBlocks = fNHitsTotal/nThreads + 1;
- if( nBlocks<12 ){
- nBlocks = 12;
- nThreads = fNHitsTotal/12+1;
- if( nThreads%32 ) nThreads = (nThreads/32+1)*32;
+ if (CheckEmptySlice()) return;
+
+#ifdef DRAW1
+ //if( fParam.ISlice()==2 || fParam.ISlice()==3)
+ {
+ AliHLTTPCCADisplay::Instance().ClearView();
+ AliHLTTPCCADisplay::Instance().SetSliceView();
+ AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
+ AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
+ if ( NHitsTotal() > 0 ) {
+ AliHLTTPCCADisplay::Instance().DrawSliceHits( kRed, .5 );
+ AliHLTTPCCADisplay::Instance().Ask();
}
-
- nThreads = fNHitsTotal;
- nBlocks = 1;
+ }
+#endif //DRAW1
- AliHLTTPCCAProcess<AliHLTTPCCAUsedHitsInitialiser>(nBlocks, nThreads,*this);
+ fCommonMem->fNTracklets = fCommonMem->fNTracks = fCommonMem->fNTrackHits = 0;
- nThreads = 256;
- nBlocks = 30;
+#if !defined(HLTCA_GPUCODE)
- nThreads = 1;
- nBlocks = 1;
-
- AliHLTTPCCAProcess<AliHLTTPCCALinksWriter>(nBlocks, nThreads,*this);
-
- Int_t nMemThreads = 128;
- nThreads = 256;//96;
- nBlocks = nStartHits/nThreads + 1;
- if( nBlocks<30 ){
- nBlocks = 30;
- nThreads = (nStartHits)/30+1;
- if( nThreads%32 ) nThreads = (nThreads/32+1)*32;
+ if (fGPUDebugLevel >= 6)
+ {
+ *fGPUDebugOut << std::endl << std::endl << "Slice: " << Param().ISlice() << std::endl;
+ *fGPUDebugOut << "Slice Data:" << std::endl;
+ DumpSliceData(*fGPUDebugOut);
}
- nThreads = nStartHits;
- nBlocks = 1;
+ StandalonePerfTime(1);
- AliHLTTPCCAProcess1<AliHLTTPCCATrackletConstructor>(nBlocks, nMemThreads+nThreads,*this);
+ RunNeighboursFinder();
- {
- nThreads = 128;
- nBlocks = nStartHits/nThreads + 1;
- if( nBlocks<12 ){
- nBlocks = 12;
- nThreads = nStartHits/12+1;
- nThreads = (nThreads/32+1)*32;
- }
- *fStartHits = 0;
- *fTrackHits = 0;
-
- nThreads = nStartHits;
- nBlocks = 1;
-
-
- AliHLTTPCCAProcess<AliHLTTPCCATrackletSelector>(nBlocks, nThreads,*this);
-
- //cudaMemcpy(cpuTrackerCopy.fNTracks, gpuTrackerCopy.fNTracks, sizeof(int), cudaMemcpyDeviceToHost);
- //cudaMemcpy(cpuTrackerCopy.fTrackHits, gpuTrackerCopy.fTrackHits, sizeof(int), cudaMemcpyDeviceToHost);
-
- //Int_t size = sizeof(AliHLTTPCCATrack)*( *cpuTrackerCopy.fNTracks );
- //cudaMemcpy(cpuTrackerCopy.fTracks, gpuTrackerCopy.fTracks, size, cudaMemcpyDeviceToHost);
- //cout<<"Tracks size = "<<size<<endl;
-
- //size = sizeof(Int_t)*( *cpuTrackerCopy.fTrackHits );
- //cudaMemcpy(cpuTrackerCopy.fTrackHits+1, gpuTrackerCopy.fTrackHits+1, size, cudaMemcpyDeviceToHost);
- //cout<<"Track hits size = "<<size<<endl;
- //cpuTrackerCopy.WriteOutput();
- nStartHits = *fStartHits;
- //cout<<"N tracklets constructed = "<<nStartHits<<endl;
-
- //cout<<"Selected NTracks = "<<*fNTracks<<endl;
- WriteOutput();
- }
+ StandalonePerfTime(2);
+ if (fGPUDebugLevel >= 6) DumpLinks(*fGPUDebugOut);
+
+#ifdef HLTCA_INTERNAL_PERFORMANCE
+ //if( Param().ISlice()<=2 )
+ //AliHLTTPCCAPerformance::Instance().LinkPerformance( Param().ISlice() );
#endif
- timer0.Stop();
- fTimers[0] = timer0.CpuTime();
- }
+#ifdef DRAW1
+ if ( NHitsTotal() > 0 ) {
+ AliHLTTPCCADisplay::Instance().DrawSliceLinks( -1, -1, 1 );
+ AliHLTTPCCADisplay::Instance().Ask();
+ }
+#endif //DRAW1
+
+ RunNeighboursCleaner();
+
+ StandalonePerfTime(3);
+
+ if (fGPUDebugLevel >= 6) DumpLinks(*fGPUDebugOut);
+
+ RunStartHitsFinder();
+
+ StandalonePerfTime(4);
+ StandalonePerfTime(5);
+
+ if (fGPUDebugLevel >= 6) DumpStartHits(*fGPUDebugOut);
+
+ fData.ClearHitWeights();
+
+ SetPointersTracklets( fCommonMem->fNTracklets * 2 ); // to calculate the size
+ fTrackletMemory = reinterpret_cast<char*> ( new uint4 [ fTrackletMemorySize/sizeof( uint4 ) + 100] );
+ SetPointersTracklets( fCommonMem->fNTracklets * 2 ); // set pointers for hits
+
+ SetPointersTracks( fCommonMem->fNTracklets * 2, NHitsTotal() ); // to calculate the size
+ fTrackMemory = reinterpret_cast<char*> ( new uint4 [ fTrackMemorySize/sizeof( uint4 ) + 100] );
+ SetPointersTracks( fCommonMem->fNTracklets * 2, NHitsTotal() ); // set pointers for hits
+
+ StandalonePerfTime(6);
+ StandalonePerfTime(7);
+
+ RunTrackletConstructor();
+
+ StandalonePerfTime(8);
+
+ if (fGPUDebugLevel >= 6) DumpTrackletHits(*fGPUDebugOut);
+ if (fGPUDebugLevel >= 6) DumpHitWeights(*fGPUDebugOut);
+ //std::cout<<"Slice "<<Param().ISlice()<<": NHits="<<NHitsTotal()<<", NTracklets="<<*NTracklets()<<std::endl;
+ RunTrackletSelector();
+ StandalonePerfTime(9);
+
+ //std::cout<<"Slice "<<Param().ISlice()<<": N start hits/tracklets/tracks = "<<nStartHits<<" "<<nStartHits<<" "<<*fNTracks<<std::endl;
+
+ if (fGPUDebugLevel >= 6) DumpTrackHits(*fGPUDebugOut);
+
+ //std::cout<<"Memory used for slice "<<fParam.ISlice()<<" : "<<fCommonMemorySize/1024./1024.<<" + "<<fHitMemorySize/1024./1024.<<" + "<<fTrackMemorySize/1024./1024.<<" = "<<( fCommonMemorySize+fHitMemorySize+fTrackMemorySize )/1024./1024.<<" Mb "<<std::endl;
+
+ WriteOutput();
+
+ StandalonePerfTime(10);
+
+#endif
+
+#ifdef DRAW1
+ {
+ AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
+ AliHLTTPCCATracker &slice = *this;
+ std::cout << "N out tracks = " << slice.NOutTracks() << std::endl;
+ AliHLTTPCCADisplay::Instance().SetSliceView();
+ AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
+ AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
+ disp.DrawSliceHits( kRed, .5 );
+ disp.Ask();
+ for ( int itr = 0; itr < slice.NOutTracks(); itr++ ) {
+ std::cout << "track N " << itr << ", nhits=" << slice.OutTracks()[itr].NHits() << std::endl;
+ disp.DrawSliceOutTrack( itr, kBlue );
+ //disp.Ask();
+ //int id = slice.OutTracks()[itr].OrigTrackID();
+ //AliHLTTPCCATrack &tr = Tracks()[id];
+ //for( int ih=0; ih<tr.NHits(); ih++ ){
+ //int ic = (fTrackHits[tr.FirstHitID()+ih]);
+ //std::cout<<ih<<" "<<ID2IRow(ic)<<" "<<ID2IHit(ic)<<std::endl;
+ //}
+ //disp.DrawSliceTrack( id, kBlue );
+ //disp.Ask();
+ }
+ disp.Ask();
+ }
+#endif //DRAW1
+
+ timer0.Stop();
+ fTimers[0] = timer0.CpuTime() / 100.;
+
+}
GPUh() void AliHLTTPCCATracker::WriteOutput()
{
// write output
TStopwatch timer;
- fOutTrackHits = new Int_t[fNHitsTotal*10];
- fOutTracks = new AliHLTTPCCAOutTrack[*fNTracks];
- fNOutTrackHits = 0;
- fNOutTracks = 0;
- //cout<<"NTracks = "<<*fNTracks<<endl;
- //cout<<"NHits = "<<fNHitsTotal<<endl;
- for( Int_t iTr=0; iTr<*fNTracks; iTr++){
- //cout<<"iTr = "<<iTr<<endl;
- AliHLTTPCCATrack &iTrack = fTracks[iTr];
- if( !iTrack.Alive() ) continue;
- if( iTrack.NHits()<3 ) continue;
- //cout<<10<<endl;
- AliHLTTPCCAOutTrack &out = fOutTracks[fNOutTracks];
- out.FirstHitRef() = fNOutTrackHits;
- out.NHits() = 0;
- out.OrigTrackID() = iTr;
- {
- out.StartPoint() = iTrack.Param();
- out.EndPoint() = iTrack.Param();
- }
- //cout<<11<<endl;
-
- Int_t iID = iTrack.FirstHitID();
- Int_t fNOutTrackHitsOld = fNOutTrackHits;
- //cout<<12<<" "<<iID<<" "<<iTrack.NHits()<<endl;
- for( Int_t ith=0; ith<iTrack.NHits(); ith++ ){
- //cout<<ith<<":"<<endl;
- Int_t ic = (fTrackHits[iID+ith]);
- //cout<<ic<<endl;
- AliHLTTPCCARow &row = ID2Row(ic);
- Int_t ih = ID2IHit(ic);
- //cout<<"write row,hit="<<ID2IRow(ic)<<" "<<ih<<endl;
- fOutTrackHits[fNOutTrackHits] = fHitsID[row.FirstHit()+ih];
- fNOutTrackHits++;
- //cout<<"ok"<<endl;
- if( fNOutTrackHits>fNHitsTotal*10 ){
- cout<<"fNOutTrackHits>fNHitsTotal"<<endl;
- exit(0);//SG!!!
- return;
- }
- out.NHits()++;
- }
- //cout<<13<<endl;
- //cout<<fNOutTracks<<": itr = "<<iTr<<", n outhits = "<<out.NHits()<<endl;
- if( out.NHits() >= 2 ){
- fNOutTracks++;
- }else {
- fNOutTrackHits = fNOutTrackHitsOld;
- }
+
+ //cout<<"output: nTracks = "<<*fNTracks<<", nHitsTotal="<<NHitsTotal()<<std::endl;
+
+ if (fOutputControl == NULL) fOutputControl = new AliHLTTPCCASliceOutput::outputControlStruct;
+ AliHLTTPCCASliceOutput::Allocate(*fOutput, fCommonMem->fNTracks, fCommonMem->fNTrackHits, fOutputControl);
+ AliHLTTPCCASliceOutput* useOutput = *fOutput;
+ if (useOutput == NULL) return;
+
+ if (fOutputControl->fDefaultOutput)
+ {
+ useOutput->SetNTracks( fCommonMem->fNTracks );
+ useOutput->SetNTrackClusters( fCommonMem->fNTrackHits );
+
+ int nStoredHits = 0;
+
+ for ( int iTr = 0; iTr < fCommonMem->fNTracks; iTr++ ) {
+ AliHLTTPCCATrack &iTrack = fTracks[iTr];
+
+ AliHLTTPCCASliceTrack out;
+ out.SetFirstClusterRef( nStoredHits );
+ out.SetNClusters( iTrack.NHits() );
+ out.SetParam( iTrack.Param() );
+
+ useOutput->SetTrack( iTr, out );
+
+ int iID = iTrack.FirstHitID();
+ for ( int ith = 0; ith < iTrack.NHits(); ith++ ) {
+ const AliHLTTPCCAHitId &ic = fTrackHits[iID + ith];
+ int iRow = ic.RowIndex();
+ int ih = ic.HitIndex();
+
+ const AliHLTTPCCARow &row = fData.Row( iRow );
+
+ //float y0 = row.Grid().YMin();
+ //float z0 = row.Grid().ZMin();
+ //float stepY = row.HstepY();
+ //float stepZ = row.HstepZ();
+ //float x = row.X();
+
+ //const uint4 *tmpint4 = RowData() + row.FullOffset();
+ //const ushort2 *hits = reinterpret_cast<const ushort2*>(tmpint4);
+ //ushort2 hh = hits[ih];
+ //float y = y0 + hh.x*stepY;
+ //float z = z0 + hh.y*stepZ;
+
+ int clusterIndex = fData.ClusterDataIndex( row, ih );
+ int clusterRowIndex = clusterIndex - fClusterData->RowOffset( iRow );
+
+ if ( clusterIndex < 0 || clusterIndex >= fClusterData->NumberOfClusters() ) {
+ //std::cout << inpIDtot << ", " << fClusterData->NumberOfClusters()
+ //<< "; " << inpID << ", " << fClusterData->NumberOfClusters( iRow ) << std::endl;
+ //abort();
+ continue;
+ }
+ if ( clusterRowIndex < 0 || clusterRowIndex >= fClusterData->NumberOfClusters( iRow ) ) {
+ //std::cout << inpIDtot << ", " << fClusterData->NumberOfClusters()
+ //<< "; " << inpID << ", " << fClusterData->NumberOfClusters( iRow ) << std::endl;
+ //abort();
+ continue;
+ }
+
+ float origX = fClusterData->X( clusterIndex );
+ float origY = fClusterData->Y( clusterIndex );
+ float origZ = fClusterData->Z( clusterIndex );
+
+
+ int id = fClusterData->Id( clusterIndex );
+
+ float2 hUnpackedYZ;
+ hUnpackedYZ.x = origY;
+ hUnpackedYZ.y = origZ;
+ float hUnpackedX = origX;
+
+ useOutput->SetClusterId( nStoredHits, id );
+ useOutput->SetClusterRow( nStoredHits, ( unsigned char ) iRow );
+ useOutput->SetClusterUnpackedYZ( nStoredHits, hUnpackedYZ );
+ useOutput->SetClusterUnpackedX( nStoredHits, hUnpackedX );
+ nStoredHits++;
+ }
+ }
+ }
+
+
+ // old stuff
+ if (fOutputControl->fObsoleteOutput)
+ {
+ useOutput->SetNOutTrackHits(0);
+ useOutput->SetNOutTracks(0);
+
+
+ for ( int iTr = 0; iTr < fCommonMem->fNTracks; iTr++ ) {
+
+ const AliHLTTPCCATrack &iTrack = fTracks[iTr];
+
+ //std::cout<<"iTr = "<<iTr<<", nHits="<<iTrack.NHits()<<std::endl;
+
+ //if( !iTrack.Alive() ) continue;
+ if ( iTrack.NHits() < 3 ) continue;
+ AliHLTTPCCAOutTrack &out = useOutput->OutTracks()[useOutput->NOutTracks()];
+ out.SetFirstHitRef( useOutput->NOutTrackHits() );
+ out.SetNHits( 0 );
+ out.SetOrigTrackID( iTr );
+ AliHLTTPCCATrackParam tmpParam;
+ tmpParam.InitParam();
+ tmpParam.SetParam(iTrack.Param());
+ out.SetStartPoint( tmpParam );
+ out.SetEndPoint( tmpParam );
+
+ int iID = iTrack.FirstHitID();
+ int nOutTrackHitsOld = useOutput->NOutTrackHits();
+
+ for ( int ith = 0; ith < iTrack.NHits(); ith++ ) {
+ const AliHLTTPCCAHitId &ic = fTrackHits[iID + ith];
+ const AliHLTTPCCARow &row = Row( ic );
+ int ih = ic.HitIndex();
+ useOutput->SetOutTrackHit(useOutput->NOutTrackHits(), HitInputID( row, ih ));
+ useOutput->SetNOutTrackHits(useOutput->NOutTrackHits() + 1 );
+ //std::cout<<"write i,row,hit,id="<<ith<<", "<<ID2IRow(ic)<<", "<<ih<<", "<<HitInputID( row, ih )<<std::endl;
+ if ( useOutput->NOutTrackHits() >= 10*NHitsTotal() ) {
+ std::cout << "fNOutTrackHits>NHitsTotal()" << std::endl;
+ //exit(0);
+ return;//SG!!!
+ }
+ out.SetNHits( out.NHits() + 1 );
+ }
+ if ( out.NHits() >= 2 ) {
+ useOutput->SetNOutTracks(useOutput->NOutTracks() + 1);
+ } else {
+ useOutput->SetNOutTrackHits(nOutTrackHitsOld);
+ }
+ }
}
+
timer.Stop();
- fTimers[5]+=timer.CpuTime();
+ fTimers[5] += timer.CpuTime();
}
-GPUh() void AliHLTTPCCATracker::FitTrackFull( AliHLTTPCCATrack &/**/, Float_t * /**/ ) const
-{
+#endif
+
+GPUh() void AliHLTTPCCATracker::FitTrackFull( const AliHLTTPCCATrack &/**/, float * /**/ ) const
+{
// fit track with material
-#ifdef XXX
- //* Fit the track
+#ifdef XXX
+ //* Fit the track
FitTrack( iTrack, tt0 );
- if( iTrack.NHits()<=3 ) return;
-
+ if ( iTrack.NHits() <= 3 ) return;
+
AliHLTTPCCATrackParam &t = iTrack.Param();
AliHLTTPCCATrackParam t0 = t;
t.Chi2() = 0;
- t.NDF() = -5;
- Bool_t first = 1;
-
- Int_t iID = iTrack.FirstHitID();
- for( Int_t ih=0; ih<iTrack.NHits(); ih++, iID++ ){
- Int_t *ic = &(fTrackHits[iID]);
- Int_t iRow = ID2IRow(*ic);
- AliHLTTPCCARow &row = fRows[iRow];
- if( !t0.TransportToX( row.X() ) ) continue;
- Float_t dy, dz;
- AliHLTTPCCAHit &h = ID2Hit(*ic);
-
- // check for wrong hits
- if(0){
+ t.NDF() = -5;
+ bool first = 1;
+
+ int iID = iTrack.FirstHitID();
+ for ( int ih = 0; ih < iTrack.NHits(); ih++, iID++ ) {
+ const AliHLTTPCCAHitId &ic = fTrackHits[iID];
+ int iRow = ic.rowIndex();
+ const AliHLTTPCCARow &row = fData.Row( iRow );
+ if ( !t0.TransportToX( row.X() ) ) continue;
+ float dy, dz;
+ const AliHLTTPCCAHit &h = ic.hitIndex();
+
+ // check for wrong hits
+ if ( 0 ) {
dy = t0.GetY() - h.Y();
dz = t0.GetZ() - h.Z();
-
+
//if( dy*dy > 3.5*3.5*(/*t0.GetErr2Y() + */h.ErrY()*h.ErrY() ) ) continue;//SG!!!
- //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;
+ //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;
}
- if( !t.TransportToX( row.X() ) ) continue;
+ if ( !t.TransportToX( row.X() ) ) continue;
//* Update the track
-
- if( first ){
- t.Cov()[ 0] = .5*.5;
+
+ if ( first ) {
+ t.Cov()[ 0] = .5 * .5;
t.Cov()[ 1] = 0;
- t.Cov()[ 2] = .5*.5;
+ t.Cov()[ 2] = .5 * .5;
t.Cov()[ 3] = 0;
t.Cov()[ 4] = 0;
- t.Cov()[ 5] = .2*.2;
+ t.Cov()[ 5] = .2 * .2;
t.Cov()[ 6] = 0;
t.Cov()[ 7] = 0;
t.Cov()[ 8] = 0;
- t.Cov()[ 9] = .2*.2;
+ t.Cov()[ 9] = .2 * .2;
t.Cov()[10] = 0;
t.Cov()[11] = 0;
t.Cov()[12] = 0;
t.Cov()[13] = 0;
- t.Cov()[14] = .2*.2;
+ t.Cov()[14] = .2 * .2;
t.Chi2() = 0;
t.NDF() = -5;
}
- Float_t err2Y, err2Z;
+ float err2Y, err2Z;
GetErrors2( iRow, t, err2Y, err2Z );
- if( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue;
+ if ( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue;
- first = 0;
- }
+ first = 0;
+ }
/*
- Float_t cosPhi = iTrack.Param().GetCosPhi();
+ float cosPhi = iTrack.Param().GetCosPhi();
p0.Param().TransportToX(ID2Row( iTrack.PointID()[0] ).X());
- p2.Param().TransportToX(ID2Row( iTrack.PointID()[1] ).X());
+ p2.Param().TransportToX(ID2Row( iTrack.PointID()[1] ).X());
if( p0.Param().GetCosPhi()*cosPhi<0 ){ // change direction
- Float_t *par = p0.Param().Par();
- Float_t *cov = p0.Param().Cov();
+ float *par = p0.Param().Par();
+ float *cov = p0.Param().Cov();
par[2] = -par[2]; // sin phi
par[3] = -par[3]; // DzDs
par[4] = -par[4]; // kappa
#endif
}
-GPUh() void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &/*track*/, Float_t */*t0[]*/ ) const
-{
- //* Fit the track
+GPUh() void AliHLTTPCCATracker::FitTrack( const AliHLTTPCCATrack &/*track*/, float * /*t0[]*/ ) const
+{
+ //* Fit the track
#ifdef XXX
- AliHLTTPCCAEndPoint &p2 = ID2Point(track.PointID()[1]);
- AliHLTTPCCAHit &c0 = ID2Hit(fTrackHits[p0.TrackHitID()].HitID());
- AliHLTTPCCAHit &c1 = ID2Hit(fTrackHits[track.HitID()[1]].HitID());
- AliHLTTPCCAHit &c2 = ID2Hit(fTrackHits[p2.TrackHitID()].HitID());
- AliHLTTPCCARow &row0 = ID2Row(fTrackHits[p0.TrackHitID()].HitID());
- AliHLTTPCCARow &row1 = ID2Row(fTrackHits[track.HitID()[1]].HitID());
- AliHLTTPCCARow &row2 = ID2Row(fTrackHits[p2.TrackHitID()].HitID());
- Float_t sp0[5] = {row0.X(), c0.Y(), c0.Z(), c0.ErrY(), c0.ErrZ() };
- Float_t sp1[5] = {row1.X(), c1.Y(), c1.Z(), c1.ErrY(), c1.ErrZ() };
- Float_t sp2[5] = {row2.X(), c2.Y(), c2.Z(), c2.ErrY(), c2.ErrZ() };
- //cout<<"Fit track, points ="<<sp0[0]<<" "<<sp0[1]<<" / "<<sp1[0]<<" "<<sp1[1]<<" / "<<sp2[0]<<" "<<sp2[1]<<endl;
- if( track.NHits()>=3 ){
- p0.Param().ConstructXYZ3(sp0,sp1,sp2,p0.Param().CosPhi(), t0);
- p2.Param().ConstructXYZ3(sp2,sp1,sp0,p2.Param().CosPhi(), t0);
+ AliHLTTPCCAEndPoint &p2 = ID2Point( track.PointID()[1] );
+ const AliHLTTPCCAHit &c0 = ID2Hit( fTrackHits[p0.TrackHitID()].HitID() );
+ const AliHLTTPCCAHit &c1 = ID2Hit( fTrackHits[track.HitID()[1]].HitID() );
+ const AliHLTTPCCAHit &c2 = ID2Hit( fTrackHits[p2.TrackHitID()].HitID() );
+ const AliHLTTPCCARow &row0 = ID2Row( fTrackHits[p0.TrackHitID()].HitID() );
+ const AliHLTTPCCARow &row1 = ID2Row( fTrackHits[track.HitID()[1]].HitID() );
+ const AliHLTTPCCARow &row2 = ID2Row( fTrackHits[p2.TrackHitID()].HitID() );
+ float sp0[5] = {row0.X(), c0.Y(), c0.Z(), c0.ErrY(), c0.ErrZ() };
+ float sp1[5] = {row1.X(), c1.Y(), c1.Z(), c1.ErrY(), c1.ErrZ() };
+ float sp2[5] = {row2.X(), c2.Y(), c2.Z(), c2.ErrY(), c2.ErrZ() };
+ //std::cout<<"Fit track, points ="<<sp0[0]<<" "<<sp0[1]<<" / "<<sp1[0]<<" "<<sp1[1]<<" / "<<sp2[0]<<" "<<sp2[1]<<std::endl;
+ if ( track.NHits() >= 3 ) {
+ p0.Param().ConstructXYZ3( sp0, sp1, sp2, p0.Param().CosPhi(), t0 );
+ p2.Param().ConstructXYZ3( sp2, sp1, sp0, p2.Param().CosPhi(), t0 );
//p2.Param() = p0.Param();
//p2.Param().TransportToX(row2.X());
//p2.Param().Par()[1] = -p2.Param().Par()[1];
p0.Param().X() = row0.X();
p0.Param().Y() = c0.Y();
p0.Param().Z() = c0.Z();
- p0.Param().Err2Y() = c0.ErrY()*c0.ErrY();
- p0.Param().Err2Z() = c0.ErrZ()*c0.ErrZ();
+ p0.Param().Err2Y() = c0.ErrY() * c0.ErrY();
+ p0.Param().Err2Z() = c0.ErrZ() * c0.ErrZ();
p2.Param().X() = row2.X();
p2.Param().Y() = c2.Y();
p2.Param().Z() = c2.Z();
- p2.Param().Err2Y() = c2.ErrY()*c2.ErrY();
- p2.Param().Err2Z() = c2.ErrZ()*c2.ErrZ();
+ p2.Param().Err2Y() = c2.ErrY() * c2.ErrY();
+ p2.Param().Err2Z() = c2.ErrZ() * c2.ErrZ();
}
#endif
}
-
-GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, const AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z ) const
+GPUd() void AliHLTTPCCATracker::GetErrors2( int iRow, float z, float sinPhi, float cosPhi, float DzDs, float &Err2Y, float &Err2Z ) const
{
//
// Use calibrated cluster error from OCDB
//
- Float_t z = CAMath::Abs((250.-0.275)-CAMath::Abs(t.GetZ()));
- Int_t type = (iRow<63) ? 0: (iRow>126) ? 1:2;
- Float_t cosPhiInv = CAMath::Abs(t.GetCosPhi())>1.e-2 ?1./t.GetCosPhi() :0;
- Float_t angleY = t.GetSinPhi()*cosPhiInv ;
- Float_t angleZ = t.GetDzDs()*cosPhiInv ;
-
- Err2Y = fParam.GetClusterError2(0,type, z,angleY);
- Err2Z = fParam.GetClusterError2(1,type, z,angleZ);
+ fParam.GetClusterErrors2( iRow, z, sinPhi, cosPhi, DzDs, Err2Y, Err2Z );
+ Err2Y*=fParam.ClusterError2CorrectionY();
+ Err2Z*=fParam.ClusterError2CorrectionZ();
}
-GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, const AliHLTTPCCATrackParam1 &t, Float_t &Err2Y, Float_t &Err2Z ) const
+GPUd() void AliHLTTPCCATracker::GetErrors2( int iRow, const AliHLTTPCCATrackParam &t, float &Err2Y, float &Err2Z ) const
{
//
// Use calibrated cluster error from OCDB
//
- Float_t z = CAMath::Abs((250.-0.275)-CAMath::Abs(t.GetZ()));
- Int_t type = (iRow<63) ? 0: (iRow>126) ? 1:2;
- Float_t cosPhiInv = CAMath::Abs(t.GetCosPhi())>1.e-2 ?1./t.GetCosPhi() :0;
- Float_t angleY = t.GetSinPhi()*cosPhiInv ;
- Float_t angleZ = t.GetDzDs()*cosPhiInv ;
+ fParam.GetClusterErrors2( iRow, t.GetZ(), t.SinPhi(), t.GetCosPhi(), t.DzDs(), Err2Y, Err2Z );
+}
+
+
+#if !defined(HLTCA_GPUCODE)
- Err2Y = fParam.GetClusterError2(0,type, z,angleY);
- Err2Z = fParam.GetClusterError2(1,type, z,angleZ);
+GPUh() void AliHLTTPCCATracker::WriteEvent( std::ostream &out )
+{
+ // write event to the file
+ for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
+ out << fData.Row( iRow ).HitNumberOffset() << " " << fData.Row( iRow ).NHits() << std::endl;
+ }
+ out << NHitsTotal() << std::endl;
+
+ AliHLTResizableArray<float> y( NHitsTotal() ), z( NHitsTotal() );
+
+ for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
+ const AliHLTTPCCARow &row = Row( iRow );
+ float y0 = row.Grid().YMin();
+ float z0 = row.Grid().ZMin();
+ float stepY = row.HstepY();
+ float stepZ = row.HstepZ();
+ for ( int ih = 0; ih < fData.Row( iRow ).NHits(); ih++ ) {
+ int id = HitInputID( row, ih );
+ y[id] = y0 + HitDataY( row, ih ) * stepY;
+ z[id] = z0 + HitDataZ( row, ih ) * stepZ;
+ }
+ }
+ for ( int ih = 0; ih < NHitsTotal(); ih++ ) {
+ out << y[ih] << " " << z[ih] << std::endl;
+ }
+}
+
+GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &out )
+{
+ //* Write tracks to file
+ AliHLTTPCCASliceOutput* useOutput = *fOutput;
+
+ out << fTimers[0] << std::endl;
+ out << useOutput->NOutTrackHits() << std::endl;
+ for ( int ih = 0; ih < useOutput->NOutTrackHits(); ih++ ) {
+ out << useOutput->OutTrackHit(ih) << " ";
+ }
+ out << std::endl;
+
+ out << useOutput->NOutTracks() << std::endl;
+
+ for ( int itr = 0; itr < useOutput->NOutTracks(); itr++ ) {
+ const AliHLTTPCCAOutTrack &t = useOutput->OutTrack(itr);
+ AliHLTTPCCATrackParam p1 = t.StartPoint();
+ AliHLTTPCCATrackParam p2 = t.EndPoint();
+ out << t.NHits() << " ";
+ out << t.FirstHitRef() << " ";
+ out << t.OrigTrackID() << " ";
+ out << std::endl;
+ out << p1.X() << " ";
+ out << p1.SignCosPhi() << " ";
+ out << p1.Chi2() << " ";
+ out << p1.NDF() << std::endl;
+ for ( int i = 0; i < 5; i++ ) out << p1.Par()[i] << " ";
+ out << std::endl;
+ for ( int i = 0; i < 15; i++ ) out << p1.Cov()[i] << " ";
+ out << std::endl;
+ out << p2.X() << " ";
+ out << p2.SignCosPhi() << " ";
+ out << p2.Chi2() << " ";
+ out << p2.NDF() << std::endl;
+ for ( int i = 0; i < 5; i++ ) out << p2.Par()[i] << " ";
+ out << std::endl;
+ for ( int i = 0; i < 15; i++ ) out << p2.Cov()[i] << " ";
+ out << std::endl;
+ }
}
+
+GPUh() void AliHLTTPCCATracker::ReadTracks( std::istream &in )
+{
+ //* Read tracks from file
+ AliHLTTPCCASliceOutput::Allocate(*fOutput, 4096, 16384, fOutputControl);//Just some max values
+ AliHLTTPCCASliceOutput* useOutput = *fOutput;
+
+ int tmpval;
+ in >> fTimers[0];
+ in >> tmpval;
+ useOutput->SetNOutTrackHits(tmpval);
+
+ for ( int ih = 0; ih < useOutput->NOutTrackHits(); ih++ ) {
+ in >> tmpval;
+ useOutput->SetOutTrackHit(ih, tmpval);
+ }
+ in >> tmpval;
+ useOutput->SetNOutTracks(tmpval);
+
+ for ( int itr = 0; itr < useOutput->NOutTracks(); itr++ ) {
+ AliHLTTPCCAOutTrack &t = useOutput->OutTracks()[itr];
+ AliHLTTPCCATrackParam p1, p2;
+ int i;
+ float f;
+ in >> i; t.SetNHits( i );
+ in >> i; t.SetFirstHitRef( i );
+ in >> i; t.SetOrigTrackID( i );
+ in >> f; p1.SetX( f );
+ in >> f; p1.SetSignCosPhi( f );
+ in >> f; p1.SetChi2( f );
+ in >> i; p1.SetNDF( i );
+ for ( int j = 0; j < 5; j++ ) { in >> f; p1.SetPar( j, f ); }
+ for ( int j = 0; j < 15; j++ ) { in >> f; p1.SetCov( j, f ); }
+ in >> f; p2.SetX( f );
+ in >> f; p2.SetSignCosPhi( f );
+ in >> f; p2.SetChi2( f );
+ in >> i; p2.SetNDF( i );
+ for ( int j = 0; j < 5; j++ ) { in >> f; p2.SetPar( j, f ); }
+ for ( int j = 0; j < 15; j++ ) { in >> f; p2.SetCov( j, f ); }
+ t.SetStartPoint( p1 );
+ t.SetEndPoint( p2 );
+ }
+}
+#endif