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;
11 } // namespace edm
12 
13 namespace l1ct {
15  public:
16  enum class Region { Barrel, Endcap, Any }; // but only Endcap supported for now
17 
19  enum class Encoding {
20  Stepping, // J = sign(F) * floor(abs(F)/LSB); F = sign(J) * ( abs(J) + 0.5 ) * LSB
21  Biased, // J = floor(F/LSB); F = (J + 0.5)*LSB
22  Unbiased // J = round(F/LSB); F = J * LSB
23  };
24 
25  TrackInputEmulator(const edm::ParameterSet &iConfig);
27  Encoding encoding = Encoding::Stepping,
28  bool bitwise = true,
29  bool slim = true);
30 
32 
33  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword, const l1ct::PFRegionEmu &sector) const {
34  return decodeTrack(tkword, sector, bitwise_, slim_);
35  }
36  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
38  bool bitwise) const {
39  return decodeTrack(tkword, sector, bitwise, slim_);
40  }
41 
42  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
44  bool bitwise,
45  bool slim) const;
46 
47  //== Unpackers ==
48  static bool valid(const ap_uint<96> &tkword) { return tkword[95]; }
49  static bool charge(const ap_uint<96> &tkword) { return !tkword[94]; }
50 
51  static ap_int<15> signedRinv(const ap_uint<96> &tkword) { return ap_int<15>(tkword(94, 80)); }
52  static ap_int<12> signedZ0(const ap_uint<96> &tkword) { return ap_int<12>(tkword(47, 36)); }
53  static ap_int<16> signedTanl(const ap_uint<96> &tkword) { return ap_int<16>(tkword(63, 48)); }
54  static ap_int<12> signedPhi(const ap_uint<96> &tkword) { return ap_int<12>(tkword(79, 68)); }
55 
56  //=== Floating point conversions ===
58  float floatTanl(ap_int<16> tanl) const { return toFloat_(tanl) / (1 << 12); }
59 
61  float floatEta(ap_int<16> tanl) const;
62 
64  float floatPt(ap_int<15> Rinv) const;
65 
67  float floatPhi(ap_int<12> phi) const;
68 
70  float floatZ0(ap_int<12> z0) const;
71 
72  //=== Configuration of floating point conversions
73  void setRinvToPtFactor(float rInvToPt) { rInvToPt_ = rInvToPt; }
74  void setPhiScale(float phiScale) { phiScale_ = phiScale; }
75  void setZ0Scale(float z0Scale) { z0Scale_ = z0Scale; }
76 
77  //=== Bitwise accurate conversions ===
78  l1ct::pt_t convPt(ap_int<15> Rinv) const;
79 
81  l1ct::glbeta_t convEta(ap_int<16> tanl) const;
82 
84  l1ct::phi_t convPhi(ap_int<12> phi) const;
85 
86  l1ct::z0_t convZ0(ap_int<12> z0) const;
87 
88  //=== Configuration for bitwise accurate conversions ===
89  void configPt(int lutBits);
90 
91  void configEta(int lutBits, int preOffs, int shift, int postOffs, bool lutSigned, bool endcap);
92 
93  void configPhi(int bits);
94 
95  void configZ0(int bits);
96 
97  //=== Track propagation to calo (float parametrization, no rounding) ===
98  //
99  // barrel DEta propagation, in layer-1 units (float parameterization, no rounding)
100  float floatDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
101  // barrel DPhi propagation, in layer-1 units (float parameterization, no rounding)
102  float floatDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
103 
104  void setDEtaBarrelParams(float pZ0) { dEtaBarrelParamZ0_ = pZ0; }
105  void setDPhiBarrelParams(float pC) { dPhiBarrelParamC_ = pC; }
106 
107  //=== Track propagation to calo (bitwise accurate) ===
108  l1ct::tkdeta_t calcDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
109  l1ct::tkdphi_t calcDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
110 
111  //=== Configuration of bitwise accurate propagation to calo ===
114 
115  // endcap DEta propagation, in layer-1 units (float parameterization, no rounding)
116  float floatDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
117  // endcap DPhi propagation, in layer-1 units (float parameterization, no rounding)
118  float floatDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
119 
120  void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2) {
121  dEtaHGCalParamZ0_ = pZ0;
122  dEtaHGCalParamRInv2C_ = pRinv2C;
123  dEtaHGCalParamRInv2ITanl1_ = pRinv2ITanl1;
124  dEtaHGCalParamRInv2ITanl2_ = pRinv2ITanl2;
125  }
126  void setDPhiHGCalParams(float pZ0, float pC) {
127  dPhiHGCalParamZ0_ = pZ0;
128  dPhiHGCalParamC_ = pC;
129  }
130 
131  //=== Track propagation to calo (bitwise accurate) ===
132  l1ct::tkdeta_t calcDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
133  l1ct::tkdphi_t calcDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
134 
135  //=== Configuration of bitwise accurate propagation to calo ===
139  int dEtaHGCalLUTBits,
140  int dEtaHGCalLUTShift,
141  float offs = 0);
145  int dPhiHGCalRInvShift,
148  float offs = 0);
149 
151  static bool mayReachHGCal(ap_int<16> tanl) { return (tanl > 6000) || (tanl < -6000); }
153  static bool withinTracker(ap_int<16> tanl) { return (-25000 < tanl) && (tanl < 25000); }
155  static bool withinBarrel(ap_int<16> tanl) { return (-13000 < tanl) && (tanl < 13000); }
156 
157  void setDebug(bool debug = true) { debug_ = debug; }
158 
159  // access to bare LUTs
160  //const std::vector<int> &dEtaBarrelLUT() const { return dEtaBarrelLUT_; }
161  //const std::vector<int> &dPhiBarrelTanlLUT() const { return dPhiBarrelTanlLUT_; }
162  const std::vector<int> &dEtaHGCalLUT() const { return dEtaHGCalLUT_; }
163  const std::vector<int> &dPhiHGCalTanlLUT() const { return dPhiHGCalTanlLUT_; }
164  const std::vector<int> &tanlLUT() const { return tanlLUT_; }
165  const std::vector<l1ct::pt_t> &ptLUT() const { return ptLUT_; }
166 
167  unsigned int countSetBits(unsigned int n) const {
168  unsigned int count = 0;
169  while (n) {
170  n &= (n - 1);
171  count++;
172  }
173  return count;
174  }
175 
176  protected:
177  // utilities
178  template <int N>
179  inline float toFloat_(ap_int<N> signedVal) const {
180  float ret = signedVal.to_float();
181  switch (encoding_) {
182  case Encoding::Stepping:
183  return (signedVal >= 0 ? ret + 0.5 : ret - 0.5);
184  case Encoding::Biased:
185  return ret + 0.5;
186  default:
187  return ret;
188  }
189  }
190 
193 
196 
198  bool bitwise_;
199 
201  bool slim_;
202 
205 
209 
213 
214  // vtx phi conversion parameters
216 
217  // z0 conversion parameters
219 
220  // deta parameters in barrel region
222 
223  // dphi parameters in barrel region
225 
226  // deta parameters in hgcal region
229  std::vector<int> dEtaHGCalLUT_;
230 
231  // dphi parameters in hgcal region
234  std::vector<int> dPhiHGCalTanlLUT_;
235 
236  // tanl to eta LUT parameters
238  std::vector<int> tanlLUT_;
240 
241  // Rinv to pR LUT parameters
243  std::vector<l1ct::pt_t> ptLUT_;
244 
246  bool debug_;
247  };
248 } // namespace l1ct
249 
250 #endif
float floatDEtaHGCal(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
std::vector< int > tanlLUT_
Definition: tkinput_ref.h:238
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:51
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:53
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:15
bool debug_
enable debug printout in some metods
Definition: tkinput_ref.h:246
bool bitwise_
Whether to run the bitwise accurate or floating point conversions.
Definition: tkinput_ref.h:198
std::pair< l1ct::TkObjEmu, bool > decodeTrack(ap_uint< 96 > tkword, const l1ct::PFRegionEmu &sector) const
Definition: tkinput_ref.h:33
void configPt(int lutBits)
const std::vector< int > & tanlLUT() const
Definition: tkinput_ref.h:164
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:207
static bool withinTracker(ap_int< 16 > tanl)
conservative cut to avoid filling LUTs outside of the tracker range
Definition: tkinput_ref.h:153
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:36
static ap_int< 12 > signedPhi(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:54
std::vector< l1ct::pt_t > ptLUT_
Definition: tkinput_ref.h:243
void configZ0(int bits)
Region region_
Region for which the emulation is configured.
Definition: tkinput_ref.h:192
float dEtaHGCalParamZ0_
Parameters for track propagation in floating point.
Definition: tkinput_ref.h:211
static bool valid(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:48
void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2)
Definition: tkinput_ref.h:120
std::vector< int > dPhiHGCalTanlLUT_
Definition: tkinput_ref.h:234
void setDPhiHGCalParams(float pZ0, float pC)
Definition: tkinput_ref.h:126
static bool charge(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:49
void setDPhiBarrelParams(float pC)
Definition: tkinput_ref.h:105
Encoding
encoding used in the digitized track word
Definition: tkinput_ref.h:19
ap_int< 6 > tkdeta_t
Definition: datatypes.h:16
const std::vector< int > & dPhiHGCalTanlLUT() const
Definition: tkinput_ref.h:163
bool slim_
Whether to unpack and populate also nstubs and various chi2 variables (needed for CompibedID in the e...
Definition: tkinput_ref.h:201
void configPhi(int bits)
void setDEtaBarrelParams(float pZ0)
Definition: tkinput_ref.h:104
void setPhiScale(float phiScale)
Definition: tkinput_ref.h:74
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:21
Encoding encoding_
Encoding used for track word inputs.
Definition: tkinput_ref.h:195
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:52
const std::vector< l1ct::pt_t > & ptLUT() const
Definition: tkinput_ref.h:165
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:151
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
Definition: datatypes.h:10
#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:204
const std::vector< int > & dEtaHGCalLUT() const
Definition: tkinput_ref.h:162
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:73
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:17
void setZ0Scale(float z0Scale)
Definition: tkinput_ref.h:75
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
static edm::ParameterSetDescription getParameterSetDescription()
unsigned int countSetBits(unsigned int n) const
Definition: tkinput_ref.h:167
float floatTanl(ap_int< 16 > tanl) const
just unpack tanl to a float
Definition: tkinput_ref.h:58
void setDebug(bool debug=true)
Definition: tkinput_ref.h:157
TrackInputEmulator(const edm::ParameterSet &iConfig)
std::vector< int > dEtaHGCalLUT_
Definition: tkinput_ref.h:229
float toFloat_(ap_int< N > signedVal) const
Definition: tkinput_ref.h:179
ap_int< 12 > glbeta_t
Definition: datatypes.h:18
static bool withinBarrel(ap_int< 16 > tanl)
conservative cut to avoid filling LUTs outside of the barrel range
Definition: tkinput_ref.h:155
Definition: datatypes.h:8