CMS 3D CMS Logo

DigitizedClusterGT.h
Go to the documentation of this file.
1 #ifndef DataFormats_L1TCalorimeterPhase2_DigitizedClusterGT_h
2 #define DataFormats_L1TCalorimeterPhase2_DigitizedClusterGT_h
3 
4 #include <ap_int.h>
5 #include <vector>
6 
7 namespace l1tp2 {
8 
10  private:
11  // Data
12  ap_uint<64> clusterData;
13 
14  // Constants
15  static constexpr float LSB_PT = 0.03125; // 0.03125 GeV
16  static constexpr unsigned int n_bits_eta_pi = 12; // 12 bits corresponds to pi in eta
17  static constexpr unsigned int n_bits_phi_pi = 12; // 12 bits corresponds to pi in phi
18  static constexpr unsigned int n_bits_pt = 16; // 12 bits allocated for pt
19  static constexpr unsigned int n_bits_unused_start = 44; // unused bits start at bit number 44
20 
23 
24  // Private member functions to perform digitization
25  ap_uint<1> digitizeIsValid(bool isValid) { return (ap_uint<1>)isValid; }
26 
27  ap_uint<16> digitizePt(float pt_f) {
28  float maxPt_f = (std::pow(2, n_bits_pt) - 1) * LSB_PT;
29  // If pT exceeds the maximum, saturate the value
30  if (pt_f >= maxPt_f) {
31  return (ap_uint<16>)0xFFFF;
32  }
33  return (ap_uint<16>)(pt_f / LSB_PT);
34  }
35 
36  // Use two's complements representation
37  ap_int<13> digitizePhi(float phi_f) {
38  ap_int<13> phi_digitized = (phi_f / LSB_PHI);
39  return phi_digitized;
40  }
41 
42  // Use two's complements representation
43  ap_int<14> digitizeEta(float eta_f) {
44  ap_int<14> eta_digitized = (eta_f / LSB_ETA);
45  return eta_digitized;
46  }
47 
48  public:
50 
52 
53  // Constructor from digitized inputs
54  DigitizedClusterGT(ap_uint<1> isValid, ap_uint<16> pt, ap_int<13> phi, ap_int<14> eta, bool fullyDigitizedInputs) {
55  (void)fullyDigitizedInputs;
56  clusterData =
57  ((ap_uint<64>)isValid) | (((ap_uint<64>)pt) << 1) | (((ap_uint<64>)phi) << 17) | (((ap_uint<64>)eta) << 30);
58  }
59 
60  // Constructor from float inputs that will perform digitization
61  DigitizedClusterGT(bool isValid, float pt_f, float phi_f, float eta_f) {
62  // N.b.: For eta/phi, after shifting the bits to the correct place and casting to ap_uint<64>,
63  // we have an additional bit mask
64  // e.g. 0x3FFE0000 for phi. This mask is all zero's except for 1 in the phi bits (bits 17 through 29):
65  // bit mask = 0x3FFE0000 = 0b111111111111100000000000000000
66  // Applying the "and" of this bitmask, avoids bogus 1's in the case where phi is negative
67 
68  clusterData = ((ap_uint<64>)digitizeIsValid(isValid)) | ((ap_uint<64>)digitizePt(pt_f) << 1) |
69  (((ap_uint<64>)digitizePhi(phi_f) << 17) &
70  0x3FFE0000) | // 0x3FFE0000 is all zero's except the phi bits (bits 17 through 29)
71  (((ap_uint<64>)digitizeEta(eta_f) << 30) &
72  0xFFFC0000000); // 0xFFFC0000000 is all zero's except the eta bits (bits 30 through 32)
73  }
74 
75  ap_uint<64> data() const { return clusterData; }
76 
77  // Other getters
78  float ptLSB() const { return LSB_PT; }
79  float phiLSB() const { return LSB_PHI; }
80  float etaLSB() const { return LSB_ETA; }
81  ap_uint<1> isValid() const { return (clusterData & 0x1); }
82  ap_uint<16> pt() const { return ((clusterData >> 1) & 0xFFFF); } // 16 1's = 0xFFFF
83  ap_int<13> phi() const { return ((clusterData >> 17) & 0x1FFF); } // (thirteen 1's)= 0x1FFF
84  ap_int<14> eta() const { return ((clusterData >> 30) & 0x3FFF); } // (fourteen 1's) = 0x3FFF
85 
86  float ptFloat() const { return (pt() * ptLSB()); }
87  float realPhi() const { // convert from signed int to float
88  return (phi() * phiLSB());
89  }
90  float realEta() const { // convert from signed int to float
91  return (eta() * etaLSB());
92  }
93  const int unusedBitsStart() const { return n_bits_unused_start; } // unused bits start at bit 44
94 
95  // Other checks
96  bool passNullBitsCheck(void) const { return ((data() >> unusedBitsStart()) == 0x0); }
97  };
98 
99  // Collection typedef
100  typedef std::vector<l1tp2::DigitizedClusterGT> DigitizedClusterGTCollection;
101 
102 } // namespace l1tp2
103 
104 #endif
static constexpr unsigned int n_bits_pt
ap_uint< 64 > data() const
ap_uint< 1 > digitizeIsValid(bool isValid)
DigitizedClusterGT(ap_uint< 1 > isValid, ap_uint< 16 > pt, ap_int< 13 > phi, ap_int< 14 > eta, bool fullyDigitizedInputs)
const int unusedBitsStart() const
DigitizedClusterGT(bool isValid, float pt_f, float phi_f, float eta_f)
constexpr int pow(int x)
Definition: conifer.h:24
std::vector< l1tp2::DigitizedClusterGT > DigitizedClusterGTCollection
static constexpr unsigned int n_bits_eta_pi
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
DigitizedClusterGT(ap_uint< 64 > data)
ap_int< 14 > digitizeEta(float eta_f)
ap_uint< 1 > isValid() const
bool passNullBitsCheck(void) const
#define M_PI
ap_int< 14 > eta() const
ap_int< 13 > phi() const
ap_int< 13 > digitizePhi(float phi_f)
static constexpr unsigned int n_bits_unused_start
static constexpr float LSB_PT
ap_uint< 16 > pt() const
static constexpr unsigned int n_bits_phi_pi
ap_uint< 16 > digitizePt(float pt_f)