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