BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
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 "L1HitPoint.h"
15#include "L1StsHit.h"
16
17#include <algorithm>
18#include <assert.h>
19#include <cstdio>
20#include <string.h>
21
22using namespace std;
23
24/// Copy to memory block [@dest, @dest+@num] num number of times the value of i of type @T with size @typesize.
25/// uses binary expansion of copied volume for speed up
26template<typename T>
27void memset(T* dest, T i, size_t num)
28{
29 const size_t tsize = sizeof(T);
30 unsigned int lastBin = 0;
31 dest[0] = i;
32 while (lastBin + 1 < num) {
33 unsigned int l = lastBin + 1;
34 l = lastBin + l + 1 > num ? num - lastBin - 1 : l;
35 memcpy(dest + lastBin + 1, dest, l * tsize);
36 lastBin += l;
37 }
38}
39
40/**
41 * @class L1Grid
42 *
43 * 2-dimensional grid of pointers.
44 * pointers to (y,z)-like objects are assigned to the corresponding grid bin
45 * used by L1Tracker to speed-up the hit operations
46 * grid axis are named Z,Y to be similar to TPC row coordinates.
47 */
48class L1Grid
49{
50 public:
52 : fN(0)
53 , fNy(0)
54 , fNz(0)
55 , fYMinOverStep(0.)
56 , fZMinOverStep(0.)
57 , fStepYInv(0.)
58 , fStepZInv(0.)
59 , fFirstHitInBin(NULL)
60 {}
61
63 {
65 delete[] fFirstHitInBin;
66 }
67
68 void Create(float yMin, float yMax, float zMin, float zMax, float sy, float sz);
69 void Fill(const L1HitPoint* points, THitI n); // call after sort
70
71 int GetBin(float Y, float Z) const;
72
73 unsigned int GetBinBounded(const float& Y, const float& Z) const;
74 void GetBinBounded(const float& Y, const float& Z, unsigned short* bY, unsigned short* bZ) const;
75 void GetBinBounds(unsigned int iBin, float& Ymin, float& Ymax, float& Zmin, float& Zmax) const;
76
77 unsigned int N() const { return fN; }
78 unsigned short Ny() const { return fNy; }
79 unsigned short Nz() const { return fNz; }
80
81 THitI FirstHitInBin(int i) const { return fFirstHitInBin[i]; }
82
83 private:
84 unsigned int fN; //* total N bins
85 unsigned short fNy; //* N bins in Y
86 unsigned short fNz; //* N bins in Z
87 float fYMinOverStep; //* minimal Y value * fStepYInv
88 float fZMinOverStep; //* minimal Z value * fStepZInv
89 float fStepYInv; //* inverse bin size in Y
90 float fStepZInv; //* inverse bin size in Z
91
93
94 L1Grid(const L1Grid&);
96};
97
98inline unsigned int L1Grid::GetBinBounded(const float& Y, const float& Z) const
99{
100 //* get the bin pointer
101
102 unsigned short yBin, zBin;
103 GetBinBounded(Y, Z, &yBin, &zBin);
104 return (unsigned int)zBin * (unsigned int)fNy + (unsigned int)yBin;
105}
106
107inline void L1Grid::GetBinBounded(const float& Y, const float& Z, unsigned short* bY, unsigned short* bZ) const
108{
109 const float& yBin = (Y * fStepYInv - fYMinOverStep);
110 const float& zBin = (Z * fStepZInv - fZMinOverStep);
111
112 *bY = max(0.f, min(float(fNy - 1), yBin));
113 *bZ = max(0.f, min(float(fNz - 1), zBin));
114}
115
116inline void L1Grid::Create(float yMin, float yMax, float zMin, float zMax, float sy, float sz)
117{
118 //* Create the grid
119 fStepYInv = 1.f / sy;
120 fStepZInv = 1.f / sz;
121
122 fYMinOverStep = yMin * fStepYInv;
123 fZMinOverStep = zMin * fStepZInv;
124
125 fNy = static_cast<unsigned short>(yMax * fStepYInv - fYMinOverStep + 1.f);
126 fNz = static_cast<unsigned short>(zMax * fStepZInv - fZMinOverStep + 1.f);
127
128 unsigned int Nold = fN;
129 fN = fNy * fNz;
130
131 if (Nold < fN || Nold == 0) {
132 delete[] fFirstHitInBin;
134 new THitI[fN + 1]; // one extra bin is needed by area to determine number of hits in the last bin
135 }
136}
137
138inline void L1Grid::Fill(const L1HitPoint* points, THitI n) // call after sort
139{
140 unsigned int lastBin = 0;
141 fFirstHitInBin[lastBin] = 0;
142 for (THitI i = 0; i < n; i++) {
143 const unsigned int currBin = GetBinBounded(points[i].Xs(), points[i].Ys());
144 L1_assert(lastBin <= currBin);
145 memset(fFirstHitInBin + lastBin + 1, i, currBin - lastBin);
146 lastBin = currBin;
147 }
148 memset(fFirstHitInBin + lastBin + 1, n, fN - lastBin);
149 // for( THitI i = 0; i < fN+1; i++ ) cout << fFirstHitInBin[i] << " ";
150 // cout << endl;
151}
152
153inline int L1Grid::GetBin(float Y, float Z) const
154{
155 //* get the bin pointer
156 const int yBin = static_cast<int>(Y * fStepYInv - fYMinOverStep);
157 const int zBin = static_cast<int>(Z * fStepZInv - fZMinOverStep);
158 assert(yBin >= 0);
159 assert(zBin >= 0);
160 assert(yBin < static_cast<int>(fNy));
161 assert(zBin < static_cast<int>(fNz));
162 const int bin = zBin * fNy + yBin;
163 return bin;
164}
165
166inline void L1Grid::GetBinBounds(unsigned int iBin, float& Ymin, float& Ymax, float& Zmin, float& Zmax) const
167{
168 int zBin = iBin / fNy;
169 int yBin = iBin % fNy;
170 Ymin = (fYMinOverStep + yBin) / fStepYInv;
171 Zmin = (fZMinOverStep + zBin) / fStepZInv;
172 Ymax = Ymin + 1. / fStepYInv;
173 Zmax = Zmin + 1. / fStepZInv;
174}
175
176#endif
#define L1_assert(v)
Definition CbmL1Def.h:49
void memset(T *dest, T i, size_t num)
Copy to memory block [@dest, @dest+@num] num number of times the value of i of type @T with size @typ...
Definition L1Grid.h:27
unsigned int THitI
Definition L1StsHit.h:6
int i
Definition P4_F32vec4.h:22
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:30
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition P4_F32vec4.h:31
unsigned int fN
Definition L1Grid.h:84
void Create(float yMin, float yMax, float zMin, float zMax, float sy, float sz)
Definition L1Grid.h:116
unsigned int N() const
Definition L1Grid.h:77
float fStepZInv
Definition L1Grid.h:90
L1Grid(const L1Grid &)
unsigned short fNy
Definition L1Grid.h:85
THitI FirstHitInBin(int i) const
Definition L1Grid.h:81
float fYMinOverStep
Definition L1Grid.h:87
~L1Grid()
Definition L1Grid.h:62
THitI * fFirstHitInBin
Definition L1Grid.h:92
unsigned short Nz() const
Definition L1Grid.h:79
unsigned short fNz
Definition L1Grid.h:86
unsigned int GetBinBounded(const float &Y, const float &Z) const
Definition L1Grid.h:98
int GetBin(float Y, float Z) const
Definition L1Grid.h:153
float fZMinOverStep
Definition L1Grid.h:88
void GetBinBounds(unsigned int iBin, float &Ymin, float &Ymax, float &Zmin, float &Zmax) const
Definition L1Grid.h:166
L1Grid & operator=(const L1Grid &)
float fStepYInv
Definition L1Grid.h:89
void Fill(const L1HitPoint *points, THitI n)
Definition L1Grid.h:138
L1Grid()
Definition L1Grid.h:51
unsigned short Ny() const
Definition L1Grid.h:78
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362
Definition json.hpp:4446
contain strips positions and coordinates of hit
Definition L1HitPoint.h:9