CbmRoot
Loading...
Searching...
No Matches
CbmFieldMapSym2.cxx
Go to the documentation of this file.
1/* Copyright (C) 2005-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Elena Litvinenko, Denis Bertini [committer] */
4
5// -------------------------------------------------------------------------
6// ----- CbmFieldMapSym2 source file -----
7// ----- Created 09/06/05 by E. Litvinenko (CbmFieldMapLIT.cxx) -----
8// ----- Redesign 20/02/06 by V. Friese -----
9// -------------------------------------------------------------------------
10#include "CbmFieldMapSym2.h"
11
12#include <TArrayF.h> // for TArrayF
13
14// ------------- Default constructor ----------------------------------
15CbmFieldMapSym2::CbmFieldMapSym2() : CbmFieldMap(), fHemiX(0.), fHemiY(0.) { fType = 2; }
16// ------------------------------------------------------------------------
17
18
19// ------------- Standard constructor ---------------------------------
20CbmFieldMapSym2::CbmFieldMapSym2(const char* mapName, const char* fileType)
21 : CbmFieldMap(mapName, fileType)
22 , fHemiX(0.)
23 , fHemiY(0.)
24{
25 fType = 2;
26}
27// ------------------------------------------------------------------------
28
29
30// ------------ Constructor from CbmFieldPar --------------------------
31CbmFieldMapSym2::CbmFieldMapSym2(CbmFieldPar* fieldPar) : CbmFieldMap(fieldPar), fHemiX(0.), fHemiY(0.) { fType = 2; }
32// ------------------------------------------------------------------------
33
34
35// ------------ Destructor --------------------------------------------
37// ------------------------------------------------------------------------
38
39
40// ----------- Get x component of the field ---------------------------
41Double_t CbmFieldMapSym2::GetBx(Double_t x, Double_t y, Double_t z)
42{
43
44 Int_t ix = 0;
45 Int_t iy = 0;
46 Int_t iz = 0;
47 Double_t dx = 0.;
48 Double_t dy = 0.;
49 Double_t dz = 0.;
50
51 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
52
53 // Get Bx field values at grid cell corners
54 fHa[0][0][0] = fBx->At(ix * fNy * fNz + iy * fNz + iz);
55 fHa[1][0][0] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + iz);
56 fHa[0][1][0] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
57 fHa[1][1][0] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
58 fHa[0][0][1] = fBx->At(ix * fNy * fNz + iy * fNz + (iz + 1));
59 fHa[1][0][1] = fBx->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
60 fHa[0][1][1] = fBx->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
61 fHa[1][1][1] = fBx->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
62
63 // Return interpolated field value
64 return Interpolate(dx, dy, dz) * fHemiX * fHemiY;
65 }
66
67 return 0.;
68}
69// ------------------------------------------------------------------------
70
71
72// ----------- Get y component of the field ---------------------------
73Double_t CbmFieldMapSym2::GetBy(Double_t x, Double_t y, Double_t z)
74{
75
76 Int_t ix = 0;
77 Int_t iy = 0;
78 Int_t iz = 0;
79 Double_t dx = 0.;
80 Double_t dy = 0.;
81 Double_t dz = 0.;
82
83 if (IsInside(x, y, z, ix, iy, iz, dx, dy, dz)) {
84
85 // Get By field values at grid cell corners
86 fHa[0][0][0] = fBy->At(ix * fNy * fNz + iy * fNz + iz);
87 fHa[1][0][0] = fBy->At((ix + 1) * fNy * fNz + iy * fNz + iz);
88 fHa[0][1][0] = fBy->At(ix * fNy * fNz + (iy + 1) * fNz + iz);
89 fHa[1][1][0] = fBy->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + iz);
90 fHa[0][0][1] = fBy->At(ix * fNy * fNz + iy * fNz + (iz + 1));
91 fHa[1][0][1] = fBy->At((ix + 1) * fNy * fNz + iy * fNz + (iz + 1));
92 fHa[0][1][1] = fBy->At(ix * fNy * fNz + (iy + 1) * fNz + (iz + 1));
93 fHa[1][1][1] = fBy->At((ix + 1) * fNy * fNz + (iy + 1) * fNz + (iz + 1));
94
95 // Return interpolated field value
96 return Interpolate(dx, dy, dz);
97 }
98
99 return 0.;
100}
101// ------------------------------------------------------------------------
102
103
104// ----------- Get z component of the field ---------------------------
105Double_t CbmFieldMapSym2::GetBz(Double_t x, Double_t y, Double_t z)
106{
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;
129 }
130
131 return 0.;
132}
133// ------------------------------------------------------------------------
134
135
136// ----------- Check whether a point is inside the map ----------------
137Bool_t CbmFieldMapSym2::IsInside(Double_t x, Double_t y, Double_t z, Int_t& ix, Int_t& iy, Int_t& iz, Double_t& dx,
138 Double_t& dy, Double_t& dz)
139{
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 = 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
157 // --- Check for being outside the map range
158 if (!(xl >= fXmin && xl < fXmax && yl >= fYmin && yl < fYmax && zl >= fZmin && zl < fZmax)) {
159 ix = iy = iz = 0;
160 dx = dy = dz = 0.;
161 return kFALSE;
162 }
163
164 // --- Determine grid cell
165 ix = Int_t((xl - fXmin) / fXstep);
166 iy = Int_t((yl - fYmin) / fYstep);
167 iz = Int_t((zl - fZmin) / fZstep);
168
169
170 // Relative distance from grid point (in units of cell size)
171 dx = (xl - fXmin) / fXstep - Double_t(ix);
172 dy = (yl - fYmin) / fYstep - Double_t(iy);
173 dz = (zl - fZmin) / fZstep - Double_t(iz);
174
175 return kTRUE;
176}
177// ------------------------------------------------------------------------
178
179
ClassImp(CbmConverterManager)
virtual ~CbmFieldMapSym2()
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)
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