FairShip
Loading...
Searching...
No Matches
ShipBFieldMap.cxx
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2// SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP
3// Collaboration
4
11
12#include "ShipBFieldMap.h"
13
14#include <array>
15#include <cmath>
16#include <fstream>
17#include <iostream>
18
19#include "FairLogger.h"
20#include "TFile.h"
21#include "TTree.h"
22
23ShipBFieldMap::ShipBFieldMap(const std::string& label,
24 const std::string& mapFileName, Float_t xOffset,
25 Float_t yOffset, Float_t zOffset, Float_t phi,
26 Float_t theta, Float_t psi, Float_t scale,
27 Bool_t isSymmetric)
28 : TVirtualMagField(label.c_str()),
29 fieldMap_(new floatArray()),
30 mapFileName_(mapFileName),
31 initialised_(kFALSE),
32 isCopy_(kFALSE),
33 Nx_(0),
34 Ny_(0),
35 Nz_(0),
36 N_(0),
37 xMin_(0.0),
38 xMax_(0.0),
39 dx_(0.0),
40 xRange_(0.0),
41 yMin_(0.0),
42 yMax_(0.0),
43 dy_(0.0),
44 yRange_(0.0),
45 zMin_(0.0),
46 zMax_(0.0),
47 dz_(0.0),
48 zRange_(0.0),
49 xOffset_(xOffset),
50 yOffset_(yOffset),
51 zOffset_(zOffset),
52 phi_(phi),
53 theta_(theta),
54 psi_(psi),
55 scale_(scale),
56 isSymmetric_(isSymmetric),
57 theTrans_(nullptr),
58 Tesla_(10.0) {
59 this->initialise();
60}
61
63 // Delete the internal vector storing the field map values
64 if (fieldMap_ && isCopy_ == kFALSE) {
65 delete fieldMap_;
66 fieldMap_ = nullptr;
67 }
68
69 if (theTrans_) {
70 delete theTrans_;
71 theTrans_ = nullptr;
72 }
73}
74
75ShipBFieldMap::ShipBFieldMap(const std::string& newName,
76 const ShipBFieldMap& rhs, Float_t newXOffset,
77 Float_t newYOffset, Float_t newZOffset,
78 Float_t newPhi, Float_t newTheta, Float_t newPsi,
79 Float_t newScale)
80 : TVirtualMagField(newName.c_str()),
83 initialised_(kFALSE),
84 isCopy_(kTRUE),
85 Nx_(rhs.Nx_),
86 Ny_(rhs.Ny_),
87 Nz_(rhs.Nz_),
88 N_(rhs.N_),
89 xMin_(rhs.xMin_),
90 xMax_(rhs.xMax_),
91 dx_(rhs.dx_),
92 xRange_(rhs.xRange_),
93 yMin_(rhs.yMin_),
94 yMax_(rhs.yMax_),
95 dy_(rhs.dy_),
96 yRange_(rhs.yRange_),
97 zMin_(rhs.zMin_),
98 zMax_(rhs.zMax_),
99 dz_(rhs.dz_),
100 zRange_(rhs.zRange_),
101 xOffset_(newXOffset),
102 yOffset_(newYOffset),
103 zOffset_(newZOffset),
104 phi_(newPhi),
105 theta_(newTheta),
106 psi_(newPsi),
107 scale_(newScale),
109 theTrans_(nullptr),
110 Tesla_(10.0) {
111 // Copy constructor with new label and different global offset, which uses
112 // the same field map data (pointer) and distance units as the rhs object
113 this->initialise();
114}
115
116void ShipBFieldMap::Field(const Double_t* position, Double_t* B) {
117 // Set the B field components given the global position coordinates
118
119 // Convert the global position into a local one for the volume field.
120 // Initialise the local co-ords, which will get overwritten if the
121 // coordinate transformation exists. For a global field, any local
122 // volume transformation is ignored
123 Double_t localCoords[3] = {position[0], position[1], position[2]};
124
125 if (theTrans_) {
126 theTrans_->MasterToLocal(position, localCoords);
127 }
128
129 // The local position coordinates
130 Float_t x = localCoords[0];
131 Float_t y = localCoords[1];
132 Float_t z = localCoords[2];
133
134 // Now check to see if we have x-y quadrant symmetry (z has no symmetry):
135 // Bx is antisymmetric in both x and y, By is symmetric in both, while Bz is
136 // symmetric in x but antisymmetric in y (dipole physics). So Bx can change
137 // sign for x < 0 or y < 0, and Bz can change sign for y < 0:
138 // 1. x > 0, y > 0: Bx = +Bx, Bz = +Bz
139 // 2. x > 0, y < 0: Bx = -Bx, Bz = -Bz
140 // 3. x < 0, y > 0: Bx = -Bx, Bz = +Bz
141 // 4. x < 0, y < 0: Bx = +Bx, Bz = -Bz
142
143 Float_t BxSign(1.0);
144 Float_t BzSign = 1;
145
146 if (isSymmetric_) {
147 // The map stores only the x > 0, y > 0 quadrant; fold negative
148 // coordinates in and track the induced signs of Bx and Bz.
149 if (x < 0.0) {
150 x = -x;
151 BxSign *= -1.0;
152 }
153
154 if (y < 0.0) {
155 y = -y;
156 BxSign *= -1.0;
157 BzSign = -1.0;
158 }
159 }
160
161 // Initialise the B field components to zero
162 B[0] = 0.0;
163 B[1] = 0.0;
164 B[2] = 0.0;
165
166 // First check to see if we are inside the field map range
167 Bool_t inside = this->insideRange(x, y, z);
168 if (inside == kFALSE) {
169 return;
170 }
171
172 // Find the neighbouring bins for the given point
173 binPair xBinInfo = this->getBinInfo(x, ShipBFieldMap::xAxis);
174 binPair yBinInfo = this->getBinInfo(y, ShipBFieldMap::yAxis);
175 binPair zBinInfo = this->getBinInfo(z, ShipBFieldMap::zAxis);
176
177 Int_t iX = xBinInfo.first;
178 Int_t iY = yBinInfo.first;
179 Int_t iZ = zBinInfo.first;
180
181 // Check that the bins are valid
182 if (iX == -1 || iY == -1 || iZ == -1) {
183 return;
184 }
185
186 // Get the various neighbouring bin entries
187 Int_t iX1(iX + 1);
188 Int_t iY1(iY + 1);
189 Int_t iZ1(iZ + 1);
190
191 const Int_t binA = this->getMapBin(iX, iY, iZ);
192 const Int_t binB = this->getMapBin(iX1, iY, iZ);
193 const Int_t binC = this->getMapBin(iX, iY1, iZ);
194 const Int_t binD = this->getMapBin(iX1, iY1, iZ);
195 const Int_t binE = this->getMapBin(iX, iY, iZ1);
196 const Int_t binF = this->getMapBin(iX1, iY, iZ1);
197 const Int_t binG = this->getMapBin(iX, iY1, iZ1);
198 const Int_t binH = this->getMapBin(iX1, iY1, iZ1);
199
200 // Retrieve the fractional bin distances and their complements
201 const Float_t xFrac = xBinInfo.second;
202 const Float_t yFrac = yBinInfo.second;
203 const Float_t zFrac = zBinInfo.second;
204 const Float_t xFrac1 = 1.0 - xFrac;
205 const Float_t yFrac1 = 1.0 - yFrac;
206 const Float_t zFrac1 = 1.0 - zFrac;
207
208 if (!fieldMap_) {
209 return;
210 }
211
212 // Fetch each of the eight corner triples once and interpolate all three
213 // field components in a single pass (trilinear interpolation), then scale
214 // with the appropriate multiplication factor (default = 1.0).
215 const floatArray& fm = *fieldMap_;
216 const std::array<Float_t, 3>& cA = fm[binA];
217 const std::array<Float_t, 3>& cB = fm[binB];
218 const std::array<Float_t, 3>& cC = fm[binC];
219 const std::array<Float_t, 3>& cD = fm[binD];
220 const std::array<Float_t, 3>& cE = fm[binE];
221 const std::array<Float_t, 3>& cF = fm[binF];
222 const std::array<Float_t, 3>& cG = fm[binG];
223 const std::array<Float_t, 3>& cH = fm[binH];
224
225 Float_t Bc[3];
226 for (Int_t i = 0; i < 3; ++i) {
227 Bc[i] = triLinearInterp(cA[i], cB[i], cC[i], cD[i], cE[i], cF[i], cG[i],
228 cH[i], xFrac, xFrac1, yFrac, yFrac1, zFrac, zFrac1);
229 }
230
231 B[0] = Bc[0] * scale_ * BxSign;
232 B[1] = Bc[1] * scale_;
233 B[2] = Bc[2] * scale_ * BzSign;
234}
235
237 if (initialised_ == kFALSE) {
238 if (isCopy_ == kFALSE) {
239 this->readMapFile();
240 }
241
242 // Set the global coordinate translation and rotation info
243 if (fabs(phi_) > 1e-6 || fabs(theta_) > 1e-6 || fabs(psi_) > 1e-6) {
244 // We have non-zero rotation angles. Create a combined translation and
245 // rotation
246 TGeoTranslation tr("offsets", xOffset_, yOffset_, zOffset_);
247 TGeoRotation rot("angles", phi_, theta_, psi_);
248 theTrans_ = new TGeoCombiTrans(tr, rot);
249
250 } else {
251 // We only need a translation
252 theTrans_ = new TGeoTranslation("offsets", xOffset_, yOffset_, zOffset_);
253 }
254
255 initialised_ = kTRUE;
256 }
257}
258
260 LOG(info) << "ShipBFieldMap::readMapFile() creating field " << this->GetName()
261 << " using file " << mapFileName_;
262
263 // Check to see if we have a ROOT file
264 if (mapFileName_.find(".root") != std::string::npos) {
265 this->readRootFile();
266
267 } else {
268 this->readTextFile();
269 }
270}
271
273 TFile* theFile = TFile::Open(mapFileName_.c_str());
274
275 if (!theFile) {
276 LOG(fatal) << "ShipBFieldMap: could not find the file " << mapFileName_;
277 }
278
279 // Coordinate ranges
280 TTree* rTree = dynamic_cast<TTree*>(theFile->Get("Range"));
281 if (!rTree) {
282 LOG(fatal) << "ShipBFieldMap: could not find Range tree in "
283 << mapFileName_;
284 }
285
286 rTree->SetBranchAddress("xMin", &xMin_);
287 rTree->SetBranchAddress("xMax", &xMax_);
288 rTree->SetBranchAddress("dx", &dx_);
289 rTree->SetBranchAddress("yMin", &yMin_);
290 rTree->SetBranchAddress("yMax", &yMax_);
291 rTree->SetBranchAddress("dy", &dy_);
292 rTree->SetBranchAddress("zMin", &zMin_);
293 rTree->SetBranchAddress("zMax", &zMax_);
294 rTree->SetBranchAddress("dz", &dz_);
295
296 // Fill the ranges
297 rTree->GetEntry(0);
298
299 this->setLimits();
300
301 // Make sure we don't have a copy
302 if (isCopy_ == kFALSE) {
303 // The data is expected to contain Bx,By,Bz data values
304 // in ascending z,y,x coordinate order
305
306 TTree* dTree = dynamic_cast<TTree*>(theFile->Get("Data"));
307 if (!dTree) {
308 LOG(fatal) << "ShipBFieldMap: could not find Data tree in "
309 << mapFileName_;
310 }
311
312 const Int_t nEntries = dTree->GetEntries();
313 if (nEntries != N_) {
314 LOG(fatal) << "Expected " << N_ << " field map entries but found "
315 << nEntries;
316 }
317
318 this->checkRootFileOrdering(dTree);
319
320 Float_t Bx, By, Bz;
321 // Only enable the field components
322 dTree->SetBranchStatus("*", 0);
323 dTree->SetBranchStatus("Bx", 1);
324 dTree->SetBranchStatus("By", 1);
325 dTree->SetBranchStatus("Bz", 1);
326
327 dTree->SetBranchAddress("Bx", &Bx);
328 dTree->SetBranchAddress("By", &By);
329 dTree->SetBranchAddress("Bz", &Bz);
330
331 fieldMap_->reserve(nEntries);
332
333 for (Int_t i = 0; i < nEntries; i++) {
334 dTree->GetEntry(i);
335
336 // B field values are in Tesla. This means these values are multiplied
337 // by a factor of ten since both FairRoot and the VMC interface use kGauss
338 Bx *= Tesla_;
339 By *= Tesla_;
340 Bz *= Tesla_;
341
342 // Store the B field 3-vector
343 fieldMap_->push_back({Bx, By, Bz});
344 }
345 }
346
347 theFile->Close();
348}
349
351 // Entry (iX*Ny_ + iY)*Nz_ + iZ has to hold the field at grid node
352 // (iX, iY, iZ). Maps converted with the coordinates stored also carry the
353 // node position, so probe a few entries and check where they land. Nothing
354 // else can catch a permuted map: when Nx == Ny and the x and y ranges agree,
355 // the entry count above still matches and the field is silently mirrored
356 // about the x = y plane.
357 if (!dTree->GetBranch("x") || !dTree->GetBranch("y") ||
358 !dTree->GetBranch("z")) {
359 LOG(warn) << "ShipBFieldMap: " << mapFileName_
360 << " stores no x,y,z branches, so the assumed ascending z,y,x "
361 "ordering cannot be verified. Convert the map with the node "
362 "coordinates stored.";
363 return;
364 }
365
366 Float_t x(0.0), y(0.0), z(0.0);
367 dTree->SetBranchStatus("*", 0);
368 dTree->SetBranchStatus("x", 1);
369 dTree->SetBranchStatus("y", 1);
370 dTree->SetBranchStatus("z", 1);
371 dTree->SetBranchAddress("x", &x);
372 dTree->SetBranchAddress("y", &y);
373 dTree->SetBranchAddress("z", &z);
374
375 // The first node, its z, y and x neighbours, and the last node. Between them
376 // these five tell apart every permutation of the three axes.
377 const std::array<Int_t, 5> probes{0, 1, Nz_, Ny_ * Nz_, N_ - 1};
378
379 for (const Int_t entry : probes) {
380 const Int_t iX = entry / (Ny_ * Nz_);
381 const Int_t iY = (entry / Nz_) % Ny_;
382 const Int_t iZ = entry % Nz_;
383
384 dTree->GetEntry(entry);
385
386 // A NaN or infinite coordinate cannot be rounded to a node, so it says
387 // nothing about the ordering and would only produce a misleading report.
388 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z)) {
389 LOG(fatal) << "ShipBFieldMap: field map " << mapFileName_ << " entry "
390 << entry << " holds a non-finite coordinate (" << x << ", "
391 << y << ", " << z << ") cm.";
392 break;
393 }
394
395 // Round to the nearest node rather than compare coordinates directly.
396 // Some maps sit slightly off the nominal grid, by up to an eighth of a
397 // bin, while a permuted ordering is off by tens of bins.
398 const Int_t nodeX = static_cast<Int_t>(std::lround((x - xMin_) / dx_));
399 const Int_t nodeY = static_cast<Int_t>(std::lround((y - yMin_) / dy_));
400 const Int_t nodeZ = static_cast<Int_t>(std::lround((z - zMin_) / dz_));
401
402 if (nodeX != iX || nodeY != iY || nodeZ != iZ) {
403 LOG(fatal) << "ShipBFieldMap: field map " << mapFileName_
404 << " is not stored in ascending z,y,x coordinate order. "
405 << "Entry " << entry << " should hold node (" << iX << ", "
406 << iY << ", " << iZ << ") at (" << xMin_ + iX * dx_ << ", "
407 << yMin_ + iY * dy_ << ", " << zMin_ + iZ * dz_
408 << ") cm but holds node (" << nodeX << ", " << nodeY << ", "
409 << nodeZ << ") at (" << x << ", " << y << ", " << z
410 << ") cm. Repack it with field/canonicaliseFieldMap.py.";
411 // Reporting every probe adds nothing once the first one has disagreed.
412 break;
413 }
414 }
415
416 // The addresses above are local, so the tree must not keep pointing at them.
417 dTree->ResetBranchAddresses();
418 dTree->SetBranchStatus("*", 1);
419}
420
422 std::ifstream getData(mapFileName_.c_str());
423
424 if (!getData.is_open()) {
425 LOG(fatal) << "Error: Cannot open magnetic field map file: "
426 << mapFileName_;
427 }
428
429 std::string tmpString("");
430
431 getData >> tmpString >> xMin_ >> xMax_ >> dx_ >> yMin_ >> yMax_ >> dy_ >>
432 zMin_ >> zMax_ >> dz_;
433
434 this->setLimits();
435
436 // Check to see if this object is a "copy"
437 if (isCopy_ == kFALSE) {
438 // Read the field map and store the magnetic field components
439
440 // Second line can be ignored since they are
441 // just labels for the data columns for readability
442 getData >> tmpString >> tmpString >> tmpString;
443
444 // The remaining lines contain Bx,By,Bz data values
445 // in ascending z,y,x co-ord order. Unlike the ROOT format the text one
446 // carries no coordinates, so that ordering cannot be verified here.
447 fieldMap_->reserve(N_);
448
449 Float_t Bx(0.0), By(0.0), Bz(0.0);
450
451 for (Int_t i = 0; i < N_; i++) {
452 getData >> Bx >> By >> Bz;
453
454 // B field values are in Tesla. This means these values are multiplied
455 // by a factor of ten since both FairRoot and the VMC interface use kGauss
456 Bx *= Tesla_;
457 By *= Tesla_;
458 Bz *= Tesla_;
459
460 // Store the B field 3-vector
461 fieldMap_->push_back({Bx, By, Bz});
462 }
463 }
464
465 getData.close();
466}
467
468Bool_t ShipBFieldMap::insideRange(Float_t x, Float_t y, Float_t z) {
469 Bool_t inside(kFALSE);
470
471 if (x >= xMin_ && x <= xMax_ && y >= yMin_ && y <= yMax_ && z >= zMin_ &&
472 z <= zMax_) {
473 inside = kTRUE;
474 }
475
476 return inside;
477}
478
480 // Since the default SHIP distance unit is cm, we do not need to convert
481 // these map limits, i.e. cm = 1 already
482
483 xRange_ = xMax_ - xMin_;
484 yRange_ = yMax_ - yMin_;
485 zRange_ = zMax_ - zMin_;
486
487 // Find the number of bins using the limits and bin sizes. The number of bins
488 // includes both the minimum and maximum values. To ensure correct rounding
489 // up to the nearest integer we need to add 1.5 not 1.0.
490 if (dx_ > 0.0) {
491 Nx_ = static_cast<Int_t>(((xMax_ - xMin_) / dx_) + 1.5);
492 }
493 if (dy_ > 0.0) {
494 Ny_ = static_cast<Int_t>(((yMax_ - yMin_) / dy_) + 1.5);
495 }
496 if (dz_ > 0.0) {
497 Nz_ = static_cast<Int_t>(((zMax_ - zMin_) / dz_) + 1.5);
498 }
499
500 // Trilinear interpolation needs at least two bins per axis; a smaller map
501 // would silently be treated as out of range for every point.
502 if (Nx_ < 2 || Ny_ < 2 || Nz_ < 2) {
503 LOG(fatal) << "ShipBFieldMap: field map needs at least 2 bins per axis; "
504 << "got Nx = " << Nx_ << ", Ny = " << Ny_ << ", Nz = " << Nz_;
505 }
506
507 // The rounding above hides limits that are not a whole number of bins apart.
508 // Left alone, every node beyond the first would sit away from where the
509 // interpolation looks for it.
510 const Float_t tolerance(1e-2);
511 if (fabs((Nx_ - 1) * dx_ - xRange_) > tolerance * dx_ ||
512 fabs((Ny_ - 1) * dy_ - yRange_) > tolerance * dy_ ||
513 fabs((Nz_ - 1) * dz_ - zRange_) > tolerance * dz_) {
514 LOG(fatal) << "ShipBFieldMap: field map extents are not whole multiples of "
515 << "the bin widths: " << xRange_ << " / " << dx_ << ", "
516 << yRange_ << " / " << dy_ << ", " << zRange_ << " / " << dz_;
517 }
518
519 N_ = Nx_ * Ny_ * Nz_;
520
521 LOG(info) << "x limits: " << xMin_ << ", " << xMax_ << ", dx = " << dx_;
522 LOG(info) << "y limits: " << yMin_ << ", " << yMax_ << ", dy = " << dy_;
523 LOG(info) << "z limits: " << zMin_ << ", " << zMax_ << ", dz = " << dz_;
524
525 LOG(info) << "Offsets: x = " << xOffset_ << ", y = " << yOffset_
526 << ", z = " << zOffset_;
527 LOG(info) << "Angles : phi = " << phi_ << ", theta = " << theta_
528 << ", psi = " << psi_;
529
530 LOG(info) << "Total number of bins = " << N_ << "; Nx = " << Nx_
531 << ", Ny = " << Ny_ << ", Nz = " << Nz_;
532}
533
535 Float_t u, ShipBFieldMap::CoordAxis theAxis) {
536 Float_t du(0.0), uMin(0.0);
537 Int_t Nu(0);
538
539 if (theAxis == ShipBFieldMap::xAxis) {
540 du = dx_;
541 uMin = xMin_;
542 Nu = Nx_;
543 } else if (theAxis == ShipBFieldMap::yAxis) {
544 du = dy_;
545 uMin = yMin_;
546 Nu = Ny_;
547 } else if (theAxis == ShipBFieldMap::zAxis) {
548 du = dz_;
549 uMin = zMin_;
550 Nu = Nz_;
551 }
552
553 Int_t iBin(-1);
554 Float_t fracL(0.0);
555
556 if (du > 1e-10) {
557 // Get the number of fractional bin widths the point is from the first
558 // volume bin
559 Float_t dist = (u - uMin) / du;
560 // Get the integer equivalent of this distance, which is the bin number
561 iBin = static_cast<Int_t>(dist);
562 // Get the actual fractional distance of the point from the leftmost bin
563 // edge
564 fracL = (dist - iBin * 1.0);
565 }
566
567 // Check that the bin number is valid
568 if (iBin < 0 || iBin >= Nu) {
569 iBin = -1;
570 fracL = 0.0;
571 } else if (iBin >= Nu - 1) {
572 // The point lies in the last bin along this axis. The trilinear
573 // interpolation uses the iBin+1 neighbour, which would fall outside the
574 // axis here, so clamp to the last valid cell (Nu-2) and use a fractional
575 // weight of 1 so the upper-edge (last valid) slice is used without reading
576 // the next, non-existent slice.
577 iBin = Nu - 2;
578 fracL = 1.0;
579 }
580
581 // Return the bin number and fractional distance of the point from the
582 // leftmost bin edge
583 binPair binInfo(iBin, fracL);
584
585 return binInfo;
586}
587
588Int_t ShipBFieldMap::getMapBin(Int_t iX, Int_t iY, Int_t iZ) {
589 // Get the index of the map entry corresponding to the x,y,z bins.
590 // Remember that the map is ordered in ascending z, y, then x
591
592 Int_t index = (iX * Ny_ + iY) * Nz_ + iZ;
593 if (index < 0) {
594 index = 0;
595 } else if (index >= N_) {
596 index = N_ - 1;
597 }
598
599 return index;
600}
601
602Float_t ShipBFieldMap::triLinearInterp(Float_t A, Float_t B, Float_t C,
603 Float_t D, Float_t E, Float_t F,
604 Float_t G, Float_t H, Float_t xFrac,
605 Float_t xFrac1, Float_t yFrac,
606 Float_t yFrac1, Float_t zFrac,
607 Float_t zFrac1) {
608 // Trilinear interpolation of a single component from its eight corner
609 // values A..H.
610 // Linear interpolation along x
611 const Float_t F00 = A * xFrac1 + B * xFrac;
612 const Float_t F10 = C * xFrac1 + D * xFrac;
613 const Float_t F01 = E * xFrac1 + F * xFrac;
614 const Float_t F11 = G * xFrac1 + H * xFrac;
615
616 // Linear interpolation along y
617 const Float_t F0 = F00 * yFrac1 + F10 * yFrac;
618 const Float_t F1 = F01 * yFrac1 + F11 * yFrac;
619
620 // Linear interpolation along z
621 return F0 * zFrac1 + F1 * zFrac;
622}
Float_t xMax_
The maximum value of x for the map.
Float_t dy_
The bin width along y.
static Float_t triLinearInterp(Float_t A, Float_t B, Float_t C, Float_t D, Float_t E, Float_t F, Float_t G, Float_t H, Float_t xFrac, Float_t xFrac1, Float_t yFrac, Float_t yFrac1, Float_t zFrac, Float_t zFrac1)
Float_t psi_
The third Euler rotation angle about the new z axis.
Float_t dz_
The bin width along z.
Float_t zRange_
The coordinate range along z.
std::pair< Int_t, Float_t > binPair
Typedef for an int-double pair.
ShipBFieldMap(const std::string &label, const std::string &mapFileName, Float_t xOffset=0.0, Float_t yOffset=0.0, Float_t zOffset=0.0, Float_t phi=0.0, Float_t theta=0.0, Float_t psi=0.0, Float_t scale=1.0, Bool_t isSymmetric=kFALSE)
Constructor.
Int_t Nz_
The number of bins along z.
Float_t Tesla_
Double converting Tesla to kiloGauss (for VMC/FairRoot B field units).
Int_t N_
The total number of bins.
floatArray * fieldMap_
Float_t yMin_
The minimum value of y for the map.
Float_t zOffset_
The z value of the positional offset for the map.
std::string mapFileName_
The name of the map file.
Bool_t initialised_
Initialisation boolean.
Int_t Ny_
The number of bins along y.
std::string GetMapFileName() const
Get the name of the map file.
Float_t theta_
The second Euler rotation angle about the new x axis.
Float_t xMin_
The minimum value of x for the map.
void Field(const Double_t *position, Double_t *B) override
Implementation of evaluating the B field.
void initialise()
Initialisation.
CoordAxis
Enumeration to specify the coordinate type.
Int_t Nx_
The number of bins along x.
void checkRootFileOrdering(TTree *dTree)
Check that the ROOT map really uses the assumed data ordering.
Float_t xRange_
The coordinate range along x.
Float_t yOffset_
The y value of the positional offset for the map.
void readTextFile()
Process the text file containing the field map data.
Float_t scale_
The B field magnitude scaling factor.
TGeoMatrix * theTrans_
The combined translation and rotation transformation.
binPair getBinInfo(Float_t x, CoordAxis theAxis)
Get the bin number and fractional distance from the leftmost bin edge.
Bool_t insideRange(Float_t x, Float_t y, Float_t z)
Check to see if a point is within the map validity range.
std::vector< std::array< Float_t, 3 > > floatArray
void readRootFile()
Process the ROOT file containing the field map data.
~ShipBFieldMap() override
Destructor.
void readMapFile()
Read the field map data and store the information internally.
Int_t getMapBin(Int_t iX, Int_t iY, Int_t iZ)
Find the vector entry of the field map data given the bins iX, iY and iZ.
Float_t yMax_
The maximum value of y for the map.
Float_t yRange_
The coordinate range along y.
Float_t zMax_
The maximum value of z for the map.
Float_t phi_
The first Euler rotation angle about the z axis.
Float_t zMin_
The minimum value of z for the map.
Float_t dx_
The bin width along x.
Bool_t isSymmetric_
The boolean specifying if we have quadrant symmetry.
Float_t xOffset_
The x value of the positional offset for the map.