CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TTTrack_TrackWord.cc
Go to the documentation of this file.
1 //
3 // class to store the 96-bit track word produced by the L1 Track Trigger. Intended to be inherited by L1 TTTrack.
4 // packing scheme given below.
5 //
6 // author: Mike Hildreth
7 // modified by: Alexx Perloff
8 // created: April 9, 2019
9 // modified: March 9, 2021
10 //
12 
15 
16 void tttrack_trackword::infoTestDigitizationScheme(const unsigned int nBits,
17  const double lsb,
18  const double floatingPointValue,
19  const unsigned int digitizedSignedValue,
20  const double undigitizedSignedValue,
21  const unsigned int redigitizedSignedValue) {
22  edm::LogInfo("TTTrack_TrackWord") << "testDigitizationScheme: (nBits, lsb) = (" << nBits << ", " << lsb << ")\n"
23  << "Floating point value = " << floatingPointValue
24  << "\tDigitized value = " << digitizedSignedValue
25  << "\tUn-digitized value = " << undigitizedSignedValue
26  << "\tRe-digitized value = " << redigitizedSignedValue;
27 }
28 
29 //Constructor - turn track parameters into 96-bit word
31  const GlobalVector& momentum,
32  const GlobalPoint& POCA,
33  double rInv,
34  double chi2RPhi, // would be xy chisq if chi2Z is non-zero
35  double chi2RZ,
36  double bendChi2,
37  unsigned int hitPattern,
38  unsigned int mvaQuality,
39  unsigned int mvaOther,
40  unsigned int sector) {
41  setTrackWord(valid, momentum, POCA, rInv, chi2RPhi, chi2RZ, bendChi2, hitPattern, mvaQuality, mvaOther, sector);
42 }
43 
45  unsigned int rInv,
46  unsigned int phi0,
47  unsigned int tanl,
48  unsigned int z0,
49  unsigned int d0,
50  unsigned int chi2RPhi, // would be total chisq if chi2Z is zero
51  unsigned int chi2RZ,
52  unsigned int bendChi2,
53  unsigned int hitPattern,
54  unsigned int mvaQuality,
55  unsigned int mvaOther) {
56  setTrackWord(valid, rInv, phi0, tanl, z0, d0, chi2RPhi, chi2RZ, bendChi2, hitPattern, mvaQuality, mvaOther);
57 }
58 
59 // A setter for the floating point values
60 void TTTrack_TrackWord::setTrackWord(unsigned int valid,
61  const GlobalVector& momentum,
62  const GlobalPoint& POCA,
63  double rInv,
64  double chi2RPhi, // would be total chisq if chi2Z is zero
65  double chi2RZ,
66  double bendChi2,
67  unsigned int hitPattern,
68  unsigned int mvaQuality,
69  unsigned int mvaOther,
70  unsigned int sector) {
71  // first, derive quantities to be packed
72  float rPhi = localPhi(momentum.phi(), sector); // this needs to be phi relative to the center of the sector
73  float rTanl = momentum.z() / momentum.perp();
74  float rZ0 = POCA.z();
75  float rD0 = POCA.perp();
76 
77  // bin and convert to integers
78  valid_t valid_ = valid;
79  rinv_t rInv_ = digitizeSignedValue(rInv, TrackBitWidths::kRinvSize, stepRinv);
80  phi_t phi0_ = digitizeSignedValue(rPhi, TrackBitWidths::kPhiSize, stepPhi0);
81  tanl_t tanl_ = digitizeSignedValue(rTanl, TrackBitWidths::kTanlSize, stepTanL);
82  z0_t z0_ = digitizeSignedValue(rZ0, TrackBitWidths::kZ0Size, stepZ0);
83  d0_t d0_ = digitizeSignedValue(rD0, TrackBitWidths::kD0Size, stepD0);
84  chi2rphi_t chi2RPhi_ = getBin(chi2RPhi, chi2RPhiBins);
85  chi2rz_t chi2RZ_ = getBin(chi2RZ, chi2RZBins);
86  bendChi2_t bendChi2_ = getBin(bendChi2, bendChi2Bins);
87  hit_t hitPattern_ = hitPattern;
88  qualityMVA_t mvaQuality_ = mvaQuality;
89  otherMVA_t mvaOther_ = mvaOther;
90 
91  // pack the track word
92  //trackWord = ( mvaOther_, mvaQuality_, hitPattern_, bendChi2_, chi2RZ_, chi2RPhi_, d0_, z0_, tanl_, phi0_, rInv_, valid_ );
94  valid_, rInv_, phi0_, tanl_, z0_, d0_, chi2RPhi_, chi2RZ_, bendChi2_, hitPattern_, mvaQuality_, mvaOther_);
95 }
96 
97 // A setter for already-digitized values
98 void TTTrack_TrackWord::setTrackWord(unsigned int valid,
99  unsigned int rInv,
100  unsigned int phi0,
101  unsigned int tanl,
102  unsigned int z0,
103  unsigned int d0,
104  unsigned int chi2RPhi, // would be total chisq if chi2Z is zero
105  unsigned int chi2RZ,
106  unsigned int bendChi2,
107  unsigned int hitPattern,
108  unsigned int mvaQuality,
109  unsigned int mvaOther) {
110  // bin and convert to integers
111  valid_t valid_ = valid;
112  rinv_t rInv_ = rInv;
113  phi_t phi0_ = phi0;
114  tanl_t tanl_ = tanl;
115  z0_t z0_ = z0;
116  d0_t d0_ = d0;
117  chi2rphi_t chi2RPhi_ = chi2RPhi;
118  chi2rz_t chi2RZ_ = chi2RZ;
119  bendChi2_t bendChi2_ = bendChi2;
120  hit_t hitPattern_ = hitPattern;
121  qualityMVA_t mvaQuality_ = mvaQuality;
122  otherMVA_t mvaOther_ = mvaOther;
123 
124  // pack the track word
125  //trackWord = ( otherMVA_t(mvaOther), qualityMVA_t(mvaQuality), hit_t(hitPattern),
126  // bendChi2_t(bendChi2), chi2rz_t(chi2RZ), chi2rphi_t(chi2RPhi),
127  // d0_t(d0), z0_t(z0), tanl_t(tanl), phi_t(phi0), rinv_t(rInv), valid_t(valid) );
128  setTrackWord(
129  valid_, rInv_, phi0_, tanl_, z0_, d0_, chi2RPhi_, chi2RZ_, bendChi2_, hitPattern_, mvaQuality_, mvaOther_);
130 }
131 
133  ap_uint<TrackBitWidths::kValidSize> valid,
134  ap_uint<TrackBitWidths::kRinvSize> rInv,
135  ap_uint<TrackBitWidths::kPhiSize> phi0,
136  ap_uint<TrackBitWidths::kTanlSize> tanl,
137  ap_uint<TrackBitWidths::kZ0Size> z0,
138  ap_uint<TrackBitWidths::kD0Size> d0,
139  ap_uint<TrackBitWidths::kChi2RPhiSize> chi2RPhi, // would be total chisq if chi2Z is zero
140  ap_uint<TrackBitWidths::kChi2RZSize> chi2RZ,
141  ap_uint<TrackBitWidths::kBendChi2Size> bendChi2,
142  ap_uint<TrackBitWidths::kHitPatternSize> hitPattern,
143  ap_uint<TrackBitWidths::kMVAQualitySize> mvaQuality,
144  ap_uint<TrackBitWidths::kMVAOtherSize> mvaOther) {
145  // pack the track word
146  unsigned int offset = 0;
147  for (unsigned int b = offset; b < (offset + TrackBitWidths::kMVAOtherSize); b++) {
148  trackWord_.set(b, mvaOther[b - offset]);
149  }
150  offset += TrackBitWidths::kMVAOtherSize;
151  for (unsigned int b = offset; b < (offset + TrackBitWidths::kMVAQualitySize); b++) {
152  trackWord_.set(b, mvaQuality[b - offset]);
153  }
154  offset += TrackBitWidths::kMVAQualitySize;
155  for (unsigned int b = offset; b < (offset + TrackBitWidths::kHitPatternSize); b++) {
156  trackWord_.set(b, hitPattern[b - offset]);
157  }
158  offset += TrackBitWidths::kHitPatternSize;
159  for (unsigned int b = offset; b < (offset + TrackBitWidths::kBendChi2Size); b++) {
160  trackWord_.set(b, bendChi2[b - offset]);
161  }
162  offset += TrackBitWidths::kBendChi2Size;
163  for (unsigned int b = offset; b < (offset + TrackBitWidths::kD0Size); b++) {
164  trackWord_.set(b, d0[b - offset]);
165  }
166  offset += TrackBitWidths::kD0Size;
167  for (unsigned int b = offset; b < (offset + TrackBitWidths::kChi2RZSize); b++) {
168  trackWord_.set(b, chi2RZ[b - offset]);
169  }
170  offset += TrackBitWidths::kChi2RZSize;
171  for (unsigned int b = offset; b < (offset + TrackBitWidths::kZ0Size); b++) {
172  trackWord_.set(b, z0[b - offset]);
173  }
174  offset += TrackBitWidths::kZ0Size;
175  for (unsigned int b = offset; b < (offset + TrackBitWidths::kTanlSize); b++) {
176  trackWord_.set(b, tanl[b - offset]);
177  }
178  offset += TrackBitWidths::kTanlSize;
179  for (unsigned int b = offset; b < (offset + TrackBitWidths::kChi2RPhiSize); b++) {
180  trackWord_.set(b, chi2RPhi[b - offset]);
181  }
182  offset += TrackBitWidths::kChi2RPhiSize;
183  for (unsigned int b = offset; b < (offset + TrackBitWidths::kPhiSize); b++) {
184  trackWord_.set(b, phi0[b - offset]);
185  }
186  offset += TrackBitWidths::kPhiSize;
187  for (unsigned int b = offset; b < (offset + TrackBitWidths::kRinvSize); b++) {
188  trackWord_.set(b, rInv[b - offset]);
189  }
190  offset += TrackBitWidths::kRinvSize;
191  for (unsigned int b = offset; b < offset + TrackBitWidths::kValidSize; b++) {
192  trackWord_.set(b, valid[b - offset]);
193  }
194 }
195 
196 bool TTTrack_TrackWord::singleDigitizationSchemeTest(const double floatingPointValue,
197  const unsigned int nBits,
198  const double lsb) const {
199  unsigned int digitizedSignedValue = digitizeSignedValue(floatingPointValue, nBits, lsb);
200  double undigitizedSignedValue = undigitizeSignedValue(digitizedSignedValue, nBits, lsb);
201  unsigned int redigitizedSignedValue = digitizeSignedValue(undigitizedSignedValue, nBits, lsb);
203  nBits, lsb, floatingPointValue, digitizedSignedValue, undigitizedSignedValue, redigitizedSignedValue);
204  return (std::abs(floatingPointValue - undigitizedSignedValue) <= (lsb / 2.0)) &&
205  (digitizedSignedValue == redigitizedSignedValue);
206 }
207 
209  /*
210  Expected output:
211  testDigitizationScheme: Floating point value = -4 Digitized value = 4 Un-digitized value = -3.5
212  testDigitizationScheme: Floating point value = 3 Digitized value = 3 Un-digitized value = 3.5
213  testDigitizationScheme: Floating point value = -3.5 Digitized value = 9 Un-digitized value = -3.25
214  testDigitizationScheme: Floating point value = 3.5 Digitized value = 7 Un-digitized value = 3.75
215  */
216  assert(singleDigitizationSchemeTest(-4.0, 3, 1.0));
217  assert(singleDigitizationSchemeTest(3.0, 3, 1.0));
218  assert(singleDigitizationSchemeTest(-3.5, 4, 0.5));
219  assert(singleDigitizationSchemeTest(3.5, 4, 0.5));
220 }
static constexpr std::array< double, 1<< TrackBitWidths::kChi2RPhiSize > chi2RPhiBins
T perp() const
Definition: PV3DBase.h:69
ap_uint< TrackBitWidths::kMVAQualitySize > qualityMVA_t
bool singleDigitizationSchemeTest(const double floatingPointValue, const unsigned int nBits, const double lsb) const
double undigitizeSignedValue(unsigned int twosValue, unsigned int nBits, double lsb) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
static constexpr double stepD0
void infoTestDigitizationScheme(const unsigned int, const double, const double, const unsigned int, const double, const unsigned int)
static constexpr std::array< double, 1<< TrackBitWidths::kBendChi2Size > bendChi2Bins
static const uint16_t valid_
Definition: Constants.h:17
assert(be >=bs)
constexpr unsigned int getBin(double value, const T &bins) const
ap_uint< TrackBitWidths::kZ0Size > z0_t
void setTrackWord(unsigned int valid, const GlobalVector &momentum, const GlobalPoint &POCA, double rInv, double chi2RPhi, double chi2RZ, double bendChi2, unsigned int hitPattern, unsigned int mvaQuality, unsigned int mvaOther, unsigned int sector)
static constexpr double stepRinv
unsigned int digitizeSignedValue(double value, unsigned int nBits, double lsb) const
ap_uint< TrackBitWidths::kMVAOtherSize > otherMVA_t
T z() const
Definition: PV3DBase.h:61
void testDigitizationScheme() const
ap_uint< TrackBitWidths::kValidSize > valid_t
ap_uint< TrackBitWidths::kRinvSize > rinv_t
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static constexpr double stepTanL
ap_uint< TrackBitWidths::kHitPatternSize > hit_t
ap_uint< TrackBitWidths::kChi2RZSize > chi2rz_t
Log< level::Info, false > LogInfo
static constexpr float d0
double b
Definition: hdecay.h:118
static constexpr double stepPhi0
float localPhi(float globalPhi, unsigned int sector) const
ap_uint< TrackBitWidths::kTanlSize > tanl_t
static constexpr std::array< double, 1<< TrackBitWidths::kChi2RZSize > chi2RZBins
ap_uint< TrackBitWidths::kD0Size > d0_t
static constexpr double stepZ0
ap_uint< TrackBitWidths::kChi2RPhiSize > chi2rphi_t
ap_uint< TrackBitWidths::kBendChi2Size > bendChi2_t
ap_uint< TrackBitWidths::kPhiSize > phi_t