18#include <boost/serialization/access.hpp>
19#include <boost/serialization/array.hpp>
20#include <boost/serialization/optional.hpp>
21#include <boost/serialization/split_free.hpp>
42 static std::tuple<double, double, double>
UndefField(
double,
double,
double);
80 template<
typename T, EFieldMode FldMode>
89 template<
typename, EFieldMode>
119 return GlobalField::GetFieldValue(fFieldFn,
x,
y, z);
124 const T& ,
const T& ,
const T& )
const
126 assert(
"cbm::algo::kf::FieldRegionBase<T, EFieldMode::Orig>::GetDoubleIntegrals() is not implemented");
127 return {defs::Undef<T>, defs::Undef<T>, defs::Undef<T>};
136 std::string
ToString(
int indentLevel = 0,
int verbose = 1)
const;
148 template<
typename, EFieldMode>
169 this->Set(b0, z0, b1, z1, b2, z2);
175 : fZfirst(utils::simd::Cast<I, T>(other.fZfirst))
177 for (
size_t iDim = 0; iDim < fCoeff.size(); ++iDim) {
178 for (
size_t iPow = 0; iPow < fCoeff[iDim].size(); ++iPow) {
179 fCoeff[iDim][iPow] = utils::simd::Cast<I, T>(other.fCoeff[iDim][iPow]);
198 const T& x2,
const T& y2,
const T& z2)
const;
234 std::string
ToString(
int indentLevel = 0,
int verbose = 1)
const;
242 friend class boost::serialization::access;
243 template<
class Archive>
268 , fFieldType(fldType)
269 , fFieldMode(fldMode)
277 : foFldIntrpl(other.foFldIntrpl.has_value()
280 , foFldOrig(other.foFldOrig.has_value()
283 , fFieldType(other.fFieldType)
284 , fFieldMode(other.fFieldMode)
292 , foFldOrig(
std::nullopt)
297 Set(b0, z0, b1, z1, b2, z2);
303 : foFldIntrpl(
std::make_optional(fld))
304 , foFldOrig(
std::nullopt)
305 , fFieldType(fieldType)
313 : foFldIntrpl(
std::nullopt)
315 , fFieldType(fieldType)
333 return fFieldMode == EFieldMode::Intrpl ? foFldIntrpl->Get(
x,
y, z) : foFldOrig->Get(
x,
y, z);
337 std::tuple<T, T, T>
GetDoubleIntegrals(
const T& x1,
const T& y1,
const T& z1,
const T& x2,
const T& y2,
340 return fFieldMode == EFieldMode::Intrpl ? foFldIntrpl->GetDoubleIntegrals(x1, y1, z1, x2, y2, z2)
341 : foFldOrig->GetDoubleIntegrals(x1, y1, z1, x2, y2, z2);
361 fFieldMode = EFieldMode::Intrpl;
362 fFieldType = EFieldType::Normal;
365 fFieldType = EFieldType::Null;
367 foFldIntrpl->Set(b0, z0, b1, z1, b2, z2);
375 void Shift(
const T& z);
378 void CheckConsistency()
const;
383 std::string
ToString(
int indentLevel = 0,
int verbose = 1)
const;
388 friend class boost::serialization::access;
391 template<
class Archive>
392 void load(Archive& ar,
const unsigned int )
396 foFldIntrpl = std::make_optional(field);
399 foFldOrig = std::nullopt;
403 template<
class Archive>
404 void save(Archive& ar,
const unsigned int )
const
406 if (fFieldMode == EFieldMode::Intrpl) {
407 ar << (*foFldIntrpl);
411 else if (fFieldMode == EFieldMode::Orig) {
412 throw std::logic_error(
"Attempt to serialize a kf::FieldRegion object with fFieldMode == EFieldMode::Orig");
417 template<
class Archive>
420 boost::serialization::split_member(ar, *
this, version);
423 std::optional<detail::FieldRegionBase<T, EFieldMode::Intrpl>> foFldIntrpl{std::nullopt};
424 std::optional<detail::FieldRegionBase<T, EFieldMode::Orig>> foFldOrig{std::nullopt};
436 using utils::simd::Cast;
437 for (
size_t i = 0; i < utils::simd::Size<T>(); ++i) {
438 auto [bx, by, bz] = fieldFn(Cast<T, double>(
x, i), Cast<T, double>(
y, i), Cast<T, double>(z, i));
std::string ToString(ECbmModuleId modId)
Common constant definitions for the Kalman Filter library.
Magnetic flux density vector representation.
Collection of generic mathematical methods.
Magnetic field region, corresponding to a hit triplet.
void save(Archive &ar, const unsigned int) const
Serialization save method.
EFieldType GetFieldType() const
Gets the field type.
EFieldMode GetFieldMode() const
Gets field mode.
const auto & GetIntrplField() const
~FieldRegion()=default
Destructor.
FieldRegion(const FieldRegion< I > &other)
Copy constructor.
FieldRegion & operator=(const FieldRegion &other)=default
Copy assignment operator.
void Set(const FieldValue< T > &b0, const T &z0, const FieldValue< T > &b1, const T &z1, const FieldValue< T > &b2, const T &z2)
Interpolates the field by three nodal points with the second order polynomial.
FieldRegion(EFieldMode fldMode=EFieldMode::Intrpl, EFieldType fldType=EFieldType::Normal)
Constructor of the generic field.
std::tuple< T, T, T > GetDoubleIntegrals(const T &x1, const T &y1, const T &z1, const T &x2, const T &y2, const T &z2) const
Gets the double integrals of the field along the track.
FieldRegion(EFieldType fieldType, const FieldFn_t &fieldFn)
Constructor for the field region with the original field function.
FieldRegion(const FieldValue< T > &b0, const T &z0, const FieldValue< T > &b1, const T &z1, const FieldValue< T > &b2, const T &z2)
Constructor for the interpolated field region.
FieldValue< T > Get(const T &x, const T &y, const T &z) const
Gets the field value in a spatial point on the track.
void SetFieldType(EFieldType fldType)
Sets the field type.
void serialize(Archive &ar, const unsigned int version)
Serialization method.
FieldRegion(EFieldType fieldType, const detail::FieldRegionBase< T, EFieldMode::Intrpl > &fld)
Constructor for the interpolated field region.
void load(Archive &ar, const unsigned int)
Serialization load method.
EFieldMode fFieldMode
Field mode.
Magnetic flux density vector.
bool IsZero() const
Checks, if the field value is zero (negligible)
void SetSimdEntry(double bx, double by, double bz, size_t i)
Sets magnetic flux density components to the field function.
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 FieldValue< T > GetFieldValue(const FieldFn_t &fieldFn, const T &x, const T &y, const T &z)
Creates a field value object in a spactial point of a generic floating-point 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 FieldFn_t fgOriginalField
Global variable to store the fielf funciton (x,y,z)->(Bx,By,Bz)
static bool IsUsingOriginalFieldForced()
Checks if the original field function is used.
static bool fgForceUseOfOriginalField
Flag to force the use of the original field in all field classes.
void Set(const CoeffArray_t &coeff, const T &z0)
Set the coefficients of the polynomial approximation.
const auto & GetCoefficients() const
Gets the coefficients of the polynomial approximation.
FieldRegionBase()=default
Default constructor.
void Shift(const T &z)
Shifts the coefficients to another first z-coordinate.
void CheckConsistency() const
Consistency checker.
FieldRegionBase & operator=(const FieldRegionBase &other)=default
Copy assignment operator.
const T & GetZfirst() const
Gets the first z-coordinate of the interpolation.
std::string ToString(int indentLevel=0, int verbose=1) const
String representation of the class content.
void serialize(Archive &ar, const unsigned int)
FieldRegionBase(const FieldValue_t &b0, const T &z0, const FieldValue_t &b1, const T &z1, const FieldValue_t &b2, const T &z2)
Constructor from parameters.
void Set(const FieldValue< T > &b0, const T &z0, const FieldValue< T > &b1, const T &z1, const FieldValue< T > &b2, const T &z2)
Interpolates the field by three nodal points with the second order polynomial.
~FieldRegionBase()=default
Destructor.
FieldValue< T > Get(const T &x, const T &y, const T &z) const
Gets the field value in a spatial point on the track.
std::tuple< T, T, T > GetDoubleIntegrals(const T &x1, const T &y1, const T &z1, const T &x2, const T &y2, const T &z2) const
Gets the double integrals of the field along the track.
FieldRegionBase(const FieldRegionBase< I, EFieldMode::Intrpl > &other)
Copy constructor.
std::array< std::array< T, 3 >, 3 > CoeffArray_t
Approximation coefficients array.
FieldRegionBase(const FieldRegionBase< I, EFieldMode::Orig > &other)
Copy constructor.
std::string ToString(int indentLevel=0, int verbose=1) const
String representation of the class content.
FieldValue< T > Get(const T &x, const T &y, const T &z) const
Gets the field value in a spatial point on the track.
~FieldRegionBase()=default
Destructor.
std::tuple< T, T, T > GetDoubleIntegrals(const T &, const T &, const T &, const T &, const T &, const T &) const
Gets the double integrals of the field along the track.
FieldRegionBase(const FieldFn_t &fieldFn)
Constructor.
FieldRegionBase()=default
Default constructor.
void CheckConsistency() const
Consistency checker.
FieldRegionBase & operator=(const FieldRegionBase &other)=default
Copy assignment operator.
Base class of the FieldRegion class (primary template)
EFieldMode
Enumiration for the magnetic field representation variants in the track fitting algorithm.
@ Intrpl
Interpolated magnetic field.
@ Orig
Original magnetic field function.
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);.