BmnRoot
Loading...
Searching...
No Matches
L1HitArea.h
Go to the documentation of this file.
1#ifndef L1HitArea_H
2#define L1HitArea_H
3
4#include "L1Grid.h"
5
6#include "CbmL1Def.h"
7
8struct L1Grid;
9class L1Row;
10class L1SliceData;
11
13{
14 public:
15
16 L1HitArea( const L1Grid & grid, float y, float z, float dy, float dz );
17
22 bool GetNext( THitI& i );
23
24 protected:
25 const L1Grid &fGrid;
26
27 unsigned short fBZmax; // maximal Z bin index
28 unsigned short fBDY; // Y distance of bin indexes
29 unsigned int fIndYmin; // minimum index for
30 unsigned short fIz; // current Z bin index (incremented while iterating)
31 THitI fHitYlst; // last possible hit index in current z-line
32 THitI fIh; // hit index iterating inside the bins
33 int fNy; // Number of bins in Y direction
34};
35
36inline L1HitArea::L1HitArea( const L1Grid & grid, float y, float z, float dy, 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{
46 const float minY = y - dy;
47 const float maxY = y + dy;
48 const float minZ = z - dz;
49 const float maxZ = z + dz;
50 unsigned short bYmin, bZmin, bYmax; // boundary bin indexes
51 fGrid.GetBinBounded( minY, minZ, &bYmin, &bZmin );
52 fGrid.GetBinBounded( maxY, maxZ, &bYmax, &fBZmax );
53
54 fBDY = ( bYmax - bYmin + 1 ); // bin index span in y direction
55
56 fIndYmin = ( bZmin * fNy + bYmin ); // same as grid.GetBin(fMinY, fMinZ), i.e. the smallest bin index of interest
57 // fIndYmin + fBDY - 1 then is the largest bin index of interest with the same Z
58
59 fGrid.GetBinBounds( fIndYmin, y, dy, z, dz );
60
61 fIz = bZmin;
62
65
66 // const unsigned int hitLst = fGrid.FirstHitInBin( fBZmax * fNy + bZmin + 1 );
67 // cout << fIh << " " << hitLst << endl;
68 // if ( fIh >= hitLst ) fIz = fBZmax + 1; // finish area in one step
69
70 // cout // << fBZmax << " " << fBDY << " " << fIndYmin << " " << fIz << " " << fHitYlst << " " << fIh << endl; // dbg
71 // << "HitArea created:\n"
72 // << y << " " << z << endl
73 // << "bYmin: " << bYmin << "\n"
74 // << "bZmin: " << bZmin << "\n"
75 // << "bYmax: " << bYmax << "\n"
76 // << "fBZmax: " << fBZmax << "\n"
77 // << "fBDY: " << fBDY << "\n"
78 // << "fIndYmin: " << fIndYmin << "\n"
79 // << "fIz: " << fIz << "\n"
80 // << "fHitYlst: " << fHitYlst << "\n"
81 // << "fIh: " << fIh << "\n"
82 // << "fNy: " << fNy << "\n"
83 // << "Nz " << fGrid.Nz() << std::endl;
84 L1_ASSERT ( fIndYmin + fBDY < fGrid.N()+1, fIndYmin << " + " << fBDY << " < " << fGrid.N());
85}
86
87inline bool L1HitArea::GetNext( THitI& i )
88{
89 bool yIndexOutOfRange = fIh >= fHitYlst; // current y is not in the area
90 bool nextZIndexOutOfRange = (fIz >= fBZmax); // there isn't any new z-line
91
92 if ( yIndexOutOfRange && nextZIndexOutOfRange ) { // all iterators are over the end
93 return false;
94 }
95
96 // at least one entry in the vector has (fIh >= fHitYlst && fIz < fBZmax)
97 bool needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
98
99 // skip as long as fIh is outside of the interesting bin y-index
100 while ( ISLIKELY( needNextZ ) ) {
101 fIz++; // get new z-line
102 // get next hit
103 fIndYmin += fNy;
104 fIh = fGrid.FirstHitInBin( fIndYmin ); // get first hit in cell, if z-line is new
106
107 yIndexOutOfRange = fIh >= fHitYlst;
108 nextZIndexOutOfRange = (fIz >= fBZmax);
109 needNextZ = yIndexOutOfRange && !nextZIndexOutOfRange;
110 }
111
112 L1_ASSERT ( fIh < fGrid.FirstHitInBin(fGrid.N()) || yIndexOutOfRange, fIh << " < " << fGrid.FirstHitInBin(fGrid.N()-1) << " || " << yIndexOutOfRange);
113
114 i = fIh; // return
115 fIh++; // go to next
116 return !yIndexOutOfRange;
117}
118
119#endif
#define ISLIKELY( x)
Definition CbmL1Def.h:36
#define L1_ASSERT(v, msg)
Definition CbmL1Def.h:44
unsigned int THitI
Definition L1StsHit.h:6
int i
Definition P4_F32vec4.h:22
unsigned int N() const
Definition L1Grid.h:63
THitI FirstHitInBin(int i) const
Definition L1Grid.h:67
unsigned int GetBinBounded(const float &Y, const float &Z) const
Definition L1Grid.h:85
void GetBinBounds(unsigned int iBin, float &Ymin, float &Ymax, float &Zmin, float &Zmax) const
Definition L1Grid.h:152
unsigned int fIndYmin
Definition L1HitArea.h:29
bool GetNext(THitI &i)
Definition L1HitArea.h:87
THitI fIh
Definition L1HitArea.h:32
L1HitArea(const L1Grid &grid, float y, float z, float dy, float dz)
Definition L1HitArea.h:36
unsigned short fBDY
Definition L1HitArea.h:28
unsigned short fBZmax
Definition L1HitArea.h:27
THitI fHitYlst
Definition L1HitArea.h:31
const L1Grid & fGrid
Definition L1HitArea.h:25
unsigned short fIz
Definition L1HitArea.h:30