CbmRoot
Loading...
Searching...
No Matches
LitFieldSlice.h
Go to the documentation of this file.
1/* Copyright (C) 2009-2013 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer] */
4
12#ifndef LITFIELDSLICE_H_
13#define LITFIELDSLICE_H_
14
15#include "LitFieldValue.h"
16
17#include <vector>
18
19namespace lit
20{
21 namespace parallel
22 {
23
28#define LIT_POLYNOM_DEGREE 7
29
40 template<class T>
42 public:
43#if LIT_POLYNOM_DEGREE == 3
44 static const unsigned int N = 10; // for the 3rd degree polynom
45#else
46#if LIT_POLYNOM_DEGREE == 5
47 static const unsigned int N = 21; // for the 5th degree polynom
48#else
49#if LIT_POLYNOM_DEGREE == 7
50 static const unsigned int N = 36; // for the 7th degree polynom
51#else
52#if LIT_POLYNOM_DEGREE == 9
53 static const unsigned int N = 55; // for the 7th degree polynom
54#endif
55#endif
56#endif
57#endif
58
59 public:
64 {
65 for (unsigned int i = 0; i < N; i++) {
66 cx[i] = cy[i] = cz[i] = 0.;
67 }
68 }
69
80 void GetFieldValue(const T& x, const T& y, LitFieldValue<T>& B) const
81 {
82#if LIT_POLYNOM_DEGREE == 3
83 T x2 = x * x;
84 T y2 = y * y;
85 T x2y = x2 * y;
86 T xy2 = x * y2;
87 T x3 = x2 * x;
88 T y3 = y2 * y;
89
90 B.Bx = cx[0] + cx[1] * x + cx[2] * y + cx[3] * x2 + cx[4] * x * y + cx[5] * y2 + cx[6] * x3 + cx[7] * x2y
91 + cx[8] * xy2 + cx[9] * y3;
92
93 B.By = cy[0] + cy[1] * x + cy[2] * y + cy[3] * x2 + cy[4] * x * y + cy[5] * y2 + cy[6] * x3 + cy[7] * x2y
94 + cy[8] * xy2 + cy[9] * y3;
95
96 B.Bz = cz[0] + cz[1] * x + cz[2] * y + cz[3] * x2 + cz[4] * x * y + cz[5] * y2 + cz[6] * x3 + cz[7] * x2y
97 + cz[8] * xy2 + cz[9] * y3;
98#else
99#if LIT_POLYNOM_DEGREE == 5
100 T x2 = x * x;
101 T y2 = y * y;
102 T xy = x * y;
103
104 T x3 = x2 * x;
105 T y3 = y2 * y;
106 T xy2 = x * y2;
107 T x2y = x2 * y;
108
109 T x4 = x3 * x;
110 T y4 = y3 * y;
111 T xy3 = x * y3;
112 T x2y2 = x2 * y2;
113 T x3y = x3 * y;
114
115 T x5 = x4 * x;
116 T y5 = y4 * y;
117 T xy4 = x * y4;
118 T x2y3 = x2 * y3;
119 T x3y2 = x3 * y2;
120 T x4y = x4 * y;
121
122 B.Bx = cx[0] + cx[1] * x + cx[2] * y + cx[3] * x2 + cx[4] * xy + cx[5] * y2 + cx[6] * x3 + cx[7] * x2y
123 + cx[8] * xy2 + cx[9] * y3 + cx[10] * x4 + cx[11] * x3y + cx[12] * x2y2 + cx[13] * xy3 + cx[14] * y4
124 + cx[15] * x5 + cx[16] * x4y + cx[17] * x3y2 + cx[18] * x2y3 + cx[19] * xy4 + cx[20] * y5;
125
126 B.By = cy[0] + cy[1] * x + cy[2] * y + cy[3] * x2 + cy[4] * xy + cy[5] * y2 + cy[6] * x3 + cy[7] * x2y
127 + cy[8] * xy2 + cy[9] * y3 + cy[10] * x4 + cy[11] * x3y + cy[12] * x2y2 + cy[13] * xy3 + cy[14] * y4
128 + cy[15] * x5 + cy[16] * x4y + cy[17] * x3y2 + cy[18] * x2y3 + cy[19] * xy4 + cy[20] * y5;
129
130 B.Bz = cz[0] + cz[1] * x + cz[2] * y + cz[3] * x2 + cz[4] * xy + cz[5] * y2 + cz[6] * x3 + cz[7] * x2y
131 + cz[8] * xy2 + cz[9] * y3 + cz[10] * x4 + cz[11] * x3y + cz[12] * x2y2 + cz[13] * xy3 + cz[14] * y4
132 + cz[15] * x5 + cz[16] * x4y + cz[17] * x3y2 + cz[18] * x2y3 + cz[19] * xy4 + cz[20] * y5;
133
134#else
135#if LIT_POLYNOM_DEGREE == 7
136 T x2 = x * x;
137 T y2 = y * y;
138 T xy = x * y;
139
140 T x3 = x2 * x;
141 T y3 = y2 * y;
142 T xy2 = x * y2;
143 T x2y = x2 * y;
144
145 T x4 = x3 * x;
146 T y4 = y3 * y;
147 T xy3 = x * y3;
148 T x2y2 = x2 * y2;
149 T x3y = x3 * y;
150
151 T x5 = x4 * x;
152 T y5 = y4 * y;
153 T xy4 = x * y4;
154 T x2y3 = x2 * y3;
155 T x3y2 = x3 * y2;
156 T x4y = x4 * y;
157
158 T x6 = x5 * x;
159 T y6 = y5 * y;
160 T xy5 = x * y5;
161 T x2y4 = x2 * y4;
162 T x3y3 = x3 * y3;
163 T x4y2 = x4 * y2;
164 T x5y = x5 * y;
165
166 T x7 = x6 * x;
167 T y7 = y6 * y;
168 T xy6 = x * y6;
169 T x2y5 = x2 * y5;
170 T x3y4 = x3 * y4;
171 T x4y3 = x4 * y3;
172 T x5y2 = x5 * y2;
173 T x6y = x6 * y;
174
175 B.Bx = cx[0] + cx[1] * x + cx[2] * y + cx[3] * x2 + cx[4] * xy + cx[5] * y2 + cx[6] * x3 + cx[7] * x2y
176 + cx[8] * xy2 + cx[9] * y3 + cx[10] * x4 + cx[11] * x3y + cx[12] * x2y2 + cx[13] * xy3 + cx[14] * y4
177 + cx[15] * x5 + cx[16] * x4y + cx[17] * x3y2 + cx[18] * x2y3 + cx[19] * xy4 + cx[20] * y5 + cx[21] * x6
178 + cx[22] * x5y + cx[23] * x4y2 + cx[24] * x3y3 + cx[25] * x2y4 + cx[26] * xy5 + cx[27] * y6 + cx[28] * x7
179 + cx[29] * x6y + cx[30] * x5y2 + cx[31] * x4y3 + cx[32] * x3y4 + cx[33] * x2y5 + cx[34] * xy6
180 + cx[35] * y7;
181
182 B.By = cy[0] + cy[1] * x + cy[2] * y + cy[3] * x2 + cy[4] * xy + cy[5] * y2 + cy[6] * x3 + cy[7] * x2y
183 + cy[8] * xy2 + cy[9] * y3 + cy[10] * x4 + cy[11] * x3y + cy[12] * x2y2 + cy[13] * xy3 + cy[14] * y4
184 + cy[15] * x5 + cy[16] * x4y + cy[17] * x3y2 + cy[18] * x2y3 + cy[19] * xy4 + cy[20] * y5 + cy[21] * x6
185 + cy[22] * x5y + cy[23] * x4y2 + cy[24] * x3y3 + cy[25] * x2y4 + cy[26] * xy5 + cy[27] * y6 + cy[28] * x7
186 + cy[29] * x6y + cy[30] * x5y2 + cy[31] * x4y3 + cy[32] * x3y4 + cy[33] * x2y5 + cy[34] * xy6
187 + cy[35] * y7;
188
189 B.Bz = cz[0] + cz[1] * x + cz[2] * y + cz[3] * x2 + cz[4] * xy + cz[5] * y2 + cz[6] * x3 + cz[7] * x2y
190 + cz[8] * xy2 + cz[9] * y3 + cz[10] * x4 + cz[11] * x3y + cz[12] * x2y2 + cz[13] * xy3 + cz[14] * y4
191 + cz[15] * x5 + cz[16] * x4y + cz[17] * x3y2 + cz[18] * x2y3 + cz[19] * xy4 + cz[20] * y5 + cz[21] * x6
192 + cz[22] * x5y + cz[23] * x4y2 + cz[24] * x3y3 + cz[25] * x2y4 + cz[26] * xy5 + cz[27] * y6 + cz[28] * x7
193 + cz[29] * x6y + cz[30] * x5y2 + cz[31] * x4y3 + cz[32] * x3y4 + cz[33] * x2y5 + cz[34] * xy6
194 + cz[35] * y7;
195#else
196#if LIT_POLYNOM_DEGREE == 9
197 T x2 = x * x;
198 T y2 = y * y;
199 T xy = x * y;
200
201 T x3 = x2 * x;
202 T y3 = y2 * y;
203 T xy2 = x * y2;
204 T x2y = x2 * y;
205
206 T x4 = x3 * x;
207 T y4 = y3 * y;
208 T xy3 = x * y3;
209 T x2y2 = x2 * y2;
210 T x3y = x3 * y;
211
212 T x5 = x4 * x;
213 T y5 = y4 * y;
214 T xy4 = x * y4;
215 T x2y3 = x2 * y3;
216 T x3y2 = x3 * y2;
217 T x4y = x4 * y;
218
219 T x6 = x5 * x;
220 T y6 = y5 * y;
221 T xy5 = x * y5;
222 T x2y4 = x2 * y4;
223 T x3y3 = x3 * y3;
224 T x4y2 = x4 * y2;
225 T x5y = x5 * y;
226
227 T x7 = x6 * x;
228 T y7 = y6 * y;
229 T xy6 = x * y6;
230 T x2y5 = x2 * y5;
231 T x3y4 = x3 * y4;
232 T x4y3 = x4 * y3;
233 T x5y2 = x5 * y2;
234 T x6y = x6 * y;
235
236 T x8 = x7 * x;
237 T y8 = y7 * y;
238 T xy7 = x * y7;
239 T x2y6 = x2 * y6;
240 T x3y5 = x3 * y5;
241 T x4y4 = x4 * y4;
242 T x5y3 = x5 * y3;
243 T x6y2 = x6 * y2;
244 T x7y = x7 * y;
245
246 T x9 = x8 * x;
247 T y9 = y8 * y;
248 T xy8 = x * y8;
249 T x2y7 = x2 * y7;
250 T x3y6 = x3 * y6;
251 T x4y5 = x4 * y5;
252 T x5y4 = x5 * y4;
253 T x6y3 = x6 * y3;
254 T x7y2 = x7 * y2;
255 T x8y = x8 * y;
256
257 B.Bx = cx[0] + cx[1] * x + cx[2] * y + cx[3] * x2 + cx[4] * xy + cx[5] * y2 + cx[6] * x3 + cx[7] * x2y
258 + cx[8] * xy2 + cx[9] * y3 + cx[10] * x4 + cx[11] * x3y + cx[12] * x2y2 + cx[13] * xy3 + cx[14] * y4
259 + cx[15] * x5 + cx[16] * x4y + cx[17] * x3y2 + cx[18] * x2y3 + cx[19] * xy4 + cx[20] * y5 + cx[21] * x6
260 + cx[22] * x5y + cx[23] * x4y2 + cx[24] * x3y3 + cx[25] * x2y4 + cx[26] * xy5 + cx[27] * y6 + cx[28] * x7
261 + cx[29] * x6y + cx[30] * x5y2 + cx[31] * x4y3 + cx[32] * x3y4 + cx[33] * x2y5 + cx[34] * xy6
262 + cx[35] * y7;
263 +cx[36] * x8 + cx[37] * x7y + cx[38] * x6y2 + cx[39] * x5y3 + cx[40] * x4y4 + cx[41] * x3y5 + cx[42] * x2y6
264 + cx[43] * xy7 + cx[44] * y8 + cx[45] * x9 + cx[46] * x8y + cx[47] * x7y2 + cx[48] * x6y3 + cx[49] * x5y4
265 + cx[50] * x4y5 + cx[51] * x3y6 + cx[52] * x2y7 + cx[53] * xy8 + cx[54] * y9;
266
267 B.By = cy[0] + cy[1] * x + cy[2] * y + cy[3] * x2 + cy[4] * xy + cy[5] * y2 + cy[6] * x3 + cy[7] * x2y
268 + cy[8] * xy2 + cy[9] * y3 + cy[10] * x4 + cy[11] * x3y + cy[12] * x2y2 + cy[13] * xy3 + cy[14] * y4
269 + cy[15] * x5 + cy[16] * x4y + cy[17] * x3y2 + cy[18] * x2y3 + cy[19] * xy4 + cy[20] * y5 + cy[21] * x6
270 + cy[22] * x5y + cy[23] * x4y2 + cy[24] * x3y3 + cy[25] * x2y4 + cy[26] * xy5 + cy[27] * y6 + cy[28] * x7
271 + cy[29] * x6y + cy[30] * x5y2 + cy[31] * x4y3 + cy[32] * x3y4 + cy[33] * x2y5 + cy[34] * xy6
272 + cy[35] * y7;
273 +cy[36] * x8 + cy[37] * x7y + cy[38] * x6y2 + cy[39] * x5y3 + cy[40] * x4y4 + cy[41] * x3y5 + cy[42] * x2y6
274 + cy[43] * xy7 + cy[44] * y8 + cy[45] * x9 + cy[46] * x8y + cy[47] * x7y2 + cy[48] * x6y3 + cy[49] * x5y4
275 + cy[50] * x4y5 + cy[51] * x3y6 + cy[52] * x2y7 + cy[53] * xy8 + cy[54] * y9;
276
277 B.Bz = cz[0] + cz[1] * x + cz[2] * y + cz[3] * x2 + cz[4] * xy + cz[5] * y2 + cz[6] * x3 + cz[7] * x2y
278 + cz[8] * xy2 + cz[9] * y3 + cz[10] * x4 + cz[11] * x3y + cz[12] * x2y2 + cz[13] * xy3 + cz[14] * y4
279 + cz[15] * x5 + cz[16] * x4y + cz[17] * x3y2 + cz[18] * x2y3 + cz[19] * xy4 + cz[20] * y5 + cz[21] * x6
280 + cz[22] * x5y + cz[23] * x4y2 + cz[24] * x3y3 + cz[25] * x2y4 + cz[26] * xy5 + cz[27] * y6 + cz[28] * x7
281 + cz[29] * x6y + cz[30] * x5y2 + cz[31] * x4y3 + cz[32] * x3y4 + cz[33] * x2y5 + cz[34] * xy6
282 + cz[35] * y7;
283 +cz[36] * x8 + cz[37] * x7y + cz[38] * x6y2 + cz[39] * x5y3 + cz[40] * x4y4 + cz[41] * x3y5 + cz[42] * x2y6
284 + cz[43] * xy7 + cz[44] * y8 + cz[45] * x9 + cz[46] * x8y + cz[47] * x7y2 + cz[48] * x6y3 + cz[49] * x5y4
285 + cz[50] * x4y5 + cz[51] * x3y6 + cz[52] * x2y7 + cz[53] * xy8 + cz[54] * y9;
286#endif
287#endif
288#endif
289#endif
290 }
291
299 void SetCoefficients(const std::vector<T>& x, const std::vector<T>& y, const std::vector<T>& z)
300 {
301 for (unsigned int i = 0; i < N; i++) {
302 cx[i] = x[i];
303 cy[i] = y[i];
304 cz[i] = z[i];
305 }
306 }
307
312 const T& GetZ() const { return fZ; }
313
318 void SetZ(const T& Z) { fZ = Z; }
319
324 std::string ToString() const
325 {
326 std::string str = "";
327 str = "LitFieldSlice: Z=" + lit::parallel::ToString<T>(fZ) + ", cx=";
328 for (unsigned int i = 0; i < N; i++) {
329 str += lit::parallel::ToString<T>(cx[i]) + " ";
330 }
331 str += "\n";
332 str += "LitFieldSlice: cy=";
333 for (unsigned int i = 0; i < N; i++) {
334 str += lit::parallel::ToString<T>(cy[i]) + " ";
335 }
336 str += "\n";
337 str += "LitFieldSlice: cz=";
338 for (unsigned int i = 0; i < N; i++) {
339 str += lit::parallel::ToString<T>(cz[i]) + " ";
340 }
341 str += "\n";
342 return str;
343 }
344
349 friend std::ostream& operator<<(std::ostream& strm, const LitFieldSlice& slice)
350 {
351 strm << slice.ToString();
352 return strm;
353 }
354
355 private:
356 T cx[N], cy[N], cz[N]; // polinom coefficients
357 T fZ; // Z position of the slice
359
365
371
372 } // namespace parallel
373} // namespace lit
374
375#endif /* LITFIELDSLICE_H_ */
Magnetic field value at a certain point in the space.
Approximated magnetic field slice in XY plane perpendicular to Z.
void SetZ(const T &Z)
Sets Z position of the slice.
friend std::ostream & operator<<(std::ostream &strm, const LitFieldSlice &slice)
Operator << for convenient output to std::ostream.
const T & GetZ() const
Returns Z position of the slice.
static const unsigned int N
std::string ToString() const
Returns std::string representation of the class.
void GetFieldValue(const T &x, const T &y, LitFieldValue< T > &B) const
Returns field value at a certain (X, Y) position.
void SetCoefficients(const std::vector< T > &x, const std::vector< T > &y, const std::vector< T > &z)
Sets polynom coefficients.
Magnetic field value at a certain point in the space.
class lit::parallel::LitDetectorLayout _fvecalignment
std::string ToString(const T &value)
Function converts object into a std::string.
Definition LitUtils.h:37
LitFieldSlice< fscal > LitFieldSliceScal
Scalar version of LitFieldSlice.
LitFieldSlice< fvec > LitFieldSliceVec
Vector version of LitFieldSlice.