Belle II Software  release-05-02-19
BFieldManager.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - 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 
13 #include <vector>
14 #include <framework/logging/Logger.h>
15 #include <framework/geometry/B2Vector3.h>
16 #include <framework/gearbox/Unit.h>
17 #include <framework/database/DBObjPtr.h>
18 #include <framework/dbobjects/MagneticField.h>
19 
20 namespace Belle2 {
34  class BFieldManager {
35  public:
40  static void getField(const double* pos, double* field);
45  static TVector3 getField(const TVector3& pos)
46  {
47  return getField(B2Vector3D(pos)).GetTVector3();
48  }
49 
56  static B2Vector3D getField(double x, double y, double z)
57  {
58  return getField(B2Vector3D(x, y, z));
59  }
64  static B2Vector3D getField(const B2Vector3D& pos)
65  {
67  }
73  {
74  return getField(pos) / Unit::T;
75  }
77  static BFieldManager& getInstance();
78  private:
80  BFieldManager() = default;
82  BFieldManager(BFieldManager&) = delete;
84  BFieldManager& operator=(const BFieldManager&) = delete;
86  ~BFieldManager() = default;
91  B2Vector3D calculate(const B2Vector3D& pos) const;
94  };
95 
96  inline B2Vector3D BFieldManager::calculate(const B2Vector3D& pos) const
97  {
98  if (!m_magfield) B2FATAL("Could not load magnetic field configuration from database");
99  return m_magfield->getField(pos);
100  };
101 
102  inline void BFieldManager::getField(const double* pos, double* field)
103  {
104  B2Vector3D fieldvec = getField(B2Vector3D(pos));
105  fieldvec.GetXYZ(field);
106  }
108 }
Belle2::BFieldManager::getInstance
static BFieldManager & getInstance()
Return the instance of the magnetic field manager.
Definition: BFieldManager.cc:15
Belle2::BFieldManager::getField
static B2Vector3D getField(double x, double y, double z)
return the magnetic field at a given position.
Definition: BFieldManager.h:64
Belle2::BFieldManager::getField
static void getField(const double *pos, double *field)
return the magnetic field at a given position.
Definition: BFieldManager.h:110
Belle2::BFieldManager
Bfield manager to obtain the magnetic field at any point.
Definition: BFieldManager.h:42
Belle2::BFieldManager::calculate
B2Vector3D calculate(const B2Vector3D &pos) const
Calculate the field value at a given position and return it.
Definition: BFieldManager.h:104
Belle2::BFieldManager::BFieldManager
BFieldManager()=default
Singleton: private constructor.
Belle2::BFieldManager::operator=
BFieldManager & operator=(const BFieldManager &)=delete
Singleton: no assignment operator.
Belle2::B2Vector3::GetXYZ
void GetXYZ(Double_t *carray) const
directly copies coordinates to an array of double
Belle2::BFieldManager::getFieldInTesla
static B2Vector3D getFieldInTesla(const B2Vector3D &pos)
return the magnetic field at a given position in Tesla.
Definition: BFieldManager.h:80
Belle2::BFieldManager::m_magfield
DBObjPtr< MagneticField > m_magfield
Pointer to the actual magnetic field in the database.
Definition: BFieldManager.h:101
Belle2::DBObjPtr
Class for accessing objects in the database.
Definition: DBObjPtr.h:31
Belle2::B2Vector3< double >
Belle2::Unit::T
static const double T
[tesla]
Definition: Unit.h:130
Belle2::B2Vector3D
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition: B2Vector3.h:507
Belle2::BFieldManager::~BFieldManager
~BFieldManager()=default
Empty destructor: this is just a wrapper to access the database object.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19