File indexing completed on 2024-04-06 12:04:31
0001 #ifndef DataFormats_L1TCalorimeterPhase2_DigitizedClusterGT_h
0002 #define DataFormats_L1TCalorimeterPhase2_DigitizedClusterGT_h
0003
0004 #include <ap_int.h>
0005 #include <vector>
0006
0007 namespace l1tp2 {
0008
0009 class DigitizedClusterGT {
0010 private:
0011
0012 unsigned long long int clusterData;
0013
0014
0015 static constexpr float LSB_PT = 0.03125;
0016 static constexpr unsigned int n_bits_eta_pi = 12;
0017 static constexpr unsigned int n_bits_phi_pi = 12;
0018 static constexpr unsigned int n_bits_pt = 16;
0019 static constexpr unsigned int n_bits_unused_start = 44;
0020
0021 float LSB_ETA = (M_PI / std::pow(2, n_bits_eta_pi));
0022 float LSB_PHI = (M_PI / std::pow(2, n_bits_phi_pi));
0023
0024
0025 ap_uint<1> digitizeIsValid(bool isValid) { return (ap_uint<1>)isValid; }
0026
0027 ap_uint<16> digitizePt(float pt_f) {
0028 float maxPt_f = (std::pow(2, n_bits_pt) - 1) * LSB_PT;
0029
0030 if (pt_f >= maxPt_f) {
0031 return (ap_uint<16>)0xFFFF;
0032 }
0033 return (ap_uint<16>)(pt_f / LSB_PT);
0034 }
0035
0036
0037 ap_int<13> digitizePhi(float phi_f) {
0038 ap_int<13> phi_digitized = (phi_f / LSB_PHI);
0039 return phi_digitized;
0040 }
0041
0042
0043 ap_int<14> digitizeEta(float eta_f) {
0044 ap_int<14> eta_digitized = (eta_f / LSB_ETA);
0045 return eta_digitized;
0046 }
0047
0048 public:
0049 DigitizedClusterGT() { clusterData = 0x0; }
0050
0051 DigitizedClusterGT(ap_uint<64> data) { clusterData = data; }
0052
0053
0054 DigitizedClusterGT(ap_uint<1> isValid, ap_uint<16> pt, ap_int<13> phi, ap_int<14> eta, bool fullyDigitizedInputs) {
0055 (void)fullyDigitizedInputs;
0056 clusterData =
0057 ((ap_uint<64>)isValid) | (((ap_uint<64>)pt) << 1) | (((ap_uint<64>)phi) << 17) | (((ap_uint<64>)eta) << 30);
0058 }
0059
0060
0061 DigitizedClusterGT(bool isValid, float pt_f, float phi_f, float eta_f) {
0062
0063
0064
0065
0066
0067
0068 clusterData = ((ap_uint<64>)digitizeIsValid(isValid)) | ((ap_uint<64>)digitizePt(pt_f) << 1) |
0069 (((ap_uint<64>)digitizePhi(phi_f) << 17) &
0070 0x3FFE0000) |
0071 (((ap_uint<64>)digitizeEta(eta_f) << 30) &
0072 0xFFFC0000000);
0073 }
0074
0075 ap_uint<64> data() const { return clusterData; }
0076
0077
0078 float ptLSB() const { return LSB_PT; }
0079 float phiLSB() const { return LSB_PHI; }
0080 float etaLSB() const { return LSB_ETA; }
0081 ap_uint<1> isValid() const { return (clusterData & 0x1); }
0082 ap_uint<16> pt() const { return ((clusterData >> 1) & 0xFFFF); }
0083 ap_int<13> phi() const { return ((clusterData >> 17) & 0x1FFF); }
0084 ap_int<14> eta() const { return ((clusterData >> 30) & 0x3FFF); }
0085
0086 float ptFloat() const { return (pt() * ptLSB()); }
0087 float realPhi() const {
0088 return (phi() * phiLSB());
0089 }
0090 float realEta() const {
0091 return (eta() * etaLSB());
0092 }
0093 const int unusedBitsStart() const { return n_bits_unused_start; }
0094
0095
0096 bool passNullBitsCheck(void) const { return ((data() >> unusedBitsStart()) == 0x0); }
0097 };
0098
0099
0100 typedef std::vector<l1tp2::DigitizedClusterGT> DigitizedClusterGTCollection;
0101
0102 }
0103
0104 #endif