ATLAS Offline Software
BFieldCacheZR.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <cmath>
7 
8 void
10  double r,
11  double* ATH_RESTRICT B,
12  double* ATH_RESTRICT deriv) const
13 {
14  const double x = xyz[0];
15  const double y = xyz[1];
16  const double z = xyz[2];
17  // fractional position inside this bin
18  const double fz = (z - m_zmin) * m_invz;
19  const double gz = 1.0 - fz;
20  const double fr = (r - m_rmin) * m_invr;
21  const double gr = 1.0 - fr;
22  // interpolate field values in z, r
23  double Bzr[2];
24  for (int i = 0; i < 2; ++i) { // z, r components
25  const double* field = m_field[i];
26  Bzr[i] = gz * (gr * field[0] + fr * field[1]) +
27  fz * (gr * field[2] + fr * field[3]);
28  }
29  // convert (Bz,Br) to (Bx,By,Bz)
30  double invr;
31  if (r > 0.0) {
32  invr = 1.0 / r;
33  } else {
34  invr = 0.0;
35  }
36  const double c(x * invr);
37  const double s(y * invr);
38  B[0] = Bzr[1] * c;
39  B[1] = Bzr[1] * s;
40  B[2] = Bzr[0];
41 
42  // compute field derivatives if requested
43  if (deriv) {
44  std::array<double, 2> dBdz{};
45  std::array<double, 2> dBdr{};
46  for (int j = 0; j < 2; ++j) { // Bz, Br components
47  const double* field = m_field[j];
48  dBdz[j] =
49  m_invz * (gr * (field[2] - field[0]) + fr * (field[3] - field[1]));
50  dBdr[j] =
51  m_invr * (gz * (field[1] - field[0]) + fz * (field[3] - field[2]));
52  }
53  // convert to cartesian coordinates
54  const double cc = c * c;
55  const double cs = c * s;
56  const double ss = s * s;
57  const double sinvr = s * invr;
58  const double cinvr = c * invr;
59  deriv[0] = cc * dBdr[1] + sinvr * B[1];
60  deriv[1] = cs * dBdr[1] - cinvr * B[1];
61  deriv[2] = c * dBdz[1];
62  deriv[3] = cs * dBdr[1] - sinvr * B[0];
63  deriv[4] = ss * dBdr[1] + cinvr * B[0];
64  deriv[5] = s * dBdz[1];
65  deriv[6] = c * dBdr[0];
66  deriv[7] = s * dBdr[0];
67  deriv[8] = dBdz[0];
68  }
69 }
70 
beamspotman.r
def r
Definition: beamspotman.py:676
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
BFieldCacheZR::m_field
double m_field[2][4]
Definition: BFieldCacheZR.h:45
xyz
#define xyz
gr
#define gr
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
x
#define x
ATH_RESTRICT
#define ATH_RESTRICT
Definition: restrict.h:31
BFieldCacheZR::m_zmin
double m_zmin
Definition: BFieldCacheZR.h:42
BFieldCacheZR.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
z
#define z
BFieldCacheZR::m_invr
double m_invr
Definition: BFieldCacheZR.h:44
BFieldCacheZR::getB
void getB(const double *ATH_RESTRICT xyz, double r, double *ATH_RESTRICT B, double *ATH_RESTRICT deriv=nullptr) const
Definition: BFieldCacheZR.cxx:9
dqt_zlumi_alleff_HIST.B
B
Definition: dqt_zlumi_alleff_HIST.py:110
BFieldCacheZR::m_invz
double m_invz
Definition: BFieldCacheZR.h:44
y
#define y
BFieldCacheZR::m_rmin
double m_rmin
Definition: BFieldCacheZR.h:43
grepfile.fr
fr
Definition: grepfile.py:32
python.compressB64.c
def c
Definition: compressB64.py:93
python.handimod.cc
int cc
Definition: handimod.py:523