CMS 3D CMS Logo

HGCalWaferMask.cc
Go to the documentation of this file.
5 
6 #include <algorithm>
7 #include <sstream>
8 
9 //#define EDM_ML_DEBUG
10 
11 bool HGCalWaferMask::maskCell(int u, int v, int n, int ncor, int fcor, int corners) {
12  /*
13 Masks each cell (or not) according to its wafer and cell position (detId) and to the user needs (corners).
14 Each wafer has k_CornerSize corners which are defined in anti-clockwise order starting from the corner at the top, which is always #0. 'ncor' denotes the number of corners inside the physical region. 'fcor' is the defined to be the first corner that appears inside the detector's physical volume in anti-clockwise order.
15 The argument 'corners' controls the types of wafers the user wants: for instance, corners=3 masks all wafers that have at least 3 corners inside the physical region.
16  */
17  bool mask(false);
18  if (ncor < corners) {
19  mask = true;
20  } else {
21  if (ncor == HGCalGeomTools::k_fourCorners) {
22  switch (fcor) {
23  case (0): {
24  mask = (v >= n);
25  break;
26  }
27  case (1): {
28  mask = (u >= n);
29  break;
30  }
31  case (2): {
32  mask = (u > v);
33  break;
34  }
35  case (3): {
36  mask = (v < n);
37  break;
38  }
39  case (4): {
40  mask = (u < n);
41  break;
42  }
43  default: {
44  mask = (u <= v);
45  break;
46  }
47  }
48  } else {
49  switch (fcor) {
50  case (0): {
51  if (ncor == HGCalGeomTools::k_threeCorners) {
52  mask = !((u > 2 * v) && (v < n));
53  } else {
54  mask = ((u >= n) && (v >= n) && ((u + v) > (3 * n - 2)));
55  }
56  break;
57  }
58  case (1): {
59  if (ncor == HGCalGeomTools::k_threeCorners) {
60  mask = !((u + v) < n);
61  } else {
62  mask = ((u >= n) && (u > v) && ((2 * u - v) > 2 * n));
63  }
64  break;
65  }
66  case (2): {
67  if (ncor == HGCalGeomTools::k_threeCorners) {
68  mask = !((u < n) && (v > u) && (v > (2 * u - 1)));
69  } else {
70  mask = ((u > 2 * v) && (v < n));
71  }
72  break;
73  }
74  case (3): {
75  if (ncor == HGCalGeomTools::k_threeCorners) {
76  mask = !((v >= u) && ((2 * v - u) > (2 * n - 2)));
77  } else {
78  mask = ((u + v) < n);
79  }
80  break;
81  }
82  case (4): {
83  if (ncor == HGCalGeomTools::k_threeCorners) {
84  mask = !((u >= n) && (v >= n) && ((u + v) > (3 * n - 2)));
85  } else {
86  mask = ((u < n) && (v > u) && (v > (2 * u - 1)));
87  }
88  break;
89  }
90  default: {
91  if (ncor == HGCalGeomTools::k_threeCorners) {
92  mask = !((u >= n) && (u > v) && ((2 * u - v) > 2 * n));
93  } else {
94  mask = ((v >= u) && ((2 * v - u) > (2 * n - 2)));
95  }
96  break;
97  }
98  }
99  }
100  }
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HGCalGeom") << "Corners: " << ncor << ":" << fcor << " N " << n << " u " << u << " v " << v
103  << " Mask " << mask;
104 #endif
105  return mask;
106 }
107 
108 bool HGCalWaferMask::goodCell(int u, int v, int n, int type, int rotn) {
109  bool good(false);
110  int n2 = n / 2;
111  int n4 = n / 4;
112  switch (type) {
113  case (HGCalTypes::WaferFull): { //WaferFull
114  good = true;
115  break;
116  }
117  case (HGCalTypes::WaferFive): { //WaferFive
118  switch (rotn) {
119  case (HGCalTypes::WaferCorner0): {
120  int u2 = u / 2;
121  good = ((v - u2) < n);
122  break;
123  }
124  case (HGCalTypes::WaferCorner1): {
125  good = ((v + u) < (3 * n - 1));
126  break;
127  }
128  case (HGCalTypes::WaferCorner2): {
129  int v2 = (v + 1) / 2;
130  good = ((u - v2) < n);
131  break;
132  }
133  case (HGCalTypes::WaferCorner3): {
134  int u2 = (u + 1) / 2;
135  good = (u2 <= v);
136  break;
137  }
138  case (HGCalTypes::WaferCorner4): {
139  good = ((v + u) >= n);
140  break;
141  }
142  default: {
143  int v2 = v / 2;
144  good = (u > v2);
145  break;
146  }
147  }
148  break;
149  }
150  case (HGCalTypes::WaferChopTwo): { //WaferChopTwo
151  switch (rotn) {
152  case (HGCalTypes::WaferCorner0): {
153  good = (v < (3 * n2));
154  break;
155  }
156  case (HGCalTypes::WaferCorner1): {
157  good = (u < (3 * n2));
158  break;
159  }
160  case (HGCalTypes::WaferCorner2): {
161  good = ((u - v) <= n2);
162  break;
163  }
164  case (HGCalTypes::WaferCorner3): {
165  good = (v >= n2);
166  break;
167  }
168  case (HGCalTypes::WaferCorner4): {
169  good = (u >= n2);
170  break;
171  }
172  default: {
173  good = ((v - u) < n2);
174  break;
175  }
176  }
177  break;
178  }
179  case (HGCalTypes::WaferChopTwoM): { //WaferChopTwoM
180  switch (rotn) {
181  case (HGCalTypes::WaferCorner0): {
182  good = (v < (5 * n4));
183  break;
184  }
185  case (HGCalTypes::WaferCorner1): {
186  good = (u < (5 * n4));
187  break;
188  }
189  case (HGCalTypes::WaferCorner2): {
190  good = ((u - v) <= n4);
191  break;
192  }
193  case (HGCalTypes::WaferCorner3): {
194  good = (v >= (3 * n4));
195  break;
196  }
197  case (HGCalTypes::WaferCorner4): {
198  good = (u >= (3 * n4));
199  break;
200  }
201  default: {
202  good = ((v - u) < n4);
203  break;
204  }
205  }
206  break;
207  }
208  case (HGCalTypes::WaferHalf): { //WaferHalf
209  switch (rotn) {
210  case (HGCalTypes::WaferCorner0): {
211  good = (v < n);
212  break;
213  }
214  case (HGCalTypes::WaferCorner1): {
215  good = (u < n);
216  break;
217  }
218  case (HGCalTypes::WaferCorner2): {
219  good = (v >= u);
220  break;
221  }
222  case (HGCalTypes::WaferCorner3): {
223  good = (v >= n);
224  break;
225  }
226  case (HGCalTypes::WaferCorner4): {
227  good = (u >= n);
228  break;
229  }
230  default: {
231  good = (u > v);
232  break;
233  }
234  }
235  break;
236  }
237  case (HGCalTypes::WaferSemi): { //WaferSemi
238  switch (rotn) {
239  case (HGCalTypes::WaferCorner0): {
240  good = ((u + v) < (2 * n));
241  break;
242  }
243  case (HGCalTypes::WaferCorner1): {
244  good = ((2 * u - v) < n);
245  break;
246  }
247  case (HGCalTypes::WaferCorner2): {
248  good = ((2 * v - u) >= n);
249  break;
250  }
251  case (HGCalTypes::WaferCorner3): {
252  good = ((u + v) >= (2 * n));
253  break;
254  }
255  case (HGCalTypes::WaferCorner4): {
256  good = ((2 * u - v) > n);
257  break;
258  }
259  default: {
260  good = ((2 * v - u) < n);
261  break;
262  }
263  }
264  break;
265  }
266  case (HGCalTypes::WaferThree): { //WaferThree
267  switch (rotn) {
268  case (HGCalTypes::WaferCorner0): {
269  good = ((v + u) < n);
270  break;
271  }
272  case (HGCalTypes::WaferCorner1): {
273  int v2 = v / 2;
274  good = (u <= v2);
275  break;
276  }
277  case (HGCalTypes::WaferCorner2): {
278  int u2 = (u / 2);
279  good = ((v - u2) >= n);
280  break;
281  }
282  case (HGCalTypes::WaferCorner3): {
283  good = ((v + u) >= (3 * n - 1));
284  break;
285  }
286  case (HGCalTypes::WaferCorner4): {
287  int v2 = ((v + 1) / 2);
288  good = ((u - v2) >= n);
289  break;
290  }
291  default: {
292  int u2 = ((u + 1) / 2);
293  good = (v < u2);
294  break;
295  }
296  }
297  break;
298  }
299  case (HGCalTypes::WaferSemi2): { //WaferSemi2
300  switch (rotn) {
301  case (HGCalTypes::WaferCorner0): {
302  int n3 = (n + 1) / 3;
303  good = ((u + v) < (4 * n3));
304  break;
305  }
306  case (HGCalTypes::WaferCorner1): {
307  good = ((2 * u - v) < n2);
308  break;
309  }
310  case (HGCalTypes::WaferCorner2): {
311  int u2 = ((u + 1) / 2);
312  good = ((v - u2) >= (3 * n4));
313  break;
314  }
315  case (HGCalTypes::WaferCorner3): {
316  good = ((u + v) >= (5 * n2));
317  break;
318  }
319  case (HGCalTypes::WaferCorner4): {
320  good = ((2 * u - v) > (3 * n2));
321  break;
322  }
323  default: {
324  int u2 = ((n == 8) ? ((u + 1) / 2) : (u / 2));
325  good = ((v - u2) < n4);
326  break;
327  }
328  }
329  break;
330  }
331  }
332 #ifdef EDM_ML_DEBUG
333  edm::LogVerbatim("HGCalGeom") << "u|v " << u << ":" << v << " N " << n << " type " << type << " rot " << rotn
334  << " good " << good;
335 #endif
336  return good;
337 }
338 
339 int HGCalWaferMask::getRotation(int zside, int type, int rotn) {
340  if (rotn >= HGCalTypes::WaferCornerMax)
342  int newrotn(rotn);
343  if ((zside < 0) && (type != HGCalTypes::WaferFull)) {
344  if (type == HGCalTypes::WaferFive) { //WaferFive
345  static constexpr int rot1[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner4,
351  newrotn = rot1[rotn];
352  } else if ((type == HGCalTypes::WaferThree) || (type == HGCalTypes::WaferSemi) ||
353  (type == HGCalTypes::WaferSemi2)) { //WaferThree/WaferSemi/WaferSemi2
354  static constexpr int rot2[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner2,
360  newrotn = rot2[rotn];
361  } else { //WaferHalf/WaferChopTwo/WaferChopTwoM
362  static constexpr int rot3[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner3,
368  newrotn = rot3[rotn];
369  }
370  }
371 #ifdef EDM_ML_DEBUG
372  edm::LogVerbatim("HGCalGeom") << "zside " << zside << " type " << type << " rotn " << rotn << ":" << newrotn;
373 #endif
374  return newrotn;
375 }
376 
377 std::pair<int, int> HGCalWaferMask::getTypeMode(const double& xpos,
378  const double& ypos,
379  const double& delX,
380  const double& delY,
381  const double& rin,
382  const double& rout,
383  const int& wType,
384  const int& mode,
385  bool debug) {
386  int ncor(0), iok(0);
388 
389  static constexpr int corners = 6;
390  static constexpr int base = 10;
391  double rin2 = rin * rin;
392  double rout2 = rout * rout;
393  double dx0[corners] = {
394  0.0, HGCalTypes::c10 * delX, HGCalTypes::c10 * delX, 0.0, -HGCalTypes::c10 * delX, -HGCalTypes::c10 * delX};
395  double dy0[corners] = {-HGCalTypes::c10 * delY,
396  -HGCalTypes::c50 * delY,
397  HGCalTypes::c50 * delY,
398  HGCalTypes::c10 * delY,
399  HGCalTypes::c50 * delY,
400  -HGCalTypes::c50 * delY};
401  double xc[corners], yc[corners];
402  for (int k = 0; k < corners; ++k) {
403  xc[k] = xpos + dx0[k];
404  yc[k] = ypos + dy0[k];
405  double rpos2 = (xc[k] * xc[k] + yc[k] * yc[k]);
406  if (rpos2 <= rout2 && rpos2 >= rin2) {
407  ++ncor;
408  iok = iok * base + 1;
409  } else {
410  iok *= base;
411  }
412  }
413  if (debug)
414  edm::LogVerbatim("HGCalGeom") << "I/p " << xpos << ":" << ypos << ":" << delX << ":" << delY << ":" << rin << ":"
415  << rout << ":" << wType << ":" << mode << " Corners " << ncor << " iok " << iok;
416 
417  static constexpr int ipat5[corners] = {101111, 110111, 111011, 111101, 111110, 11111};
418  static constexpr int ipat4[corners] = {100111, 110011, 111001, 111100, 11110, 1111};
419  static constexpr int ipat3[corners] = {100011, 110001, 111000, 11100, 1110, 111};
420  double dx1[corners] = {HGCalTypes::c50 * delX,
421  HGCalTypes::c10 * delX,
422  HGCalTypes::c50 * delX,
423  -HGCalTypes::c50 * delX,
424  -HGCalTypes::c10 * delX,
425  -HGCalTypes::c50 * delX};
426  double dy1[corners] = {
427  -HGCalTypes::c75 * delY, 0.0, HGCalTypes::c75 * delY, HGCalTypes::c75 * delY, 0.0, -HGCalTypes::c75 * delY};
428  double dx2[corners] = {HGCalTypes::c50 * delX,
429  -HGCalTypes::c50 * delX,
430  -HGCalTypes::c10 * delX,
431  -HGCalTypes::c50 * delX,
432  HGCalTypes::c50 * delX,
433  HGCalTypes::c10 * delX};
434  double dy2[corners] = {
435  HGCalTypes::c75 * delY, HGCalTypes::c75 * delY, 0.0, -HGCalTypes::c75 * delY, -HGCalTypes::c75 * delY, 0.0};
436  double dx3[corners] = {
437  HGCalTypes::c22 * delX, delX, HGCalTypes::c77 * delX, -HGCalTypes::c22 * delX, -delX, -HGCalTypes::c77 * delX};
438  double dy3[corners] = {-HGCalTypes::c88 * delY,
439  -HGCalTypes::c27 * delY,
440  HGCalTypes::c61 * delY,
441  HGCalTypes::c88 * delY,
442  HGCalTypes::c27 * delY,
443  -HGCalTypes::c61 * delY};
444  double dx4[corners] = {HGCalTypes::c22 * delX,
445  -HGCalTypes::c77 * delX,
446  -delX,
447  -HGCalTypes::c22 * delX,
448  HGCalTypes::c77 * delX,
449  HGCalTypes::c10 * delX};
450  double dy4[corners] = {HGCalTypes::c88 * delY,
451  HGCalTypes::c61 * delY,
452  -HGCalTypes::c27 * delY,
453  -HGCalTypes::c88 * delY,
454  -HGCalTypes::c61 * delY,
455  HGCalTypes::c27 * delY};
456  double dx5[corners] = {-HGCalTypes::c50 * delX,
457  -HGCalTypes::c10 * delX,
458  -HGCalTypes::c50 * delX,
459  HGCalTypes::c50 * delX,
460  HGCalTypes::c10 * delX,
461  HGCalTypes::c50 * delX};
462  double dy5[corners] = {
463  HGCalTypes::c75 * delY, 0.0, -HGCalTypes::c75 * delY, -HGCalTypes::c75 * delY, 0.0, HGCalTypes::c75 * delY};
464  double dx6[corners] = {-HGCalTypes::c77 * delX,
465  -HGCalTypes::c10 * delX,
466  -HGCalTypes::c22 * delX,
467  HGCalTypes::c77 * delX,
468  HGCalTypes::c10 * delX,
469  HGCalTypes::c22 * delX};
470  double dy6[corners] = {HGCalTypes::c61 * delY,
471  -HGCalTypes::c27 * delY,
472  -HGCalTypes::c88 * delY,
473  -HGCalTypes::c61 * delY,
474  HGCalTypes::c27 * delY,
475  HGCalTypes::c88 * delY};
476 
477  if (ncor == HGCalGeomTools::k_allCorners) {
478  } else if (ncor == HGCalGeomTools::k_fiveCorners) {
479  rotn = static_cast<int>(std::find(ipat5, ipat5 + 6, iok) - ipat5);
481  } else if (ncor == HGCalGeomTools::k_fourCorners) {
482  rotn = static_cast<int>(std::find(ipat4, ipat4 + 6, iok) - ipat4);
484  double rpos12 = ((xpos + dx1[rotn]) * (xpos + dx1[rotn]) + (ypos + dy1[rotn]) * (ypos + dy1[rotn]));
485  double rpos22(0);
486  if (rpos12 <= rout2 && rpos12 >= rin2) {
487  rpos22 = ((xpos + dx2[rotn]) * (xpos + dx2[rotn]) + (ypos + dy2[rotn]) * (ypos + dy2[rotn]));
488  if (rpos22 <= rout2 && rpos22 >= rin2)
490  }
491  if (debug)
492  edm::LogVerbatim("HGCalGeom") << "Test for Chop2 " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
493  << type;
494  if ((type == HGCalTypes::WaferHalf) && (wType == 0)) {
495  rpos12 = ((xpos + dx3[rotn]) * (xpos + dx3[rotn]) + (ypos + dy3[rotn]) * (ypos + dy3[rotn]));
496  if (rpos12 <= rout2 && rpos12 >= rin2) {
497  rpos22 = ((xpos + dx4[rotn]) * (xpos + dx4[rotn]) + (ypos + dy4[rotn]) * (ypos + dy4[rotn]));
498  if (rpos22 <= rout2 && rpos22 >= rin2)
500  }
501  if (debug)
502  edm::LogVerbatim("HGCalGeom") << "Test for Chop2M " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
503  << type;
504  }
505  } else if (ncor == HGCalGeomTools::k_threeCorners) {
506  rotn = static_cast<int>(std::find(ipat3, ipat3 + 6, iok) - ipat3);
508  double rpos12 = ((xpos + dx1[rotn]) * (xpos + dx1[rotn]) + (ypos + dy1[rotn]) * (ypos + dy1[rotn]));
509  double rpos22(0);
510  if (rpos12 <= rout2 && rpos12 >= rin2) {
511  rpos22 = ((xpos + dx5[rotn]) * (xpos + dx5[rotn]) + (ypos + dy5[rotn]) * (ypos + dy5[rotn]));
512  if (rpos22 <= rout2 && rpos22 >= rin2)
514  }
515  if (debug)
516  edm::LogVerbatim("HGCalGeom") << "Test for Semi " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
517  << type;
518  if ((type == HGCalTypes::WaferThree) && (wType == 0)) {
519  rpos12 = ((xpos + dx3[rotn]) * (xpos + dx3[rotn]) + (ypos + dy3[rotn]) * (ypos + dy3[rotn]));
520  if (rpos12 <= rout2 && rpos12 >= rin2) {
521  rpos22 = ((xpos + dx6[rotn]) * (xpos + dx6[rotn]) + (ypos + dy6[rotn]) * (ypos + dy6[rotn]));
522  if (rpos22 <= rout2 && rpos22 >= rin2)
524  }
525  if (debug)
526  edm::LogVerbatim("HGCalGeom") << "Test for SemiM " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
527  << type;
528  }
529  } else {
531  }
532 
533  if (debug)
534  edm::LogVerbatim("HGCalGeom") << "I/p " << xpos << ":" << ypos << ":" << delX << ":" << delY << ":" << rin << ":"
535  << rout << ":" << wType << ":" << mode << " o/p " << iok << ":" << ncor << ":" << type
536  << ":" << rotn;
537  return ((mode == 0) ? std::make_pair(ncor, rotn) : std::make_pair(type, (rotn + HGCalWaferMask::k_OffsetRotation)));
538 }
539 
541  double xpos, double ypos, double delX, double delY, double rin, double rout, int part, int rotn, bool debug) {
543  return false;
544  if (rotn < 0 || rotn > HGCalTypes::WaferCornerMax)
545  return false;
546  double rin2 = rin * rin;
547  double rout2 = rout * rout;
548  static constexpr int corners = HGCalTypes::WaferCornerMax;
549  static constexpr int corner2 = 2 * HGCalTypes::WaferCornerMax;
550  static constexpr int base = 10;
551  static constexpr int base2 = 100;
552  double dx0[corners] = {
553  0.0, HGCalTypes::c10 * delX, HGCalTypes::c10 * delX, 0.0, -HGCalTypes::c10 * delX, -HGCalTypes::c10 * delX};
554  double dy0[corners] = {-HGCalTypes::c10 * delY,
555  -HGCalTypes::c50 * delY,
556  HGCalTypes::c50 * delY,
557  HGCalTypes::c10 * delY,
558  HGCalTypes::c50 * delY,
559  -HGCalTypes::c50 * delY};
560  double dx1[corners] = {HGCalTypes::c50 * delX,
561  HGCalTypes::c10 * delX,
562  HGCalTypes::c50 * delX,
563  -HGCalTypes::c50 * delX,
564  -HGCalTypes::c10 * delX,
565  -HGCalTypes::c50 * delX};
566  double dy1[corners] = {
567  -HGCalTypes::c75 * delY, 0.0, HGCalTypes::c75 * delY, HGCalTypes::c75 * delY, 0.0, -HGCalTypes::c75 * delY};
568  double dx2[corner2] = {HGCalTypes::c22 * delX,
569  HGCalTypes::c77 * delX,
570  HGCalTypes::c10 * delX,
571  HGCalTypes::c10 * delX,
572  HGCalTypes::c77 * delX,
573  HGCalTypes::c22 * delX,
574  -HGCalTypes::c22 * delX,
575  -HGCalTypes::c77 * delX,
576  -HGCalTypes::c10 * delX,
577  -HGCalTypes::c10 * delX,
578  -HGCalTypes::c77 * delX,
579  -HGCalTypes::c22 * delX};
580  double dy2[corner2] = {-HGCalTypes::c88 * delY,
581  -HGCalTypes::c61 * delY,
582  -HGCalTypes::c27 * delY,
583  HGCalTypes::c27 * delY,
584  HGCalTypes::c61 * delY,
585  HGCalTypes::c88 * delY,
586  HGCalTypes::c88 * delY,
587  HGCalTypes::c61 * delY,
588  HGCalTypes::c27 * delY,
589  -HGCalTypes::c27 * delY,
590  -HGCalTypes::c61 * delY,
591  -HGCalTypes::c88 * delY};
592  bool ok(true);
593  int ncf(-1);
594  switch (part) {
595  case (HGCalTypes::WaferThree): {
596  static constexpr int nc0[corners] = {450, 150, 201, 312, 423, 534};
597  int nc = nc0[rotn];
598  for (int k1 = 0; k1 < 3; ++k1) {
599  int k = nc % base;
600  double xc1 = xpos + dx0[k];
601  double yc1 = ypos + dy0[k];
602  double rpos2 = (xc1 * xc1 + yc1 * yc1);
603  if ((rpos2 > rout2) || (rpos2 < rin2)) {
604  ok = false;
605  ncf = k;
606  break;
607  }
608  nc /= base;
609  }
610  break;
611  }
612  case (HGCalTypes::WaferSemi2): {
613  static constexpr int nc10[corners] = {450, 150, 201, 312, 423, 534};
614  static constexpr int nc11[corners] = {700, 902, 1104, 106, 308, 510};
615  int nc = nc10[rotn];
616  for (int k1 = 0; k1 < 3; ++k1) {
617  int k = nc % base;
618  double xc1 = xpos + dx0[k];
619  double yc1 = ypos + dy0[k];
620  double rpos2 = (xc1 * xc1 + yc1 * yc1);
621  if ((rpos2 > rout2) || (rpos2 < rin2)) {
622  ok = false;
623  ncf = k;
624  break;
625  }
626  nc /= base;
627  }
628  nc = nc11[rotn];
629  for (int k1 = 0; k1 < 2; ++k1) {
630  int k = nc % base2;
631  double xc1 = xpos + dx2[k];
632  double yc1 = ypos + dy2[k];
633  double rpos2 = (xc1 * xc1 + yc1 * yc1);
634  if ((rpos2 > rout2) || (rpos2 < rin2)) {
635  ok = false;
636  ncf = k + base2;
637  break;
638  }
639  nc /= base2;
640  }
641  break;
642  }
643  case (HGCalTypes::WaferSemi): {
644  static constexpr int nc20[corners] = {450, 150, 201, 312, 423, 534};
645  static constexpr int nc21[corners] = {30, 14, 25, 30, 41, 52};
646  int nc = nc20[rotn];
647  for (int k1 = 0; k1 < 3; ++k1) {
648  int k = nc % base;
649  double xc1 = xpos + dx0[k];
650  double yc1 = ypos + dy0[k];
651  double rpos2 = (xc1 * xc1 + yc1 * yc1);
652  if ((rpos2 > rout2) || (rpos2 < rin2)) {
653  ok = false;
654  ncf = k;
655  break;
656  }
657  nc /= base;
658  }
659  nc = nc21[rotn];
660  for (int k1 = 0; k1 < 2; ++k1) {
661  int k = nc % base;
662  double xc1 = xpos + dx1[k];
663  double yc1 = ypos + dy1[k];
664  double rpos2 = (xc1 * xc1 + yc1 * yc1);
665  if ((rpos2 > rout2) || (rpos2 < rin2)) {
666  ok = false;
667  ncf = k + base2;
668  break;
669  }
670  nc /= base;
671  }
672  break;
673  }
674  case (HGCalTypes::WaferHalf): {
675  static constexpr int nc3[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
676  int nc = nc3[rotn];
677  for (int k1 = 0; k1 < 4; ++k1) {
678  int k = nc % base;
679  double xc1 = xpos + dx0[k];
680  double yc1 = ypos + dy0[k];
681  double rpos2 = (xc1 * xc1 + yc1 * yc1);
682  if ((rpos2 > rout2) || (rpos2 < rin2)) {
683  ok = false;
684  ncf = k;
685  break;
686  }
687  nc /= base;
688  }
689  break;
690  }
691  case (HGCalTypes::WaferChopTwoM): {
692  static constexpr int nc40[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
693  static constexpr int nc41[corners] = {500, 702, 904, 1106, 108, 310};
694  int nc = nc40[rotn];
695  for (int k1 = 0; k1 < 4; ++k1) {
696  int k = nc % base;
697  double xc1 = xpos + dx0[k];
698  double yc1 = ypos + dy0[k];
699  double rpos2 = (xc1 * xc1 + yc1 * yc1);
700  if ((rpos2 > rout2) || (rpos2 < rin2)) {
701  ok = false;
702  ncf = k;
703  break;
704  }
705  nc /= base;
706  }
707  nc = nc41[rotn];
708  for (int k1 = 0; k1 < 2; ++k1) {
709  int k = nc % base2;
710  double xc1 = xpos + dx2[k];
711  double yc1 = ypos + dy2[k];
712  double rpos2 = (xc1 * xc1 + yc1 * yc1);
713  if ((rpos2 > rout2) || (rpos2 < rin2)) {
714  ok = false;
715  ncf = k + base2;
716  break;
717  }
718  nc /= base2;
719  }
720  break;
721  }
722  case (HGCalTypes::WaferChopTwo): {
723  static constexpr int nc50[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
724  static constexpr int nc51[corners] = {20, 13, 24, 35, 40, 51};
725  int nc = nc50[rotn];
726  for (int k1 = 0; k1 < 4; ++k1) {
727  int k = nc % base;
728  double xc1 = xpos + dx0[k];
729  double yc1 = ypos + dy0[k];
730  double rpos2 = (xc1 * xc1 + yc1 * yc1);
731  if ((rpos2 > rout2) || (rpos2 < rin2)) {
732  ok = false;
733  ncf = k;
734  break;
735  }
736  nc /= base;
737  }
738  nc = nc51[rotn];
739  for (int k1 = 0; k1 < 2; ++k1) {
740  int k = nc % base;
741  double xc1 = xpos + dx1[k];
742  double yc1 = ypos + dy1[k];
743  double rpos2 = (xc1 * xc1 + yc1 * yc1);
744  if ((rpos2 > rout2) || (rpos2 < rin2)) {
745  ok = false;
746  ncf = k + base2;
747  break;
748  }
749  nc /= base;
750  }
751  break;
752  }
753  case (HGCalTypes::WaferFive): {
754  static constexpr int nc6[corners] = {23450, 13450, 24501, 35012, 40123, 51234};
755  int nc = nc6[rotn];
756  for (int k1 = 0; k1 < 5; ++k1) {
757  int k = nc % base;
758  double xc1 = xpos + dx0[k];
759  double yc1 = ypos + dy0[k];
760  double rpos2 = (xc1 * xc1 + yc1 * yc1);
761  if ((rpos2 > rout2) || (rpos2 < rin2)) {
762  ok = false;
763  ncf = k;
764  break;
765  }
766  }
767  break;
768  }
769  default: {
770  for (int k = 0; k < corners; ++k) {
771  double xc1 = xpos + dx0[k];
772  double yc1 = ypos + dy0[k];
773  double rpos2 = (xc1 * xc1 + yc1 * yc1);
774  if ((rpos2 > rout2) || (rpos2 < rin2)) {
775  ok = false;
776  ncf = k;
777  break;
778  }
779  }
780  break;
781  }
782  }
783  if (debug)
784  edm::LogVerbatim("HGCalGeom") << "I/p "
785  << ":" << xpos << ":" << ypos << ":" << delX << ":" << delY << ":" << rin << ":"
786  << rout << ":" << part << ":" << rotn << " Results " << ok << ":" << ncf;
787  return ok;
788 }
789 
790 std::vector<std::pair<double, double> > HGCalWaferMask::waferXY(
791  int part, int ori, int zside, double delX, double delY, double xpos, double ypos) {
792  std::vector<std::pair<double, double> > xy;
793  int orient = getRotation(-zside, part, ori);
794 #ifdef EDM_ML_DEBUG
795  edm::LogVerbatim("HGCalGeom") << "Part " << part << " zSide " << zside << " Orient " << ori << ":" << orient;
796 #endif
797  double dx[24] = {HGCalTypes::c00 * delX, HGCalTypes::c10 * delX, HGCalTypes::c10 * delX, HGCalTypes::c00 * delX,
798  -HGCalTypes::c10 * delX, -HGCalTypes::c10 * delX, HGCalTypes::c50 * delX, HGCalTypes::c10 * delX,
799  HGCalTypes::c50 * delX, -HGCalTypes::c50 * delX, -HGCalTypes::c10 * delX, -HGCalTypes::c50 * delX,
800  HGCalTypes::c22 * delX, HGCalTypes::c10 * delX, HGCalTypes::c77 * delX, -HGCalTypes::c22 * delX,
801  -HGCalTypes::c10 * delX, -HGCalTypes::c77 * delX, HGCalTypes::c22 * delX, -HGCalTypes::c77 * delX,
802  -HGCalTypes::c10 * delX, -HGCalTypes::c22 * delX, HGCalTypes::c77 * delX, HGCalTypes::c10 * delX};
803  double dy[24] = {-HGCalTypes::c10 * delY, -HGCalTypes::c50 * delY, HGCalTypes::c50 * delY, HGCalTypes::c10 * delY,
804  HGCalTypes::c50 * delY, -HGCalTypes::c50 * delY, -HGCalTypes::c75 * delY, HGCalTypes::c00 * delY,
805  HGCalTypes::c75 * delY, HGCalTypes::c75 * delY, HGCalTypes::c00 * delY, -HGCalTypes::c75 * delY,
806  -HGCalTypes::c88 * delY, -HGCalTypes::c27 * delY, HGCalTypes::c61 * delY, HGCalTypes::c88 * delY,
807  HGCalTypes::c27 * delY, -HGCalTypes::c61 * delY, HGCalTypes::c88 * delY, HGCalTypes::c61 * delY,
808  -HGCalTypes::c27 * delY, -HGCalTypes::c88 * delY, -HGCalTypes::c61 * delY, HGCalTypes::c27 * delY};
809  if (part == HGCalTypes::WaferFull) {
810  int np[7] = {0, 1, 2, 3, 4, 5, 0};
811  for (int k = 0; k < 7; ++k)
812  xy.push_back(std::make_pair((xpos + dx[np[k]]), (ypos + dy[np[k]])));
813  } else if (part == HGCalTypes::WaferFive) {
814  int np[6][6] = {{0, 2, 3, 4, 5, 0},
815  {1, 3, 4, 5, 0, 1},
816  {2, 4, 5, 0, 1, 2},
817  {3, 5, 0, 1, 2, 3},
818  {4, 0, 1, 2, 3, 4},
819  {5, 1, 2, 3, 4, 5}};
820  for (int k = 0; k < 6; ++k) {
821  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
822 #ifdef EDM_ML_DEBUG
823  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
824  << dy[np[orient][k]];
825 #endif
826  }
827  } else if (part == HGCalTypes::WaferHalf) {
828  int np[6][5] = {
829  {0, 3, 4, 5, 0}, {1, 4, 5, 0, 1}, {2, 5, 0, 1, 2}, {3, 0, 1, 2, 3}, {4, 1, 2, 3, 4}, {5, 2, 3, 4, 5}};
830  for (int k = 0; k < 5; ++k) {
831  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
832 #ifdef EDM_ML_DEBUG
833  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
834  << dy[np[orient][k]];
835 #endif
836  }
837  } else if (part == HGCalTypes::WaferThree) {
838  int np[6][4] = {{0, 4, 5, 0}, {1, 5, 0, 1}, {2, 0, 1, 2}, {3, 1, 2, 3}, {4, 2, 3, 4}, {5, 3, 4, 5}};
839  for (int k = 0; k < 4; ++k) {
840  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
841 #ifdef EDM_ML_DEBUG
842  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
843  << dy[np[orient][k]];
844 #endif
845  }
846  } else if (part == HGCalTypes::WaferChopTwo) {
847  int np[6][7] = {{6, 8, 3, 4, 5, 0, 6},
848  {7, 9, 4, 5, 0, 1, 7},
849  {8, 10, 5, 0, 1, 2, 8},
850  {9, 11, 0, 1, 2, 3, 9},
851  {10, 6, 1, 2, 3, 4, 10},
852  {11, 7, 2, 3, 4, 5, 11}};
853  for (int k = 0; k < 7; ++k) {
854  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
855 #ifdef EDM_ML_DEBUG
856  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
857  << dy[np[orient][k]];
858 #endif
859  }
860  } else if (part == HGCalTypes::WaferSemi) {
861  int np[6][6] = {{6, 9, 4, 5, 0, 6},
862  {7, 10, 5, 0, 1, 7},
863  {8, 11, 0, 1, 2, 8},
864  {9, 6, 1, 2, 3, 9},
865  {10, 7, 2, 3, 4, 10},
866  {11, 8, 3, 4, 5, 11}};
867  for (int k = 0; k < 6; ++k) {
868  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
869 #ifdef EDM_ML_DEBUG
870  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
871  << dy[np[orient][k]];
872 #endif
873  }
874  } else if (part == HGCalTypes::WaferChopTwoM) {
875  int np[6][7] = {{12, 18, 3, 4, 5, 0, 12},
876  {13, 19, 4, 5, 0, 1, 13},
877  {14, 20, 5, 0, 1, 2, 14},
878  {15, 21, 0, 1, 2, 3, 15},
879  {16, 22, 1, 2, 3, 4, 16},
880  {17, 23, 2, 3, 4, 5, 17}};
881  for (int k = 0; k < 7; ++k) {
882  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
883 #ifdef EDM_ML_DEBUG
884  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
885  << dy[np[orient][k]];
886 #endif
887  }
888  } else if (part == HGCalTypes::WaferSemi2) {
889  int np[6][6] = {{12, 19, 4, 5, 0, 12},
890  {13, 20, 5, 0, 1, 13},
891  {14, 21, 0, 1, 2, 14},
892  {15, 22, 1, 2, 3, 15},
893  {16, 23, 2, 3, 4, 16},
894  {17, 18, 3, 4, 5, 17}};
895  for (int k = 0; k < 6; ++k) {
896  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
897 #ifdef EDM_ML_DEBUG
898  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
899  << dy[np[orient][k]];
900 #endif
901  }
902  }
903 #ifdef EDM_ML_DEBUG
904  edm::LogVerbatim("HGCalGeom") << "I/p: " << part << ":" << ori << ":" << zside << ":" << delX << ":" << delY << ":"
905  << xpos << ":" << ypos << " O/p having " << xy.size() << " points:";
906  std::ostringstream st1;
907  for (unsigned int i = 0; i < xy.size(); ++i)
908  st1 << " [" << i << "] " << xy[i].first << ":" << xy[i].second;
909  edm::LogVerbatim("HGCalGeom") << st1.str();
910 #endif
911  return xy;
912 }
HGCalGeomTools::k_allCorners
static constexpr int k_allCorners
Definition: HGCalGeomTools.h:13
mps_fire.i
i
Definition: mps_fire.py:428
HGCalTypes::WaferChopTwo
Definition: HGCalTypes.h:52
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
HGCalWaferMask::goodCell
static bool goodCell(int u, int v, int N, int type, int rotn)
Definition: HGCalWaferMask.cc:108
HGCalTypes::WaferCornerMax
static constexpr int32_t WaferCornerMax
Definition: HGCalTypes.h:62
HGCalTypes::c00
static constexpr double c00
Definition: HGCalTypes.h:65
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
HGCalWaferMask.h
HGCalTypes::WaferThree
Definition: HGCalTypes.h:57
HGCalWaferMask::waferXY
static std::vector< std::pair< double, double > > waferXY(int part, int orient, int zside, double delX, double delY, double xpos, double ypos)
Definition: HGCalWaferMask.cc:790
HGCalTypes::WaferFull
Definition: HGCalTypes.h:50
np
int np
Definition: AMPTWrapper.h:43
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
HGCalTypes::WaferCorner1
Definition: HGCalTypes.h:31
HGCalTypes::c75
static constexpr double c75
Definition: HGCalTypes.h:71
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
HGCalTypes::WaferOut
Definition: HGCalTypes.h:58
findQualityFiles.v
v
Definition: findQualityFiles.py:179
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
HGCalTypes::WaferFive
Definition: HGCalTypes.h:51
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
HGCalTypes::c77
static constexpr double c77
Definition: HGCalTypes.h:72
HGCalWaferMask::getRotation
static int getRotation(int zside, int type, int rotn)
Definition: HGCalWaferMask.cc:339
debug
#define debug
Definition: HDRShower.cc:19
part
part
Definition: HCALResponse.h:20
HGCalTypes::c22
static constexpr double c22
Definition: HGCalTypes.h:66
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
HGCalTypes::c61
static constexpr double c61
Definition: HGCalTypes.h:70
dqmdumpme.k
k
Definition: dqmdumpme.py:60
HGCalTypes::WaferSizeMax
static constexpr int32_t WaferSizeMax
Definition: HGCalTypes.h:63
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
HGCalTypes::WaferCorner5
Definition: HGCalTypes.h:35
HGCalTypes::WaferSemi
Definition: HGCalTypes.h:55
HGCalTypes::WaferCorner2
Definition: HGCalTypes.h:32
HGCalWaferMask::getTypeMode
static std::pair< int, int > getTypeMode(const double &xpos, const double &ypos, const double &delX, const double &delY, const double &rin, const double &rout, const int &waferType, const int &mode, bool deug=false)
Definition: HGCalWaferMask.cc:377
HGCalTypes::WaferSemi2
Definition: HGCalTypes.h:56
HGCalWaferMask::goodTypeMode
static bool goodTypeMode(double xpos, double ypos, double delX, double delY, double rin, double rout, int part, int rotn, bool debug)
Definition: HGCalWaferMask.cc:540
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
HGCalWaferMask::k_OffsetRotation
static constexpr int k_OffsetRotation
Definition: HGCalWaferMask.h:37
HGCalTypes::c50
static constexpr double c50
Definition: HGCalTypes.h:69
HGCalTypes::WaferCorner4
Definition: HGCalTypes.h:34
HGCalTypes::c88
static constexpr double c88
Definition: HGCalTypes.h:73
HGCalTypes::WaferChopTwoM
Definition: HGCalTypes.h:53
PVValHelper::dy
Definition: PVValidationHelpers.h:50
HGCalGeomTools::k_fiveCorners
static constexpr int k_fiveCorners
Definition: HGCalGeomTools.h:14
compare_using_db.base2
base2
Definition: compare_using_db.py:175
HGCalGeomTools.h
HGCalTypes::c10
static constexpr double c10
Definition: HGCalTypes.h:74
hgcalPerformanceValidation.orient
orient
Definition: hgcalPerformanceValidation.py:733
HGCalTypes::WaferCorner3
Definition: HGCalTypes.h:33
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
HGCalTypes::WaferHalf
Definition: HGCalTypes.h:54
HGCalTypes::c27
static constexpr double c27
Definition: HGCalTypes.h:68
MetAnalyzer.u2
u2
Definition: MetAnalyzer.py:61
HGCalTypes.h
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
HGCalGeomTools::k_fourCorners
static constexpr int k_fourCorners
Definition: HGCalGeomTools.h:15
PVValHelper::dx
Definition: PVValidationHelpers.h:49
HGCalWaferMask::maskCell
static bool maskCell(int u, int v, int N, int ncor, int fcor, int corners)
Definition: HGCalWaferMask.cc:11
HGCalGeomTools::k_threeCorners
static constexpr int k_threeCorners
Definition: HGCalGeomTools.h:16
HGCalTypes::WaferCorner0
Definition: HGCalTypes.h:30