test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BFit.cc
Go to the documentation of this file.
1 #include "BFit.h"
2 #include <cstring>
3 
4 using namespace std;
5 using namespace magfieldparam;
6 
7 //_______________________________________________________________________________
8 
9 
10 #ifdef BFit_PW
11 const double BFit::Z_nom[4] = { -2.37615687260664e-2,
12  -1.86400109250045e-2,
13  -1.80502358070104e-2,
14  -1.60470955291956e-2 };
15 
16 const double BFit::B_nom[4] = { 2.02156567013928, //Nominal foeld values
17  3.51622117206486,
18  3.81143026675623,
19  4.01242188708911 };
20 
21 const double BFit::C_nom[4][16] = {{ 1.0, -3.61278802720839e-3,
22  6.36561393690475e-6, 8.32541914664693e-5,
23  -2.42108313492765e-6, -1.87295909297299e-5,
24  3.06832709074461e-7, 1.91827319271226e-6,
25  -2.15392717311725e-8, -1.25266203359502e-7,
26  3.87507522135914e-10, 4.85518568040635e-9,
27  4.42080729840719e-11, -8.83065447433858e-11,
28  -2.41380148377896e-12, 0.0 },
29  { 1.0, -5.04020236643808e-3,
30  2.03224205921125e-6, 6.79444854179620e-5,
31  -1.98082200052911e-6, -1.93324798138490e-5,
32  3.15120940544812e-7, 1.82623212354924e-6,
33  -3.30483297560429e-8, -1.13251951654739e-7,
34  1.96974144659278e-9, 4.25153392971594e-9,
35  -6.12986034064675e-11, -7.59031334826116e-11,
36  6.40295019219590e-13, 0.0 },
37  { 1.0, -5.23012318846739e-3,
38  8.80302231241395e-7, 6.51341641212249e-5,
39  -1.68564063895995e-6, -1.93693613146655e-5,
40  2.58178734098114e-7, 1.81311192824207e-6,
41  -2.79301520182866e-8, -1.11679980224632e-7,
42  1.72615649164433e-9, 4.17328869038146e-9,
43  -5.72514160410955e-11, -7.41998111228714e-11,
44  7.30938527053447e-13, 0.0 },
45  { 1.0, -5.34172971309074e-3,
46  2.48943649506081e-7, 6.23054033447814e-5,
47  -1.60390978074464e-6, -1.92618217244767e-5,
48  2.42461261622770e-7, 1.78772142159379e-6,
49  -2.61432416866515e-8, -1.09159464672341e-7,
50  1.62705377496138e-9, 4.02967933726133e-9,
51  -5.48168162195020e-11, -7.00249566028285e-11,
52  8.22254619144001e-13, 0.0 }};
53 #else
54 const double BFit::dZ_0 = -2.62328760352034e-2;
55 const double BFit::dZ_2 = 5.94363870284212e-4;
56 
57 const double BFit::C_0[16] = { 1.0, -2.52864632909442e-3,
58  8.76365790071351e-6, 9.19077286315044e-5,
59  -2.49284256023752e-6, -1.80143891826520e-5,
60  2.29295162454016e-7, 1.96139195659245e-6,
61  -3.47342625923464e-9, -1.32147627969588e-7,
62  -1.50735830442900e-9, 5.17724172101696e-9,
63  1.54539960459831e-10, -9.30914368388717e-11,
64  -5.20466591966397e-12, 0.0 };
65 
66 const double BFit::C_2[16] = { 0.0, -2.96314154618866e-4,
67  -6.04246295125223e-7, -2.22393436573694e-6,
68  2.84133631738674e-9, -2.07090716476209e-7,
69  2.55850963123821e-8, -1.06689136150163e-8,
70  -5.48842256680751e-9, 1.78987539969165e-9,
71  5.57809366992069e-10, -8.25055601520632e-11,
72  -3.18509299957904e-11, 1.11714602344300e-12,
73  7.90102331886296e-13, 0.0 };
74 
75 const double BFit::C_4[16] = { 0.0, 7.57194953855834e-6,
76  4.48169046115052e-9, 2.49606093449927e-8,
77  3.42264285146368e-9, 7.95338846845187e-9,
78  -1.57711106312732e-9, 1.02715424120585e-11,
79  2.57261485255293e-10, -2.41682937761163e-11,
80  -2.27894837943020e-11, 7.98570801347331e-13,
81  1.17889573705870e-12, 1.64571374852252e-14,
82  -2.60212133934707e-14, 0.0 };
83 #endif
84 //_______________________________________________________________________________
85 BFit::BFit()
86 {
87  dZ = 0.;
88  memset(C, 0, 16*sizeof(double));
89  rz_poly *P_base = new rz_poly(16); //Potential basis
90 
91  Bz_base = new rz_poly(P_base->Diff(1)); //Bz basis
92  Bz_base->SetOFF(1); //Switch off linear term
93 
94  Br_base = new rz_poly(P_base->Diff(0)); //Br basis is shifted, so
95  Br_base->SetOFF(0); //"0" term is ignored
96 
97  delete P_base;
98 }
99 
100 //_______________________________________________________________________________
101 void BFit::SetField(double B)
102 {
103 //Set nominal field [Tesla]
104 //
105  unsigned int jj;
106 
107 #ifdef BFit_PW
108  unsigned int kk = 1;
109  double w_0, w_1;
110  if (B <= B_nom[0]) {
111  dZ = Z_nom[0];
112  for (jj = 0; jj < 16; ++jj) {
113  C[jj] = B*C_nom[0][jj];
114  }
115  } else if (B >= B_nom[3]) {
116  dZ = Z_nom[3];
117  for (jj = 0; jj < 16; ++jj) {
118  C[jj] = B*C_nom[3][jj];
119  }
120  } else {
121  while (B_nom[kk] < B) ++kk;
122  w_1 = (B - B_nom[kk-1])/(B_nom[kk] - B_nom[kk-1]);
123  w_0 = 1.0 - w_1;
124  dZ = Z_nom[kk-1]*w_0 + Z_nom[kk]*w_1;
125  for (jj = 0; jj < 16; ++jj) {
126  C[jj] = B*(C_nom[kk-1][jj]*w_0 + C_nom[kk][jj]*w_1);
127  }
128  }
129 #else
130  double B2 = B*B;
131  dZ = dZ_0 + dZ_2*B2;
132  for (jj = 0; jj < 16; ++jj) {
133  C[jj] = B*((C_4[jj]*B2 + C_2[jj])*B2 + C_0[jj]);
134  }
135 #endif
136 }
137 
138 //_______________________________________________________________________________
139 void BFit::GetField(double r, double z, double phi,
140  double &Br, double &Bz, double &Bphi) const
141 {
142 //Get field components in the point (r,z,phi). Always return Bphi=0.
143 //Parameters phi and Bphi introduced in order to keep interface
144 //compatible with future trully 3D version
145 //
146  double zc = z + dZ;
147 
148  Bz = Bz_base->GetSVal(r, zc, C);
149  Br = Br_base->GetSVal(r, zc, C+1);
150  Bphi = 0.;
151 }
double_binary B
Definition: DDStreamer.cc:248
void SetOFF(int npoly)
Definition: rz_poly.cc:88
rz_poly Diff(int nvar, bool keep_empty=false)
Definition: rz_poly.cc:128