27 float solenoidCurrent,
69 tree->SetBranchAddress(
"id", &
id);
70 tree->SetBranchAddress(
"zmin", &
zmin);
71 tree->SetBranchAddress(
"zmax", &
zmax);
72 tree->SetBranchAddress(
"rmin", &rmin);
73 tree->SetBranchAddress(
"rmax", &rmax);
74 tree->SetBranchAddress(
"phimin", &phimin);
75 tree->SetBranchAddress(
"phimax", &phimax);
76 tree->SetBranchAddress(
"bscale", &bscale);
77 tree->SetBranchAddress(
"ncond", &ncond);
78 tree->SetBranchAddress(
"nmeshz", &nmeshz);
79 tree->SetBranchAddress(
"nmeshr", &nmeshr);
80 tree->SetBranchAddress(
"nmeshphi", &nmeshphi);
81 tree->SetBranchAddress(
"nfield", &nfield);
90 unsigned maxmeshphi(0);
93 TTree* tmax = (TTree*)
rootfile->Get(
"BFieldMapSize");
94 if (tmax !=
nullptr) {
95 tmax->SetBranchAddress(
"maxcond", &maxcond);
96 tmax->SetBranchAddress(
"maxmeshz", &maxmeshz);
97 tmax->SetBranchAddress(
"maxmeshr", &maxmeshr);
98 tmax->SetBranchAddress(
"maxmeshphi", &maxmeshphi);
99 tmax->SetBranchAddress(
"maxfield", &maxfield);
102 for (
int i = 0;
i <
tree->GetEntries();
i++) {
104 maxcond =
std::max(maxcond, (
unsigned)ncond);
105 maxmeshz =
std::max(maxmeshz, (
unsigned)nmeshz);
106 maxmeshr =
std::max(maxmeshr, (
unsigned)nmeshr);
107 maxmeshphi =
std::max(maxmeshphi, (
unsigned)nmeshphi);
108 maxfield =
std::max(maxfield, (
unsigned)nfield);
111 finite =
new bool[maxcond];
112 p1x =
new double[maxcond];
113 p1y =
new double[maxcond];
114 p1z =
new double[maxcond];
115 p2x =
new double[maxcond];
116 p2y =
new double[maxcond];
117 p2z =
new double[maxcond];
118 curr =
new double[maxcond];
119 meshz =
new double[maxmeshz];
120 meshr =
new double[maxmeshr];
121 meshphi =
new double[maxmeshphi];
122 fieldz =
new short[maxfield];
123 fieldr =
new short[maxfield];
124 fieldphi =
new short[maxfield];
126 tree->SetBranchAddress(
"finite", finite);
127 tree->SetBranchAddress(
"p1x", p1x);
128 tree->SetBranchAddress(
"p1y", p1y);
129 tree->SetBranchAddress(
"p1z", p1z);
130 tree->SetBranchAddress(
"p2x", p2x);
131 tree->SetBranchAddress(
"p2y", p2y);
132 tree->SetBranchAddress(
"p2z", p2z);
133 tree->SetBranchAddress(
"curr", curr);
134 tree->SetBranchAddress(
"meshz", meshz);
135 tree->SetBranchAddress(
"meshr", meshr);
136 tree->SetBranchAddress(
"meshphi", meshphi);
137 tree->SetBranchAddress(
"fieldz", fieldz);
138 tree->SetBranchAddress(
"fieldr", fieldr);
139 tree->SetBranchAddress(
"fieldphi", fieldphi);
144 for (
int i = 0;
i <
tree->GetEntries();
i++) {
148 m_zone.back().reserve(nmeshz, nmeshr, nmeshphi);
149 for (
int j = 0; j < ncond; j++) {
160 m_zone.back().appendCond(cond);
162 for (
int j = 0; j < nmeshz; j++) {
163 m_zone.back().appendMesh(0, meshz[j]);
165 for (
int j = 0; j < nmeshr; j++) {
166 m_zone.back().appendMesh(1, meshr[j]);
168 for (
int j = 0; j < nmeshphi; j++) {
169 m_zone.back().appendMesh(2, meshphi[j]);
171 for (
int j = 0; j < nfield; j++) {
212 for (
int j = m_zone.size() - 1; j >= 0; --j) {
230 for (
int j = 0; j < 3; j++) {
231 for (
unsigned i = 0;
i < m_zone.size();
i++) {
233 e[0] = m_zone[
i].min(j);
234 e[1] = m_zone[
i].max(j);
235 for (
int k = 0;
k < 2;
k++) {
237 if (j == 2 &&
e[
k] >
M_PI) {
240 m_edge[j].push_back(
e[
k]);
244 m_edge[2].push_back(-
M_PI);
245 m_edge[2].push_back(
M_PI);
247 sort(m_edge[j].
begin(), m_edge[j].
end());
251 for (
unsigned k = 1;
k < m_edge[j].size();
k++) {
252 if (fabs(m_edge[j][
i] - m_edge[j][
k]) < 1.0
e-6) {
255 m_edge[j][++
i] = m_edge[j][
k];
257 m_edge[j].resize(
i + 1);
262 for (
unsigned i = 0;
i < m_zone.size();
i++) {
263 for (
unsigned k = 0;
k < m_edge[j].size();
k++) {
264 if (fabs(m_zone[
i].
min(j) - m_edge[j][
k]) < 1.0
e-6) {
265 m_zone[
i].adjustMin(j, m_edge[j][
k]);
267 if (fabs(m_zone[
i].
max(j) - m_edge[j][
k]) < 1.0
e-6) {
268 m_zone[
i].adjustMax(j, m_edge[j][
k]);
274 for (
int j = 0; j < 3; j++) {
276 double width = m_edge[j].back() - m_edge[j].front();
278 for (
unsigned i = 0;
i < m_edge[j].size() - 1;
i++) {
288 for (
int i = 0;
i <
n;
i++) {
289 if (
q *
i + m_edge[j].front() > m_edge[j][
m + 1]) {
292 m_edgeLUT[j].push_back(
m);
296 m_zmin = m_edge[0].front();
297 m_zmax = m_edge[0].back();
298 m_rmax = m_edge[1].back();
300 m_nz = m_edge[0].size() - 1;
301 m_nr = m_edge[1].size() - 1;
302 m_nphi = m_edge[2].size() - 1;
303 m_zoneLUT.reserve(m_nz * m_nr * m_nphi);
304 for (
int iz = 0; iz < m_nz; iz++) {
305 double z = 0.5 * (m_edge[0][iz] + m_edge[0][iz + 1]);
306 for (
int ir = 0;
ir < m_nr;
ir++) {
307 double r = 0.5 * (m_edge[1][
ir] + m_edge[1][
ir + 1]);
308 for (
int iphi = 0; iphi < m_nphi; iphi++) {
309 double phi = 0.5 * (m_edge[2][iphi] + m_edge[2][iphi + 1]);
311 m_zoneLUT.push_back(
zone);
316 for (
unsigned i = 0;
i < m_zone.size();
i++) {
317 m_zone[
i].buildLUT();
333 const BFieldZone* solezone = findBFieldZone(0.0, 200.0, 0.0);
341 unsigned nmeshz = solezone->
nmesh(0);
342 unsigned nmeshr = solezone->
nmesh(1);
343 if (solezone->
rmin() > 0.0) {
346 m_meshZR->reserve(nmeshz, nmeshr);
350 if (solezone->
rmin() > 0.0) {
351 m_meshZR->appendMesh(1, 0.0);
354 for (
int i = 0;
i < 2;
i++) {
355 for (
unsigned j = 0; j < solezone->
nmesh(
i); j++) {
356 m_meshZR->appendMesh(
i, solezone->
mesh(
i, j));
361 for (
unsigned iz = 0; iz < m_meshZR->nmesh(0); iz++) {
362 double z = m_meshZR->mesh(0, iz);
363 for (
unsigned ir = 0;
ir < m_meshZR->nmesh(1);
ir++) {
364 double r = m_meshZR->mesh(1,
ir);
368 for (
int iphi = 0; iphi < nphi; iphi++) {
375 solezone->
getB(
xyz, B,
nullptr);
376 Br += B[0] *
cos(phi) + B[1] *
sin(phi);
386 m_meshZR->buildLUT();
398 for (
unsigned i = 0;
i < m_zone.size();
i++) {
399 size += m_zone[
i].memSize();
401 for (
int i = 0;
i < 3;
i++) {
403 size +=
sizeof(
int) * m_edgeLUT[
i].capacity();
407 size += m_meshZR->memSize();