Belle II Software  release-05-02-19
MagneticField.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #include <framework/geometry/B2Vector3.h>
13 #include <framework/dbobjects/MagneticFieldComponent.h>
14 #include <framework/gearbox/Unit.h>
15 
16 namespace Belle2 {
35  class MagneticField: public TObject {
36  public:
38  MagneticField(): TObject() {}
41  {
42  for (auto c : m_components) delete c;
43  m_components.clear();
44  }
46  MagneticField(const MagneticField&) = delete;
48  MagneticField(MagneticField&& other) noexcept: m_components(std::move(other.m_components)) {}
55  B2Vector3D getField(const B2Vector3D& pos) const;
60  B2Vector3D getFieldInTesla(const B2Vector3D& pos) const { return getField(pos) / Unit::T; }
62  void addComponent(MagneticFieldComponent* component) { m_components.emplace_back(component); }
63  private:
65  std::vector<MagneticFieldComponent*> m_components;
68  };
69 
71  {
72  B2Vector3D field;
73  for (auto c : m_components) {
74  if (c->inside(pos)) {
75  // is it an exclusive component? If so return the field
76  if (c->isExclusive()) return c->getField(pos);
77  // else add it to what we already have
78  field += c->getField(pos);
79  }
80  }
81  return field;
82  }
84 } //Belle2 namespace
Belle2::MagneticField::~MagneticField
~MagneticField()
Delete all components.
Definition: MagneticField.h:48
Belle2::B2Vector3< double >
Belle2::Unit::T
static const double T
[tesla]
Definition: Unit.h:130
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MagneticField::getFieldInTesla
B2Vector3D getFieldInTesla(const B2Vector3D &pos) const
Convenience function to get the field directly in Tesla.
Definition: MagneticField.h:68
Belle2::MagneticField::m_components
std::vector< MagneticFieldComponent * > m_components
Magnetic field components to evaluate the field.
Definition: MagneticField.h:73
Belle2::MagneticField
Magnetic field map.
Definition: MagneticField.h:43
Belle2::MagneticField::getField
B2Vector3D getField(const B2Vector3D &pos) const
Calculate the magnetic field at a given position.
Definition: MagneticField.h:78
Belle2::MagneticField::addComponent
void addComponent(MagneticFieldComponent *component)
Add a new component to the magnetic field.
Definition: MagneticField.h:70
Belle2::MagneticField::MagneticField
MagneticField()
Empty Constructor.
Definition: MagneticField.h:46
Belle2::MagneticField::ClassDef
ClassDef(MagneticField, 1)
ROOT dictionary definition.