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