Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-10 01:53:49

0001 #ifndef L1Trigger_Phase2L1ParticleFlow_l1converters_tracks_tkinput_ref_h
0002 #define L1Trigger_Phase2L1ParticleFlow_l1converters_tracks_tkinput_ref_h
0003 
0004 #include "DataFormats/L1TParticleFlow/interface/layer1_emulator.h"
0005 #include <cstdio>
0006 #include <algorithm>
0007 
0008 namespace edm {
0009   class ParameterSet;
0010 }
0011 
0012 namespace l1ct {
0013   class TrackInputEmulator {
0014   public:
0015     enum class Region { Barrel, Endcap, Any };  // but only Endcap supported for now
0016 
0017     /// encoding used in the digitized track word
0018     enum class Encoding {
0019       Stepping,  // J = sign(F) * floor(abs(F)/LSB);  F = sign(J) * ( abs(J) + 0.5 ) * LSB
0020       Biased,    // J = floor(F/LSB);  F = (J + 0.5)*LSB
0021       Unbiased   // J = round(F/LSB);  F = J * LSB
0022     };
0023 
0024     TrackInputEmulator(const edm::ParameterSet &iConfig);
0025     TrackInputEmulator(Region = Region::Endcap, Encoding encoding = Encoding::Stepping, bool bitwise = true);
0026 
0027     std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword, const l1ct::PFRegionEmu &sector) const {
0028       return decodeTrack(tkword, sector, bitwise_);
0029     }
0030     std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
0031                                                 const l1ct::PFRegionEmu &sector,
0032                                                 bool bitwise) const;
0033 
0034     //== Unpackers ==
0035     static bool valid(const ap_uint<96> &tkword) { return tkword[95]; }
0036     static bool charge(const ap_uint<96> &tkword) { return !tkword[94]; }
0037 
0038     static ap_int<15> signedRinv(const ap_uint<96> &tkword) { return ap_int<15>(tkword(94, 80)); }
0039     static ap_int<12> signedZ0(const ap_uint<96> &tkword) { return ap_int<12>(tkword(47, 36)); }
0040     static ap_int<16> signedTanl(const ap_uint<96> &tkword) { return ap_int<16>(tkword(63, 48)); }
0041     static ap_int<12> signedPhi(const ap_uint<96> &tkword) { return ap_int<12>(tkword(79, 68)); }
0042 
0043     //=== Floating point conversions ===
0044     /// just unpack tanl to a float
0045     float floatTanl(ap_int<16> tanl) const { return toFloat_(tanl) / (1 << 12); }
0046 
0047     /// convert track-word int tanl into float eta (at vertex) in radiants (exact)
0048     float floatEta(ap_int<16> tanl) const;
0049 
0050     /// convert track-word Rinv into float pt (almost exact)
0051     float floatPt(ap_int<15> Rinv) const;
0052 
0053     /// convert track-word int phi into float phi (at vertex) in radiants (exact)
0054     float floatPhi(ap_int<12> phi) const;
0055 
0056     /// convert track-word int z0 into float z0 in cm (exact)
0057     float floatZ0(ap_int<12> z0) const;
0058 
0059     //=== Configuration of floating point conversions
0060     void setRinvToPtFactor(float rInvToPt) { rInvToPt_ = rInvToPt; }
0061     void setPhiScale(float phiScale) { phiScale_ = phiScale; }
0062     void setZ0Scale(float z0Scale) { z0Scale_ = z0Scale; }
0063 
0064     //=== Bitwise accurate conversions ===
0065     l1ct::pt_t convPt(ap_int<15> Rinv) const;
0066 
0067     /// convert track-word int tanl into eta *at vertex* in layer 1 units
0068     l1ct::glbeta_t convEta(ap_int<16> tanl) const;
0069 
0070     /// convert track-word int phi into phi *at vertex* in layer 1 units
0071     l1ct::phi_t convPhi(ap_int<12> phi) const;
0072 
0073     l1ct::z0_t convZ0(ap_int<12> z0) const;
0074 
0075     //=== Configuration for bitwise accurate conversions ===
0076     void configPt(int lutBits);
0077 
0078     void configEta(int lutBits, int preOffs, int shift, int postOffs, bool lutSigned, bool endcap);
0079 
0080     void configPhi(int bits);
0081 
0082     void configZ0(int bits);
0083 
0084     //=== Track propagation to calo (float parametrization, no rounding) ===
0085     //
0086     // barrel DEta propagation, in layer-1 units (float parameterization, no rounding)
0087     float floatDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0088     // barrel DPhi propagation, in layer-1 units (float parameterization, no rounding)
0089     float floatDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0090 
0091     void setDEtaBarrelParams(float pZ0) { dEtaBarrelParamZ0_ = pZ0; }
0092     void setDPhiBarrelParams(float pC) { dPhiBarrelParamC_ = pC; }
0093 
0094     //=== Track propagation to calo (bitwise accurate) ===
0095     l1ct::tkdeta_t calcDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0096     l1ct::tkdphi_t calcDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0097 
0098     //=== Configuration of bitwise accurate propagation to calo ===
0099     void configDEtaBarrel(int dEtaBarrelBits, int dEtaBarrelZ0PreShift, int dEtaBarrelZ0PostShift, float offs = 0);
0100     void configDPhiBarrel(int dPhiBarrelBits, int dPhiBarrelRInvPreShift, int dPhiBarrelRInvPostShift, float offs = 0);
0101 
0102     // endcap DEta propagation, in layer-1 units (float parameterization, no rounding)
0103     float floatDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0104     // endcap DPhi propagation, in layer-1 units (float parameterization, no rounding)
0105     float floatDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0106 
0107     void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2) {
0108       dEtaHGCalParamZ0_ = pZ0;
0109       dEtaHGCalParamRInv2C_ = pRinv2C;
0110       dEtaHGCalParamRInv2ITanl1_ = pRinv2ITanl1;
0111       dEtaHGCalParamRInv2ITanl2_ = pRinv2ITanl2;
0112     }
0113     void setDPhiHGCalParams(float pZ0, float pC) {
0114       dPhiHGCalParamZ0_ = pZ0;
0115       dPhiHGCalParamC_ = pC;
0116     }
0117 
0118     //=== Track propagation to calo (bitwise accurate) ===
0119     l1ct::tkdeta_t calcDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0120     l1ct::tkdphi_t calcDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0121 
0122     //=== Configuration of bitwise accurate propagation to calo ===
0123     void configDEtaHGCal(int dEtaHGCalBits,
0124                          int dEtaHGCalZ0PreShift,
0125                          int dEtaHGCalRInvPreShift,
0126                          int dEtaHGCalLUTBits,
0127                          int dEtaHGCalLUTShift,
0128                          float offs = 0);
0129     void configDPhiHGCal(int dPhiHGCalBits,
0130                          int dPhiHGCalZ0PreShift,
0131                          int dPhiHGCalZ0PostShift,
0132                          int dPhiHGCalRInvShift,
0133                          int dPhiHGCalTanlInvShift,
0134                          int dPhiHGCalTanlLUTBits,
0135                          float offs = 0);
0136 
0137     /// conservative cut to select tracks that may have |eta| > 1.25 or |calo eta| > 1.25
0138     static bool mayReachHGCal(ap_int<16> tanl) { return (tanl > 6000) || (tanl < -6000); }
0139     /// conservative cut to avoid filling LUTs outside of the tracker range
0140     static bool withinTracker(ap_int<16> tanl) { return (-25000 < tanl) && (tanl < 25000); }
0141     /// conservative cut to avoid filling LUTs outside of the barrel range
0142     static bool withinBarrel(ap_int<16> tanl) { return (-13000 < tanl) && (tanl < 13000); }
0143 
0144     void setDebug(bool debug = true) { debug_ = debug; }
0145 
0146     // access to bare LUTs
0147     //const std::vector<int> &dEtaBarrelLUT() const { return dEtaBarrelLUT_; }
0148     //const std::vector<int> &dPhiBarrelTanlLUT() const { return dPhiBarrelTanlLUT_; }
0149     const std::vector<int> &dEtaHGCalLUT() const { return dEtaHGCalLUT_; }
0150     const std::vector<int> &dPhiHGCalTanlLUT() const { return dPhiHGCalTanlLUT_; }
0151     const std::vector<int> &tanlLUT() const { return tanlLUT_; }
0152     const std::vector<l1ct::pt_t> &ptLUT() const { return ptLUT_; }
0153 
0154   protected:
0155     // utilities
0156     template <int N>
0157     inline float toFloat_(ap_int<N> signedVal) const {
0158       float ret = signedVal.to_float();
0159       switch (encoding_) {
0160         case Encoding::Stepping:
0161           return (signedVal >= 0 ? ret + 0.5 : ret - 0.5);
0162         case Encoding::Biased:
0163           return ret + 0.5;
0164         default:
0165           return ret;
0166       }
0167     }
0168 
0169     /// Region for which the emulation is configured
0170     Region region_;
0171 
0172     /// Encoding used for track word inputs
0173     Encoding encoding_;
0174 
0175     /// Whether to run the bitwise accurate or floating point conversions
0176     bool bitwise_;
0177 
0178     /// Main constants
0179     float rInvToPt_, phiScale_, z0Scale_;
0180 
0181     /// Parameters for track propagation in floating point
0182     float dEtaBarrelParamZ0_;
0183     float dPhiBarrelParamC_;
0184 
0185     /// Parameters for track propagation in floating point
0186     float dEtaHGCalParamZ0_, dEtaHGCalParamRInv2C_, dEtaHGCalParamRInv2ITanl1_, dEtaHGCalParamRInv2ITanl2_;
0187     float dPhiHGCalParamZ0_, dPhiHGCalParamC_;
0188 
0189     // vtx phi conversion parameters
0190     int vtxPhiMult_, vtxPhiOffsPos_, vtxPhiOffsNeg_, vtxPhiBitShift_;
0191 
0192     // z0 conversion parameters
0193     int z0Mult_, z0OffsPos_, z0OffsNeg_, z0BitShift_;
0194 
0195     // deta parameters in barrel region
0196     int dEtaBarrelBits_, dEtaBarrelZ0PreShift_, dEtaBarrelZ0PostShift_, dEtaBarrelOffs_, dEtaBarrelZ0_;
0197 
0198     // dphi parameters in barrel region
0199     int dPhiBarrelBits_, dPhiBarrelRInvPreShift_, dPhiBarrelRInvPostShift_, dPhiBarrelOffs_, dPhiBarrelC_;
0200 
0201     // deta parameters in hgcal region
0202     int dEtaHGCalBits_, dEtaHGCalZ0PreShift_, dEtaHGCalZ0_, dEtaHGCalRInvPreShift_, dEtaHGCalTanlShift_,
0203         dEtaHGCalLUTShift_, dEtaHGCalTanlTermOffs_, dEtaHGCalTanlTermShift_, dEtaHGCalOffs_;
0204     std::vector<int> dEtaHGCalLUT_;
0205 
0206     // dphi parameters in hgcal region
0207     int dPhiHGCalBits_, dPhiHGCalZ0PreShift_, dPhiHGCalZ0_, dPhiHGCalZ0PostShift_, dPhiHGCalRInvShift_,
0208         dPhiHGCalTanlShift_, dPhiHGCalTanlInvShift_, dPhiHGCalPreOffs_, dPhiHGCalOffs_;
0209     std::vector<int> dPhiHGCalTanlLUT_;
0210 
0211     // tanl to eta LUT parameters
0212     int tanlLUTPreOffs_, tanlLUTShift_, tanlLUTPostOffs_;
0213     std::vector<int> tanlLUT_;
0214     bool tanlLUTSigned_;
0215 
0216     // Rinv to pR LUT parameters
0217     int ptLUTShift_;
0218     std::vector<l1ct::pt_t> ptLUT_;
0219 
0220     /// enable debug printout in some metods
0221     bool debug_;
0222   };
0223 }  // namespace l1ct
0224 
0225 #endif