]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/tracking-ca/AliHLTTPCCAGrid.cxx
89d51e02130b626201ebfd3003187c60e366071a
[u/mrichter/AliRoot.git] / HLT / TPCLib / tracking-ca / AliHLTTPCCAGrid.cxx
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
21
22 #include "AliHLTTPCCAGrid.h"
23 #include "AliHLTTPCCAMath.h"
24 #include <assert.h>
25 #include <iostream>
26
27 GPUd() void AliHLTTPCCAGrid::CreateEmpty()
28 {
29   fYMin = 0.f;
30   fYMax = 1.f;
31   fZMin = 0.f;
32   fZMax = 1.f;
33
34   fNy = 0;
35   fNz = 0;
36   fN = 0;
37
38   fStepYInv = 1.f;
39   fStepZInv = 1.f;
40 }
41
42
43 GPUd() void AliHLTTPCCAGrid::Create( float yMin, float yMax, float zMin, float zMax, float sy, float sz )
44 {
45   //* Create the grid
46   fYMin = yMin;
47   fZMin = zMin;
48
49   fStepYInv = 1.f / sy;
50   fStepZInv = 1.f / sz;
51
52   fNy = static_cast<unsigned int>( ( yMax - fYMin ) * fStepYInv + 1.f );
53   fNz = static_cast<unsigned int>( ( zMax - fZMin ) * fStepZInv + 1.f );
54
55   fN = fNy * fNz;
56
57   fYMax = fYMin + fNy * sy;
58   fZMax = fZMin + fNz * sz;
59 }
60
61
62 GPUd() int AliHLTTPCCAGrid::GetBin( float Y, float Z ) const
63 {
64   //* get the bin pointer
65   const int yBin = static_cast<int>( CAMath::FMulRZ( Y - fYMin, fStepYInv ) );
66   const int zBin = static_cast<int>( CAMath::FMulRZ( Z - fZMin, fStepZInv ) );
67   const int bin = CAMath::Mul24( zBin, fNy ) + yBin;
68   assert( bin >= 0 );
69   assert( bin < static_cast<int>( fN ) );
70   return bin;
71 }
72
73 int AliHLTTPCCAGrid::GetBinBounded( float Y, float Z ) const
74 {
75   //* get the bin pointer
76   const int yBin = static_cast<int>( CAMath::FMulRZ( Y - fYMin, fStepYInv ) );
77   const int zBin = static_cast<int>( CAMath::FMulRZ( Z - fZMin, fStepZInv ) );
78   const int bin = CAMath::Mul24( zBin, fNy ) + yBin;
79   if ( bin < 0 ) return 0;
80   if ( bin >= static_cast<int>( fN ) ) return fN - 1;
81   return bin;
82 }
83
84 GPUd() void AliHLTTPCCAGrid::GetBin( float Y, float Z, int *bY, int *bZ ) const
85 {
86   //* get the bin pointer
87
88   int bbY = ( int ) ( ( Y - fYMin ) * fStepYInv );
89   int bbZ = ( int ) ( ( Z - fZMin ) * fStepZInv );
90
91   if ( bbY < 0 ) bbY = 0;
92   else if ( bbY >= ( int )fNy ) bbY = fNy - 1;
93   if ( bbZ < 0 ) bbZ = 0;
94   else if ( bbZ >= ( int )fNz ) bbZ = fNz - 1;
95   *bY = ( unsigned int ) bbY;
96   *bZ = ( unsigned int ) bbZ;
97 }