Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:13:02

0001 #ifndef L1Trigger_L1TTrackMatch_L1TkEtMissEmuAlgo_HH
0002 #define L1Trigger_L1TTrackMatch_L1TkEtMissEmuAlgo_HH
0003 
0004 #include <ap_int.h>
0005 
0006 #include <cmath>
0007 #include <cstdint>
0008 #include <filesystem>
0009 #include <fstream>
0010 #include <iostream>
0011 #include <iomanip>
0012 #include <numeric>
0013 
0014 #include "DataFormats/L1TrackTrigger/interface/TTTrack_TrackWord.h"
0015 #include "DataFormats/L1TrackTrigger/interface/TTTypes.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 
0018 // Namespace that defines constants and types used by the EtMiss Emulation
0019 // Includes functions for writing LUTs and converting to integer representations
0020 namespace l1tmetemu {
0021 
0022   const unsigned int kInternalPtWidth{14};
0023   const unsigned int kPtMagSize{9};
0024   const unsigned int kMETSize{16};  // For output Magnitude default 16
0025   const unsigned int kMETMagSize{11};
0026   const unsigned int kMETPhiSize{13};  // For Output Phi default 13
0027   const unsigned int kEtExtra{4};
0028   const unsigned int kGlobalPhiExtra{4};
0029   const unsigned int kCosLUTSize{10};
0030   const unsigned int kCosLUTMagSize{1};
0031   const unsigned int kAtanLUTSize{64};
0032   const unsigned int kAtanLUTMagSize{2};
0033 
0034   typedef ap_ufixed<kMETSize, kMETMagSize, AP_RND_CONV, AP_SAT> METWord_t;
0035   typedef ap_int<kMETPhiSize> METWordphi_t;
0036   typedef ap_int<TTTrack_TrackWord::TrackBitWidths::kPhiSize + kGlobalPhiExtra> global_phi_t;
0037   typedef ap_ufixed<kCosLUTSize, kCosLUTMagSize, AP_RND_CONV, AP_SAT> cos_lut_fixed_t;
0038   typedef ap_ufixed<kAtanLUTSize, kAtanLUTMagSize, AP_RND_CONV, AP_SAT> atan_lut_fixed_t;
0039   typedef ap_fixed<kMETSize + kEtExtra, kMETMagSize + kEtExtra, AP_RND_CONV, AP_SAT> Et_t;
0040   typedef ap_fixed<kMETPhiSize + kEtExtra, 4, AP_RND_CONV, AP_SAT> metphi_fixed_t;
0041   typedef ap_ufixed<kMETPhiSize + kEtExtra + 7, kMETPhiSize - 2, AP_RND_CONV, AP_SAT> pi_bins_fixed_t;
0042 
0043   // Output definition as per interface document, only used when creating output format
0044   const double kMaxMET = 1 << kMETMagSize;  // 2 TeV
0045   const double kMaxMETPhi{2 * M_PI};
0046 
0047   const double kStepMETwordEt = kMaxMET / (1 << kMETSize);
0048   const double kStepMETwordPhi = kMaxMETPhi / (1 << kMETPhiSize);
0049   const double kBinsInPi = 1.0 / kStepMETwordPhi;
0050 
0051   // Enough symmetry in cos and sin between 0 and pi/2 to get all possible values
0052   // of cos and sin phi
0053   const double kMaxCosLUTPhi{M_PI / 2};
0054 
0055   const unsigned int kNSector{9};
0056   const unsigned int kNQuadrants{4};
0057 
0058   // Simple struct used for ouput of cordic
0059   struct EtMiss {
0060     METWord_t Et;
0061     METWordphi_t Phi;
0062   };
0063 
0064   std::vector<cos_lut_fixed_t> generateCosLUT(unsigned int size);
0065 
0066   global_phi_t localToGlobalPhi(TTTrack_TrackWord::phi_t local_phi, global_phi_t sector_shift);
0067 
0068   std::vector<global_phi_t> generatePhiSliceLUT(unsigned int N);
0069 
0070   template <typename T>
0071   void printLUT(std::vector<T> lut, std::string module = "", std::string name = "") {
0072     edm::LogVerbatim log(module);
0073     log << "The " << name << "[" << lut.size() << "] values are ... \n" << std::setprecision(30);
0074     for (unsigned int i = 0; i < lut.size(); i++) {
0075       log << "\t" << i << "\t" << lut[i] << "\n";
0076     }
0077   }
0078 
0079 }  // namespace l1tmetemu
0080 #endif