19#include <boost/serialization/access.hpp>
20#include <boost/serialization/array.hpp>
21#include <boost/serialization/optional.hpp>
22#include <boost/serialization/split_free.hpp>
46 static std::tuple<double, double, double>
UndefField(
double,
double,
double);
84 template<
typename T, EFieldMode FldMode>
94 template<
typename, EFieldMode>
111 this->
Set(b0, b1, b2);
120 for (
size_t iDim = 0; iDim <
fCoeff.size(); ++iDim) {
121 for (
size_t iPow = 0; iPow <
fCoeff[iDim].size(); ++iPow) {
198 std::string
ToString(
int indentLevel = 0,
int verbose = 1)
const;
210 friend class boost::serialization::access;
211 template<
class Archive>
226 template<
typename, EFieldMode>
272 assert(
"cbm::algo::kf::ConcreteFieldRegion<T, EFieldMode::Original>::GetDoubleIntegrals() is not implemented");
290 std::string
ToString(
int indentLevel = 0,
int verbose = 1)
const;
312 template<EFieldMode Mode>
379 template<EFieldMode FieldMode>
382 return std::get_if<ConcreteFieldRegion_t<FieldMode>>(&
fFrVariant);
388 template<EFieldMode FieldMode>
391 return std::get_if<ConcreteFieldRegion_t<FieldMode>>(&
fFrVariant);
397 return kf::visit([&x1, &y1, &z1, &x2, &y2, &z2](
398 const auto& c) -> std::tuple<T, T, T> {
return c.GetDoubleIntegrals(x1, y1, z1, x2, y2, z2); },
405 return kf::visit([](
const auto& c) {
return std::decay_t<
decltype(c)>
::Mode(); },
fFrVariant);
415 template<
EFieldMode FieldMode,
typename... Args>
424 template<
typename... Args>
432 __builtin_unreachable();
443 [&b0, &b1, &b2](
auto&& c) ->
void {
454 kf::visit([type](
auto&& c) { c.SetFieldType(type); },
fFrVariant);
462 [&z](
auto&& c) ->
void {
473 kf::visit([](
const auto& c) ->
void {
return c.CheckConsistency(); },
fFrVariant);
479 std::string
ToString(
int indentLevel = 0,
int verbose = 1)
const
482 [indentLevel, verbose](
const auto& c) -> std::string {
return c.ToString(indentLevel, verbose); },
fFrVariant);
489 template<
typename I, EFieldMode FieldMode>
498 template<
class Archive>
499 void load(Archive& ar,
const unsigned int )
503 fFrVariant.template emplace<Interpolated_t>(std::move(fieldRegion));
507 template<
class Archive>
508 void save(Archive& ar,
const unsigned int )
const
510 if (std::holds_alternative<Interpolated_t>(
fFrVariant)) {
514 throw std::logic_error(
"Attempt to serialize a kf::FieldRegion object with fFieldMode == EFieldMode::Original");
519 friend class boost::serialization::access;
520 template<
class Archive>
523 boost::serialization::split_member(ar, *
this, version);
537 for (
size_t i = 0; i < utils::simd::Size<T>(); ++i) {
538 auto [bx, by, bz] = fieldFn(Cast<T, double>(
x, i), Cast<T, double>(
y, i), Cast<T, double>(z, i));
539 B.SetSimdEntry(bx, by, bz, Cast<T, double>(z, i), i);
Common constant definitions for the Kalman Filter library.
Magnetic flux density vector representation.
Collection of generic mathematical methods.
Optimized implementation of std::visit.
FieldRegionVariant_t fFrVariant
A variant of concrete field region.
void save(Archive &ar, const unsigned int) const
Serialization save method.
typename detail::ConcreteFieldRegion< T, Mode > ConcreteFieldRegion_t
std::tuple< T, T, T > GetDoubleIntegrals(T x1, T y1, T z1, T x2, T y2, T z2) const
Gets the double integrals of the field along the track.
ConcreteFieldRegion_t< EFieldMode::Interpolated > Interpolated_t
EFieldType GetFieldType() const
Gets field type.
EFieldMode GetFieldMode() const
Gets field mode.
void Set(const FieldValue< T > &b0, const FieldValue< T > &b1, const FieldValue< T > &b2)
Interpolates the field by three nodal points with the second order polynomial.
ConcreteFieldRegion_t< EFieldMode::Original > Original_t
~FieldRegion()=default
Constructor from a concrete field.
void CheckConsistency() const
Consistency checker.
FieldRegion(const FieldValue< T > &b0, const FieldValue< T > &b1, const FieldValue< T > &b2)
Constructor for interpolated field.
FieldRegion()=default
Default constructor.
FieldRegion & operator=(const FieldRegion &)=default
Copy assignment operator.
std::string ToString(int indentLevel=0, int verbose=1) const
String representation of the class content.
void Shift(T z)
Shifts the coefficients to another first z-coordinate.
typename std::variant< Interpolated_t, Original_t > FieldRegionVariant_t
FieldValue< T > Get(T x, T y, T z) const
Gets the field value in a spatial point on the track.
static constexpr FieldRegion Create(EFieldMode mode, Args... args)
Creates a field region.
static constexpr FieldRegion Create(Args... args)
Creates a field region.
FieldRegion(FieldRegion &&)=default
Move constructor.
FieldRegion(EFieldType type, const FieldFn_t &fieldFn)
Constructor for original field.
void SetFieldType(EFieldType type)
Sets the field type.
static FieldRegion CopyConvert(const FieldRegion< I > &other)
Creates a converted copy of the field with a different floating point type.
FieldRegion(const FieldRegion &)=default
Copy constructor.
FieldRegion(const FieldRegion< I > &other, Tag< FieldMode >)
Constructor from a field region with another floating point type.
void serialize(Archive &ar, const unsigned int version)
ConcreteFieldRegion_t< FieldMode > * GetConcrete()
Gets a pointer to the concrete field instance (mutable access)
void load(Archive &ar, const unsigned int)
Serialization load method.
const ConcreteFieldRegion_t< FieldMode > * GetConcrete() const
Gets a pointer to the concrete field instance (constant access)
FieldRegion & operator=(FieldRegion &&)=default
Move assignment operator.
Magnetic flux density vector.
Handler for the global magnetic field related functions.
static void SetFieldFunction(EFieldType fldType, const FieldFn_t &fn)
Sets global field function.
static EFieldType fgOriginalFieldType
Global field type.
static void ForceUseOfOriginalField(bool v=true)
Forces the use of the original field function.
static std::tuple< double, double, double > UndefField(double, double, double)
Undefined magnetic field function.
static FieldValue< T > GetFieldValue(const FieldFn_t &fieldFn, T x, T y, T z)
Creates a field value object in a spactial point of a generic floating-point type.
static FieldFn_t fgOriginalField
Global variable to store the field function (x,y,z)->(Bx,By,Bz)
static bool IsUsingOriginalFieldForced()
Checks if the original field function is used.
~GlobalField()=delete
Destructor of static class.
static bool fgForceUseOfOriginalField
Flag to force the use of the original field in all field classes.
void Set(const FieldValue< T > &b0, const FieldValue< T > &b1, const FieldValue< T > &b2)
Interpolates the field by three nodal points with the second order polynomial.
EFieldType fFieldType
Field type in a given region.
ConcreteFieldRegion & operator=(const ConcreteFieldRegion &)=default
Copy assignment operator.
T fZfirst
Reference z-coordinate of the field region.
ConcreteFieldRegion(ConcreteFieldRegion &&)=default
Move constructor.
ConcreteFieldRegion(const FieldValue_t &b0, const FieldValue_t &b1, const FieldValue_t &b2)
Constructor from parameters.
ConcreteFieldRegion(const ConcreteFieldRegion< I, EFieldMode::Interpolated > &other)
Copy constructor (with type conversion)
const auto & GetCoefficients() const
Gets the coefficients of the polynomial approximation.
ConcreteFieldRegion(const ConcreteFieldRegion &)=default
Copy constructor (from the same type)
std::array< std::array< T, 3 >, 3 > CoeffArray_t
Approximation coefficients array.
FieldValue< T > Get(T x, T y, T z) const
Gets the field value in a spatial point on the track.
void Shift(T z)
Shifts the coefficients to another first z-coordinate.
friend class ConcreteFieldRegion
EFieldType GetFieldType() const
Gets field type.
void serialize(Archive &ar, const unsigned int)
ConcreteFieldRegion()=default
Default constructor.
static constexpr EFieldMode Mode()
Returns the mode of the field.
void CheckConsistency() const
Consistency checker.
std::tuple< T, T, T > GetDoubleIntegrals(T x1, T y1, T z1, T x2, T y2, T z2) const
Gets the double integrals of the field along the track.
ConcreteFieldRegion & operator=(ConcreteFieldRegion &&)=default
Move assignment operator.
const T & GetZfirst() const
Gets the first z-coordinate of the interpolation.
CoeffArray_t fCoeff
Approximation coefficients.
std::string ToString(int indentLevel=0, int verbose=1) const
String representation of the class content.
void SetFieldType(EFieldType type)
Sets the field type.
void Set(const CoeffArray_t &coeff, T z0)
Set the coefficients of the polynomial approximation.
~ConcreteFieldRegion()=default
Destructor.
FieldValue< T > FieldValue_t
ConcreteFieldRegion & operator=(const ConcreteFieldRegion &)=default
Copy assignment operator.
ConcreteFieldRegion(const ConcreteFieldRegion< I, EFieldMode::Original > &other)
Copy constructor (with type change)
EFieldType fFieldType
Field type in a given region.
ConcreteFieldRegion(ConcreteFieldRegion &&)=default
Move constructor.
FieldValue< T > Get(T x, T y, T z) const
Gets the field value in a spatial point on the track.
ConcreteFieldRegion(EFieldType type, const FieldFn_t &fieldFn)
Constructor.
void CheckConsistency() const
Consistency checker.
friend class ConcreteFieldRegion
std::tuple< T, T, T > GetDoubleIntegrals(T, T, T, T, T, T) const
Gets the double integrals of the field along the track.
static constexpr EFieldMode Mode()
Returns the mode of the field.
ConcreteFieldRegion(const ConcreteFieldRegion &)=default
Copy constructor (from the same type)
std::string ToString(int indentLevel=0, int verbose=1) const
String representation of the class content.
ConcreteFieldRegion & operator=(ConcreteFieldRegion &&)=default
Move assignment operator.
void SetFieldType(EFieldType type)
Sets the field type.
FieldFn_t fFieldFn
Field function: (x,y,z) [cm] -> (Bx,By,Bz) [kG].
EFieldType GetFieldType() const
Gets field type.
ConcreteFieldRegion()=default
Default constructor.
~ConcreteFieldRegion()=default
Destructor.
Concrete representation of the FieldRegion class (primary template)
constexpr auto ZeroFieldFn
Zero magnetic field function.
constexpr T2 Undef
Undefined values.
DataOut Cast(const DataT &val)
Converts a value of type DataT to type DataOut.
EFieldMode
Enumiration for the magnetic field representation variants in the track fitting algorithm.
@ Original
Original magnetic field function.
@ Interpolated
Interpolated magnetic field.
typename Literal< T >::type Literal_t
EFieldType
Magnetic field type in different setup regions.
@ Normal
Field near the tracker subsystem.
std::function< std::tuple< double, double, double >(double, double, double)> FieldFn_t
Magnetic field function type Signature: tuple<Bx, By, Bz>(x, y, z);.
A generic tag for tag dispatching.