CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

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

Definition at line 40 of file FastMath.h.

References fastmath_details::_2pif, fastmath_details::atanbuf_, cuy::cv, f, flags, i, invSqrt(), mag2(), x, and detailsBasic3DVector::y.

Referenced by etaphi().

40  {
41  using namespace fastmath_details;
42  float mag2 = x_ * x_ + y_ * y_;
43  if(!(mag2 > 0)) { return std::pair<float,float>(0.f,0.f); } // 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 ) { flags |= 4; y_ = -y_; }
55  if (x_ < 0 ) { flags |= 2; x_ = -x_; }
56  if (y_ > x_) {
57  flags |= 1;
58  x = rinv * y_; y = rinv * x_; yp.f += y;
59  }
60  else {
61  x = rinv * x_; y = rinv * y_; yp.f += y;
62  }
63  int ind = (yp.i & 0x01FF) * 2;
64 
65  float* asbuf = (float*)(atanbuf_ + ind);
66  float sv = yp.f - 32768.f;
67  float cv = asbuf[0];
68  float asv = asbuf[1];
69  sv = y * cv - x * sv; // delta sin value
70  // ____ compute arcsin directly
71  float asvd = 6.f + sv * sv; sv *= float(1.0f / 6.0f);
72  float th = asv + asvd * sv;
73  if (flags & 1) { th = (_2pif / 4.f) - th; }
74  if (flags & 2) { th = (_2pif / 2.f) - th; }
75  if (flags & 4) { th = -th; }
76  return std::pair<float,float>(th,overR ? rinv : rinv*mag2);
77  }
int i
Definition: DBlmapReader.cc:9
const float _2pif
Definition: FastMath.h:30
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
float invSqrt(float in)
Definition: FastMath.h:11
float atanbuf_[257 *2]
Definition: FastMath.cc:3
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
double f[11][100]
dictionary cv
Definition: cuy.py:362
Definition: DDAxes.h:10
std::pair<double, double> fastmath::atan2r ( double  y_,
double  x_,
bool  overR = false 
)
inline

Definition at line 82 of file FastMath.h.

References fastmath_details::_2pi, cuy::cv, ztail::d, fastmath_details::datanbuf_, flags, i, mag2(), mathSSE::sqrt(), x, and detailsBasic3DVector::y.

82  {
83  using namespace fastmath_details;
84  // assert(ataninited);
85  double mag2 = x_ * x_ + y_ * y_;
86  if(!(mag2 > 0)) { return std::pair<double, double>(0.,0.); } // degenerate case
87 
88  double r_ = std::sqrt(mag2);
89  double rinv = 1./r_;
90  unsigned int flags = 0;
91  double x, y;
92  const double _2p43 = 65536.0 * 65536.0 * 2048.0;
93  union {
94  double d;
95  int i[2];
96  } yp;
97 
98  yp.d = _2p43;
99  if (y_ < 0) { flags |= 4; y_ = -y_; }
100  if (x_ < 0) { flags |= 2; x_ = -x_; }
101  if (y_ > x_) {
102  flags |= 1;
103  x = rinv * y_; y = rinv * x_; yp.d += y;
104  }
105  else {
106  x = rinv * x_; y = rinv * y_; yp.d += y;
107  }
108 
109  int ind = (yp.i[0] & 0x03FF) * 2; // 0 for little indian
110 
111  double* dasbuf = (double*)(datanbuf_ + ind);
112  double sv = yp.d - _2p43; // index fraction
113  double cv = dasbuf[0];
114  double asv = dasbuf[1];
115  sv = y * cv - x * sv; // delta sin value
116  // double sv = y *(cv-x);
117  // ____ compute arcsin directly
118  double asvd = 6 + sv * sv; sv *= double(1.0 / 6.0);
119  double th = asv + asvd * sv;
120  if (flags & 1) { th = (_2pi / 4) - th; }
121  if (flags & 2) { th = (_2pi / 2) - th; }
122  if (flags & 4) { th = -th; }
123  return std::pair<double,double>(th,overR ? rinv : r_);
124  }
int i
Definition: DBlmapReader.cc:9
const double _2pi
Definition: FastMath.h:29
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
tuple d
Definition: ztail.py:151
T sqrt(T t)
Definition: SSEVec.h:48
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
dictionary cv
Definition: cuy.py:362
double datanbuf_[513 *2]
Definition: FastMath.cc:4
Definition: DDAxes.h:10
template<typename T >
std::pair<T,T> fastmath::etaphi ( T  x,
T  y,
T  z 
)
inline

Definition at line 128 of file FastMath.h.

References atan2r(), cmsBatch::log, and mathSSE::sqrt().

Referenced by L1TdeGCT::analyze(), L1TDEMON::analyze(), DQMHcalIsoTrackAlCaReco::analyze(), IsoTrig::analyze(), L1TdeGCT::bookHistograms(), L1TDEMON::bookHistograms(), FastL1GlobalAlgo::FillL1RegionsTP(), FastL1GlobalAlgo::FillMET(), spr::getEtaPhi(), and IPTCorrector::produce().

128  {
129  std::pair<T,T> por = atan2r(y,x, true);
130  x = z*por.second;
131  return std::pair<float,float>( std::log(x+std::sqrt(x*x+T(1))), por.first);
132  }
float float float z
T sqrt(T t)
Definition: SSEVec.h:48
std::pair< float, float > atan2r(float y_, float x_, bool overR=false)
Definition: FastMath.h:40
Definition: DDAxes.h:10
long double T
tuple log
Definition: cmsBatch.py:347
float fastmath::invSqrt ( float  in)
inline

Definition at line 11 of file FastMath.h.

References dbtoconf::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:48
tuple out
Definition: dbtoconf.py:99
double fastmath::invSqrt ( double  in)
inline

Definition at line 22 of file FastMath.h.

References mathSSE::sqrt().

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