CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TkBfield.cc
Go to the documentation of this file.
2 
4 
5 // #include <iostream>
6 // #include <iomanip>
7 #include <cmath>
9 
10 using namespace magfieldparam;
11 
12 
13 TkBfield::TkBfield(std::string fld) {
14  double p1[]={4.90541,17.8768,2.02355,0.0210538,0.000321885,2.37511,0.00326725,2.07656,1.71879}; // 2.0T-2G
15  double p2[]={4.41982,15.7732,3.02621,0.0197814,0.000515759,2.43385,0.00584258,2.11333,1.76079}; // 3.0T-2G
16  double p3[]={4.30161,15.2586,3.51926,0.0183494,0.000606773,2.45110,0.00709986,2.12161,1.77038}; // 3.5T-2G
17  double p4[]={4.24326,15.0201,3.81492,0.0178712,0.000656527,2.45818,0.00778695,2.12500,1.77436}; // 3.8T-2G
18  double p5[]={4.21136,14.8824,4.01683,0.0175932,0.000695541,2.45311,0.00813447,2.11688,1.76076}; // 4.0T-2G
19  prm[0]=0;
20  if (fld=="2_0T") for (int i=0; i<9; i++) prm[i]=p1[i];
21  if (fld=="3_0T") for (int i=0; i<9; i++) prm[i]=p2[i];
22  if (fld=="3_5T") for (int i=0; i<9; i++) prm[i]=p3[i];
23  if (fld=="3_8T") for (int i=0; i<9; i++) prm[i]=p4[i];
24  if (fld=="4_0T") for (int i=0; i<9; i++) prm[i]=p5[i];
25  // cout<<std::endl<<"Instantiation of TkBfield with key "<<fld<<endl;
26  if (!prm[0]) {
27  throw cms::Exception("BadParameters") << "Undefined key - " // abort!\n";
28  <<"Defined keys are: \"2_0T\" \"3_0T\" \"3_5T\" \"3_8T\" and \"4_0T\"\n";
29  // exit(1);
30  }
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 
38 namespace {
39 
40  template<typename T>
41  inline void ffunkti(T u, T * __restrict__ ff) __attribute__((always_inline)) __attribute__ ((pure));
42 
43  template<typename T>
44  inline void ffunkti(T u, T * __restrict__ ff) {
45  // Function and its 3 derivatives
46  T a,b,a2,u2;
47  u2=u*u;
48  a=T(1)/(T(1)+u2);
49  a2=-3*a*a;
50  b=mathSSE::sqrt(a);
51  ff[0]=u*b;
52  ff[1]=a*b;
53  ff[2]=a2*ff[0];
54  ff[3]=a2*ff[1]*(T(1)-4*u2);
55  }
56 }
57 
58 #if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ > 4)
59 
60 void TkBfield::Bcyl(double r, double z, double * __restrict__ Bw) const{
61  z-=prm[3]; // max Bz point is shifted in z
62  double az=std::abs(z);
63  double zainv=z*ainv;
64 
65  mathSSE::Vec2D uv(hlova-zainv,hlova+zainv);
66  mathSSE::Vec2D fuv[4];
67  ffunkti(uv,fuv);
68 
69  double rat=0.5*r*ainv;
70  double rat2=rat*rat;
71  Bw[0]=hb0*rat*(fuv[1][0]-fuv[1][1]-(fuv[3][0]-fuv[3][1])*rat2*0.5);
72  Bw[1]=0;
73  Bw[2]=hb0*(fuv[0][0]+fuv[0][1]-(fuv[2][0]+fuv[2][1])*rat2);
74 
75  double corBr= prm[4]*r*z*(az-prm[5])*(az-prm[5]);
76  double corBz=-prm[6]*(exp(-(z-prm[7])*(z-prm[7])*coeff) +
77  exp(-(z+prm[7])*(z+prm[7])*coeff)
78  ); // double Gaussian
79  Bw[0]+=corBr;
80  Bw[2]+=corBz;
81 }
82 
83 #else
84 
85 void TkBfield::Bcyl(double r, double z, double * __restrict__ Bw) const{
86  // if (r<1.15&&fabs(z)<2.8) // NOTE: check omitted, is done already by the wrapper! (NA)
87  z-=prm[3]; // max Bz point is shifted in z
88  double az=std::abs(z);
89  double zainv=z*ainv;
90  double u=hlova-zainv;
91  double v=hlova+zainv;
92  double fu[4],gv[4];
93  ffunkti(u,fu);
94  ffunkti(v,gv);
95  double rat=0.5*r*ainv;
96  double rat2=rat*rat;
97  Bw[0]=hb0*rat*(fu[1]-gv[1]-(fu[3]-gv[3])*rat2*0.5);
98  Bw[1]=0;
99  Bw[2]=hb0*(fu[0]+gv[0]-(fu[2]+gv[2])*rat2);
100  double corBr= prm[4]*r*z*(az-prm[5])*(az-prm[5]);
101  // double corBz=-prm[6]*exp(coeff*(az-prm[7])*(az-prm[7]));
102  // double corBz=-prm[6]/(1+coeff*(az-prm[7])*(az-prm[7]));
103  // double corBz=-prm[6]*(exp(-(z-prm[7])*(z-prm[7])/(prm[8]*prm[8]))
104  // + exp(-(z+prm[7])*(z+prm[7])/(prm[8]*prm[8]))); // double Gaussian
105  double corBz=-prm[6]*(exp(-(z-prm[7])*(z-prm[7])*coeff) +
106  exp(-(z+prm[7])*(z+prm[7])*coeff)
107  ); // double Gaussian
108  Bw[0]+=corBr;
109  Bw[2]+=corBz;
110  // } else {
111  // cout <<"TkBfield: The point is outside the region r<1.15m && |z|<2.8m"<<endl;
112 }
113 #endif
114 
115 
116 void TkBfield::getBrfz(double const * __restrict__ x, double * __restrict__ Brfz) const {
117  Bcyl(sqrt(x[0]*x[0]+x[1]*x[1]),x[2], Brfz);
118 }
119 
120 void TkBfield::getBxyz(double const * __restrict__ x, double * __restrict__ Bxyz) const {
121  double Bw[3];
122  double r=sqrt(x[0]*x[0]+x[1]*x[1]);
123  Bcyl(r, x[2], Bw);
124  double rinv=(r>0) ? 1/r:0;
125  Bxyz[0]=Bw[0]*x[0]*rinv;
126  Bxyz[1]=Bw[0]*x[1]*rinv;
127  Bxyz[2]=Bw[2];
128 }
129 
int i
Definition: DBlmapReader.cc:9
class Geom::OnePiRange __attribute__
#define abs(x)
Definition: mlp_lapack.h:159
void getBrfz(double const *__restrict__ x, double *__restrict__ Brfz) const
B out in cylindrical.
Definition: TkBfield.cc:116
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
Definition: DDAxes.h:10
T sqrt(T t)
Definition: SSEVec.h:28
double p4[4]
Definition: TauolaWrapper.h:92
TkBfield(std::string T="3_8T")
Definition: TkBfield.cc:13
double p2[4]
Definition: TauolaWrapper.h:90
tuple ff
Definition: createTree.py:204
void getBxyz(double const *__restrict__ x, double *__restrict__ Bxyz) const
B out in cartesian.
Definition: TkBfield.cc:120
double b
Definition: hdecay.h:120
double p1[4]
Definition: TauolaWrapper.h:89
double a
Definition: hdecay.h:121
void Bcyl(double r, double z, double *__restrict__ Bw) const
Definition: TkBfield.cc:85
mathSSE::Vec4< T > v
def template
Definition: svgfig.py:520
double p3[4]
Definition: TauolaWrapper.h:91