StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AliHLTTPCCAGrid.cxx
1 // $Id: AliHLTTPCCAGrid.cxx,v 1.1 2016/02/05 23:27:27 fisyak Exp $
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 // Developed by: Igor Kulakov <I.Kulakov@gsi.de> *
11 // Maksym Zyzak <M.Zyzak@gsi.de> *
12 // *
13 // Permission to use, copy, modify and distribute this software and its *
14 // documentation strictly for non-commercial purposes is hereby granted *
15 // without fee, provided that the above copyright notice appears in all *
16 // copies and that both the copyright notice and this permission notice *
17 // appear in the supporting documentation. The authors make no claims *
18 // about the suitability of this software for any purpose. It is *
19 // provided "as is" without express or implied warranty. *
20 // *
21 //***************************************************************************
22 
23 
24 
25 #include "AliHLTTPCCAGrid.h"
26 #include "AliHLTTPCCAMath.h"
27 #include <assert.h>
28 #include <cstdio>
29 
30 void AliHLTTPCCAGrid::CreateEmpty()
31 {
32  fYMinOverStep = 0.f;
33  fZMinOverStep = 0.f;
34 
35  fNy = 0;
36  fNz = 0;
37  fN = 0;
38 
39  fStepYInv = 1.f;
40  fStepZInv = 1.f;
41 }
42 
43 void AliHLTTPCCAGrid::Create1( float y, float z, float sy, float sz )
44 {
45  fN = 1;
46  fNy = 1;
47  fNz = 1;
48 
49  fStepYInv = 1.f / sy;
50  fStepZInv = 1.f / sz;
51 
52  fYMinOverStep = y * fStepYInv - 0.5f;
53  fZMinOverStep = z * fStepZInv - 0.5f;
54 }
55 
56 void AliHLTTPCCAGrid::Create( float yMin, float yMax, float zMin, float zMax, float sy, float sz )
57 {
58  //* Create the grid
59  fStepYInv = 1.f / sy;
60  fStepZInv = 1.f / sz;
61 
62  fYMinOverStep = yMin * fStepYInv;
63  fZMinOverStep = zMin * fStepZInv;
64 
65 // std::cout << "fYMinOverStep " << yMax * fStepYInv - fYMinOverStep << "fZMinOverStep " << zMax * fStepZInv - fZMinOverStep << std::endl;
66  fNy = static_cast<unsigned short>( yMax * fStepYInv - fYMinOverStep + 1.f );
67  fNz = static_cast<unsigned short>( zMax * fStepZInv - fZMinOverStep + 1.f );
68 
69 // std::cout << "fNy " << fNy << "fNz " << fNz << std::endl;
70  fN = fNy * fNz;
71 
72  //printf( "Grid::Create( %f, %f, %f, %f, %f, %f ): %d (%d x %d) with %f, %f\n", yMin, yMax, zMin, zMax, sy, sz, fN, fNy, fNz, fYMinOverStep, fZMinOverStep );
73 }
74 
75 
76 int AliHLTTPCCAGrid::GetBin( float Y, float Z ) const
77 {
78  //* get the bin pointer
79  const int yBin = static_cast<int>( Y * fStepYInv - fYMinOverStep );
80  const int zBin = static_cast<int>( Z * fStepZInv - fZMinOverStep );
81  assert( yBin >= 0 );
82  assert( zBin >= 0 );
83  assert( yBin < static_cast<int>( fNy ) );
84  assert( zBin < static_cast<int>( fNz ) );
85  const int bin = zBin * fNy + yBin;
86  return bin;
87 }
88 
89 void AliHLTTPCCAGrid::GetBinBounds( int iBin, float &Ymin, float &Ymax, float &Zmin, float &Zmax) const
90 {
91  int zBin = iBin / fNy;
92  int yBin = iBin % fNy;
93  Ymin = (fYMinOverStep + yBin)/fStepYInv;
94  Zmin = (fZMinOverStep + zBin)/fStepZInv;
95  Ymax = Ymin + 1. / fStepYInv;
96  Zmax = Zmin + 1. / fStepZInv;
97 }