CMS 3D CMS Logo

Functions
fastmath Namespace Reference

Functions

std::pair< double, double > atan2r (double y_, double x_, bool overR=false)
 
std::pair< float, float > atan2r (float y_, float x_, bool overR=false)
 
template<typename T >
std::pair< T, Tetaphi (T x, T y, T z)
 
double invSqrt (double in)
 
float invSqrt (float in)
 

Function Documentation

◆ atan2r() [1/2]

std::pair<double, double> fastmath::atan2r ( double  y_,
double  x_,
bool  overR = false 
)
inline

Definition at line 98 of file FastMath.h.

98  {
99  using namespace fastmath_details;
100  // assert(ataninited);
101  double mag2 = x_ * x_ + y_ * y_;
102  if (!(mag2 > 0)) {
103  return std::pair<double, double>(0., 0.);
104  } // degenerate case
105 
106  double r_ = std::sqrt(mag2);
107  double rinv = 1. / r_;
108  unsigned int flags = 0;
109  double x, y;
110  const double _2p43 = 65536.0 * 65536.0 * 2048.0;
111  union {
112  double d;
113  int i[2];
114  } yp;
115 
116  yp.d = _2p43;
117  if (y_ < 0) {
118  flags |= 4;
119  y_ = -y_;
120  }
121  if (x_ < 0) {
122  flags |= 2;
123  x_ = -x_;
124  }
125  if (y_ > x_) {
126  flags |= 1;
127  x = rinv * y_;
128  y = rinv * x_;
129  yp.d += y;
130  } else {
131  x = rinv * x_;
132  y = rinv * y_;
133  yp.d += y;
134  }
135 
136  int ind = (yp.i[0] & 0x03FF) * 2; // 0 for little indian
137 
138  double* dasbuf = (double*)(datanbuf_ + ind);
139  double sv = yp.d - _2p43; // index fraction
140  double cv = dasbuf[0];
141  double asv = dasbuf[1];
142  sv = y * cv - x * sv; // delta sin value
143  // double sv = y *(cv-x);
144  // ____ compute arcsin directly
145  double asvd = 6 + sv * sv;
146  sv *= double(1.0 / 6.0);
147  double th = asv + asvd * sv;
148  if (flags & 1) {
149  th = (_2pi / 4) - th;
150  }
151  if (flags & 2) {
152  th = (_2pi / 2) - th;
153  }
154  if (flags & 4) {
155  th = -th;
156  }
157  return std::pair<double, double>(th, overR ? rinv : r_);
158  }

References fastmath_details::_2pi, cuy::cv, ztail::d, fastmath_details::datanbuf_, HLT_FULL_cff::flags, mps_fire::i, mag2(), trklet::rinv(), mathSSE::sqrt(), and pfDeepBoostedJetPreprocessParams_cfi::sv.

◆ atan2r() [2/2]

std::pair<float, float> fastmath::atan2r ( float  y_,
float  x_,
bool  overR = false 
)
inline

Definition at line 38 of file FastMath.h.

38  {
39  using namespace fastmath_details;
40  float mag2 = x_ * x_ + y_ * y_;
41  if (!(mag2 > 0)) {
42  return std::pair<float, float>(0.f, 0.f);
43  } // degenerate case
44 
45  // float r_ = std::sqrt(mag2);
46  float rinv = invSqrt(mag2);
47  unsigned int flags = 0;
48  float x, y;
49  union {
50  float f;
51  int i;
52  } yp;
53  yp.f = 32768.f;
54  if (y_ < 0) {
55  flags |= 4;
56  y_ = -y_;
57  }
58  if (x_ < 0) {
59  flags |= 2;
60  x_ = -x_;
61  }
62  if (y_ > x_) {
63  flags |= 1;
64  x = rinv * y_;
65  y = rinv * x_;
66  yp.f += y;
67  } else {
68  x = rinv * x_;
69  y = rinv * y_;
70  yp.f += y;
71  }
72  int ind = (yp.i & 0x01FF) * 2;
73 
74  float* asbuf = (float*)(atanbuf_ + ind);
75  float sv = yp.f - 32768.f;
76  float cv = asbuf[0];
77  float asv = asbuf[1];
78  sv = y * cv - x * sv; // delta sin value
79  // ____ compute arcsin directly
80  float asvd = 6.f + sv * sv;
81  sv *= float(1.0f / 6.0f);
82  float th = asv + asvd * sv;
83  if (flags & 1) {
84  th = (_2pif / 4.f) - th;
85  }
86  if (flags & 2) {
87  th = (_2pif / 2.f) - th;
88  }
89  if (flags & 4) {
90  th = -th;
91  }
92  return std::pair<float, float>(th, overR ? rinv : rinv * mag2);
93  }

References fastmath_details::_2pif, fastmath_details::atanbuf_, cuy::cv, f, HLT_FULL_cff::flags, dqmMemoryStats::float, mps_fire::i, invSqrt(), mag2(), trklet::rinv(), and pfDeepBoostedJetPreprocessParams_cfi::sv.

Referenced by etaphi().

◆ etaphi()

template<typename T >
std::pair<T, T> fastmath::etaphi ( T  x,
T  y,
T  z 
)
inline

◆ invSqrt() [1/2]

double fastmath::invSqrt ( double  in)
inline

Definition at line 22 of file FastMath.h.

22 { return 1. / std::sqrt(in); }

References recoMuon::in, and mathSSE::sqrt().

◆ invSqrt() [2/2]

float fastmath::invSqrt ( float  in)
inline

Definition at line 11 of file FastMath.h.

11  {
12 #ifndef __SSE2__
13  return 1.f / std::sqrt(in);
14 #else
15  float out;
16  _mm_store_ss(&out, _mm_rsqrt_ss(_mm_load_ss(&in))); // compiles to movss, rsqrtss, movss
17  // return out; // already good enough!
18  return out * (1.5f - 0.5f * in * out * out); // One (more?) round of Newton's method
19 #endif
20  }

References recoMuon::in, MillePedeFileConverter_cfg::out, and mathSSE::sqrt().

Referenced by atan2r().

DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
detailsBasic3DVector::z
float float float z
Definition: extBasic3DVector.h:14
cuy.cv
cv
Definition: cuy.py:364
fastmath::atan2r
std::pair< double, double > atan2r(double y_, double x_, bool overR=false)
Definition: FastMath.h:98
DDAxes::x
fastmath_details::atanbuf_
float atanbuf_[257 *2]
Definition: FastMath.cc:3
fastmath_details::_2pi
const double _2pi
Definition: FastMath.h:27
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
pfDeepBoostedJetPreprocessParams_cfi.sv
sv
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:352
fastmath_details::_2pif
const float _2pif
Definition: FastMath.h:28
trklet::rinv
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:173
recoMuon::in
Definition: RecoMuonEnumerators.h:6
mag2
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
Definition: Basic3DVectorLD.h:124
fastmath_details
Definition: FastMath.h:26
fastmath_details::datanbuf_
double datanbuf_[513 *2]
Definition: FastMath.cc:4
fastmath::invSqrt
double invSqrt(double in)
Definition: FastMath.h:22
T
long double T
Definition: Basic3DVectorLD.h:48
genVertex_cff.x
x
Definition: genVertex_cff.py:12
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ztail.d
d
Definition: ztail.py:151
HLT_FULL_cff.flags
flags
Definition: HLT_FULL_cff.py:13150