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>
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
int init
Definition: HydjetWrapper.h:66
void operator()(T r2, T z, T &Br, T &Bz) const
Definition: BCyl.h:70
float myExp(float x)
Definition: BCyl.h:61
constexpr BCylParam(Args... init)
Definition: BCyl.h:28
void compute(T r2, T z, T &Br, T &Bz) const
Definition: BCyl.h:73
BCylParam< T > pars
Definition: BCyl.h:97
T sqrt(T t)
Definition: SSEVec.h:23
float __attribute__((vector_size(8))) cms_float32x2_t
Definition: ExtVec.h:8
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void ffunkti(T u, T *__restrict__ ff) __attribute__((always_inline))
Definition: BCyl.h:47
Definition: init.py:1
double myExp(double x)
Definition: BCyl.h:60
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
BCycl(BCylParam< T > const &ipar)
Definition: BCyl.h:68
float x
long double T