CbmRoot
Loading...
Searching...
No Matches
KfFieldValue.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: Sergei Zharko [committer] */
4
9
10#pragma once
11
12#include "KfDefs.h"
13#include "KfMath.h"
14#include "KfUtils.h"
15
16#include <boost/serialization/access.hpp>
17#include <boost/serialization/array.hpp>
18
19#include <array>
20#include <functional>
21#include <string>
22#include <tuple>
23
24namespace cbm::algo::kf
25{
26
30 template<typename T>
31 class alignas(VcMemAlign) FieldValue {
32 template<typename>
33 friend class FieldValue;
34
35 public:
38 FieldValue() = default;
39
45 template<typename I>
46 FieldValue(const I& bx, const I& by, const I& bz)
47 : fB({utils::simd::Cast<I, T>(bx), utils::simd::Cast<I, T>(by), utils::simd::Cast<I, T>(bz)})
48 {
49 }
50
53 template<typename I>
54 FieldValue(const FieldValue<I>& other) : fB(utils::simd::Cast<I, T, 3>(other.fB))
55 {
56 }
57
59 ~FieldValue() = default;
60
62 FieldValue& operator=(const FieldValue& other) = default;
63
69 template<typename I>
70 void Set(const I& bx, const I& by, const I& bz)
71 {
72 fB[0] = utils::simd::Cast<I, T>(bx);
73 fB[1] = utils::simd::Cast<I, T>(by);
74 fB[2] = utils::simd::Cast<I, T>(bz);
75 }
76
80 void SetSimdEntries(const FieldValue& other, const kf::utils::masktype<T>& mask)
81 {
82 for (size_t iD = 0; iD < fB.size(); ++iD) {
83 this->fB[iD] = kf::utils::iif(mask, other.fB[iD], this->fB[iD]);
84 }
85 }
86
89 [[gnu::always_inline]] std::tuple<T, T, T> Get() const { return std::make_tuple(fB[0], fB[1], fB[2]); }
90
92 [[gnu::always_inline]] T GetAbsSq() const { return fB[0] * fB[0] + fB[1] * fB[1] + fB[2] * fB[2]; }
93
95 [[gnu::always_inline]] T GetAbs() const { return std::sqrt(this->GetAbsSq()); }
96
99 [[gnu::always_inline]] T GetComponent(int iD) const { return fB[iD]; }
100
102 [[gnu::always_inline]] T GetBx() const { return fB[0]; }
103
105 [[gnu::always_inline]] T GetBy() const { return fB[1]; }
106
108 [[gnu::always_inline]] T GetBz() const { return fB[2]; }
109
111 [[gnu::always_inline]] bool IsZero() const
112 {
113 auto bZero = this->GetAbsSq() <= defs::MinField<T> * defs::MinField<T>;
114 if constexpr (std::is_same_v<T, fvec>) {
115 return bZero.isFull();
116 }
117 else {
118 return bZero;
119 }
120 }
121
123 void CheckConsistency() const;
124
125 // TODO (?): Provide setters/accessors
126
132 [[gnu::always_inline]] void SetSimdEntry(double bx, double by, double bz, size_t i)
133 {
134 utils::simd::SetEntry(fB[0], bx, i); //B.x[i] = bx;
135 utils::simd::SetEntry(fB[1], by, i); //B.y[i] = by;
136 utils::simd::SetEntry(fB[2], bz, i); //B.z[i] = bz;
137 }
138
140 std::string ToString(int indentLevel = 0) const;
141
142 private:
144 friend class boost::serialization::access;
145 template<class Archive>
146 void serialize(Archive& ar, const unsigned int)
147 {
148 ar& fB;
149 }
150
153 {utils::simd::Cast<float, T>(0.F), utils::simd::Cast<float, T>(0.F), utils::simd::Cast<float, T>(0.F)}};
154 };
155
156} // namespace cbm::algo::kf
std::string ToString(ECbmModuleId modId)
Definition CbmDefs.cxx:70
Common constant definitions for the Kalman Filter library.
Collection of generic mathematical methods.
Magnetic flux density vector.
FieldValue()=default
Default constructor.
void serialize(Archive &ar, const unsigned int)
FieldValue & operator=(const FieldValue &other)=default
Copy assignment operator.
FieldValue(const I &bx, const I &by, const I &bz)
Constructor from components.
T GetComponent(int iD) const
Gets component by index.
GeoVector_t< T > fB
Magnetic flux vector [kG].
T GetBz() const
Gets magnetic flux density z-component [kG].
FieldValue(const FieldValue< I > &other)
Copy constructor.
T GetAbsSq() const
Gets squared absolute magnetic flux [kG2].
void SetSimdEntries(const FieldValue &other, const kf::utils::masktype< T > &mask)
Combines the current magnetic field value with another one using a mask.
T GetBx() const
Gets magnetic flux x-component [kG].
std::tuple< T, T, T > Get() const
Gets magnetic flux density x, y, z-components [kG].
T GetBy() const
Gets magnetic flux density y-component [kG].
bool IsZero() const
Checks, if the field value is zero (negligible)
~FieldValue()=default
Destructor.
void Set(const I &bx, const I &by, const I &bz)
Constructor from components.
void SetSimdEntry(double bx, double by, double bz, size_t i)
Sets magnetic flux density components to the field function.
T GetAbs() const
Gets absolute magnetic flux [kG].
typename std::conditional< std::is_same< T, fvec >::value, fmask, bool >::type masktype
Definition KfUtils.h:27
std::array< T, 3 > GeoVector_t
Geometry (spatial) vector.
Definition KfDefs.h:62