CMS 3D CMS Logo

BCyl.h
Go to the documentation of this file.
1 #ifndef ParametrizedEngine_BCyl_h
2 #define ParametrizedEngine_BCyl_h
3 
19 #include <cmath>
20 
22 
23 namespace magfieldparam {
24  template <typename T>
25  struct BCylParam {
26  // constexpr BCylParam(std::initializer_list<T> init) :
27  template <typename... Args>
28  constexpr BCylParam(Args... init)
29  : prm{std::forward<Args>(init)...},
30  //prm(std::forward<Args>(init)...),
31  ap2(4 * prm[0] * prm[0] / (prm[1] * prm[1])),
32  hb0(0.5 * prm[2] * std::sqrt(1.0 + ap2)),
33  hlova(1 / std::sqrt(ap2)),
34  ainv(2 * hlova / prm[1]),
35  coeff(1 / (prm[8] * prm[8])) {}
36 
37  T prm[9];
39  };
40 
41  namespace bcylDetails {
42 
43  template <typename T>
44  inline void ffunkti(T u, T* __restrict__ ff) __attribute__((always_inline));
45 
46  template <typename T>
47  inline void ffunkti(T u, T* __restrict__ ff) {
48  // Function and its 3 derivatives
49  T a, b, a2, u2;
50  u2 = u * u;
51  a = T(1) / (T(1) + u2);
52  a2 = -T(3) * a * a;
53  b = std::sqrt(a);
54  ff[0] = u * b;
55  ff[1] = a * b;
56  ff[2] = a2 * ff[0];
57  ff[3] = a2 * ff[1] * (T(1) - 4 * u2);
58  }
59 
60  inline double myExp(double x) { return std::exp(x); }
61  inline float myExp(float x) { return unsafe_expf<3>(x); }
62 
63  } // namespace bcylDetails
64 
65  template <typename T>
66  class BCycl {
67  public:
68  BCycl(BCylParam<T> const& ipar) : pars(ipar) {}
69 
70  void operator()(T r2, T z, T& Br, T& Bz) const { compute(r2, z, Br, Bz); }
71 
72  // in meters and T (Br needs to be multiplied by r)
73  void compute(T r2, T z, T& Br, T& Bz) const {
74  using namespace bcylDetails;
75  // if (r<1.15&&fabs(z)<2.8) // NOTE: check omitted, is done already by the wrapper! (NA)
76  z -= pars.prm[3]; // max Bz point is shifted in z
77  T az = std::abs(z);
78  T zainv = z * pars.ainv;
79  T u = pars.hlova - zainv;
80  T v = pars.hlova + zainv;
81  T fu[4], gv[4];
82  ffunkti(u, fu);
83  ffunkti(v, gv);
84  T rat = T(0.5) * pars.ainv;
85  T rat2 = rat * rat * r2;
86  Br = pars.hb0 * rat * (fu[1] - gv[1] - (fu[3] - gv[3]) * rat2 * T(0.5));
87  Bz = pars.hb0 * (fu[0] + gv[0] - (fu[2] + gv[2]) * rat2);
88 
89  T corBr = pars.prm[4] * z * (az - pars.prm[5]) * (az - pars.prm[5]);
90  T corBz = -pars.prm[6] * (myExp(-(z - pars.prm[7]) * (z - pars.prm[7]) * pars.coeff) +
91  myExp(-(z + pars.prm[7]) * (z + pars.prm[7]) * pars.coeff)); // double Gaussian
92  Br += corBr;
93  Bz += corBz;
94  }
95 
96  private:
98  };
99 } // namespace magfieldparam
100 
101 #endif
magfieldparam::BCylParam::BCylParam
constexpr BCylParam(Args... init)
Definition: BCyl.h:28
__attribute__
float __attribute__((vector_size(8))) cms_float32x2_t
Definition: ExtVec.h:12
findQualityFiles.v
v
Definition: findQualityFiles.py:179
testProducerWithPsetDescEmpty_cfi.a2
a2
Definition: testProducerWithPsetDescEmpty_cfi.py:35
magfieldparam::BCycl::BCycl
BCycl(BCylParam< T > const &ipar)
Definition: BCyl.h:68
alignCSCRings.ff
ff
Definition: alignCSCRings.py:148
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
b
double b
Definition: hdecay.h:118
magfieldparam
Definition: BCyl.h:23
magfieldparam::bcylDetails::myExp
float myExp(float x)
Definition: BCyl.h:61
magfieldparam::BCylParam::ap2
T ap2
Definition: BCyl.h:38
magfieldparam::BCylParam::hb0
T hb0
Definition: BCyl.h:38
a
double a
Definition: hdecay.h:119
diffTwoXMLs.r2
r2
Definition: diffTwoXMLs.py:73
magfieldparam::BCycl::operator()
void operator()(T r2, T z, T &Br, T &Bz) const
Definition: BCyl.h:70
magfieldparam::BCylParam::coeff
T coeff
Definition: BCyl.h:38
magfieldparam::BCylParam
Definition: BCyl.h:25
init
Definition: init.py:1
magfieldparam::BCylParam::prm
T prm[9]
Definition: BCyl.h:37
T
long double T
Definition: Basic3DVectorLD.h:48
magfieldparam::BCylParam::hlova
T hlova
Definition: BCyl.h:38
magfieldparam::BCycl
Definition: BCyl.h:66
magfieldparam::BCylParam::ainv
T ainv
Definition: BCyl.h:38
magfieldparam::bcylDetails::myExp
double myExp(double x)
Definition: BCyl.h:60
magfieldparam::BCycl::pars
BCylParam< T > pars
Definition: BCyl.h:97
magfieldparam::BCycl::compute
void compute(T r2, T z, T &Br, T &Bz) const
Definition: BCyl.h:73
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
magfieldparam::bcylDetails::ffunkti
void ffunkti(T u, T *__restrict__ ff) __attribute__((always_inline))
Definition: BCyl.h:47
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
approx_exp.h
MetAnalyzer.u2
u2
Definition: MetAnalyzer.py:61