CMS 3D CMS Logo

PtAssignmentEngine2016.cc
Go to the documentation of this file.
3 
4 #include <iostream>
5 #include <sstream>
6 
9  return instance;
10 }
11 
12 float PtAssignmentEngine2016::scale_pt(const float pt, const int mode) const {
13  // Scaling to achieve 90% efficency at any given L1 pT threshold
14  // For 2016, was a flat scaling factor of 1.4
15  float pt_scale = 1.4;
16  return pt_scale;
17 }
18 
19 float PtAssignmentEngine2016::unscale_pt(const float pt, const int mode) const {
20  float pt_unscale = 1. / 1.4;
21  return pt_unscale;
22 }
23 
25  address_t address = 0;
26 
27  const EMTFPtLUT& ptlut_data = track.PtLUT();
28 
29  int mode_inv = track.Mode_inv();
30  int theta = track.Theta_fp();
31  theta >>= 2; // truncate from 7-bit to 5-bit
32 
33  int dPhi12 = ptlut_data.delta_ph[0];
34  int dPhi13 = ptlut_data.delta_ph[1];
35  int dPhi14 = ptlut_data.delta_ph[2];
36  int dPhi23 = ptlut_data.delta_ph[3];
37  int dPhi24 = ptlut_data.delta_ph[4];
38  int dPhi34 = ptlut_data.delta_ph[5];
39  int dTheta12 = ptlut_data.delta_th[0];
40  int dTheta13 = ptlut_data.delta_th[1];
41  int dTheta14 = ptlut_data.delta_th[2];
42  int dTheta23 = ptlut_data.delta_th[3];
43  int dTheta24 = ptlut_data.delta_th[4];
44  int dTheta34 = ptlut_data.delta_th[5];
45  int FR1 = ptlut_data.fr[0];
46  int FR2 = ptlut_data.fr[1];
47  int FR3 = ptlut_data.fr[2];
48  int FR4 = ptlut_data.fr[3];
49 
50  int sign12 = ptlut_data.sign_ph[0];
51  int sign13 = ptlut_data.sign_ph[1];
52  int sign14 = ptlut_data.sign_ph[2];
53  int sign23 = ptlut_data.sign_ph[3];
54  int sign24 = ptlut_data.sign_ph[4];
55  int sign34 = ptlut_data.sign_ph[5];
56  int dTheta12Sign = ptlut_data.sign_th[0];
57  int dTheta13Sign = ptlut_data.sign_th[1];
58  int dTheta14Sign = ptlut_data.sign_th[2];
59  int dTheta23Sign = ptlut_data.sign_th[3];
60  int dTheta24Sign = ptlut_data.sign_th[4];
61  int dTheta34Sign = ptlut_data.sign_th[5];
62 
63  int CLCT1 = std::abs(aux().getCLCT(ptlut_data.cpattern[0]));
64  int CLCT2 = std::abs(aux().getCLCT(ptlut_data.cpattern[1]));
65  int CLCT3 = std::abs(aux().getCLCT(ptlut_data.cpattern[2]));
66  int CLCT4 = std::abs(aux().getCLCT(ptlut_data.cpattern[3]));
67  int CLCT1Sign = (aux().getCLCT(ptlut_data.cpattern[0]) > 0);
68  int CLCT2Sign = (aux().getCLCT(ptlut_data.cpattern[1]) > 0);
69  int CLCT3Sign = (aux().getCLCT(ptlut_data.cpattern[2]) > 0);
70  int CLCT4Sign = (aux().getCLCT(ptlut_data.cpattern[3]) > 0);
71 
72  int CSCID1 = (ptlut_data.bt_vi[0] == 0 && ptlut_data.bt_vi[1] != 0) ? ptlut_data.bt_ci[1] + 16 : ptlut_data.bt_ci[0];
73  int CSCID2 = ptlut_data.bt_ci[2];
74  int CSCID3 = ptlut_data.bt_ci[3];
75  int CSCID4 = ptlut_data.bt_ci[4];
76 
77  auto get_signed_int = [](int var, int sign) { return (sign == 1) ? (var * 1) : (var * -1); };
78 
79  dTheta12 = aux().getdTheta(get_signed_int(dTheta12, dTheta12Sign));
80  dTheta13 = aux().getdTheta(get_signed_int(dTheta13, dTheta13Sign));
81  dTheta14 = aux().getdTheta(get_signed_int(dTheta14, dTheta14Sign));
82  dTheta23 = aux().getdTheta(get_signed_int(dTheta23, dTheta23Sign));
83  dTheta24 = aux().getdTheta(get_signed_int(dTheta24, dTheta24Sign));
84  dTheta34 = aux().getdTheta(get_signed_int(dTheta34, dTheta34Sign));
85 
86  bool use_FRLUT = true;
87  if (use_FRLUT) {
88  if (CSCID1 >= 16)
89  FR1 = aux().getFRLUT(track.Sector(), 1, CSCID1 - 16);
90  else
91  FR1 = aux().getFRLUT(track.Sector(), 0, CSCID1);
92  FR2 = aux().getFRLUT(track.Sector(), 2, CSCID2);
93  FR3 = aux().getFRLUT(track.Sector(), 3, CSCID3);
94  FR4 = aux().getFRLUT(track.Sector(), 4, CSCID4);
95  }
96 
97  switch (mode_inv) {
98  case 3: // 1-2
99  if (!bug9BitDPhi_)
100  dPhi12 = std::min(511, dPhi12);
101 
102  address |= (dPhi12 & ((1 << 9) - 1)) << (0);
103  address |= (sign12 & ((1 << 1) - 1)) << (0 + 9);
104  address |= (dTheta12 & ((1 << 3) - 1)) << (0 + 9 + 1);
105  address |= (CLCT1 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3);
106  address |= (CLCT1Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2);
107  address |= (CLCT2 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3 + 2 + 1);
108  address |= (CLCT2Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2);
109  address |= (FR1 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1);
110  address |= (FR2 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1);
111  address |= (theta & ((1 << 5) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1);
112  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1 + 5);
113  break;
114 
115  case 5: // 1-3
116  if (!bug9BitDPhi_)
117  dPhi13 = std::min(511, dPhi13);
118 
119  address |= (dPhi13 & ((1 << 9) - 1)) << (0);
120  address |= (sign13 & ((1 << 1) - 1)) << (0 + 9);
121  address |= (dTheta13 & ((1 << 3) - 1)) << (0 + 9 + 1);
122  address |= (CLCT1 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3);
123  address |= (CLCT1Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2);
124  address |= (CLCT3 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3 + 2 + 1);
125  address |= (CLCT3Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2);
126  address |= (FR1 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1);
127  address |= (FR3 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1);
128  address |= (theta & ((1 << 5) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1);
129  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1 + 5);
130  break;
131 
132  case 9: // 1-4
133  if (!bug9BitDPhi_)
134  dPhi14 = std::min(511, dPhi14);
135 
136  address |= (dPhi14 & ((1 << 9) - 1)) << (0);
137  address |= (sign14 & ((1 << 1) - 1)) << (0 + 9);
138  address |= (dTheta14 & ((1 << 3) - 1)) << (0 + 9 + 1);
139  address |= (CLCT1 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3);
140  address |= (CLCT1Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2);
141  address |= (CLCT4 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3 + 2 + 1);
142  address |= (CLCT4Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2);
143  address |= (FR1 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1);
144  address |= (FR4 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1);
145  address |= (theta & ((1 << 5) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1);
146  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1 + 5);
147  break;
148 
149  case 6: // 2-3
150  if (!bug9BitDPhi_)
151  dPhi23 = std::min(511, dPhi23);
152 
153  address |= (dPhi23 & ((1 << 9) - 1)) << (0);
154  address |= (sign23 & ((1 << 1) - 1)) << (0 + 9);
155  address |= (dTheta23 & ((1 << 3) - 1)) << (0 + 9 + 1);
156  address |= (CLCT2 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3);
157  address |= (CLCT2Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2);
158  address |= (CLCT3 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3 + 2 + 1);
159  address |= (CLCT3Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2);
160  address |= (FR2 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1);
161  address |= (FR3 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1);
162  address |= (theta & ((1 << 5) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1);
163  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1 + 5);
164  break;
165 
166  case 10: // 2-4
167  if (!bug9BitDPhi_)
168  dPhi24 = std::min(511, dPhi24);
169 
170  address |= (dPhi24 & ((1 << 9) - 1)) << (0);
171  address |= (sign24 & ((1 << 1) - 1)) << (0 + 9);
172  address |= (dTheta24 & ((1 << 3) - 1)) << (0 + 9 + 1);
173  address |= (CLCT2 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3);
174  address |= (CLCT2Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2);
175  address |= (CLCT4 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3 + 2 + 1);
176  address |= (CLCT4Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2);
177  address |= (FR2 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1);
178  address |= (FR4 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1);
179  address |= (theta & ((1 << 5) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1);
180  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1 + 5);
181  break;
182 
183  case 12: // 3-4
184  if (!bug9BitDPhi_)
185  dPhi34 = std::min(511, dPhi34);
186 
187  address |= (dPhi34 & ((1 << 9) - 1)) << (0);
188  address |= (sign34 & ((1 << 1) - 1)) << (0 + 9);
189  address |= (dTheta34 & ((1 << 3) - 1)) << (0 + 9 + 1);
190  address |= (CLCT3 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3);
191  address |= (CLCT3Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2);
192  address |= (CLCT4 & ((1 << 2) - 1)) << (0 + 9 + 1 + 3 + 2 + 1);
193  address |= (CLCT4Sign & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2);
194  address |= (FR3 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1);
195  address |= (FR4 & ((1 << 1) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1);
196  address |= (theta & ((1 << 5) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1);
197  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1 + 5);
198  break;
199 
200  case 7: // 1-2-3
201  dPhi12 = aux().getNLBdPhiBin(dPhi12, 7, 512);
202  dPhi23 = aux().getNLBdPhiBin(dPhi23, 5, 256);
203 
204  address |= (dPhi12 & ((1 << 7) - 1)) << (0);
205  address |= (dPhi23 & ((1 << 5) - 1)) << (0 + 7);
206  address |= (sign12 & ((1 << 1) - 1)) << (0 + 7 + 5);
207  address |= (sign23 & ((1 << 1) - 1)) << (0 + 7 + 5 + 1);
208  address |= (dTheta13 & ((1 << 3) - 1)) << (0 + 7 + 5 + 1 + 1);
209  address |= (CLCT1 & ((1 << 2) - 1)) << (0 + 7 + 5 + 1 + 1 + 3);
210  address |= (CLCT1Sign & ((1 << 1) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2);
211  address |= (FR1 & ((1 << 1) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1);
212  address |= (theta & ((1 << 5) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1);
213  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1 + 5);
214  break;
215 
216  case 11: // 1-2-4
217  dPhi12 = aux().getNLBdPhiBin(dPhi12, 7, 512);
218  dPhi24 = aux().getNLBdPhiBin(dPhi24, 5, 256);
219 
220  address |= (dPhi12 & ((1 << 7) - 1)) << (0);
221  address |= (dPhi24 & ((1 << 5) - 1)) << (0 + 7);
222  address |= (sign12 & ((1 << 1) - 1)) << (0 + 7 + 5);
223  address |= (sign24 & ((1 << 1) - 1)) << (0 + 7 + 5 + 1);
224  address |= (dTheta14 & ((1 << 3) - 1)) << (0 + 7 + 5 + 1 + 1);
225  address |= (CLCT1 & ((1 << 2) - 1)) << (0 + 7 + 5 + 1 + 1 + 3);
226  address |= (CLCT1Sign & ((1 << 1) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2);
227  address |= (FR1 & ((1 << 1) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1);
228  address |= (theta & ((1 << 5) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1);
229  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1 + 5);
230  break;
231 
232  case 13: // 1-3-4
233  dPhi13 = aux().getNLBdPhiBin(dPhi13, 7, 512);
234  dPhi34 = aux().getNLBdPhiBin(dPhi34, 5, 256);
235 
236  address |= (dPhi13 & ((1 << 7) - 1)) << (0);
237  address |= (dPhi34 & ((1 << 5) - 1)) << (0 + 7);
238  address |= (sign13 & ((1 << 1) - 1)) << (0 + 7 + 5);
239  address |= (sign34 & ((1 << 1) - 1)) << (0 + 7 + 5 + 1);
240  address |= (dTheta14 & ((1 << 3) - 1)) << (0 + 7 + 5 + 1 + 1);
241  address |= (CLCT1 & ((1 << 2) - 1)) << (0 + 7 + 5 + 1 + 1 + 3);
242  address |= (CLCT1Sign & ((1 << 1) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2);
243  address |= (FR1 & ((1 << 1) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1);
244  address |= (theta & ((1 << 5) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1);
245  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1 + 5);
246  break;
247 
248  case 14: // 2-3-4
249  dPhi23 = aux().getNLBdPhiBin(dPhi23, 7, 512);
250  dPhi34 = aux().getNLBdPhiBin(dPhi34, 6, 256);
251 
252  address |= (dPhi23 & ((1 << 7) - 1)) << (0);
253  address |= (dPhi34 & ((1 << 6) - 1)) << (0 + 7);
254  address |= (sign23 & ((1 << 1) - 1)) << (0 + 7 + 6);
255  address |= (sign34 & ((1 << 1) - 1)) << (0 + 7 + 6 + 1);
256  address |= (dTheta24 & ((1 << 3) - 1)) << (0 + 7 + 6 + 1 + 1);
257  address |= (CLCT2 & ((1 << 2) - 1)) << (0 + 7 + 6 + 1 + 1 + 3);
258  address |= (CLCT2Sign & ((1 << 1) - 1)) << (0 + 7 + 6 + 1 + 1 + 3 + 2);
259  address |= (theta & ((1 << 5) - 1)) << (0 + 7 + 6 + 1 + 1 + 3 + 2 + 1);
260  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 7 + 6 + 1 + 1 + 3 + 2 + 1 + 5);
261  break;
262 
263  case 15: // 1-2-3-4
264  // Set sign23 and sign34 relative to sign12
265  if (!sign12) {
266  sign23 = !sign23;
267  sign34 = !sign34;
268  }
269 
270  dPhi12 = aux().getNLBdPhiBin(dPhi12, 7, 512);
271  dPhi23 = aux().getNLBdPhiBin(dPhi23, 5, 256);
272  dPhi34 = aux().getNLBdPhiBin(dPhi34, 6, 256);
273 
274  address |= (dPhi12 & ((1 << 7) - 1)) << (0);
275  address |= (dPhi23 & ((1 << 5) - 1)) << (0 + 7);
276  address |= (dPhi34 & ((1 << 6) - 1)) << (0 + 7 + 5);
277  address |= (sign23 & ((1 << 1) - 1)) << (0 + 7 + 5 + 6);
278  address |= (sign34 & ((1 << 1) - 1)) << (0 + 7 + 5 + 6 + 1);
279  address |= (FR1 & ((1 << 1) - 1)) << (0 + 7 + 5 + 6 + 1 + 1);
280  address |= (theta & ((1 << 5) - 1)) << (0 + 7 + 5 + 6 + 1 + 1 + 1);
281  address |= (mode_inv & ((1 << 4) - 1)) << (0 + 7 + 5 + 6 + 1 + 1 + 1 + 5);
282  break;
283 
284  default:
285  break;
286  }
287 
288  return address;
289 }
290 
292  float pt = 0.;
293 
294  if (address == 0) // invalid address
295  return -1; // return pt;
296 
297  int mode_inv = (address >> (30 - 4)) & ((1 << 4) - 1);
298 
299  auto contain = [](const std::vector<int>& vec, int elem) {
300  return (std::find(vec.begin(), vec.end(), elem) != vec.end());
301  };
302 
303  bool is_good_mode = contain(allowedModes_, mode_inv);
304 
305  if (!is_good_mode) // invalid mode
306  return -1; // return pt;
307 
308  int dPhi12 = -999;
309  int dPhi13 = -999;
310  int dPhi14 = -999;
311  int dPhi23 = -999;
312  int dPhi24 = -999;
313  int dPhi34 = -999;
314  int dTheta12 = -999;
315  int dTheta13 = -999;
316  int dTheta14 = -999;
317  int dTheta23 = -999;
318  int dTheta24 = -999;
319  int dTheta34 = -999;
320  int CLCT1 = -999;
321  int CLCT2 = -999;
322  int CLCT3 = -999;
323  int CLCT4 = -999;
324  int CSCID1 = -999;
325  int CSCID2 = -999;
326  int CSCID3 = -999;
327  int CSCID4 = -999;
328  int FR1 = -999;
329  int FR2 = -999;
330  int FR3 = -999;
331  int FR4 = -999;
332 
333  int sign12 = 1;
334  int sign13 = 1;
335  int sign14 = 1;
336  int sign23 = 1;
337  int sign24 = 1;
338  int sign34 = 1;
339 
340  int CLCT1Sign = 1;
341  int CLCT2Sign = 1;
342  int CLCT3Sign = 1;
343  int CLCT4Sign = 1;
344 
345  int theta = 0;
346 
347  switch (mode_inv) {
348  case 3: // 1-2
349  dPhi12 = (address >> (0)) & ((1 << 9) - 1);
350  sign12 = (address >> (0 + 9)) & ((1 << 1) - 1);
351  dTheta12 = (address >> (0 + 9 + 1)) & ((1 << 3) - 1);
352  CLCT1 = (address >> (0 + 9 + 1 + 3)) & ((1 << 2) - 1);
353  CLCT1Sign = (address >> (0 + 9 + 1 + 3 + 2)) & ((1 << 1) - 1);
354  CLCT2 = (address >> (0 + 9 + 1 + 3 + 2 + 1)) & ((1 << 2) - 1);
355  CLCT2Sign = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2)) & ((1 << 1) - 1);
356  FR1 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1)) & ((1 << 1) - 1);
357  FR2 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1)) & ((1 << 1) - 1);
358  theta = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1)) & ((1 << 5) - 1);
359  break;
360 
361  case 5: // 1-3
362  dPhi13 = (address >> (0)) & ((1 << 9) - 1);
363  sign13 = (address >> (0 + 9)) & ((1 << 1) - 1);
364  dTheta13 = (address >> (0 + 9 + 1)) & ((1 << 3) - 1);
365  CLCT1 = (address >> (0 + 9 + 1 + 3)) & ((1 << 2) - 1);
366  CLCT1Sign = (address >> (0 + 9 + 1 + 3 + 2)) & ((1 << 1) - 1);
367  CLCT3 = (address >> (0 + 9 + 1 + 3 + 2 + 1)) & ((1 << 2) - 1);
368  CLCT3Sign = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2)) & ((1 << 1) - 1);
369  FR1 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1)) & ((1 << 1) - 1);
370  FR3 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1)) & ((1 << 1) - 1);
371  theta = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1)) & ((1 << 5) - 1);
372  break;
373 
374  case 9: // 1-4
375  dPhi14 = (address >> (0)) & ((1 << 9) - 1);
376  sign14 = (address >> (0 + 9)) & ((1 << 1) - 1);
377  dTheta14 = (address >> (0 + 9 + 1)) & ((1 << 3) - 1);
378  CLCT1 = (address >> (0 + 9 + 1 + 3)) & ((1 << 2) - 1);
379  CLCT1Sign = (address >> (0 + 9 + 1 + 3 + 2)) & ((1 << 1) - 1);
380  CLCT4 = (address >> (0 + 9 + 1 + 3 + 2 + 1)) & ((1 << 2) - 1);
381  CLCT4Sign = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2)) & ((1 << 1) - 1);
382  FR1 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1)) & ((1 << 1) - 1);
383  FR4 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1)) & ((1 << 1) - 1);
384  theta = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1)) & ((1 << 5) - 1);
385  break;
386 
387  case 6: // 2-3
388  dPhi23 = (address >> (0)) & ((1 << 9) - 1);
389  sign23 = (address >> (0 + 9)) & ((1 << 1) - 1);
390  dTheta23 = (address >> (0 + 9 + 1)) & ((1 << 3) - 1);
391  CLCT2 = (address >> (0 + 9 + 1 + 3)) & ((1 << 2) - 1);
392  CLCT2Sign = (address >> (0 + 9 + 1 + 3 + 2)) & ((1 << 1) - 1);
393  CLCT3 = (address >> (0 + 9 + 1 + 3 + 2 + 1)) & ((1 << 2) - 1);
394  CLCT3Sign = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2)) & ((1 << 1) - 1);
395  FR2 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1)) & ((1 << 1) - 1);
396  FR3 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1)) & ((1 << 1) - 1);
397  theta = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1)) & ((1 << 5) - 1);
398  break;
399 
400  case 10: // 2-4
401  dPhi24 = (address >> (0)) & ((1 << 9) - 1);
402  sign24 = (address >> (0 + 9)) & ((1 << 1) - 1);
403  dTheta24 = (address >> (0 + 9 + 1)) & ((1 << 3) - 1);
404  CLCT2 = (address >> (0 + 9 + 1 + 3)) & ((1 << 2) - 1);
405  CLCT2Sign = (address >> (0 + 9 + 1 + 3 + 2)) & ((1 << 1) - 1);
406  CLCT4 = (address >> (0 + 9 + 1 + 3 + 2 + 1)) & ((1 << 2) - 1);
407  CLCT4Sign = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2)) & ((1 << 1) - 1);
408  FR2 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1)) & ((1 << 1) - 1);
409  FR4 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1)) & ((1 << 1) - 1);
410  theta = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1)) & ((1 << 5) - 1);
411  break;
412 
413  case 12: // 3-4
414  dPhi34 = (address >> (0)) & ((1 << 9) - 1);
415  sign34 = (address >> (0 + 9)) & ((1 << 1) - 1);
416  dTheta34 = (address >> (0 + 9 + 1)) & ((1 << 3) - 1);
417  CLCT3 = (address >> (0 + 9 + 1 + 3)) & ((1 << 2) - 1);
418  CLCT3Sign = (address >> (0 + 9 + 1 + 3 + 2)) & ((1 << 1) - 1);
419  CLCT4 = (address >> (0 + 9 + 1 + 3 + 2 + 1)) & ((1 << 2) - 1);
420  CLCT4Sign = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2)) & ((1 << 1) - 1);
421  FR3 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1)) & ((1 << 1) - 1);
422  FR4 = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1)) & ((1 << 1) - 1);
423  theta = (address >> (0 + 9 + 1 + 3 + 2 + 1 + 2 + 1 + 1 + 1)) & ((1 << 5) - 1);
424  break;
425 
426  case 7: // 1-2-3
427  dPhi12 = (address >> (0)) & ((1 << 7) - 1);
428  dPhi23 = (address >> (0 + 7)) & ((1 << 5) - 1);
429  sign12 = (address >> (0 + 7 + 5)) & ((1 << 1) - 1);
430  sign23 = (address >> (0 + 7 + 5 + 1)) & ((1 << 1) - 1);
431  dTheta13 = (address >> (0 + 7 + 5 + 1 + 1)) & ((1 << 3) - 1);
432  CLCT1 = (address >> (0 + 7 + 5 + 1 + 1 + 3)) & ((1 << 2) - 1);
433  CLCT1Sign = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2)) & ((1 << 1) - 1);
434  FR1 = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1)) & ((1 << 1) - 1);
435  theta = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1)) & ((1 << 5) - 1);
436 
437  dPhi12 = aux().getdPhiFromBin(dPhi12, 7, 512);
438  dPhi23 = aux().getdPhiFromBin(dPhi23, 5, 256);
439  break;
440 
441  case 11: // 1-2-4
442  dPhi12 = (address >> (0)) & ((1 << 7) - 1);
443  dPhi24 = (address >> (0 + 7)) & ((1 << 5) - 1);
444  sign12 = (address >> (0 + 7 + 5)) & ((1 << 1) - 1);
445  sign24 = (address >> (0 + 7 + 5 + 1)) & ((1 << 1) - 1);
446  dTheta14 = (address >> (0 + 7 + 5 + 1 + 1)) & ((1 << 3) - 1);
447  CLCT1 = (address >> (0 + 7 + 5 + 1 + 1 + 3)) & ((1 << 2) - 1);
448  CLCT1Sign = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2)) & ((1 << 1) - 1);
449  FR1 = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1)) & ((1 << 1) - 1);
450  theta = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1)) & ((1 << 5) - 1);
451 
452  dPhi12 = aux().getdPhiFromBin(dPhi12, 7, 512);
453  dPhi24 = aux().getdPhiFromBin(dPhi24, 5, 256);
454  break;
455 
456  case 13: // 1-3-4
457  dPhi13 = (address >> (0)) & ((1 << 7) - 1);
458  dPhi34 = (address >> (0 + 7)) & ((1 << 5) - 1);
459  sign13 = (address >> (0 + 7 + 5)) & ((1 << 1) - 1);
460  sign34 = (address >> (0 + 7 + 5 + 1)) & ((1 << 1) - 1);
461  dTheta14 = (address >> (0 + 7 + 5 + 1 + 1)) & ((1 << 3) - 1);
462  CLCT1 = (address >> (0 + 7 + 5 + 1 + 1 + 3)) & ((1 << 2) - 1);
463  CLCT1Sign = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2)) & ((1 << 1) - 1);
464  FR1 = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1)) & ((1 << 1) - 1);
465  theta = (address >> (0 + 7 + 5 + 1 + 1 + 3 + 2 + 1 + 1)) & ((1 << 5) - 1);
466 
467  dPhi13 = aux().getdPhiFromBin(dPhi13, 7, 512);
468  dPhi34 = aux().getdPhiFromBin(dPhi34, 5, 256);
469  break;
470 
471  case 14: // 2-3-4
472  dPhi23 = (address >> (0)) & ((1 << 7) - 1);
473  dPhi34 = (address >> (0 + 7)) & ((1 << 6) - 1);
474  sign23 = (address >> (0 + 7 + 6)) & ((1 << 1) - 1);
475  sign34 = (address >> (0 + 7 + 6 + 1)) & ((1 << 1) - 1);
476  dTheta24 = (address >> (0 + 7 + 6 + 1 + 1)) & ((1 << 3) - 1);
477  CLCT2 = (address >> (0 + 7 + 6 + 1 + 1 + 3)) & ((1 << 2) - 1);
478  CLCT2Sign = (address >> (0 + 7 + 6 + 1 + 1 + 3 + 2)) & ((1 << 1) - 1);
479  theta = (address >> (0 + 7 + 6 + 1 + 1 + 3 + 2 + 1)) & ((1 << 5) - 1);
480 
481  dPhi23 = aux().getdPhiFromBin(dPhi23, 7, 512);
482  dPhi34 = aux().getdPhiFromBin(dPhi34, 6, 256);
483  break;
484 
485  case 15: // 1-2-3-4
486  dPhi12 = (address >> (0)) & ((1 << 7) - 1);
487  dPhi23 = (address >> (0 + 7)) & ((1 << 5) - 1);
488  dPhi34 = (address >> (0 + 7 + 5)) & ((1 << 6) - 1);
489  sign23 = (address >> (0 + 7 + 5 + 6)) & ((1 << 1) - 1);
490  sign34 = (address >> (0 + 7 + 5 + 6 + 1)) & ((1 << 1) - 1);
491  FR1 = (address >> (0 + 7 + 5 + 6 + 1 + 1)) & ((1 << 1) - 1);
492  theta = (address >> (0 + 7 + 5 + 6 + 1 + 1 + 1)) & ((1 << 5) - 1);
493 
494  dPhi12 = aux().getdPhiFromBin(dPhi12, 7, 512);
495  dPhi23 = aux().getdPhiFromBin(dPhi23, 5, 256);
496  dPhi34 = aux().getdPhiFromBin(dPhi34, 6, 256);
497  break;
498 
499  default:
500  break;
501  }
502 
503  auto get_signed_int = [](int var, int sign) { return (sign == 1) ? (var * 1) : (var * -1); };
504 
505  dPhi12 = get_signed_int(dPhi12, sign12);
506  dPhi13 = get_signed_int(dPhi13, sign13);
507  dPhi14 = get_signed_int(dPhi14, sign14);
508  dPhi23 = get_signed_int(dPhi23, sign23);
509  dPhi24 = get_signed_int(dPhi24, sign24);
510  dPhi34 = get_signed_int(dPhi34, sign34);
511 
512  CLCT1 = get_signed_int(CLCT1, CLCT1Sign);
513  CLCT2 = get_signed_int(CLCT2, CLCT2Sign);
514  CLCT3 = get_signed_int(CLCT3, CLCT3Sign);
515  CLCT4 = get_signed_int(CLCT4, CLCT4Sign);
516 
517  theta <<= 2;
518  float eta = aux().getEtaFromThetaInt(theta, 5);
519 
520  bool use_lossy_eta = true;
521  if (use_lossy_eta) {
522  int etaInt = aux().getEtaInt(eta, 5);
523  etaInt &= ((1 << 5) - 1);
524  eta = aux().getEtaFromEtaInt(etaInt, 5);
525  }
526 
527  // First fix to recover high pT muons with 3 hits in a line and one displaced hit
528  // Done by re-writing a few addresses in the original LUT, according to the following logic
529  // Implemented in FW 26.07.16, as of run 2774278 / fill 5119
530  if (fixMode15HighPt_) {
531  if (mode_inv == 15) { // 1-2-3-4
532  bool st2_off = false;
533  bool st3_off = false;
534  bool st4_off = false;
535 
536  dPhi13 = dPhi12 + dPhi23;
537  dPhi14 = dPhi13 + dPhi34;
538  dPhi24 = dPhi23 + dPhi34;
539 
540  int sum_st1 = abs(dPhi12 + dPhi13 + dPhi14);
541  int sum_st2 = abs(-dPhi12 + dPhi23 + dPhi24);
542  int sum_st3 = abs(-dPhi13 - dPhi23 + dPhi34);
543  int sum_st4 = abs(-dPhi14 - dPhi24 - dPhi34);
544 
545  // Detect outliers
546  if (sum_st2 > sum_st1 && sum_st2 > sum_st3 && sum_st2 > sum_st4)
547  st2_off = true;
548  if (sum_st3 > sum_st1 && sum_st3 > sum_st2 && sum_st3 > sum_st4)
549  st3_off = true;
550  if (sum_st4 > sum_st1 && sum_st4 > sum_st2 && sum_st4 > sum_st3)
551  st4_off = true;
552 
553  // Recover outliers
554  if (st2_off) {
555  if ((abs(dPhi12) > 9 || abs(dPhi23) > 9 || abs(dPhi24) > 9) &&
556  (abs(dPhi13) < 10 && abs(dPhi14) < 10 && abs(dPhi34) < 10)) {
557  dPhi12 = dPhi13 / 2;
558  dPhi23 = dPhi13 / 2;
559  }
560  }
561  if (st3_off) {
562  if ((abs(dPhi13) > 9 || abs(dPhi23) > 9 || abs(dPhi34) > 9) &&
563  (abs(dPhi12) < 10 && abs(dPhi14) < 10 && abs(dPhi24) < 10)) {
564  dPhi23 = dPhi24 / 2;
565  dPhi34 = dPhi24 / 2;
566  }
567  }
568  if (st4_off) {
569  if ((abs(dPhi14) > 9 || abs(dPhi24) > 9 || abs(dPhi34) > 9) &&
570  (abs(dPhi12) < 10 && abs(dPhi13) < 10 && abs(dPhi23) < 10)) {
571  if (abs(dPhi13) < abs(dPhi23))
572  dPhi34 = dPhi13;
573  else
574  dPhi34 = dPhi23;
575  }
576  }
577 
578  // Set sign23 and sign34 relative to sign12
579  //sign12 = (dPhi12 >= 0);
580  //sign23 = (dPhi23 >= 0);
581  //sign34 = (dPhi34 >= 0);
582  //if (!sign12) {
583  // sign12 = !sign12;
584  // sign23 = !sign23;
585  // sign34 = !sign34;
586  //}
587 
588  sign12 = 1;
589  if (dPhi12 > 0) {
590  sign23 = (dPhi23 > 0) ? 1 : 0;
591  sign34 = (dPhi34 > 0) ? 1 : 0;
592  } else {
593  sign23 = (dPhi23 < 0) ? 1 : 0;
594  sign34 = (dPhi34 < 0) ? 1 : 0;
595  }
596 
597  dPhi12 = get_signed_int(abs(dPhi12), sign12);
598  dPhi23 = get_signed_int(abs(dPhi23), sign23);
599  dPhi34 = get_signed_int(abs(dPhi34), sign34);
600 
601  } // end if mode_inv == 15
602  }
603 
604  // Inherit some bugs
605  if (bugMode7CLCT_) {
606  if (mode_inv == 14) { // 2-3-4
607  int bugged_CLCT2;
608  address_t bugged_address;
609 
610  //CLCT2 = (address >> (0+7+6+1+1+3)) & ((1<<2)-1);
611  //address |= (CLCT2 & ((1<<2)-1)) << (0+7+6+1+1+3);
612 
613  bugged_CLCT2 = (address >> (0 + 7 + 5 + 1 + 1 + 3)) & ((1 << 2) - 1); // bad
614  bugged_address = address & ~(((1 << 2) - 1) << (0 + 7 + 6 + 1 + 1 + 3)); // clear bits
615  bugged_address |= (bugged_CLCT2 & ((1 << 2) - 1)) << (0 + 7 + 6 + 1 + 1 + 3);
616  bugged_CLCT2 = (bugged_address >> (0 + 7 + 5 + 1 + 1 + 3)) & ((1 << 2) - 1); // bad
617 
618  CLCT2 = bugged_CLCT2;
619  CLCT2 = get_signed_int(CLCT2, CLCT2Sign);
620 
621  } // end if mode_inv == 14
622  }
623 
624  // Get pT from XML (forest)
625  const int(*mode_variables)[6] = aux().getModeVariables();
626 
627  std::vector<int> variables = {dPhi12, dPhi13, dPhi14, dPhi23, dPhi24, dPhi34, dTheta12, dTheta13,
628  dTheta14, dTheta23, dTheta24, dTheta34, CLCT1, CLCT2, CLCT3, CLCT4,
629  CSCID1, CSCID2, CSCID3, CSCID4, FR1, FR2, FR3, FR4};
630 
631  std::vector<double> tree_data;
632  tree_data.push_back(1.0);
633  tree_data.push_back(eta);
634 
635  for (int i = 0; i < 6; i++) { // loop over 6 variables (or less)
636  int mv = mode_variables[mode_inv - 3][i];
637  if (mv != -999) {
638  int v = variables.at(mv);
639  if (!(mode_inv == 13 && i == 3)) { // somehow this uses CSCID1
640  emtf_assert(v != -999);
641  }
642  tree_data.push_back(v);
643  } else {
644  tree_data.push_back(0); // pad with zeroes, somehow BDT tries to access out of bounds
645  }
646  }
647 
648  if (verbose_ > 2) {
649  std::cout << "mode_inv: " << mode_inv << " variables: ";
650  for (const auto& v : tree_data)
651  std::cout << v << " ";
652  std::cout << std::endl;
653  }
654 
655  auto tree_event = std::make_unique<emtf::Event>();
656  tree_event->predictedValue = 0; // must explicitly initialize
657  tree_event->data = tree_data;
658 
659  // forests_.at(mode_inv).predictEvent(tree_event.get(), 64);
660  emtf::Forest& forest = const_cast<emtf::Forest&>(forests_.at(mode_inv));
661  forest.predictEvent(tree_event.get(), 64);
662 
663  float tmp_pt = tree_event->predictedValue; // is actually 1/pT
664 
665  if (verbose_ > 1) {
666  std::cout << "mode_inv: " << mode_inv << " 1/pT: " << tmp_pt << std::endl;
667  std::cout << "dPhi12: " << dPhi12 << " dPhi13: " << dPhi13 << " dPhi14: " << dPhi14 << " dPhi23: " << dPhi23
668  << " dPhi24: " << dPhi24 << " dPhi34: " << dPhi34 << std::endl;
669  std::cout << "dTheta12: " << dTheta12 << " dTheta13: " << dTheta13 << " dTheta14: " << dTheta14
670  << " dTheta23: " << dTheta23 << " dTheta24: " << dTheta24 << " dTheta34: " << dTheta34 << std::endl;
671  std::cout << "CLCT1: " << CLCT1 << " CLCT2: " << CLCT2 << " CLCT3: " << CLCT3 << " CLCT4: " << CLCT4 << std::endl;
672  std::cout << "CSCID1: " << CSCID1 << " CSCID2: " << CSCID2 << " CSCID3: " << CSCID3 << " CSCID4: " << CSCID4
673  << std::endl;
674  std::cout << "FR1: " << FR1 << " FR2: " << FR2 << " FR3: " << FR3 << " FR4: " << FR4 << std::endl;
675  }
676 
677  if (bugNegPt_) {
678  pt = (tmp_pt == 0) ? tmp_pt : 1.0 / tmp_pt;
679  if (pt < 0.0)
680  pt = 1.0;
681  if (pt > 200.0)
682  pt = 200.0;
683 
684  } else {
685  if (tmp_pt < 0.0)
686  tmp_pt = 1.0 / 7000;
687  pt = (tmp_pt == 0) ? tmp_pt : 1.0 / tmp_pt;
688  }
689 
690  emtf_assert(pt > 0);
691  return pt;
692 }
693 
694 // Not implemented for 2016
696  float pt = 0.;
697 
698  return pt;
699 }
void predictEvent(Event *e, unsigned int trees)
Definition: Forest.cc:440
uint16_t bt_ci[5]
Definition: EMTFTrack.h:40
int getEtaInt(float eta, int bits=5) const
uint16_t sign_ph[6]
Definition: EMTFTrack.h:32
static PFTauRenderPlugin instance
float getEtaFromEtaInt(int etaInt, int bits=5) const
uint16_t bt_vi[5]
Definition: EMTFTrack.h:38
float getEtaFromThetaInt(int thetaInt, int bits=5) const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
uint16_t delta_ph[6]
Definition: EMTFTrack.h:30
int getFRLUT(int sector, int station, int chamber) const
float calculate_pt_xml(const address_t &address) const override
uint16_t delta_th[6]
Definition: EMTFTrack.h:31
const PtAssignmentEngineAux2016 & aux() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
uint16_t cpattern[4]
Definition: EMTFTrack.h:34
int getdPhiFromBin(int dPhiBin, int bits, int max=512) const
uint16_t fr[4]
Definition: EMTFTrack.h:37
const int(* getModeVariables() const)[6]
uint16_t sign_th[6]
Definition: EMTFTrack.h:33
std::array< emtf::Forest, 16 > forests_
#define emtf_assert(expr)
Definition: DebugTools.h:18
float unscale_pt(const float pt, const int mode=15) const override
float scale_pt(const float pt, const int mode=15) const override
address_t calculate_address(const EMTFTrack &track) const override
int getNLBdPhiBin(int dPhi, int bits, int max=512) const
std::vector< int > allowedModes_