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  };
42 
43  namespace bcylDetails{
44 
45  template<typename T>
46  inline void ffunkti(T u, T * __restrict__ ff) __attribute__((always_inline));
47 
48  template<typename T>
49  inline void ffunkti(T u, T * __restrict__ ff) {
50  // Function and its 3 derivatives
51  T a,b,a2,u2;
52  u2=u*u;
53  a=T(1)/(T(1)+u2);
54  a2=-T(3)*a*a;
55  b=std::sqrt(a);
56  ff[0]=u*b;
57  ff[1]=a*b;
58  ff[2]=a2*ff[0];
59  ff[3]=a2*ff[1]*(T(1)-4*u2);
60  }
61 
62  inline double myExp(double x) { return std::exp(x);}
63  inline float myExp(float x) { return unsafe_expf<3>(x);}
64 
65  }
66 
67 
68  template<typename T>
69  class BCycl {
70  public:
71  BCycl(BCylParam<T> const & ipar) : pars(ipar) {}
72 
73  void operator()(T r2, T z, T& Br, T& Bz) const {
74  compute(r2,z,Br,Bz);
75  }
76 
77 
78  // in meters and T (Br needs to be multiplied by r)
79  void compute(T r2, T z, T& Br, T& Bz) const {
80  using namespace bcylDetails;
81  // if (r<1.15&&fabs(z)<2.8) // NOTE: check omitted, is done already by the wrapper! (NA)
82  z-=pars.prm[3]; // max Bz point is shifted in z
83  T az=std::abs(z);
84  T zainv=z*pars.ainv;
85  T u=pars.hlova-zainv;
86  T v=pars.hlova+zainv;
87  T fu[4],gv[4];
88  ffunkti(u,fu);
89  ffunkti(v,gv);
90  T rat=T(0.5)*pars.ainv;
91  T rat2=rat*rat*r2;
92  Br=pars.hb0*rat*(fu[1]-gv[1]-(fu[3]-gv[3])*rat2*T(0.5));
93  Bz=pars.hb0*(fu[0]+gv[0]-(fu[2]+gv[2])*rat2);
94 
95  T corBr= pars.prm[4]*z*(az-pars.prm[5])*(az-pars.prm[5]);
96  T corBz=-pars.prm[6]*(
97  myExp(-(z-pars.prm[7])*(z-pars.prm[7])*pars.coeff) +
98  myExp(-(z+pars.prm[7])*(z+pars.prm[7])*pars.coeff)
99  ); // double Gaussian
100  Br+=corBr;
101  Bz+=corBz;
102  }
103 
104  private:
106 
107  };
108 }
109 
110 #endif
int init
Definition: HydjetWrapper.h:67
float __attribute__((vector_size(8))) cms_float32x2_t
Definition: ExtVec.h:12
constexpr BCylParam(Args...init)
Definition: BCyl.h:28
void operator()(T r2, T z, T &Br, T &Bz) const
Definition: BCyl.h:73
#define constexpr
float myExp(float x)
Definition: BCyl.h:63
BCylParam< T > pars
Definition: BCyl.h:105
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void compute(T r2, T z, T &Br, T &Bz) const
Definition: BCyl.h:79
void ffunkti(T u, T *__restrict__ ff) __attribute__((always_inline))
Definition: BCyl.h:49
Definition: init.py:1
def compute(min, max)
double b
Definition: hdecay.h:120
double a
Definition: hdecay.h:121
BCycl(BCylParam< T > const &ipar)
Definition: BCyl.h:71
long double T