CbmRoot
Loading...
Searching...
No Matches
KfMaterialMap.h
Go to the documentation of this file.
1/* Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Igor Kulakov, Sergey Gorbunov, Andrey Lebedev, Sergei Zharko [committer] */
4
5#pragma once // include this header only once per compilation unit
6
7// NOTE: No dependency from CaCore is allowed
8//#include "CaSimd.h"
9//#include "CaUtils.h"
11#include "KfDefs.h"
12#include "KfUtils.h"
13
14#include <boost/serialization/vector.hpp>
15
16#include <iomanip>
17#include <sstream>
18#include <string>
19#include <type_traits>
20#include <vector>
21
22//TODO: rewrite
23namespace cbm::algo::kf
24{
27 class alignas(VcMemAlign) MaterialMap {
28 public:
30 MaterialMap() = default;
31
38 MaterialMap(int nBins, float xyMax, float zRef, float zMin, float zMax);
39
41 MaterialMap(const MaterialMap& other) = default;
42
44 MaterialMap& operator=(const MaterialMap& other) = default;
45
47 MaterialMap(MaterialMap&& other) noexcept;
48
50 MaterialMap& operator=(MaterialMap&& other) noexcept;
51
53 ~MaterialMap() noexcept = default;
54
58 void Add(const MaterialMap& other, float zTarg = defs::Undef<float>);
59
61 int GetBin(float x, float y) const;
62
64 int GetNbins() const { return fNbins; }
65
67 float GetXYmax() const { return fXYmax; }
68
70 float GetZref() const { return fZref; }
71
73 float GetZmin() const { return fZmin; }
74
76 float GetZmax() const { return fZmax; }
77
82 template<typename I>
83 I GetThicknessX0(const I& x, const I& y) const
84 {
85 if constexpr (std::is_same_v<I, fvec>) {
86 fvec res;
87 for (size_t i = 0; i < utils::simd::Size<I>(); ++i) {
88 res[i] = GetThicknessX0(x[i], y[i]);
89 }
90 return res;
91 }
92 else {
93 I xNew = (x < fXYmax && x >= -fXYmax) ? x : 0;
94 I yNew = (y < fXYmax && y >= -fXYmax) ? y : 0;
95 int i = static_cast<int>((xNew + fXYmax) * fFactor);
96 int j = static_cast<int>((yNew + fXYmax) * fFactor);
97 i = (i < fNbins && i >= 0) ? i : fNbins / 2;
98 j = (j < fNbins && j >= 0) ? j : fNbins / 2;
99 return fTable[i + j * fNbins];
100 }
101 }
102
106 template<typename I>
107 I GetBinThicknessX0(int iGlob) const
108 {
109 if constexpr (std::is_same_v<I, fvec>) {
110 fvec res;
111 for (size_t i = 0; i < utils::simd::Size<I>(); ++i) {
112 res[i] = GetBinThicknessX0<fscal>(iGlob);
113 }
114 return res;
115 }
116 else {
117 return fTable[iGlob];
118 }
119 }
120
125 template<typename I>
126 I GetBinThicknessX0(int iX, int iY) const
127 {
128 return GetBinThicknessX0<I>(iX + iY * fNbins);
129 }
130
132 bool IsUndefined() const
133 {
134 return utils::IsUndefined(fNbins) || utils::IsUndefined(fXYmax * fFactor * fZref * fZmin * fZmax);
135 }
136
139 void Rebin(int factor);
140
148 void SetRadThickBin(int iBinX, int iBinY, float thickness) { fTable[iBinX + fNbins * iBinY] = thickness; }
149
151 void Swap(MaterialMap& other) noexcept;
152
156 std::string ToString(int indentLevel = 0, int verbose = 1) const;
157
159 friend bool operator<(const MaterialMap& lhs, const MaterialMap& rhs) { return lhs.fZref < rhs.fZref; }
160
161 private:
164 void CheckConsistency() const;
165
166
167 int fNbins = defs::Undef<int>;
168 float fXYmax = defs::Undef<float>;
169 float fFactor = defs::Undef<float>;
170 float fZref = defs::Undef<float>;
171 float fZmin = defs::Undef<float>;
172 float fZmax = defs::Undef<float>;
173 std::vector<float> fTable{};
174
176 friend class boost::serialization::access;
177 template<class Archive>
178 void serialize(Archive& ar, const unsigned int)
179 {
180 ar& fNbins;
181 ar& fXYmax;
182 ar& fFactor;
183 ar& fZref;
184 ar& fZmin;
185 ar& fZmax;
186 ar& fTable;
187 }
188 };
189} // namespace cbm::algo::kf
std::string ToString(ECbmModuleId modId)
Definition CbmDefs.cxx:70
bool Add(const std::vector< litfloat > &a, const std::vector< litfloat > &b, std::vector< litfloat > &c)
Common constant definitions for the Kalman Filter library.
A map of station thickness in units of radiation length (X0) to the specific point in XY plane.
float GetXYmax() const
Gets radius of the material table [cm].
MaterialMap & operator=(const MaterialMap &other)=default
Copy assignment operator.
float GetZmin() const
Gets minimal Z of the collected material [cm].
~MaterialMap() noexcept=default
Destructor.
float GetZref() const
Gets reference Z of the material [cm].
float fZref
Reference Z of the collected material [cm].
void SetRadThickBin(int iBinX, int iBinY, float thickness)
Sets value of material thickness in units of X0 for a given cell of the material table.
MaterialMap(const MaterialMap &other)=default
Copy constructor.
MaterialMap()=default
Default constructor.
I GetBinThicknessX0(int iGlob) const
Gets material thickness in units of radiational length X0.
friend bool operator<(const MaterialMap &lhs, const MaterialMap &rhs)
Comparison operator (material map ordering by fZref)
I GetThicknessX0(const I &x, const I &y) const
Gets material thickness in units of radiational length X0.
void serialize(Archive &ar, const unsigned int)
float GetZmax() const
Gets maximal Z of the collected material [cm].
bool IsUndefined() const
Function to test the instance for NaN.
I GetBinThicknessX0(int iX, int iY) const
Gets material thickness in units of radiational length X0.