16 const std::string& mapFileName,
25 TVirtualMagField(label.c_str()),
27 mapFileName_(mapFileName),
30 Nx_(0), Ny_(0), Nz_(0), N_(0),
31 xMin_(0.0), xMax_(0.0),
32 dx_(0.0), xRange_(0.0),
33 yMin_(0.0), yMax_(0.0),
34 dy_(0.0), yRange_(0.0),
35 zMin_(0.0), zMax_(0.0),
36 dz_(0.0), zRange_(0.0),
44 isSymmetric_(isSymmetric),
64 Float_t newXOffset, Float_t newYOffset, Float_t newZOffset,
65 Float_t newPhi, Float_t newTheta, Float_t newPsi, Float_t newScale) :
66 TVirtualMagField(newName.c_str()),
67 fieldMap_(rhs.fieldMap_),
68 mapFileName_(rhs.GetMapFileName()),
94 isSymmetric_(rhs.isSymmetric_),
112 Double_t localCoords[3] = {position[0], position[1], position[2]};
117 Float_t x = localCoords[0];
118 Float_t y = localCoords[1];
119 Float_t z = localCoords[2];
138 x = -x; BxSign *= -1.0;
142 y = -y; BxSign *= -1.0;
154 if (inside == kFALSE) {
return;}
161 Int_t iX = xBinInfo.first;
162 Int_t iY = yBinInfo.first;
163 Int_t iZ = zBinInfo.first;
166 if (iX == -1 || iY == -1 || iZ == -1) {
return;}
208 if (fabs(
phi_) > 1e-6 || fabs(
theta_) > 1e-6 || fabs(
psi_) > 1e-6) {
231 std::cout<<
"ShipBFieldMap::readMapFile() creating field "<<this->GetName()
252 std::cout<<
"ShipBFieldMap: could not find the file "<<
mapFileName_<<std::endl;
257 TTree* rTree =
dynamic_cast<TTree*
>(theFile->Get(
"Range"));
259 std::cout<<
"ShipBFieldMap: could not find Range tree in "<<
mapFileName_<<std::endl;
263 rTree->SetBranchAddress(
"xMin", &
xMin_);
264 rTree->SetBranchAddress(
"xMax", &
xMax_);
265 rTree->SetBranchAddress(
"dx", &
dx_);
266 rTree->SetBranchAddress(
"yMin", &
yMin_);
267 rTree->SetBranchAddress(
"yMax", &
yMax_);
268 rTree->SetBranchAddress(
"dy", &
dy_);
269 rTree->SetBranchAddress(
"zMin", &
zMin_);
270 rTree->SetBranchAddress(
"zMax", &
zMax_);
271 rTree->SetBranchAddress(
"dz", &
dz_);
284 TTree* dTree =
dynamic_cast<TTree*
>(theFile->Get(
"Data"));
286 std::cout<<
"ShipBFieldMap: could not find Data tree in "<<
mapFileName_<<std::endl;
292 dTree->SetBranchStatus(
"*", 0);
293 dTree->SetBranchStatus(
"Bx", 1);
294 dTree->SetBranchStatus(
"By", 1);
295 dTree->SetBranchStatus(
"Bz", 1);
297 dTree->SetBranchAddress(
"Bx", &Bx);
298 dTree->SetBranchAddress(
"By", &By);
299 dTree->SetBranchAddress(
"Bz", &Bz);
301 Int_t nEntries = dTree->GetEntries();
302 if (nEntries !=
N_) {
303 std::cout<<
"Expected "<<
N_<<
" field map entries but found "<<nEntries<<std::endl;
309 for (Int_t i = 0; i < nEntries; i++) {
320 std::vector<Float_t> BVector(3);
321 BVector[0] = Bx; BVector[1] = By; BVector[2] = Bz;
336 std::string tmpString(
"");
350 getData >> tmpString >> tmpString >> tmpString;
356 Float_t Bx(0.0), By(0.0), Bz(0.0);
358 for (Int_t i = 0; i <
N_; i++) {
360 getData >> Bx >> By >> Bz;
369 std::vector<Float_t> BVector(3);
370 BVector[0] = Bx; BVector[1] = By; BVector[2] = Bz;
384 Bool_t inside(kFALSE);
387 y <= yMax_ && z >=
zMin_ && z <=
zMax_) {inside = kTRUE;}
417 std::cout<<
"x limits: "<<
xMin_<<
", "<<
xMax_<<
", dx = "<<
dx_<<std::endl;
418 std::cout<<
"y limits: "<<
yMin_<<
", "<<
yMax_<<
", dy = "<<
dy_<<std::endl;
419 std::cout<<
"z limits: "<<
zMin_<<
", "<<
zMax_<<
", dz = "<<
dz_<<std::endl;
422 std::cout<<
"Angles : phi = "<<
phi_<<
", theta = "<<
theta_<<
", psi = "<<
psi_<<std::endl;
424 std::cout<<
"Total number of bins = "<<
N_
425 <<
"; Nx = "<<
Nx_<<
", Ny = "<<
Ny_<<
", Nz = "<<
Nz_<<std::endl;
433 Float_t du(0.0), uMin(0.0), Nu(0);
449 Float_t dist = (u - uMin)/du;
451 iBin =
static_cast<Int_t
>(dist);
453 fracL = (dist - iBin*1.0);
458 if (iBin < 0 || iBin >= Nu) {
459 iBin = -1; fracL = 0.0;
475 Int_t index = (iX*
Ny_ + iY)*
Nz_ + iZ;
478 }
else if (index >=
N_) {
504 Float_t A = (*fieldMap_)[
binA_][iAxis];
505 Float_t B = (*fieldMap_)[
binB_][iAxis];
506 Float_t C = (*fieldMap_)[
binC_][iAxis];
507 Float_t D = (*fieldMap_)[
binD_][iAxis];
508 Float_t E = (*fieldMap_)[
binE_][iAxis];
509 Float_t F = (*fieldMap_)[
binF_][iAxis];
510 Float_t G = (*fieldMap_)[
binG_][iAxis];
511 Float_t H = (*fieldMap_)[
binH_][iAxis];
Class that defines a (3d) magnetic field map (distances in cm, fields in tesla)
Float_t zFrac_
Fractional bin distance along z.
Float_t xMax_
The maximum value of x for the map.
Int_t binD_
Bin D for the trilinear interpolation.
Float_t dy_
The bin width along y.
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 co-ordinate range along z.
std::pair< Int_t, Float_t > binPair
Typedef for an int-double pair.
std::vector< std::vector< Float_t > > floatArray
Typedef for a vector containing a vector of floats.
Float_t zFrac1_
Complimentary fractional bin distance along z.
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 binE_
Bin E for the trilinear interpolation.
Float_t BInterCalc(CoordAxis theAxis)
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.
Float_t yFrac1_
Complimentary fractional bin distance along y.
Float_t xFrac_
Fractional bin distance along x.
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.
Float_t theta_
The second Euler rotation angle about the new x axis.
Float_t yFrac_
Fractional bin distance along y.
Bool_t isCopy_
Flag to specify if we are a copy of the field map (just a change of global offsets)
Int_t binC_
Bin C for the trilinear interpolation.
virtual void Field(const Double_t *position, Double_t *B)
Implementation of evaluating the B field.
Int_t binG_
Bin G for the trilinear interpolation.
Int_t binH_
Bin H for the trilinear interpolation.
Float_t xMin_
The minimum value of x for the map.
void initialise()
Initialisation.
Int_t binB_
Bin B for the trilinear interpolation.
Int_t binF_
Bin F for the trilinear interpolation.
CoordAxis
Enumeration to specify the co-ordinate type.
Int_t Nx_
The number of bins along x.
Float_t xRange_
The co-ordinate 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.
virtual ~ShipBFieldMap()
Destructor.
void readRootFile()
Process the ROOT file containing the field map data.
Float_t xFrac1_
Complimentary fractional bin distance along x.
Int_t binA_
Bin A for the trilinear interpolation.
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 co-ordinate 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.