CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
Cordic Class Reference

#include <Cordic.h>

Public Member Functions

 Cordic (const uint32_t &aPhiScale, const uint32_t &aMagnitudeBits, const uint32_t &aSteps)
 
int32_t IntegerizeMagnitude (const double &aMagnitude) const
 
double NormalizeMagnitude (const uint32_t &aMagnitude) const
 
double NormalizePhi (const uint32_t &aPhi) const
 
void operator() (int32_t aX, int32_t aY, int32_t &aPhi, uint32_t &aMagnitude) const
 
virtual ~Cordic ()
 

Private Member Functions

uint32_t tower (const double &aRadians) const
 

Private Attributes

uint32_t mMagnitudeBits
 
uint64_t mMagnitudeRenormalization
 
uint32_t mMagnitudeScale
 
uint32_t mPhiScale
 
const double mPi
 
std::vector< uint32_t > mRotations
 
uint32_t mSteps
 

Detailed Description

Definition at line 7 of file Cordic.h.

Constructor & Destructor Documentation

◆ Cordic()

Cordic::Cordic ( const uint32_t &  aPhiScale,
const uint32_t &  aMagnitudeBits,
const uint32_t &  aSteps 
)

Definition at line 9 of file Cordic.cc.

10  : mPhiScale(aPhiScale),
11  mMagnitudeScale(1 << aMagnitudeBits),
12  mMagnitudeBits(aMagnitudeBits),
13  mSteps(aSteps),
14  mPi(3.1415926535897932384626433832795) {
15  mRotations.reserve(mSteps);
16 
17  double lValue(1.0);
18 
19  for (uint32_t lStep(0); lStep != mSteps; ++lStep) {
20  lValue /= sqrt(1.0 + pow(4.0, -double(lStep)));
21  mRotations.push_back(tower(atan(pow(2.0, -double(lStep)))));
22  }
23  mMagnitudeRenormalization = uint32_t(round(mMagnitudeScale * lValue));
24 }

References mMagnitudeRenormalization, mMagnitudeScale, mRotations, mSteps, funct::pow(), mathSSE::sqrt(), and tower().

◆ ~Cordic()

Cordic::~Cordic ( )
virtual

Definition at line 26 of file Cordic.cc.

26 {}

Member Function Documentation

◆ IntegerizeMagnitude()

int32_t Cordic::IntegerizeMagnitude ( const double &  aMagnitude) const

Definition at line 34 of file Cordic.cc.

34 { return int32_t(aMagnitude * mMagnitudeScale); }

References mMagnitudeScale.

◆ NormalizeMagnitude()

double Cordic::NormalizeMagnitude ( const uint32_t &  aMagnitude) const

Definition at line 30 of file Cordic.cc.

30  {
31  return double(aMagnitude) / double(mMagnitudeScale);
32 }

References mMagnitudeScale.

◆ NormalizePhi()

double Cordic::NormalizePhi ( const uint32_t &  aPhi) const

Definition at line 28 of file Cordic.cc.

28 { return double(aPhi) / double(mPhiScale); }

References simKBmtfDigis_cfi::aPhi, and mPhiScale.

◆ operator()()

void Cordic::operator() ( int32_t  aX,
int32_t  aY,
int32_t &  aPhi,
uint32_t &  aMagnitude 
) const

Definition at line 38 of file Cordic.cc.

38  {
39  bool lSign(true);
40 
41  switch (((aY >= 0) ? 0x0 : 0x2) | ((aX >= 0) ? 0x0 : 0x1)) {
42  case 0:
43  aPhi = tower(mPi);
44  break;
45  case 1:
46  aPhi = tower(2 * mPi);
47  lSign = false;
48  aX = -aX;
49  break;
50  case 2:
51  aPhi = tower(mPi);
52  lSign = false;
53  aY = -aY;
54  break;
55  case 3:
56  aPhi = 0;
57  aX = -aX;
58  aY = -aY;
59  break;
60  default:
61  throw 0;
62  }
63 
64  for (uint32_t lStep(0); lStep != mSteps; ++lStep) {
65  if ((aY < 0) == lSign) {
66  aPhi -= mRotations[lStep];
67  } else {
68  aPhi += mRotations[lStep];
69  }
70 
71  int32_t lX(aX), lY(aY);
72  if (lY < 0) {
73  aX = lX - (lY >> lStep);
74  aY = lY + (lX >> lStep);
75  } else {
76  aX = lX + (lY >> lStep);
77  aY = lY - (lX >> lStep);
78  }
79  }
80 
81  aMagnitude = (aX * mMagnitudeRenormalization) >> mMagnitudeBits;
82 }

References simKBmtfDigis_cfi::aPhi, mMagnitudeBits, mMagnitudeRenormalization, mPi, mRotations, mSteps, tower(), testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::x2.

◆ tower()

uint32_t Cordic::tower ( const double &  aRadians) const
private

Definition at line 36 of file Cordic.cc.

36 { return uint32_t(round(mPhiScale * 0.5 * aRadians / mPi)); }

References mPhiScale, and mPi.

Referenced by Cordic(), and operator()().

Member Data Documentation

◆ mMagnitudeBits

uint32_t Cordic::mMagnitudeBits
private

Definition at line 24 of file Cordic.h.

Referenced by operator()().

◆ mMagnitudeRenormalization

uint64_t Cordic::mMagnitudeRenormalization
private

Definition at line 26 of file Cordic.h.

Referenced by Cordic(), and operator()().

◆ mMagnitudeScale

uint32_t Cordic::mMagnitudeScale
private

Definition at line 23 of file Cordic.h.

Referenced by Cordic(), IntegerizeMagnitude(), and NormalizeMagnitude().

◆ mPhiScale

uint32_t Cordic::mPhiScale
private

Definition at line 22 of file Cordic.h.

Referenced by NormalizePhi(), and tower().

◆ mPi

const double Cordic::mPi
private

Definition at line 29 of file Cordic.h.

Referenced by operator()(), and tower().

◆ mRotations

std::vector<uint32_t> Cordic::mRotations
private

Definition at line 27 of file Cordic.h.

Referenced by Cordic(), and operator()().

◆ mSteps

uint32_t Cordic::mSteps
private

Definition at line 25 of file Cordic.h.

Referenced by Cordic(), and operator()().

testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
Cordic::tower
uint32_t tower(const double &aRadians) const
Definition: Cordic.cc:36
Cordic::mRotations
std::vector< uint32_t > mRotations
Definition: Cordic.h:27
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
Cordic::mPi
const double mPi
Definition: Cordic.h:29
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
Cordic::mPhiScale
uint32_t mPhiScale
Definition: Cordic.h:22
Cordic::mMagnitudeBits
uint32_t mMagnitudeBits
Definition: Cordic.h:24
Cordic::mSteps
uint32_t mSteps
Definition: Cordic.h:25
Cordic::mMagnitudeRenormalization
uint64_t mMagnitudeRenormalization
Definition: Cordic.h:26
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:30
Cordic::mMagnitudeScale
uint32_t mMagnitudeScale
Definition: Cordic.h:23
simKBmtfDigis_cfi.aPhi
aPhi
Definition: simKBmtfDigis_cfi.py:5