Back to home page

Project CMSSW displayed by LXR

 
 

    


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     // Data
0012     unsigned long long int clusterData;
0013 
0014     // Constants
0015     static constexpr float LSB_PT = 0.03125;                 // 0.03125 GeV
0016     static constexpr unsigned int n_bits_eta_pi = 12;        // 12 bits corresponds to pi in eta
0017     static constexpr unsigned int n_bits_phi_pi = 12;        // 12 bits corresponds to pi in phi
0018     static constexpr unsigned int n_bits_pt = 16;            // 12 bits allocated for pt
0019     static constexpr unsigned int n_bits_unused_start = 44;  // unused bits start at bit number 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     // Private member functions to perform digitization
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       // If pT exceeds the maximum, saturate the value
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     // Use two's complements representation
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     // Use two's complements representation
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     // Constructor from digitized inputs
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     // Constructor from float inputs that will perform digitization
0061     DigitizedClusterGT(bool isValid, float pt_f, float phi_f, float eta_f) {
0062       // N.b.: For eta/phi, after shifting the bits to the correct place and casting to ap_uint<64>,
0063       // we have an additional bit mask
0064       // e.g. 0x3FFE0000 for phi. This mask is all zero's except for 1 in the phi bits (bits 17 through 29):
0065       // bit mask = 0x3FFE0000 = 0b111111111111100000000000000000
0066       // Applying the "and" of this bitmask, avoids bogus 1's in the case where phi is negative
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) |  // 0x3FFE0000 is all zero's except the phi bits (bits 17 through 29)
0071                     (((ap_uint<64>)digitizeEta(eta_f) << 30) &
0072                      0xFFFC0000000);  // 0xFFFC0000000 is all zero's except the eta bits (bits 30 through 32)
0073     }
0074 
0075     ap_uint<64> data() const { return clusterData; }
0076 
0077     // Other getters
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); }   // 16 1's = 0xFFFF
0083     ap_int<13> phi() const { return ((clusterData >> 17) & 0x1FFF); }  // (thirteen 1's)= 0x1FFF
0084     ap_int<14> eta() const { return ((clusterData >> 30) & 0x3FFF); }  // (fourteen 1's) = 0x3FFF
0085 
0086     float ptFloat() const { return (pt() * ptLSB()); }
0087     float realPhi() const {  // convert from signed int to float
0088       return (phi() * phiLSB());
0089     }
0090     float realEta() const {  // convert from signed int to float
0091       return (eta() * etaLSB());
0092     }
0093     const int unusedBitsStart() const { return n_bits_unused_start; }  // unused bits start at bit 44
0094 
0095     // Other checks
0096     bool passNullBitsCheck(void) const { return ((data() >> unusedBitsStart()) == 0x0); }
0097   };
0098 
0099   // Collection typedef
0100   typedef std::vector<l1tp2::DigitizedClusterGT> DigitizedClusterGTCollection;
0101 
0102 }  // namespace l1tp2
0103 
0104 #endif