// @(#) $Id$ // ************************************************************************** // This file is property of and copyright by the ALICE HLT Project * // ALICE Experiment at CERN, All rights reserved. * // * // Primary Authors: Sergey Gorbunov * // Ivan Kisel * // for The ALICE HLT Project. * // * // Permission to use, copy, modify and distribute this software and its * // documentation strictly for non-commercial purposes is hereby granted * // without fee, provided that the above copyright notice appears in all * // copies and that both the copyright notice and this permission notice * // 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 "TStopwatch.h" #include "AliHLTTPCCAHitArea.h" #include "AliHLTTPCCANeighboursFinder.h" #include "AliHLTTPCCANeighboursCleaner.h" #include "AliHLTTPCCAStartHitsFinder.h" #include "AliHLTTPCCATrackletConstructor.h" #include "AliHLTTPCCATrackletSelector.h" #include "AliHLTTPCCAProcess.h" #include "AliHLTTPCCAUsedHitsInitialiser.h" #include "AliHLTTPCCASliceTrack.h" #include "AliHLTTPCCASliceOutput.h" #include "AliHLTTPCCADataCompressor.h" #include "AliHLTTPCCATrackParam.h" #if !defined(HLTCA_GPUCODE) #include #endif //#define DRAW #ifdef DRAW #include "AliHLTTPCCADisplay.h" #endif //DRAW #ifdef HLTCA_INTERNAL_PERFORMANCE #include "AliHLTTPCCAPerformance.h" #endif ClassImp(AliHLTTPCCATracker) #if !defined(HLTCA_GPUCODE) AliHLTTPCCATracker::AliHLTTPCCATracker() : fParam(), fNHitsTotal(0), fCommonMemory(0), fCommonMemorySize(0), fHitMemory(0), fHitMemorySize(0), fTrackMemory(0), fTrackMemorySize(0), fInputEvent(0), fInputEventSize(0), fRowData(0), fRowDataSize(0), fHitInputIDs(0), fHitWeights(0), fNTracklets(0), fTrackletStartHits(0), fTracklets(0), fNTracks(0), fTracks(0), fNTrackHits(0), fTrackHits(0), fOutput(0), fNOutTracks(0), fOutTracks(0), fNOutTrackHits(0), fOutTrackHits(0), fTmpHitInputIDs(0) { // constructor } AliHLTTPCCATracker::AliHLTTPCCATracker( const AliHLTTPCCATracker& ) : fParam(), fNHitsTotal(0), fCommonMemory(0), fCommonMemorySize(0), fHitMemory(0), fHitMemorySize(0), fTrackMemory(0), fTrackMemorySize(0), fInputEvent(0), fInputEventSize(0), fRowData(0), fRowDataSize(0), fHitInputIDs(0), fHitWeights(0), fNTracklets(0), fTrackletStartHits(0), fTracklets(0), fNTracks(0), fTracks(0), fNTrackHits(0), fTrackHits(0), fOutput(0), fNOutTracks(0), fOutTracks(0), fNOutTrackHits(0), fOutTrackHits(0), fTmpHitInputIDs(0) { // dummy } AliHLTTPCCATracker &AliHLTTPCCATracker::operator=( const AliHLTTPCCATracker& ) { // dummy fCommonMemory = 0; fHitMemory = 0; fTrackMemory = 0; return *this; } GPUd() AliHLTTPCCATracker::~AliHLTTPCCATracker() { // destructor if( fCommonMemory ) delete[] fCommonMemory; if( fHitMemory ) delete[] fHitMemory; if( fTrackMemory ) delete[] fTrackMemory; if( fTmpHitInputIDs ) delete[] fTmpHitInputIDs; } #endif // ---------------------------------------------------------------------------------- GPUd() void AliHLTTPCCATracker::Initialize( const AliHLTTPCCAParam ¶m ) { // initialisation fParam = param; fParam.Update(); for( Int_t irow=0; irow ( new uint4 [ fCommonMemorySize/sizeof(uint4) + 100] ); SetPointersCommon();// set pointers } if( fHitMemory ) delete[] fHitMemory; fHitMemory = 0; if( fTrackMemory ) delete[] fTrackMemory; fTrackMemory = 0; fNHitsTotal = 0; *fNTracklets = 0; *fNTracks = 0 ; *fNTrackHits = 0; *fNOutTracks = 0; *fNOutTrackHits = 0; if( fTmpHitInputIDs ) delete[] fTmpHitInputIDs; fTmpHitInputIDs = 0; } GPUhd() void AliHLTTPCCATracker::SetPointersCommon() { // set all pointers to the event memory ULong_t mem = (ULong_t) fCommonMemory; UInt_t sI = sizeof(Int_t); // set common memory fNTracklets = (Int_t*) mem; mem+= sI; fNTracks = (Int_t*) mem; mem+= sI; fNTrackHits = (Int_t*) mem; mem+= sI; fNOutTracks = (Int_t*) mem; mem+= sI; fNOutTrackHits = (Int_t*) mem; mem+= sI; // calculate the size fCommonMemorySize = mem - (ULong_t) fCommonMemory; } GPUhd() void AliHLTTPCCATracker::SetPointersHits( Int_t MaxNHits ) { // set all pointers to the event memory Int_t gridSizeTotal = 2*(2*MaxNHits + 10*Param().NRows()); //gridSizeTotal *=100;//SG!!! ULong_t mem = (ULong_t) fHitMemory; UInt_t sI = sizeof(Int_t); UInt_t sF = sizeof(Float_t); UInt_t sS = sizeof(Short_t); UInt_t s4 = sizeof(uint4); // set input event mem = ( mem/s4 + 1 )*s4; fInputEvent = (Char_t*) mem; fInputEventSize = (1+fParam.NRows()*2 + 1)*sI + (MaxNHits*2)*sF; mem+= fInputEventSize; // set cluster data for TPC rows mem = ( mem/s4 + 1 )*s4; fRowData = (uint4*) mem; fRowDataSize = ( 2*MaxNHits*sS + // yz gridSizeTotal*sS + // grid 2*MaxNHits*sS + // link up,link down fParam.NRows()*s4 // row alignment ); mem += fRowDataSize; // extra arrays for tpc clusters mem = ( mem/sI + 1 )*sI; fHitInputIDs = (Int_t*) mem; mem+= MaxNHits*sI; fTrackletStartHits = (Int_t*) mem; mem+= MaxNHits*sI; fHitWeights = (Int_t*) mem; mem+= MaxNHits*sI; // arrays for track hits fTrackHits = (Int_t*) mem; mem+= 10*MaxNHits*sI;//SG!!! fOutTrackHits = (Int_t*) mem; mem+= 10*MaxNHits*sI; //SG!!! // calculate the size fHitMemorySize = mem - (ULong_t) fHitMemory; } GPUhd() void AliHLTTPCCATracker::SetPointersTracks( Int_t MaxNTracks, Int_t MaxNHits ) { // set all pointers to the tracks memory ULong_t mem = (ULong_t) fTrackMemory; // memory for tracklets mem = ( mem/sizeof(AliHLTTPCCATracklet) + 1 )*sizeof(AliHLTTPCCATracklet); fTracklets = (AliHLTTPCCATracklet *) mem; mem+= MaxNTracks*sizeof(AliHLTTPCCATracklet); // memory for selected tracks mem = ( mem/sizeof(AliHLTTPCCATrack) + 1 )*sizeof(AliHLTTPCCATrack); fTracks = (AliHLTTPCCATrack*) mem; mem+= MaxNTracks*sizeof(AliHLTTPCCATrack); // memory for output mem = ( mem/sizeof(AliHLTTPCCASliceOutput) + 1 )*sizeof(AliHLTTPCCASliceOutput); fOutput = (AliHLTTPCCASliceOutput*) mem; mem+= AliHLTTPCCASliceOutput::EstimateSize(MaxNTracks, MaxNHits); // memory for output tracks mem = ( mem/sizeof(AliHLTTPCCAOutTrack) + 1 )*sizeof(AliHLTTPCCAOutTrack); fOutTracks = (AliHLTTPCCAOutTrack*) mem; mem+= MaxNTracks*sizeof(AliHLTTPCCAOutTrack); // calculate the size fTrackMemorySize = mem - (ULong_t) fTrackMemory; } GPUd() void AliHLTTPCCATracker::ReadEvent( const Int_t *RowFirstHit, const Int_t *RowNHits, const Float_t *Y, const Float_t *Z, Int_t NHits ) { //* Read event StartEvent(); fNHitsTotal = NHits; { SetPointersHits(NHits); // to calculate the size fHitMemory = reinterpret_cast ( new uint4 [ fHitMemorySize/sizeof(uint4) + 100] ); SetPointersHits(NHits); // set pointers for hits *fNTracklets = 0; *fNTracks = 0 ; *fNOutTracks = 0; *fNOutTrackHits = 0; } reinterpret_cast( fInputEvent )[0] = fParam.NRows(); reinterpret_cast( fInputEvent )[1+fParam.NRows()*2] = NHits; Int_t *rowHeaders = reinterpret_cast( fInputEvent ) +1; Float_t *hitsYZ = reinterpret_cast( fInputEvent ) + 1+fParam.NRows()*2+1; for( Int_t iRow=0; iRow( fInputEvent )[1+fParam.NRows()*2] = newRowNHitsTotal; delete[] usedHits; SetupRowData(); } GPUd() void AliHLTTPCCATracker::SetupRowData() { //* Convert input hits, create grids, etc. fNHitsTotal = reinterpret_cast( fInputEvent )[1+fParam.NRows()*2]; Int_t *rowHeaders = reinterpret_cast( fInputEvent ) +1; Float_t *hitsYZ = reinterpret_cast( fInputEvent ) + 1+fParam.NRows()*2+1; for( Int_t iRow=0; iRow y ) yMin = y; if( zMax < z ) zMax = z; if( zMin > z ) zMin = z; } if( nGrid <= 0 ){ yMin = yMax = zMin = zMax = 0; nGrid = 1; } AliHLTTPCCAGrid grid; grid.Create( yMin, yMax, zMin, zMax, nGrid ); Float_t sy = ( CAMath::Abs( grid.StepYInv() ) >1.e-4 ) ?1./grid.StepYInv() :1; Float_t sz = ( CAMath::Abs( grid.StepZInv() ) >1.e-4 ) ?1./grid.StepZInv() :1; //cout<<"grid n = "<=65536 || yy>= 65536 ){ std::cout<<"!!!! hit packing error!!! "<=10*fNHitsTotal ){ std::cout<<"fNOutTrackHits>fNHitsTotal"<= 2 ){ (*fNOutTracks)++; }else { (*fNOutTrackHits) = nOutTrackHitsOld; } } timer.Stop(); fTimers[5]+=timer.CpuTime(); } GPUh() void AliHLTTPCCATracker::FitTrackFull( AliHLTTPCCATrack &/**/, Float_t * /**/ ) const { // fit track with material #ifdef XXX //* Fit the track FitTrack( iTrack, tt0 ); 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 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( !t.TransportToX( row.X() ) ) continue; //* Update the track if( first ){ t.Cov()[ 0] = .5*.5; t.Cov()[ 1] = 0; t.Cov()[ 2] = .5*.5; t.Cov()[ 3] = 0; t.Cov()[ 4] = 0; t.Cov()[ 5] = .2*.2; t.Cov()[ 6] = 0; t.Cov()[ 7] = 0; t.Cov()[ 8] = 0; 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.Chi2() = 0; t.NDF() = -5; } Float_t err2Y, err2Z; GetErrors2( iRow, t, err2Y, err2Z ); if( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue; first = 0; } /* Float_t cosPhi = iTrack.Param().GetCosPhi(); p0.Param().TransportToX(ID2Row( iTrack.PointID()[0] ).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(); par[2] = -par[2]; // sin phi par[3] = -par[3]; // DzDs par[4] = -par[4]; // kappa cov[3] = -cov[3]; cov[4] = -cov[4]; cov[6] = -cov[6]; cov[7] = -cov[7]; cov[10] = -cov[10]; cov[11] = -cov[11]; p0.Param().CosPhi() = -p0.Param().GetCosPhi(); } */ #endif } GPUh() void AliHLTTPCCATracker::FitTrack( AliHLTTPCCATrack &/*track*/, Float_t */*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 ="<=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]; //p2.Param().Par()[4] = -p2.Param().Par()[4]; } else { 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(); 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(); } #endif } GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, Float_t z, Float_t sinPhi, Float_t cosPhi, Float_t DzDs, Float_t &Err2Y, Float_t &Err2Z ) const { // // Use calibrated cluster error from OCDB // fParam.GetClusterErrors2( iRow, z, sinPhi, cosPhi, DzDs, Err2Y, Err2Z ); } GPUd() void AliHLTTPCCATracker::GetErrors2( Int_t iRow, const AliHLTTPCCATrackParam &t, Float_t &Err2Y, Float_t &Err2Z ) const { // // Use calibrated cluster error from OCDB // fParam.GetClusterErrors2( iRow, t.GetZ(), t.SinPhi(), t.CosPhi(), t.DzDs(), Err2Y, Err2Z ); } #if !defined(HLTCA_GPUCODE) GPUh() void AliHLTTPCCATracker::WriteEvent( std::ostream &out ) { // write event to the file for( Int_t iRow=0; iRow(tmpint4); for( Int_t ih=0; ih>rowFirstHit[iRow]>>rowNHits[iRow]; } Int_t nHits; in >> nHits; Float_t y[nHits], z[nHits]; for( Int_t ih=0; ih>y[ih]>>z[ih]; } ReadEvent( rowFirstHit, rowNHits, y, z, nHits ); } GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &out ) { //* Write tracks to file out<>fTimers[0]; in>>*fNOutTrackHits; for( Int_t ih=0; ih<*fNOutTrackHits; ih++ ){ in>>fOutTrackHits[ih]; } in>>*fNOutTracks; for( Int_t itr=0; itr<*fNOutTracks; itr++ ){ AliHLTTPCCAOutTrack &t = fOutTracks[itr]; AliHLTTPCCATrackParam p1, p2; Int_t i; Float_t f; in>> i; t.SetNHits( i ); in>> i; t.SetFirstHitRef( i ); in>> i; t.SetOrigTrackID( i ); in>> f; p1.SetX( f ); in>> f; p1.SetCosPhi( f ); in>> f; p1.SetChi2( f ); in>> i; p1.SetNDF( i ); for( Int_t j=0; j<5; j++ ){ in>>f; p1.SetPar(j,f); } for( Int_t j=0; j<15; j++ ){ in>>f; p1.SetCov(j,f); } in>> f; p2.SetX( f ); in>> f; p2.SetCosPhi( f ); in>> f; p2.SetChi2( f ); in>> i; p2.SetNDF( i ); for( Int_t j=0; j<5; j++ ){ in>>f; p2.SetPar(j,f); } for( Int_t j=0; j<15; j++ ){ in>>f; p2.SetCov(j,f); } t.SetStartPoint( p1 ); t.SetEndPoint( p2 ); } } #endif