LCOV - code coverage report
Current view: top level - HLT/TPCLib/tracking-ca - AliHLTTPCCATracker.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 399 0.3 %
Date: 2016-06-14 17:26:59 Functions: 1 43 2.3 %

          Line data    Source code
       1             : // @(#) $Id$
       2             : // **************************************************************************
       3             : // This file is property of and copyright by the ALICE HLT Project          *
       4             : // ALICE Experiment at CERN, All rights reserved.                           *
       5             : //                                                                          *
       6             : // Primary Authors: Sergey Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de> *
       7             : //                  Ivan Kisel <kisel@kip.uni-heidelberg.de>                *
       8             : //                  for The ALICE HLT Project.                              *
       9             : //                                                                          *
      10             : // Permission to use, copy, modify and distribute this software and its     *
      11             : // documentation strictly for non-commercial purposes is hereby granted     *
      12             : // without fee, provided that the above copyright notice appears in all     *
      13             : // copies and that both the copyright notice and this permission notice     *
      14             : // appear in the supporting documentation. The authors make no claims       *
      15             : // about the suitability of this software for any purpose. It is            *
      16             : // provided "as is" without express or implied warranty.                    *
      17             : //                                                                          *
      18             : //***************************************************************************
      19             : 
      20             : #include "AliHLTTPCCATracker.h"
      21             : #include "AliHLTTPCCARow.h"
      22             : #include "AliHLTTPCCATrack.h"
      23             : #include "AliHLTTPCCATracklet.h"
      24             : #include "AliHLTTPCCAMath.h"
      25             : #include "MemoryAssignmentHelpers.h"
      26             : 
      27             : #include "AliHLTTPCCAHitArea.h"
      28             : #include "AliHLTTPCCANeighboursFinder.h"
      29             : #include "AliHLTTPCCANeighboursCleaner.h"
      30             : #include "AliHLTTPCCAStartHitsFinder.h"
      31             : #include "AliHLTTPCCATrackletConstructor.h"
      32             : #include "AliHLTTPCCATrackletSelector.h"
      33             : #include "AliHLTTPCCAProcess.h"
      34             : #include "AliHLTTPCCAClusterData.h"
      35             : 
      36             : #include "AliHLTTPCCATrackParam.h"
      37             : 
      38             : #include "AliHLTTPCCAGPUConfig.h"
      39             : 
      40             : #if !defined(HLTCA_GPUCODE)
      41             : #include "TStopwatch.h"
      42             : #include <iostream>
      43             : #include <iomanip>
      44             : #include <string.h>
      45             : #include <cmath>
      46             : #endif
      47             : 
      48             : //#define DRAW1
      49             : 
      50             : #ifdef DRAW1
      51             : #include "AliHLTTPCCADisplay.h"
      52             : #endif //DRAW1
      53             : 
      54             : #ifdef HLTCA_INTERNAL_PERFORMANCE
      55             : //#include "AliHLTTPCCAPerformance.h"
      56             : #endif
      57             : 
      58           6 : ClassImp( AliHLTTPCCATracker )
      59             : 
      60             : #if !defined(__OPENCL__) || defined(HLTCA_HOSTCODE)
      61             : 
      62             : #if !defined(HLTCA_GPUCODE)
      63             : 
      64             : AliHLTTPCCATracker::~AliHLTTPCCATracker()
      65           0 : {
      66             :         // destructor
      67           0 :         if (!fIsGPUTracker)
      68             :         {
      69           0 :                 if (fCommonMem) delete fCommonMem;
      70           0 :                 if (fHitMemory) delete[] fHitMemory;
      71           0 :                 if (fTrackletMemory) delete[] fTrackletMemory;
      72           0 :                 if (fTrackMemory) delete[] fTrackMemory;
      73           0 :                 fCommonMem = NULL;
      74           0 :                 fHitMemory = fTrackMemory = NULL;
      75           0 :         }
      76             : #ifdef HLTCA_STANDALONE
      77             :         if (fLinkTmpMemory) delete[] fLinkTmpMemory;
      78             : #endif
      79           0 : }
      80             : 
      81             : // ----------------------------------------------------------------------------------
      82             : void AliHLTTPCCATracker::Initialize( const AliHLTTPCCAParam &param )
      83             : {
      84             :         // initialisation
      85           0 :         fParam = param;
      86           0 :         fParam.Update();
      87           0 :         fData.InitializeRows( fParam );
      88             : 
      89           0 :         StartEvent();
      90           0 : }
      91             : 
      92             : void AliHLTTPCCATracker::StartEvent()
      93             : {
      94             :         // start new event and fresh the memory
      95             : 
      96           0 :         SetupCommonMemory();
      97           0 : }
      98             : 
      99             : void AliHLTTPCCATracker::SetGPUTracker()
     100             : {
     101             :         //Make this a GPU Tracker
     102           0 :         fIsGPUTracker = true;
     103           0 :         fData.SetGpuSliceData();
     104           0 : }
     105             : 
     106             : char* AliHLTTPCCATracker::SetGPUTrackerCommonMemory(char* const pGPUMemory)
     107             : {
     108             :         //Set up common Memory Pointer for GPU Tracker
     109           0 :         fCommonMem = (commonMemoryStruct*) pGPUMemory;
     110           0 :         return(pGPUMemory + sizeof(commonMemoryStruct));
     111             : }
     112             : 
     113             : 
     114             : char* AliHLTTPCCATracker::SetGPUTrackerHitsMemory(char* pGPUMemory, int MaxNHits)
     115             : {
     116             :         //Set up Hits Memory Pointers for GPU Tracker
     117           0 :         fHitMemory = (char*) pGPUMemory;
     118           0 :         SetPointersHits(MaxNHits);
     119           0 :         pGPUMemory += fHitMemorySize;
     120           0 :         AssignMemory(fTrackletTmpStartHits, pGPUMemory, NHitsTotal());
     121           0 :         AssignMemory(fRowStartHitCountOffset, pGPUMemory, Param().NRows());
     122             : 
     123           0 :         return(pGPUMemory);
     124             : }
     125             : 
     126             : char* AliHLTTPCCATracker::SetGPUTrackerTrackletsMemory(char* pGPUMemory, int MaxNTracks, int 
     127             : #ifndef HLTCA_GPU_ALTERNATIVE_SCHEDULER
     128             : constructorBlockCount
     129             : #endif
     130             : )
     131             : {
     132             :         //Set up Tracklet Memory Pointers for GPU Tracker
     133           0 :         fTrackletMemory = (char*) pGPUMemory;
     134           0 :         SetPointersTracklets(MaxNTracks);
     135           0 :         pGPUMemory += fTrackletMemorySize;
     136             : #ifndef HLTCA_GPU_ALTERNATIVE_SCHEDULER
     137             :         AssignMemory(fGPUTrackletTemp, pGPUMemory, MaxNTracks);
     138             :         AssignMemory(fRowBlockTracklets, pGPUMemory, MaxNTracks * 2 * (Param().NRows() / HLTCA_GPU_SCHED_ROW_STEP + 1));
     139             :         AssignMemory(fRowBlockPos, pGPUMemory, 2 * (Param().NRows() / HLTCA_GPU_SCHED_ROW_STEP + 1));
     140             :         AssignMemory(fBlockStartingTracklet, pGPUMemory, constructorBlockCount);
     141             : #endif
     142             : 
     143           0 :         return(pGPUMemory);
     144             : }
     145             : 
     146             : char* AliHLTTPCCATracker::SetGPUTrackerTracksMemory(char* pGPUMemory, int MaxNTracks, int MaxNHits )
     147             : {
     148             :         //Set up Tracks Memory Pointer for GPU Tracker
     149           0 :         fTrackMemory = (char*) pGPUMemory;
     150           0 :         SetPointersTracks(MaxNTracks, MaxNHits);
     151           0 :         pGPUMemory += fTrackMemorySize;
     152             : 
     153           0 :         return(pGPUMemory);
     154             : }
     155             : 
     156             : void AliHLTTPCCATracker::DumpOutput(FILE* out)
     157             : {
     158           0 :         fprintf(out, "Slice %d\n", fParam.ISlice());
     159           0 :         const AliHLTTPCCASliceOutTrack* track = (*(Output()))->GetFirstTrack();
     160           0 :         for (int j = 0;j < (*(Output()))->NTracks();j++)
     161             :         {
     162           0 :                 fprintf(out, "Track %d (%d): ", j, track->NClusters());
     163           0 :                 for (int k = 0;k < track->NClusters();k++)
     164             :                 {
     165           0 :                         fprintf(out, "(%2.3f,%2.3f,%2.4f) ", track->Cluster(k).GetX(), track->Cluster(k).GetY(), track->Cluster(k).GetZ());
     166             :                 }
     167           0 :                 fprintf(out, " - (%8.5f %8.5f %8.5f %8.5f %8.5f)", track->Param().Y(), track->Param().Z(), track->Param().SinPhi(), track->Param().DzDs(), track->Param().QPt());
     168           0 :                 fprintf(out, "\n");
     169           0 :                 track = track->GetNextTrack();
     170             :         }
     171           0 : }
     172             : 
     173             : void AliHLTTPCCATracker::DumpSliceData(std::ostream &out)
     174             : {
     175             :         //Dump Slice Input Data to File
     176           0 :         out << "Slice Data (Slice" << Param().ISlice() << "):" << std::endl;
     177           0 :         for (int i = 0;i < Param().NRows();i++)
     178             :         {
     179           0 :                 if (Row(i).NHits() == 0) continue;
     180           0 :                 out << "Row: " << i << std::endl;
     181           0 :                 for (int j = 0;j < Row(i).NHits();j++)
     182             :                 {
     183           0 :                         if (j && j % 16 == 0) out << std::endl;
     184           0 :                         out << j << '-' << Data().HitDataY(Row(i), j) << '-' << Data().HitDataZ(Row(i), j) << ", ";
     185             :                 }
     186           0 :                 out << std::endl;
     187           0 :         }
     188           0 : }
     189             : 
     190             : void AliHLTTPCCATracker::DumpLinks(std::ostream &out)
     191             : {
     192             :         //Dump Links (after Neighbours Finder / Cleaner) to file
     193           0 :         out << "Hit Links(Slice" << Param().ISlice() << "):" << std::endl;
     194           0 :         for (int i = 0;i < Param().NRows();i++)
     195             :         {
     196           0 :                 if (Row(i).NHits() == 0) continue;
     197           0 :                 out << "Row: " << i << std::endl;
     198           0 :                 for (int j = 0;j < Row(i).NHits();j++)
     199             :                 {
     200           0 :                         if (j && j % 32 == 0) out << std::endl;
     201           0 :                         out << HitLinkUpData(Row(i), j) << "/" << HitLinkDownData(Row(i), j) << ", ";
     202             :                 }
     203           0 :                 out << std::endl;
     204           0 :         }
     205           0 : }
     206             : 
     207             : void AliHLTTPCCATracker::DumpHitWeights(std::ostream &out)
     208             : {
     209             :         //dump hit weights to file
     210           0 :         out << "Hit Weights(Slice" << Param().ISlice() << "):" << std::endl;
     211           0 :         for (int i = 0;i < Param().NRows();i++)
     212             :         {
     213           0 :                 if (Row(i).NHits() == 0) continue;
     214           0 :                 out << "Row: " << i << ":" << std::endl;
     215           0 :                 for (int j = 0;j < Row(i).NHits();j++)
     216             :                 {
     217           0 :                         if (j && j % 32 == 0) out << std::endl;
     218           0 :                         out << HitWeight(Row(i), j) << ", ";
     219             :                 }
     220           0 :                 out << std::endl;
     221           0 :         }
     222           0 : }
     223             : 
     224             : int AliHLTTPCCATracker::StarthitSortComparison(const void*a, const void* b)
     225             : {
     226             :         //qsort helper function to sort start hits
     227           0 :         AliHLTTPCCAHitId* aa = (AliHLTTPCCAHitId*) a;
     228           0 :         AliHLTTPCCAHitId* bb = (AliHLTTPCCAHitId*) b;
     229             : 
     230           0 :         if (aa->RowIndex() != bb->RowIndex()) return(aa->RowIndex() - bb->RowIndex());
     231           0 :         return(aa->HitIndex() - bb->HitIndex());
     232           0 : }
     233             : 
     234             : void AliHLTTPCCATracker::DumpStartHits(std::ostream &out)
     235             : {
     236             :         //sort start hits and dump to file
     237           0 :         out << "Start Hits: (Slice" << Param().ISlice() << ") (" << *NTracklets() << ")" << std::endl;
     238             : #ifdef HLTCA_GPU_SORT_DUMPDATA
     239           0 :         qsort(TrackletStartHits(), *NTracklets(), sizeof(AliHLTTPCCAHitId), StarthitSortComparison);
     240             : #endif
     241           0 :         for (int i = 0;i < *NTracklets();i++)
     242             :         {
     243           0 :                 out << TrackletStartHit(i).RowIndex() << "-" << TrackletStartHit(i).HitIndex() << std::endl;
     244             :         }
     245           0 :         out << std::endl;
     246           0 : }
     247             : 
     248             : void AliHLTTPCCATracker::DumpTrackHits(std::ostream &out)
     249             : {
     250             :         //dump tracks to file
     251           0 :         out << "Tracks: (Slice" << Param().ISlice() << ") (" << *NTracks() << ")" << std::endl;
     252             : #ifdef HLTCA_GPU_SORT_DUMPDATA
     253           0 :         for (int k = 0;k < Param().NRows();k++)
     254             :         {
     255           0 :                 for (int l = 0;l < Row(k).NHits();l++)
     256             :                 {
     257             : #endif
     258           0 :                         for (int j = 0;j < *NTracks();j++)
     259             :                         {
     260           0 :                                 if (Tracks()[j].NHits() == 0 || !Tracks()[j].Alive()) continue;
     261             : #ifdef HLTCA_GPU_SORT_DUMPDATA
     262           0 :                                 if (TrackHits()[Tracks()[j].FirstHitID()].RowIndex() == k && TrackHits()[Tracks()[j].FirstHitID()].HitIndex() == l)
     263             :                                 {
     264             : #endif
     265           0 :                                         for (int i = 0;i < Tracks()[j].NHits();i++)
     266             :                                         {
     267           0 :                                                 out << TrackHits()[Tracks()[j].FirstHitID() + i].RowIndex() << "-" << TrackHits()[Tracks()[j].FirstHitID() + i].HitIndex() << ", ";
     268             :                                         }
     269             : #ifndef BITWISE_COMPATIBLE_DEBUG_OUTPUT
     270             :                                         out << "(Track: " << j << ")";
     271             : #endif
     272           0 :                                         out << std::endl;
     273             : #ifdef HLTCA_GPU_SORT_DUMPDATA
     274           0 :                                 }
     275             :                         }       
     276             : #endif
     277             :                 }       
     278             : #ifdef HLTCA_GPU_SORT_DUMPDATA
     279             :         }
     280             : #endif
     281           0 : }
     282             : 
     283             : void AliHLTTPCCATracker::DumpTrackletHits(std::ostream &out)
     284             : {
     285             :         //dump tracklets to file
     286           0 :         int nTracklets = *NTracklets();
     287           0 :         if( nTracklets<0 ) nTracklets = 0;
     288           0 :         if( nTracklets>HLTCA_GPU_MAX_TRACKLETS ) nTracklets = HLTCA_GPU_MAX_TRACKLETS;
     289           0 :         out << "Tracklets: (Slice" << Param().ISlice() << ") (" << nTracklets << ")" << std::endl;
     290             : #ifdef HLTCA_GPU_SORT_DUMPDATA
     291           0 :         AliHLTTPCCAHitId* tmpIds = new AliHLTTPCCAHitId[nTracklets];
     292           0 :         AliHLTTPCCATracklet* tmpTracklets = new AliHLTTPCCATracklet[nTracklets];
     293           0 :         memcpy(tmpIds, TrackletStartHits(), nTracklets * sizeof(AliHLTTPCCAHitId));
     294           0 :         memcpy(tmpTracklets, Tracklets(), nTracklets * sizeof(AliHLTTPCCATracklet));
     295             : #ifdef EXTERN_ROW_HITS
     296           0 :         int* tmpHits = new int[nTracklets * Param().NRows()];
     297           0 :         memcpy(tmpHits, TrackletRowHits(), nTracklets * Param().NRows() * sizeof(int));
     298             : #endif
     299           0 :         qsort(TrackletStartHits(), nTracklets, sizeof(AliHLTTPCCAHitId), StarthitSortComparison);
     300           0 :         for (int i = 0;i < nTracklets; i++ ){
     301           0 :                 for (int j = 0;j < nTracklets; j++ ){
     302           0 :                         if (tmpIds[i].RowIndex() == TrackletStartHit(j).RowIndex() && tmpIds[i].HitIndex() == TrackletStartHit(j).HitIndex() ){
     303           0 :                                 memcpy(&Tracklets()[j], &tmpTracklets[i], sizeof(AliHLTTPCCATracklet));
     304             : #ifdef EXTERN_ROW_HITS
     305           0 :                                 if (tmpTracklets[i].NHits() ){
     306           0 :                                         for (int k = tmpTracklets[i].FirstRow();k <= tmpTracklets[i].LastRow();k++){
     307           0 :                                                 const int pos = k * nTracklets + j;
     308           0 :                                                 if (pos < 0 || pos >= HLTCA_GPU_MAX_TRACKLETS * fParam.NRows()){
     309           0 :                                                         printf("internal error\n");         
     310           0 :                                                 } else {
     311           0 :                                                         fTrackletRowHits[pos] = tmpHits[k * nTracklets + i];
     312             :                                                 }
     313             :                                         }
     314           0 :                                 }
     315             : #endif
     316           0 :                                 break;
     317             :                         }
     318             :                 }
     319             :         }
     320           0 :         delete[] tmpIds;
     321           0 :         delete[] tmpTracklets;
     322             : #ifdef EXTERN_ROW_HITS
     323           0 :         delete[] tmpHits;
     324             : #endif
     325             : #endif
     326           0 :         for (int j = 0;j < nTracklets; j++ )
     327             :         {
     328           0 :                 out << "Tracklet " << std::setw(4) << j << " (Hits: " << std::setw(3) << Tracklets()[j].NHits() << ", Start: " << std::setw(3) << TrackletStartHit(j).RowIndex() << "-" << std::setw(3) << TrackletStartHit(j).HitIndex() << ", Rows: " << (Tracklets()[j].NHits() ? Tracklets()[j].FirstRow() : -1) << " - " << (Tracklets()[j].NHits() ? Tracklets()[j].LastRow() : -1) << ") ";
     329           0 :                 if (Tracklets()[j].NHits() == 0);
     330           0 :                 else if (Tracklets()[j].LastRow() > Tracklets()[j].FirstRow() && (Tracklets()[j].FirstRow() >= Param().NRows() || Tracklets()[j].LastRow() >= Param().NRows()))
     331             :                 {
     332             : #ifdef HLTCA_STANDALONE
     333             :                         printf("\nError: Tracklet %d First %d Last %d Hits %d", j, Tracklets()[j].FirstRow(), Tracklets()[j].LastRow(), Tracklets()[j].NHits());
     334             :                         out << " (Error: Tracklet " << j << " First " << Tracklets()[j].FirstRow() << " Last " << Tracklets()[j].LastRow() << " Hits " << Tracklets()[j].NHits() << ") ";
     335             :                         for (int i = 0;i < Param().NRows();i++)
     336             :                         {
     337             :                                 //if (Tracklets()[j].RowHit(i) != -1)
     338             : #ifdef EXTERN_ROW_HITS
     339             :                                 out << i << "-" << fTrackletRowHits[i * fCommonMem->fNTracklets + j] << ", ";
     340             : #else
     341             :                                 out << i << "-" << Tracklets()[j].RowHit(i) << ", ";
     342             : #endif
     343             :                         }
     344             : #endif
     345             :                 }
     346           0 :                 else if (Tracklets()[j].NHits() && Tracklets()[j].LastRow() > Tracklets()[j].FirstRow())
     347             :                 {
     348             :                         int nHits = 0;;
     349           0 :                         for (int i = Tracklets()[j].FirstRow();i <= Tracklets()[j].LastRow();i++)
     350             :                         {
     351             : #ifdef EXTERN_ROW_HITS
     352           0 :                                 if (fTrackletRowHits[i * fCommonMem->fNTracklets + j] != -1)
     353             : #else
     354             :                                 if (Tracklets()[j].RowHit(i) != -1)
     355             : #endif
     356             :                                 {
     357           0 :                                         nHits++;
     358           0 :                                 }
     359             : #ifdef EXTERN_ROW_HITS
     360           0 :                                 out << i << "-" << fTrackletRowHits[i * fCommonMem->fNTracklets + j] << ", ";
     361             : #else
     362             :                                 out << i << "-" << Tracklets()[j].RowHit(i) << ", ";
     363             : #endif
     364             :                         }
     365           0 :                         if (nHits != Tracklets()[j].NHits())
     366             :                         {
     367           0 :                                 out << std::endl << "Wrong NHits!: Expected " << Tracklets()[j].NHits() << ", fount " << nHits;
     368           0 :                         }
     369           0 :                 }
     370           0 :                 out << std::endl;
     371             :         }
     372           0 : }
     373             : 
     374             : 
     375             : void AliHLTTPCCATracker::SetupCommonMemory()
     376             : {
     377             :         // set up common memory
     378             : 
     379           0 :         if (!fIsGPUTracker)
     380             :         {
     381           0 :                 if ( !fCommonMem ) {
     382             :                         // the 1600 extra bytes are not used unless fCommonMemorySize increases with a later event
     383             :                         //fCommonMemory = reinterpret_cast<char*> ( new uint4 [ fCommonMemorySize/sizeof( uint4 ) + 100] );
     384           0 :                         fCommonMem = new commonMemoryStruct;
     385           0 :                 }
     386             : 
     387           0 :                 if (fHitMemory) delete[] fHitMemory;
     388           0 :                 if (fTrackletMemory) delete[] fTrackletMemory;
     389           0 :                 if (fTrackMemory) delete[] fTrackMemory;
     390             :         }
     391             : 
     392           0 :         fHitMemory = fTrackletMemory = fTrackMemory = 0;
     393             : 
     394           0 :         fData.Clear();
     395           0 :         fCommonMem->fNTracklets = 0;
     396           0 :         fCommonMem->fNTracks = 0 ;
     397           0 :         fCommonMem->fNTrackHits = 0;
     398           0 : }
     399             : 
     400             : void AliHLTTPCCATracker::ReadEvent( AliHLTTPCCAClusterData *clusterData )
     401             : {
     402             :         // read event
     403             : 
     404           0 :         fClusterData = clusterData;
     405             : 
     406           0 :         StartEvent();
     407             : 
     408             :         //* Convert input hits, create grids, etc.
     409           0 :         fData.InitFromClusterData( *clusterData );
     410             :         {
     411           0 :                 if (!fIsGPUTracker)
     412             :                 {
     413           0 :                         SetPointersHits( fData.NumberOfHits() ); // to calculate the size
     414           0 :                         fHitMemory = reinterpret_cast<char*> ( new uint4 [ fHitMemorySize/sizeof( uint4 ) + 100] );
     415           0 :                 }
     416           0 :                 SetPointersHits( fData.NumberOfHits() ); // set pointers for hits
     417             :         }
     418           0 : }
     419             : 
     420             : GPUhd() void  AliHLTTPCCATracker::SetPointersHits( int MaxNHits )
     421             : {
     422             :         // set all pointers to the event memory
     423             : 
     424           0 :         char *mem = fHitMemory;
     425             : 
     426             :         // extra arrays for tpc clusters
     427             : 
     428             : #ifdef HLTCA_GPU_SORT_STARTHITS_2
     429             :         AssignMemory( fTrackletStartHits, mem, MaxNHits + 32);
     430             : #else
     431           0 :         AssignMemory( fTrackletStartHits, mem, MaxNHits);
     432             : #endif
     433             : 
     434             :         // calculate the size
     435             : 
     436           0 :         fHitMemorySize = mem - fHitMemory;
     437           0 : }
     438             : 
     439             : GPUhd() void  AliHLTTPCCATracker::SetPointersTracklets( int MaxNTracklets )
     440             : {
     441             :         // set all pointers to the tracklets memory
     442           0 :         char *mem = fTrackletMemory;
     443             : 
     444             :         // memory for tracklets
     445             : 
     446           0 :         AssignMemory( fTracklets, mem, MaxNTracklets );
     447             : #ifdef EXTERN_ROW_HITS
     448           0 :         AssignMemory( fTrackletRowHits, mem, MaxNTracklets * Param().NRows());
     449             : #endif
     450             : 
     451           0 :         fTrackletMemorySize = mem - fTrackletMemory;
     452           0 : }
     453             : 
     454             : 
     455             : GPUhd() void  AliHLTTPCCATracker::SetPointersTracks( int MaxNTracks, int MaxNHits )
     456             : {
     457             :         // set all pointers to the tracks memory
     458           0 :         char *mem = fTrackMemory;
     459             : 
     460             :         // memory for selected tracks
     461             : 
     462           0 :         AssignMemory( fTracks, mem, MaxNTracks );
     463           0 :         AssignMemory( fTrackHits, mem, 2 * MaxNHits );
     464             : 
     465             :         // calculate the size
     466             : 
     467           0 :         fTrackMemorySize = mem - fTrackMemory;
     468           0 : }
     469             : 
     470             : GPUh() int AliHLTTPCCATracker::CheckEmptySlice() const
     471             : {
     472             :         //Check if the Slice is empty, if so set the output apropriate and tell the reconstuct procesdure to terminate
     473           0 :         if ( NHitsTotal() < 1 ) {
     474             :                 {
     475           0 :                         AliHLTTPCCASliceOutput::Allocate(*fOutput, 0, 0, fOutputControl);
     476           0 :                         AliHLTTPCCASliceOutput* useOutput = *fOutput;
     477           0 :                         if (useOutput == NULL) return(1);
     478           0 :                         useOutput->SetNTracks( 0 );
     479           0 :                         useOutput->SetNTrackClusters( 0 );
     480           0 :                 }
     481             : 
     482           0 :                 return 1;
     483             :         }
     484           0 :         return 0;
     485           0 : }
     486             : 
     487             : void AliHLTTPCCATracker::RunNeighboursFinder()
     488             : {
     489             :         //Run the CPU Neighbours Finder
     490           0 :         AliHLTTPCCAProcess<AliHLTTPCCANeighboursFinder>( Param().NRows(), 1, *this );
     491           0 : }
     492             : 
     493             : void AliHLTTPCCATracker::RunNeighboursCleaner()
     494             : {
     495             :         //Run the CPU Neighbours Cleaner
     496           0 :         AliHLTTPCCAProcess<AliHLTTPCCANeighboursCleaner>( Param().NRows() - 2, 1, *this );
     497           0 : }
     498             : 
     499             : void AliHLTTPCCATracker::RunStartHitsFinder()
     500             : {
     501             :         //Run the CPU Start Hits Finder
     502           0 :         AliHLTTPCCAProcess<AliHLTTPCCAStartHitsFinder>( Param().NRows() - 4, 1, *this );
     503           0 : }
     504             : 
     505             : void AliHLTTPCCATracker::RunTrackletConstructor()
     506             : {
     507             :         //Run CPU Tracklet Constructor
     508           0 :         AliHLTTPCCATrackletConstructor::AliHLTTPCCATrackletConstructorCPU(*this);
     509           0 : }
     510             : 
     511             : void AliHLTTPCCATracker::RunTrackletSelector()
     512             : {
     513             :         //Run CPU Tracklet Selector
     514           0 :         AliHLTTPCCAProcess<AliHLTTPCCATrackletSelector>( 1, fCommonMem->fNTracklets, *this );
     515           0 : }
     516             : 
     517             : #ifdef HLTCA_STANDALONE
     518             : void AliHLTTPCCATracker::StandalonePerfTime(int i)
     519             : {
     520             :         //Query Performance Timer for Standalone Version of Tracker
     521             :         if (fGPUDebugLevel >= 1)
     522             :         {
     523             :                 StandaloneQueryTime(&fPerfTimers[i]);
     524             :         }
     525             : }
     526             : #else
     527           0 : void AliHLTTPCCATracker::StandalonePerfTime(int /*i*/) {}
     528             : #endif
     529             : 
     530             : GPUh() void AliHLTTPCCATracker::DoTracking()
     531             : {
     532           0 :         fCommonMem->fNTracklets = fCommonMem->fNTracks = fCommonMem->fNTrackHits = 0;
     533             : 
     534           0 :         if (fGPUDebugLevel >= 6)
     535             :         {
     536             : #ifndef BITWISE_COMPATIBLE_DEBUG_OUTPUT
     537             :                 *fGPUDebugOut << std::endl << std::endl << "Slice: " << Param().ISlice() << std::endl;
     538             :                 *fGPUDebugOut << "Slice Data:" << std::endl;
     539             : #endif
     540           0 :                 DumpSliceData(*fGPUDebugOut);
     541           0 :         }
     542             : 
     543           0 :         StandalonePerfTime(1);
     544             : 
     545           0 :         RunNeighboursFinder();
     546             : 
     547           0 :         StandalonePerfTime(2);
     548             : 
     549             : #ifdef TRACKER_KEEP_TEMPDATA
     550             :         if (fLinkTmpMemory) delete[] fLinkTmpMemory;
     551             :         fLinkTmpMemory = new char[fData.MemorySize()];
     552             :         memcpy(fLinkTmpMemory, fData.Memory(), fData.MemorySize());
     553             : #endif
     554             : 
     555           0 :         if (fGPUDebugLevel >= 6) DumpLinks(*fGPUDebugOut);
     556             : 
     557             : #ifdef HLTCA_INTERNAL_PERFORMANCE
     558             :         //if( Param().ISlice()<=2 )
     559             :         //AliHLTTPCCAPerformance::Instance().LinkPerformance( Param().ISlice() );
     560             : #endif
     561             : 
     562             : 
     563             : #ifdef DRAW1
     564             :         if ( NHitsTotal() > 0 ) {
     565             :                 AliHLTTPCCADisplay::Instance().DrawSliceLinks( -1, -1, 1 );
     566             :                 AliHLTTPCCADisplay::Instance().Ask();
     567             :         }
     568             : #endif //DRAW1
     569             : 
     570           0 :         RunNeighboursCleaner();
     571             : 
     572           0 :         StandalonePerfTime(3);
     573             : 
     574           0 :         if (fGPUDebugLevel >= 6) DumpLinks(*fGPUDebugOut);
     575             : 
     576           0 :         RunStartHitsFinder();
     577             : 
     578           0 :         StandalonePerfTime(4);
     579           0 :         StandalonePerfTime(5);
     580             : 
     581           0 :         if (fGPUDebugLevel >= 6) DumpStartHits(*fGPUDebugOut);
     582             : 
     583           0 :         fData.ClearHitWeights();
     584             : 
     585           0 :         if (!fIsGPUTracker)
     586             :         {
     587           0 :                 SetPointersTracklets( fCommonMem->fNTracklets * 2 ); // to calculate the size
     588           0 :                 fTrackletMemory = reinterpret_cast<char*> ( new uint4 [ fTrackletMemorySize/sizeof( uint4 ) + 100] );
     589           0 :                 SetPointersTracks( fCommonMem->fNTracklets * 2, NHitsTotal() ); // to calculate the size
     590           0 :                 fTrackMemory = reinterpret_cast<char*> ( new uint4 [ fTrackMemorySize/sizeof( uint4 ) + 100] );
     591           0 :         }
     592             : 
     593           0 :         SetPointersTracklets( fCommonMem->fNTracklets * 2 ); // set pointers for hits
     594           0 :         SetPointersTracks( fCommonMem->fNTracklets * 2, NHitsTotal() ); // set pointers for hits
     595             : 
     596           0 :         StandalonePerfTime(6);
     597           0 :         StandalonePerfTime(7);
     598             : 
     599           0 :         RunTrackletConstructor();
     600             : 
     601           0 :         StandalonePerfTime(8);
     602             : 
     603           0 :         if (fGPUDebugLevel >= 6) DumpTrackletHits(*fGPUDebugOut);
     604             : #ifndef BITWISE_COMPATIBLE_DEBUG_OUTPUT
     605             :         if (fGPUDebugLevel >= 6) DumpHitWeights(*fGPUDebugOut);
     606             : #endif
     607             : 
     608             :         //std::cout<<"Slice "<<Param().ISlice()<<": NHits="<<NHitsTotal()<<", NTracklets="<<*NTracklets()<<std::endl;
     609             : 
     610           0 :         RunTrackletSelector();
     611             : 
     612           0 :         StandalonePerfTime(9);
     613             : 
     614             :         //std::cout<<"Slice "<<Param().ISlice()<<": N start hits/tracklets/tracks = "<<nStartHits<<" "<<nStartHits<<" "<<*fNTracks<<std::endl;
     615             : 
     616           0 :         if (fGPUDebugLevel >= 6) DumpTrackHits(*fGPUDebugOut);
     617             : 
     618             :         //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;
     619           0 : }
     620             : 
     621             : GPUh() void AliHLTTPCCATracker::Reconstruct()
     622             : {
     623             :         //* reconstruction of event
     624             :         //std::cout<<"Reconstruct slice "<<fParam.ISlice()<<", nHits="<<NHitsTotal()<<std::endl;
     625             : 
     626           0 :         fTimers[0] = 0; // find neighbours
     627           0 :         fTimers[1] = 0; // construct tracklets
     628           0 :         fTimers[2] = 0; // fit tracklets
     629           0 :         fTimers[3] = 0; // prolongation of tracklets
     630           0 :         fTimers[4] = 0; // selection
     631           0 :         fTimers[5] = 0; // write output
     632           0 :         fTimers[6] = 0;
     633           0 :         fTimers[7] = 0;
     634             : 
     635             :         //if( fParam.ISlice()<1 ) return; //SG!!!
     636             : 
     637           0 :         TStopwatch timer0;
     638             : 
     639           0 :         if (CheckEmptySlice()) return;
     640             : 
     641             : #ifdef DRAW1
     642             :         //if( fParam.ISlice()==2 || fParam.ISlice()==3)
     643             :         {
     644             :                 AliHLTTPCCADisplay::Instance().ClearView();
     645             :                 AliHLTTPCCADisplay::Instance().SetSliceView();
     646             :                 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
     647             :                 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
     648             :                 if ( NHitsTotal() > 0 ) {
     649             :                         AliHLTTPCCADisplay::Instance().DrawSliceHits( kRed, .5 );
     650             :                         AliHLTTPCCADisplay::Instance().Ask();
     651             :                 }
     652             :         }
     653             : #endif //DRAW1
     654             : 
     655           0 :         DoTracking();
     656           0 :         fTimers[0] = timer0.CpuTime() / 100.;
     657           0 : }
     658             : 
     659             : GPUh() void AliHLTTPCCATracker::ReconstructOutput()
     660             : {
     661           0 :         TStopwatch timer0;
     662           0 :         WriteOutputPrepare();
     663           0 :         WriteOutput();
     664             : 
     665           0 :         StandalonePerfTime(10);
     666             : 
     667             : #ifdef DRAW1
     668             :         {
     669             :                 AliHLTTPCCADisplay &disp = AliHLTTPCCADisplay::Instance();
     670             :                 AliHLTTPCCATracker &slice = *this;
     671             :                 std::cout << "N out tracks = " << slice.NOutTracks() << std::endl;
     672             :                 AliHLTTPCCADisplay::Instance().SetSliceView();
     673             :                 AliHLTTPCCADisplay::Instance().SetCurrentSlice( this );
     674             :                 AliHLTTPCCADisplay::Instance().DrawSlice( this, 1 );
     675             :                 disp.DrawSliceHits( kRed, .5 );
     676             :                 disp.Ask();
     677             :                 for ( int itr = 0; itr < slice.NOutTracks(); itr++ ) {
     678             :                         std::cout << "track N " << itr << ", nhits=" << slice.OutTracks()[itr].NHits() << std::endl;
     679             :                         disp.DrawSliceOutTrack( itr, kBlue );      
     680             :                         //disp.Ask();
     681             :                         //int id = slice.OutTracks()[itr].OrigTrackID();
     682             :                         //AliHLTTPCCATrack &tr = Tracks()[id];
     683             :                         //for( int ih=0; ih<tr.NHits(); ih++ ){
     684             :                         //int ic = (fTrackHits[tr.FirstHitID()+ih]);
     685             :                         //std::cout<<ih<<" "<<ID2IRow(ic)<<" "<<ID2IHit(ic)<<std::endl;
     686             :                         //}
     687             :                         //disp.DrawSliceTrack( id, kBlue );
     688             :                         //disp.Ask();
     689             :                 }
     690             :                 disp.Ask();
     691             :         }
     692             : #endif //DRAW1
     693             : 
     694           0 :         timer0.Stop();
     695           0 :         fTimers[0] += timer0.CpuTime() / 100.;
     696           0 : }
     697             : 
     698             : GPUh() void AliHLTTPCCATracker::WriteOutputPrepare()
     699             : {
     700           0 :         if (fOutputControl == NULL) fOutputControl = new AliHLTTPCCASliceOutput::outputControlStruct;
     701           0 :         AliHLTTPCCASliceOutput::Allocate(*fOutput, fCommonMem->fNTracks, fCommonMem->fNTrackHits, fOutputControl);
     702           0 : }
     703             : 
     704             : GPUh() int AliHLTTPCCATracker::SortComparison(const void* a, const void* b)
     705             : {
     706           0 :         return(((trackSortData*) a)->fSortVal < ((trackSortData*) b)->fSortVal ? 1 : -1);
     707             : }
     708             : 
     709             : GPUh() void AliHLTTPCCATracker::WriteOutput()
     710             : {
     711             :         // write output
     712           0 :         AliHLTTPCCASliceOutput* useOutput = *fOutput;
     713             : 
     714           0 :         TStopwatch timer;
     715             : 
     716             :         //cout<<"output: nTracks = "<<*fNTracks<<", nHitsTotal="<<NHitsTotal()<<std::endl;
     717             : 
     718           0 :         if (useOutput == NULL) return;
     719             : 
     720           0 :         useOutput->SetNTracks( 0 );
     721           0 :         useOutput->SetNTrackClusters( 0 );
     722             : 
     723             :         int nStoredHits = 0;
     724             :         int nStoredTracks = 0;
     725             :         int nStoredLocalTracks = 0;
     726             : 
     727           0 :         AliHLTTPCCASliceOutTrack *out = useOutput->FirstTrack();
     728             : 
     729           0 :         trackSortData* trackOrder = new trackSortData[fCommonMem->fNTracks];
     730           0 :         for (int i = 0;i < fCommonMem->fNTracks;i++)
     731             :         {
     732           0 :                 trackOrder[i].fTtrack = i;
     733           0 :                 trackOrder[i].fSortVal = fTracks[trackOrder[i].fTtrack].NHits() / 1000.f + fTracks[trackOrder[i].fTtrack].Param().GetZ() * 100.f + fTracks[trackOrder[i].fTtrack].Param().GetY();
     734             :         }
     735           0 :         qsort(trackOrder, fCommonMem->fNLocalTracks, sizeof(trackSortData), SortComparison);
     736           0 :         qsort(trackOrder + fCommonMem->fNLocalTracks, fCommonMem->fNTracks - fCommonMem->fNLocalTracks, sizeof(trackSortData), SortComparison);
     737             : 
     738           0 :         for ( int iTrTmp = 0; iTrTmp < fCommonMem->fNTracks; iTrTmp++ ) {
     739           0 :                 int iTr = trackOrder[iTrTmp].fTtrack;
     740           0 :                 AliHLTTPCCATrack &iTrack = fTracks[iTr];    
     741             : 
     742           0 :                 if( iTr < fCommonMem->fNLocalTracks && iTrack.NHits() < fParam.MinNTrackClusters() ) continue;
     743           0 :                 if( CAMath::Abs(iTrack.Param().GetQPt())> fParam.MaxTrackQPt() ) continue;
     744             : 
     745           0 :                 out->SetParam( iTrack.Param() );
     746           0 :                 out->SetLocalTrackId( iTrack.LocalTrackId() );
     747             :                 int nClu = 0;
     748           0 :                 int iID = iTrack.FirstHitID();
     749             : 
     750           0 :                 for ( int ith = 0; ith < iTrack.NHits(); ith++ ) {
     751           0 :                         const AliHLTTPCCAHitId &ic = fTrackHits[iID + ith];
     752           0 :                         int iRow = ic.RowIndex();
     753           0 :                         int ih = ic.HitIndex();
     754             : 
     755           0 :                         const AliHLTTPCCARow &row = fData.Row( iRow );
     756             : #ifdef HLTCA_ARRAY_BOUNDS_CHECKS
     757             :                         if (ih >= row.NHits() || ih < 0)
     758             :                         {
     759             :                                 printf("Array out of bounds access (Sector Row) (Hit %d / %d - NumC %d): Sector %d Row %d Index %d\n", ith, iTrack.NHits(), fClusterData->NumberOfClusters(), fParam.ISlice(), iRow, ih);
     760             :                                 fflush(stdout);
     761             :                                 continue;
     762             :                         }
     763             : #endif
     764           0 :                         int clusterIndex = fData.ClusterDataIndex( row, ih );
     765             : 
     766             : #ifdef HLTCA_ARRAY_BOUNDS_CHECKS
     767             :                         if (clusterIndex >= fClusterData->NumberOfClusters() || clusterIndex < 0)
     768             :                         {
     769             :                                 printf("Array out of bounds access (Cluster Data) (Hit %d / %d - NumC %d): Sector %d Row %d Hit %d, Clusterdata Index %d\n", ith, iTrack.NHits(), fClusterData->NumberOfClusters(), fParam.ISlice(), iRow, ih, clusterIndex);
     770             :                                 fflush(stdout);
     771             :                                 continue;
     772             :                         }
     773             : #endif
     774             : 
     775           0 :                         float origX = fClusterData->X( clusterIndex );
     776           0 :                         float origY = fClusterData->Y( clusterIndex );
     777           0 :                         float origZ = fClusterData->Z( clusterIndex );      
     778           0 :                         int id = fClusterData->Id( clusterIndex );
     779           0 :                         AliHLTTPCCASliceOutCluster c;
     780           0 :                         c.Set( id, iRow, origX, origY, origZ );
     781           0 :                         out->SetCluster( nClu, c );
     782           0 :                         nClu++;
     783           0 :                 }
     784             : 
     785           0 :                 nStoredTracks++;
     786           0 :                 if (iTr < fCommonMem->fNLocalTracks) nStoredLocalTracks++;
     787           0 :                 nStoredHits+=nClu; 
     788           0 :                 out->SetNClusters( nClu );
     789           0 :                 out = out->NextTrack();    
     790           0 :         }
     791           0 :         delete[] trackOrder;
     792             : 
     793           0 :         useOutput->SetNTracks( nStoredTracks );
     794           0 :         useOutput->SetNLocalTracks( nStoredLocalTracks );
     795           0 :         useOutput->SetNTrackClusters( nStoredHits );
     796             : 
     797           0 :         timer.Stop();
     798           0 :         fTimers[5] += timer.CpuTime();
     799           0 : }
     800             : 
     801             : #endif
     802             : 
     803             : GPUh() void AliHLTTPCCATracker::FitTrackFull( const MEM_LG2(AliHLTTPCCATrack) &/**/, float * /**/ ) const
     804             : {
     805             :         // fit track with material
     806             : #ifdef XXX
     807             :         //* Fit the track
     808             :         FitTrack( iTrack, tt0 );
     809             :         if ( iTrack.NHits() <= 3 ) return;
     810             : 
     811             :         AliHLTTPCCATrackParam &t = iTrack.Param();
     812             :         AliHLTTPCCATrackParam t0 = t;
     813             : 
     814             :         t.Chi2() = 0;
     815             :         t.NDF() = -5;
     816             :         bool first = 1;
     817             : 
     818             :         int iID = iTrack.FirstHitID();
     819             :         for ( int ih = 0; ih < iTrack.NHits(); ih++, iID++ ) {
     820             :                 const AliHLTTPCCAHitId &ic = fTrackHits[iID];
     821             :                 int iRow = ic.rowIndex();
     822             :                 const AliHLTTPCCARow &row = fData.Row( iRow );
     823             :                 if ( !t0.TransportToX( row.X() ) ) continue;
     824             :                 float dy, dz;
     825             :                 const AliHLTTPCCAHit &h = ic.hitIndex();
     826             : 
     827             :                 // check for wrong hits
     828             :                 if ( 0 ) {
     829             :                         dy = t0.GetY() - h.Y();
     830             :                         dz = t0.GetZ() - h.Z();
     831             : 
     832             :                         //if( dy*dy > 3.5*3.5*(/*t0.GetErr2Y() + */h.ErrY()*h.ErrY() ) ) continue;//SG!!!
     833             :                         //if( dz*dz > 3.5*3.5*(/*t0.GetErr2Z() + */h.ErrZ()*h.ErrZ() ) ) continue;
     834             :                 }
     835             : 
     836             :                 if ( !t.TransportToX( row.X() ) ) continue;
     837             : 
     838             :                 //* Update the track
     839             : 
     840             :                 if ( first ) {
     841             :                         t.Cov()[ 0] = .5 * .5;
     842             :                         t.Cov()[ 1] = 0;
     843             :                         t.Cov()[ 2] = .5 * .5;
     844             :                         t.Cov()[ 3] = 0;
     845             :                         t.Cov()[ 4] = 0;
     846             :                         t.Cov()[ 5] = .2 * .2;
     847             :                         t.Cov()[ 6] = 0;
     848             :                         t.Cov()[ 7] = 0;
     849             :                         t.Cov()[ 8] = 0;
     850             :                         t.Cov()[ 9] = .2 * .2;
     851             :                         t.Cov()[10] = 0;
     852             :                         t.Cov()[11] = 0;
     853             :                         t.Cov()[12] = 0;
     854             :                         t.Cov()[13] = 0;
     855             :                         t.Cov()[14] = .2 * .2;
     856             :                         t.Chi2() = 0;
     857             :                         t.NDF() = -5;
     858             :                 }
     859             :                 float err2Y, err2Z;
     860             :                 GetErrors2( iRow, t, err2Y, err2Z );
     861             : 
     862             :                 if ( !t.Filter2( h.Y(), h.Z(), err2Y, err2Z ) ) continue;
     863             : 
     864             :                 first = 0;
     865             :         }
     866             :         /*
     867             :         float cosPhi = iTrack.Param().GetCosPhi();
     868             :         p0.Param().TransportToX(ID2Row( iTrack.PointID()[0] ).X());
     869             :         p2.Param().TransportToX(ID2Row( iTrack.PointID()[1] ).X());
     870             :         if( p0.Param().GetCosPhi()*cosPhi<0 ){ // change direction
     871             :         float *par = p0.Param().Par();
     872             :         float *cov = p0.Param().Cov();
     873             :         par[2] = -par[2]; // sin phi
     874             :         par[3] = -par[3]; // DzDs
     875             :         par[4] = -par[4]; // kappa
     876             :         cov[3] = -cov[3];
     877             :         cov[4] = -cov[4];
     878             :         cov[6] = -cov[6];
     879             :         cov[7] = -cov[7];
     880             :         cov[10] = -cov[10];
     881             :         cov[11] = -cov[11];
     882             :         p0.Param().CosPhi() = -p0.Param().GetCosPhi();
     883             :         }
     884             :         */
     885             : #endif
     886           0 : }
     887             : 
     888             : GPUh() void AliHLTTPCCATracker::FitTrack( const AliHLTTPCCATrack &/*track*/, float * /*t0[]*/ ) const
     889             : {
     890             :         //* Fit the track
     891             : #ifdef XXX
     892             :         AliHLTTPCCAEndPoint &p2 = ID2Point( track.PointID()[1] );
     893             :         const AliHLTTPCCAHit &c0 = ID2Hit( fTrackHits[p0.TrackHitID()].HitID() );
     894             :         const AliHLTTPCCAHit &c1 = ID2Hit( fTrackHits[track.HitID()[1]].HitID() );
     895             :         const AliHLTTPCCAHit &c2 = ID2Hit( fTrackHits[p2.TrackHitID()].HitID() );
     896             :         const AliHLTTPCCARow &row0 = ID2Row( fTrackHits[p0.TrackHitID()].HitID() );
     897             :         const AliHLTTPCCARow &row1 = ID2Row( fTrackHits[track.HitID()[1]].HitID() );
     898             :         const AliHLTTPCCARow &row2 = ID2Row( fTrackHits[p2.TrackHitID()].HitID() );
     899             :         float sp0[5] = {row0.X(), c0.Y(), c0.Z(), c0.ErrY(), c0.ErrZ() };
     900             :         float sp1[5] = {row1.X(), c1.Y(), c1.Z(), c1.ErrY(), c1.ErrZ() };
     901             :         float sp2[5] = {row2.X(), c2.Y(), c2.Z(), c2.ErrY(), c2.ErrZ() };
     902             :         //std::cout<<"Fit track, points ="<<sp0[0]<<" "<<sp0[1]<<" / "<<sp1[0]<<" "<<sp1[1]<<" / "<<sp2[0]<<" "<<sp2[1]<<std::endl;
     903             :         if ( track.NHits() >= 3 ) {
     904             :                 p0.Param().ConstructXYZ3( sp0, sp1, sp2, p0.Param().CosPhi(), t0 );
     905             :                 p2.Param().ConstructXYZ3( sp2, sp1, sp0, p2.Param().CosPhi(), t0 );
     906             :                 //p2.Param() = p0.Param();
     907             :                 //p2.Param().TransportToX(row2.X());
     908             :                 //p2.Param().Par()[1] = -p2.Param().Par()[1];
     909             :                 //p2.Param().Par()[4] = -p2.Param().Par()[4];
     910             :         } else {
     911             :                 p0.Param().X() = row0.X();
     912             :                 p0.Param().Y() = c0.Y();
     913             :                 p0.Param().Z() = c0.Z();
     914             :                 p0.Param().Err2Y() = c0.ErrY() * c0.ErrY();
     915             :                 p0.Param().Err2Z() = c0.ErrZ() * c0.ErrZ();
     916             :                 p2.Param().X() = row2.X();
     917             :                 p2.Param().Y() = c2.Y();
     918             :                 p2.Param().Z() = c2.Z();
     919             :                 p2.Param().Err2Y() = c2.ErrY() * c2.ErrY();
     920             :                 p2.Param().Err2Z() = c2.ErrZ() * c2.ErrZ();
     921             :         }
     922             : #endif
     923           0 : }
     924             : 
     925             : #if !defined(HLTCA_GPUCODE)
     926             : 
     927             : GPUh() void AliHLTTPCCATracker::WriteEvent( std::ostream &out )
     928             : {
     929             :         // write event to the file
     930           0 :         for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
     931           0 :                 out << fData.Row( iRow ).HitNumberOffset() << " " << fData.Row( iRow ).NHits() << std::endl;
     932             :         }
     933           0 :         out << NHitsTotal() << std::endl;
     934             : 
     935           0 :         AliHLTResizableArray<float> y( NHitsTotal() ), z( NHitsTotal() );
     936             : 
     937           0 :         for ( int iRow = 0; iRow < fParam.NRows(); iRow++ ) {
     938           0 :                 const AliHLTTPCCARow &row = Row( iRow );
     939           0 :                 float y0 = row.Grid().YMin();
     940           0 :                 float z0 = row.Grid().ZMin();
     941           0 :                 float stepY = row.HstepY();
     942           0 :                 float stepZ = row.HstepZ();
     943           0 :                 for ( int ih = 0; ih < fData.Row( iRow ).NHits(); ih++ ) {
     944           0 :                         int id = HitInputID( row, ih );
     945           0 :                         y[id] = y0 + HitDataY( row, ih ) * stepY;
     946           0 :                         z[id] = z0 + HitDataZ( row, ih ) * stepZ;
     947             :                 }
     948             :         }
     949           0 :         for ( int ih = 0; ih < NHitsTotal(); ih++ ) {
     950           0 :                 out << y[ih] << " " << z[ih] << std::endl;
     951             :         }
     952           0 : }
     953             : 
     954             : GPUh() void AliHLTTPCCATracker::WriteTracks( std::ostream &/*out*/ )
     955             : {
     956             :         //* Write tracks to file --- dummy
     957           0 : }
     958             : 
     959             : GPUh() void AliHLTTPCCATracker::ReadTracks( std::istream &/*in*/ )
     960             : {
     961             :         //* Read tracks  from file -- dummy
     962           0 : }
     963             : 
     964             : GPUh() int AliHLTTPCCATracker::PerformGlobalTrackingRun(AliHLTTPCCATracker& sliceNeighbour, int iTrack, int rowIndex, float angle, int direction)
     965             : {
     966             :         /*for (int j = 0;j < fTracks[j].NHits();j++)
     967             :         {
     968             :                 printf("Hit %3d: Row %3d: X %3.7lf Y %3.7lf\n", j, fTrackHits[fTracks[iTrack].FirstHitID() + j].RowIndex(), Row(fTrackHits[fTracks[iTrack].FirstHitID() + j].RowIndex()).X(),
     969             :                 (float) Data().HitDataY(Row(fTrackHits[fTracks[iTrack].FirstHitID() + j].RowIndex()), fTrackHits[fTracks[iTrack].FirstHitID() + j].HitIndex()) * Row(fTrackHits[fTracks[iTrack].FirstHitID() + j].RowIndex()).HstepY() + Row(fTrackHits[fTracks[iTrack].FirstHitID() + j].RowIndex()).Grid().YMin());
     970             :                 }*/
     971             : 
     972           0 :         if (sliceNeighbour.fCommonMem->fNTracklets == 0) return(0);
     973             : 
     974           0 :         AliHLTTPCCATrackParam tParam;
     975           0 :         tParam.InitParam();
     976           0 :         tParam.SetCov( 0, 0.05 );
     977           0 :         tParam.SetCov( 2, 0.05 );
     978           0 :         tParam.SetCov( 5, 0.001 );
     979           0 :         tParam.SetCov( 9, 0.001 );
     980           0 :         tParam.SetCov( 14, 0.05 );
     981           0 :         tParam.SetParam(fTracks[iTrack].Param());
     982             : 
     983             :         //printf("Parameters X %f Y %f Z %f SinPhi %f DzDs %f QPt %f SignCosPhi %f\n", tParam.X(), tParam.Y(), tParam.Z(), tParam.SinPhi(), tParam.DzDs(), tParam.QPt(), tParam.SignCosPhi());
     984           0 :         if (!tParam.Rotate(angle, .999)) return(0);
     985             :         //printf("Rotated X %f Y %f Z %f SinPhi %f DzDs %f QPt %f SignCosPhi %f\n", tParam.X(), tParam.Y(), tParam.Z(), tParam.SinPhi(), tParam.DzDs(), tParam.QPt(), tParam.SignCosPhi());
     986             : 
     987             :         int maxRowGap = 6;
     988           0 :         do
     989             :         {
     990           0 :                 rowIndex += direction;
     991           0 :                 if (!tParam.TransportToX(sliceNeighbour.Row(rowIndex).X(), fParam.ConstBz(), .999)) {maxRowGap = 0;break;}
     992             :                 //printf("Transported X %f Y %f Z %f SinPhi %f DzDs %f QPt %f SignCosPhi %f (MaxY %f)\n", tParam.X(), tParam.Y(), tParam.Z(), tParam.SinPhi(), tParam.DzDs(), tParam.QPt(), tParam.SignCosPhi(), sliceNeighbour.Row(rowIndex).MaxY());
     993           0 :         } while (fabs(tParam.Y()) > sliceNeighbour.Row(rowIndex).MaxY() && --maxRowGap);
     994           0 :         if (maxRowGap == 0) return(0);
     995             : 
     996             : #ifdef GLOBAL_TRACKING_MAINTAIN_TRACKLETS
     997             :         int tmphits[HLTCA_ROW_COUNT];
     998             :         for (int i = 0;i < HLTCA_ROW_COUNT;i++)
     999             :         {
    1000             : #ifdef EXTERN_ROW_HITS
    1001             :                 tmphits[i] = sliceNeighbour.TrackletRowHits()[i * *sliceNeighbour.NTracklets()];
    1002             : #else
    1003             :                 tmphits[i] = sliceNeighbour.Tracklet(0).RowHit(i);
    1004             : #endif
    1005             :         }
    1006             : #endif
    1007             : 
    1008           0 :         int nHits = AliHLTTPCCATrackletConstructor::AliHLTTPCCATrackletConstructorGlobalTracking(sliceNeighbour, tParam, rowIndex, direction);
    1009           0 :         if (nHits >= GLOBAL_TRACKING_MIN_HITS)
    1010             :         {
    1011             :                 //printf("%d hits found\n", nHits);
    1012           0 :                 AliHLTTPCCATrack& track = sliceNeighbour.fTracks[sliceNeighbour.fCommonMem->fNTracks];
    1013           0 :                 if (direction == 1)
    1014             :                 {
    1015             :                         int i = 0;
    1016           0 :                         while (i < nHits)
    1017             :                         {
    1018             : #ifdef EXTERN_ROW_HITS
    1019           0 :                                 const int rowHit = sliceNeighbour.TrackletRowHits()[rowIndex * *sliceNeighbour.NTracklets()];
    1020             : #else
    1021             :                                 const int rowHit = sliceNeighbour.Tracklet(0).RowHit(rowIndex);
    1022             : #endif
    1023           0 :                                 if (rowHit != -1)
    1024             :                                 {
    1025             :                                         //printf("New track: entry %d, row %d, hitindex %d\n", i, rowIndex, sliceNeighbour.fTrackletRowHits[rowIndex * sliceNeighbour.fCommonMem->fNTracklets]);
    1026           0 :                                         sliceNeighbour.fTrackHits[sliceNeighbour.fCommonMem->fNTrackHits + i].Set(rowIndex, rowHit);
    1027           0 :                                         if (i == 0) tParam.TransportToX(sliceNeighbour.Row(rowIndex).X(), fParam.ConstBz(), .999);
    1028           0 :                                         i++;
    1029           0 :                                 }
    1030           0 :                                 rowIndex ++;
    1031             :                         }
    1032           0 :                 }
    1033             :                 else
    1034             :                 {
    1035           0 :                         int i = nHits - 1;
    1036           0 :                         while (i >= 0)
    1037             :                         {
    1038             : #ifdef EXTERN_ROW_HITS
    1039           0 :                                 const int rowHit = sliceNeighbour.TrackletRowHits()[rowIndex * *sliceNeighbour.NTracklets()];
    1040             : #else
    1041             :                                 const int rowHit = sliceNeighbour.Tracklet(0).RowHit(rowIndex);
    1042             : #endif
    1043           0 :                                 if (rowHit != -1)
    1044             :                                 {
    1045             :                                         //printf("New track: entry %d, row %d, hitindex %d\n", i, rowIndex, sliceNeighbour.fTrackletRowHits[rowIndex * sliceNeighbour.fCommonMem->fNTracklets]);
    1046           0 :                                         sliceNeighbour.fTrackHits[sliceNeighbour.fCommonMem->fNTrackHits + i].Set(rowIndex, rowHit);
    1047           0 :                                         i--;
    1048           0 :                                 }
    1049           0 :                                 rowIndex--;
    1050             :                         }
    1051             :                 }
    1052           0 :                 track.SetAlive(1);
    1053           0 :                 track.SetParam(tParam.GetParam());
    1054           0 :                 track.SetNHits(nHits);
    1055           0 :                 track.SetFirstHitID(sliceNeighbour.fCommonMem->fNTrackHits);
    1056           0 :                 const int kMaxTrackIdInSlice = AliHLTTPCCASliceOutTrack::MaxTrackId();
    1057           0 :                 track.SetLocalTrackId(fParam.ISlice() * kMaxTrackIdInSlice + fTracks[iTrack].LocalTrackId());
    1058           0 :                 sliceNeighbour.fCommonMem->fNTracks++;
    1059           0 :                 sliceNeighbour.fCommonMem->fNTrackHits += nHits;
    1060             : 
    1061           0 :         }
    1062             : 
    1063             : #ifdef GLOBAL_TRACKING_MAINTAIN_TRACKLETS
    1064             :         for (int i = 0;i < HLTCA_ROW_COUNT;i++)
    1065             :         {
    1066             : #ifdef EXTERN_ROW_HITS
    1067             :                 sliceNeighbour.TrackletRowHits()[i * *sliceNeighbour.NTracklets()] = tmphits[i];
    1068             : #else
    1069             :                 sliceNeighbour.Tracklet(0).SetRowHit(i, tmphits[i]);
    1070             : #endif
    1071             :         }
    1072             : #endif
    1073             : 
    1074           0 :         return(nHits >= GLOBAL_TRACKING_MIN_HITS);
    1075           0 : }
    1076             : 
    1077             : GPUh() void AliHLTTPCCATracker::PerformGlobalTracking(AliHLTTPCCATracker& sliceLeft, AliHLTTPCCATracker& sliceRight, int MaxTracks)
    1078             : {
    1079             :         int ul = 0, ur = 0, ll = 0, lr = 0;
    1080           0 :         for (int i = 0;i < fCommonMem->fNLocalTracks;i++)
    1081             :         {
    1082           0 :                 if (sliceLeft.fCommonMem->fNTracks >= MaxTracks || sliceRight.fCommonMem->fNTracks >= MaxTracks) return;
    1083             : 
    1084             :                 {
    1085           0 :                         const int tmpHit = fTracks[i].FirstHitID();
    1086           0 :                         if (fTrackHits[tmpHit].RowIndex() >= GLOBAL_TRACKING_MIN_ROWS && fTrackHits[tmpHit].RowIndex() < GLOBAL_TRACKING_RANGE)
    1087             :                         {
    1088           0 :                                 int rowIndex = fTrackHits[tmpHit].RowIndex();
    1089           0 :                                 const AliHLTTPCCARow& row = Row(rowIndex);
    1090           0 :                                 float Y = (float) Data().HitDataY(row, fTrackHits[tmpHit].HitIndex()) * row.HstepY() + row.Grid().YMin();
    1091           0 :                                 if (Y < -row.MaxY() * GLOBAL_TRACKING_Y_RANGE_LOWER_LEFT)
    1092             :                                 {
    1093             :                                         //printf("Track %d, lower row %d, left border (%f of %f)\n", i, fTrackHits[tmpHit].RowIndex(), Y, -row.MaxY());
    1094           0 :                                         ll += PerformGlobalTrackingRun(sliceLeft, i, rowIndex, -fParam.DAlpha(), -1);
    1095           0 :                                 }
    1096           0 :                                 if (Y > row.MaxY() * GLOBAL_TRACKING_Y_RANGE_LOWER_RIGHT)
    1097             :                                 {
    1098             :                                         //printf("Track %d, lower row %d, right border (%f of %f)\n", i, fTrackHits[tmpHit].RowIndex(), Y, row.MaxY());
    1099           0 :                                         lr += PerformGlobalTrackingRun(sliceRight, i, rowIndex, fParam.DAlpha(), -1);
    1100           0 :                                 }
    1101           0 :                         }
    1102             :                 }
    1103             :                 
    1104             :                 {
    1105           0 :                         const int tmpHit = fTracks[i].FirstHitID() + fTracks[i].NHits() - 1;
    1106           0 :                         if (fTrackHits[tmpHit].RowIndex() < HLTCA_ROW_COUNT - GLOBAL_TRACKING_MIN_ROWS && fTrackHits[tmpHit].RowIndex() >= HLTCA_ROW_COUNT - GLOBAL_TRACKING_RANGE)
    1107             :                         {
    1108           0 :                                 int rowIndex = fTrackHits[tmpHit].RowIndex();
    1109           0 :                                 const AliHLTTPCCARow& row = Row(rowIndex);
    1110           0 :                                 float Y = (float) Data().HitDataY(row, fTrackHits[tmpHit].HitIndex()) * row.HstepY() + row.Grid().YMin();
    1111           0 :                                 if (Y < -row.MaxY() * GLOBAL_TRACKING_Y_RANGE_UPPER_LEFT)
    1112             :                                 {
    1113             :                                         //printf("Track %d, upper row %d, left border (%f of %f)\n", i, fTrackHits[tmpHit].RowIndex(), Y, -row.MaxY());
    1114           0 :                                         ul += PerformGlobalTrackingRun(sliceLeft, i, rowIndex, -fParam.DAlpha(), 1);
    1115           0 :                                 }
    1116           0 :                                 if (Y > row.MaxY() * GLOBAL_TRACKING_Y_RANGE_UPPER_RIGHT)
    1117             :                                 {
    1118             :                                         //printf("Track %d, upper row %d, right border (%f of %f)\n", i, fTrackHits[tmpHit].RowIndex(), Y, row.MaxY());
    1119           0 :                                         ur += PerformGlobalTrackingRun(sliceRight, i, rowIndex, fParam.DAlpha(), 1);
    1120           0 :                                 }
    1121           0 :                         }
    1122             :                 }
    1123             :         }
    1124             :         //printf("Global Tracking Result: Slide %2d: LL %3d LR %3d UL %3d UR %3d\n", fParam.ISlice(), ll, lr, ul, ur);
    1125           0 : }
    1126             : 
    1127             : #endif
    1128             : #endif

Generated by: LCOV version 1.11