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