Belle II Software  release-08-01-10
MagneticFieldComponent3D.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 <framework/dbobjects/MagneticFieldComponent.h>
12 #include <framework/geometry/B2Vector3.h>
13 
14 #include <vector>
15 
16 namespace Belle2 {
23  public:
27  MagneticFieldComponent3D(double minR, double maxR, double minZ, double maxZ,
28  int nR, int nPhi, int nZ,
29  std::vector<ROOT::Math::XYZVector>&& fieldmap):
30  MagneticFieldComponent(true), m_minR(minR), m_maxR(maxR), m_minZ(minZ), m_maxZ(maxZ), m_mapSize{nR, nPhi, nZ},
31  m_gridPitch{static_cast<float>((maxR - minR) / (nR - 1)), static_cast<float>(M_PI / (nPhi - 1)), static_cast<float>((maxZ - minZ) / (nZ - 1))},
32  m_invgridPitch{static_cast<float>(1. / m_gridPitch[0]), static_cast<float>(1. / m_gridPitch[1]), static_cast<float>(1. / m_gridPitch[2])},
33  m_bmap(fieldmap)
34  {}
35 
37  bool inside(const ROOT::Math::XYZVector& pos) const override
38  {
39  const float z = pos.Z();
40  if (z < m_minZ || z > m_maxZ) return false;
41  const float r = pos.Rho();
42  return (r >= m_minR && r <= m_maxR);
43  }
45  ROOT::Math::XYZVector getField(const ROOT::Math::XYZVector& pos) const override;
46  private:
55  ROOT::Math::XYZVector interpolate(unsigned int ir, unsigned int iphi, unsigned int iz, double wr, double wphi, double wz) const;
57  float m_minR{0};
59  float m_maxR{0};
61  float m_minZ{0};
63  float m_maxZ{0};
65  int m_mapSize[3] {0};
67  float m_gridPitch[3] {0};
69  float m_invgridPitch[3] {0};
71  std::vector<ROOT::Math::XYZVector> m_bmap;
74  };
76 }; // Belle2 namespace
Describe one component of the Geometry.
bool inside(const ROOT::Math::XYZVector &pos) const override
return whether we are inside the active region for this component
MagneticFieldComponent3D(double minR, double maxR, double minZ, double maxZ, int nR, int nPhi, int nZ, std::vector< ROOT::Math::XYZVector > &&fieldmap)
Full constructor to create an object from data.
float m_maxR
maximal R=sqrt(x^2+y^2) for which this field is present
float m_gridPitch[3]
grid pitch in r, phi and z
int m_mapSize[3]
number of bins in r, phi and z
float m_maxZ
maximal Z for which this field is present
std::vector< ROOT::Math::XYZVector > m_bmap
magnetic field strength
ClassDefOverride(MagneticFieldComponent3D, 2)
ROOT dictionary.
float m_invgridPitch[3]
inverted grid pitch in r, phi and z
MagneticFieldComponent3D()
empty constructor for ROOT
float m_minZ
minimal Z for which this field is present
float m_minR
minimal R=sqrt(x^2+y^2) for which this field is present
Abstract base class for BField components.
ROOT::Math::XYZVector interpolate(unsigned int ir, unsigned int iphi, unsigned int iz, double wr, double wphi, double wz) const
Linear interpolate the magnetic field inside a bin.
ROOT::Math::XYZVector getField(const ROOT::Math::XYZVector &pos) const override
return the field assuming we are inside the active region as returned by inside()
Abstract base class for different kinds of events.