Belle II Software light-2406-ragdoll
BFieldComponentRadial Class Reference

The BFieldComponentRadial class. More...

#include <BFieldComponentRadial.h>

Inheritance diagram for BFieldComponentRadial:
Collaboration diagram for BFieldComponentRadial:

Classes

struct  BFieldPoint
 Magnetic field data structure. More...
 

Public Member Functions

 BFieldComponentRadial ()=default
 The BFieldComponentRadial constructor.
 
virtual ~BFieldComponentRadial ()=default
 The BFieldComponentRadial destructor.
 
virtual void initialize () override
 Initializes the magnetic field component.
 
virtual ROOT::Math::XYZVector calculate (const ROOT::Math::XYZVector &point) const override
 Calculates the magnetic field vector at the specified space point.
 
virtual void terminate () override
 Terminates the magnetic field component.
 
void setMapFilename (const std::string &filename)
 Sets the filename of the magnetic field map.
 
void setMapSize (int sizeR, int sizeZ)
 Sets the size of the magnetic field map.
 
void setMapRegionZ (double minZ, double maxZ, double offset)
 Sets the size of the magnetic field map.
 
void setMapRegionR (double minR, double maxR)
 Sets the size of the magnetic field map.
 
void setGridPitch (double pitchR, double pitchZ)
 Sets the grid pitch of the magnetic field map.
 
void setKlmParameters (double srmin, double zyoke, double gaph, double iront)
 Sets parameter for EKLM.
 

Private Attributes

std::string m_mapFilename {""}
 The filename of the magnetic field map.
 
std::vector< BFieldPointm_mapBuffer
 The memory buffer for the magnetic field map.
 
int m_mapSize [2] {0}
 The size of the map in r and z.
 
double m_mapRegionZ [2] {0}
 The min and max boundaries of the map region in z.
 
double m_mapOffset {0}
 Offset required because the accelerator group defines the Belle center as zero.
 
double m_mapRegionR [2] {0}
 The min and max boundaries of the map region in r.
 
double m_gridPitchR {0}
 The grid pitch in r.
 
double m_gridPitchZ {0}
 The grid pitch in z.
 
double m_igridPitchR {0}
 The reciprocal of grid pitch in r.
 
double m_igridPitchZ {0}
 The reciprocal of grid pitch in z.
 
double m_slotRMin {0}
 minimum radius for the gap in endyoke
 
double m_endyokeZMin {0}
 minimum Z of endyoke
 
double m_gapHeight {0}
 height of the gap in endyoke
 
double m_ironPlateThickness {0}
 thickness of iron plate in endyoke
 
double m_Layer {0}
 height of the layer (gap + iron plate) in endyoke
 
double m_iLayer {0}
 reciprocal of height of the layer (gap + iron plate) in endyoke
 

Detailed Description

The BFieldComponentRadial class.

This class represents a radial magnetic field map. The magnetic field map is stored as a grid in cylindrical coordinates. It is defined by a minimum radius and a maximum radius, a minimum z and a maximum z value, a pitch size in both, r and z, and the number of grid points. The ZOffset is used to account for the fact that the acceleration group defines 0 to be in the center of the detector, while the detector group defines the IP to be the center. The filename points to the zip file containing the magnetic field map.

Definition at line 34 of file BFieldComponentRadial.h.

Member Function Documentation

◆ calculate()

ROOT::Math::XYZVector calculate ( const ROOT::Math::XYZVector &  point) const
overridevirtual

Calculates the magnetic field vector at the specified space point.

Parameters
pointThe space point in Cartesian coordinates (x,y,z) in [cm] at which the magnetic field vector should be calculated.
Returns
The magnetic field vector at the given space point in [T]. Returns a zero vector XYZVector(0,0,0) if the space point lies outside the region described by the component.

Implements BFieldComponentAbs.

Definition at line 86 of file BFieldComponentRadial.cc.

87{
88 ROOT::Math::XYZVector B;
89 // If both 'Radial' and 'Beamline' components are defined in xml file,
90 // '3d' component returns zero field where 'Beamline' component is defined.
91 // If no 'Beamline' component is defined in xml file, the following function will never be called.
92 if (BFieldComponentBeamline::Instance().isInRange(point)) return B;
93
94 //Get the z component
95 double z = point.Z();
96 //Check if the point lies inside the magnetic field boundaries
97 if ((z < m_mapRegionZ[0]) || (z > m_mapRegionZ[1])) return B;
98
99 //Get the r component
100 double r2 = point.Perp2();
101 //Check if the point lies inside the magnetic field boundaries
102 if ((r2 < m_mapRegionR[0]*m_mapRegionR[0]) || (r2 > m_mapRegionR[1]*m_mapRegionR[1])) return B;
103
104 double r = sqrt(r2);
105 //Calculate the distance to the lower grid point
106 double wr = (r - m_mapRegionR[0]) * m_igridPitchR;
107 double wz = (z - m_mapRegionZ[0]) * m_igridPitchZ;
108 //Calculate the lower index of the point in the grid
109 int ir = static_cast<int>(wr);
110 int iz = static_cast<int>(wz);
111
112 double za = z - m_mapOffset;
113 double dz_eklm = abs(za) - (m_endyokeZMin - m_gapHeight);
114 if (dz_eklm > 0 && r > m_slotRMin) {
115 double wl = dz_eklm * m_iLayer;
116 int il = static_cast<int>(wl);
117 if (il <= 16) {
118 double L = m_Layer * il;
119 double l = dz_eklm - L;
120 int ingap = l < m_gapHeight;
121 ir += ingap & (r < m_slotRMin + m_gridPitchR);
122
123 double zlg = L + m_endyokeZMin, zl0 = zlg - m_gapHeight, zl1 = zlg + m_ironPlateThickness;
124 if (za < 0) {
125 zl0 = -zl0;
126 zlg = -zlg;
127 zl1 = -zl1;
128 }
129 double zoff = m_mapOffset - m_mapRegionZ[0];
130 int izl0 = static_cast<int>((zl0 + zoff) * m_igridPitchZ);
131 int izlg = static_cast<int>((zlg + zoff) * m_igridPitchZ);
132 int izl1 = static_cast<int>((zl1 + zoff) * m_igridPitchZ);
133 int ig = izlg == iz;
134 int idz = (izl0 == iz) - (izl1 == iz) + (ingap ? -ig : ig);
135 iz += (za > 0) ? idz : -idz;
136 }
137 }
138
139 //Bring the index values within the range
140 ir = min(m_mapSize[0] - 2, ir);
141 iz = min(m_mapSize[1] - 2, iz);
142
143 wr -= ir;
144 wz -= iz;
145
146 double wz0 = 1 - wz, wr0 = 1 - wr;
147 //Calculate the linear approx. of the magnetic field vector
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;
150 const BFieldPoint* H = m_mapBuffer.data();
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;
153
154 if (r > 0.0) {
155 double norm = Brz.r / r;
156 B.SetXYZ(point.X()*norm, point.Y()*norm, Brz.z);
157 } else {
158 B.SetZ(Brz.z);
159 }
160
161 return B;
162}
double m_iLayer
reciprocal of height of the layer (gap + iron plate) in endyoke
double m_slotRMin
minimum radius for the gap in endyoke
double m_Layer
height of the layer (gap + iron plate) in endyoke
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.
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 BFieldComponentBeamline & Instance()
BFieldComponentBeamline instance.

◆ initialize()

void initialize ( )
overridevirtual

Initializes the magnetic field component.

This method opens the magnetic field map file.

Reimplemented from BFieldComponentAbs.

Definition at line 25 of file BFieldComponentRadial.cc.

26{
27 if (m_mapFilename.empty()) {
28 B2ERROR("The filename for the radial magnetic field component is empty !");
29 return;
30 }
31
32 string fullPath = FileSystem::findFile("/data/" + m_mapFilename);
33
34 if (!FileSystem::fileExists(fullPath)) {
35 B2ERROR("The radial magnetic field map file '" << m_mapFilename << "' could not be found !");
36 return;
37 }
38
39 //Load the map file
40 io::filtering_istream fieldMapFile;
41 fieldMapFile.push(io::gzip_decompressor());
42 fieldMapFile.push(io::file_source(fullPath));
43
44 //Create the magnetic field map [r,z] and read the data from the file
45 B2DEBUG(10, "Loading the radial magnetic field from file '" << m_mapFilename << "' in to the memory...");
46 m_mapBuffer.clear();
47 m_mapBuffer.reserve(m_mapSize[0]*m_mapSize[1]);
48
49 double r, z, Br, Bz;
50 for (int i = 0; i < m_mapSize[0]; ++i) {
51 for (int j = 0; j < m_mapSize[1]; j++) {
52 fieldMapFile >> r >> z >> Br >> Bz;
53 //Store the values
54 m_mapBuffer.push_back({Br, Bz});
55 }
56 }
57
61 m_iLayer = 1 / m_Layer;
62
63 B2DEBUG(10, "... loaded " << m_mapSize[0] << "x" << m_mapSize[1] << " (r,z) elements.");
64}
double m_gridPitchZ
The grid pitch in z.
std::string m_mapFilename
The filename of the magnetic field map.
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...
Definition: FileSystem.cc:151
static bool fileExists(const std::string &filename)
Check if the file with given filename exists.
Definition: FileSystem.cc:32

◆ setGridPitch()

void setGridPitch ( double  pitchR,
double  pitchZ 
)
inline

Sets the grid pitch of the magnetic field map.

Parameters
pitchRThe pitch of the grid in r [cm].
pitchZThe pitch of the grid in z [cm].

Definition at line 103 of file BFieldComponentRadial.h.

103{ m_gridPitchR = pitchR; m_gridPitchZ = pitchZ; }

◆ setKlmParameters()

void setKlmParameters ( double  srmin,
double  zyoke,
double  gaph,
double  iront 
)
inline

Sets parameter for EKLM.

Parameters
srminminimum radius for the gap in endyoke [cm].
zyokeminimum Z of endyoke [cm].
gaphheight of the gap in endyoke [cm].
irontthickness of iron plate in endyoke [cm].

Definition at line 113 of file BFieldComponentRadial.h.

114 {
115 m_slotRMin = srmin, m_endyokeZMin = zyoke; m_gapHeight = gaph; m_ironPlateThickness = iront;
116 }

◆ setMapFilename()

void setMapFilename ( const std::string &  filename)
inline

Sets the filename of the magnetic field map.

Parameters
filenameThe filename of the magnetic field map.

Definition at line 74 of file BFieldComponentRadial.h.

74{ m_mapFilename = filename; };

◆ setMapRegionR()

void setMapRegionR ( double  minR,
double  maxR 
)
inline

Sets the size of the magnetic field map.

Parameters
minRThe left (min) border of the magnetic field map region in r [cm].
maxRThe right (max) border of the magnetic field map region in r [cm].

Definition at line 96 of file BFieldComponentRadial.h.

96{ m_mapRegionR[0] = minR; m_mapRegionR[1] = maxR; }

◆ setMapRegionZ()

void setMapRegionZ ( double  minZ,
double  maxZ,
double  offset 
)
inline

Sets the size of the magnetic field map.

Parameters
minZThe left (min) border of the magnetic field map region in z [cm].
maxZThe right (max) border of the magnetic field map region in z [cm].
offsetThe offset in z [cm] which is required because the accelerator group defines the Belle center as zero.

Definition at line 89 of file BFieldComponentRadial.h.

89{ m_mapRegionZ[0] = minZ; m_mapRegionZ[1] = maxZ; m_mapOffset = offset; }

◆ setMapSize()

void setMapSize ( int  sizeR,
int  sizeZ 
)
inline

Sets the size of the magnetic field map.

Parameters
sizeRThe number of points in the r direction.
sizeZThe number of points in the z direction.

Definition at line 81 of file BFieldComponentRadial.h.

81{ m_mapSize[0] = sizeR; m_mapSize[1] = sizeZ; }

◆ terminate()

void terminate ( )
overridevirtual

Terminates the magnetic field component.

This method closes the magnetic field map file.

Reimplemented from BFieldComponentAbs.

Definition at line 164 of file BFieldComponentRadial.cc.

165{
166}

Member Data Documentation

◆ m_endyokeZMin

double m_endyokeZMin {0}
private

minimum Z of endyoke

Definition at line 134 of file BFieldComponentRadial.h.

◆ m_gapHeight

double m_gapHeight {0}
private

height of the gap in endyoke

Definition at line 135 of file BFieldComponentRadial.h.

◆ m_gridPitchR

double m_gridPitchR {0}
private

The grid pitch in r.

Definition at line 128 of file BFieldComponentRadial.h.

◆ m_gridPitchZ

double m_gridPitchZ {0}
private

The grid pitch in z.

Definition at line 129 of file BFieldComponentRadial.h.

◆ m_igridPitchR

double m_igridPitchR {0}
private

The reciprocal of grid pitch in r.

Definition at line 130 of file BFieldComponentRadial.h.

◆ m_igridPitchZ

double m_igridPitchZ {0}
private

The reciprocal of grid pitch in z.

Definition at line 131 of file BFieldComponentRadial.h.

◆ m_iLayer

double m_iLayer {0}
private

reciprocal of height of the layer (gap + iron plate) in endyoke

Definition at line 138 of file BFieldComponentRadial.h.

◆ m_ironPlateThickness

double m_ironPlateThickness {0}
private

thickness of iron plate in endyoke

Definition at line 136 of file BFieldComponentRadial.h.

◆ m_Layer

double m_Layer {0}
private

height of the layer (gap + iron plate) in endyoke

Definition at line 137 of file BFieldComponentRadial.h.

◆ m_mapBuffer

std::vector<BFieldPoint> m_mapBuffer
private

The memory buffer for the magnetic field map.

Definition at line 123 of file BFieldComponentRadial.h.

◆ m_mapFilename

std::string m_mapFilename {""}
private

The filename of the magnetic field map.

Definition at line 122 of file BFieldComponentRadial.h.

◆ m_mapOffset

double m_mapOffset {0}
private

Offset required because the accelerator group defines the Belle center as zero.

Definition at line 126 of file BFieldComponentRadial.h.

◆ m_mapRegionR

double m_mapRegionR[2] {0}
private

The min and max boundaries of the map region in r.

Definition at line 127 of file BFieldComponentRadial.h.

◆ m_mapRegionZ

double m_mapRegionZ[2] {0}
private

The min and max boundaries of the map region in z.

Definition at line 125 of file BFieldComponentRadial.h.

◆ m_mapSize

int m_mapSize[2] {0}
private

The size of the map in r and z.

Definition at line 124 of file BFieldComponentRadial.h.

◆ m_slotRMin

double m_slotRMin {0}
private

minimum radius for the gap in endyoke

Definition at line 133 of file BFieldComponentRadial.h.


The documentation for this class was generated from the following files: