CMS 3D CMS Logo

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