Belle II Software  release-06-00-14
BFieldMap.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <geometry/bfieldmap/BFieldComponentAbs.h>
12 
13 #include <framework/geometry/B2Vector3.h>
14 #include <framework/logging/Logger.h>
15 
16 #include <list>
17 
18 namespace Belle2 {
30  class BFieldMap {
31 
32  public:
33 
39  static BFieldMap& Instance();
40 
41  private:
49  B2Vector3D getBField(const B2Vector3D& point) const;
50  public:
51 
57  template<class BFIELDCOMP> BFIELDCOMP& addBFieldComponent();
58 
60  void initialize();
61 
65  void clear();
66 
67  protected:
68 
69  std::list<BFieldComponentAbs*> m_components;
72  private:
73 
77  BFieldMap();
78 
81 
84 
86  virtual ~BFieldMap();
87 
89  friend struct std::default_delete<BFieldMap>;
92  };
93 
94 
95  //------------------------------------------------------
96  // Implementation of template based methods
97  //------------------------------------------------------
98  template<class BFIELDCOMP> BFIELDCOMP& BFieldMap::addBFieldComponent()
99  {
100  BFIELDCOMP* newComponent = new BFIELDCOMP;
101  m_components.push_back(newComponent);
102  return *newComponent;
103  }
104 
105 
106  inline B2Vector3D BFieldMap::getBField(const B2Vector3D& point) const
107  {
108  B2Vector3D magFieldVec(0.0, 0.0, 0.0);
109  //Check that the point makes sense
110  if (std::isnan(point.X()) || std::isnan(point.Y()) || std::isnan(point.Z())) {
111  B2ERROR("Bfield requested for a position containing NaN, returning field 0");
112  return magFieldVec;
113  }
114  //Loop over all magnetic field components and add their magnetic field vectors
115  for (const BFieldComponentAbs* comp : m_components) {
116  magFieldVec += comp->calculate(point);
117  }
118  return magFieldVec;
119  }
120 
121 
123 } //end of namespace Belle2
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:420
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:416
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:418
The BFieldComponentAbs class.
Simple BFieldComponent to just wrap the existing BFieldMap with the new BFieldManager.
This class represents the magnetic field of the Belle II detector.
Definition: BFieldMap.h:30
BFieldMap()
The constructor is hidden to avoid that someone creates an instance of this class.
Definition: BFieldMap.cc:44
std::list< BFieldComponentAbs * > m_components
The components of the magnetic field.
Definition: BFieldMap.h:69
void initialize()
Initialize the magnetic field after adding all components.
Definition: BFieldMap.cc:21
BFieldMap & operator=(const BFieldMap &)
Disable/Hide the copy assignment operator.
virtual ~BFieldMap()
The destructor of the BFieldMap class.
Definition: BFieldMap.cc:49
BFieldMap(const BFieldMap &)
Disable/Hide the copy constructor.
void clear()
Clear the existing components.
Definition: BFieldMap.cc:33
static BFieldMap & Instance()
Static method to get a reference to the BFieldMap instance.
Definition: BFieldMap.cc:15
bool m_isMapInitialized
If false the map hasn't been initialized yet.
Definition: BFieldMap.h:74
B2Vector3D getBField(const B2Vector3D &point) const
Returns the magnetic field of the Belle II detector at the specified space point.
Definition: BFieldMap.h:106
BFIELDCOMP & addBFieldComponent()
Adds a new BField component to the Belle II magnetic field.
Definition: BFieldMap.h:98
Abstract base class for different kinds of events.