CbmRoot
Loading...
Searching...
No Matches
CbmFieldMapSym3.cxx
Go to the documentation of this file.
1/* Copyright (C) 2004-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Mohammad Al-Turany, Denis Bertini [committer] */
4
5// -------------------------------------------------------------------------
6// ----- CbmFieldMapSym3 source file -----
7// ----- Created 12/01/04 by M. Al/Turany (CbmField.cxx) -----
8// ----- Redesign 13/02/06 by V. Friese -----
9// -------------------------------------------------------------------------
10#include "CbmFieldMapSym3.h"
11
12#include <TArrayF.h> // for TArrayF
13
14// ------------- Default constructor ----------------------------------
15CbmFieldMapSym3::CbmFieldMapSym3() : CbmFieldMap(), fHemiX(0.), fHemiY(0.), fHemiZ(0.) { fType = 3; }
16// ------------------------------------------------------------------------
17
18
19// ------------- Standard constructor ---------------------------------
20CbmFieldMapSym3::CbmFieldMapSym3(const char* mapName, const char* fileType)
21 : CbmFieldMap(mapName, fileType)
22 , fHemiX(0.)
23 , fHemiY(0.)
24 , fHemiZ(0.)
25{
26 fType = 3;
27}
28// ------------------------------------------------------------------------
29
30
31// ------------- Constructor from CbmFieldPar -------------------------
32CbmFieldMapSym3::CbmFieldMapSym3(CbmFieldPar* fieldPar) : CbmFieldMap(fieldPar), fHemiX(0.), fHemiY(0.), fHemiZ(0.)
33{
34 fType = 3;
35}
36// ------------------------------------------------------------------------
37
38
39// ------------ Destructor --------------------------------------------
41// ------------------------------------------------------------------------
42
43
44// ----------- Get x component of the field ---------------------------
45Double_t CbmFieldMapSym3::GetBx(Double_t x, Double_t y, Double_t z)
46{
47
48 Int_t ix = 0;
49 Int_t iy = 0;
50 Int_t iz = 0;
51 Double_t dx = 0.;
52 Double_t dy = 0.;
53 Double_t dz = 0.;
54
55 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
56
57 // Get Bx field values at grid cell corners
58 fHa[0][0][0] = fBx->At(ix * fNy * fNz + iy * fNz + iz);
59 fHa[1][0][0] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + iz);
60 fHa[0][1][0] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
61 fHa[1][1][0] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
62 fHa[0][0][1] = fBx->At(ix * fNy * fNz + iy * fNz + (iz + 1));
63 fHa[1][0][1] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
64 fHa[0][1][1] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
65 fHa[1][1][1] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
66
67 // Return interpolated field value
68 return Interpolate(dx, dy, dz) * fHemiX * fHemiY;
69 }
70
71 return 0.;
72}
73// ------------------------------------------------------------------------
74
75
76// ----------- Get y component of the field ---------------------------
77Double_t CbmFieldMapSym3::GetBy(Double_t x, Double_t y, Double_t z)
78{
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
103 return 0.;
104}
105// ------------------------------------------------------------------------
106
107
108// ----------- Get z component of the field ---------------------------
109Double_t CbmFieldMapSym3::GetBz(Double_t x, Double_t y, Double_t z)
110{
111
112 Int_t ix = 0;
113 Int_t iy = 0;
114 Int_t iz = 0;
115 Double_t dx = 0.;
116 Double_t dy = 0.;
117 Double_t dz = 0.;
118
119 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
120
121 // Get Bz field values at grid cell corners
122 fHa[0][0][0] = fBz->At(ix * fNy * fNz + iy * fNz + iz);
123 fHa[1][0][0] = fBz->At((ix + 1) * fNy * fNz + iy * fNz + iz);
124 fHa[0][1][0] = fBz->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
125 fHa[1][1][0] = fBz->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
126 fHa[0][0][1] = fBz->At(ix * fNy * fNz + iy * fNz + (iz + 1));
127 fHa[1][0][1] = fBz->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
128 fHa[0][1][1] = fBz->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
129 fHa[1][1][1] = fBz->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
130
131 // Return interpolated field value
132 return Interpolate(dx, dy, dz) * fHemiY * fHemiZ;
133 }
134
135 return 0.;
136}
137// ------------------------------------------------------------------------
138
139
140// ----------- Check whether a point is inside the map ----------------
141Bool_t CbmFieldMapSym3::IsInside(Double_t x, Double_t y, Double_t z, Int_t& ix, Int_t& iy, Int_t& iz, Double_t& dx,
142 Double_t& dy, Double_t& dz)
143{
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// ------------------------------------------------------------------------
185
186
ClassImp(CbmConverterManager)
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 ~CbmFieldMapSym3()
Double_t fPosZ
TArrayF * fBy
Double_t fPosY
TArrayF * GetBz() const
Double_t fPosX
Double_t fZmin
Double_t fZmax
Double_t fYmin
Double_t fHa[2][2][2]
TArrayF * GetBx() const
TArrayF * fBx
TArrayF * fBz
Double_t fXmin
Double_t fYstep
Double_t fZstep
Double_t Interpolate(Double_t dx, Double_t dy, Double_t dz)
Double_t fXstep
TArrayF * GetBy() const