Belle II Software  release-06-01-15
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 
13 namespace Belle2 {
20  public:
24  MagneticFieldComponent3D(double minR, double maxR, double minZ, double maxZ,
25  int nR, int nPhi, int nZ,
26  std::vector<B2Vector3F>&& fieldmap):
27  MagneticFieldComponent(true), m_minR(minR), m_maxR(maxR), m_minZ(minZ), m_maxZ(maxZ), m_mapSize{nR, nPhi, nZ},
28  m_gridPitch{static_cast<float>((maxR - minR) / (nR - 1)), static_cast<float>(M_PI / (nPhi - 1)), static_cast<float>((maxZ - minZ) / (nZ - 1))},
29  m_invgridPitch{static_cast<float>(1. / m_gridPitch[0]), static_cast<float>(1. / m_gridPitch[1]), static_cast<float>(1. / m_gridPitch[2])},
30  m_bmap(fieldmap)
31  {}
32 
34  bool inside(const B2Vector3D& pos) const override
35  {
36  const float z = pos.Z();
37  if (z < m_minZ || z > m_maxZ) return false;
38  const float r = pos.Perp();
39  return (r >= m_minR && r <= m_maxR);
40  }
42  B2Vector3D getField(const B2Vector3D& pos) const override;
43  private:
52  B2Vector3D interpolate(unsigned int ir, unsigned int iphi, unsigned int iz, double wr, double wphi, double wz) const;
54  float m_minR{0};
56  float m_maxR{0};
58  float m_minZ{0};
60  float m_maxZ{0};
62  int m_mapSize[3] {0};
64  float m_gridPitch[3] {0};
66  float m_invgridPitch[3] {0};
68  std::vector<B2Vector3F> m_bmap;
71  };
73 }; // Belle2 namespace
Describe one component of the Geometry.
ClassDefOverride(MagneticFieldComponent3D, 1)
ROOT dictionary.
float m_maxR
maximal R=sqrt(x^2+y^2) for which this field is present
bool inside(const B2Vector3D &pos) const override
return whether we are inside the active region for this component
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
MagneticFieldComponent3D(double minR, double maxR, double minZ, double maxZ, int nR, int nPhi, int nZ, std::vector< B2Vector3F > &&fieldmap)
Full constructor to create an object from data.
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
std::vector< B2Vector3F > m_bmap
magnetic field strength
Abstract base class for BField components.
B2Vector3D 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.
B2Vector3D getField(const B2Vector3D &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.