CMS 3D CMS Logo

tkinput_ref.h
Go to the documentation of this file.
1 #ifndef L1Trigger_Phase2L1ParticleFlow_l1converters_tracks_tkinput_ref_h
2 #define L1Trigger_Phase2L1ParticleFlow_l1converters_tracks_tkinput_ref_h
3 
5 #include <cstdio>
6 #include <algorithm>
7 
8 namespace edm {
9  class ParameterSet;
10 }
11 
12 namespace l1ct {
14  public:
15  enum class Region { Barrel, Endcap, Any }; // but only Endcap supported for now
16 
18  enum class Encoding {
19  Stepping, // J = sign(F) * floor(abs(F)/LSB); F = sign(J) * ( abs(J) + 0.5 ) * LSB
20  Biased, // J = floor(F/LSB); F = (J + 0.5)*LSB
21  Unbiased // J = round(F/LSB); F = J * LSB
22  };
23 
24  TrackInputEmulator(const edm::ParameterSet &iConfig);
26  Encoding encoding = Encoding::Stepping,
27  bool bitwise = true,
28  bool slim = true);
29 
30  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword, const l1ct::PFRegionEmu &sector) const {
31  return decodeTrack(tkword, sector, bitwise_, slim_);
32  }
33  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
35  bool bitwise) const {
36  return decodeTrack(tkword, sector, bitwise, slim_);
37  }
38 
39  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
41  bool bitwise,
42  bool slim) const;
43 
44  //== Unpackers ==
45  static bool valid(const ap_uint<96> &tkword) { return tkword[95]; }
46  static bool charge(const ap_uint<96> &tkword) { return !tkword[94]; }
47 
48  static ap_int<15> signedRinv(const ap_uint<96> &tkword) { return ap_int<15>(tkword(94, 80)); }
49  static ap_int<12> signedZ0(const ap_uint<96> &tkword) { return ap_int<12>(tkword(47, 36)); }
50  static ap_int<16> signedTanl(const ap_uint<96> &tkword) { return ap_int<16>(tkword(63, 48)); }
51  static ap_int<12> signedPhi(const ap_uint<96> &tkword) { return ap_int<12>(tkword(79, 68)); }
52 
53  //=== Floating point conversions ===
55  float floatTanl(ap_int<16> tanl) const { return toFloat_(tanl) / (1 << 12); }
56 
58  float floatEta(ap_int<16> tanl) const;
59 
61  float floatPt(ap_int<15> Rinv) const;
62 
64  float floatPhi(ap_int<12> phi) const;
65 
67  float floatZ0(ap_int<12> z0) const;
68 
69  //=== Configuration of floating point conversions
70  void setRinvToPtFactor(float rInvToPt) { rInvToPt_ = rInvToPt; }
71  void setPhiScale(float phiScale) { phiScale_ = phiScale; }
72  void setZ0Scale(float z0Scale) { z0Scale_ = z0Scale; }
73 
74  //=== Bitwise accurate conversions ===
75  l1ct::pt_t convPt(ap_int<15> Rinv) const;
76 
78  l1ct::glbeta_t convEta(ap_int<16> tanl) const;
79 
81  l1ct::phi_t convPhi(ap_int<12> phi) const;
82 
83  l1ct::z0_t convZ0(ap_int<12> z0) const;
84 
85  //=== Configuration for bitwise accurate conversions ===
86  void configPt(int lutBits);
87 
88  void configEta(int lutBits, int preOffs, int shift, int postOffs, bool lutSigned, bool endcap);
89 
90  void configPhi(int bits);
91 
92  void configZ0(int bits);
93 
94  //=== Track propagation to calo (float parametrization, no rounding) ===
95  //
96  // barrel DEta propagation, in layer-1 units (float parameterization, no rounding)
97  float floatDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
98  // barrel DPhi propagation, in layer-1 units (float parameterization, no rounding)
99  float floatDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
100 
101  void setDEtaBarrelParams(float pZ0) { dEtaBarrelParamZ0_ = pZ0; }
102  void setDPhiBarrelParams(float pC) { dPhiBarrelParamC_ = pC; }
103 
104  //=== Track propagation to calo (bitwise accurate) ===
105  l1ct::tkdeta_t calcDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
106  l1ct::tkdphi_t calcDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
107 
108  //=== Configuration of bitwise accurate propagation to calo ===
111 
112  // endcap DEta propagation, in layer-1 units (float parameterization, no rounding)
113  float floatDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
114  // endcap DPhi propagation, in layer-1 units (float parameterization, no rounding)
115  float floatDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
116 
117  void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2) {
118  dEtaHGCalParamZ0_ = pZ0;
119  dEtaHGCalParamRInv2C_ = pRinv2C;
120  dEtaHGCalParamRInv2ITanl1_ = pRinv2ITanl1;
121  dEtaHGCalParamRInv2ITanl2_ = pRinv2ITanl2;
122  }
123  void setDPhiHGCalParams(float pZ0, float pC) {
124  dPhiHGCalParamZ0_ = pZ0;
125  dPhiHGCalParamC_ = pC;
126  }
127 
128  //=== Track propagation to calo (bitwise accurate) ===
129  l1ct::tkdeta_t calcDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
130  l1ct::tkdphi_t calcDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
131 
132  //=== Configuration of bitwise accurate propagation to calo ===
136  int dEtaHGCalLUTBits,
137  int dEtaHGCalLUTShift,
138  float offs = 0);
142  int dPhiHGCalRInvShift,
145  float offs = 0);
146 
148  static bool mayReachHGCal(ap_int<16> tanl) { return (tanl > 6000) || (tanl < -6000); }
150  static bool withinTracker(ap_int<16> tanl) { return (-25000 < tanl) && (tanl < 25000); }
152  static bool withinBarrel(ap_int<16> tanl) { return (-13000 < tanl) && (tanl < 13000); }
153 
154  void setDebug(bool debug = true) { debug_ = debug; }
155 
156  // access to bare LUTs
157  //const std::vector<int> &dEtaBarrelLUT() const { return dEtaBarrelLUT_; }
158  //const std::vector<int> &dPhiBarrelTanlLUT() const { return dPhiBarrelTanlLUT_; }
159  const std::vector<int> &dEtaHGCalLUT() const { return dEtaHGCalLUT_; }
160  const std::vector<int> &dPhiHGCalTanlLUT() const { return dPhiHGCalTanlLUT_; }
161  const std::vector<int> &tanlLUT() const { return tanlLUT_; }
162  const std::vector<l1ct::pt_t> &ptLUT() const { return ptLUT_; }
163 
164  unsigned int countSetBits(unsigned int n) const {
165  unsigned int count = 0;
166  while (n) {
167  n &= (n - 1);
168  count++;
169  }
170  return count;
171  }
172 
173  protected:
174  // utilities
175  template <int N>
176  inline float toFloat_(ap_int<N> signedVal) const {
177  float ret = signedVal.to_float();
178  switch (encoding_) {
179  case Encoding::Stepping:
180  return (signedVal >= 0 ? ret + 0.5 : ret - 0.5);
181  case Encoding::Biased:
182  return ret + 0.5;
183  default:
184  return ret;
185  }
186  }
187 
190 
193 
195  bool bitwise_;
196 
198  bool slim_;
199 
202 
206 
210 
211  // vtx phi conversion parameters
213 
214  // z0 conversion parameters
216 
217  // deta parameters in barrel region
219 
220  // dphi parameters in barrel region
222 
223  // deta parameters in hgcal region
226  std::vector<int> dEtaHGCalLUT_;
227 
228  // dphi parameters in hgcal region
231  std::vector<int> dPhiHGCalTanlLUT_;
232 
233  // tanl to eta LUT parameters
235  std::vector<int> tanlLUT_;
237 
238  // Rinv to pR LUT parameters
240  std::vector<l1ct::pt_t> ptLUT_;
241 
243  bool debug_;
244  };
245 } // namespace l1ct
246 
247 #endif
float floatDEtaHGCal(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
std::vector< int > tanlLUT_
Definition: tkinput_ref.h:235
float floatEta(ap_int< 16 > tanl) const
convert track-word int tanl into float eta (at vertex) in radiants (exact)
l1ct::tkdeta_t calcDEtaBarrel(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
static ap_int< 15 > signedRinv(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:48
void configEta(int lutBits, int preOffs, int shift, int postOffs, bool lutSigned, bool endcap)
static ap_int< 16 > signedTanl(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:50
float floatZ0(ap_int< 12 > z0) const
convert track-word int z0 into float z0 in cm (exact)
ret
prodAgent to be discontinued
ap_int< 10 > phi_t
Definition: datatypes.h:24
bool debug_
enable debug printout in some metods
Definition: tkinput_ref.h:243
bool bitwise_
Whether to run the bitwise accurate or floating point conversions.
Definition: tkinput_ref.h:195
std::pair< l1ct::TkObjEmu, bool > decodeTrack(ap_uint< 96 > tkword, const l1ct::PFRegionEmu &sector) const
Definition: tkinput_ref.h:30
void configPt(int lutBits)
constexpr uint32_t bits
Definition: gpuClustering.h:25
const std::vector< int > & tanlLUT() const
Definition: tkinput_ref.h:161
void configDEtaHGCal(int dEtaHGCalBits, int dEtaHGCalZ0PreShift, int dEtaHGCalRInvPreShift, int dEtaHGCalLUTBits, int dEtaHGCalLUTShift, float offs=0)
float dEtaBarrelParamZ0_
Parameters for track propagation in floating point.
Definition: tkinput_ref.h:204
static bool withinTracker(ap_int< 16 > tanl)
conservative cut to avoid filling LUTs outside of the tracker range
Definition: tkinput_ref.h:150
float floatDEtaBarrel(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
std::pair< l1ct::TkObjEmu, bool > decodeTrack(ap_uint< 96 > tkword, const l1ct::PFRegionEmu &sector, bool bitwise) const
Definition: tkinput_ref.h:33
static ap_int< 12 > signedPhi(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:51
std::vector< l1ct::pt_t > ptLUT_
Definition: tkinput_ref.h:240
void configZ0(int bits)
Region region_
Region for which the emulation is configured.
Definition: tkinput_ref.h:189
float dEtaHGCalParamZ0_
Parameters for track propagation in floating point.
Definition: tkinput_ref.h:208
static bool valid(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:45
void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2)
Definition: tkinput_ref.h:117
std::vector< int > dPhiHGCalTanlLUT_
Definition: tkinput_ref.h:231
void setDPhiHGCalParams(float pZ0, float pC)
Definition: tkinput_ref.h:123
static bool charge(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:46
void setDPhiBarrelParams(float pC)
Definition: tkinput_ref.h:102
Encoding
encoding used in the digitized track word
Definition: tkinput_ref.h:18
ap_int< 6 > tkdeta_t
Definition: datatypes.h:25
const std::vector< int > & dPhiHGCalTanlLUT() const
Definition: tkinput_ref.h:160
bool slim_
Whether to unpack and populate also nstubs and various chi2 variables (needed for CompibedID in the e...
Definition: tkinput_ref.h:198
void configPhi(int bits)
void setDEtaBarrelParams(float pZ0)
Definition: tkinput_ref.h:101
void setPhiScale(float phiScale)
Definition: tkinput_ref.h:71
l1ct::z0_t convZ0(ap_int< 12 > z0) const
l1ct::tkdphi_t calcDPhiHGCal(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
float floatPhi(ap_int< 12 > phi) const
convert track-word int phi into float phi (at vertex) in radiants (exact)
void configDEtaBarrel(int dEtaBarrelBits, int dEtaBarrelZ0PreShift, int dEtaBarrelZ0PostShift, float offs=0)
void configDPhiHGCal(int dPhiHGCalBits, int dPhiHGCalZ0PreShift, int dPhiHGCalZ0PostShift, int dPhiHGCalRInvShift, int dPhiHGCalTanlInvShift, int dPhiHGCalTanlLUTBits, float offs=0)
float floatPt(ap_int< 15 > Rinv) const
convert track-word Rinv into float pt (almost exact)
ap_int< 10 > z0_t
Definition: datatypes.h:30
Encoding encoding_
Encoding used for track word inputs.
Definition: tkinput_ref.h:192
l1ct::tkdphi_t calcDPhiBarrel(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
static ap_int< 12 > signedZ0(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:49
const std::vector< l1ct::pt_t > & ptLUT() const
Definition: tkinput_ref.h:162
float floatDPhiBarrel(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
l1ct::pt_t convPt(ap_int< 15 > Rinv) const
l1ct::glbeta_t convEta(ap_int< 16 > tanl) const
convert track-word int tanl into eta at vertex in layer 1 units
static bool mayReachHGCal(ap_int< 16 > tanl)
conservative cut to select tracks that may have |eta| > 1.25 or |calo eta| > 1.25 ...
Definition: tkinput_ref.h:148
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
Definition: datatypes.h:19
#define debug
Definition: HDRShower.cc:19
void configDPhiBarrel(int dPhiBarrelBits, int dPhiBarrelRInvPreShift, int dPhiBarrelRInvPostShift, float offs=0)
float rInvToPt_
Main constants.
Definition: tkinput_ref.h:201
const std::vector< int > & dEtaHGCalLUT() const
Definition: tkinput_ref.h:159
l1ct::tkdeta_t calcDEtaHGCal(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
void setRinvToPtFactor(float rInvToPt)
Definition: tkinput_ref.h:70
HLT enums.
float floatDPhiHGCal(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
ap_uint< 7 > tkdphi_t
Definition: datatypes.h:26
void setZ0Scale(float z0Scale)
Definition: tkinput_ref.h:72
static unsigned int const shift
l1ct::phi_t convPhi(ap_int< 12 > phi) const
convert track-word int phi into phi at vertex in layer 1 units
unsigned int countSetBits(unsigned int n) const
Definition: tkinput_ref.h:164
float floatTanl(ap_int< 16 > tanl) const
just unpack tanl to a float
Definition: tkinput_ref.h:55
void setDebug(bool debug=true)
Definition: tkinput_ref.h:154
TrackInputEmulator(const edm::ParameterSet &iConfig)
std::vector< int > dEtaHGCalLUT_
Definition: tkinput_ref.h:226
float toFloat_(ap_int< N > signedVal) const
Definition: tkinput_ref.h:176
ap_int< 12 > glbeta_t
Definition: datatypes.h:27
static bool withinBarrel(ap_int< 16 > tanl)
conservative cut to avoid filling LUTs outside of the barrel range
Definition: tkinput_ref.h:152
Definition: datatypes.h:17