Belle II Software  release-06-02-00
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 <framework/logging/Logger.h>
13 #include <framework/geometry/B2Vector3.h>
14 #include <framework/gearbox/Unit.h>
15 #include <framework/database/DBObjPtr.h>
16 #include <framework/dbobjects/MagneticField.h>
17 
18 namespace Belle2 {
32  class BFieldManager {
33  public:
38  static void getField(const double* pos, double* field);
43  static TVector3 getField(const TVector3& pos)
44  {
45  return getField(B2Vector3D(pos)).GetTVector3();
46  }
47 
54  static B2Vector3D getField(double x, double y, double z)
55  {
56  return getField(B2Vector3D(x, y, z));
57  }
62  static B2Vector3D getField(const B2Vector3D& pos)
63  {
65  }
71  {
72  return getField(pos) / Unit::T;
73  }
75  static BFieldManager& getInstance();
76  private:
78  BFieldManager() = default;
84  ~BFieldManager() = default;
89  B2Vector3D calculate(const B2Vector3D& pos) const;
92  };
93 
95  {
96  if (!m_magfield) B2FATAL("Could not load magnetic field configuration from database");
97  return m_magfield->getField(pos);
98  };
99 
100  inline void BFieldManager::getField(const double* pos, double* field)
101  {
102  B2Vector3D fieldvec = getField(B2Vector3D(pos));
103  fieldvec.GetXYZ(field);
104  }
106 }
void GetXYZ(Double_t *carray) const
directly copies coordinates to an array of double
Bfield manager to obtain the magnetic field at any point.
Definition: BFieldManager.h:32
static B2Vector3D getField(double x, double y, double z)
return the magnetic field at a given position.
Definition: BFieldManager.h:54
BFieldManager()=default
Singleton: private constructor.
static TVector3 getField(const TVector3 &pos)
return the magnetic field at a given position.
Definition: BFieldManager.h:43
static BFieldManager & getInstance()
Return the instance of the magnetic field manager.
BFieldManager(BFieldManager &)=delete
Singleton: no copy constructor.
static B2Vector3D getFieldInTesla(const B2Vector3D &pos)
return the magnetic field at a given position in Tesla.
Definition: BFieldManager.h:70
BFieldManager & operator=(const BFieldManager &)=delete
Singleton: no assignment operator.
static B2Vector3D getField(const B2Vector3D &pos)
return the magnetic field at a given position.
Definition: BFieldManager.h:62
DBObjPtr< MagneticField > m_magfield
Pointer to the actual magnetic field in the database.
Definition: BFieldManager.h:91
~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
B2Vector3D calculate(const B2Vector3D &pos) const
Calculate the field value at a given position and return it.
Definition: BFieldManager.h:94
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:493
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Abstract base class for different kinds of events.