Belle II Software light-2406-ragdoll
BFieldComponentKlm1 Class Reference

The Bfieldcomponentklm1 class. More...

#include <BFieldComponentKlm1.h>

Inheritance diagram for BFieldComponentKlm1:
Collaboration diagram for BFieldComponentKlm1:

Classes

struct  BFieldPoint
 Trivial struct representing rz coordinate. More...
 

Public Member Functions

 BFieldComponentKlm1 ()=default
 The BFieldComponentklm1 constructor.
 
virtual ~BFieldComponentKlm1 ()=default
 The BFieldComponentklm1 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 setNLayers (int b, int e)
 Sets the number of barrel and endcap layers.
 
void setBarrelRegion (double minR, double maxZ, double offset)
 Sets the dimensions of the barrel region.
 
void setEndcapRegion (double minR, double minZ)
 Set the dimensions of the endcap region.
 
void setLayerParam (double bgapl0, double bironth, double egap, double dl)
 Set the layer parameters.
 

Private Attributes

double m_cospi8 {cos(M_PI / 8)}
 cos(pi/8)
 
double m_cos3pi8 {cos(3 * M_PI / 8)}
 cos(3pi/8)
 
double m_cospi4 {cos(M_PI / 4)}
 cos(pi/4)
 
std::string m_mapFilename {""}
 The filename of the magnetic field map.
 
double m_mapOffset {0}
 Offset required because the accelerator group defines the Belle center as zero.
 
double m_barrelRMin {0}
 The minimum boundaries of BKLM region in r.
 
double m_barrelZMax {0}
 The maximum boundaries of BKLM region in r.
 
double m_endcapRMin {0}
 The minimum boundaries of EKLM region in r.
 
double m_endcapZMin {0}
 The minimum boundaries of EKLM region in z.
 
int m_nBarrelLayers {0}
 The number of layers per 1 sector for BKLM.
 
int m_nEndcapLayers {0}
 The number of layers per 1 sector for EKLM.
 
double m_barrelGapHeightLayer0 {0}
 Gap height of BKLM layer0.
 
double m_endcapGapHeight {0}
 Gap height of BKLM layer1-14.
 
double m_dLayer {0}
 depth of BKLM module?
 
double m_barrelIronThickness {0}
 Thickness of Barrel iron plate.
 
double m_barrelZBreakpoint [15] {0}
 z position of breakpoints between the two linear approximations of Bz in the barrel.
 
double m_barrelRBreakpoint [15] {0}
 z position of breakpoints between the two linear approximations of Br in the barrel.
 
double m_barrelFieldZSlope1 [15] {0}
 Slope of Bz before the breakpoint in the barrel.
 
double m_barrelFieldZIntercept1 [15] {0}
 Intercept of Bz before the beackpoint in the barrel.
 
double m_barrelFieldZSlope2 [15] {0}
 Slope of Bz after the breakpoint in the barrel.
 
double m_barrelFieldZIntercept2 [15] {0}
 Intercept of Bz after the breakpoint in the barrel.
 
double m_barrelFieldRSlope1 [15] {0}
 Slope of Br before the breakpoint in the barrel.
 
double m_barrelFieldRIntercept1 [15] {0}
 Intercept of Br before the beackpoint in the barrel.
 
double m_barrelFieldRSlope2 [15] {0}
 Slope of Br after the breakpoint in the barrel.
 
double m_barrelFieldRIntercept2 [15] {0}
 Intercept of Br after the beackpoint in the barrel.
 
double m_endcapZBreakpoint [2][15][5] {{{0}}}
 z position of breakpoints between linear functions in the endcap.
 
double m_endcapRBreakpoint [2][15][5] {{{0}}}
 r position of breakpoints between linear functions in the endcap First index indicates whether or not where in a gap (0) or in iron (1), second index is the layer and third index is the number of breaks we have in the linear approximation and their positions
 
double m_endcapFieldZSlope [2][15][5] {{{0}}}
 Slopes of the linear approximation of Bz in the endcap.
 
double m_endcapFieldZIntercept [2][15][5] {{{0}}}
 Intercepts of the linear approximation of Bz in the endcap.
 
double m_endcapFieldRSlope [2][15][5] {{{0}}}
 Slopes of the linear approximation of Br in the endcap.
 
double m_endcapFieldRIntercept [2][15][5] {{{0}}}
 Intercepts of the linear approximation of Br in the endcap.
 

Detailed Description

The Bfieldcomponentklm1 class.

This class represents a magnetic field map in KLM region and outside of solenoid. This magnetic field is for Belle. This is porting class from g4superb to basf2. The magnetic field map is stored as linear functions in cylindrical coordinates. It is defined by a maximum radius, a minimum z, r and z, the number of layers for Barrel KLM and Endcap KLM. 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.

Definition at line 33 of file BFieldComponentKlm1.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 87 of file BFieldComponentKlm1.cc.

88{
89 //Get the r and z Component
90 double r = point.Rho();
91 double x = point.X();
92 double y = point.Y();
93 double z = point.Z() - m_mapOffset;
94 double absZ = std::abs(z);
95
96 ROOT::Math::XYZVector bField(0., 0., 0.);
97
98 // Barrel
99 if (absZ < m_barrelZMax) {
100
101 // This code assumes that we are in the barrel KLM. Use the field map
102 // inside an iron plate; use zero in the gap between the iron plates.
103
104 double cosphi = std::abs(x) / r;
105 double d = ((cosphi < m_cospi8) ? ((cosphi < m_cos3pi8) ? std::abs(y)
106 : (std::abs(x) + std::abs(y)) * m_cospi4)
108
109 if (d >= 0.0) {
110 int layer = static_cast<int>(floor(d / m_dLayer));
111
112 // make sure layer is in a valid range
113 if (layer < 0 || layer > m_nBarrelLayers) return bField;
114 if (layer == m_nBarrelLayers) {
115 layer = m_nBarrelLayers - 1;
116 d = layer * m_dLayer; // for extra-thick outermost iron plate
117 }
118 if ((d - layer * m_dLayer) < m_barrelIronThickness) {
119 double br = ((absZ > m_barrelRBreakpoint[layer]) ?
120 m_barrelFieldRIntercept2[layer] + m_barrelFieldRSlope2[layer] * absZ :
121 m_barrelFieldRIntercept1[layer] + m_barrelFieldRSlope1[layer] * absZ);
122 if (z < 0.0) { br = -br; }
123 bField.SetXYZ(br * x / r, br * y / r,
124 ((absZ > m_barrelZBreakpoint[layer]) ?
125 m_barrelFieldZIntercept2[layer] + m_barrelFieldZSlope2[layer] * absZ :
126 m_barrelFieldZIntercept1[layer] + m_barrelFieldZSlope1[layer] * absZ));
127 }
128 }
129 } else if (absZ > m_endcapZMin) {
130 //Endcap
131 if (r <= m_endcapRMin) return bField;
132
133 // This code assumes that we are in the endcap KLM.
134 // The field in an inter-plate gap in the endcap is not zero.
135
136 double dz = absZ - (m_endcapZMin - m_endcapGapHeight);
137 int layer = static_cast<int>(floor(dz / m_dLayer));
138 // make sure layer is in a valid range
139 if (layer < 0 || layer >= m_nEndcapLayers) return bField;
140
141 int GapIron = 0; // in gap
142 if ((dz - m_dLayer * layer) > m_endcapGapHeight) GapIron = 1; // in Iron plate?
143 for (int j = 0; j < 5; j++) {
144 if (r < m_endcapRBreakpoint[GapIron][layer][j]) {
145 double br = m_endcapFieldRIntercept[GapIron][layer][j] + m_endcapFieldRSlope[GapIron][layer][j] * r;
146 if (z < 0.0) { br = -br; }
147 bField.SetX(br * x / r);
148 bField.SetY(br * y / r);
149 break;
150 }
151 }
152 for (int j = 0; j < 5; j++) {
153 if (r < m_endcapZBreakpoint[GapIron][layer][j]) {
154 bField.SetZ(m_endcapFieldZIntercept[GapIron][layer][j] + m_endcapFieldZSlope[GapIron][layer][j] * r);
155 break;
156 }
157 }
158 }
159
160 return bField;
161}
double m_endcapFieldZSlope[2][15][5]
Slopes of the linear approximation of Bz in the endcap.
double m_endcapGapHeight
Gap height of BKLM layer1-14.
double m_barrelFieldRIntercept1[15]
Intercept of Br before the beackpoint in the barrel.
int m_nBarrelLayers
The number of layers per 1 sector for BKLM.
double m_barrelFieldZSlope1[15]
Slope of Bz before the breakpoint in the barrel.
double m_endcapFieldRIntercept[2][15][5]
Intercepts of the linear approximation of Br in the endcap.
double m_barrelZMax
The maximum boundaries of BKLM region in r.
double m_barrelIronThickness
Thickness of Barrel iron plate.
double m_barrelFieldZIntercept1[15]
Intercept of Bz before the beackpoint in the barrel.
double m_mapOffset
Offset required because the accelerator group defines the Belle center as zero.
double m_endcapRMin
The minimum boundaries of EKLM region in r.
double m_barrelFieldRSlope2[15]
Slope of Br after the breakpoint in the barrel.
double m_endcapRBreakpoint[2][15][5]
r position of breakpoints between linear functions in the endcap First index indicates whether or not...
double m_barrelRBreakpoint[15]
z position of breakpoints between the two linear approximations of Br in the barrel.
double m_barrelGapHeightLayer0
Gap height of BKLM layer0.
double m_barrelRMin
The minimum boundaries of BKLM region in r.
double m_endcapFieldRSlope[2][15][5]
Slopes of the linear approximation of Br in the endcap.
int m_nEndcapLayers
The number of layers per 1 sector for EKLM.
double m_barrelFieldZIntercept2[15]
Intercept of Bz after the breakpoint in the barrel.
double m_barrelZBreakpoint[15]
z position of breakpoints between the two linear approximations of Bz in the barrel.
double m_barrelFieldZSlope2[15]
Slope of Bz after the breakpoint in the barrel.
double m_barrelFieldRSlope1[15]
Slope of Br before the breakpoint in the barrel.
double m_endcapZBreakpoint[2][15][5]
z position of breakpoints between linear functions in the endcap.
double m_endcapFieldZIntercept[2][15][5]
Intercepts of the linear approximation of Bz in the endcap.
double m_endcapZMin
The minimum boundaries of EKLM region in z.
double m_barrelFieldRIntercept2[15]
Intercept of Br after the beackpoint in the barrel.
double m_dLayer
depth of BKLM module?
STL namespace.

◆ initialize()

void initialize ( )
overridevirtual

Initializes the magnetic field Component.

This method opens the magnetic field map file.

Reimplemented from BFieldComponentAbs.

Definition at line 23 of file BFieldComponentKlm1.cc.

24{
25 if (m_mapFilename.empty()) {
26 B2ERROR("The filename for the magnetic field Component is empty !");
27 return;
28 }
29
30 string fullPath = FileSystem::findFile("/data/" + m_mapFilename);
31
32 if (!FileSystem::fileExists(fullPath)) {
33 B2ERROR("The magnetic field map file '" << m_mapFilename << "' could not be found !");
34 return;
35 }
36
37 //Load the map file
38 io::filtering_istream fieldMapFile;
39 fieldMapFile.push(io::file_source(fullPath));
40
41 //read the data from the file
42 B2DEBUG(10, "Loading the magnetic field from file '" << m_mapFilename << "' in to the memory...");
43
44 char dummy[100];
45
46 //store parameters for Barrel
47 fieldMapFile.getline(dummy, sizeof(dummy));
48 for (int layer = 0; layer < m_nBarrelLayers; ++layer) {
49 int l;
50 fieldMapFile >> l >> m_barrelZBreakpoint[layer] >> m_barrelRBreakpoint[layer]
51 >> m_barrelFieldZSlope1[layer]
53 >> m_barrelFieldZSlope2[layer]
55 >> m_barrelFieldRSlope1[layer]
57 >> m_barrelFieldRSlope2[layer]
59
60 if (layer != l)
61 B2ERROR("Barrel Parameter file is something wrong ! " << layer << " " << l);
62 }
63
64 //store parameters for Endcap
65 fieldMapFile.getline(dummy, sizeof(dummy));
66 fieldMapFile.getline(dummy, sizeof(dummy));
67 for (int GapIron = 0; GapIron < 2; GapIron++) {
68 for (int layer = 0; layer < m_nEndcapLayers + 1; layer++) {
69 for (int j = 0; j < 5; j++) {
70 int g, l, jj;
71 fieldMapFile >> g >> l >> jj
72 >> m_endcapZBreakpoint[GapIron][layer][j] >> m_endcapRBreakpoint[GapIron][layer][j]
73 >> m_endcapFieldZSlope[GapIron][layer][j]
74 >> m_endcapFieldZIntercept[GapIron][layer][j]
75 >> m_endcapFieldRSlope[GapIron][layer][j]
76 >> m_endcapFieldRIntercept[GapIron][layer][j];
77 if (GapIron != g || layer != l || jj != j)
78 B2ERROR("Endcap Parameter file is something wrong ! " << g << " " << l << " " << jj);
79 }
80 }
81 }
82
83 B2DEBUG(10, "... loaded ");
84}
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

◆ setBarrelRegion()

void setBarrelRegion ( double  minR,
double  maxZ,
double  offset 
)
inline

Sets the dimensions of the barrel region.

Parameters
minRminimal radius
maxZmax extension in z in both directions
offsetmap offset in z

Definition at line 87 of file BFieldComponentKlm1.h.

87{ m_barrelRMin = minR; m_barrelZMax = maxZ; m_mapOffset = offset; }

◆ setEndcapRegion()

void setEndcapRegion ( double  minR,
double  minZ 
)
inline

Set the dimensions of the endcap region.

Parameters
minRminimal radius
minZstarting z coordinate in both directions

Definition at line 93 of file BFieldComponentKlm1.h.

93{ m_endcapRMin = minR; m_endcapZMin = minZ;}

◆ setLayerParam()

void setLayerParam ( double  bgapl0,
double  bironth,
double  egap,
double  dl 
)
inline

Set the layer parameters.

Parameters
bgapl0Barrel gap height for layer 0.
bironthBarrel iron thickness.
egapEndcap gap height.
dlDistance between two layers.

Definition at line 102 of file BFieldComponentKlm1.h.

103 {
105 m_endcapGapHeight = egap; m_dLayer = dl;
106 }

◆ 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 BFieldComponentKlm1.h.

74{ m_mapFilename = filename; };

◆ setNLayers()

void setNLayers ( int  b,
int  e 
)
inline

Sets the number of barrel and endcap layers.

Parameters
bbarrel layers
eendcap layers

Definition at line 80 of file BFieldComponentKlm1.h.

◆ terminate()

void terminate ( )
overridevirtual

Terminates the magnetic field Component.

Reimplemented from BFieldComponentAbs.

Definition at line 164 of file BFieldComponentKlm1.cc.

165{
166}

Member Data Documentation

◆ m_barrelFieldRIntercept1

double m_barrelFieldRIntercept1[15] {0}
private

Intercept of Br before the beackpoint in the barrel.

Index indicates the current layer

Definition at line 167 of file BFieldComponentKlm1.h.

◆ m_barrelFieldRIntercept2

double m_barrelFieldRIntercept2[15] {0}
private

Intercept of Br after the beackpoint in the barrel.

Index indicates the current layer

Definition at line 173 of file BFieldComponentKlm1.h.

◆ m_barrelFieldRSlope1

double m_barrelFieldRSlope1[15] {0}
private

Slope of Br before the breakpoint in the barrel.

Index indicates the current layer

Definition at line 164 of file BFieldComponentKlm1.h.

◆ m_barrelFieldRSlope2

double m_barrelFieldRSlope2[15] {0}
private

Slope of Br after the breakpoint in the barrel.

Index indicates the current layer

Definition at line 170 of file BFieldComponentKlm1.h.

◆ m_barrelFieldZIntercept1

double m_barrelFieldZIntercept1[15] {0}
private

Intercept of Bz before the beackpoint in the barrel.

Index indicates the current layer

Definition at line 155 of file BFieldComponentKlm1.h.

◆ m_barrelFieldZIntercept2

double m_barrelFieldZIntercept2[15] {0}
private

Intercept of Bz after the breakpoint in the barrel.

Index indicates the current layer

Definition at line 161 of file BFieldComponentKlm1.h.

◆ m_barrelFieldZSlope1

double m_barrelFieldZSlope1[15] {0}
private

Slope of Bz before the breakpoint in the barrel.

Index indicates the current layer

Definition at line 152 of file BFieldComponentKlm1.h.

◆ m_barrelFieldZSlope2

double m_barrelFieldZSlope2[15] {0}
private

Slope of Bz after the breakpoint in the barrel.

Index indicates the current layer

Definition at line 158 of file BFieldComponentKlm1.h.

◆ m_barrelGapHeightLayer0

double m_barrelGapHeightLayer0 {0}
private

Gap height of BKLM layer0.

Definition at line 136 of file BFieldComponentKlm1.h.

◆ m_barrelIronThickness

double m_barrelIronThickness {0}
private

Thickness of Barrel iron plate.

Definition at line 142 of file BFieldComponentKlm1.h.

◆ m_barrelRBreakpoint

double m_barrelRBreakpoint[15] {0}
private

z position of breakpoints between the two linear approximations of Br in the barrel.

Index indicates the current layer

Definition at line 149 of file BFieldComponentKlm1.h.

◆ m_barrelRMin

double m_barrelRMin {0}
private

The minimum boundaries of BKLM region in r.

Definition at line 122 of file BFieldComponentKlm1.h.

◆ m_barrelZBreakpoint

double m_barrelZBreakpoint[15] {0}
private

z position of breakpoints between the two linear approximations of Bz in the barrel.

Index indicates the current layer

Definition at line 146 of file BFieldComponentKlm1.h.

◆ m_barrelZMax

double m_barrelZMax {0}
private

The maximum boundaries of BKLM region in r.

Definition at line 124 of file BFieldComponentKlm1.h.

◆ m_cos3pi8

double m_cos3pi8 {cos(3 * M_PI / 8)}
private

cos(3pi/8)

Definition at line 112 of file BFieldComponentKlm1.h.

◆ m_cospi4

double m_cospi4 {cos(M_PI / 4)}
private

cos(pi/4)

Definition at line 114 of file BFieldComponentKlm1.h.

◆ m_cospi8

double m_cospi8 {cos(M_PI / 8)}
private

cos(pi/8)

Definition at line 110 of file BFieldComponentKlm1.h.

◆ m_dLayer

double m_dLayer {0}
private

depth of BKLM module?

Definition at line 140 of file BFieldComponentKlm1.h.

◆ m_endcapFieldRIntercept

double m_endcapFieldRIntercept[2][15][5] {{{0}}}
private

Intercepts of the linear approximation of Br in the endcap.

First index indicates whether or not where in a gap (0) or in iron (1), second index is the layer and third index is the number of breaks we have in the linear approximation and their positions

Definition at line 205 of file BFieldComponentKlm1.h.

◆ m_endcapFieldRSlope

double m_endcapFieldRSlope[2][15][5] {{{0}}}
private

Slopes of the linear approximation of Br in the endcap.

First index indicates whether or not where in a gap (0) or in iron (1), second index is the layer and third index is the number of breaks we have in the linear approximation and their positions

Definition at line 200 of file BFieldComponentKlm1.h.

◆ m_endcapFieldZIntercept

double m_endcapFieldZIntercept[2][15][5] {{{0}}}
private

Intercepts of the linear approximation of Bz in the endcap.

First index indicates whether or not where in a gap (0) or in iron (1), second index is the layer and third index is the number of breaks we have in the linear approximation and their positions

Definition at line 195 of file BFieldComponentKlm1.h.

◆ m_endcapFieldZSlope

double m_endcapFieldZSlope[2][15][5] {{{0}}}
private

Slopes of the linear approximation of Bz in the endcap.

First index indicates whether or not where in a gap (0) or in iron (1), second index is the layer and third index is the number of breaks we have in the linear approximation and their positions

Definition at line 190 of file BFieldComponentKlm1.h.

◆ m_endcapGapHeight

double m_endcapGapHeight {0}
private

Gap height of BKLM layer1-14.

Definition at line 138 of file BFieldComponentKlm1.h.

◆ m_endcapRBreakpoint

double m_endcapRBreakpoint[2][15][5] {{{0}}}
private

r position of breakpoints between linear functions in the endcap First index indicates whether or not where in a gap (0) or in iron (1), second index is the layer and third index is the number of breaks we have in the linear approximation and their positions

Definition at line 184 of file BFieldComponentKlm1.h.

◆ m_endcapRMin

double m_endcapRMin {0}
private

The minimum boundaries of EKLM region in r.

Definition at line 126 of file BFieldComponentKlm1.h.

◆ m_endcapZBreakpoint

double m_endcapZBreakpoint[2][15][5] {{{0}}}
private

z position of breakpoints between linear functions in the endcap.

First index indicates whether or not where in a gap (0) or in iron (1), second index is the layer and third index is the number of breaks we have in the linear approximation and their positions

Definition at line 179 of file BFieldComponentKlm1.h.

◆ m_endcapZMin

double m_endcapZMin {0}
private

The minimum boundaries of EKLM region in z.

Definition at line 128 of file BFieldComponentKlm1.h.

◆ m_mapFilename

std::string m_mapFilename {""}
private

The filename of the magnetic field map.

Definition at line 117 of file BFieldComponentKlm1.h.

◆ m_mapOffset

double m_mapOffset {0}
private

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

Definition at line 119 of file BFieldComponentKlm1.h.

◆ m_nBarrelLayers

int m_nBarrelLayers {0}
private

The number of layers per 1 sector for BKLM.

Definition at line 131 of file BFieldComponentKlm1.h.

◆ m_nEndcapLayers

int m_nEndcapLayers {0}
private

The number of layers per 1 sector for EKLM.

Definition at line 133 of file BFieldComponentKlm1.h.


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