CMS 3D CMS Logo

Functions
fastmath Namespace Reference

Functions

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

Function Documentation

◆ atan2r() [1/2]

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

Definition at line 38 of file FastMath.h.

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

Referenced by etaphi().

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  }
const float _2pif
Definition: FastMath.h:28
cv
Definition: cuy.py:363
float atanbuf_[257 *2]
Definition: FastMath.cc:3
double invSqrt(double in)
Definition: FastMath.h:22
double f[11][100]
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:49
float x

◆ atan2r() [2/2]

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

Definition at line 98 of file FastMath.h.

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

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  }
const double _2pi
Definition: FastMath.h:27
cv
Definition: cuy.py:363
T sqrt(T t)
Definition: SSEVec.h:19
d
Definition: ztail.py:151
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
double rinv(double phi1, double phi2, double r1, double r2)
Definition: Util.h:49
double datanbuf_[513 *2]
Definition: FastMath.cc:4
float x

◆ etaphi()

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

Definition at line 162 of file FastMath.h.

References atan2r(), dqm-mbProfile::log, mathSSE::sqrt(), and x.

Referenced by L1TdeGCT::analyze(), L1TDEMON::analyze(), DQMHcalIsoTrackAlCaReco::analyze(), HcalGeomCheck::analyze(), IsoTrig::analyze(), L1TdeGCT::bookHistograms(), L1TDEMON::bookHistograms(), JetHTJetPlusHOFilter::filter(), spr::getEtaPhi(), and IPTCorrector::produce().

162  {
163  std::pair<T, T> por = atan2r(y, x, true);
164  x = z * por.second;
165  return std::pair<float, float>(std::log(x + std::sqrt(x * x + T(1))), por.first);
166  }
std::pair< double, double > atan2r(double y_, double x_, bool overR=false)
Definition: FastMath.h:98
float float float z
T sqrt(T t)
Definition: SSEVec.h:19
float x
long double T

◆ invSqrt() [1/2]

float fastmath::invSqrt ( float  in)
inline

Definition at line 11 of file FastMath.h.

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

Referenced by atan2r().

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  }
T sqrt(T t)
Definition: SSEVec.h:19

◆ invSqrt() [2/2]

double fastmath::invSqrt ( double  in)
inline

Definition at line 22 of file FastMath.h.

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

22 { return 1. / std::sqrt(in); }
T sqrt(T t)
Definition: SSEVec.h:19