Belle II Software  release-05-02-19
BFieldMap.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #ifndef BFIELDMAP_H_
12 #define BFIELDMAP_H_
13 
14 #include <geometry/bfieldmap/BFieldComponentAbs.h>
15 
16 #include <framework/geometry/B2Vector3.h>
17 #include <framework/logging/Logger.h>
18 
19 #include <list>
20 
21 namespace Belle2 {
33  class BFieldMap {
34 
35  public:
36 
42  static BFieldMap& Instance();
43 
44  private:
52  B2Vector3D getBField(const B2Vector3D& point) const;
53  public:
54 
60  template<class BFIELDCOMP> BFIELDCOMP& addBFieldComponent();
61 
63  void initialize();
64 
68  void clear();
69 
70  protected:
71 
72  std::list<BFieldComponentAbs*> m_components;
75  private:
76 
77  bool m_isMapInitialized;
81 
83  BFieldMap(const BFieldMap&);
84 
86  BFieldMap& operator=(const BFieldMap&);
87 
89  virtual ~BFieldMap();
90 
92  friend struct std::default_delete<BFieldMap>;
94  friend class BFieldFrameworkInterface;
95  };
96 
97 
98  //------------------------------------------------------
99  // Implementation of template based methods
100  //------------------------------------------------------
101  template<class BFIELDCOMP> BFIELDCOMP& BFieldMap::addBFieldComponent()
102  {
103  BFIELDCOMP* newComponent = new BFIELDCOMP;
104  m_components.push_back(newComponent);
105  return *newComponent;
106  }
107 
108 
109  inline B2Vector3D BFieldMap::getBField(const B2Vector3D& point) const
110  {
111  B2Vector3D magFieldVec(0.0, 0.0, 0.0);
112  //Check that the point makes sense
113  if (std::isnan(point.X()) || std::isnan(point.Y()) || std::isnan(point.Z())) {
114  B2ERROR("Bfield requested for a position containing NaN, returning field 0");
115  return magFieldVec;
116  }
117  //Loop over all magnetic field components and add their magnetic field vectors
118  for (const BFieldComponentAbs* comp : m_components) {
119  magFieldVec += comp->calculate(point);
120  }
121  return magFieldVec;
122  }
123 
124 
126 } //end of namespace Belle2
127 
128 #endif /* BFIELDMAP_H_ */
Belle2::BFieldMap::clear
void clear()
Clear the existing components.
Definition: BFieldMap.cc:35
Belle2::BFieldMap::m_isMapInitialized
bool m_isMapInitialized
If false the map hasn't been initialized yet.
Definition: BFieldMap.h:85
Belle2::BFieldMap
This class represents the magnetic field of the Belle II detector.
Definition: BFieldMap.h:41
Belle2::B2Vector3::Z
DataType Z() const
access variable Z (= .at(2) without boundary check)
Definition: B2Vector3.h:434
Belle2::B2Vector3< double >
Belle2::BFieldMap::initialize
void initialize()
Initialize the magnetic field after adding all components.
Definition: BFieldMap.cc:23
Belle2::BFieldMap::Instance
static BFieldMap & Instance()
Static method to get a reference to the BFieldMap instance.
Definition: BFieldMap.cc:17
Belle2::BFieldMap::addBFieldComponent
BFIELDCOMP & addBFieldComponent()
Adds a new BField component to the Belle II magnetic field.
Definition: BFieldMap.h:109
Belle2::B2Vector3D
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:507
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::BFieldMap::operator=
BFieldMap & operator=(const BFieldMap &)
Disable/Hide the copy assignment operator.
Belle2::BFieldMap::getBField
B2Vector3D getBField(const B2Vector3D &point) const
Returns the magnetic field of the Belle II detector at the specified space point.
Definition: BFieldMap.h:117
Belle2::BFieldFrameworkInterface
Simple BFieldComponent to just wrap the existing BFieldMap with the new BFieldManager.
Definition: BFieldFrameworkInterface.h:25
Belle2::BFieldMap::BFieldMap
BFieldMap()
The constructor is hidden to avoid that someone creates an instance of this class.
Definition: BFieldMap.cc:46
Belle2::BFieldMap::~BFieldMap
virtual ~BFieldMap()
The destructor of the BFieldMap class.
Definition: BFieldMap.cc:51
Belle2::BFieldComponentAbs
The BFieldComponentAbs class.
Definition: BFieldComponentAbs.h:41
Belle2::B2Vector3::X
DataType X() const
access variable X (= .at(0) without boundary check)
Definition: B2Vector3.h:430
Belle2::BFieldMap::m_components
std::list< BFieldComponentAbs * > m_components
The components of the magnetic field.
Definition: BFieldMap.h:80
Belle2::B2Vector3::Y
DataType Y() const
access variable Y (= .at(1) without boundary check)
Definition: B2Vector3.h:432