Belle II Software  light-2212-foldex
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/logging/Logger.h>
14 
15 #include <list>
16 
17 namespace Belle2 {
29  class BFieldMap {
30 
31  public:
32 
38  static BFieldMap& Instance();
39 
40  private:
48  ROOT::Math::XYZVector getBField(const ROOT::Math::XYZVector& point) const;
49  public:
50 
56  template<class BFIELDCOMP> BFIELDCOMP& addBFieldComponent();
57 
59  void initialize();
60 
64  void clear();
65 
66  protected:
67 
68  std::list<BFieldComponentAbs*> m_components;
71  private:
72 
76  BFieldMap();
77 
80 
83 
85  virtual ~BFieldMap();
86 
88  friend struct std::default_delete<BFieldMap>;
91  };
92 
93 
94  //------------------------------------------------------
95  // Implementation of template based methods
96  //------------------------------------------------------
97  template<class BFIELDCOMP> BFIELDCOMP& BFieldMap::addBFieldComponent()
98  {
99  BFIELDCOMP* newComponent = new BFIELDCOMP;
100  m_components.push_back(newComponent);
101  return *newComponent;
102  }
103 
104 
105  inline ROOT::Math::XYZVector BFieldMap::getBField(const ROOT::Math::XYZVector& point) const
106  {
107  ROOT::Math::XYZVector magFieldVec(0.0, 0.0, 0.0);
108  //Check that the point makes sense
109  if (std::isnan(point.X()) || std::isnan(point.Y()) || std::isnan(point.Z())) {
110  B2ERROR("Bfield requested for a position containing NaN, returning field 0");
111  return magFieldVec;
112  }
113  //Loop over all magnetic field components and add their magnetic field vectors
114  for (const BFieldComponentAbs* comp : m_components) {
115  magFieldVec += comp->calculate(point);
116  }
117  return magFieldVec;
118  }
119 
120 
122 } //end of namespace Belle2
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:29
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:68
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:73
ROOT::Math::XYZVector getBField(const ROOT::Math::XYZVector &point) const
Returns the magnetic field of the Belle II detector at the specified space point.
Definition: BFieldMap.h:105
BFIELDCOMP & addBFieldComponent()
Adds a new BField component to the Belle II magnetic field.
Definition: BFieldMap.h:97
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:23