CMS 3D CMS Logo

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