Belle II Software  release-06-01-15
MagneticField.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 #include <framework/geometry/B2Vector3.h>
11 #include <framework/dbobjects/MagneticFieldComponent.h>
12 #include <framework/gearbox/Unit.h>
13 
14 namespace Belle2 {
33  class MagneticField: public TObject {
34  public:
36  MagneticField(): TObject() {}
39  {
40  for (auto c : m_components) delete c;
41  m_components.clear();
42  }
44  MagneticField(const MagneticField&) = delete;
46  MagneticField(MagneticField&& other) noexcept: m_components(std::move(other.m_components)) {}
53  B2Vector3D getField(const B2Vector3D& pos) const;
58  B2Vector3D getFieldInTesla(const B2Vector3D& pos) const { return getField(pos) / Unit::T; }
60  void addComponent(MagneticFieldComponent* component) { m_components.emplace_back(component); }
61  private:
63  std::vector<MagneticFieldComponent*> m_components;
66  };
67 
69  {
70  B2Vector3D field;
71  for (auto c : m_components) {
72  if (c->inside(pos)) {
73  // is it an exclusive component? If so return the field
74  if (c->isExclusive()) return c->getField(pos);
75  // else add it to what we already have
76  field += c->getField(pos);
77  }
78  }
79  return field;
80  }
82 } //Belle2 namespace
Abstract base class for BField components.
Magnetic field map.
Definition: MagneticField.h:33
MagneticField()
Empty Constructor.
Definition: MagneticField.h:36
std::vector< MagneticFieldComponent * > m_components
Magnetic field components to evaluate the field.
Definition: MagneticField.h:63
ClassDef(MagneticField, 1)
ROOT dictionary definition.
void addComponent(MagneticFieldComponent *component)
Add a new component to the magnetic field.
Definition: MagneticField.h:60
B2Vector3D getFieldInTesla(const B2Vector3D &pos) const
Convenience function to get the field directly in Tesla.
Definition: MagneticField.h:58
~MagneticField()
Delete all components.
Definition: MagneticField.h:38
MagneticField(MagneticField &&other) noexcept
But allow move construction.
Definition: MagneticField.h:46
MagneticField(const MagneticField &)=delete
Disallow copying the magnetic field.
static const double T
[tesla]
Definition: Unit.h:120
B2Vector3D getField(const B2Vector3D &pos) const
Calculate the magnetic field at a given position.
Definition: MagneticField.h:68
Abstract base class for different kinds of events.