CbmRoot
Loading...
Searching...
No Matches
CaGridArea.h
Go to the documentation of this file.
1/* Copyright (C) 2012-2020 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Maksym Zyzak, Igor Kulakov [committer] */
4
6
7#pragma once // include this header only once per compilation unit
8
9#include "CaGrid.h"
10#include "CaHit.h"
11#include "CaSimd.h"
12
13namespace cbm::algo::ca
14{
17 class GridArea {
18 public:
25 GridArea(const ca::Grid& grid, fscal x, fscal y, fscal dx, fscal dy);
26
27
32
36 bool GetNextObjectId(ca::HitIndex_t& objectId);
37
40
41 private:
43
44 int fAreaLastBinY{0}; // last Y bin of the area
45 int fAreaNbinsX{0}; // number of area bins in X
46 int fAreaFirstBin{0}; // first bin of the area (left-down corner of the area)
47 int fAreaCurrentBinY{0}; // current Y bin (incremented while iterating)
48 ca::HitIndex_t fCurentEntry{0}; // index of the current entry in fGrid.GetEntries()
49 ca::HitIndex_t fEntriesXend{0}; // end of the hit indices in current y-row
50 int fGridNbinsX{0}; // Number of grid bins in X (copy of fGrid::GetNofBinsX())
51 };
52
53 inline GridArea::GridArea(const ca::Grid& grid, fscal x, fscal y, fscal dx, fscal dy)
54 : fGrid(grid)
55 , fGridNbinsX(fGrid.GetNofBinsX())
56 {
57 int binXmin = fGrid.GetBinX(x - dx);
58 int binXmax = fGrid.GetBinX(x + dx);
59 int binYmin = fGrid.GetBinY(y - dy);
60 int binYmax = fGrid.GetBinY(y + dy);
61
62 fAreaLastBinY = binYmax;
63 fAreaNbinsX = (binXmax - binXmin + 1); // bin index span in x direction
64
65 fAreaFirstBin = (binYmin * fGridNbinsX + binXmin);
66
67 fAreaCurrentBinY = binYmin;
70 }
71
73 {
74 bool xIndexOutOfRange = (fCurentEntry >= fEntriesXend); // current entry is not in the area
75
76 // jump to the next y row if fCurentEntry is outside of the X area
77 while (kfutils::IsUnlikely(xIndexOutOfRange)) {
79 return false;
80 }
81 fAreaCurrentBinY++; // get new y-line
82 fAreaFirstBin += fGridNbinsX; // move the left-down corner of the area to the next y-line
83 fCurentEntry = fGrid.GetFirstBinEntryIndex(fAreaFirstBin); // get first hit in cell, if y-line is new
85 xIndexOutOfRange = (fCurentEntry >= fEntriesXend);
86 }
87 ind = fCurentEntry; // return value
88 fCurentEntry++; // go to next
89 return true;
90 }
91
93 {
94 ca::HitIndex_t entryIndex = 0;
95
96 bool ok = GetNextGridEntry(entryIndex);
97 if (ok) {
98 objectId = fGrid.GetEntries()[entryIndex].GetObjectId();
99 }
100 return ok;
101 }
102
104 {
105 fCurentEntry = 0;
106 fEntriesXend = fGrid.GetEntries().size();
107 fAreaLastBinY = 0;
108 fAreaNbinsX = 0;
109 fAreaFirstBin = 0;
111 }
112
113} // namespace cbm::algo::ca
A class to store hit information in a backet-sorted way on 2D grid.
A generic hit for the CA tracker (header)
Class for accessing objects in the 2D area that are stored in ca::Grid.
Definition CaGridArea.h:17
bool GetNextObjectId(ca::HitIndex_t &objectId)
look up the next object id in the requested area
Definition CaGridArea.h:92
const ca::Grid & fGrid
Definition CaGridArea.h:42
void DoLoopOverEntireGrid()
debug mode: loop over the entire GetEntries() vector ignoring the search area
Definition CaGridArea.h:103
bool GetNextGridEntry(ca::HitIndex_t &ind)
look up the next grid entry in the requested area
Definition CaGridArea.h:72
GridArea(const ca::Grid &grid, fscal x, fscal y, fscal dx, fscal dy)
Constructor.
Definition CaGridArea.h:53
ca::HitIndex_t fCurentEntry
Definition CaGridArea.h:48
ca::HitIndex_t fEntriesXend
Definition CaGridArea.h:49
Class for storing 2d objects in a grid.
Definition CaGrid.h:32
const ca::Vector< ca::GridEntry > & GetEntries() const
Get number of entries in the bin.
Definition CaGrid.h:106
ca::HitIndex_t GetFirstBinEntryIndex(int bin) const
Get index of the first bin entry in fHitsInBin array.
Definition CaGrid.h:100
int GetBinY(fscal Y) const
Get bin Y index with boundary check.
Definition CaGrid.h:170
int GetBinX(fscal X) const
Get bin X index with boundary check.
Definition CaGrid.h:164
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
kf::fscal fscal
Definition CaSimd.h:14
unsigned int HitIndex_t
Index of ca::Hit.
Definition CaHit.h:27
bool IsUnlikely(bool b)
Definition KfUtils.h:72