CbmRoot
Loading...
Searching...
No Matches
CaSearchWindowMap.h
Go to the documentation of this file.
1/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergey Gorbunov, Sergei Zharko [committer] */
4
9
10#pragma once // include this header only once per compilation unit
11
12#include <boost/serialization/array.hpp>
13#include <boost/serialization/string.hpp>
14
15#include <algorithm>
16#include <cmath>
17#include <tuple>
18#include <vector>
19
20namespace cbm::algo::ca
21{
25 public:
26 struct SearchWindow {
27 float xMin;
28 float xMax;
29 float yMin;
30 float yMax;
31
32 public:
34 std::string ToString() const;
35 };
36
38 SearchWindowMap() = default;
39
41 ~SearchWindowMap() = default;
42
44 void SetRange(float xMin, float xMax, int xNbins, float yMin, float yMax, int yNbins)
45 {
46 fXmin = xMin;
47 fXmax = xMax;
48 fXnBins = xNbins;
49 fYmin = yMin;
50 fYmax = yMax;
51 fYnBins = yNbins;
52 fNbins = xNbins * yNbins;
53 fBins.clear();
54 fBins.resize(fNbins);
55 }
56
58 void Clear()
59 {
60 for (auto& bin : fBins) {
61 bin.dx = 0.f;
62 bin.dy = 0.f;
63 }
64 }
65
67 void Update(float x, float y, float dx, float dy, float ms)
68 {
69 auto& bin = fBins[GetBin(x, y)];
70 bin.dx = std::max(bin.dx, std::fabs(dx));
71 bin.dy = std::max(bin.dy, std::fabs(dy));
72 bin.ms = std::max(bin.ms, std::fabs(ms));
73 }
74
76 int GetBin(float x, float y) const
77 {
78 int binX = (x - fXmin) / (fXmax - fXmin) * fXnBins;
79 int binY = (y - fYmin) / (fYmax - fYmin) * fYnBins;
80 binX = std::clamp(binX, 0, fXnBins - 1);
81 binY = std::clamp(binY, 0, fYnBins - 1);
82 return binX * fYnBins + binY;
83 }
84
86 SearchWindow GetSearchWindow(float x, float y) const
87 {
88 auto& b = fBins[GetBin(x, y)];
89 return {x - b.dx, x + b.dx, y - b.dy, y + b.dy};
90 };
91
92 std::tuple<SearchWindow, float> GetSearchWindowAndMs(float x, float y) const
93 {
94 auto& b = fBins[GetBin(x, y)];
95 return {{x - b.dx, x + b.dx, y - b.dy, y + b.dy}, b.ms};
96 };
97
99 std::string ToString() const;
100
101 // TODO: make the members private
102 public:
103 struct BinData {
104 float dx{0.f};
105 float dy{0.f};
106 float ms{0.f};
107
110 template<class Archive>
111 void serialize(Archive& ar, const unsigned int)
112 {
113 ar& dx;
114 ar& dy;
115 ar& ms;
116 }
117 };
118
119 float fXmin{0.f};
120 float fXmax{0.f};
121 int fXnBins{0};
122 float fYmin{0.f};
123 float fYmax{0.f};
124 int fYnBins{0};
125 int fNbins{0};
126 std::vector<BinData> fBins{};
127
130 template<class Archive>
131 void serialize(Archive& ar, const unsigned int)
132 {
133 ar& fXmin;
134 ar& fXmax;
135 ar& fXnBins;
136 ar& fYmin;
137 ar& fYmax;
138 ar& fYnBins;
139 ar& fNbins;
140 ar& fBins;
141 }
142 };
143} // namespace cbm::algo::ca
int fYnBins
Number of bins in Y.
SearchWindow GetSearchWindow(float x, float y) const
void SetRange(float xMin, float xMax, int xNbins, float yMin, float yMax, int yNbins)
Constructor.
int fXnBins
Number of bins in X.
int GetBin(float x, float y) const
Get bin index.
std::vector< BinData > fBins
Bin data.
std::string ToString() const
String representation of the contents.
SearchWindowMap()=default
Default constructor.
void serialize(Archive &ar, const unsigned int)
int fNbins
Total number of bins.
void Update(float x, float y, float dx, float dy, float ms)
Update the map.
~SearchWindowMap()=default
Destructor.
friend class boost::serialization::access
Serialization function.
std::tuple< SearchWindow, float > GetSearchWindowAndMs(float x, float y) const
TODO: SZh 8.11.2022: add selection of parameterisation.
Definition CaBranch.h:14
friend class boost::serialization::access
Serialization function.
void serialize(Archive &ar, const unsigned int)
std::string ToString() const
String representation of the contents.