BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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
9#include "FairRun.h"
10#include "FairRuntimeDb.h"
11#include "TArrayF.h"
12#include "TMath.h"
13
14using namespace TMath;
15
16// ------------- Default constructor ----------------------------------
18 : BmnFieldMap()
19 , fHemiX(0.)
20 , fHemiY(0.)
21 , fHemiZ(0.)
22{
23 fType = 3;
24}
25
26// ------------- Standard constructor ---------------------------------
28 : BmnFieldMap(mapName)
29 , fHemiX(0.)
30 , fHemiY(0.)
31 , fHemiZ(0.)
32{
33 fType = 3;
34}
35
36// ------------- Constructor from BmnFieldPar -------------------------
38 : BmnFieldMap(fieldPar)
39 , fHemiX(0.)
40 , fHemiY(0.)
41 , fHemiZ(0.)
42{
43 fType = 3;
44}
45
46// ------------ Destructor --------------------------------------------
48
49// ----------- Get x component of the field ---------------------------
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 // Get Bx field values at grid cell corners
61 fHa[0][0][0] = fBx->At(ix * fNy * fNz + iy * fNz + iz);
62 fHa[1][0][0] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + iz);
63 fHa[0][1][0] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
64 fHa[1][1][0] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
65 fHa[0][0][1] = fBx->At(ix * fNy * fNz + iy * fNz + (iz + 1));
66 fHa[1][0][1] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
67 fHa[0][1][1] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
68 fHa[1][1][1] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
69
70 // Return interpolated field value
71 return Interpolate(dx, dy, dz) * fHemiX * fHemiY;
72 }
73
74 return 0.;
75}
76
77// ----------- Get y component of the field ---------------------------
79{
80 Int_t ix = 0;
81 Int_t iy = 0;
82 Int_t iz = 0;
83 Double_t dx = 0.;
84 Double_t dy = 0.;
85 Double_t dz = 0.;
86
87 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
88
89 // Get By field values at grid cell corners
90 fHa[0][0][0] = fBy->At(ix * fNy * fNz + iy * fNz + iz);
91 fHa[1][0][0] = fBy->At((ix + 1) * fNy * fNz + iy * fNz + iz);
92 fHa[0][1][0] = fBy->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
93 fHa[1][1][0] = fBy->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
94 fHa[0][0][1] = fBy->At(ix * fNy * fNz + iy * fNz + (iz + 1));
95 fHa[1][0][1] = fBy->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
96 fHa[0][1][1] = fBy->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
97 fHa[1][1][1] = fBy->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
98
99 // Return interpolated field value
100 return Interpolate(dx, dy, dz);
101 }
102 return 0.;
103}
104
105// ----------- Get z component of the field ---------------------------
107{
108 Int_t ix = 0;
109 Int_t iy = 0;
110 Int_t iz = 0;
111 Double_t dx = 0.;
112 Double_t dy = 0.;
113 Double_t dz = 0.;
114
115 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
116
117 // Get Bz field values at grid cell corners
118 fHa[0][0][0] = fBz->At(ix * fNy * fNz + iy * fNz + iz);
119 fHa[1][0][0] = fBz->At((ix + 1) * fNy * fNz + iy * fNz + iz);
120 fHa[0][1][0] = fBz->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
121 fHa[1][1][0] = fBz->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
122 fHa[0][0][1] = fBz->At(ix * fNy * fNz + iy * fNz + (iz + 1));
123 fHa[1][0][1] = fBz->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
124 fHa[0][1][1] = fBz->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
125 fHa[1][1][1] = fBz->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
126
127 // Return interpolated field value
128 return Interpolate(dx, dy, dz) * fHemiY * fHemiZ;
129 }
130
131 return 0.;
132}
133
134// ----------- Check whether a point is inside the map ----------------
136 Double_t y,
137 Double_t z,
138 Int_t& ix,
139 Int_t& iy,
140 Int_t& iz,
141 Double_t& dx,
142 Double_t& dy,
143 Double_t& dz)
144{
145 // --- Transform into local coordinate system
146 Double_t xl = x - fPosX;
147 Double_t yl = y - fPosY;
148 Double_t zl = z - fPosZ;
149
150 // --- Reflect w.r.t. symmetry axes
151 fHemiX = fHemiY = fHemiZ = 1.;
152 if (xl < 0.) {
153 fHemiX = -1.;
154 xl = -1. * xl;
155 }
156 if (yl < 0.) {
157 fHemiY = -1.;
158 yl = -1. * yl;
159 }
160 if (zl < 0.) {
161 fHemiZ = -1.;
162 zl = -1. * zl;
163 }
164
165 // --- Check for being outside the map range
166 if (!(xl >= fXmin && xl < fXmax && yl >= fYmin && yl < fYmax && zl >= fZmin && zl < fZmax)) {
167 ix = iy = iz = 0;
168 dx = dy = dz = 0.;
169 return kFALSE;
170 }
171
172 // --- Determine grid cell
173 ix = Int_t((xl - fXmin) / fXstep);
174 iy = Int_t((yl - fYmin) / fYstep);
175 iz = Int_t((zl - fZmin) / fZstep);
176
177 // Relative distance from grid point (in units of cell size)
178 dx = (xl - fXmin) / fXstep - Double_t(ix);
179 dy = (yl - fYmin) / fYstep - Double_t(iy);
180 dz = (zl - fZmin) / fZstep - Double_t(iz);
181
182 return kTRUE;
183}
184
186{
187 TString MapName = GetName();
188 // LOG(info) << "BmnFieldMapSym3::FillParContainer() ";
189 FairRun* fRun = FairRun::Instance();
190 FairRuntimeDb* rtdb = fRun->GetRuntimeDb();
191 // Bool_t kParameterMerged = kTRUE;
192 BmnFieldPar* fieldPar = (BmnFieldPar*)rtdb->getContainer("BmnFieldPar");
193 fieldPar->SetParameters(this);
194 fieldPar->setInputVersion(fRun->GetRunId(), 1);
195 fieldPar->setChanged();
196}
bool Bool_t
int Int_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
Double_t fHemiX
Hemispheres of a point (for temporary use).
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)
Determine whether a point is inside the field map.
BmnFieldMapSym3()
Default constructor.
virtual ~BmnFieldMapSym3()
Destructor.
Double_t fHa[2][2][2]
Variables for temporary storage Used in the very frequently called method GetFieldValue.
TArrayF * fBy
Double_t fPosZ
TArrayF * GetBx() const
Accessors to the field value arrays.
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)
Get field values by interpolation of the grid.
Double_t fPosX
Field centre position in global coordinates.
Double_t fZmin
TArrayF * GetBz() const
Definition BmnFieldMap.h:98
Double_t fXstep
Double_t fZstep
Double_t fXmin
Field limits in local coordinate system.
TArrayF * fBx
Arrays with the field values.
Double_t fZmax
Double_t fYmin
Double_t fYstep
void SetParameters(FairField *field)
Set parameters from BmnField.