CMS 3D CMS Logo

L1TkEtMissEmuAlgo.h
Go to the documentation of this file.
1 #ifndef L1Trigger_L1TTrackMatch_L1TkEtMissEmuAlgo_HH
2 #define L1Trigger_L1TTrackMatch_L1TkEtMissEmuAlgo_HH
3 
4 #include <ap_int.h>
5 
6 #include <cmath>
7 #include <cstdint>
8 #include <filesystem>
9 #include <fstream>
10 #include <iostream>
11 #include <iomanip>
12 #include <numeric>
13 
17 
18 // Namespace that defines constants and types used by the EtMiss Emulation
19 // Includes functions for writing LUTs and converting to integer representations
20 namespace l1tmetemu {
21 
22  const unsigned int kInternalPtWidth{14};
23  const unsigned int kPtMagSize{9};
24  const unsigned int kMETSize{16}; // For output Magnitude default 16
25  const unsigned int kMETMagSize{11};
26  const unsigned int kMETPhiSize{13}; // For Output Phi default 13
27  const unsigned int kEtExtra{4};
28  const unsigned int kGlobalPhiExtra{4};
29  const unsigned int kCosLUTSize{10};
30  const unsigned int kCosLUTMagSize{1};
31  const unsigned int kCosLUTTableSize{10};
32  const unsigned int kCosLUTBins{(1 << kCosLUTTableSize) + 1};
33  const unsigned int kCosLUTShift{TTTrack_TrackWord::TrackBitWidths::kPhiSize - kCosLUTTableSize};
34  const unsigned int kAtanLUTSize{64};
35  const unsigned int kAtanLUTMagSize{2};
36 
37  typedef ap_ufixed<kMETSize, kMETMagSize, AP_RND_CONV, AP_SAT> METWord_t;
38  typedef ap_int<kMETPhiSize> METWordphi_t;
39  typedef ap_int<TTTrack_TrackWord::TrackBitWidths::kPhiSize + kGlobalPhiExtra> global_phi_t;
40  typedef ap_ufixed<kCosLUTSize, kCosLUTMagSize, AP_RND_CONV, AP_SAT> cos_lut_fixed_t;
41  typedef ap_ufixed<kAtanLUTSize, kAtanLUTMagSize, AP_RND_CONV, AP_SAT> atan_lut_fixed_t;
42  typedef ap_fixed<kMETSize + kEtExtra, kMETMagSize + kEtExtra, AP_RND_CONV, AP_SAT> Et_t;
43  typedef ap_fixed<kMETPhiSize + kEtExtra, 4, AP_RND_CONV, AP_SAT> metphi_fixed_t;
44  typedef ap_ufixed<kMETPhiSize + kEtExtra + 7, kMETPhiSize - 2, AP_RND_CONV, AP_SAT> pi_bins_fixed_t;
45 
46  // Output definition as per interface document, only used when creating output format
47  const double kMaxMET = 1 << kMETMagSize; // 2 TeV
48  const double kMaxMETPhi{2 * M_PI};
49 
50  const double kStepMETwordEt = kMaxMET / (1 << kMETSize);
51  const double kStepMETwordPhi = kMaxMETPhi / (1 << kMETPhiSize);
52  const double kBinsInPi = 1.0 / kStepMETwordPhi;
53 
54  // Enough symmetry in cos and sin between 0 and pi/2 to get all possible values
55  // of cos and sin phi
56  const double kMaxCosLUTPhi{M_PI / 2};
57 
58  const unsigned int kNSector{9};
59  const unsigned int kNQuadrants{4};
60 
61  // Simple struct used for ouput of cordic
62  struct EtMiss {
65  };
66 
67  std::vector<cos_lut_fixed_t> generateCosLUT();
68 
70 
71  std::vector<global_phi_t> generatePhiSliceLUT(unsigned int N);
72 
73  template <typename T>
74  void printLUT(std::vector<T> lut, std::string module = "", std::string name = "") {
76  log << "The " << name << "[" << lut.size() << "] values are ... \n" << std::setprecision(30);
77  for (unsigned int i = 0; i < lut.size(); i++) {
78  log << "\t" << i << "\t" << lut[i] << "\n";
79  }
80  }
81 
82 } // namespace l1tmetemu
83 #endif
ap_int< kMETPhiSize > METWordphi_t
ap_fixed< kMETSize+kEtExtra, kMETMagSize+kEtExtra, AP_RND_CONV, AP_SAT > Et_t
const unsigned int kGlobalPhiExtra
ap_int< TTTrack_TrackWord::TrackBitWidths::kPhiSize+kGlobalPhiExtra > global_phi_t
void printLUT(std::vector< T > lut, std::string module="", std::string name="")
ap_ufixed< kAtanLUTSize, kAtanLUTMagSize, AP_RND_CONV, AP_SAT > atan_lut_fixed_t
ap_ufixed< kMETSize, kMETMagSize, AP_RND_CONV, AP_SAT > METWord_t
global_phi_t localToGlobalPhi(TTTrack_TrackWord::phi_t local_phi, global_phi_t sector_shift)
const double kStepMETwordEt
const unsigned int kNQuadrants
const unsigned int kNSector
const unsigned int kCosLUTMagSize
const unsigned int kAtanLUTSize
const unsigned int kAtanLUTMagSize
const double kMaxCosLUTPhi
const double kStepMETwordPhi
const unsigned int kCosLUTBins
const unsigned int kEtExtra
const unsigned int kMETSize
ap_ufixed< kCosLUTSize, kCosLUTMagSize, AP_RND_CONV, AP_SAT > cos_lut_fixed_t
#define M_PI
const unsigned int kInternalPtWidth
#define N
Definition: blowfish.cc:9
const double kMaxMET
const unsigned int kCosLUTShift
ap_fixed< kMETPhiSize+kEtExtra, 4, AP_RND_CONV, AP_SAT > metphi_fixed_t
const unsigned int kMETPhiSize
std::vector< global_phi_t > generatePhiSliceLUT(unsigned int N)
const unsigned int kPtMagSize
std::vector< cos_lut_fixed_t > generateCosLUT()
const unsigned int kCosLUTSize
const double kMaxMETPhi
const unsigned int kMETMagSize
const unsigned int kCosLUTTableSize
const double kBinsInPi
ap_uint< TrackBitWidths::kPhiSize > phi_t
ap_ufixed< kMETPhiSize+kEtExtra+7, kMETPhiSize - 2, AP_RND_CONV, AP_SAT > pi_bins_fixed_t