CbmRoot
Loading...
Searching...
No Matches
CaGrid.cxx
Go to the documentation of this file.
1/* Copyright (C) 2017-2021 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Maksym Zyzak [committer], Valentina Akishina */
4
7
8
9#include "CaGrid.h"
10
11#include "CaHit.h"
12
13#include <algorithm>
14#include <cstring>
15
16
17namespace cbm::algo::ca
18{
19 void Grid::BuildBins(fscal xMin, fscal xMax, fscal yMin, fscal yMax, fscal binWidthX, fscal binWidthY)
20 {
21 fMinX = std::min(xMin, xMax);
22 fMinY = std::min(yMin, yMax);
23
24 xMax = std::max(xMin, xMax);
25 yMax = std::max(yMin, yMax);
26
27 fBinWidthX = binWidthX;
28 fBinWidthY = binWidthY;
29
30 // some sanity checks
31 if (fBinWidthX < 0.001) {
32 fBinWidthX = 0.001;
33 }
34 if (fBinWidthY < 0.001) {
35 fBinWidthY = 0.001;
36 }
37
40
41 fNx = static_cast<int>(std::ceil((xMax - fMinX) / fBinWidthX));
42 fNy = static_cast<int>(std::ceil((yMax - fMinY) / fBinWidthY));
43
44 // some sanity checks
45 if (fNx < 1) fNx = 1;
46 if (fNy < 1) fNy = 1;
47
48 fN = fNx * fNy;
49
50 fEntries.clear();
52 fNofBinEntries.reset(fN + 1, 0);
53 }
54
55
57 const Vector<unsigned char>& hitKeyFlags)
58 {
60 fNofBinEntries.reset(fN + 1, 0);
61
62 int nEntries = 0;
63 for (ca::HitIndex_t ih = 0; ih < nHits; ih++) {
64 const ca::Hit& hit = hits[hitStartIndex + ih];
65 if (!(hitKeyFlags[hit.FrontKey()] || hitKeyFlags[hit.BackKey()])) {
66 fNofBinEntries[GetBin(hit.X(), hit.Y())]++;
67 nEntries++;
68 }
69 }
70
71 fEntries.reset(nEntries);
72
73 for (int bin = 0; bin < fN; bin++) {
75 fNofBinEntries[bin] = 0;
76 }
77 fNofBinEntries[fN] = 0;
78
79 fMaxRangeX = 0.;
80 fMaxRangeY = 0.;
81 fMaxRangeT = 0.;
82
83 for (ca::HitIndex_t ih = 0; ih < nHits; ih++) {
84 const ca::Hit& hit = hits[hitStartIndex + ih];
85 if (!(hitKeyFlags[hit.FrontKey()] || hitKeyFlags[hit.BackKey()])) {
86 int bin = GetBin(hit.X(), hit.Y());
87 fEntries[fFirstBinEntryIndex[bin] + fNofBinEntries[bin]].Set(hit, hitStartIndex + ih);
88 fNofBinEntries[bin]++;
89 fMaxRangeX = std::max(fMaxRangeX, hit.RangeX());
90 fMaxRangeY = std::max(fMaxRangeY, hit.RangeY());
91 fMaxRangeT = std::max(fMaxRangeT, hit.RangeT());
92 }
93 }
94 }
95
97 {
98 int nEntries = 0;
99 fMaxRangeX = 0.;
100 fMaxRangeY = 0.;
101 fMaxRangeT = 0.;
102
103 for (int bin = 0; bin < fN; bin++) {
104 ca::HitIndex_t firstEntryOld = fFirstBinEntryIndex[bin];
105 fFirstBinEntryIndex[bin] = nEntries;
106 fNofBinEntries[bin] = 0;
107 for (ca::HitIndex_t i = firstEntryOld; i < fFirstBinEntryIndex[bin + 1]; i++) {
108 auto entry = fEntries[i];
109 const ca::Hit& hit = hits[entry.GetObjectId()];
110
111 if (!(hitKeyFlags[hit.FrontKey()] || hitKeyFlags[hit.BackKey()])) {
112 fEntries[nEntries] = entry;
113 nEntries++;
114 fNofBinEntries[bin]++;
115 fMaxRangeX = std::max(fMaxRangeX, entry.RangeX());
116 fMaxRangeY = std::max(fMaxRangeY, entry.RangeY());
117 fMaxRangeT = std::max(fMaxRangeT, entry.RangeT());
118 }
119 }
120 }
121 fFirstBinEntryIndex[fN] = nEntries;
122 fNofBinEntries[fN] = 0;
123 fEntries.shrink(nEntries);
124 }
125} // 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)
static vector< vector< QAHit > > hits
void StoreHits(const ca::Vector< ca::Hit > &hits, ca::HitIndex_t hitStartIndex, ca::HitIndex_t nHits, const ca::Vector< unsigned char > &hitKeyFlags)
Store objects in the grid.
Definition CaGrid.cxx:56
fscal fMinY
minimal Y value
Definition CaGrid.h:137
int fNx
N bins in X.
Definition CaGrid.h:133
ca::Vector< ca::GridEntry > fEntries
grid entries with references to the hit index in fWindowHits
Definition CaGrid.h:152
void RemoveUsedHits(const ca::Vector< ca::Hit > &hits, const ca::Vector< unsigned char > &hitKeyFlags)
Remove grid entries that correspond to the used hits.
Definition CaGrid.cxx:96
int GetBin(fscal X, fscal Y) const
Get bin index for (X,Y) point with boundary check.
Definition CaGrid.h:158
fscal fMaxRangeT
maximal entry range in T
Definition CaGrid.h:145
fscal fBinWidthX
bin width in X
Definition CaGrid.h:138
int fNy
N bins in Y.
Definition CaGrid.h:134
void BuildBins(fscal xMin, fscal xMax, fscal yMin, fscal yMax, fscal binWidthX, fscal binWidthY)
Build the grid.
Definition CaGrid.cxx:19
fscal fMaxRangeX
maximal entry range in X
Definition CaGrid.h:143
int fN
— Data members —
Definition CaGrid.h:132
fscal fBinWidthYinv
inverse bin width in Y
Definition CaGrid.h:141
fscal fMaxRangeY
maximal entry range in Y
Definition CaGrid.h:144
fscal fBinWidthY
bin width in Y
Definition CaGrid.h:139
ca::Vector< ca::HitIndex_t > fNofBinEntries
number of hits in the bin
Definition CaGrid.h:150
ca::Vector< ca::HitIndex_t > fFirstBinEntryIndex
index of the first entry in the bin
Definition CaGrid.h:147
fscal fMinX
minimal X value
Definition CaGrid.h:136
fscal fBinWidthXinv
inverse bin width in X
Definition CaGrid.h:140
ca::Hit class describes a generic hit for the CA tracker
Definition CaHit.h:32
HitKeyIndex_t BackKey() const
Get the back key index.
Definition CaHit.h:99
fscal RangeX() const
Get the +/- range of uncertainty of X coordinate.
Definition CaHit.h:126
fscal Y() const
Get the Y coordinate.
Definition CaHit.h:105
fscal RangeY() const
Get the +/- range of uncertainty of Y coordinate.
Definition CaHit.h:129
fscal RangeT() const
Get the +/- range of uncertainty of time.
Definition CaHit.h:132
HitKeyIndex_t FrontKey() const
Get the front key index.
Definition CaHit.h:96
fscal X() const
Get the X coordinate.
Definition CaHit.h:102
void shrink(std::size_t count)
Reduces the vector to a given size.
Definition CaVector.h:150
void reset(std::size_t count, Tinput... value)
Clears vector and resizes it to the selected size with selected values.
Definition CaVector.h:121
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