CbmRoot
L1Grid.h
Go to the documentation of this file.
1 //-*- Mode: C++ -*-
2 // $Id: AliHLTTPCCAGrid.h,v 1.1.1.1 2010/07/26 20:55:38 ikulakov Exp $
3 // ************************************************************************
4 // This file is property of and copyright by the ALICE HLT Project *
5 // ALICE Experiment at CERN, All rights reserved. *
6 // See cxx source for full Copyright notice *
7 // *
8 //*************************************************************************
9 
10 #ifndef L1GRID_H
11 #define L1GRID_H
12 
13 #include "CbmL1Def.h"
14 #include <algorithm>
15 #include <string.h>
16 
17 #include <assert.h>
18 #include <cstdio>
19 #ifdef _OPENMP
20 #include "omp.h"
21 #endif
22 #include "L1HitPoint.h"
23 #include "L1StsHit.h"
24 
25 using namespace std;
26 
27 class L1Algo;
28 //class L1HitPoint;
29 
30 
39 class L1Grid {
40 public:
42  : fN(0)
43  , fNy(0)
44  , fNz(0)
45  , fNt(0)
46  , fYMinOverStep(0.)
47  , fZMinOverStep(0.)
48  , fTMinOverStep(0.)
49  , fStepYInv(0.)
50  , fStepZInv(0.)
51  , fStepTInv(0.)
52  , fBinInGrid(0)
53  , fFirstHitInBin()
54  , fHitsInBin()
55  , fNThreads(0) {}
56 
57  L1Grid(const L1Grid& grid)
58  : fN(grid.N())
59  , fNy(grid.Ny())
60  , fNz(grid.Nz())
61  , fNt(grid.Nt())
62  , fYMinOverStep(0.)
63  , fZMinOverStep(0.)
64  , fTMinOverStep(0.)
65  , fStepYInv(0.)
66  , fStepZInv(0.)
67  , fStepTInv(0.)
68  , fBinInGrid(0)
69  , fFirstHitInBin()
70  , fHitsInBin()
71  , fNThreads(0) {}
72  // ~L1Grid(){ //if ( fFirstHitInBin ) delete[] fFirstHitInBin;
73  //
74  //
75  //
76  // for( int i = 0; i < fNThreads; i++ ) {
77  // // if (fFirstHitInBinArray[i]) delete[] fFirstHitInBinArray[i];
78  // if (fFirstHitInBin[i]) delete[] fFirstHitInBin[i];
79  // }
80  // }
81 
83  THitI nhits,
84  L1Vector<L1HitPoint>* pointsBuf,
85  L1Vector<L1StsHit>* hitsBuf,
86  const L1StsHit* hits,
87  L1Vector<THitI>* indices,
88  L1Vector<THitI>* indicesBuf,
89  char iS,
90  L1Algo& Algo,
91  THitI n);
92  void StoreHits(THitI nhits,
93  const L1StsHit* hits,
94  char iS,
95  L1Algo& Algo,
96  THitI n,
97  L1StsHit* hitsBuf1,
98  const L1StsHit* hits1,
99  THitI* indices1);
100 
101  void CreatePar0(float yMin,
102  float yMax,
103  float zMin,
104  float zMax,
105  float sy,
106  float sz);
107  void BuildBins(float yMin,
108  float yMax,
109  float zMin,
110  float zMax,
111  float tMin,
112  float tMax,
113  float sy,
114  float sz,
115  float st);
116 
117  void HitsSort(L1HitPoint* pointsBuf,
118  L1StsHit* hitsBuf,
119  const L1StsHit* hits,
120  THitI* indices,
121  THitI* indicesBuf,
123  THitI n,
124  THitI nhits,
125  char iS,
126  L1Algo& Algo);
127 
128  void Initial1(int NThreads);
129  void AllocateMemory(int NThreads);
130  void
131  Create(float yMin, float yMax, float zMin, float zMax, float sy, float sz);
132 
133  void Fill(const L1HitPoint* points, THitI n); // call after sort
134  void FillPar(const L1HitPoint* points, THitI n);
135 
136 
137  int GetBin(float Y, float Z) const;
138 
139  unsigned int GetBinBounded(const float& Y, const float& Z) const;
140  void GetBinBounded(const float& Y,
141  const float& Z,
142  unsigned short& bY,
143  unsigned short& bZ) const;
144 
145 
146  int GetBin(float Y, float Z, float T) const;
147 
148  // static unsigned short GetBinBounded( const L1Grid *array, const unsigned short &indexes, const float &Y, const float &Z );
149  // static void GetBinBounded( const L1Grid *array, const unsigned short &indexes, const float &Y, const float &Z, unsigned short *bY, unsigned short *bZ );
150  // static unsigned short Ny( const L1Grid *array, const unsigned short &indexes ) { return unsigned short( array, &L1Grid::fNy, indexes ); }
151 
152  void GetBinBounds(unsigned int iBin,
153  float& Ymin,
154  float& Ymax,
155  float& Zmin,
156  float& Zmax) const;
157  unsigned int
158  GetBinBounded(const float& Y, const float& Z, const float& T) const;
159  void GetBinBounded(const float& Y,
160  const float& Z,
161  const float& T,
162  unsigned short& bY,
163  unsigned short& bZ,
164  unsigned short& bT) const;
165  void GetBinBounds(unsigned int iBin,
166  float& Ymin,
167  float& Ymax,
168  float& Zmin,
169  float& Zmax,
170  float& Tmin,
171  float& Tmax) const;
172 
173  unsigned int N() const { return fN; }
174  unsigned short Ny() const { return fNy; }
175  unsigned short Nz() const { return fNz; }
176  unsigned short Nt() const { return fNt; }
177 
178  THitI FirstHitInBin(unsigned int i) const {
179  if (i < (fN + 1))
180  return fFirstHitInBin[i];
181  else
182  return fFirstHitInBin[fN + 1];
183  }
184 
185 
186  // inline void UpdateGrid (fscal x, fscal y)
187  // {
188  // // #pragma omp atomic
189  // fNumberHitsInBin[GetBinBounded(x, y)]++;
190  //
191  // };
192 
193 
194  void UpdateIterGrid(unsigned int Nelements,
195  L1StsHit* hits,
196  vector<THitI>* indicesBuf,
197  THitI* indices,
198  vector<L1StsHit>* hits2,
199  vector<L1HitPoint>* pointsBuf,
201  int& NHitsOnStation,
202  char iS,
203  L1Algo& Algo,
204  const vector<unsigned char>* vSFlag,
205  const vector<unsigned char>* vSFlagB);
206 
207 
208 private:
209  unsigned int fN; //* total N bins
210  unsigned short fNy; //* N bins in Y
211  unsigned short fNz; //* N bins in Z
212  unsigned short fNt; //* N bins in Z
213  float fYMinOverStep; //* minimal Y value * fStepYInv
214  float fZMinOverStep; //* minimal Z value * fStepZInv
215  float fTMinOverStep; //* minimal Z value * fStepZInv
216  float fStepYInv; //* inverse bin size in Y
217  float fStepZInv; //* inverse bin size in Z
218  float fStepTInv; //* inverse bin size in Z
220 
221  vector<THitI> fFirstHitInBin;
222  vector<THitI> fHitsInBin;
223  // vector <THitI*> fFirstHitInBinArray;
224  // vector <THitI> fOffsets;
225  // vector <THitI> fNumberHitsInBin;
226 
227 
228  unsigned short fNThreads;
229 
230  // vector <omp_lock_t> lock;
231 };
232 
233 // inline unsigned short L1Grid::GetBinBounded( const L1Grid *array, const unsigned short &indexes, const float &Y, const float &Z )
234 // {
235 
236 // const float fZMinOverStep( array, &L1Grid::fZMinOverStep, indexes );
237 // const float fStepZInv( array, &L1Grid::fStepZInv, indexes );
238 // const unsigned short fNz( array, &L1Grid::fNz, indexes );
239 // short_v zBin = ( Z * fStepZInv - fZMinOverStep ).staticCast<short_v>();
240 // unsigned short zBin2 = CAMath::Max( short_v( Vc::Zero ), CAMath::Min( short_v( fNz - 1 ), zBin ) ).staticCast<unsigned short>();
241 
242 // const float fYMinOverStep( array, &L1Grid::fYMinOverStep, indexes );
243 // const float fStepYInv( array, &L1Grid::fStepYInv, indexes );
244 // const unsigned short fNy( array, &L1Grid::fNy, indexes );
245 // short_v yBin = ( Y * fStepYInv - fYMinOverStep ).staticCast<short_v>();
246 // unsigned short yBin2 = CAMath::Max( short_v( Vc::Zero ), CAMath::Min( short_v( fNy - 1 ), yBin ) ).staticCast<unsigned short>();
247 // return zBin2 * fNy + yBin2;
248 // }
249 
250 // inline void L1Grid::GetBinBounded( const L1Grid *array, const unsigned short &indexes, const float &Y, const float &Z, unsigned short *bY, unsigned short *bZ )
251 // {
252 // const float fYMinOverStep( array, &L1Grid::fYMinOverStep, indexes );
253 // const float fStepYInv( array, &L1Grid::fStepYInv, indexes );
254 // const unsigned short fNy( array, &L1Grid::fNy, indexes );
255 // const short fNy2 = fNy.staticCast<short_v>();
256 // const short &yBin = static_cast<short>( Y * fStepYInv - fYMinOverStep );
257 // *bY = static_cast<unsigned short>(max( 0, min( fNy2 - 1, yBin ) ));
258 
259 // const float fZMinOverStep( array, &L1Grid::fZMinOverStep, indexes );
260 // const float fStepZInv( array, &L1Grid::fStepZInv, indexes );
261 // const unsigned short fNz( array, &L1Grid::fNz, indexes );
262 // const short_v fNz2 = fNz.staticCast<short_v>();
263 // const short_v &zBin = ( Z * fStepZInv - fZMinOverStep ).staticCast<short_v>();
264 // *bZ = CAMath::Max( short_v( Vc::Zero ), CAMath::Min( fNz2 - 1, zBin ) ).staticCast<unsigned short>();
265 
266 
267 // }
268 inline int L1Grid::GetBin(float Y, float Z) const {
269  //* get the bin pointer
270  const int& yBin = static_cast<int>(Y * fStepYInv - fYMinOverStep);
271  const int& zBin = static_cast<int>(Z * fStepZInv - fZMinOverStep);
272  assert(yBin >= 0);
273  assert(zBin >= 0);
274  assert(yBin < static_cast<int>(fNy));
275  assert(zBin < static_cast<int>(fNz));
276  const int& bin = zBin * fNy + yBin;
277  return bin;
278 }
279 
280 inline int L1Grid::GetBin(float Y, float Z, float T) const {
281  //* get the bin pointer
282  const int& yBin = static_cast<int>(Y * fStepYInv - fYMinOverStep);
283  const int& zBin = static_cast<int>(Z * fStepZInv - fZMinOverStep);
284  const int& tBin = static_cast<int>(T * fStepTInv - fTMinOverStep);
285  assert(yBin >= 0);
286  assert(zBin >= 0);
287  assert(tBin >= 0);
288  assert(yBin < static_cast<int>(fNy));
289  assert(zBin < static_cast<int>(fNz));
290  assert(tBin < static_cast<int>(fNt));
291  const int& bin = zBin * fNy + yBin + tBin * (fNy * fNz);
292  return bin;
293 }
294 
295 
296 inline void L1Grid::GetBinBounds(unsigned int iBin,
297  float& Ymin,
298  float& Ymax,
299  float& Zmin,
300  float& Zmax) const {
301  int zBin = iBin / fNy;
302  int yBin = iBin % fNy;
303  Ymin = (fYMinOverStep + yBin) / fStepYInv;
304  Zmin = (fZMinOverStep + zBin) / fStepZInv;
305  Ymax = Ymin + 1. / fStepYInv;
306  Zmax = Zmin + 1. / fStepZInv;
307 }
308 
309 inline void L1Grid::GetBinBounds(unsigned int iBin,
310  float& Ymin,
311  float& Ymax,
312  float& Zmin,
313  float& Zmax,
314  float& Tmin,
315  float& Tmax) const {
316  int zBin = (iBin % (fNy * fNz)) / fNy;
317  int yBin = (iBin % (fNy * fNz)) % fNy;
318  int tBin = (iBin / (fNy * fNz));
319  Ymin = (fYMinOverStep + yBin) / fStepYInv;
320  Zmin = (fZMinOverStep + zBin) / fStepZInv;
321  Tmin = (fTMinOverStep + tBin) / fStepTInv;
322  Ymax = Ymin + 1. / fStepYInv;
323  Zmax = Zmin + 1. / fStepZInv;
324  Tmax = Tmin + 1. / fStepTInv;
325 }
326 
327 
328 inline unsigned int L1Grid::GetBinBounded(const float& Y,
329  const float& Z) const {
330  //* get the bin pointer at
331 
332  unsigned short yBin, zBin;
333  GetBinBounded(Y, Z, yBin, zBin);
334  return (unsigned int) zBin * (unsigned int) fNy + (unsigned int) yBin;
335 }
336 
337 inline unsigned int
338 L1Grid::GetBinBounded(const float& Y, const float& Z, const float& T) const {
339  //* get the bin pointer at
340 
341  unsigned short yBin, zBin, tBin;
342  GetBinBounded(Y, Z, T, yBin, zBin, tBin);
343  return (unsigned int) zBin * (unsigned int) fNy + (unsigned int) yBin
344  + tBin * ((unsigned int) fNy * (unsigned int) fNz);
345 }
346 
347 inline void L1Grid::GetBinBounded(const float& Y,
348  const float& Z,
349  unsigned short& bY,
350  unsigned short& bZ) const {
351  const short& yBin = (Y * fStepYInv - fYMinOverStep);
352  const short& zBin = (Z * fStepZInv - fZMinOverStep);
353 
354  bY = max(short(0), min(short(fNy - 1), yBin));
355  bZ = max(short(0), min(short(fNz - 1), zBin));
356 }
357 
358 inline void L1Grid::GetBinBounded(const float& Y,
359  const float& Z,
360  const float& T,
361  unsigned short& bY,
362  unsigned short& bZ,
363  unsigned short& bT) const {
364  const short& yBin = (Y * fStepYInv - fYMinOverStep);
365  const short& zBin = (Z * fStepZInv - fZMinOverStep);
366  const short& tBin = (T * fStepTInv - fTMinOverStep);
367 
368 
369  // cout<<fStepTInv<<" fStepTInv "<<fTMinOverStep<<" fTMinOverStep "<<T<<" T "<<endl;
370 
371  bY = max(short(0), min(short(fNy - 1), yBin));
372  bZ = max(short(0), min(short(fNz - 1), zBin));
373  bT = max(short(0), min(short(fNt - 1), tBin));
374 
375  // cout<<(fNt - 1)<<" (fNt - 1) "<<tBin<<" tBin "<<bT<<" bT "<<endl;
376 }
377 
378 
379 #endif
L1Grid::Create
void Create(float yMin, float yMax, float zMin, float zMax, float sy, float sz)
L1HitPoint
contain strips positions and coordinates of hit
Definition: L1HitPoint.h:6
L1Grid::fTMinOverStep
float fTMinOverStep
Definition: L1Grid.h:215
L1Grid::fN
unsigned int fN
Definition: L1Grid.h:209
L1Grid
Definition: L1Grid.h:39
L1Grid::fNz
unsigned short fNz
Definition: L1Grid.h:211
L1Grid::GetBin
int GetBin(float Y, float Z) const
Definition: L1Grid.h:268
L1Grid::HitsSort
void HitsSort(L1HitPoint *pointsBuf, L1StsHit *hitsBuf, const L1StsHit *hits, THitI *indices, THitI *indicesBuf, L1HitPoint *points, THitI n, THitI nhits, char iS, L1Algo &Algo)
L1Grid::L1Grid
L1Grid()
Definition: L1Grid.h:41
L1Grid::Fill
void Fill(const L1HitPoint *points, THitI n)
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
L1Grid::GetBinBounded
unsigned int GetBinBounded(const float &Y, const float &Z) const
Definition: L1Grid.h:328
L1Grid::FirstHitInBin
THitI FirstHitInBin(unsigned int i) const
Definition: L1Grid.h:178
L1Grid::Initial1
void Initial1(int NThreads)
L1StsHit
Definition: L1StsHit.h:12
L1Grid::fFirstHitInBin
vector< THitI > fFirstHitInBin
Definition: L1Grid.h:221
L1Grid::CreatePar
void CreatePar(L1HitPoint *points, THitI nhits, L1Vector< L1HitPoint > *pointsBuf, L1Vector< L1StsHit > *hitsBuf, const L1StsHit *hits, L1Vector< THitI > *indices, L1Vector< THitI > *indicesBuf, char iS, L1Algo &Algo, THitI n)
L1Grid::fStepYInv
float fStepYInv
Definition: L1Grid.h:216
L1Grid::N
unsigned int N() const
Definition: L1Grid.h:173
L1Vector
Definition: CbmL1Def.h:66
L1Grid::fYMinOverStep
float fYMinOverStep
Definition: L1Grid.h:213
L1Grid::fStepZInv
float fStepZInv
Definition: L1Grid.h:217
min
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:33
CbmL1Def.h
L1Grid::fBinInGrid
int fBinInGrid
Definition: L1Grid.h:219
THitI
unsigned int THitI
Definition: L1StsHit.h:8
L1Grid::fStepTInv
float fStepTInv
Definition: L1Grid.h:218
L1Grid::Nt
unsigned short Nt() const
Definition: L1Grid.h:176
L1Grid::fNThreads
unsigned short fNThreads
Definition: L1Grid.h:228
L1Grid::Ny
unsigned short Ny() const
Definition: L1Grid.h:174
L1Grid::fNt
unsigned short fNt
Definition: L1Grid.h:212
L1HitPoint.h
L1Algo
Definition: L1Algo.h:79
L1Grid::fZMinOverStep
float fZMinOverStep
Definition: L1Grid.h:214
L1Grid::fHitsInBin
vector< THitI > fHitsInBin
Definition: L1Grid.h:222
L1Grid::CreatePar0
void CreatePar0(float yMin, float yMax, float zMin, float zMax, float sy, float sz)
L1Grid::FillPar
void FillPar(const L1HitPoint *points, THitI n)
points
TClonesArray * points
Definition: Analyze_matching.h:18
L1StsHit.h
hits
static vector< vector< QAHit > > hits
Definition: CbmTofHitFinderTBQA.cxx:114
L1Grid::GetBinBounds
void GetBinBounds(unsigned int iBin, float &Ymin, float &Ymax, float &Zmin, float &Zmax) const
Definition: L1Grid.h:296
max
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: L1/vectors/P4_F32vec4.h:36
L1Grid::L1Grid
L1Grid(const L1Grid &grid)
Definition: L1Grid.h:57
L1Grid::fNy
unsigned short fNy
Definition: L1Grid.h:210
L1Grid::Nz
unsigned short Nz() const
Definition: L1Grid.h:175