CbmRoot
L1HitArea.h
Go to the documentation of this file.
1 #ifndef L1HitArea_H
2 #define L1HitArea_H
3 
4 #include "CbmL1Def.h"
5 #include "L1Grid.h"
6 
7 class L1Row;
8 class L1SliceData;
9 
10 class L1HitArea {
11 public:
12  L1HitArea(const L1Grid& grid, float y, float z, float dy, float dz);
13 
18  bool GetNext(THitI& i);
19 
20 protected:
21  const L1Grid& fGrid;
22 
23  unsigned short fBZmax; // maximal Z bin index
24  unsigned short fBDY; // Y distance of bin indexes
25  unsigned int fIndYmin; // minimum index for
26  unsigned short fIz; // current Z bin index (incremented while iterating)
27  THitI fHitYlst; // last possible hit index in current z-line
28  THitI fIh; // hit index iterating inside the bins
29  int fNy; // Number of bins in Y direction
30 };
31 
32 inline L1HitArea::L1HitArea(const L1Grid& grid,
33  float y,
34  float z,
35  float dy,
36  float dz)
37  : fGrid(grid)
38  , fBZmax(0)
39  , fBDY(0)
40  , fIndYmin(0)
41  , fIz(0)
42  , fHitYlst(0)
43  , fIh(0)
44  , fNy(fGrid.Ny()) {
45  const float minY = y - dy;
46  const float maxY = y + dy;
47  const float minZ = z - dz;
48  const float maxZ = z + dz;
49  unsigned short bYmin, bZmin, bYmax; // boundary bin indexes
50  fGrid.GetBinBounded(minY, minZ, bYmin, bZmin);
51  fGrid.GetBinBounded(maxY, maxZ, bYmax, fBZmax);
52 
53  fBDY = (bYmax - bYmin + 1); // bin index span in y direction
54 
55  fIndYmin =
56  (bZmin * fNy
57  + bYmin); // same as grid.GetBin(fMinY, fMinZ), i.e. the smallest bin index of interest
58  // fIndYmin + fBDY - 1 then is the largest bin index of interest with the same Z
59 
60  fGrid.GetBinBounds(fIndYmin, y, dy, z, dz);
61 
62  fIz = bZmin;
63 
66 }
67 
68 inline bool L1HitArea::GetNext(THitI& i) {
69  bool yIndexOutOfRange = fIh >= fHitYlst; // current y is not in the area
70  bool nextZIndexOutOfRange = (fIz >= fBZmax); // there isn't any new z-line
71 
72  if (yIndexOutOfRange
73  && nextZIndexOutOfRange) { // all iterators are over the end
74  return false;
75  }
76 
77  // at least one entry in the vector has (fIh >= fHitYlst && fIz < fBZmax)
78  bool needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
79 
80  // skip as long as fIh is outside of the interesting bin y-index
81  while (ISLIKELY(
82  needNextZ)) { //ISLIKELY to speed the programm and optimise the use of registers
83  fIz++; // get new z-line
84  // get next hit
85  fIndYmin += fNy;
86  fIh =
87  fGrid.FirstHitInBin(fIndYmin); // get first hit in cell, if z-line is new
89 
90  yIndexOutOfRange = fIh >= fHitYlst;
91  nextZIndexOutOfRange = (fIz >= fBZmax);
92  needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
93  }
94 
95  L1_ASSERT(fIh < fGrid.FirstHitInBin(fGrid.N()) || yIndexOutOfRange,
96  fIh << " < " << fGrid.FirstHitInBin(fGrid.N()) << " || "
97  << yIndexOutOfRange);
98  i = fIh; // return
99 
100  fIh++; // go to next
101  return !yIndexOutOfRange;
102 }
103 
105 public:
106  L1HitAreaTime(const L1Grid& grid,
107  float y,
108  float z,
109  float dy,
110  float dz,
111  float t,
112  float dt);
113 
118  bool GetNext(THitI& i);
119 
120 protected:
121  const L1Grid& fGrid;
122 
123  unsigned short fBZmax; // maximal Z bin index
124  unsigned short fBDY; // Y distance of bin indexes
125  unsigned int fIndYmin; // minimum index for
126  unsigned short fIz; // current Z bin index (incremented while iterating)
127  THitI fHitYlst; // last possible hit index in current z-line
128  THitI fIh; // hit index iterating inside the bins
129  int fNy; // Number of bins in Y direction
130  int fNz;
131 
132  unsigned short fBTmax; // maximal Z bin index
133  unsigned short fIt; // current Z bin index (incremented while iterating)
134 
135  unsigned short fBZmin;
136  unsigned short fBYmin;
137 
138 
139  unsigned int fIndZmin; // minimum index for
140 };
141 
143  float y,
144  float z,
145  float dy,
146  float dz,
147  float t,
148  float dt)
149  : fGrid(grid)
150  , fBZmax(0)
151  , fBDY(0)
152  , fIndYmin(0)
153  , fIz(0)
154  , fHitYlst(0)
155  , fIh(0)
156  , fNy(fGrid.Ny())
157  , fNz(fGrid.Nz())
158  , fBTmax(0)
159  , fIt(0)
160  , fBZmin(0)
161  , fBYmin(0)
162  , fIndZmin(0) {
163  const float minY = y - dy;
164  const float maxY = y + dy;
165  const float minZ = z - dz;
166  const float maxZ = z + dz;
167  const float minT = t - dt;
168 
169 
170  const float maxT = t + dt;
171 
172  unsigned short bYmin, bZmin, bYmax, bTmin; // boundary bin indexes
173  fGrid.GetBinBounded(minY, minZ, minT, bYmin, bZmin, bTmin);
174  fGrid.GetBinBounded(maxY, maxZ, maxT, bYmax, fBZmax, fBTmax);
175  fBZmin = bZmin;
176  fBYmin = bYmin;
177 
178 
179  fBDY = (bYmax - bYmin + 1); // bin index span in y direction
180 
181  fIndYmin = (bTmin * fNy * fNz + bZmin * fNy + bYmin);
182 
183  //fGrid.GetBinBounds(fIndYmin, y, dy, z, dz, t, dt);
184 
185  fIz = bZmin;
186 
187  fIt = bTmin;
188 
190 
192 }
193 
195  bool yIndexOutOfRange = fIh >= fHitYlst; // current y is not in the area
196  bool nextZIndexOutOfRange = (fIz >= fBZmax); // there isn't any new z-line
197  bool nextTIndexOutOfRange = (fIt >= fBTmax); // there isn't any new z-line
198 
199 
200  if (yIndexOutOfRange && nextZIndexOutOfRange
201  && nextTIndexOutOfRange) { // all iterators are over the end
202  return false;
203  }
204 
205  // at least one entry in the vector has (fIh >= fHitYlst && fIz < fBZmax)
206  bool needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
207  bool needNextT =
208  yIndexOutOfRange && nextZIndexOutOfRange && !nextTIndexOutOfRange;
209 
210 
211  while (ISLIKELY(
212  (needNextZ)
213  || (needNextT))) { //ISLIKELY to speed the programm and optimise the use of registers
214 
215  if (needNextT) {
216  fIt++;
217  fIz = fBZmin;
218 
219  fIndYmin = (fIt * fNy * fNz + fBZmin * fNy + fBYmin);
221  fIndYmin); // get first hit in cell, if z-line is new
223  } else {
224 
225  fIz++; // get new z-line
226  // get next hit
227  fIndYmin += fNy;
229  fIndYmin); // get first hit in cell, if z-line is new
230 
232  }
233 
234  yIndexOutOfRange = fIh >= fHitYlst;
235  nextZIndexOutOfRange = (fIz >= fBZmax);
236  needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
237 
238  nextTIndexOutOfRange = (fIt >= fBTmax);
239  needNextT =
240  yIndexOutOfRange && nextZIndexOutOfRange && !nextTIndexOutOfRange;
241  }
242 
243  L1_ASSERT(fIh < fGrid.FirstHitInBin(fGrid.N() + 1) || yIndexOutOfRange,
244  fIh << " < " << fGrid.FirstHitInBin(fGrid.N() + 1) << " || "
245  << yIndexOutOfRange);
246  i = fIh; // return
247 
248  fIh++; // go to next
249  return !yIndexOutOfRange;
250 }
251 
252 #endif
L1HitAreaTime::fIt
unsigned short fIt
Definition: L1HitArea.h:133
L1HitArea::fHitYlst
THitI fHitYlst
Definition: L1HitArea.h:27
L1HitAreaTime::fIz
unsigned short fIz
Definition: L1HitArea.h:126
ISLIKELY
#define ISLIKELY(x)
Definition: CbmL1Def.h:40
L1Grid
Definition: L1Grid.h:39
L1HitAreaTime::fNz
int fNz
Definition: L1HitArea.h:130
L1HitAreaTime::fIh
THitI fIh
Definition: L1HitArea.h:128
L1HitArea
Definition: L1HitArea.h:10
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
L1HitAreaTime::GetNext
bool GetNext(THitI &i)
Definition: L1HitArea.h:194
L1Grid::FirstHitInBin
THitI FirstHitInBin(unsigned int i) const
Definition: L1Grid.h:178
L1HitAreaTime::fIndZmin
unsigned int fIndZmin
Definition: L1HitArea.h:139
L1HitAreaTime::fIndYmin
unsigned int fIndYmin
Definition: L1HitArea.h:125
L1HitArea::fNy
int fNy
Definition: L1HitArea.h:29
L1HitAreaTime::fBTmax
unsigned short fBTmax
Definition: L1HitArea.h:132
L1Grid::N
unsigned int N() const
Definition: L1Grid.h:173
L1HitAreaTime::fNy
int fNy
Definition: L1HitArea.h:129
CbmL1Def.h
L1HitAreaTime::fBYmin
unsigned short fBYmin
Definition: L1HitArea.h:136
THitI
unsigned int THitI
Definition: L1StsHit.h:8
L1HitArea::fIh
THitI fIh
Definition: L1HitArea.h:28
L1HitAreaTime::fHitYlst
THitI fHitYlst
Definition: L1HitArea.h:127
L1HitArea::fIz
unsigned short fIz
Definition: L1HitArea.h:26
L1HitAreaTime
Definition: L1HitArea.h:104
L1HitArea::GetNext
bool GetNext(THitI &i)
Definition: L1HitArea.h:68
L1HitArea::fIndYmin
unsigned int fIndYmin
Definition: L1HitArea.h:25
L1HitArea::L1HitArea
L1HitArea(const L1Grid &grid, float y, float z, float dy, float dz)
Definition: L1HitArea.h:32
L1HitArea::fBDY
unsigned short fBDY
Definition: L1HitArea.h:24
L1HitAreaTime::fBZmax
unsigned short fBZmax
Definition: L1HitArea.h:123
L1HitAreaTime::fBDY
unsigned short fBDY
Definition: L1HitArea.h:124
L1HitAreaTime::fGrid
const L1Grid & fGrid
Definition: L1HitArea.h:121
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
L1HitAreaTime::fBZmin
unsigned short fBZmin
Definition: L1HitArea.h:135
L1HitArea::fGrid
const L1Grid & fGrid
Definition: L1HitArea.h:21
L1Grid::GetBinBounds
void GetBinBounds(unsigned int iBin, float &Ymin, float &Ymax, float &Zmin, float &Zmax) const
Definition: L1Grid.h:296
L1HitAreaTime::L1HitAreaTime
L1HitAreaTime(const L1Grid &grid, float y, float z, float dy, float dz, float t, float dt)
Definition: L1HitArea.h:142
L1_ASSERT
#define L1_ASSERT(v, msg)
Definition: CbmL1Def.h:48
L1Grid.h
L1HitArea::fBZmax
unsigned short fBZmax
Definition: L1HitArea.h:23