CMS 3D CMS Logo

PtLUTVarCalc.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <cstdlib>
6 
7 // From here down, exact copy of code used for training BDT: EMTFPtAssign2017/src/PtLUTVarCalc.cc
8 
10 
11 int CalcTrackTheta(const int th1,
12  const int th2,
13  const int th3,
14  const int th4,
15  const int st1_ring2,
16  const int mode,
17  const bool BIT_COMP) {
18  int theta = -99;
19 
20  if ((mode % 8) / 4 > 0) // Has station 2 hit
21  theta = th2;
22  else if ((mode % 4) / 2 > 0) // Has station 3 hit
23  theta = th3;
24  else if ((mode % 2) > 0) // Has station 4 hit
25  theta = th4;
26 
27  if (not(theta > 0)) {
28  edm::LogError("L1T") << "theta = " << theta;
29  return 0;
30  }
31 
32  if (BIT_COMP) {
33  int nBits = (mode == 15 ? 4 : 5);
34  theta = ENG.getTheta(theta, st1_ring2, nBits);
35  }
36 
37  return theta;
38 }
39 
40 void CalcDeltaPhis(int& dPh12,
41  int& dPh13,
42  int& dPh14,
43  int& dPh23,
44  int& dPh24,
45  int& dPh34,
46  int& dPhSign,
47  int& dPhSum4,
48  int& dPhSum4A,
49  int& dPhSum3,
50  int& dPhSum3A,
51  int& outStPh,
52  const int ph1,
53  const int ph2,
54  const int ph3,
55  const int ph4,
56  const int mode,
57  const bool BIT_COMP) {
58  dPh12 = ph2 - ph1;
59  dPh13 = ph3 - ph1;
60  dPh14 = ph4 - ph1;
61  dPh23 = ph3 - ph2;
62  dPh24 = ph4 - ph2;
63  dPh34 = ph4 - ph3;
64  dPhSign = 0;
65 
66  if (mode >= 8) { // First hit is station 1
67  if ((mode % 8) / 4 > 0) // Has station 2 hit
68  dPhSign = (dPh12 >= 0 ? +1 : -1);
69  else if ((mode % 4) / 2 > 0) // Has station 3 hit
70  dPhSign = (dPh13 >= 0 ? +1 : -1);
71  else if ((mode % 2) > 0) // Has station 4 hit
72  dPhSign = (dPh14 >= 0 ? +1 : -1);
73  } else if ((mode % 8) / 4 > 0) { // First hit is station 2
74  if ((mode % 4) / 2 > 0) // Has station 3 hit
75  dPhSign = (dPh23 >= 0 ? +1 : -1);
76  else if ((mode % 2) > 0) // Has station 4 hit
77  dPhSign = (dPh24 >= 0 ? +1 : -1);
78  } else if ((mode % 4) / 2 > 0) { // First hit is station 3
79  if ((mode % 2) > 0) // Has station 4 hit
80  dPhSign = (dPh34 >= 0 ? +1 : -1);
81  }
82 
83  if (not(dPhSign != 0)) {
84  edm::LogError("L1T") << "dPhSign = " << dPhSign;
85  return;
86  }
87 
88  dPh12 *= dPhSign;
89  dPh13 *= dPhSign;
90  dPh14 *= dPhSign;
91  dPh23 *= dPhSign;
92  dPh24 *= dPhSign;
93  dPh34 *= dPhSign;
94 
95  if (BIT_COMP) {
96  int nBitsA = 7;
97  int nBitsB = 7;
98  int nBitsC = 7;
99  int maxA = 512;
100  int maxB = 512;
101  int maxC = 512;
102 
103  if (mode == 7 || mode == 11 || mode > 12) {
104  nBitsB = 5;
105  maxB = 256;
106  nBitsC = 5;
107  maxC = 256;
108  }
109  if (mode == 15) {
110  nBitsC = 4;
111  maxC = 256;
112  }
113 
114  dPh12 = ENG.getNLBdPhi(dPh12, nBitsA, maxA);
115  dPh13 = ENG.getNLBdPhi(dPh13, nBitsA, maxA);
116  dPh14 = ENG.getNLBdPhi(dPh14, nBitsA, maxA);
117  if (mode == 7)
118  dPh23 = ENG.getNLBdPhi(dPh23, nBitsA, maxA);
119  else
120  dPh23 = ENG.getNLBdPhi(dPh23, nBitsB, maxB);
121  dPh24 = ENG.getNLBdPhi(dPh24, nBitsB, maxB);
122  dPh34 = ENG.getNLBdPhi(dPh34, nBitsC, maxC);
123 
124  // Some delta phi values must be computed from others
125  switch (mode) {
126  case 15:
127  dPh13 = dPh12 + dPh23;
128  dPh14 = dPh13 + dPh34;
129  dPh24 = dPh23 + dPh34;
130  break;
131  case 14:
132  dPh13 = dPh12 + dPh23;
133  break;
134  case 13:
135  dPh14 = dPh12 + dPh24;
136  break;
137  case 11:
138  dPh14 = dPh13 + dPh34;
139  break;
140  case 7:
141  dPh24 = dPh23 + dPh34;
142  break;
143  default:
144  break;
145  }
146 
147  } // End conditional: if (BIT_COMP)
148 
149  // Compute summed quantities
150  if (mode == 15)
151  CalcDeltaPhiSums(dPhSum4, dPhSum4A, dPhSum3, dPhSum3A, outStPh, dPh12, dPh13, dPh14, dPh23, dPh24, dPh34);
152 
153 } // End function: CalcDeltaPhis()
154 
155 void CalcDeltaThetas(int& dTh12,
156  int& dTh13,
157  int& dTh14,
158  int& dTh23,
159  int& dTh24,
160  int& dTh34,
161  const int th1,
162  const int th2,
163  const int th3,
164  const int th4,
165  const int mode,
166  const bool BIT_COMP) {
167  dTh12 = th2 - th1;
168  dTh13 = th3 - th1;
169  dTh14 = th4 - th1;
170  dTh23 = th3 - th2;
171  dTh24 = th4 - th2;
172  dTh34 = th4 - th3;
173 
174  if (BIT_COMP) {
175  int nBits = (mode == 15 ? 2 : 3);
176 
177  dTh12 = ENG.getdTheta(dTh12, nBits);
178  dTh13 = ENG.getdTheta(dTh13, nBits);
179  dTh14 = ENG.getdTheta(dTh14, nBits);
180  dTh23 = ENG.getdTheta(dTh23, nBits);
181  dTh24 = ENG.getdTheta(dTh24, nBits);
182  dTh34 = ENG.getdTheta(dTh34, nBits);
183  } // End conditional: if (BIT_COMP)
184 
185 } // CalcDeltaThetas()
186 
187 void CalcBends(int& bend1,
188  int& bend2,
189  int& bend3,
190  int& bend4,
191  const int pat1,
192  const int pat2,
193  const int pat3,
194  const int pat4,
195  const int dPhSign,
196  const int endcap,
197  const int mode,
198  const bool BIT_COMP) {
199  bend1 = CalcBendFromPattern(pat1, endcap);
200  bend2 = CalcBendFromPattern(pat2, endcap);
201  bend3 = CalcBendFromPattern(pat3, endcap);
202  bend4 = CalcBendFromPattern(pat4, endcap);
203 
204  if (BIT_COMP) {
205  int nBits = 3;
206  if (mode == 7 || mode == 11 || mode > 12)
207  nBits = 2;
208 
209  if (mode / 8 > 0) // Has station 1 hit
210  bend1 = ENG.getCLCT(pat1, endcap, dPhSign, nBits);
211  if ((mode % 8) / 4 > 0) // Has station 2 hit
212  bend2 = ENG.getCLCT(pat2, endcap, dPhSign, nBits);
213  if ((mode % 4) / 2 > 0) // Has station 3 hit
214  bend3 = ENG.getCLCT(pat3, endcap, dPhSign, nBits);
215  if ((mode % 2) > 0) // Has station 4 hit
216  bend4 = ENG.getCLCT(pat4, endcap, dPhSign, nBits);
217  } // End conditional: if (BIT_COMP)
218 
219 } // End function: CalcBends()
220 
221 void CalcRPCs(int& RPC1,
222  int& RPC2,
223  int& RPC3,
224  int& RPC4,
225  const int mode,
226  const int st1_ring2,
227  const int theta,
228  const bool BIT_COMP) {
229  if (BIT_COMP) {
230  // Mask some invalid locations for RPC hits
231  // theta is assumed to be the compressed, mode 15 version
232  if (mode == 15 && !st1_ring2) {
233  RPC1 = 0;
234  RPC2 = 0;
235  if (theta < 4) {
236  RPC3 = 0;
237  RPC4 = 0;
238  }
239  }
240 
241  int nRPC = (RPC1 == 1) + (RPC2 == 1) + (RPC3 == 1) + (RPC4 == 1);
242 
243  // In 3- and 4-station modes, only specify some combinations of RPCs
244  if (nRPC >= 2) {
245  if (mode == 15) {
246  if (RPC1 == 1 && RPC2 == 1) {
247  RPC3 = 0;
248  RPC4 = 0;
249  } else if (RPC1 == 1 && RPC3 == 1) {
250  RPC4 = 0;
251  } else if (RPC4 == 1 && RPC2 == 1) {
252  RPC3 = 0;
253  } else if (RPC3 == 1 && RPC4 == 1 && !st1_ring2) {
254  RPC3 = 0;
255  }
256  } else if (mode == 14) {
257  if (RPC1 == 1) {
258  RPC2 = 0;
259  RPC3 = 0;
260  } else if (RPC3 == 1) {
261  RPC2 = 0;
262  }
263  } else if (mode == 13) {
264  if (RPC1 == 1) {
265  RPC2 = 0;
266  RPC4 = 0;
267  } else if (RPC4 == 1) {
268  RPC2 = 0;
269  }
270  } else if (mode == 11) {
271  if (RPC1 == 1) {
272  RPC3 = 0;
273  RPC4 = 0;
274  } else if (RPC4 == 1) {
275  RPC3 = 0;
276  }
277  } else if (mode == 7) {
278  if (RPC2 == 1) {
279  RPC3 = 0;
280  RPC4 = 0;
281  } else if (RPC4 == 1) {
282  RPC3 = 0;
283  }
284  }
285 
286  } // End conditional: if (nRPC >= 2)
287  } // End conditional: if (BIT_COMP)
288 
289 } // End function: void CalcRPCs()
290 
291 int CalcBendFromPattern(const int pattern, const int endcap) {
292  int bend = -99;
293  if (pattern < 0)
294  return bend;
295 
296  if (pattern == 10)
297  bend = 0;
298  else if ((pattern % 2) == 0)
299  bend = (10 - pattern) / 2;
300  else if ((pattern % 2) == 1)
301  bend = -1 * (11 - pattern) / 2;
302 
303  // Reverse to match dPhi convention
304  if (endcap == 1)
305  bend *= -1;
306 
307  if (not(bend != -99)) {
308  edm::LogError("L1T") << "bend = " << bend;
309  return 0;
310  }
311  return bend;
312 }
313 
314 void CalcDeltaPhiSums(int& dPhSum4,
315  int& dPhSum4A,
316  int& dPhSum3,
317  int& dPhSum3A,
318  int& outStPh,
319  const int dPh12,
320  const int dPh13,
321  const int dPh14,
322  const int dPh23,
323  const int dPh24,
324  const int dPh34) {
325  dPhSum4 = dPh12 + dPh13 + dPh14 + dPh23 + dPh24 + dPh34;
326  dPhSum4A = abs(dPh12) + abs(dPh13) + abs(dPh14) + abs(dPh23) + abs(dPh24) + abs(dPh34);
327  int devSt1 = abs(dPh12) + abs(dPh13) + abs(dPh14);
328  int devSt2 = abs(dPh12) + abs(dPh23) + abs(dPh24);
329  int devSt3 = abs(dPh13) + abs(dPh23) + abs(dPh34);
330  int devSt4 = abs(dPh14) + abs(dPh24) + abs(dPh34);
331 
332  if (devSt4 > devSt3 && devSt4 > devSt2 && devSt4 > devSt1)
333  outStPh = 4;
334  else if (devSt3 > devSt4 && devSt3 > devSt2 && devSt3 > devSt1)
335  outStPh = 3;
336  else if (devSt2 > devSt4 && devSt2 > devSt3 && devSt2 > devSt1)
337  outStPh = 2;
338  else if (devSt1 > devSt4 && devSt1 > devSt3 && devSt1 > devSt2)
339  outStPh = 1;
340  else
341  outStPh = 0;
342 
343  if (outStPh == 4) {
344  dPhSum3 = dPh12 + dPh13 + dPh23;
345  dPhSum3A = abs(dPh12) + abs(dPh13) + abs(dPh23);
346  } else if (outStPh == 3) {
347  dPhSum3 = dPh12 + dPh14 + dPh24;
348  dPhSum3A = abs(dPh12) + abs(dPh14) + abs(dPh24);
349  } else if (outStPh == 2) {
350  dPhSum3 = dPh13 + dPh14 + dPh34;
351  dPhSum3A = abs(dPh13) + abs(dPh14) + abs(dPh34);
352  } else {
353  dPhSum3 = dPh23 + dPh24 + dPh34;
354  dPhSum3A = abs(dPh23) + abs(dPh24) + abs(dPh34);
355  }
356 
357 } // End function: void CalcDeltaPhiSums()
int getTheta(int theta, int ring2, int bits=5) const
void CalcBends(int &bend1, int &bend2, int &bend3, int &bend4, const int pat1, const int pat2, const int pat3, const int pat4, const int dPhSign, const int endcap, const int mode, const bool BIT_COMP)
Geom::Theta< T > theta() const
int CalcTrackTheta(const int th1, const int th2, const int th3, const int th4, const int st1_ring2, const int mode, const bool BIT_COMP)
Definition: PtLUTVarCalc.cc:11
int CalcBendFromPattern(const int pattern, const int endcap)
void CalcDeltaPhis(int &dPh12, int &dPh13, int &dPh14, int &dPh23, int &dPh24, int &dPh34, int &dPhSign, int &dPhSum4, int &dPhSum4A, int &dPhSum3, int &dPhSum3A, int &outStPh, const int ph1, const int ph2, const int ph3, const int ph4, const int mode, const bool BIT_COMP)
Definition: PtLUTVarCalc.cc:40
void CalcDeltaPhiSums(int &dPhSum4, int &dPhSum4A, int &dPhSum3, int &dPhSum3A, int &outStPh, const int dPh12, const int dPh13, const int dPh14, const int dPh23, const int dPh24, const int dPh34)
int getNLBdPhi(int dPhi, int bits=7, int max=512) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int getCLCT(int clct, int endcap, int dPhiSign, int bits=3) const
void CalcDeltaThetas(int &dTh12, int &dTh13, int &dTh14, int &dTh23, int &dTh24, int &dTh34, const int th1, const int th2, const int th3, const int th4, const int mode, const bool BIT_COMP)
void CalcRPCs(int &RPC1, int &RPC2, int &RPC3, int &RPC4, const int mode, const int st1_ring2, const int theta, const bool BIT_COMP)
int getdTheta(int dTheta, int bits=3) const
PtAssignmentEngineAux2017 ENG
Definition: PtLUTVarCalc.cc:9