Belle II Software development
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#include <memory>
17
18namespace Belle2 {
30 class BFieldMap {
31
32 public:
33
39 static BFieldMap& Instance();
40
41 private:
49 ROOT::Math::XYZVector getBField(const ROOT::Math::XYZVector& 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;
70
71
72 private:
73
75
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 ROOT::Math::XYZVector BFieldMap::getBField(const ROOT::Math::XYZVector& point) const
107 {
108 ROOT::Math::XYZVector 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
The BFieldComponentAbs class.
BFieldMap & operator=(const BFieldMap &)
Disable/Hide the copy assignment operator.
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
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
friend class BFieldFrameworkInterface
only allow lookup by framework payload interface from now on
Definition BFieldMap.h:91
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
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: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.