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 <numeric>
12 
16 
17 // Namespace that defines constants and types used by the EtMiss Emulation
18 // Includes functions for writing LUTs and converting to integer representations
19 namespace l1tmetemu {
20 
21  const unsigned int kInternalVTXWidth{12}; //default 8 max 12
22  const unsigned int kInternalEtaWidth{8}; //default 8 max 16
23  const unsigned int kInternalPtWidth{15}; // default 15 max 15
24  const unsigned int kInternalPhiWidth{8}; //default 8 max 12
25 
26  // Extra bits needed by global phi to span full range
27  const unsigned int kGlobalPhiExtra{3}; // default 3
28  // Extra room for Et sums
29  const unsigned int kEtExtra{10}; // default 8
30 
31  typedef ap_uint<3> nstub_t;
32 
33  typedef ap_uint<kInternalPhiWidth + kGlobalPhiExtra> global_phi_t;
34 
35  typedef ap_uint<kInternalPtWidth> pt_t;
36  typedef ap_uint<kInternalEtaWidth> eta_t;
37  typedef ap_uint<kInternalVTXWidth> z_t;
38  // For internal Et representation, sums become larger than initial pt
39  // representation
40  typedef ap_int<kInternalPtWidth + kEtExtra> Et_t;
41 
42  //Output format
43  const float kMaxMET{4096}; // 4 TeV
44  const float kMaxMETPhi{2 * M_PI};
45  const unsigned int kMETSize{15}; // For output Magnitude default 15
46  const unsigned int kMETPhiSize{14}; // For Output Phi default 14
47 
48  typedef ap_uint<kMETSize> MET_t;
49  // Cordic means this is evaluated between 0 and 2Pi rather than -pi to pi so
50  // unsigned
51  typedef ap_uint<kMETPhiSize> METphi_t;
52 
53  const unsigned int kGlobalPhiBins = 1 << kInternalPhiWidth;
54  const unsigned int kMETBins = 1 << kMETSize;
55  const unsigned int kMETPhiBins = 1 << kMETPhiSize;
56 
57  const unsigned int kNEtaRegion{6};
58  const unsigned int kNSector{9};
59  const unsigned int kNQuadrants{4};
60 
62  const float kMaxTrackPt{512};
63  const float kMaxTrackEta{4};
64 
65  // Steps used to convert from track word floats to track MET integer representations
66 
67  const double kStepPt = (std::abs(kMaxTrackPt)) / (1 << kInternalPtWidth);
68  const double kStepEta = (2 * std::abs(kMaxTrackEta)) / (1 << kInternalEtaWidth);
69  const double kStepZ0 = (2 * std::abs(kMaxTrackZ0)) / (1 << kInternalVTXWidth);
70 
71  const double kStepPhi = (2 * -TTTrack_TrackWord::minPhi0) / (kGlobalPhiBins - 1);
72 
75 
76  // Enough symmetry in cos and sin between 0 and pi/2 to get all possible values
77  // of cos and sin phi
78  const float kMaxCosLUTPhi{M_PI / 2};
79 
80  // Simple struct used for ouput of cordic
81  struct EtMiss {
84  };
85 
86  std::vector<global_phi_t> generateCosLUT(unsigned int size);
87  std::vector<eta_t> generateEtaRegionLUT(std::vector<double> EtaRegions);
88  std::vector<z_t> generateDeltaZLUT(std::vector<double> DeltaZBins);
89 
90  template <typename T>
91  T digitizeSignedValue(double value, unsigned int nBits, double lsb) {
92  // Digitize the incoming value
93  int digitizedValue = std::floor(value / lsb);
94 
95  // Calculate the maxmum possible positive value given an output of nBits in size
96  int digitizedMaximum = (1 << (nBits - 1)) - 1; // The remove 1 bit from nBits to account for the sign
97  int digitizedMinimum = -1. * (digitizedMaximum + 1);
98 
99  // Saturate the digitized value
100  digitizedValue = std::clamp(digitizedValue, digitizedMinimum, digitizedMaximum);
101 
102  // Do the two's compliment encoding
103  T twosValue = digitizedValue;
104  if (digitizedValue < 0) {
105  twosValue += (1 << nBits);
106  }
107 
108  return twosValue;
109  }
110 
111  template <typename T>
112  unsigned int getBin(double value, const T& bins) {
113  auto up = std::upper_bound(bins.begin(), bins.end(), value);
114  return (up - bins.begin() - 1);
115  }
116 
117  int unpackSignedValue(unsigned int bits, unsigned int nBits);
118 
119  unsigned int transformSignedValue(unsigned int bits, unsigned int oldnBits, unsigned int newnBits);
120 
121 } // namespace l1tmetemu
122 #endif
size
Write out results.
const unsigned int kGlobalPhiBins
Definition: BitonicSort.h:7
std::vector< eta_t > generateEtaRegionLUT(std::vector< double > EtaRegions)
ap_uint< kMETPhiSize > METphi_t
const float kMaxTrackZ0
const unsigned int kGlobalPhiExtra
const float kMaxMETPhi
static constexpr double minZ0
int unpackSignedValue(unsigned int bits, unsigned int nBits)
constexpr uint32_t bits
Definition: gpuClustering.h:23
const float kMaxTrackEta
ap_uint< kInternalVTXWidth > z_t
const double kStepEta
std::vector< z_t > generateDeltaZLUT(std::vector< double > DeltaZBins)
const unsigned int kNEtaRegion
const double kStepPt
const double kStepMET
const unsigned int kNQuadrants
const unsigned int kNSector
const unsigned int kInternalVTXWidth
unsigned int transformSignedValue(unsigned int bits, unsigned int oldnBits, unsigned int newnBits)
const double kStepZ0
const unsigned int kMETPhiBins
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const unsigned int kEtExtra
const unsigned int kMETSize
ap_uint< kInternalEtaWidth > eta_t
Definition: value.py:1
T digitizeSignedValue(double value, unsigned int nBits, double lsb)
ap_uint< kMETSize > MET_t
#define M_PI
static constexpr double minPhi0
const unsigned int kInternalPtWidth
ap_uint< kInternalPhiWidth+kGlobalPhiExtra > global_phi_t
unsigned int getBin(double value, const T &bins)
std::vector< global_phi_t > generateCosLUT(unsigned int size)
const float kMaxMET
const unsigned int kMETPhiSize
const float kMaxTrackPt
const float kMaxCosLUTPhi
const unsigned int kInternalEtaWidth
ap_uint< 3 > nstub_t
const unsigned int kMETBins
long double T
const unsigned int kInternalPhiWidth
ap_uint< kInternalPtWidth > pt_t
ap_int< kInternalPtWidth+kEtExtra > Et_t
const double kStepPhi
const double kStepMETPhi