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