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 <Math/Vector3D.h>
12#include <framework/logging/Logger.h>
13#include <framework/gearbox/Unit.h>
14#include <framework/database/DBObjPtr.h>
15#include <framework/dbobjects/MagneticField.h>
16
17namespace Belle2 {
32 public:
37 static void getField(const double* pos, double* field);
44 static ROOT::Math::XYZVector getField(double x, double y, double z)
45 {
46 return getField(ROOT::Math::XYZVector(x, y, z));
47 }
52 static ROOT::Math::XYZVector getField(const ROOT::Math::XYZVector& pos)
53 {
55 }
60 static ROOT::Math::XYZVector getFieldInTesla(const ROOT::Math::XYZVector& pos)
61 {
62 return getField(pos) / Unit::T;
63 }
65 static BFieldManager& getInstance();
66 private:
68 BFieldManager() = default;
74 ~BFieldManager() = default;
79 ROOT::Math::XYZVector calculate(const ROOT::Math::XYZVector& pos) const;
82 };
83
84 inline ROOT::Math::XYZVector BFieldManager::calculate(const ROOT::Math::XYZVector& pos) const
85 {
86 if (!m_magfield) B2FATAL("Could not load magnetic field configuration from database");
87 return m_magfield->getField(pos);
88 };
89
90 inline void BFieldManager::getField(const double* pos, double* field)
91 {
92 ROOT::Math::XYZVector fieldvec = getField(ROOT::Math::XYZVector(pos[0], pos[1], pos[2]));
93 field[0] = fieldvec.X();
94 field[1] = fieldvec.Y();
95 field[2] = fieldvec.Z();
96 }
98}
Bfield manager to obtain the magnetic field at any point.
Definition: BFieldManager.h:31
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:52
static ROOT::Math::XYZVector getField(double x, double y, double z)
return the magnetic field at a given position.
Definition: BFieldManager.h:44
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:60
DBObjPtr< MagneticField > m_magfield
Pointer to the actual magnetic field in the database.
Definition: BFieldManager.h:81
~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:84
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:90
Abstract base class for different kinds of events.