File indexing completed on 2025-04-30 22:24:27
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 class ParameterSetDescription;
0011 }
0012
0013 namespace l1ct {
0014 class TrackInputEmulator {
0015 public:
0016 enum class Region { Barrel, Endcap, Any };
0017
0018
0019 enum class Encoding {
0020 Stepping,
0021 Biased,
0022 Unbiased
0023 };
0024
0025 TrackInputEmulator(const edm::ParameterSet &iConfig);
0026 TrackInputEmulator(Region = Region::Endcap,
0027 Encoding encoding = Encoding::Stepping,
0028 bool bitwise = true,
0029 bool slim = true);
0030
0031 static edm::ParameterSetDescription getParameterSetDescription();
0032
0033 std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword, const l1ct::PFRegionEmu §or) const {
0034 return decodeTrack(tkword, sector, bitwise_, slim_);
0035 }
0036 std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
0037 const l1ct::PFRegionEmu §or,
0038 bool bitwise) const {
0039 return decodeTrack(tkword, sector, bitwise, slim_);
0040 }
0041
0042 std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
0043 const l1ct::PFRegionEmu §or,
0044 bool bitwise,
0045 bool slim) const;
0046
0047
0048 static bool valid(const ap_uint<96> &tkword) { return tkword[95]; }
0049 static bool charge(const ap_uint<96> &tkword) { return !tkword[94]; }
0050
0051 static ap_int<15> signedRinv(const ap_uint<96> &tkword) { return ap_int<15>(tkword(94, 80)); }
0052 static ap_int<12> signedZ0(const ap_uint<96> &tkword) { return ap_int<12>(tkword(47, 36)); }
0053 static ap_int<13> signedDxy(const ap_uint<96> &tkword) { return ap_int<13>(tkword(31, 19)); }
0054 static ap_int<16> signedTanl(const ap_uint<96> &tkword) { return ap_int<16>(tkword(63, 48)); }
0055 static ap_int<12> signedPhi(const ap_uint<96> &tkword) { return ap_int<12>(tkword(79, 68)); }
0056
0057
0058
0059 float floatTanl(ap_int<16> tanl) const { return toFloat_(tanl) / (1 << 12); }
0060
0061
0062 float floatEta(ap_int<16> tanl) const;
0063
0064
0065 float floatPt(ap_int<15> Rinv) const;
0066
0067
0068 float floatPhi(ap_int<12> phi) const;
0069
0070
0071 float floatZ0(ap_int<12> z0) const;
0072
0073
0074 float floatDxy(ap_int<13> dxy) const;
0075
0076
0077 void setRinvToPtFactor(float rInvToPt) { rInvToPt_ = rInvToPt; }
0078 void setPhiScale(float phiScale) { phiScale_ = phiScale; }
0079 void setZ0Scale(float z0Scale) { z0Scale_ = z0Scale; }
0080 void setDxyScale(float dxyScale) { dxyScale_ = dxyScale; }
0081
0082
0083 l1ct::pt_t convPt(ap_int<15> Rinv) const;
0084
0085
0086 l1ct::glbeta_t convEta(ap_int<16> tanl) const;
0087
0088
0089 l1ct::phi_t convPhi(ap_int<12> phi) const;
0090
0091 l1ct::z0_t convZ0(ap_int<12> z0) const;
0092
0093 l1ct::dxy_t convDxy(ap_int<13> dxy) const;
0094
0095
0096 void configPt(int lutBits);
0097
0098 void configEta(int lutBits, int preOffs, int shift, int postOffs, bool lutSigned, bool endcap);
0099
0100 void configPhi(int bits);
0101
0102 void configZ0(int bits);
0103
0104 void configDxy(int bits);
0105
0106
0107
0108
0109 float floatDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0110
0111 float floatDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0112
0113 void setDEtaBarrelParams(float pZ0) { dEtaBarrelParamZ0_ = pZ0; }
0114 void setDPhiBarrelParams(float pC) { dPhiBarrelParamC_ = pC; }
0115
0116
0117 l1ct::tkdeta_t calcDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0118 l1ct::tkdphi_t calcDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0119
0120
0121 void configDEtaBarrel(int dEtaBarrelBits, int dEtaBarrelZ0PreShift, int dEtaBarrelZ0PostShift, float offs = 0);
0122 void configDPhiBarrel(int dPhiBarrelBits, int dPhiBarrelRInvPreShift, int dPhiBarrelRInvPostShift, float offs = 0);
0123
0124
0125 float floatDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0126
0127 float floatDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0128
0129 void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2) {
0130 dEtaHGCalParamZ0_ = pZ0;
0131 dEtaHGCalParamRInv2C_ = pRinv2C;
0132 dEtaHGCalParamRInv2ITanl1_ = pRinv2ITanl1;
0133 dEtaHGCalParamRInv2ITanl2_ = pRinv2ITanl2;
0134 }
0135 void setDPhiHGCalParams(float pZ0, float pC) {
0136 dPhiHGCalParamZ0_ = pZ0;
0137 dPhiHGCalParamC_ = pC;
0138 }
0139
0140
0141 l1ct::tkdeta_t calcDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0142 l1ct::tkdphi_t calcDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0143
0144
0145 void configDEtaHGCal(int dEtaHGCalBits,
0146 int dEtaHGCalZ0PreShift,
0147 int dEtaHGCalRInvPreShift,
0148 int dEtaHGCalLUTBits,
0149 int dEtaHGCalLUTShift,
0150 float offs = 0);
0151 void configDPhiHGCal(int dPhiHGCalBits,
0152 int dPhiHGCalZ0PreShift,
0153 int dPhiHGCalZ0PostShift,
0154 int dPhiHGCalRInvShift,
0155 int dPhiHGCalTanlInvShift,
0156 int dPhiHGCalTanlLUTBits,
0157 float offs = 0);
0158
0159
0160 static bool mayReachHGCal(ap_int<16> tanl) { return (tanl > 6000) || (tanl < -6000); }
0161
0162 static bool withinTracker(ap_int<16> tanl) { return (-25000 < tanl) && (tanl < 25000); }
0163
0164 static bool withinBarrel(ap_int<16> tanl) { return (-13000 < tanl) && (tanl < 13000); }
0165
0166 void setDebug(bool debug = true) { debug_ = debug; }
0167
0168
0169
0170
0171 const std::vector<int> &dEtaHGCalLUT() const { return dEtaHGCalLUT_; }
0172 const std::vector<int> &dPhiHGCalTanlLUT() const { return dPhiHGCalTanlLUT_; }
0173 const std::vector<int> &tanlLUT() const { return tanlLUT_; }
0174 const std::vector<l1ct::pt_t> &ptLUT() const { return ptLUT_; }
0175
0176 unsigned int countSetBits(unsigned int n) const {
0177 unsigned int count = 0;
0178 while (n) {
0179 n &= (n - 1);
0180 count++;
0181 }
0182 return count;
0183 }
0184
0185 protected:
0186
0187 template <int N>
0188 inline float toFloat_(ap_int<N> signedVal) const {
0189 float ret = signedVal.to_float();
0190 switch (encoding_) {
0191 case Encoding::Stepping:
0192 return (signedVal >= 0 ? ret + 0.5 : ret - 0.5);
0193 case Encoding::Biased:
0194 return ret + 0.5;
0195 default:
0196 return ret;
0197 }
0198 }
0199
0200
0201 Region region_;
0202
0203
0204 Encoding encoding_;
0205
0206
0207 bool bitwise_;
0208
0209
0210 bool slim_;
0211
0212
0213 float rInvToPt_, phiScale_, z0Scale_, dxyScale_;
0214
0215
0216 float dEtaBarrelParamZ0_;
0217 float dPhiBarrelParamC_;
0218
0219
0220 float dEtaHGCalParamZ0_, dEtaHGCalParamRInv2C_, dEtaHGCalParamRInv2ITanl1_, dEtaHGCalParamRInv2ITanl2_;
0221 float dPhiHGCalParamZ0_, dPhiHGCalParamC_;
0222
0223
0224 int vtxPhiMult_, vtxPhiOffsPos_, vtxPhiOffsNeg_, vtxPhiBitShift_;
0225
0226
0227 int z0Mult_, z0OffsPos_, z0OffsNeg_, z0BitShift_;
0228
0229
0230 int dxyMult_, dxyOffsPos_, dxyOffsNeg_, dxyBitShift_;
0231
0232
0233 int dEtaBarrelBits_, dEtaBarrelZ0PreShift_, dEtaBarrelZ0PostShift_, dEtaBarrelOffs_, dEtaBarrelZ0_;
0234
0235
0236 int dPhiBarrelBits_, dPhiBarrelRInvPreShift_, dPhiBarrelRInvPostShift_, dPhiBarrelOffs_, dPhiBarrelC_;
0237
0238
0239 int dEtaHGCalBits_, dEtaHGCalZ0PreShift_, dEtaHGCalZ0_, dEtaHGCalRInvPreShift_, dEtaHGCalTanlShift_,
0240 dEtaHGCalLUTShift_, dEtaHGCalTanlTermOffs_, dEtaHGCalTanlTermShift_, dEtaHGCalOffs_;
0241 std::vector<int> dEtaHGCalLUT_;
0242
0243
0244 int dPhiHGCalBits_, dPhiHGCalZ0PreShift_, dPhiHGCalZ0_, dPhiHGCalZ0PostShift_, dPhiHGCalRInvShift_,
0245 dPhiHGCalTanlShift_, dPhiHGCalTanlInvShift_, dPhiHGCalPreOffs_, dPhiHGCalOffs_;
0246 std::vector<int> dPhiHGCalTanlLUT_;
0247
0248
0249 int tanlLUTPreOffs_, tanlLUTShift_, tanlLUTPostOffs_;
0250 std::vector<int> tanlLUT_;
0251 bool tanlLUTSigned_;
0252
0253
0254 int ptLUTShift_;
0255 std::vector<l1ct::pt_t> ptLUT_;
0256
0257
0258 bool debug_;
0259 };
0260 }
0261
0262 #endif