BmnRoot
Loading...
Searching...
No Matches
BmnFieldMapSym3.cxx
Go to the documentation of this file.
1// -------------------------------------------------------------------------
2// ----- BmnFieldMapSym3 source file -----
3// ----- Created 12/01/04 by M. Al/Turany (BmnField.cxx) -----
4// ----- Redesign 13/02/06 by V. Friese -----
5// -------------------------------------------------------------------------
6
7#include "BmnFieldMapSym3.h"
8#include "FairRun.h"
9#include "FairRuntimeDb.h"
10#include "TArrayF.h"
11#include "TMath.h"
12
13using namespace TMath;
14
15// ------------- Default constructor ----------------------------------
17: BmnFieldMap(),
18fHemiX(0.),
19fHemiY(0.),
20fHemiZ(0.)
21{
22 fType = 3;
23}
24
25// ------------- Standard constructor ---------------------------------
27: BmnFieldMap(mapName),
28fHemiX(0.),
29fHemiY(0.),
30fHemiZ(0.)
31{
32 fType = 3;
33}
34
35// ------------- Constructor from BmnFieldPar -------------------------
37: BmnFieldMap(fieldPar),
38fHemiX(0.),
39fHemiY(0.),
40fHemiZ(0.)
41{
42 fType = 3;
43}
44
45// ------------ Destructor --------------------------------------------
48
49// ----------- Get x component of the field ---------------------------
50Double_t BmnFieldMapSym3::GetBx(Double_t x, Double_t y, Double_t z)
51{
52 Int_t ix = 0;
53 Int_t iy = 0;
54 Int_t iz = 0;
55 Double_t dx = 0.;
56 Double_t dy = 0.;
57 Double_t dz = 0.;
58
59 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz))
60 {
61 // Get Bx field values at grid cell corners
62 fHa[0][0][0] = fBx->At(ix * fNy * fNz + iy * fNz + iz);
63 fHa[1][0][0] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + iz);
64 fHa[0][1][0] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
65 fHa[1][1][0] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
66 fHa[0][0][1] = fBx->At(ix * fNy * fNz + iy * fNz + (iz + 1));
67 fHa[1][0][1] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
68 fHa[0][1][1] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
69 fHa[1][1][1] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
70
71 // Return interpolated field value
72 return Interpolate(dx, dy, dz) * fHemiX * fHemiY;
73 }
74
75 return 0.;
76}
77
78// ----------- Get y component of the field ---------------------------
79Double_t BmnFieldMapSym3::GetBy(Double_t x, Double_t y, Double_t z)
80{
81 Int_t ix = 0;
82 Int_t iy = 0;
83 Int_t iz = 0;
84 Double_t dx = 0.;
85 Double_t dy = 0.;
86 Double_t dz = 0.;
87
88 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
89
90 // Get By field values at grid cell corners
91 fHa[0][0][0] = fBy->At(ix * fNy * fNz + iy * fNz + iz);
92 fHa[1][0][0] = fBy->At((ix + 1) * fNy * fNz + iy * fNz + iz);
93 fHa[0][1][0] = fBy->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
94 fHa[1][1][0] = fBy->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
95 fHa[0][0][1] = fBy->At(ix * fNy * fNz + iy * fNz + (iz + 1));
96 fHa[1][0][1] = fBy->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
97 fHa[0][1][1] = fBy->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
98 fHa[1][1][1] = fBy->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
99
100 // Return interpolated field value
101 return Interpolate(dx, dy, dz);
102 }
103 return 0.;
104}
105
106// ----------- Get z component of the field ---------------------------
107Double_t BmnFieldMapSym3::GetBz(Double_t x, Double_t y, Double_t z)
108{
109 Int_t ix = 0;
110 Int_t iy = 0;
111 Int_t iz = 0;
112 Double_t dx = 0.;
113 Double_t dy = 0.;
114 Double_t dz = 0.;
115
116 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
117
118 // Get Bz field values at grid cell corners
119 fHa[0][0][0] = fBz->At(ix * fNy * fNz + iy * fNz + iz);
120 fHa[1][0][0] = fBz->At((ix + 1) * fNy * fNz + iy * fNz + iz);
121 fHa[0][1][0] = fBz->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
122 fHa[1][1][0] = fBz->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
123 fHa[0][0][1] = fBz->At(ix * fNy * fNz + iy * fNz + (iz + 1));
124 fHa[1][0][1] = fBz->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
125 fHa[0][1][1] = fBz->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
126 fHa[1][1][1] = fBz->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
127
128 // Return interpolated field value
129 return Interpolate(dx, dy, dz) * fHemiY * fHemiZ;
130
131 }
132
133 return 0.;
134}
135
136// ----------- Check whether a point is inside the map ----------------
137Bool_t BmnFieldMapSym3::IsInside(Double_t x, Double_t y, Double_t z,
138 Int_t& ix, Int_t& iy, Int_t& iz,
139 Double_t& dx, Double_t& dy, Double_t& dz)
140{
141 // --- Transform into local coordinate system
142 Double_t xl = x - fPosX;
143 Double_t yl = y - fPosY;
144 Double_t zl = z - fPosZ;
145
146 // --- Reflect w.r.t. symmetry axes
147 fHemiX = fHemiY = fHemiZ = 1.;
148 if (xl < 0.) {
149 fHemiX = -1.;
150 xl = -1. * xl;
151 }
152 if (yl < 0.) {
153 fHemiY = -1.;
154 yl = -1. * yl;
155 }
156 if (zl < 0.) {
157 fHemiZ = -1.;
158 zl = -1. * zl;
159 }
160
161 // --- Check for being outside the map range
162 if (!(xl >= fXmin && xl < fXmax && yl >= fYmin && yl < fYmax &&
163 zl >= fZmin && zl < fZmax)) {
164 ix = iy = iz = 0;
165 dx = dy = dz = 0.;
166 return kFALSE;
167 }
168
169 // --- Determine grid cell
170 ix = Int_t((xl - fXmin) / fXstep);
171 iy = Int_t((yl - fYmin) / fYstep);
172 iz = Int_t((zl - fZmin) / fZstep);
173
174 // Relative distance from grid point (in units of cell size)
175 dx = (xl - fXmin) / fXstep - Double_t(ix);
176 dy = (yl - fYmin) / fYstep - Double_t(iy);
177 dz = (zl - fZmin) / fZstep - Double_t(iz);
178
179 return kTRUE;
180}
181
183{
184 TString MapName = GetName();
185 // LOG(info) << "BmnFieldMapSym3::FillParContainer() ";
186 FairRun* fRun = FairRun::Instance();
187 FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
188 // Bool_t kParameterMerged = kTRUE;
189 BmnFieldPar* fieldPar = (BmnFieldPar*) rtdb->getContainer("BmnFieldPar");
190 fieldPar->SetParameters(this);
191 fieldPar->setInputVersion(fRun->GetRunId(), 1);
192 fieldPar->setChanged();
193}
virtual Bool_t IsInside(Double_t x, Double_t y, Double_t z, Int_t &ix, Int_t &iy, Int_t &iz, Double_t &dx, Double_t &dy, Double_t &dz)
virtual ~BmnFieldMapSym3()
Double_t fHa[2][2][2]
TArrayF * fBy
Double_t fPosZ
TArrayF * GetBx() const
Definition BmnFieldMap.h:96
Double_t fPosY
TArrayF * GetBy() const
Definition BmnFieldMap.h:97
TArrayF * fBz
Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz)
Double_t fPosX
Double_t fZmin
TArrayF * GetBz() const
Definition BmnFieldMap.h:98
Double_t fYmax
Double_t fXstep
Double_t fZstep
Double_t fXmin
TArrayF * fBx
Double_t fZmax
Double_t fYmin
Double_t fYstep
void SetParameters(FairField *field)