CMS 3D CMS Logo

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 // date: April 9, 2019
8 //
10 
12 #include <iostream>
13 #include <bitset>
14 #include <string>
15 
16 //Constructor - turn track parameters into 96-bit word
17 
19  const GlobalPoint& POCA,
20  double theRinv,
21  double theChi2,
22  double theBendChi2,
23  unsigned int theHitPattern,
24  unsigned int iSpare) {
25  setTrackWord(Momentum, POCA, theRinv, theChi2, theBendChi2, theHitPattern, iSpare);
26 }
27 
29  unsigned int phi0,
30  unsigned int eta,
31  unsigned int z0,
32  unsigned int d0,
33  unsigned int theChi2,
34  unsigned int theBendChi2,
35  unsigned int theHitPattern,
36  unsigned int iSpare)
37  : iRinv(theRinv),
38  iphi(phi0),
39  ieta(eta),
40  iz0(z0),
41  id0(d0),
42  ichi2(theChi2), //revert to other packing? Or will be unpacked wrong
43  iBendChi2(theBendChi2), // revert to ogher packing? Or will be unpacked wrong
44  ispare(iSpare),
45  iHitPattern(theHitPattern) {
46  initialize();
47 }
48 
49 // one for already-digitized values:
50 
51 void TTTrack_TrackWord::setTrackWord(unsigned int theRinv,
52  unsigned int phi0,
53  unsigned int eta,
54  unsigned int z0,
55  unsigned int d0,
56  unsigned int theChi2,
57  unsigned int theBendChi2,
58  unsigned int theHitPattern,
59  unsigned int iSpare) {
60  iRinv = theRinv;
61  iphi = phi0;
62  ieta = eta;
63  iz0 = z0;
64  id0 = d0;
65  ichi2 = theChi2; //revert to other packing? Or will be unpacked wrong
66  iBendChi2 = theBendChi2; // revert to ogher packing? Or will be unpacked wrong
67  ispare = iSpare;
68  iHitPattern = theHitPattern;
69 
70  initialize();
71 }
72 
73 // one for floats:
75  const GlobalPoint& POCA,
76  double theRinv,
77  double theChi2,
78  double theBendChi2,
79  unsigned int theHitPattern,
80  unsigned int iSpare) {
81  initialize();
82 
83  // first, derive quantities to be packed
84 
85  float rPhi = Momentum.phi(); // this needs to be phi relative to center of sector ****
86  float rEta = Momentum.eta();
87  float rZ0 = POCA.z();
88  float rD0 = POCA.perp();
89 
90  // bin, convert to integers, and pack
91 
92  unsigned int seg1, seg2, seg3;
93  seg1 = 0;
94  seg2 = 0;
95  seg3 = 0;
96 
97  //eta
98 
100 
101  //z0
102  iz0 = digitize_Signed(rZ0, NZ0Bits, 0, valLSBZ0);
103 
104  //chi2 has non-linear bins
105 
106  ichi2 = 0;
107 
108  for (unsigned int ibin = 0; ibin < Nchi2; ++ibin) {
109  ichi2 = ibin;
110  if (theChi2 < chi2Bins[ibin])
111  break;
112  }
113 
114  //phi
115  iphi = digitize_Signed(rPhi, NPhiBits, 0, valLSBPhi);
116 
117  //d0
118  id0 = digitize_Signed(rD0, ND0Bits, 0, valLSBD0);
119 
120  //Rinv
121  iRinv = digitize_Signed(theRinv, NCurvBits, 0, valLSBCurv);
122 
123  //bend chi2 - non-linear bins
124  iBendChi2 = 0;
125 
126  for (unsigned int ibin = 0; ibin < NBchi2; ++ibin) {
127  iBendChi2 = ibin;
128  if (theBendChi2 < Bchi2Bins[ibin])
129  break;
130  }
131 
132  ispare = iSpare;
133 
134  // spare bits
135  if (ispare > 0x3FFF)
136  ispare = 0x3FFF;
137 
138  iHitPattern = theHitPattern;
139 
140  //set bits
141  /*
142  Current packing scheme. Any changes here ripple everywhere!
143 
144  uint word1 = 16 (eta) + 12 (z0) + 4 (chi2) = 32 bits
145  uint word2 = 12 (phi) + 13 (d0) + 7 (hitPattern) = 32 bits
146  uint word3 = 15 (pT) + 3 (bend chi2) + 14 (spare/TMVA) = 32 bits
147  */
148 
149  //now pack bits; leave hardcoded for now as am example of how this could work
150 
151  seg1 = (ieta << 16); //take care of word packing later...
152  seg2 = (iz0 << 4);
153  seg3 = ichi2;
154 
155  //set bits
156 
157  TrackWord1 = seg1 + seg2 + seg3;
158  seg1 = 0;
159  seg2 = 0;
160  seg3 = 0;
161 
162  //second 32-bit word
163  seg1 = (iphi << 20);
164  seg2 = (id0 << 7);
165 
166  //HitMask
167  seg3 = theHitPattern;
168 
169  //set bits
170 
171  TrackWord2 = seg1 + seg2 + seg3;
172  seg1 = 0;
173  seg2 = 0;
174  seg3 = 0;
175 
176  //third 32-bit word
177 
178  seg1 = (iRinv << 17);
179  seg2 = (iBendChi2 << 14);
180  seg3 = ispare;
181 
182  TrackWord3 = seg1 + seg2 + seg3;
183 }
184 // unpack
185 
187  unsigned int bits = (TrackWord1 & 0xFFFF0000) >> 16;
188  float unpEta = unpack_Signed(bits, NEtaBits, valLSBEta);
189  return unpEta;
190 }
191 
193  float unpEta = unpack_Signed(ieta, NEtaBits, valLSBEta);
194  return unpEta;
195 }
196 
198  //unsigned int bits = (TrackWord1 & 0xFFFF0000) >> 16;
199  return ieta;
200 }
201 
203  unsigned int bits = (TrackWord1 & 0x0000FFF0) >> 4;
204  float unpZ0 = unpack_Signed(bits, NZ0Bits, valLSBZ0);
205  return unpZ0;
206 }
207 
209  float unpZ0 = unpack_Signed(iz0, NZ0Bits, valLSBZ0);
210  return unpZ0;
211 }
212 
214  //unsigned int bits = (TrackWord1 & 0x0000FFF0) >> 4;
215  return iz0;
216 }
217 
219  unsigned int bits = (TrackWord1 & 0x0000000F);
220  float unpChi2 = chi2Bins[bits];
221  return unpChi2;
222 }
223 
225  float unpChi2 = chi2Bins[ichi2];
226  return unpChi2;
227 }
228 
230  //unsigned int bits = (TrackWord1 & 0x0000000F);
231  return ichi2;
232 }
233 
235  unsigned int bits = (TrackWord2 & 0xFFF00000) >> 20;
236  float unpPhi = unpack_Signed(bits, NPhiBits, valLSBPhi);
237  return unpPhi;
238 }
239 
241  float unpPhi = unpack_Signed(iphi, NPhiBits, valLSBPhi);
242  return unpPhi;
243 }
244 
246  //unsigned int bits = (TrackWord2 & 0xFFF00000) >> 20;
247  return iphi;
248 }
249 
251  unsigned int bits = (TrackWord2 & 0x000FFF80) >> 7;
252  float unpD0 = unpack_Signed(bits, ND0Bits, valLSBD0);
253  return unpD0;
254 }
255 
257  float unpD0 = unpack_Signed(id0, ND0Bits, valLSBD0);
258  return unpD0;
259 }
260 
262  // unsigned int bits = (TrackWord2 & 0x000FFF80) >> 7;
263  return id0;
264 }
265 
267  unsigned int bits = (TrackWord2 & 0x0000007F);
268  return bits;
269 }
270 
272 
274  unsigned int bits = (TrackWord3 & 0xFFFE0000) >> 17;
275  float unpCurv = unpack_Signed(bits, NCurvBits, valLSBCurv);
276  return unpCurv;
277 }
278 
280  float unpCurv = unpack_Signed(iRinv, NCurvBits, valLSBCurv);
281  return unpCurv;
282 }
283 
285  unsigned int bits = (TrackWord3 & 0x0001C000) >> 14;
286  float unpBChi2 = Bchi2Bins[bits];
287  return unpBChi2;
288 }
289 
291  float unpBChi2 = Bchi2Bins[iBendChi2];
292  return unpBChi2;
293 }
294 
296  unsigned int bits = (TrackWord3 & 0x0001C000) >> 14;
297  return bits;
298 }
299 
301  unsigned int bits = (TrackWord3 & 0x00003FFF);
302  return bits;
303 }
304 
305 unsigned int TTTrack_TrackWord::get_ispare() { return ispare; }
306 
307 unsigned int TTTrack_TrackWord::digitize_Signed(float var, unsigned int maxBit, unsigned int minBit, float lsb) {
308  unsigned int nBits = (maxBit - minBit + 1);
309  unsigned int myVar = std::floor(fabs(var) / lsb);
310  unsigned int maxVal = (1 << (nBits - 1)) - 1;
311  if (myVar > maxVal)
312  myVar = maxVal;
313  if (var < 0)
314  myVar = (1 << nBits) - myVar; // two's complement encoding
315  unsigned int seg = myVar;
316  return seg;
317 }
318 
319 float TTTrack_TrackWord::unpack_Signed(unsigned int bits, unsigned int nBits, float lsb) {
320  int isign = 1;
321  unsigned int maxVal = (1 << nBits) - 1;
322  if (bits & (1 << nBits)) { //check sign
323  isign = -1;
324  bits = (1 << (nBits + 1)) - bits; // if negative, flip everything for two's complement encoding
325  }
326  float unpacked = (float(bits & maxVal) + 0.5) * lsb;
327  unpacked = isign * unpacked;
328  return unpacked;
329 }
330 
332  /* bits for packing, constants defined in TTTrack_TrackWord.h :
333 
334  signed quantities (one bit for sign):
335 
336  q/R = 14+1
337  phi = 11+1 (relative to sector center)
338  eta = 15+1
339  z0 = 11+1
340  d0 = 12+1
341 
342  unsigned:
343 
344  chi2 = 4
345  BendChi2 = 3
346  hitPattern = 7
347  Spare = 14
348 
349  */
350 
351  // define bits, 1<<N = 2^N
352 
353  unsigned int CurvBins = (1 << NCurvBits);
354  unsigned int phiBins = (1 << NPhiBits);
355  unsigned int etaBins = (1 << NEtaBits);
356  unsigned int z0Bins = (1 << NZ0Bits);
357  unsigned int d0Bins = (1 << ND0Bits);
358 
359  Nchi2 = (1 << NChi2Bits);
360  NBchi2 = (1 << NBChi2Bits);
361 
362  valLSBCurv = maxCurv / float(CurvBins);
363  valLSBPhi = maxPhi / float(phiBins);
364  valLSBEta = maxEta / float(etaBins);
365  valLSBZ0 = maxZ0 / float(z0Bins);
366  valLSBD0 = maxD0 / float(d0Bins);
367 
368  chi2Bins[0] = 0.25;
369  chi2Bins[1] = 0.5;
370  chi2Bins[2] = 1.0;
371  chi2Bins[3] = 2.;
372  chi2Bins[4] = 3.;
373  chi2Bins[5] = 5.;
374  chi2Bins[6] = 7.;
375  chi2Bins[7] = 10.;
376  chi2Bins[8] = 15.;
377  chi2Bins[9] = 20.;
378  chi2Bins[10] = 40.;
379  chi2Bins[11] = 60.;
380  chi2Bins[12] = 100.;
381  chi2Bins[13] = 200.;
382  chi2Bins[14] = 500.;
383 
384  Bchi2Bins[0] = 0.5;
385  Bchi2Bins[1] = 1.25;
386  Bchi2Bins[2] = 2.0;
387  Bchi2Bins[3] = 3.0;
388  Bchi2Bins[4] = 5.0;
389  Bchi2Bins[5] = 10.;
390  Bchi2Bins[6] = 50.;
391 };
const unsigned int NZ0Bits
const unsigned int NBChi2Bits
unsigned int get_ispare()
const unsigned int NPhiBits
T perp() const
Definition: PV3DBase.h:72
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
const unsigned int NChi2Bits
unsigned int get_BendChi2Bits()
unsigned int unpack_hitPattern()
unsigned int iBendChi2
unsigned int get_d0Bits()
const unsigned int NEtaBits
void setTrackWord(const GlobalVector &Momentum, const GlobalPoint &POCA, double theRinv, double theChi2, double theBendChi2, unsigned int theHitPattern, unsigned int iSpare)
T z() const
Definition: PV3DBase.h:64
unsigned int get_etaBits()
unsigned int unpack_ispare()
const unsigned int NCurvBits
unsigned int get_hitPattern()
unsigned int TrackWord2
float unpack_Signed(unsigned int bits, unsigned int nBits, float lsb)
unsigned int iHitPattern
T eta() const
Definition: PV3DBase.h:76
unsigned int digitize_Signed(float var, unsigned int maxBit, unsigned int minBit, float lsb)
unsigned int TrackWord1
unsigned int get_chi2Bits()
const unsigned int ND0Bits
unsigned int TrackWord3
unsigned int get_phiBits()
unsigned int get_z0Bits()