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