PandaRoot
L1Field.h
Go to the documentation of this file.
1 //****************************************************************************
2 //* This file is part of PandaRoot. *
3 //* *
4 //* PandaRoot is distributed under the terms of the *
5 //* GNU General Public License (GPL) version 3, *
6 //* copied verbatim in the file "LICENSE". *
7 //* *
8 //* Copyright (C) 2006 - 2024 FAIR GmbH and copyright holders of PandaRoot *
9 //* The copyright holders are listed in the file "COPYRIGHTHOLDERS". *
10 //* The authors are listed in the file "AUTHORS". *
11 //****************************************************************************
12 
13 #ifndef L1Field_h
14 #define L1Field_h 1
15 
16 #include "PndFTSCADef.h"
17 #include <iostream>
18 using std::cout;
19 using std::endl;
20 using std::ostream;
21 #include <vector>
22 using std::max;
23 using std::min;
24 using std::vector;
25 
26 #include "CAFieldValue.h"
27 
28 #if 0 // use lookUpTable rather than polinom aproximation
29 class L1FieldSlice{
30 
31  public:
32 
33  vector<float> bX, bY, bZ;
34  float xMin, yMin, dx, dy;
35  int nXBins, nYBins;
36 
37  void GetBBin( float x, float y, float &bX_, float &bY_, float &bZ_ ) const {
38  int iXBin = static_cast<int>((x - xMin)/dx);
39  int iYBin = static_cast<int>((y - yMin)/dy);
40  iXBin = min( iXBin, nXBins-1 );
41  iXBin = max( 0, iXBin );
42  iYBin = min( iYBin, nYBins-1 );
43  iYBin = max( 0, iYBin );
44  const int iBin = iXBin*nYBins + iYBin;
45  bX_ = bX[iBin];
46  bY_ = bY[iBin];
47  bZ_ = bZ[iBin];
48  };
49 
50  void AlocateMemory() {
51  const int NBins = nXBins*nYBins;
52  bX.resize(NBins);
53  bY.resize(NBins);
54  bZ.resize(NBins);
55  }
56 
57  L1FieldSlice(){};
58 
59  ~L1FieldSlice(){}
60 
61  void GetFieldValue( const float_v &x, const float_v &y, CAFieldValue &B, const float_m &mask = float_m(true) ) const
62  {
63  float bX_, bY_, bZ_;
64  foreach_bit( int iV, mask ) {
65  GetBBin( x[iV], y[iV], bX_, bY_, bZ_ );
66  B.x[iV] = bX_;
67  B.y[iV] = bY_;
68  B.z[iV] = bZ_;
69  }
70  }
71 };
72 
73 #else // 0
74 class L1FieldSlice {
75 
76  public:
77  float_v cx[21], cy[21], cz[21]; // polinom coeff.
78 
80  {
81  for (int i = 0; i < 21; i++)
82  cx[i] = cy[i] = cz[i] = Vc::Zero;
83  }
84 
85  void GetFieldValue(const float_v &x, const float_v &y, CAFieldValue &B, const float_m &mask = float_m(true)) const
86  {
87  float_v x2 = x * x;
88  float_v y2 = y * y;
89  float_v xy = x * y;
90 
91  float_v x3 = x2 * x;
92  float_v y3 = y2 * y;
93  float_v xy2 = x * y2;
94  float_v x2y = x2 * y;
95 
96  float_v x4 = x3 * x;
97  float_v y4 = y3 * y;
98  float_v xy3 = x * y3;
99  float_v x2y2 = x2 * y2;
100  float_v x3y = x3 * y;
101 
102  float_v x5 = x4 * x;
103  float_v y5 = y4 * y;
104  float_v xy4 = x * y4;
105  float_v x2y3 = x2 * y3;
106  float_v x3y2 = x3 * y2;
107  float_v x4y = x4 * y;
108 
109  B.x(mask) = cx[0] + cx[1] * x + cx[2] * y + cx[3] * x2 + cx[4] * xy + cx[5] * y2 + cx[6] * x3 + cx[7] * x2y + cx[8] * xy2 + cx[9] * y3 + cx[10] * x4 + cx[11] * x3y +
110  cx[12] * x2y2 + cx[13] * xy3 + cx[14] * y4 + cx[15] * x5 + cx[16] * x4y + cx[17] * x3y2 + cx[18] * x2y3 + cx[19] * xy4 + cx[20] * y5;
111 
112  B.y(mask) = cy[0] + cy[1] * x + cy[2] * y + cy[3] * x2 + cy[4] * xy + cy[5] * y2 + cy[6] * x3 + cy[7] * x2y + cy[8] * xy2 + cy[9] * y3 + cy[10] * x4 + cy[11] * x3y +
113  cy[12] * x2y2 + cy[13] * xy3 + cy[14] * y4 + cy[15] * x5 + cy[16] * x4y + cy[17] * x3y2 + cy[18] * x2y3 + cy[19] * xy4 + cy[20] * y5;
114 
115  B.z(mask) = cz[0] + cz[1] * x + cz[2] * y + cz[3] * x2 + cz[4] * xy + cz[5] * y2 + cz[6] * x3 + cz[7] * x2y + cz[8] * xy2 + cz[9] * y3 + cz[10] * x4 + cz[11] * x3y +
116  cz[12] * x2y2 + cz[13] * xy3 + cz[14] * y4 + cz[15] * x5 + cz[16] * x4y + cz[17] * x3y2 + cz[18] * x2y3 + cz[19] * xy4 + cz[20] * y5;
117  }
118 };
119 
120 #endif // 0
121 
123 
124  public:
125  L1FieldRegion() : cx0(Vc::Zero), cx1(Vc::Zero), cx2(Vc::Zero), cy0(Vc::Zero), cy1(Vc::Zero), cy2(Vc::Zero), cz0(Vc::Zero), cz1(Vc::Zero), cz2(Vc::Zero), z0(Vc::Zero) {}
126 
127  L1FieldRegion(float reg[10]) : cx0(reg[0]), cx1(reg[1]), cx2(reg[2]), cy0(reg[3]), cy1(reg[4]), cy2(reg[5]), cz0(reg[6]), cz1(reg[7]), cz2(reg[8]), z0(reg[9]) {}
128 
129  float_v cx0, cx1, cx2; // Bx(z) = cx0 + cx1*(z-z0) + cx2*(z-z0)^2
130  float_v cy0, cy1, cy2; // By(z) = cy0 + cy1*(z-z0) + cy2*(z-z0)^2
131  float_v cz0, cz1, cz2; // Bz(z) = cz0 + cz1*(z-z0) + cz2*(z-z0)^2
132  float_v z0;
133 
134  CAFieldValue Get(const float_v z)
135  {
136  float_v dz = (z - z0);
137  float_v dz2 = dz * dz;
138  CAFieldValue B;
139  B.x = cx0 + cx1 * dz + cx2 * dz2;
140  B.y = cy0 + cy1 * dz + cy2 * dz2;
141  B.z = cz0 + cz1 * dz + cz2 * dz2;
142  return B;
143  }
144 
145  void Set(const CAFieldValue &B0, const float_v B0z, const CAFieldValue &B1, const float_v B1z, const CAFieldValue &B2, const float_v B2z)
146  {
147  z0 = B0z;
148  float_v dz1 = B1z - B0z, dz2 = B2z - B0z;
149 
150  float_v deti = dz1 * dz2 * (dz2 - dz1);
151  float_m mask = abs(deti) > float_v(1.e-8f);
152 
153  float_v det = rcp(float_v(dz1 * dz2 * (dz2 - dz1)));
154  float_v w21 = -dz2 * det;
155  float_v w22 = dz1 * det;
156  float_v w11 = -dz2 * w21;
157  float_v w12 = -dz1 * w22;
158 
159  float_v dB1 = B1.x - B0.x;
160  float_v dB2 = B2.x - B0.x;
161  cx0(mask) = B0.x;
162  cx1(mask) = dB1 * w11 + dB2 * w12;
163  cx2(mask) = dB1 * w21 + dB2 * w22;
164 
165  dB1 = B1.y - B0.y;
166  dB2 = B2.y - B0.y;
167  cy0(mask) = B0.y;
168  cy1(mask) = dB1 * w11 + dB2 * w12;
169  cy2(mask) = dB1 * w21 + dB2 * w22;
170 
171  dB1 = B1.z - B0.z;
172  dB2 = B2.z - B0.z;
173  cz0(mask) = B0.z;
174  cz1(mask) = dB1 * w11 + dB2 * w12;
175  cz2(mask) = dB1 * w21 + dB2 * w22;
176  }
177 
178  void Set(const CAFieldValue &B0, const float_v B0z, const CAFieldValue &B1, const float_v B1z)
179  {
180  z0 = B0z[0];
181  float_v dzi = rcp(float_v(B1z - B0z));
182  cx0 = B0.x;
183  cy0 = B0.y;
184  cz0 = B0.z;
185  cx1 = (B1.x - B0.x) * dzi;
186  cy1 = (B1.y - B0.y) * dzi;
187  cz1 = (B1.z - B0.z) * dzi;
188  cx2 = cy2 = cz2 = 0;
189  }
190 
191  void Shift(float_v z)
192  {
193  float_v dz = z - z0;
194  float_v cx2dz = cx2 * dz;
195  float_v cy2dz = cy2 * dz;
196  float_v cz2dz = cz2 * dz;
197  z0 = float_v(z[0]);
198  cx0 += (cx1 + cx2dz) * dz;
199  cy0 += (cy1 + cy2dz) * dz;
200  cz0 += (cz1 + cz2dz) * dz;
201  cx1 += cx2dz + cx2dz;
202  cy1 += cy2dz + cy2dz;
203  cz1 += cz2dz + cz2dz;
204  }
205 
206  void SetOneEntry(const int i0, const L1FieldRegion &f1, const int i1)
207  {
208  cx0[i0] = f1.cx0[i1];
209  cx1[i0] = f1.cx1[i1];
210  cx2[i0] = f1.cx2[i1];
211  cy0[i0] = f1.cy0[i1];
212  cy1[i0] = f1.cy1[i1];
213  cy2[i0] = f1.cy2[i1];
214  cz0[i0] = f1.cz0[i1];
215  cz1[i0] = f1.cz1[i1];
216  cz2[i0] = f1.cz2[i1];
217  z0[i0] = f1.z0[i1];
218  }
219 
220  void SetOneEntry(const L1FieldRegion &f1, const int i1)
221  {
222  cx0 = f1.cx0[i1];
223  cx1 = f1.cx1[i1];
224  cx2 = f1.cx2[i1];
225  cy0 = f1.cy0[i1];
226  cy1 = f1.cy1[i1];
227  cy2 = f1.cy2[i1];
228  cz0 = f1.cz0[i1];
229  cz1 = f1.cz1[i1];
230  cz2 = f1.cz2[i1];
231  z0 = f1.z0[i1];
232  }
233 
234  void GetOneEntry(float reg[10], const int iVec)
235  {
236  reg[0] = cx0[iVec];
237  reg[1] = cx1[iVec];
238  reg[2] = cx2[iVec];
239  reg[3] = cy0[iVec];
240  reg[4] = cy1[iVec];
241  reg[5] = cy2[iVec];
242  reg[6] = cz0[iVec];
243  reg[7] = cz1[iVec];
244  reg[8] = cz2[iVec];
245  reg[9] = z0[iVec];
246  }
247 
248  friend ostream &operator<<(ostream &out, L1FieldRegion &B)
249  {
250  return out << " FieldRegion " << endl
251  << B.cx0 << endl
252  << B.cx1 << endl
253  << B.cx2 << endl
254  << B.cy0 << endl
255  << B.cy1 << endl
256  << B.cy2 << endl
257  << B.cz0 << endl
258  << B.cz1 << endl
259  << B.cz2 << endl
260  << B.z0 << endl;
261  };
262 };
263 
264 #endif
float_v cy1
Definition: L1Field.h:130
float_v cz1
Definition: L1Field.h:131
float_v cz2
Definition: L1Field.h:131
float_v cx1
Definition: L1Field.h:129
void Set(const CAFieldValue &B0, const float_v B0z, const CAFieldValue &B1, const float_v B1z)
Definition: L1Field.h:178
friend F32vec4 max(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:37
friend ostream & operator<<(ostream &out, L1FieldRegion &B)
Definition: L1Field.h:248
unsigned int i
Definition: P4_F32vec4.h:33
T rcp(T val)
Definition: PndFTSCADef.h:67
L1FieldSlice()
Definition: L1Field.h:79
void GetOneEntry(float reg[10], const int iVec)
Definition: L1Field.h:234
L1FieldRegion(float reg[10])
Definition: L1Field.h:127
float_v cx0
Definition: L1Field.h:129
friend F32vec4 min(const F32vec4 &a, const F32vec4 &b)
Definition: P4_F32vec4.h:36
float_v cy[21]
Definition: L1Field.h:77
float_v cy0
Definition: L1Field.h:130
float_v cz[21]
Definition: L1Field.h:77
float_v cy2
Definition: L1Field.h:130
float f
Definition: P4_F32vec4.h:32
float_v cz0
Definition: L1Field.h:131
void Set(const CAFieldValue &B0, const float_v B0z, const CAFieldValue &B1, const float_v B1z, const CAFieldValue &B2, const float_v B2z)
Definition: L1Field.h:145
float_v cx[21]
Definition: L1Field.h:77
basic_ostream< char, char_traits< char > > ostream
void Shift(float_v z)
Definition: L1Field.h:191
float_v cx2
Definition: L1Field.h:129
float_v z0
Definition: L1Field.h:132
void SetOneEntry(const L1FieldRegion &f1, const int i1)
Definition: L1Field.h:220
void GetFieldValue(const float_v &x, const float_v &y, CAFieldValue &B, const float_m &mask=float_m(true)) const
Definition: L1Field.h:85
CAFieldValue Get(const float_v z)
Definition: L1Field.h:134
void SetOneEntry(const int i0, const L1FieldRegion &f1, const int i1)
Definition: L1Field.h:206