CMS 3D CMS Logo

BFit3D.cc
Go to the documentation of this file.
1 #include <cmath>
2 #ifndef M_PI
3 #define M_PI 3.1415926535897932385
4 #endif
5 
6 #include "BFit3D_data.h"
7 
8 using namespace magfieldparam;
9 
10 //_______________________________________________________________________________
11 void BFit3D::SetCoeff_Linear(const double B) {
12  unsigned jj, kk = 1;
13  double w_0, w_1, B_mod = fabs(B);
14  if (B_mod <= B_nom[0]) {
15  w_0 = B / B_nom[0];
16  for (jj = 0; jj < 360; ++jj) {
17  C[jj] = w_0 * C0[jj][0];
18  }
19  } else if (B_mod >= B_nom[3]) {
20  w_0 = B / B_nom[3];
21  for (jj = 0; jj < 360; ++jj) {
22  C[jj] = w_0 * C0[jj][3];
23  }
24  } else {
25  while (B_nom[kk] < B_mod)
26  ++kk; //Simple linear search
27  w_1 = (B_mod - B_nom[kk - 1]) / (B_nom[kk] - B_nom[kk - 1]);
28  w_0 = 1.0 - w_1;
29  if (B < 0.) {
30  w_0 = -w_0;
31  w_1 = -w_1;
32  }
33  for (jj = 0; jj < 360; ++jj) {
34  C[jj] = w_0 * C0[jj][kk - 1] + w_1 * C0[jj][kk];
35  }
36  }
37 }
38 
39 //_______________________________________________________________________________
40 void BFit3D::SetCoeff_Spline(const double B) {
41  int jc, k0 = 0, k1 = 1;
42  double dB2, dB = fabs(B);
43  if (dB >= B_nom[3]) { //Linear extrapolation for a large field
44  dB -= B_nom[3];
45  for (jc = 0; jc < 360; ++jc)
46  C[jc] = C0[jc][3] + C1[jc][4] * dB;
47  } else {
48  if (dB < B_nom[0]) {
49  dB2 = dB * dB / (3. * B_nom[0]);
50  for (jc = 0; jc < 360; ++jc)
51  C[jc] = (C2[jc][0] * dB2 + C1[jc][0]) * dB;
52  } else {
53  while (B_nom[k1] < dB)
54  ++k1; //Simple linear search
55  k0 = k1 - 1;
56  dB2 = (dB -= B_nom[k0]) / (3. * (B_nom[k1] - B_nom[k0]));
57  if (k1 < 3) { //"Regular" interval
58  for (jc = 0; jc < 360; ++jc)
59  C[jc] = (((C2[jc][k1] - C2[jc][k0]) * dB2 + C2[jc][k0]) * dB + C1[jc][k1]) * dB + C0[jc][k0];
60  } else { //The last interval
61  dB2 = (1. - dB2) * dB;
62  for (jc = 0; jc < 360; ++jc)
63  C[jc] = (C2[jc][k0] * dB2 + C1[jc][k1]) * dB + C0[jc][k0];
64  }
65  }
66  }
67  if (B < 0)
68  for (jc = 0; jc < 360; ++jc)
69  C[jc] = -C[jc];
70 }
71 
72 //_______________________________________________________________________________
73 void BFit3D::GetField(const double r, const double z, const double phi, double &Br, double &Bz, double &Bphi) {
74  //Return field components in Br, Bz, Bphi. SetField must be called before use.
75  //
76  if (signed_rad || (r >= 0.))
77  HB->SetPoint(r, z, phi);
78  else
79  HB->SetPoint(-r, z, phi + M_PI);
80  HB->EvalBr();
81  HB->EvalBz();
82  HB->EvalBphi();
83  Br = HB->GetBr(C);
84  Bz = HB->GetBz(C);
85  Bphi = HB->GetBphi(C);
86 }
87 
89 // //
90 // T E S T A R E A //
91 // //
magfieldparam::BFit3D::C2
static const double C2[360][3]
Definition: BFit3D.h:15
magfieldparam::BFit3D::C0
static const double C0[360][4]
Definition: BFit3D.h:13
magfieldparam::BFit3D::HB
HarmBasis3DCyl * HB
Definition: BFit3D.h:23
reco::ParticleMasses::k0
const double k0
Definition: ParticleMasses.h:7
magfieldparam::HarmBasis3DCyl::GetBz
double GetBz(double *coeff)
Definition: HarmBasis3DCyl.h:68
magfieldparam::HarmBasis3DCyl::EvalBphi
void EvalBphi()
Definition: HarmBasis3DCyl.cc:107
GetRecoTauVFromDQM_MC_cff.kk
kk
Definition: GetRecoTauVFromDQM_MC_cff.py:84
magfieldparam
Definition: BCyl.h:23
magfieldparam::BFit3D::SetCoeff_Spline
void SetCoeff_Spline(const double B)
Definition: BFit3D.cc:40
magfieldparam::BFit3D::GetField
void GetField(const double r, const double z, const double phi, double &Br, double &Bz, double &Bphi)
Definition: BFit3D.cc:73
M_PI
#define M_PI
Definition: BFit3D.cc:3
magfieldparam::BFit3D::C1
static const double C1[360][5]
Definition: BFit3D.h:14
magfieldparam::HarmBasis3DCyl::EvalBr
void EvalBr()
Definition: HarmBasis3DCyl.h:52
alignCSCRings.r
r
Definition: alignCSCRings.py:93
TtFullHadDaughter::B
static const std::string B
Definition: TtFullHadronicEvent.h:9
magfieldparam::HarmBasis3DCyl::SetPoint
void SetPoint(const double r, const double z, const double phi)
Definition: HarmBasis3DCyl.h:47
magfieldparam::HarmBasis3DCyl::GetBphi
double GetBphi(double *coeff)
Definition: HarmBasis3DCyl.h:69
magfieldparam::BFit3D::signed_rad
bool signed_rad
Definition: BFit3D.h:20
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
magfieldparam::BFit3D::B_nom
static const double B_nom[4]
Definition: BFit3D.h:12
magfieldparam::BFit3D::SetCoeff_Linear
void SetCoeff_Linear(const double B)
Definition: BFit3D.cc:11
BFit3D_data.h
magfieldparam::BFit3D::C
double C[360]
Definition: BFit3D.h:17
magfieldparam::HarmBasis3DCyl::EvalBz
void EvalBz()
Definition: HarmBasis3DCyl.h:53
magfieldparam::HarmBasis3DCyl::GetBr
double GetBr(double *coeff)
Definition: HarmBasis3DCyl.h:67