16#include <boost/serialization/access.hpp>
17#include <boost/serialization/split_free.hpp>
31 template<
typename T, EFieldMode FldMode>
40 template<
typename, EFieldMode>
52 fvFieldSliceZ.reserve(other.fvFieldSliceZ.size());
53 for (
const auto& slice : other.fvFieldSliceZ) {
54 fvFieldSliceZ.emplace_back(utils::simd::Cast<I, T>(slice));
62 fvFieldSliceZ = other.fvFieldSliceZ;
63 fFieldFn = other.fFieldFn;
70 void AddFieldSlice(
const T& fieldSliceZref) { fvFieldSliceZ.push_back(fieldSliceZref); }
78 return GlobalField::GetFieldValue(fFieldFn,
x,
y, fvFieldSliceZ[sliceID]);
89 void RemoveSlice(
int iLayer) { fvFieldSliceZ.erase(fvFieldSliceZ.begin() + iLayer); }
98 std::string
ToString(
int indentLevel,
int verbose)
const;
101 std::vector<T> fvFieldSliceZ{};
111 template<
typename, EFieldMode>
125 fvFieldSlices.reserve(other.fvFieldSlices.size());
126 for (
const auto& slice : other.fvFieldSlices) {
134 if (
this != &other) {
135 fvFieldSlices = other.fvFieldSlices;
146 const auto&
GetFieldSlice(
int sliceID)
const {
return fvFieldSlices[sliceID]; }
154 return fvFieldSlices[sliceID].GetFieldValue(
x,
y);
162 void RemoveSlice(
int iLayer) { fvFieldSlices.erase(fvFieldSlices.begin() + iLayer); }
167 std::string
ToString(
int indentLevel,
int verbose)
const;
174 friend class boost::serialization::access;
175 template<
class Archive>
192 friend class boost::serialization::access;
202 , fPrimVertexField(
FieldRegion<T>(fldMode, fldType))
203 , fFieldType(fldType)
204 , fFieldMode(fldMode)
211 : foFldIntrpl(other.foFldIntrpl.has_value()
214 , foFldOrig(other.foFldOrig.has_value()
217 , fPrimVertexField(
FieldRegion<I>(other.fPrimVertexField))
218 , fFieldType(other.fFieldType)
219 , fFieldMode(other.fFieldMode)
229 if (
this != &other) {
245 return fFieldMode == EFieldMode::Intrpl ? foFldIntrpl->GetFieldValue(sliceID,
x,
y)
246 : foFldOrig->GetFieldValue(sliceID,
x,
y);
266 return (fFieldMode == EFieldMode::Intrpl ?
FieldRegion<T>(b0, z0, b1, z1, b2, z2)
272 void RemoveSlice(
int iLayer);
277 std::string
ToString(
int indentLevel,
int verbose)
const;
284 template<
class Archive>
285 void load(Archive& ar,
const unsigned int )
289 foFldIntrpl = std::make_optional(field);
290 ar >> fPrimVertexField;
293 foFldOrig = std::nullopt;
297 template<
class Archive>
298 void save(Archive& ar,
const unsigned int )
const
300 if (fFieldMode == EFieldMode::Intrpl) {
301 ar << (*foFldIntrpl);
302 ar << fPrimVertexField;
306 else if (fFieldMode == EFieldMode::Orig) {
307 throw std::logic_error(
"Attempt to serialize a kf::FieldRegion object with fFieldMode == EFieldMode::Orig");
312 template<
class Archive>
315 boost::serialization::split_member(ar, *
this, version);
318 std::optional<detail::FieldBase<T, EFieldMode::Intrpl>> foFldIntrpl{std::nullopt};
319 std::optional<detail::FieldBase<T, EFieldMode::Orig>> foFldOrig{std::nullopt};
332 double fHalfSizeX{defs::Undef<double>};
333 double fHalfSizeY{defs::Undef<double>};
334 double fRefZ{defs::Undef<double>};
340 SliceRef(
double halfX,
double halfY,
double refZ) : fHalfSizeX(halfX), fHalfSizeY(halfY), fRefZ(refZ) {}
363 void AddSliceReference(
double halfSizeX,
double halfSizeY,
double refZ);
387 fFieldType = fldType;
395 void SetStep(
double step = 2.5) { fTargetStep = step; }
406 double fTargetStep{2.5};
411 std::array<double, 3> fTarget{{defs::Undef<double>, defs::Undef<double>, defs::Undef<double>}};
419 auto field =
Field<T>(fFieldMode, fFieldType);
422 if (std::any_of(fTarget.begin(), fTarget.end(), [](
double x) { return !utils::IsFinite(x); })) {
423 throw std::logic_error(
"FieldFactory::MakeField: target is undefined");
425 if (!fSliceReferences.size()) {
426 throw std::logic_error(
"FieldFactory::MakeField: no slice references were provided");
429 throw std::logic_error(
"FieldFactory::CreateField: no field function is provided");
433 if (fFieldMode == EFieldMode::Orig) {
434 field.foFldOrig->SetFieldFunction(fFieldFn);
436 for (
const auto& sliceRef : fSliceReferences) {
437 field.foFldOrig->AddFieldSlice(sliceRef.fRefZ);
440 else if (fFieldMode == EFieldMode::Intrpl) {
441 for (
const auto& sliceRef : fSliceReferences) {
442 field.foFldIntrpl->AddFieldSlice(
443 FieldSlice<T>(fFieldFn, sliceRef.fHalfSizeX, sliceRef.fHalfSizeY, sliceRef.fRefZ));
447 constexpr size_t nNodes = 3;
448 double z = fTarget[2];
449 std::array<FieldValue<T>, nNodes> fld;
450 std::array<T, nNodes>
pos;
451 for (
size_t iNode = 0; iNode < nNodes; ++iNode) {
452 pos[iNode] = utils::simd::Cast<double, T>(z);
453 fld[iNode] = GlobalField::GetFieldValue<double>(fFieldFn, fTarget[0], fTarget[1], z);
std::string ToString(ECbmModuleId modId)
Common constant definitions for the Kalman Filter library.
Magnetic flux density interpolation along the track vs. z-coordinate (header)
A class for a magnetic field approximation on a transverse plane (source)
A helper class to instantiate a Field object.
void SetFieldMode(EFieldMode fldMode)
Sets field mode.
FieldFactory()=default
Default constructor.
void SetStep(double step=2.5)
Sets a step for the primary vertex field region estimation.
void ResetSliceReferences()
Resets slicer references.
void SetTarget(double x, double y, double z)
Sets target.
void SetFieldFunction(const FieldFn_t &fieldFn, EFieldType fldType)
Sets magnetic field function.
FieldFactory & operator=(const FieldFactory &)=default
Copy assignment operator.
void Reset()
Resets the instance.
EFieldMode GetFieldMode() const
Gets field mode.
~FieldFactory()=default
Destructor.
std::set< SliceRef > fSliceReferences
Set of slice references.
FieldFactory(const FieldFactory &)=default
Copy constructor.
EFieldType GetFieldType() const
Gets field type.
Magnetic field region, corresponding to a hit triplet.
A magnetic field approximation on the two-dimensional plane.
Magnetic flux density vector.
Magnetic field manager class.
FieldValue< T > GetFieldValue(int sliceID, const T &x, const T &y) const
Creates field value object.
void load(Archive &ar, const unsigned int)
Serialization load method.
EFieldType fFieldType
Field type.
void serialize(Archive &ar, const unsigned int version)
Serialization method.
const FieldRegion< T > & GetPrimVertexField() const
Gets field region near primary vertex.
Field()=default
Default constructor.
Field & operator=(const Field &other)
Copy assignment operator.
FieldRegion< T > fPrimVertexField
Field region near primary vertex (constant field is assumed)
FieldRegion< T > GetFieldRegion(const FieldValue< T > &b0, const T &z0, const FieldValue< T > &b1, const T &z1, const FieldValue< T > &b2, const T &z2) const
Makes field region object.
~Field()=default
Destructor.
std::optional< detail::FieldBase< T, EFieldMode::Orig > > foFldOrig
Original field.
EFieldMode fFieldMode
Field mode.
EFieldType GetFieldType() const
Gets field type.
Field(EFieldMode fldMode, EFieldType fldType)
Constructor.
void save(Archive &ar, const unsigned int) const
Serialization save method.
std::optional< detail::FieldBase< T, EFieldMode::Intrpl > > foFldIntrpl
Interpolated field.
Field(const Field< I > &other)
Copy constructor.
FieldBase()=default
Default constructor.
void AddFieldSlice(const FieldSlice< T > &fieldSlice)
Sets a field slice.
int GetNofFieldSlices() const
Gets number of field slices in the instance.
std::vector< FieldSlice< T > > SlicesContainer_t
std::string ToString(int indentLevel, int verbose) const
String representation of the class.
const auto & GetFieldSlice(int sliceID) const
Gets field slice.
void serialize(Archive &ar, const unsigned int)
FieldBase(const FieldBase< I, EFieldMode::Intrpl > &other)
Copy constructor.
void RemoveSlice(int iLayer)
Removes a field slice.
FieldBase & operator=(const FieldBase &other)
Copy assignment operator.
FieldValue< T > GetFieldValue(int sliceID, const T &x, const T &y) const
Creates field value object.
FieldValue< T > GetFieldValue(int sliceID, const T &x, const T &y) const
Creates field value object.
void AddFieldSlice(const T &fieldSliceZref)
Sets a field slice (z-ref)
std::string ToString(int indentLevel, int verbose) const
String representation of the class.
int GetNofFieldSlices() const
Gets number of field slices in the instance.
void RemoveSlice(int iLayer)
Removes a field slice.
void SetFieldFunction(const FieldFn_t &fieldFn)
Sets magnetic field function.
FieldBase(const FieldBase< I, EFieldMode::Orig > &other)
Copy constructor.
FieldBase()=default
Default constructor.
FieldBase & operator=(const FieldBase &other)
Copy assignment operator.
const FieldFn_t & GetFieldFunction() const
Gets field function.
Data members of the Field 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.
EFieldType
Magnetic field type in different setup regions.
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 helper structure for field slices initialization.
double fRefZ
Reference z-position of the slice [cm].
SliceRef(double halfX, double halfY, double refZ)
Constructor.
bool operator<(const SliceRef &r) const
Comparision operator.