Belle II Software development
BFieldManager.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 <vector>
12#include <Math/Vector3D.h>
13#include <framework/logging/Logger.h>
14#include <framework/gearbox/Unit.h>
15#include <framework/database/DBObjPtr.h>
16#include <framework/dbobjects/MagneticField.h>
17
18namespace Belle2 {
33 public:
38 static void getField(const double* pos, double* field);
45 static ROOT::Math::XYZVector getField(double x, double y, double z)
46 {
47 return getField(ROOT::Math::XYZVector(x, y, z));
48 }
53 static ROOT::Math::XYZVector getField(const ROOT::Math::XYZVector& pos)
54 {
56 }
61 static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector& pos)
62 {
63 return getField(pos) / Unit::T;
64 }
66 static BFieldManager& getInstance();
67 private:
69 BFieldManager() = default;
75 ~BFieldManager() = default;
80 ROOT::Math::XYZVector calculate(const ROOT::Math::XYZVector& pos) const;
83 };
84
85 inline ROOT::Math::XYZVector BFieldManager::calculate(const ROOT::Math::XYZVector& pos) const
86 {
87 if (!m_magfield) B2FATAL("Could not load magnetic field configuration from database");
88 return m_magfield->getField(pos);
89 };
90
91 inline void BFieldManager::getField(const double* pos, double* field)
92 {
93 ROOT::Math::XYZVector fieldvec = getField(ROOT::Math::XYZVector(pos[0], pos[1], pos[2]));
94 field[0] = fieldvec.X();
95 field[1] = fieldvec.Y();
96 field[2] = fieldvec.Z();
97 }
99}
Bfield manager to obtain the magnetic field at any point.
Definition: BFieldManager.h:32
BFieldManager & operator=(const BFieldManager &)=delete
Singleton: no assignment operator.
BFieldManager()=default
Singleton: private constructor.
static ROOT::Math::XYZVector getField(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position.
Definition: BFieldManager.h:53
static ROOT::Math::XYZVector getField(double x, double y, double z)
return the magnetic field at a given position.
Definition: BFieldManager.h:45
static BFieldManager & getInstance()
Return the instance of the magnetic field manager.
BFieldManager(BFieldManager &)=delete
Singleton: no copy constructor.
static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector &pos)
return the magnetic field at a given position in Tesla.
Definition: BFieldManager.h:61
DBObjPtr< MagneticField > m_magfield
Pointer to the actual magnetic field in the database.
Definition: BFieldManager.h:82
~BFieldManager()=default
Empty destructor: this is just a wrapper to access the database object.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
static const double T
[tesla]
Definition: Unit.h:120
ROOT::Math::XYZVector calculate(const ROOT::Math::XYZVector &pos) const
Calculate the field value at a given position and return it.
Definition: BFieldManager.h:85
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:91
Abstract base class for different kinds of events.