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)
 
 Cordic ()
 
 Cordic (int aPhiScale, int aMagnitudeBits, const int aSteps, bool debug)
 
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
 
l1tmetemu::EtMiss toPolar (l1tmetemu::Et_t x, l1tmetemu::Et_t y) const
 
virtual ~Cordic ()
 

Private Member Functions

uint32_t tower (const double &aRadians) const
 

Private Attributes

std::vector< l1tmetemu::METphi_tatanLUT
 
const int cordicSteps
 
const bool debug
 
std::vector< l1tmetemu::Et_tmagNormalisationLUT
 
uint32_t mMagnitudeBits
 
const int mMagnitudeBits
 
uint64_t mMagnitudeRenormalization
 
uint32_t mMagnitudeScale
 
const int mMagnitudeScale
 
uint32_t mPhiScale
 
const int 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() [1/3]

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

Definition at line 9 of file Cordic.cc.

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

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 }
uint32_t mMagnitudeBits
Definition: Cordic.h:24
uint32_t mPhiScale
Definition: Cordic.h:22
uint32_t tower(const double &aRadians) const
Definition: Cordic.cc:36
T sqrt(T t)
Definition: SSEVec.h:19
const double mPi
Definition: Cordic.h:29
uint32_t mSteps
Definition: Cordic.h:25
uint64_t mMagnitudeRenormalization
Definition: Cordic.h:26
uint32_t mMagnitudeScale
Definition: Cordic.h:23
std::vector< uint32_t > mRotations
Definition: Cordic.h:27
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ ~Cordic()

Cordic::~Cordic ( )
virtual

Definition at line 26 of file Cordic.cc.

26 {}

◆ Cordic() [2/3]

Cordic::Cordic ( )

◆ Cordic() [3/3]

Cordic::Cordic ( int  aPhiScale,
int  aMagnitudeBits,
const int  aSteps,
bool  debug 
)

Definition at line 8 of file Cordic.cc.

References atanLUT, debug, mps_fire::i, dqmiolumiharvest::j, M_PI, magNormalisationLUT, mMagnitudeScale, mPhiScale, funct::pow(), and heppy_batch::val.

9  : mPhiScale(aPhiScale),
10  mMagnitudeScale(1 << aMagnitudeBits),
11  mMagnitudeBits(aMagnitudeBits),
12  cordicSteps(aSteps),
13  debug(debug) {
14  atanLUT.reserve(aSteps);
15  magNormalisationLUT.reserve(aSteps);
16 
17  if (debug) {
18  edm::LogVerbatim("L1TkEtMissEmulator") << "=====atan LUT=====";
19  }
20 
21  for (int i = 0; i < aSteps; i++) {
22  atanLUT.push_back(METphi_t(round(mPhiScale * atan(pow(2, -i)) / (2 * M_PI))));
23  if (debug) {
24  edm::LogVerbatim("L1TkEtMissEmulator") << atanLUT[i] << " | ";
25  }
26  }
27  if (debug) {
28  edm::LogVerbatim("L1TkEtMissEmulator") << "\n=====Normalisation LUT=====";
29  }
30 
31  float val = 1.0;
32  for (int j = 0; j < aSteps; j++) {
33  val = val / (pow(1 + pow(4, -j), 0.5));
34  magNormalisationLUT.push_back(Et_t(round(mMagnitudeScale * val)));
35  if (debug) {
36  edm::LogVerbatim("L1TkEtMissEmulator") << magNormalisationLUT[j] << " | ";
37  }
38  }
39 }
Log< level::Info, true > LogVerbatim
ap_uint< kMETPhiSize > METphi_t
const int cordicSteps
Definition: Cordic.h:30
const bool debug
Definition: Cordic.h:32
uint32_t mMagnitudeBits
Definition: Cordic.h:24
uint32_t mPhiScale
Definition: Cordic.h:22
std::vector< l1tmetemu::Et_t > magNormalisationLUT
Definition: Cordic.h:37
std::vector< l1tmetemu::METphi_t > atanLUT
Definition: Cordic.h:35
#define M_PI
uint32_t mMagnitudeScale
Definition: Cordic.h:23
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
ap_int< kInternalPtWidth+kEtExtra > Et_t

Member Function Documentation

◆ IntegerizeMagnitude()

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

Definition at line 34 of file Cordic.cc.

References mMagnitudeScale.

34 { return int32_t(aMagnitude * mMagnitudeScale); }
uint32_t mMagnitudeScale
Definition: Cordic.h:23

◆ NormalizeMagnitude()

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

Definition at line 30 of file Cordic.cc.

References mMagnitudeScale.

30  {
31  return double(aMagnitude) / double(mMagnitudeScale);
32 }
uint32_t mMagnitudeScale
Definition: Cordic.h:23

◆ NormalizePhi()

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

Definition at line 28 of file Cordic.cc.

References simKBmtfDigis_cfi::aPhi, and mPhiScale.

28 { return double(aPhi) / double(mPhiScale); }
uint32_t mPhiScale
Definition: Cordic.h:22

◆ 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.

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

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 }
uint32_t mMagnitudeBits
Definition: Cordic.h:24
uint32_t tower(const double &aRadians) const
Definition: Cordic.cc:36
const double mPi
Definition: Cordic.h:29
uint32_t mSteps
Definition: Cordic.h:25
uint64_t mMagnitudeRenormalization
Definition: Cordic.h:26
std::vector< uint32_t > mRotations
Definition: Cordic.h:27

◆ toPolar()

EtMiss Cordic::toPolar ( l1tmetemu::Et_t  x,
l1tmetemu::Et_t  y 
) const

Definition at line 41 of file Cordic.cc.

References atanLUT, cordicSteps, debug, l1tmetemu::EtMiss::Et, dqmMemoryStats::float, createfilelist::int, l1tmetemu::kMaxMET, l1tmetemu::kMaxTrackPt, l1tmetemu::kMETSize, magNormalisationLUT, mMagnitudeBits, mPhiScale, phi, l1tmetemu::EtMiss::Phi, Validation_hcalonly_cfi::sign, x, and y.

41  {
42  Et_t new_x = 0;
43  Et_t new_y = 0;
44 
45  METphi_t phi = 0;
46  METphi_t new_phi = 0;
47  bool sign = false;
48 
49  EtMiss ret_etmiss;
50 
51  if (debug) {
52  edm::LogVerbatim("L1TkEtMissEmulator") << "\n=====Cordic Steps=====";
53  }
54 
55  if (x >= 0 && y >= 0) {
56  phi = 0;
57  sign = true;
58  //x = x;
59  //y = y;
60  } else if (x < 0 && y >= 0) {
61  phi = mPhiScale >> 1;
62  sign = false;
63  x = -x;
64  //y = y;
65  } else if (x < 0 && y < 0) {
66  phi = mPhiScale >> 1;
67  sign = true;
68  x = -x;
69  y = -y;
70  } else {
71  phi = mPhiScale;
72  sign = false;
73  //x = x;
74  y = -y;
75  }
76 
77  for (int step = 0; step < cordicSteps; step++) {
78  if (y < 0) {
79  new_x = x - (y >> step);
80  new_y = y + (x >> step);
81  } else {
82  new_x = x + (y >> step);
83  new_y = y - (x >> step);
84  }
85 
86  if ((y < 0) == sign) {
87  new_phi = phi - atanLUT[step];
88  } else {
89  new_phi = phi + atanLUT[step];
90  }
91 
92  x = new_x;
93  y = new_y;
94  phi = new_phi;
95 
96  if (debug) {
97  edm::LogVerbatim("L1TkEtMissEmulator")
98  << " Cordic x: " << x << " Cordic y: " << y << " Cordic phi: " << phi << "\n";
99  }
100  }
101 
102  // Cordic performs calculation in internal Et granularity, convert to final
103  // granularity for Et word
104 
105  // emulate fw rounding with float division then floor
106  float tempMET = (float)(x * magNormalisationLUT[cordicSteps - 1] * kMaxTrackPt) / ((float)kMaxMET);
107  ret_etmiss.Et = (int)floor(tempMET) >> (mMagnitudeBits + TTTrack_TrackWord::TrackBitWidths::kRinvSize - kMETSize);
108  ret_etmiss.Phi = phi;
109  return ret_etmiss;
110 }
Log< level::Info, true > LogVerbatim
ap_uint< kMETPhiSize > METphi_t
const int cordicSteps
Definition: Cordic.h:30
const bool debug
Definition: Cordic.h:32
uint32_t mMagnitudeBits
Definition: Cordic.h:24
uint32_t mPhiScale
Definition: Cordic.h:22
std::vector< l1tmetemu::Et_t > magNormalisationLUT
Definition: Cordic.h:37
const unsigned int kMETSize
std::vector< l1tmetemu::METphi_t > atanLUT
Definition: Cordic.h:35
const float kMaxMET
const float kMaxTrackPt
step
Definition: StallMonitor.cc:98
ap_int< kInternalPtWidth+kEtExtra > Et_t

◆ tower()

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

Definition at line 36 of file Cordic.cc.

References mPhiScale, and mPi.

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

36 { return uint32_t(round(mPhiScale * 0.5 * aRadians / mPi)); }
uint32_t mPhiScale
Definition: Cordic.h:22
const double mPi
Definition: Cordic.h:29

Member Data Documentation

◆ atanLUT

std::vector<l1tmetemu::METphi_t> Cordic::atanLUT
private

Definition at line 35 of file Cordic.h.

Referenced by Cordic(), and toPolar().

◆ cordicSteps

const int Cordic::cordicSteps
private

Definition at line 30 of file Cordic.h.

Referenced by toPolar().

◆ debug

const bool Cordic::debug
private

◆ magNormalisationLUT

std::vector<l1tmetemu::Et_t> Cordic::magNormalisationLUT
private

Definition at line 37 of file Cordic.h.

Referenced by Cordic(), and toPolar().

◆ mMagnitudeBits [1/2]

uint32_t Cordic::mMagnitudeBits
private

Definition at line 24 of file Cordic.h.

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

◆ mMagnitudeBits [2/2]

const int Cordic::mMagnitudeBits
private

Definition at line 28 of file Cordic.h.

◆ mMagnitudeRenormalization

uint64_t Cordic::mMagnitudeRenormalization
private

Definition at line 26 of file Cordic.h.

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

◆ mMagnitudeScale [1/2]

uint32_t Cordic::mMagnitudeScale
private

Definition at line 23 of file Cordic.h.

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

◆ mMagnitudeScale [2/2]

const int Cordic::mMagnitudeScale
private

Definition at line 26 of file Cordic.h.

◆ mPhiScale [1/2]

uint32_t Cordic::mPhiScale
private

Definition at line 22 of file Cordic.h.

Referenced by Cordic(), NormalizePhi(), toPolar(), and tower().

◆ mPhiScale [2/2]

const int Cordic::mPhiScale
private

Definition at line 24 of file Cordic.h.

◆ 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()().