File indexing completed on 2024-04-06 12:21:26
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<16> signedTanl(const ap_uint<96> &tkword) { return ap_int<16>(tkword(63, 48)); }
0054 static ap_int<12> signedPhi(const ap_uint<96> &tkword) { return ap_int<12>(tkword(79, 68)); }
0055
0056
0057
0058 float floatTanl(ap_int<16> tanl) const { return toFloat_(tanl) / (1 << 12); }
0059
0060
0061 float floatEta(ap_int<16> tanl) const;
0062
0063
0064 float floatPt(ap_int<15> Rinv) const;
0065
0066
0067 float floatPhi(ap_int<12> phi) const;
0068
0069
0070 float floatZ0(ap_int<12> z0) const;
0071
0072
0073 void setRinvToPtFactor(float rInvToPt) { rInvToPt_ = rInvToPt; }
0074 void setPhiScale(float phiScale) { phiScale_ = phiScale; }
0075 void setZ0Scale(float z0Scale) { z0Scale_ = z0Scale; }
0076
0077
0078 l1ct::pt_t convPt(ap_int<15> Rinv) const;
0079
0080
0081 l1ct::glbeta_t convEta(ap_int<16> tanl) const;
0082
0083
0084 l1ct::phi_t convPhi(ap_int<12> phi) const;
0085
0086 l1ct::z0_t convZ0(ap_int<12> z0) const;
0087
0088
0089 void configPt(int lutBits);
0090
0091 void configEta(int lutBits, int preOffs, int shift, int postOffs, bool lutSigned, bool endcap);
0092
0093 void configPhi(int bits);
0094
0095 void configZ0(int bits);
0096
0097
0098
0099
0100 float floatDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0101
0102 float floatDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0103
0104 void setDEtaBarrelParams(float pZ0) { dEtaBarrelParamZ0_ = pZ0; }
0105 void setDPhiBarrelParams(float pC) { dPhiBarrelParamC_ = pC; }
0106
0107
0108 l1ct::tkdeta_t calcDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0109 l1ct::tkdphi_t calcDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0110
0111
0112 void configDEtaBarrel(int dEtaBarrelBits, int dEtaBarrelZ0PreShift, int dEtaBarrelZ0PostShift, float offs = 0);
0113 void configDPhiBarrel(int dPhiBarrelBits, int dPhiBarrelRInvPreShift, int dPhiBarrelRInvPostShift, float offs = 0);
0114
0115
0116 float floatDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0117
0118 float floatDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0119
0120 void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2) {
0121 dEtaHGCalParamZ0_ = pZ0;
0122 dEtaHGCalParamRInv2C_ = pRinv2C;
0123 dEtaHGCalParamRInv2ITanl1_ = pRinv2ITanl1;
0124 dEtaHGCalParamRInv2ITanl2_ = pRinv2ITanl2;
0125 }
0126 void setDPhiHGCalParams(float pZ0, float pC) {
0127 dPhiHGCalParamZ0_ = pZ0;
0128 dPhiHGCalParamC_ = pC;
0129 }
0130
0131
0132 l1ct::tkdeta_t calcDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0133 l1ct::tkdphi_t calcDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
0134
0135
0136 void configDEtaHGCal(int dEtaHGCalBits,
0137 int dEtaHGCalZ0PreShift,
0138 int dEtaHGCalRInvPreShift,
0139 int dEtaHGCalLUTBits,
0140 int dEtaHGCalLUTShift,
0141 float offs = 0);
0142 void configDPhiHGCal(int dPhiHGCalBits,
0143 int dPhiHGCalZ0PreShift,
0144 int dPhiHGCalZ0PostShift,
0145 int dPhiHGCalRInvShift,
0146 int dPhiHGCalTanlInvShift,
0147 int dPhiHGCalTanlLUTBits,
0148 float offs = 0);
0149
0150
0151 static bool mayReachHGCal(ap_int<16> tanl) { return (tanl > 6000) || (tanl < -6000); }
0152
0153 static bool withinTracker(ap_int<16> tanl) { return (-25000 < tanl) && (tanl < 25000); }
0154
0155 static bool withinBarrel(ap_int<16> tanl) { return (-13000 < tanl) && (tanl < 13000); }
0156
0157 void setDebug(bool debug = true) { debug_ = debug; }
0158
0159
0160
0161
0162 const std::vector<int> &dEtaHGCalLUT() const { return dEtaHGCalLUT_; }
0163 const std::vector<int> &dPhiHGCalTanlLUT() const { return dPhiHGCalTanlLUT_; }
0164 const std::vector<int> &tanlLUT() const { return tanlLUT_; }
0165 const std::vector<l1ct::pt_t> &ptLUT() const { return ptLUT_; }
0166
0167 unsigned int countSetBits(unsigned int n) const {
0168 unsigned int count = 0;
0169 while (n) {
0170 n &= (n - 1);
0171 count++;
0172 }
0173 return count;
0174 }
0175
0176 protected:
0177
0178 template <int N>
0179 inline float toFloat_(ap_int<N> signedVal) const {
0180 float ret = signedVal.to_float();
0181 switch (encoding_) {
0182 case Encoding::Stepping:
0183 return (signedVal >= 0 ? ret + 0.5 : ret - 0.5);
0184 case Encoding::Biased:
0185 return ret + 0.5;
0186 default:
0187 return ret;
0188 }
0189 }
0190
0191
0192 Region region_;
0193
0194
0195 Encoding encoding_;
0196
0197
0198 bool bitwise_;
0199
0200
0201 bool slim_;
0202
0203
0204 float rInvToPt_, phiScale_, z0Scale_;
0205
0206
0207 float dEtaBarrelParamZ0_;
0208 float dPhiBarrelParamC_;
0209
0210
0211 float dEtaHGCalParamZ0_, dEtaHGCalParamRInv2C_, dEtaHGCalParamRInv2ITanl1_, dEtaHGCalParamRInv2ITanl2_;
0212 float dPhiHGCalParamZ0_, dPhiHGCalParamC_;
0213
0214
0215 int vtxPhiMult_, vtxPhiOffsPos_, vtxPhiOffsNeg_, vtxPhiBitShift_;
0216
0217
0218 int z0Mult_, z0OffsPos_, z0OffsNeg_, z0BitShift_;
0219
0220
0221 int dEtaBarrelBits_, dEtaBarrelZ0PreShift_, dEtaBarrelZ0PostShift_, dEtaBarrelOffs_, dEtaBarrelZ0_;
0222
0223
0224 int dPhiBarrelBits_, dPhiBarrelRInvPreShift_, dPhiBarrelRInvPostShift_, dPhiBarrelOffs_, dPhiBarrelC_;
0225
0226
0227 int dEtaHGCalBits_, dEtaHGCalZ0PreShift_, dEtaHGCalZ0_, dEtaHGCalRInvPreShift_, dEtaHGCalTanlShift_,
0228 dEtaHGCalLUTShift_, dEtaHGCalTanlTermOffs_, dEtaHGCalTanlTermShift_, dEtaHGCalOffs_;
0229 std::vector<int> dEtaHGCalLUT_;
0230
0231
0232 int dPhiHGCalBits_, dPhiHGCalZ0PreShift_, dPhiHGCalZ0_, dPhiHGCalZ0PostShift_, dPhiHGCalRInvShift_,
0233 dPhiHGCalTanlShift_, dPhiHGCalTanlInvShift_, dPhiHGCalPreOffs_, dPhiHGCalOffs_;
0234 std::vector<int> dPhiHGCalTanlLUT_;
0235
0236
0237 int tanlLUTPreOffs_, tanlLUTShift_, tanlLUTPostOffs_;
0238 std::vector<int> tanlLUT_;
0239 bool tanlLUTSigned_;
0240
0241
0242 int ptLUTShift_;
0243 std::vector<l1ct::pt_t> ptLUT_;
0244
0245
0246 bool debug_;
0247 };
0248 }
0249
0250 #endif