Juggler
Juggling algorithms and event processing using gaudi framework
BField.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: LGPL-3.0-or-later
2 // Copyright (C) 2022 Whitney Armstrong
3 #ifndef Jug_BFIELD_HH
4 #define Jug_BFIELD_HH 1
5 
6 #include "Acts//Definitions/Units.hpp"
7 #include "Acts/Utilities/detail/AxisFwd.hpp"
8 #include "Acts/Utilities/detail/GridFwd.hpp"
9 #include <memory>
10 #include <tuple>
11 #include<variant>
12 
13 #include "Acts/MagneticField/MagneticFieldContext.hpp"
14 #include "Acts/Definitions/Common.hpp"
15 
16 // Forward declarations
17 namespace Acts {
18  template <typename G>
20  template <typename M>
22  class ConstantBField;
23 
24 } // namespace Acts
25 
26 namespace Jug {
27  // namespace BField {
28  // class ScalableBField;
29  //}
30  namespace BField {
31 
32  /// The Context to be handed around
34  double scalor = 1.;
35  };
36 
37  /// @ingroup MagneticField
38  ///
39  /// @brief returns a given constant field value at every point
40  ///
41  /// This class is based on the constant magnetic field class
42  /// but allows a event based context
43  class ScalableBField final {
44  public:
45  struct Cache {
46  double scalor = 1.;
47 
48  /// @brief constructor with context
49  Cache(const Acts::MagneticFieldContext& mcfg)
50  {
51  scalor = std::any_cast<const ScalableBFieldContext>(mcfg).scalor;
52  }
53  };
54 
55  /// @brief construct constant magnetic field from field vector
56  ///
57  /// @param [in] B magnetic field vector in global coordinate system
58  explicit ScalableBField(Acts::Vector3 B) : m_BField(std::move(B)) {}
59 
60  /// @brief construct constant magnetic field from components
61  ///
62  /// @param [in] Bx magnetic field component in global x-direction
63  /// @param [in] By magnetic field component in global y-direction
64  /// @param [in] Bz magnetic field component in global z-direction
65  ScalableBField(double Bx = 0., double By = 0., double Bz = 0.) : m_BField(Bx, By, Bz) {}
66 
67  /// @brief retrieve magnetic field value
68  ///
69  /// @param [in] position global position
70  /// @return magnetic field vector
71  ///
72  /// @note The @p position is ignored and only kept as argument to provide
73  /// a consistent interface with other magnetic field services.
74  Acts::Vector3 getField(const Acts::Vector3& /*position*/) const { return m_BField; }
75 
76  /// @brief retrieve magnetic field value
77  ///
78  /// @param [in] position global position
79  /// @param [in] cache Cache object (is ignored)
80  /// @return magnetic field vector
81  ///
82  /// @note The @p position is ignored and only kept as argument to provide
83  /// a consistent interface with other magnetic field services.
84  Acts::Vector3 getField(const Acts::Vector3& /*position*/, Cache& cache) const
85  {
86  return m_BField * cache.scalor;
87  }
88 
89  /// @brief retrieve magnetic field value & its gradient
90  ///
91  /// @param [in] position global position
92  /// @param [out] derivative gradient of magnetic field vector as (3x3)
93  /// matrix
94  /// @return magnetic field vector
95  ///
96  /// @note The @p position is ignored and only kept as argument to provide
97  /// a consistent interface with other magnetic field services.
98  /// @note currently the derivative is not calculated
99  /// @todo return derivative
100  Acts::Vector3 getFieldGradient(const Acts::Vector3& /*position*/, Acts::ActsMatrix<3, 3>& /*derivative*/) const
101  {
102  return m_BField;
103  }
104 
105  /// @brief retrieve magnetic field value & its gradient
106  ///
107  /// @param [in] position global position
108  /// @param [out] derivative gradient of magnetic field vector as (3x3)
109  /// matrix
110  /// @param [in] cache Cache object (is ignored)
111  /// @return magnetic field vector
112  ///
113  /// @note The @p position is ignored and only kept as argument to provide
114  /// a consistent interface with other magnetic field services.
115  /// @note currently the derivative is not calculated
116  /// @todo return derivative
117  Acts::Vector3 getFieldGradient(const Acts::Vector3& /*position*/, Acts::ActsMatrix<3, 3>& /*derivative*/,
118  Cache& cache) const
119  {
120  return m_BField * cache.scalor;
121  }
122 
123  /// @brief check whether given 3D position is inside look-up domain
124  ///
125  /// @param [in] position global 3D position
126  /// @return @c true if position is inside the defined look-up grid,
127  /// otherwise @c false
128  /// @note The method will always return true for the constant B-Field
129  bool isInside(const Acts::Vector3& /*position*/) const { return true; }
130 
131  /// @brief update magnetic field vector from components
132  ///
133  /// @param [in] Bx magnetic field component in global x-direction
134  /// @param [in] By magnetic field component in global y-direction
135  /// @param [in] Bz magnetic field component in global z-direction
136  void setField(double Bx, double By, double Bz) { m_BField << Bx, By, Bz; }
137 
138  /// @brief update magnetic field vector
139  ///
140  /// @param [in] B magnetic field vector in global coordinate system
141  void setField(const Acts::Vector3& B) { m_BField = B; }
142 
143  private:
144  /// magnetic field vector
145  Acts::Vector3 m_BField;
146  };
147 
148 } // namespace BField
149 } // namespace Jug
150 
152  Acts::detail::Grid<Acts::Vector2, Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis>>;
153 
155  Acts::InterpolatedBFieldMapper<Acts::detail::Grid<Acts::Vector3, Acts::detail::EquidistantAxis,
156  Acts::detail::EquidistantAxis, Acts::detail::EquidistantAxis>>;
159 
160 using BFieldVariant = std::variant<std::shared_ptr<InterpolatedBFieldMap2D>, std::shared_ptr<InterpolatedBFieldMap3D>,
161  std::shared_ptr<Acts::ConstantBField>, std::shared_ptr<Jug::BField::ScalableBField>>;
162 
163 #endif
Jug::BField::ScalableBField::getFieldGradient
Acts::Vector3 getFieldGradient(const Acts::Vector3 &, Acts::ActsMatrix< 3, 3 > &) const
retrieve magnetic field value & its gradient
Definition: BField.h:100
BFieldVariant
std::variant< std::shared_ptr< InterpolatedBFieldMap2D >, std::shared_ptr< InterpolatedBFieldMap3D >, std::shared_ptr< Acts::ConstantBField >, std::shared_ptr< Jug::BField::ScalableBField > > BFieldVariant
Definition: BField.h:161
Jug::BField::ScalableBField::ScalableBField
ScalableBField(double Bx=0., double By=0., double Bz=0.)
construct constant magnetic field from components
Definition: BField.h:65
Jug::BField::ScalableBField::isInside
bool isInside(const Acts::Vector3 &) const
check whether given 3D position is inside look-up domain
Definition: BField.h:129
Jug::BField::ScalableBField::Cache::scalor
double scalor
Definition: BField.h:46
Jug::BField::ScalableBField::getField
Acts::Vector3 getField(const Acts::Vector3 &) const
retrieve magnetic field value
Definition: BField.h:74
Jug::BField::ScalableBFieldContext
The Context to be handed around.
Definition: BField.h:33
Jug::BField::ScalableBField::setField
void setField(double Bx, double By, double Bz)
update magnetic field vector from components
Definition: BField.h:136
Jug::BField::ScalableBField
returns a given constant field value at every point
Definition: BField.h:43
Jug::BField::ScalableBField::Cache
Definition: BField.h:45
Jug
Definition: DD4hepBField.h:22
Jug::BField::ScalableBField::getField
Acts::Vector3 getField(const Acts::Vector3 &, Cache &cache) const
retrieve magnetic field value
Definition: BField.h:84
Acts::InterpolatedBFieldMapper
Definition: BField.h:19
Jug::BField::ScalableBField::setField
void setField(const Acts::Vector3 &B)
update magnetic field vector
Definition: BField.h:141
Jug::BField::ScalableBField::Cache::Cache
Cache(const Acts::MagneticFieldContext &mcfg)
constructor with context
Definition: BField.h:49
Jug::BField::ScalableBField::getFieldGradient
Acts::Vector3 getFieldGradient(const Acts::Vector3 &, Acts::ActsMatrix< 3, 3 > &, Cache &cache) const
retrieve magnetic field value & its gradient
Definition: BField.h:117
Acts::InterpolatedBFieldMap
Definition: BField.h:21
Acts
Definition: MaterialWiper.hpp:20
Jug::BField::ScalableBFieldContext::scalor
double scalor
Definition: BField.h:34
Jug::BField::ScalableBField::ScalableBField
ScalableBField(Acts::Vector3 B)
construct constant magnetic field from field vector
Definition: BField.h:58