9 #include <geometry/bfieldmap/BFieldComponentKlm1.h>
11 #include <framework/utilities/FileSystem.h>
12 #include <framework/logging/Logger.h>
14 #include <boost/iostreams/filtering_stream.hpp>
15 #include <boost/iostreams/device/file.hpp>
21 namespace io = boost::iostreams;
23 void BFieldComponentKlm1::initialize()
25 if (m_mapFilename.empty()) {
26 B2ERROR(
"The filename for the magnetic field Component is empty !");
30 string fullPath = FileSystem::findFile(
"/data/" + m_mapFilename);
32 if (!FileSystem::fileExists(fullPath)) {
33 B2ERROR(
"The magnetic field map file '" << m_mapFilename <<
"' could not be found !");
38 io::filtering_istream fieldMapFile;
39 fieldMapFile.push(io::file_source(fullPath));
42 B2DEBUG(10,
"Loading the magnetic field from file '" << m_mapFilename <<
"' in to the memory...");
47 fieldMapFile.getline(dummy,
sizeof(dummy));
48 for (
int layer = 0; layer < m_nBarrelLayers; ++layer) {
50 fieldMapFile >> l >> m_barrelZBreakpoint[layer] >> m_barrelRBreakpoint[layer]
51 >> m_barrelFieldZSlope1[layer]
52 >> m_barrelFieldZIntercept1[layer]
53 >> m_barrelFieldZSlope2[layer]
54 >> m_barrelFieldZIntercept2[layer]
55 >> m_barrelFieldRSlope1[layer]
56 >> m_barrelFieldRIntercept1[layer]
57 >> m_barrelFieldRSlope2[layer]
58 >> m_barrelFieldRIntercept2[layer];
61 B2ERROR(
"Barrel Parameter file is something wrong ! " << layer <<
" " << l);
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++) {
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);
83 B2DEBUG(10,
"... loaded ");
90 double r = point.
Perp();
93 double z = point.
Z() - m_mapOffset;
94 double absZ = std::abs(z);
99 if (absZ < m_barrelZMax) {
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)
107 : std::abs(x)) - m_barrelRMin - m_barrelGapHeightLayer0;
110 int layer =
static_cast<int>(floor(d / m_dLayer));
113 if (layer < 0 || layer > m_nBarrelLayers)
return bField;
114 if (layer == m_nBarrelLayers) {
115 layer = m_nBarrelLayers - 1;
116 d = layer * m_dLayer;
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));
129 }
else if (absZ > m_endcapZMin) {
131 if (r <= m_endcapRMin)
return bField;
136 double dz = absZ - (m_endcapZMin - m_endcapGapHeight);
137 int layer =
static_cast<int>(floor(dz / m_dLayer));
139 if (layer < 0 || layer >= m_nEndcapLayers)
return bField;
142 if ((dz - m_dLayer * layer) > m_endcapGapHeight) GapIron = 1;
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);
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);
164 void BFieldComponentKlm1::terminate()
DataType Z() const
access variable Z (= .at(2) without boundary check)
void SetX(DataType x)
set X/1st-coordinate
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
void SetZ(DataType z)
set Z/3rd-coordinate
void SetY(DataType y)
set Y/2nd-coordinate
DataType Perp() const
The transverse component (R in cylindrical coordinate system).
void SetXYZ(DataType x, DataType y, DataType z)
set all coordinates using data type
Abstract base class for different kinds of events.