9#include <geometry/bfieldmap/BFieldComponentRadial.h>
10#include <geometry/bfieldmap/BFieldComponentBeamline.h>
12#include <framework/utilities/FileSystem.h>
13#include <framework/logging/Logger.h>
15#include <boost/iostreams/filtering_stream.hpp>
16#include <boost/iostreams/device/file.hpp>
17#include <boost/iostreams/filter/gzip.hpp>
23namespace io = boost::iostreams;
28 B2ERROR(
"The filename for the radial magnetic field component is empty !");
35 B2ERROR(
"The radial magnetic field map file '" <<
m_mapFilename <<
"' could not be found !");
40 io::filtering_istream fieldMapFile;
41 fieldMapFile.push(io::gzip_decompressor());
42 fieldMapFile.push(io::file_source(fullPath));
45 B2DEBUG(10,
"Loading the radial magnetic field from file '" <<
m_mapFilename <<
"' in to the memory...");
52 fieldMapFile >> r >> z >> Br >> Bz;
63 B2DEBUG(10,
"... loaded " <<
m_mapSize[0] <<
"x" <<
m_mapSize[1] <<
" (r,z) elements.");
74 return {v.
r * a, v.
z * a};
81 return {u.r + v.
r, u.z + v.
z};
88 ROOT::Math::XYZVector B;
100 double r2 = point.Perp2();
109 int ir =
static_cast<int>(wr);
110 int iz =
static_cast<int>(wz);
116 int il =
static_cast<int>(wl);
119 double l = dz_eklm - L;
134 int idz = (izl0 == iz) - (izl1 == iz) + (ingap ? -ig : ig);
135 iz += (za > 0) ? idz : -idz;
146 double wz0 = 1 - wz, wr0 = 1 - wr;
148 const unsigned int strideZ =
m_mapSize[1];
149 const unsigned int i00 = ir * strideZ + iz, i01 = i00 + 1, i10 = i00 + strideZ, i11 = i01 + strideZ;
151 double w00 = wz0 * wr0, w01 = wz * wr0, w10 = wz0 * wr, w11 = wz * wr;
152 BFieldPoint Brz = H[i00] * w00 + H[i01] * w01 + H[i10] * w10 + H[i11] * w11;
155 double norm = Brz.
r / r;
156 B.SetXYZ(point.X()*norm, point.Y()*norm, Brz.
z);
double m_iLayer
reciprocal of height of the layer (gap + iron plate) in endyoke
double m_slotRMin
minimum radius for the gap in endyoke
virtual void initialize() override
Initializes the magnetic field component.
double m_gridPitchZ
The grid pitch in z.
std::string m_mapFilename
The filename of the magnetic field map.
double m_Layer
height of the layer (gap + iron plate) in endyoke
virtual void terminate() override
Terminates the magnetic field component.
double m_mapRegionZ[2]
The min and max boundaries of the map region in z.
double m_mapOffset
Offset required because the accelerator group defines the Belle center as zero.
virtual ROOT::Math::XYZVector calculate(const ROOT::Math::XYZVector &point) const override
Calculates the magnetic field vector at the specified space point.
double m_ironPlateThickness
thickness of iron plate in endyoke
double m_gridPitchR
The grid pitch in r.
double m_mapRegionR[2]
The min and max boundaries of the map region in r.
double m_endyokeZMin
minimum Z of endyoke
std::vector< BFieldPoint > m_mapBuffer
The memory buffer for the magnetic field map.
double m_gapHeight
height of the gap in endyoke
double m_igridPitchZ
The reciprocal of grid pitch in z.
int m_mapSize[2]
The size of the map in r and z.
double m_igridPitchR
The reciprocal of grid pitch in r.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
B2Vector3< DataType > operator*(DataType a, const B2Vector3< DataType > &p)
non-memberfunction Scaling of 3-vectors with a real number
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
double sqrt(double a)
sqrt for double
static BFieldComponentBeamline & Instance()
BFieldComponentBeamline instance.
Abstract base class for different kinds of events.
Magnetic field data structure.
double r
Magnetic field in r direction.
double z
Magnetic field in z direction.