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
46 template<typename I>
47 FieldValue(const I& bx, const I& by, const I& bz, const I& z)
50 {
51 }
52
55 template<typename I>
57 : fB(utils::simd::Cast<I, T, 3>(other.fB))
58 , fZ(utils::simd::Cast<I, T>(other.fZ))
59 {
60 }
61
63 ~FieldValue() = default;
64
66 FieldValue& operator=(const FieldValue& other) = default;
67
74 template<typename I>
75 void Set(const I& bx, const I& by, const I& bz, const I& z)
76 {
81 }
82
86 void SetSimdEntries(const FieldValue& other, const kf::utils::masktype<T>& mask)
87 {
88 for (size_t iD = 0; iD < fB.size(); ++iD) {
89 this->fB[iD] = kf::utils::iif(mask, other.fB[iD], this->fB[iD]);
90 }
91 this->fZ = kf::utils::iif(mask, other.fZ, this->fZ);
92 }
93
96 [[gnu::always_inline]] std::tuple<T, T, T> Get() const { return std::make_tuple(fB[0], fB[1], fB[2]); }
97
99 [[gnu::always_inline]] T GetAbsSq() const { return fB[0] * fB[0] + fB[1] * fB[1] + fB[2] * fB[2]; }
100
102 [[gnu::always_inline]] T GetAbs() const { return std::sqrt(this->GetAbsSq()); }
103
106 [[gnu::always_inline]] T GetComponent(int iD) const { return fB[iD]; }
107
109 [[gnu::always_inline]] T GetBx() const { return fB[0]; }
110
112 [[gnu::always_inline]] T GetBy() const { return fB[1]; }
113
115 [[gnu::always_inline]] T GetBz() const { return fB[2]; }
116
118 [[gnu::always_inline]] T GetZ() const { return fZ; }
119
121 [[gnu::always_inline]] bool IsZero() const
122 {
123 auto bZero = this->GetAbsSq() <= defs::MinField<T> * defs::MinField<T>;
124 if constexpr (std::is_same_v<T, fvec>) {
125 return bZero.isFull();
126 }
127 else {
128 return bZero;
129 }
130 }
131
133 void CheckConsistency() const;
134
135 // TODO (?): Provide setters/accessors
136
143 [[gnu::always_inline]] void SetSimdEntry(double bx, double by, double bz, double z, size_t i)
144 {
145 utils::simd::SetEntry(fB[0], bx, i); //B.x[i] = bx;
146 utils::simd::SetEntry(fB[1], by, i); //B.y[i] = by;
147 utils::simd::SetEntry(fB[2], bz, i); //B.z[i] = bz;
149 }
150
152 std::string ToString(int indentLevel = 0) const;
153
154 private:
156 friend class boost::serialization::access;
157 template<class Archive>
158 void serialize(Archive& ar, const unsigned int)
159 {
160 ar& fB;
161 ar& fZ;
162 }
163
167 T fZ{};
168 };
169
170} // 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.
Collection of generic mathematical methods.
FieldValue()=default
Default constructor.
void serialize(Archive &ar, const unsigned int)
FieldValue & operator=(const FieldValue &other)=default
Copy assignment operator.
T GetComponent(int iD) const
Gets component by index.
void Set(const I &bx, const I &by, const I &bz, const I &z)
Constructor from components.
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].
FieldValue(const I &bx, const I &by, const I &bz, const I &z)
Constructor from components.
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].
T GetZ() const
Gets z-coordinate of the spatial point [cm].
bool IsZero() const
Checks, if the field value is zero (negligible)
~FieldValue()=default
Destructor.
void SetSimdEntry(double bx, double by, double bz, double z, size_t i)
Sets magnetic flux density components to the field function.
T GetAbs() const
Gets absolute magnetic flux [kG].
constexpr auto MinField
Minimal (negligible) magnetic field value [kG].
Definition KfDefs.h:213
DataOut Cast(const DataT &val)
Converts a value of type DataT to type DataOut.
Definition KfUtils.h:212
void SetEntry(DataT &out, DataIn in, size_t)
Sets a value at a specific index in the output data.
Definition KfUtils.h:338
typename std::conditional< std::is_same< T, fvec >::value, fmask, bool >::type masktype
Definition KfUtils.h:27
fvec iif(const fmask &m, const fvec &t, const fvec &f)
Definition KfUtils.h:29
std::array< T, 3 > GeoVector_t
Geometry (spatial) vector.
Definition KfDefs.h:165