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);
25  TrackInputEmulator(Region = Region::Endcap, Encoding encoding = Encoding::Stepping, bool bitwise = true);
26 
27  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword, const l1ct::PFRegionEmu &sector) const {
28  return decodeTrack(tkword, sector, bitwise_);
29  }
30  std::pair<l1ct::TkObjEmu, bool> decodeTrack(ap_uint<96> tkword,
32  bool bitwise) const;
33 
34  //== Unpackers ==
35  static bool valid(const ap_uint<96> &tkword) { return tkword[95]; }
36  static bool charge(const ap_uint<96> &tkword) { return !tkword[94]; }
37 
38  static ap_int<15> signedRinv(const ap_uint<96> &tkword) { return ap_int<15>(tkword(94, 80)); }
39  static ap_int<12> signedZ0(const ap_uint<96> &tkword) { return ap_int<12>(tkword(47, 36)); }
40  static ap_int<16> signedTanl(const ap_uint<96> &tkword) { return ap_int<16>(tkword(63, 48)); }
41  static ap_int<12> signedPhi(const ap_uint<96> &tkword) { return ap_int<12>(tkword(79, 68)); }
42 
43  //=== Floating point conversions ===
45  float floatTanl(ap_int<16> tanl) const { return toFloat_(tanl) / (1 << 12); }
46 
48  float floatEta(ap_int<16> tanl) const;
49 
51  float floatPt(ap_int<15> Rinv) const;
52 
54  float floatPhi(ap_int<12> phi) const;
55 
57  float floatZ0(ap_int<12> z0) const;
58 
59  //=== Configuration of floating point conversions
60  void setRinvToPtFactor(float rInvToPt) { rInvToPt_ = rInvToPt; }
61  void setPhiScale(float phiScale) { phiScale_ = phiScale; }
62  void setZ0Scale(float z0Scale) { z0Scale_ = z0Scale; }
63 
64  //=== Bitwise accurate conversions ===
65  l1ct::pt_t convPt(ap_int<15> Rinv) const;
66 
68  l1ct::glbeta_t convEta(ap_int<16> tanl) const;
69 
71  l1ct::phi_t convPhi(ap_int<12> phi) const;
72 
73  l1ct::z0_t convZ0(ap_int<12> z0) const;
74 
75  //=== Configuration for bitwise accurate conversions ===
76  void configPt(int lutBits);
77 
78  void configEta(int lutBits, int preOffs, int shift, int postOffs, bool lutSigned, bool endcap);
79 
80  void configPhi(int bits);
81 
82  void configZ0(int bits);
83 
84  //=== Track propagation to calo (float parametrization, no rounding) ===
85  //
86  // barrel DEta propagation, in layer-1 units (float parameterization, no rounding)
87  float floatDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
88  // barrel DPhi propagation, in layer-1 units (float parameterization, no rounding)
89  float floatDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
90 
91  void setDEtaBarrelParams(float pZ0) { dEtaBarrelParamZ0_ = pZ0; }
92  void setDPhiBarrelParams(float pC) { dPhiBarrelParamC_ = pC; }
93 
94  //=== Track propagation to calo (bitwise accurate) ===
95  l1ct::tkdeta_t calcDEtaBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
96  l1ct::tkdphi_t calcDPhiBarrel(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
97 
98  //=== Configuration of bitwise accurate propagation to calo ===
101 
102  // endcap DEta propagation, in layer-1 units (float parameterization, no rounding)
103  float floatDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
104  // endcap DPhi propagation, in layer-1 units (float parameterization, no rounding)
105  float floatDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
106 
107  void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2) {
108  dEtaHGCalParamZ0_ = pZ0;
109  dEtaHGCalParamRInv2C_ = pRinv2C;
110  dEtaHGCalParamRInv2ITanl1_ = pRinv2ITanl1;
111  dEtaHGCalParamRInv2ITanl2_ = pRinv2ITanl2;
112  }
113  void setDPhiHGCalParams(float pZ0, float pC) {
114  dPhiHGCalParamZ0_ = pZ0;
115  dPhiHGCalParamC_ = pC;
116  }
117 
118  //=== Track propagation to calo (bitwise accurate) ===
119  l1ct::tkdeta_t calcDEtaHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
120  l1ct::tkdphi_t calcDPhiHGCal(ap_int<12> z0, ap_int<15> Rinv, ap_int<16> tanl) const;
121 
122  //=== Configuration of bitwise accurate propagation to calo ===
126  int dEtaHGCalLUTBits,
127  int dEtaHGCalLUTShift,
128  float offs = 0);
132  int dPhiHGCalRInvShift,
135  float offs = 0);
136 
138  static bool mayReachHGCal(ap_int<16> tanl) { return (tanl > 6000) || (tanl < -6000); }
140  static bool withinTracker(ap_int<16> tanl) { return (-25000 < tanl) && (tanl < 25000); }
142  static bool withinBarrel(ap_int<16> tanl) { return (-13000 < tanl) && (tanl < 13000); }
143 
144  void setDebug(bool debug = true) { debug_ = debug; }
145 
146  // access to bare LUTs
147  //const std::vector<int> &dEtaBarrelLUT() const { return dEtaBarrelLUT_; }
148  //const std::vector<int> &dPhiBarrelTanlLUT() const { return dPhiBarrelTanlLUT_; }
149  const std::vector<int> &dEtaHGCalLUT() const { return dEtaHGCalLUT_; }
150  const std::vector<int> &dPhiHGCalTanlLUT() const { return dPhiHGCalTanlLUT_; }
151  const std::vector<int> &tanlLUT() const { return tanlLUT_; }
152  const std::vector<l1ct::pt_t> &ptLUT() const { return ptLUT_; }
153 
154  protected:
155  // utilities
156  template <int N>
157  inline float toFloat_(ap_int<N> signedVal) const {
158  float ret = signedVal.to_float();
159  switch (encoding_) {
160  case Encoding::Stepping:
161  return (signedVal >= 0 ? ret + 0.5 : ret - 0.5);
162  case Encoding::Biased:
163  return ret + 0.5;
164  default:
165  return ret;
166  }
167  }
168 
171 
174 
176  bool bitwise_;
177 
180 
184 
188 
189  // vtx phi conversion parameters
191 
192  // z0 conversion parameters
194 
195  // deta parameters in barrel region
197 
198  // dphi parameters in barrel region
200 
201  // deta parameters in hgcal region
204  std::vector<int> dEtaHGCalLUT_;
205 
206  // dphi parameters in hgcal region
209  std::vector<int> dPhiHGCalTanlLUT_;
210 
211  // tanl to eta LUT parameters
213  std::vector<int> tanlLUT_;
215 
216  // Rinv to pR LUT parameters
218  std::vector<l1ct::pt_t> ptLUT_;
219 
221  bool debug_;
222  };
223 } // namespace l1ct
224 
225 #endif
float floatDEtaHGCal(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
std::vector< int > tanlLUT_
Definition: tkinput_ref.h:213
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:38
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:40
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:26
bool debug_
enable debug printout in some metods
Definition: tkinput_ref.h:221
bool bitwise_
Whether to run the bitwise accurate or floating point conversions.
Definition: tkinput_ref.h:176
std::pair< l1ct::TkObjEmu, bool > decodeTrack(ap_uint< 96 > tkword, const l1ct::PFRegionEmu &sector) const
Definition: tkinput_ref.h:27
void configPt(int lutBits)
constexpr uint32_t bits
Definition: gpuClustering.h:25
const std::vector< int > & tanlLUT() const
Definition: tkinput_ref.h:151
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:182
static bool withinTracker(ap_int< 16 > tanl)
conservative cut to avoid filling LUTs outside of the tracker range
Definition: tkinput_ref.h:140
float floatDEtaBarrel(ap_int< 12 > z0, ap_int< 15 > Rinv, ap_int< 16 > tanl) const
static ap_int< 12 > signedPhi(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:41
std::vector< l1ct::pt_t > ptLUT_
Definition: tkinput_ref.h:218
void configZ0(int bits)
Region region_
Region for which the emulation is configured.
Definition: tkinput_ref.h:170
float dEtaHGCalParamZ0_
Parameters for track propagation in floating point.
Definition: tkinput_ref.h:186
static bool valid(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:35
void setDEtaHGCalParams(float pZ0, float pRinv2C, float pRinv2ITanl1, float pRinv2ITanl2)
Definition: tkinput_ref.h:107
std::vector< int > dPhiHGCalTanlLUT_
Definition: tkinput_ref.h:209
void setDPhiHGCalParams(float pZ0, float pC)
Definition: tkinput_ref.h:113
static bool charge(const ap_uint< 96 > &tkword)
Definition: tkinput_ref.h:36
void setDPhiBarrelParams(float pC)
Definition: tkinput_ref.h:92
Encoding
encoding used in the digitized track word
Definition: tkinput_ref.h:18
ap_int< 6 > tkdeta_t
Definition: datatypes.h:27
const std::vector< int > & dPhiHGCalTanlLUT() const
Definition: tkinput_ref.h:150
void configPhi(int bits)
void setDEtaBarrelParams(float pZ0)
Definition: tkinput_ref.h:91
void setPhiScale(float phiScale)
Definition: tkinput_ref.h:61
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:32
Encoding encoding_
Encoding used for track word inputs.
Definition: tkinput_ref.h:173
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:39
const std::vector< l1ct::pt_t > & ptLUT() const
Definition: tkinput_ref.h:152
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:138
ap_ufixed< 14, 12, AP_TRN, AP_SAT > pt_t
Definition: datatypes.h:21
#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:179
const std::vector< int > & dEtaHGCalLUT() const
Definition: tkinput_ref.h:149
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:60
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:28
void setZ0Scale(float z0Scale)
Definition: tkinput_ref.h:62
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
float floatTanl(ap_int< 16 > tanl) const
just unpack tanl to a float
Definition: tkinput_ref.h:45
void setDebug(bool debug=true)
Definition: tkinput_ref.h:144
TrackInputEmulator(const edm::ParameterSet &iConfig)
std::vector< int > dEtaHGCalLUT_
Definition: tkinput_ref.h:204
float toFloat_(ap_int< N > signedVal) const
Definition: tkinput_ref.h:157
ap_int< 12 > glbeta_t
Definition: datatypes.h:29
static bool withinBarrel(ap_int< 16 > tanl)
conservative cut to avoid filling LUTs outside of the barrel range
Definition: tkinput_ref.h:142
Definition: datatypes.h:19