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 = default;
48
50 MaterialMap& operator=(MaterialMap&& other) noexcept = default;
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 {
135 }
136
139 void Rebin(int factor);
140
148 void SetRadThickBin(int iBinX, int iBinY, float thickness) { fTable[iBinX + fNbins * iBinY] = thickness; }
149
153 std::string ToString(int indentLevel = 0, int verbose = 1) const;
154
156 friend bool operator<(const MaterialMap& lhs, const MaterialMap& rhs) { return lhs.fZref < rhs.fZref; }
157
158 private:
161 void CheckConsistency() const;
162
163
170 std::vector<float> fTable{};
171
173 friend class boost::serialization::access;
174 template<class Archive>
175 void serialize(Archive& ar, const unsigned int)
176 {
177 ar& fNbins;
178 ar& fXYmax;
179 ar& fFactor;
180 ar& fZref;
181 ar& fZmin;
182 ar& fZmax;
183 ar& fTable;
184 }
185 };
186} // namespace cbm::algo::kf
std::string ToString(CbmCutId id)
Convert CbmCutId to a string representation.
Definition CbmCutId.cxx:7
Common constant definitions for the Kalman Filter library.
float GetXYmax() const
Gets radius of the material table [cm].
std::vector< float > fTable
Material budget table.
MaterialMap & operator=(const MaterialMap &other)=default
Copy assignment operator.
float GetZmin() const
Gets minimal Z of the collected material [cm].
float fFactor
Util. var. for the conversion of point coordinates to row/column id.
int fNbins
Number of rows (== N columns) in the material budget table.
~MaterialMap() noexcept=default
Destructor.
float GetZref() const
Gets reference Z of the material [cm].
MaterialMap & operator=(MaterialMap &&other) noexcept=default
Move assignment operator.
float fXYmax
Size of the station in x and y dimensions [cm].
float fZmax
Minimal Z of the collected material [cm].
float fZref
Reference Z of the collected material [cm].
int GetNbins() const
Gets number of bins (rows or columns) of the material table.
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(MaterialMap &&other) noexcept=default
Move constructor.
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.
int GetBin(float x, float y) const
Gets bin index for (x,y). Returns -1 when outside of the map.
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.
float fZmin
Minimal Z of the collected material [cm].
void Add(const MaterialMap &other, float zTarg=defs::Undef< float >)
Adds material layer.
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.
constexpr T2 Undef
Undefined values.
Definition KfDefs.h:218
bool IsUndefined(const T &val)
Checks whether a variable of a particular type defined.
Definition KfUtils.h:78