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  // for V15 and V16
110  bool good(false);
111  int n2 = n / 2;
112  int n4 = n / 4;
113  int n3 = (n + 1) / 3;
114  switch (type) {
115  case (HGCalTypes::WaferFull): { //WaferFull
116  good = true;
117  break;
118  }
119  case (HGCalTypes::WaferFive): { //WaferFive
120  switch (rotn) {
121  case (HGCalTypes::WaferCorner0): {
122  int u2 = u / 2;
123  good = ((v - u2) <= n);
124  break;
125  }
126  case (HGCalTypes::WaferCorner1): {
127  good = ((v + u) < (3 * n));
128  break;
129  }
130  case (HGCalTypes::WaferCorner2): {
131  int v2 = (v + 1) / 2;
132  good = ((u - v2) <= n);
133  break;
134  }
135  case (HGCalTypes::WaferCorner3): {
136  int u2 = (u - 1) / 2;
137  good = (u2 <= v);
138  break;
139  }
140  case (HGCalTypes::WaferCorner4): {
141  good = ((v + u) >= n - 1);
142  break;
143  }
144  default: {
145  int v2 = v / 2;
146  good = (u >= v2);
147  break;
148  }
149  }
150  break;
151  }
152  case (HGCalTypes::WaferChopTwo): { //WaferChopTwo
153  switch (rotn) {
154  case (HGCalTypes::WaferCorner0): {
155  good = (v < (3 * n2));
156  break;
157  }
158  case (HGCalTypes::WaferCorner1): {
159  good = (u < (3 * n2));
160  break;
161  }
162  case (HGCalTypes::WaferCorner2): {
163  good = ((u - v) <= n2);
164  break;
165  }
166  case (HGCalTypes::WaferCorner3): {
167  good = (v >= n2);
168  break;
169  }
170  case (HGCalTypes::WaferCorner4): {
171  good = (u >= n2 - 1);
172  break;
173  }
174  default: {
175  good = ((v - u) < n2);
176  break;
177  }
178  }
179  break;
180  }
181  case (HGCalTypes::WaferChopTwoM): { //WaferChopTwoM
182  switch (rotn) {
183  case (HGCalTypes::WaferCorner0): {
184  good = (v < (5 * n4));
185  break;
186  }
187  case (HGCalTypes::WaferCorner1): {
188  good = (u <= (5 * n4));
189  break;
190  }
191  case (HGCalTypes::WaferCorner2): {
192  good = ((u - v) <= n4);
193  break;
194  }
195  case (HGCalTypes::WaferCorner3): {
196  good = (v >= (3 * n4 - 1));
197  break;
198  }
199  case (HGCalTypes::WaferCorner4): {
200  good = (u >= (3 * n4));
201  break;
202  }
203  default: {
204  good = ((v - u) <= n4);
205  break;
206  }
207  }
208  break;
209  }
210  case (HGCalTypes::WaferHalf): { //WaferHalf
211  switch (rotn) {
212  case (HGCalTypes::WaferCorner0): {
213  good = (v < n);
214  break;
215  }
216  case (HGCalTypes::WaferCorner1): {
217  good = (u <= n);
218  break;
219  }
220  case (HGCalTypes::WaferCorner2): {
221  good = (v >= u);
222  break;
223  }
224  case (HGCalTypes::WaferCorner3): {
225  good = (v >= n - 1);
226  break;
227  }
228  case (HGCalTypes::WaferCorner4): {
229  good = (u >= n);
230  break;
231  }
232  default: {
233  good = (u >= v);
234  break;
235  }
236  }
237  break;
238  }
239  case (HGCalTypes::WaferSemi): { //WaferSemi
240  switch (rotn) {
241  case (HGCalTypes::WaferCorner0): {
242  good = ((u + v) < (2 * n));
243  break;
244  }
245  case (HGCalTypes::WaferCorner1): {
246  good = ((2 * u - v) < n);
247  break;
248  }
249  case (HGCalTypes::WaferCorner2): {
250  good = ((2 * v - u) >= n);
251  break;
252  }
253  case (HGCalTypes::WaferCorner3): {
254  good = ((u + v) >= (2 * n));
255  break;
256  }
257  case (HGCalTypes::WaferCorner4): {
258  good = ((2 * u - v) > n);
259  break;
260  }
261  default: {
262  good = ((2 * v - u) < n);
263  break;
264  }
265  }
266  break;
267  }
268  case (HGCalTypes::WaferThree): { //WaferThree
269  switch (rotn) {
270  case (HGCalTypes::WaferCorner0): {
271  good = ((v + u) < n);
272  break;
273  }
274  case (HGCalTypes::WaferCorner1): {
275  int v2 = v / 2;
276  good = (u <= v2);
277  break;
278  }
279  case (HGCalTypes::WaferCorner2): {
280  int u2 = (u / 2);
281  good = ((v - u2) >= n);
282  break;
283  }
284  case (HGCalTypes::WaferCorner3): {
285  good = ((v + u) >= (3 * n - 1));
286  break;
287  }
288  case (HGCalTypes::WaferCorner4): {
289  int v2 = ((v + 1) / 2);
290  good = ((u - v2) >= n);
291  break;
292  }
293  default: {
294  int u2 = ((u + 1) / 2);
295  good = (v < u2);
296  break;
297  }
298  }
299  break;
300  }
301  case (HGCalTypes::WaferSemi2): { //WaferSemi2
302  switch (rotn) {
303  case (HGCalTypes::WaferCorner0): {
304  good = ((u + v) <= (4 * n3 + 1));
305  break;
306  }
307  case (HGCalTypes::WaferCorner1): {
308  good = ((2 * u - v) <= n2);
309  break;
310  }
311  case (HGCalTypes::WaferCorner2): {
312  int u2 = ((u + 1) / 2);
313  good = ((v - u2) >= (3 * n4 - 1));
314  break;
315  }
316  case (HGCalTypes::WaferCorner3): {
317  good = ((u + v) >= (5 * n2 - 1));
318  break;
319  }
320  case (HGCalTypes::WaferCorner4): {
321  good = ((2 * u - v) >= (3 * n2));
322  break;
323  }
324  default: {
325  int u2 = (u + 1) / 2;
326  good = ((v - u2) < n4);
327  break;
328  }
329  }
330  break;
331  }
332  case (HGCalTypes::WaferFive2): { //WaferFive2
333  switch (rotn) {
334  case (HGCalTypes::WaferCorner0): {
335  good = ((2 * v - u) <= (3 * n2));
336  break;
337  }
338  case (HGCalTypes::WaferCorner1): {
339  good = ((u + v) < (5 * n2));
340  break;
341  }
342  case (HGCalTypes::WaferCorner2): {
343  good = ((2 * u - v) >= (3 * n2));
344  break;
345  }
346  case (HGCalTypes::WaferCorner3): {
347  good = ((2 * v - u) >= n3);
348  break;
349  }
350  case (HGCalTypes::WaferCorner4): {
351  good = ((u + v) > (4 * n3));
352  break;
353  }
354  default: {
355  good = ((2 * u - v) >= n2);
356  break;
357  }
358  }
359  break;
360  }
361  case (HGCalTypes::WaferHalf2): { //WaferHalf2
362  switch (rotn) {
363  case (HGCalTypes::WaferCorner0): {
364  good = (v <= (3 * n4));
365  break;
366  }
367  case (HGCalTypes::WaferCorner1): {
368  good = (u <= (3 * n4));
369  break;
370  }
371  case (HGCalTypes::WaferCorner2): {
372  good = ((v - u) >= n4 - 1);
373  break;
374  }
375  case (HGCalTypes::WaferCorner3): {
376  good = (v >= (5 * n4 - 1));
377  break;
378  }
379  case (HGCalTypes::WaferCorner4): {
380  good = (u >= (5 * n4 - 1));
381  break;
382  }
383  default: {
384  good = ((u - v) >= n4);
385  break;
386  }
387  }
388  break;
389  }
390  }
391 #ifdef EDM_ML_DEBUG
392  edm::LogVerbatim("HGCalGeom") << "u|v " << u << ":" << v << " N " << n << " type " << type << " rot " << rotn
393  << " good " << good;
394 #endif
395  return good;
396 }
397 
398 bool HGCalWaferMask::goodCell(int u, int v, int waferType) {
399  // for V17
400  bool good(false);
401  switch (waferType) {
402  case (HGCalTypes::WaferFull): { //WaferFull
403  good = true;
404  break;
405  }
406  case (HGCalTypes::WaferLDTop): {
408  break;
409  }
410  case (HGCalTypes::WaferLDBottom): {
413  break;
414  }
415  case (HGCalTypes::WaferLDLeft): {
416  good =
418  break;
419  }
420  case (HGCalTypes::WaferLDRight): {
423  break;
424  }
425  case (HGCalTypes::WaferLDFive): {
426  good =
428  break;
429  }
430  case (HGCalTypes::WaferLDThree): {
433  break;
434  }
435  case (HGCalTypes::WaferHDTop): {
437  break;
438  }
439  case (HGCalTypes::WaferHDBottom): {
442  break;
443  }
444  case (HGCalTypes::WaferHDLeft): {
445  good =
447  break;
448  }
449  case (HGCalTypes::WaferHDRight): {
452  break;
453  }
454  case (HGCalTypes::WaferHDFive): {
455  good =
457  break;
458  }
459  }
460 #ifdef EDM_ML_DEBUG
461  edm::LogVerbatim("HGCalGeom") << "u|v " << u << ":" << v << " WaferType " << waferType << " good " << good;
462 #endif
463  return good;
464 }
465 
466 int HGCalWaferMask::getRotation(int zside, int type, int rotn) {
467  // Needs extension for V17
468  if (rotn >= HGCalTypes::WaferCornerMax)
470  int newrotn(rotn);
471  if ((zside < 0) && (type != HGCalTypes::WaferFull)) {
472  if ((type == HGCalTypes::WaferFive) || (type == HGCalTypes::WaferFive2)) { //WaferFive/WaferFive2
473  static constexpr int rot1[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner4,
479  newrotn = rot1[rotn];
480  } else if ((type == HGCalTypes::WaferThree) || (type == HGCalTypes::WaferSemi) ||
481  (type == HGCalTypes::WaferSemi2)) { //WaferThree/WaferSemi/WaferSemi2
482  static constexpr int rot2[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner2,
488  newrotn = rot2[rotn];
489  } else { //WaferHalf/WaferChopTwo/WaferChopTwoM/WaferHalf2
490  static constexpr int rot3[HGCalTypes::WaferCornerMax] = {HGCalTypes::WaferCorner3,
496  newrotn = rot3[rotn];
497  }
498  }
499 #ifdef EDM_ML_DEBUG
500  edm::LogVerbatim("HGCalGeom") << "zside " << zside << " type " << type << " rotn " << rotn << ":" << newrotn;
501 #endif
502  return newrotn;
503 }
504 
505 std::pair<int, int> HGCalWaferMask::getTypeMode(const double& xpos,
506  const double& ypos,
507  const double& delX,
508  const double& delY,
509  const double& rin,
510  const double& rout,
511  const int& wType,
512  const int& mode,
513  bool debug) {
514  // No need to extend this for V17 -- use flat file information only
515  int ncor(0), iok(0);
517 
518  static constexpr int corners = 6;
519  static constexpr int base = 10;
520  double rin2 = rin * rin;
521  double rout2 = rout * rout;
522  double dx0[corners] = {HGCalTypes::c00 * delX,
523  HGCalTypes::c10 * delX,
524  HGCalTypes::c10 * delX,
525  HGCalTypes::c00 * delX,
526  -HGCalTypes::c10 * delX,
527  -HGCalTypes::c10 * delX};
528  double dy0[corners] = {-HGCalTypes::c10 * delY,
529  -HGCalTypes::c50 * delY,
530  HGCalTypes::c50 * delY,
531  HGCalTypes::c10 * delY,
532  HGCalTypes::c50 * delY,
533  -HGCalTypes::c50 * delY};
534  double xc[corners], yc[corners];
535  for (int k = 0; k < corners; ++k) {
536  xc[k] = xpos + dx0[k];
537  yc[k] = ypos + dy0[k];
538  double rpos2 = (xc[k] * xc[k] + yc[k] * yc[k]);
539  if (rpos2 <= rout2 && rpos2 >= rin2) {
540  ++ncor;
541  iok = iok * base + 1;
542  } else {
543  iok *= base;
544  }
545  }
546  if (debug)
547  edm::LogVerbatim("HGCalGeom") << "I/p " << xpos << ":" << ypos << ":" << delX << ":" << delY << ":" << rin << ":"
548  << rout << ":" << wType << ":" << mode << " Corners " << ncor << " iok " << iok;
549 
550  static constexpr int ipat5[corners] = {101111, 110111, 111011, 111101, 111110, 11111};
551  static constexpr int ipat4[corners] = {100111, 110011, 111001, 111100, 11110, 1111};
552  static constexpr int ipat3[corners] = {100011, 110001, 111000, 11100, 1110, 111};
553  static constexpr int ipat2[corners] = {11, 100001, 110000, 11000, 1100, 110};
554  double dx1[corners] = {HGCalTypes::c50 * delX,
555  HGCalTypes::c10 * delX,
556  HGCalTypes::c50 * delX,
557  -HGCalTypes::c50 * delX,
558  -HGCalTypes::c10 * delX,
559  -HGCalTypes::c50 * delX};
560  double dy1[corners] = {-HGCalTypes::c75 * delY,
561  HGCalTypes::c00 * delY,
562  HGCalTypes::c75 * delY,
563  HGCalTypes::c75 * delY,
564  HGCalTypes::c00 * delY,
565  -HGCalTypes::c75 * delY};
566  double dx2[corners] = {HGCalTypes::c50 * delX,
567  -HGCalTypes::c50 * delX,
568  -HGCalTypes::c10 * delX,
569  -HGCalTypes::c50 * delX,
570  HGCalTypes::c50 * delX,
571  HGCalTypes::c10 * delX};
572  double dy2[corners] = {HGCalTypes::c75 * delY,
573  HGCalTypes::c75 * delY,
574  HGCalTypes::c00 * delY,
575  -HGCalTypes::c75 * delY,
576  -HGCalTypes::c75 * delY,
577  HGCalTypes::c00 * delY};
578  double dx3[corners] = {HGCalTypes::c22 * delX,
579  HGCalTypes::c10 * delX,
580  HGCalTypes::c77 * delX,
581  -HGCalTypes::c22 * delX,
582  -HGCalTypes::c10 * delX,
583  -HGCalTypes::c77 * delX};
584  double dy3[corners] = {-HGCalTypes::c88 * delY,
585  -HGCalTypes::c27 * delY,
586  HGCalTypes::c61 * delY,
587  HGCalTypes::c88 * delY,
588  HGCalTypes::c27 * delY,
589  -HGCalTypes::c61 * delY};
590  double dx4[corners] = {HGCalTypes::c22 * delX,
591  -HGCalTypes::c77 * delX,
592  -HGCalTypes::c10 * delX,
593  -HGCalTypes::c22 * delX,
594  HGCalTypes::c77 * delX,
595  HGCalTypes::c10 * delX};
596  double dy4[corners] = {HGCalTypes::c88 * delY,
597  HGCalTypes::c61 * delY,
598  -HGCalTypes::c27 * delY,
599  -HGCalTypes::c88 * delY,
600  -HGCalTypes::c61 * delY,
601  HGCalTypes::c27 * delY};
602  double dx5[corners] = {-HGCalTypes::c50 * delX,
603  -HGCalTypes::c10 * delX,
604  -HGCalTypes::c50 * delX,
605  HGCalTypes::c50 * delX,
606  HGCalTypes::c10 * delX,
607  HGCalTypes::c50 * delX};
608  double dy5[corners] = {HGCalTypes::c75 * delY,
609  HGCalTypes::c00 * delY,
610  -HGCalTypes::c75 * delY,
611  -HGCalTypes::c75 * delY,
612  HGCalTypes::c00 * delY,
613  HGCalTypes::c75 * delY};
614  double dx6[corners] = {-HGCalTypes::c77 * delX,
615  -HGCalTypes::c10 * delX,
616  -HGCalTypes::c22 * delX,
617  HGCalTypes::c77 * delX,
618  HGCalTypes::c10 * delX,
619  HGCalTypes::c22 * delX};
620  double dy6[corners] = {HGCalTypes::c61 * delY,
621  -HGCalTypes::c27 * delY,
622  -HGCalTypes::c88 * delY,
623  -HGCalTypes::c61 * delY,
624  HGCalTypes::c27 * delY,
625  HGCalTypes::c88 * delY};
626  double dx7[corners] = {-HGCalTypes::c22 * delX,
627  -HGCalTypes::c10 * delX,
628  -HGCalTypes::c77 * delX,
629  HGCalTypes::c22 * delX,
630  HGCalTypes::c10 * delX,
631  HGCalTypes::c77 * delX};
632  double dy7[corners] = {HGCalTypes::c88 * delY,
633  HGCalTypes::c27 * delY,
634  -HGCalTypes::c61 * delY,
635  -HGCalTypes::c88 * delY,
636  -HGCalTypes::c27 * delY,
637  HGCalTypes::c61 * delY};
638  double dx8[corners] = {HGCalTypes::c77 * delX,
639  HGCalTypes::c10 * delX,
640  HGCalTypes::c22 * delX,
641  -HGCalTypes::c77 * delX,
642  -HGCalTypes::c10 * delX,
643  -HGCalTypes::c22 * delX};
644  double dy8[corners] = {-HGCalTypes::c61 * delY,
645  HGCalTypes::c27 * delY,
646  HGCalTypes::c88 * delY,
647  HGCalTypes::c61 * delY,
648  -HGCalTypes::c27 * delY,
649  -HGCalTypes::c88 * delY};
650  double dx9[corners] = {-HGCalTypes::c22 * delX,
651  HGCalTypes::c77 * delX,
652  HGCalTypes::c10 * delX,
653  HGCalTypes::c22 * delX,
654  -HGCalTypes::c77 * delX,
655  -HGCalTypes::c10 * delX};
656  double dy9[corners] = {-HGCalTypes::c88 * delY,
657  -HGCalTypes::c61 * delY,
658  HGCalTypes::c27 * delY,
659  HGCalTypes::c88 * delY,
660  HGCalTypes::c61 * delY,
661  -HGCalTypes::c27 * delY};
662 
663  if (ncor == HGCalGeomTools::k_allCorners) {
664  } else if (ncor == HGCalGeomTools::k_fiveCorners) {
665  rotn = static_cast<int>(std::find(ipat5, ipat5 + 6, iok) - ipat5);
667  } else if (ncor == HGCalGeomTools::k_fourCorners) {
668  rotn = static_cast<int>(std::find(ipat4, ipat4 + 6, iok) - ipat4);
670  double rpos12 = ((xpos + dx1[rotn]) * (xpos + dx1[rotn]) + (ypos + dy1[rotn]) * (ypos + dy1[rotn]));
671  double rpos22(0);
672  if (rpos12 <= rout2 && rpos12 >= rin2) {
673  rpos22 = ((xpos + dx2[rotn]) * (xpos + dx2[rotn]) + (ypos + dy2[rotn]) * (ypos + dy2[rotn]));
674  if (rpos22 <= rout2 && rpos22 >= rin2)
676  }
677  if (debug)
678  edm::LogVerbatim("HGCalGeom") << "Test for Chop2 " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
679  << type;
680  if ((type == HGCalTypes::WaferHalf) && (wType == 0)) {
681  rpos12 = ((xpos + dx3[rotn]) * (xpos + dx3[rotn]) + (ypos + dy3[rotn]) * (ypos + dy3[rotn]));
682  if (rpos12 <= rout2 && rpos12 >= rin2) {
683  rpos22 = ((xpos + dx4[rotn]) * (xpos + dx4[rotn]) + (ypos + dy4[rotn]) * (ypos + dy4[rotn]));
684  if (rpos22 <= rout2 && rpos22 >= rin2)
686  }
687  if (debug)
688  edm::LogVerbatim("HGCalGeom") << "Test for Chop2M " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
689  << type;
690  }
691  } else if (ncor == HGCalGeomTools::k_threeCorners) {
692  rotn = static_cast<int>(std::find(ipat3, ipat3 + 6, iok) - ipat3);
694  double rpos12 = ((xpos + dx7[rotn]) * (xpos + dx7[rotn]) + (ypos + dy7[rotn]) * (ypos + dy7[rotn]));
695  double rpos22(0);
696  if (rpos12 <= rout2 && rpos12 >= rin2) {
697  rpos22 = ((xpos + dx8[rotn]) * (xpos + dx8[rotn]) + (ypos + dy8[rotn]) * (ypos + dy8[rotn]));
698  if (rpos22 <= rout2 && rpos22 >= rin2)
700  }
701  if (debug)
702  edm::LogVerbatim("HGCalGeom") << "Test for Five2 " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
703  << type;
704  if ((type == HGCalTypes::WaferThree) && (wType == 0)) {
705  rpos12 = ((xpos + dx1[rotn]) * (xpos + dx1[rotn]) + (ypos + dy1[rotn]) * (ypos + dy1[rotn]));
706  if (rpos12 <= rout2 && rpos12 >= rin2) {
707  rpos22 = ((xpos + dx5[rotn]) * (xpos + dx5[rotn]) + (ypos + dy5[rotn]) * (ypos + dy5[rotn]));
708  if (rpos22 <= rout2 && rpos22 >= rin2)
710  }
711  if (debug)
712  edm::LogVerbatim("HGCalGeom") << "Test for Semi " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
713  << type;
714  }
715  if ((type == HGCalTypes::WaferThree) && (wType == 0)) {
716  rpos12 = ((xpos + dx3[rotn]) * (xpos + dx3[rotn]) + (ypos + dy3[rotn]) * (ypos + dy3[rotn]));
717  if (rpos12 <= rout2 && rpos12 >= rin2) {
718  rpos22 = ((xpos + dx6[rotn]) * (xpos + dx6[rotn]) + (ypos + dy6[rotn]) * (ypos + dy6[rotn]));
719  if (rpos22 <= rout2 && rpos22 >= rin2)
721  }
722  if (debug)
723  edm::LogVerbatim("HGCalGeom") << "Test for SemiM " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
724  << type;
725  }
726  } else if (ncor == HGCalGeomTools::k_twoCorners) {
727  rotn = static_cast<int>(std::find(ipat2, ipat2 + 6, iok) - ipat2);
729  double rpos12 = ((xpos + dx7[rotn]) * (xpos + dx7[rotn]) + (ypos + dy7[rotn]) * (ypos + dy7[rotn]));
730  double rpos22(0);
731  if (rpos12 <= rout2 && rpos12 >= rin2) {
732  rpos22 = ((xpos + dx9[rotn]) * (xpos + dx9[rotn]) + (ypos + dy9[rotn]) * (ypos + dy9[rotn]));
733  if (rpos22 <= rout2 && rpos22 >= rin2)
735  else
737  }
738  if (debug)
739  edm::LogVerbatim("HGCalGeom") << "Test for Half2 " << std::sqrt(rpos12) << ":" << std::sqrt(rpos22) << " Type "
740  << type;
741  } else {
743  }
744 
745  if (debug)
746  edm::LogVerbatim("HGCalGeom") << "I/p " << xpos << ":" << ypos << ":" << delX << ":" << delY << ":" << rin << ":"
747  << rout << ":" << wType << ":" << mode << " o/p " << iok << ":" << ncor << ":" << type
748  << ":" << rotn;
749  return ((mode == 0) ? std::make_pair(ncor, rotn) : std::make_pair(type, (rotn + HGCalTypes::k_OffsetRotation)));
750 }
751 
753  double xpos, double ypos, double delX, double delY, double rin, double rout, int part, int rotn, bool debug) {
754  // Needs extension for V17
756  return false;
757  if (rotn < 0 || rotn > HGCalTypes::WaferCornerMax)
758  return false;
759  double rin2 = rin * rin;
760  double rout2 = rout * rout;
761  double rpos2(0);
762  static constexpr int corners = HGCalTypes::WaferCornerMax;
763  static constexpr int corner2 = 2 * HGCalTypes::WaferCornerMax;
764  static constexpr int base = 10;
765  static constexpr int base2 = 100;
766  double dx0[corners] = {HGCalTypes::c00 * delX,
767  HGCalTypes::c10 * delX,
768  HGCalTypes::c10 * delX,
769  HGCalTypes::c00 * delX,
770  -HGCalTypes::c10 * delX,
771  -HGCalTypes::c10 * delX};
772  double dy0[corners] = {-HGCalTypes::c10 * delY,
773  -HGCalTypes::c50 * delY,
774  HGCalTypes::c50 * delY,
775  HGCalTypes::c10 * delY,
776  HGCalTypes::c50 * delY,
777  -HGCalTypes::c50 * delY};
778  double dx1[corners] = {HGCalTypes::c50 * delX,
779  HGCalTypes::c10 * delX,
780  HGCalTypes::c50 * delX,
781  -HGCalTypes::c50 * delX,
782  -HGCalTypes::c10 * delX,
783  -HGCalTypes::c50 * delX};
784  double dy1[corners] = {-HGCalTypes::c75 * delY,
785  HGCalTypes::c00 * delY,
786  HGCalTypes::c75 * delY,
787  HGCalTypes::c75 * delY,
788  HGCalTypes::c00 * delY,
789  -HGCalTypes::c75 * delY};
790  double dx2[corner2] = {HGCalTypes::c22 * delX,
791  HGCalTypes::c77 * delX,
792  HGCalTypes::c10 * delX,
793  HGCalTypes::c10 * delX,
794  HGCalTypes::c77 * delX,
795  HGCalTypes::c22 * delX,
796  -HGCalTypes::c22 * delX,
797  -HGCalTypes::c77 * delX,
798  -HGCalTypes::c10 * delX,
799  -HGCalTypes::c10 * delX,
800  -HGCalTypes::c77 * delX,
801  -HGCalTypes::c22 * delX};
802  double dy2[corner2] = {-HGCalTypes::c88 * delY,
803  -HGCalTypes::c61 * delY,
804  -HGCalTypes::c27 * delY,
805  HGCalTypes::c27 * delY,
806  HGCalTypes::c61 * delY,
807  HGCalTypes::c88 * delY,
808  HGCalTypes::c88 * delY,
809  HGCalTypes::c61 * delY,
810  HGCalTypes::c27 * delY,
811  -HGCalTypes::c27 * delY,
812  -HGCalTypes::c61 * delY,
813  -HGCalTypes::c88 * delY};
814  bool ok(true);
815  int ncf(-1);
816  switch (part) {
817  case (HGCalTypes::WaferThree): {
818  static constexpr int nc0[corners] = {450, 150, 201, 312, 423, 534};
819  int nc = nc0[rotn];
820  for (int k1 = 0; k1 < 3; ++k1) {
821  int k = nc % base;
822  double xc1 = xpos + dx0[k];
823  double yc1 = ypos + dy0[k];
824  rpos2 = (xc1 * xc1 + yc1 * yc1);
825  if ((rpos2 > rout2) || (rpos2 < rin2)) {
826  ok = false;
827  ncf = k;
828  break;
829  }
830  nc /= base;
831  }
832  break;
833  }
834  case (HGCalTypes::WaferSemi2): {
835  static constexpr int nc10[corners] = {450, 150, 201, 312, 423, 534};
836  static constexpr int nc11[corners] = {700, 902, 1104, 106, 308, 510};
837  int nc = nc10[rotn];
838  for (int k1 = 0; k1 < 3; ++k1) {
839  int k = nc % base;
840  double xc1 = xpos + dx0[k];
841  double yc1 = ypos + dy0[k];
842  rpos2 = (xc1 * xc1 + yc1 * yc1);
843  if ((rpos2 > rout2) || (rpos2 < rin2)) {
844  ok = false;
845  ncf = k;
846  break;
847  }
848  nc /= base;
849  }
850  nc = nc11[rotn];
851  for (int k1 = 0; k1 < 2; ++k1) {
852  int k = nc % base2;
853  double xc1 = xpos + dx2[k];
854  double yc1 = ypos + dy2[k];
855  rpos2 = (xc1 * xc1 + yc1 * yc1);
856  if ((rpos2 > rout2) || (rpos2 < rin2)) {
857  ok = false;
858  ncf = k + base2;
859  break;
860  }
861  nc /= base2;
862  }
863  break;
864  }
865  case (HGCalTypes::WaferSemi): {
866  static constexpr int nc20[corners] = {450, 150, 201, 312, 423, 534};
867  static constexpr int nc21[corners] = {30, 14, 25, 30, 41, 52};
868  int nc = nc20[rotn];
869  for (int k1 = 0; k1 < 3; ++k1) {
870  int k = nc % base;
871  double xc1 = xpos + dx0[k];
872  double yc1 = ypos + dy0[k];
873  rpos2 = (xc1 * xc1 + yc1 * yc1);
874  if ((rpos2 > rout2) || (rpos2 < rin2)) {
875  ok = false;
876  ncf = k;
877  break;
878  }
879  nc /= base;
880  }
881  nc = nc21[rotn];
882  for (int k1 = 0; k1 < 2; ++k1) {
883  int k = nc % base;
884  double xc1 = xpos + dx1[k];
885  double yc1 = ypos + dy1[k];
886  rpos2 = (xc1 * xc1 + yc1 * yc1);
887  if ((rpos2 > rout2) || (rpos2 < rin2)) {
888  ok = false;
889  ncf = k + base2;
890  break;
891  }
892  nc /= base;
893  }
894  break;
895  }
896  case (HGCalTypes::WaferHalf): {
897  static constexpr int nc3[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
898  int nc = nc3[rotn];
899  for (int k1 = 0; k1 < 4; ++k1) {
900  int k = nc % base;
901  double xc1 = xpos + dx0[k];
902  double yc1 = ypos + dy0[k];
903  rpos2 = (xc1 * xc1 + yc1 * yc1);
904  if ((rpos2 > rout2) || (rpos2 < rin2)) {
905  ok = false;
906  ncf = k;
907  break;
908  }
909  nc /= base;
910  }
911  break;
912  }
913  case (HGCalTypes::WaferChopTwoM): {
914  static constexpr int nc40[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
915  static constexpr int nc41[corners] = {500, 702, 904, 1106, 108, 310};
916  int nc = nc40[rotn];
917  for (int k1 = 0; k1 < 4; ++k1) {
918  int k = nc % base;
919  double xc1 = xpos + dx0[k];
920  double yc1 = ypos + dy0[k];
921  rpos2 = (xc1 * xc1 + yc1 * yc1);
922  if ((rpos2 > rout2) || (rpos2 < rin2)) {
923  ok = false;
924  ncf = k;
925  break;
926  }
927  nc /= base;
928  }
929  nc = nc41[rotn];
930  for (int k1 = 0; k1 < 2; ++k1) {
931  int k = nc % base2;
932  double xc1 = xpos + dx2[k];
933  double yc1 = ypos + dy2[k];
934  rpos2 = (xc1 * xc1 + yc1 * yc1);
935  if ((rpos2 > rout2) || (rpos2 < rin2)) {
936  ok = false;
937  ncf = k + base2;
938  break;
939  }
940  nc /= base2;
941  }
942  break;
943  }
944  case (HGCalTypes::WaferChopTwo): {
945  static constexpr int nc50[corners] = {3450, 1450, 2501, 3012, 4123, 5234};
946  static constexpr int nc51[corners] = {20, 13, 24, 35, 40, 51};
947  int nc = nc50[rotn];
948  for (int k1 = 0; k1 < 4; ++k1) {
949  int k = nc % base;
950  double xc1 = xpos + dx0[k];
951  double yc1 = ypos + dy0[k];
952  rpos2 = (xc1 * xc1 + yc1 * yc1);
953  if ((rpos2 > rout2) || (rpos2 < rin2)) {
954  ok = false;
955  ncf = k;
956  break;
957  }
958  nc /= base;
959  }
960  nc = nc51[rotn];
961  for (int k1 = 0; k1 < 2; ++k1) {
962  int k = nc % base;
963  double xc1 = xpos + dx1[k];
964  double yc1 = ypos + dy1[k];
965  rpos2 = (xc1 * xc1 + yc1 * yc1);
966  if ((rpos2 > rout2) || (rpos2 < rin2)) {
967  ok = false;
968  ncf = k + base2;
969  break;
970  }
971  nc /= base;
972  }
973  break;
974  }
975  case (HGCalTypes::WaferFive): {
976  static constexpr int nc6[corners] = {23450, 13450, 24501, 35012, 40123, 51234};
977  int nc = nc6[rotn];
978  for (int k1 = 0; k1 < 5; ++k1) {
979  int k = nc % base;
980  double xc1 = xpos + dx0[k];
981  double yc1 = ypos + dy0[k];
982  rpos2 = (xc1 * xc1 + yc1 * yc1);
983  if ((rpos2 > rout2) || (rpos2 < rin2)) {
984  ok = false;
985  ncf = k;
986  break;
987  }
988  }
989  break;
990  }
991  case (HGCalTypes::WaferFive2): {
992  static constexpr int nc60[corners] = {450, 150, 201, 312, 423, 534};
993  static constexpr int nc61[corners] = {601, 803, 1005, 7, 209, 411};
994  int nc = nc60[rotn];
995  for (int k1 = 0; k1 < 3; ++k1) {
996  int k = nc % base;
997  double xc1 = xpos + dx0[k];
998  double yc1 = ypos + dy0[k];
999  rpos2 = (xc1 * xc1 + yc1 * yc1);
1000  if ((rpos2 > rout2) || (rpos2 < rin2)) {
1001  ok = false;
1002  ncf = k;
1003  break;
1004  }
1005  nc /= base;
1006  }
1007  nc = nc61[rotn];
1008  for (int k1 = 0; k1 < 2; ++k1) {
1009  int k = nc % base2;
1010  double xc1 = xpos + dx2[k];
1011  double yc1 = ypos + dy2[k];
1012  rpos2 = (xc1 * xc1 + yc1 * yc1);
1013  if ((rpos2 > rout2) || (rpos2 < rin2)) {
1014  ok = false;
1015  ncf = k + base2;
1016  break;
1017  }
1018  nc /= base2;
1019  }
1020  break;
1021  }
1022  case (HGCalTypes::WaferHalf2): {
1023  static constexpr int nc70[corners] = {45, 50, 1, 12, 23, 34};
1024  static constexpr int nc71[corners] = {611, 801, 1003, 5, 207, 409};
1025  int nc = nc70[rotn];
1026  for (int k1 = 0; k1 < 2; ++k1) {
1027  int k = nc % base;
1028  double xc1 = xpos + dx0[k];
1029  double yc1 = ypos + dy0[k];
1030  rpos2 = (xc1 * xc1 + yc1 * yc1);
1031  if ((rpos2 > rout2) || (rpos2 < rin2)) {
1032  ok = false;
1033  ncf = k;
1034  break;
1035  }
1036  nc /= base;
1037  }
1038  nc = nc71[rotn];
1039  for (int k1 = 0; k1 < 2; ++k1) {
1040  int k = nc % base2;
1041  double xc1 = xpos + dx2[k];
1042  double yc1 = ypos + dy2[k];
1043  rpos2 = (xc1 * xc1 + yc1 * yc1);
1044  if ((rpos2 > rout2) || (rpos2 < rin2)) {
1045  ok = false;
1046  ncf = k + base2;
1047  break;
1048  }
1049  nc /= base2;
1050  }
1051  break;
1052  }
1053  default: {
1054  for (int k = 0; k < corners; ++k) {
1055  double xc1 = xpos + dx0[k];
1056  double yc1 = ypos + dy0[k];
1057  rpos2 = (xc1 * xc1 + yc1 * yc1);
1058  if ((rpos2 > rout2) || (rpos2 < rin2)) {
1059  ok = false;
1060  ncf = k;
1061  break;
1062  }
1063  }
1064  break;
1065  }
1066  }
1067  if (debug || (!ok))
1068  edm::LogVerbatim("HGCalGeom") << "I/p "
1069  << ":" << xpos << ":" << ypos << ":" << delX << ":" << delY << ":" << rin << ":"
1070  << rout << ":" << part << ":" << rotn << " Results " << ok << ":" << ncf << " R "
1071  << rin2 << ":" << rout2 << ":" << rpos2;
1072  return ok;
1073 }
1074 
1075 std::vector<std::pair<double, double> > HGCalWaferMask::waferXY(
1076  int part, int ori, int zside, double delX, double delY, double xpos, double ypos) {
1077  // Good for V15 and V16 versions
1078  std::vector<std::pair<double, double> > xy;
1079  int orient = getRotation(-zside, part, ori);
1080 #ifdef EDM_ML_DEBUG
1081  edm::LogVerbatim("HGCalGeom") << "Part " << part << " zSide " << zside << " Orient " << ori << ":" << orient;
1082 #endif
1083  /*
1084  The exact contour of partial wafers are obtained by joining points on
1085  the circumference of a full wafer.
1086  Numbering the points along the edges of a hexagonal wafer, starting from
1087  the bottom corner:
1088 
1089  3
1090  15 18
1091  9 8
1092  19 14
1093  4 2
1094  16 23
1095  10 7
1096  20 13
1097  5 1
1098  17 22
1099  11 6
1100  21 12
1101  0
1102 
1103  Depending on the wafer type and orientation index, the corners
1104  are chosen in the variable *np*
1105  */
1106  double dx[24] = {HGCalTypes::c00 * delX, HGCalTypes::c10 * delX, HGCalTypes::c10 * delX, HGCalTypes::c00 * delX,
1107  -HGCalTypes::c10 * delX, -HGCalTypes::c10 * delX, HGCalTypes::c50 * delX, HGCalTypes::c10 * delX,
1108  HGCalTypes::c50 * delX, -HGCalTypes::c50 * delX, -HGCalTypes::c10 * delX, -HGCalTypes::c50 * delX,
1109  HGCalTypes::c22 * delX, HGCalTypes::c10 * delX, HGCalTypes::c77 * delX, -HGCalTypes::c22 * delX,
1110  -HGCalTypes::c10 * delX, -HGCalTypes::c77 * delX, HGCalTypes::c22 * delX, -HGCalTypes::c77 * delX,
1111  -HGCalTypes::c10 * delX, -HGCalTypes::c22 * delX, HGCalTypes::c77 * delX, HGCalTypes::c10 * delX};
1112  double dy[24] = {-HGCalTypes::c10 * delY, -HGCalTypes::c50 * delY, HGCalTypes::c50 * delY, HGCalTypes::c10 * delY,
1113  HGCalTypes::c50 * delY, -HGCalTypes::c50 * delY, -HGCalTypes::c75 * delY, HGCalTypes::c00 * delY,
1114  HGCalTypes::c75 * delY, HGCalTypes::c75 * delY, HGCalTypes::c00 * delY, -HGCalTypes::c75 * delY,
1115  -HGCalTypes::c88 * delY, -HGCalTypes::c27 * delY, HGCalTypes::c61 * delY, HGCalTypes::c88 * delY,
1116  HGCalTypes::c27 * delY, -HGCalTypes::c61 * delY, HGCalTypes::c88 * delY, HGCalTypes::c61 * delY,
1117  -HGCalTypes::c27 * delY, -HGCalTypes::c88 * delY, -HGCalTypes::c61 * delY, HGCalTypes::c27 * delY};
1118  if (part == HGCalTypes::WaferFull) {
1119  int np[7] = {0, 1, 2, 3, 4, 5, 0};
1120  for (int k = 0; k < 7; ++k)
1121  xy.push_back(std::make_pair((xpos + dx[np[k]]), (ypos + dy[np[k]])));
1122  } else if (part == HGCalTypes::WaferFive) {
1123  int np[6][6] = {{0, 2, 3, 4, 5, 0},
1124  {1, 3, 4, 5, 0, 1},
1125  {2, 4, 5, 0, 1, 2},
1126  {3, 5, 0, 1, 2, 3},
1127  {4, 0, 1, 2, 3, 4},
1128  {5, 1, 2, 3, 4, 5}};
1129  for (int k = 0; k < 6; ++k) {
1130  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1131 #ifdef EDM_ML_DEBUG
1132  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1133  << dy[np[orient][k]];
1134 #endif
1135  }
1136  } else if (part == HGCalTypes::WaferHalf) {
1137  int np[6][5] = {
1138  {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}};
1139  for (int k = 0; k < 5; ++k) {
1140  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1141 #ifdef EDM_ML_DEBUG
1142  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1143  << dy[np[orient][k]];
1144 #endif
1145  }
1146  } else if (part == HGCalTypes::WaferThree) {
1147  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}};
1148  for (int k = 0; k < 4; ++k) {
1149  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1150 #ifdef EDM_ML_DEBUG
1151  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1152  << dy[np[orient][k]];
1153 #endif
1154  }
1155  } else if (part == HGCalTypes::WaferChopTwo) {
1156  int np[6][7] = {{6, 8, 3, 4, 5, 0, 6},
1157  {7, 9, 4, 5, 0, 1, 7},
1158  {8, 10, 5, 0, 1, 2, 8},
1159  {9, 11, 0, 1, 2, 3, 9},
1160  {10, 6, 1, 2, 3, 4, 10},
1161  {11, 7, 2, 3, 4, 5, 11}};
1162  for (int k = 0; k < 7; ++k) {
1163  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1164 #ifdef EDM_ML_DEBUG
1165  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1166  << dy[np[orient][k]];
1167 #endif
1168  }
1169  } else if (part == HGCalTypes::WaferSemi) {
1170  int np[6][6] = {{6, 9, 4, 5, 0, 6},
1171  {7, 10, 5, 0, 1, 7},
1172  {8, 11, 0, 1, 2, 8},
1173  {9, 6, 1, 2, 3, 9},
1174  {10, 7, 2, 3, 4, 10},
1175  {11, 8, 3, 4, 5, 11}};
1176  for (int k = 0; k < 6; ++k) {
1177  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1178 #ifdef EDM_ML_DEBUG
1179  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1180  << dy[np[orient][k]];
1181 #endif
1182  }
1183  } else if (part == HGCalTypes::WaferChopTwoM) {
1184  int np[6][7] = {{12, 18, 3, 4, 5, 0, 12},
1185  {13, 19, 4, 5, 0, 1, 13},
1186  {14, 20, 5, 0, 1, 2, 14},
1187  {15, 21, 0, 1, 2, 3, 15},
1188  {16, 22, 1, 2, 3, 4, 16},
1189  {17, 23, 2, 3, 4, 5, 17}};
1190  for (int k = 0; k < 7; ++k) {
1191  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1192 #ifdef EDM_ML_DEBUG
1193  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1194  << dy[np[orient][k]];
1195 #endif
1196  }
1197  } else if (part == HGCalTypes::WaferSemi2) {
1198  int np[6][6] = {{12, 19, 4, 5, 0, 12},
1199  {13, 20, 5, 0, 1, 13},
1200  {14, 21, 0, 1, 2, 14},
1201  {15, 22, 1, 2, 3, 15},
1202  {16, 23, 2, 3, 4, 16},
1203  {17, 18, 3, 4, 5, 17}};
1204  for (int k = 0; k < 6; ++k) {
1205  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1206 #ifdef EDM_ML_DEBUG
1207  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1208  << dy[np[orient][k]];
1209 #endif
1210  }
1211  } else if (part == HGCalTypes::WaferFive2) {
1212  int np[6][6] = {{22, 15, 4, 5, 0, 22},
1213  {23, 16, 5, 0, 1, 23},
1214  {18, 17, 0, 1, 2, 18},
1215  {19, 12, 1, 2, 3, 19},
1216  {20, 13, 2, 3, 4, 20},
1217  {21, 14, 3, 4, 5, 21}};
1218  for (int k = 0; k < 6; ++k) {
1219  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1220 #ifdef EDM_ML_DEBUG
1221  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1222  << dy[np[orient][k]];
1223 #endif
1224  }
1225  } else if (part == HGCalTypes::WaferHalf2) {
1226  int np[6][5] = {{21, 15, 4, 5, 21},
1227  {22, 16, 5, 0, 22},
1228  {23, 17, 0, 1, 23},
1229  {18, 12, 1, 2, 18},
1230  {19, 13, 2, 3, 19},
1231  {20, 14, 3, 4, 20}};
1232  for (int k = 0; k < 5; ++k) {
1233  xy.push_back(std::make_pair((xpos + dx[np[orient][k]]), (ypos + dy[np[orient][k]])));
1234 #ifdef EDM_ML_DEBUG
1235  edm::LogVerbatim("HGCalGeom") << k << ":" << np[orient][k] << ":" << dx[np[orient][k]] << ":"
1236  << dy[np[orient][k]];
1237 #endif
1238  }
1239  }
1240 #ifdef EDM_ML_DEBUG
1241  edm::LogVerbatim("HGCalGeom") << "I/p: " << part << ":" << ori << ":" << zside << ":" << delX << ":" << delY << ":"
1242  << xpos << ":" << ypos << " O/p having " << xy.size() << " points:";
1243  std::ostringstream st1;
1244  for (unsigned int i = 0; i < xy.size(); ++i)
1245  st1 << " [" << i << "] " << xy[i].first << ":" << xy[i].second;
1246  edm::LogVerbatim("HGCalGeom") << st1.str();
1247 #endif
1248  return xy;
1249 }
1250 
1251 std::vector<std::pair<double, double> > HGCalWaferMask::waferXY(
1252  int part, int place, double delX, double delY, double xpos, double ypos) {
1253  std::vector<std::pair<double, double> > xy;
1254  // Good for V17 version and uses partial wafer type & placement index
1255 #ifdef EDM_ML_DEBUG
1256  edm::LogVerbatim("HGCalGeom") << "Part " << part << " Placement Index " << place;
1257 #endif
1258  /*
1259  The exact contour of partial wafers are obtained by joining points on
1260  the circumference of a full wafer.
1261  Numbering the points along the edges of a hexagonal wafer, starting from
1262  the bottom corner:
1263 
1264  3
1265  15 18
1266  9 8
1267  19 14
1268  4 2
1269  16 23
1270  10 7
1271  20 13
1272  5 1
1273  17 22
1274  11 6
1275  21 12
1276  0
1277 
1278  Depending on the wafer type and placement index, the corners
1279  are chosen in the variable *np*
1280  */
1281  double dx[24] = {HGCalTypes::c00 * delX, HGCalTypes::c10 * delX, HGCalTypes::c10 * delX, HGCalTypes::c00 * delX,
1282  -HGCalTypes::c10 * delX, -HGCalTypes::c10 * delX, HGCalTypes::c50 * delX, HGCalTypes::c10 * delX,
1283  HGCalTypes::c50 * delX, -HGCalTypes::c50 * delX, -HGCalTypes::c10 * delX, -HGCalTypes::c50 * delX,
1284  HGCalTypes::c22 * delX, HGCalTypes::c10 * delX, HGCalTypes::c77 * delX, -HGCalTypes::c22 * delX,
1285  -HGCalTypes::c10 * delX, -HGCalTypes::c77 * delX, HGCalTypes::c22 * delX, -HGCalTypes::c77 * delX,
1286  -HGCalTypes::c10 * delX, -HGCalTypes::c22 * delX, HGCalTypes::c77 * delX, HGCalTypes::c10 * delX};
1287  double dy[24] = {-HGCalTypes::c10 * delY, -HGCalTypes::c50 * delY, HGCalTypes::c50 * delY, HGCalTypes::c10 * delY,
1288  HGCalTypes::c50 * delY, -HGCalTypes::c50 * delY, -HGCalTypes::c75 * delY, HGCalTypes::c00 * delY,
1289  HGCalTypes::c75 * delY, HGCalTypes::c75 * delY, HGCalTypes::c00 * delY, -HGCalTypes::c75 * delY,
1290  -HGCalTypes::c88 * delY, -HGCalTypes::c27 * delY, HGCalTypes::c61 * delY, HGCalTypes::c88 * delY,
1291  HGCalTypes::c27 * delY, -HGCalTypes::c61 * delY, HGCalTypes::c88 * delY, HGCalTypes::c61 * delY,
1292  -HGCalTypes::c27 * delY, -HGCalTypes::c88 * delY, -HGCalTypes::c61 * delY, HGCalTypes::c27 * delY};
1293  if (part == HGCalTypes::WaferFull) {
1294  int np[7] = {0, 1, 2, 3, 4, 5, 0};
1295  for (int k = 0; k < 7; ++k)
1296  xy.push_back(std::make_pair((xpos + dx[np[k]]), (ypos + dy[np[k]])));
1297  } else if (part == HGCalTypes::WaferLDTop) {
1298  int np[12][5] = {{0, 1, 4, 5, 0},
1299  {1, 2, 5, 0, 1},
1300  {2, 3, 0, 1, 2},
1301  {3, 4, 1, 2, 3},
1302  {4, 5, 2, 3, 4},
1303  {5, 0, 3, 4, 5},
1304  {0, 1, 2, 5, 0},
1305  {5, 0, 1, 4, 5},
1306  {4, 5, 0, 3, 4},
1307  {3, 4, 5, 2, 3},
1308  {2, 3, 4, 1, 2},
1309  {1, 2, 3, 0, 1}};
1310  for (int k = 0; k < 5; ++k) {
1311  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1312 #ifdef EDM_ML_DEBUG
1313  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1314 #endif
1315  }
1316  } else if (part == HGCalTypes::WaferLDBottom) {
1317  int np[12][5] = {{1, 2, 3, 4, 1},
1318  {2, 3, 4, 5, 2},
1319  {3, 4, 5, 0, 3},
1320  {4, 5, 0, 1, 4},
1321  {5, 0, 1, 2, 5},
1322  {0, 1, 2, 3, 0},
1323  {5, 2, 3, 4, 5},
1324  {4, 1, 2, 3, 4},
1325  {3, 0, 1, 2, 3},
1326  {2, 5, 0, 1, 2},
1327  {1, 4, 5, 0, 1},
1328  {0, 3, 4, 5, 0}};
1329  for (int k = 0; k < 5; ++k) {
1330  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1331 #ifdef EDM_ML_DEBUG
1332  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1333 #endif
1334  }
1335  } else if (part == HGCalTypes::WaferLDLeft) {
1336  int np[12][6] = {{0, 1, 2, 8, 11, 0},
1337  {1, 2, 3, 9, 6, 1},
1338  {2, 3, 4, 10, 7, 2},
1339  {3, 4, 5, 11, 8, 3},
1340  {4, 5, 0, 6, 9, 4},
1341  {5, 0, 1, 7, 10, 5},
1342  {0, 6, 9, 4, 5, 0},
1343  {5, 11, 8, 3, 4, 5},
1344  {4, 10, 7, 2, 3, 4},
1345  {3, 9, 6, 1, 2, 3},
1346  {2, 8, 11, 0, 1, 2},
1347  {1, 7, 10, 5, 0, 1}};
1348  for (int k = 0; k < 6; ++k) {
1349  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1350 #ifdef EDM_ML_DEBUG
1351  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1352 #endif
1353  }
1354  } else if (part == HGCalTypes::WaferLDRight) {
1355  int np[12][6] = {{5, 11, 8, 3, 4, 5},
1356  {0, 6, 9, 4, 5, 0},
1357  {1, 7, 10, 5, 0, 1},
1358  {2, 8, 11, 0, 1, 2},
1359  {3, 9, 6, 1, 2, 3},
1360  {4, 10, 7, 2, 3, 4},
1361  {1, 2, 3, 9, 6, 1},
1362  {0, 1, 2, 8, 11, 0},
1363  {5, 0, 1, 7, 10, 5},
1364  {4, 5, 0, 6, 9, 4},
1365  {3, 4, 5, 11, 8, 3},
1366  {2, 3, 4, 10, 7, 2}};
1367  for (int k = 0; k < 6; ++k) {
1368  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1369 #ifdef EDM_ML_DEBUG
1370  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1371 #endif
1372  }
1373  } else if (part == HGCalTypes::WaferLDFive) {
1374  int np[12][6] = {{0, 1, 2, 3, 5, 0},
1375  {1, 2, 3, 4, 0, 1},
1376  {2, 3, 4, 5, 1, 2},
1377  {3, 4, 5, 0, 2, 3},
1378  {4, 5, 0, 1, 3, 4},
1379  {5, 0, 1, 2, 4, 5},
1380  {0, 1, 3, 4, 5, 0},
1381  {5, 0, 2, 3, 4, 5},
1382  {4, 5, 1, 2, 3, 4},
1383  {3, 4, 0, 1, 2, 3},
1384  {2, 3, 5, 0, 1, 2},
1385  {1, 2, 4, 5, 0, 1}};
1386  for (int k = 0; k < 6; ++k) {
1387  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1388 #ifdef EDM_ML_DEBUG
1389  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1390 #endif
1391  }
1392  } else if (part == HGCalTypes::WaferLDThree) {
1393  int np[12][4] = {{5, 3, 4, 5},
1394  {0, 4, 5, 0},
1395  {1, 5, 0, 1},
1396  {2, 0, 1, 2},
1397  {3, 1, 2, 3},
1398  {4, 2, 3, 4},
1399  {1, 2, 3, 1},
1400  {0, 1, 2, 0},
1401  {5, 0, 1, 5},
1402  {4, 5, 0, 4},
1403  {3, 4, 5, 3},
1404  {2, 3, 4, 2}};
1405  for (int k = 0; k < 4; ++k) {
1406  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1407 #ifdef EDM_ML_DEBUG
1408  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1409 #endif
1410  }
1411  } else if (part == HGCalTypes::WaferHDTop) {
1412  int np[12][5] = {{0, 22, 16, 5, 0},
1413  {1, 23, 17, 0, 1},
1414  {2, 18, 12, 1, 2},
1415  {3, 19, 13, 2, 3},
1416  {4, 20, 14, 3, 4},
1417  {5, 21, 15, 4, 5},
1418  {0, 1, 23, 17, 0},
1419  {5, 0, 22, 16, 5},
1420  {4, 5, 21, 15, 4},
1421  {3, 4, 20, 14, 3},
1422  {2, 3, 19, 13, 2},
1423  {1, 2, 18, 12, 1}};
1424  for (int k = 0; k < 5; ++k) {
1425  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1426 #ifdef EDM_ML_DEBUG
1427  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1428 #endif
1429  }
1430  } else if (part == HGCalTypes::WaferHDBottom) {
1431  int np[12][7] = {{1, 2, 3, 4, 16, 22, 1},
1432  {2, 3, 4, 5, 17, 23, 2},
1433  {3, 4, 5, 0, 12, 18, 3},
1434  {4, 5, 0, 1, 13, 19, 4},
1435  {5, 0, 1, 2, 14, 20, 5},
1436  {0, 1, 2, 3, 15, 21, 0},
1437  {5, 17, 23, 2, 3, 4, 5},
1438  {4, 16, 22, 1, 2, 3, 4},
1439  {3, 15, 21, 0, 1, 2, 3},
1440  {2, 14, 20, 5, 0, 1, 2},
1441  {1, 13, 19, 4, 5, 0, 1},
1442  {0, 12, 18, 3, 4, 5, 0}};
1443  for (int k = 0; k < 7; ++k) {
1444  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1445 #ifdef EDM_ML_DEBUG
1446  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1447 #endif
1448  }
1449  } else if (part == HGCalTypes::WaferHDLeft) {
1450  int np[12][6] = {{0, 1, 2, 14, 21, 0},
1451  {1, 2, 3, 15, 22, 1},
1452  {2, 3, 4, 16, 23, 2},
1453  {3, 4, 5, 17, 18, 3},
1454  {4, 5, 0, 12, 19, 4},
1455  {5, 0, 1, 13, 20, 5},
1456  {0, 12, 19, 4, 5, 0},
1457  {5, 17, 18, 3, 4, 5},
1458  {4, 16, 23, 2, 3, 4},
1459  {3, 15, 22, 1, 2, 3},
1460  {2, 14, 21, 0, 1, 2},
1461  {1, 13, 20, 5, 0, 1}};
1462  for (int k = 0; k < 6; ++k) {
1463  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1464 #ifdef EDM_ML_DEBUG
1465  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1466 #endif
1467  }
1468  } else if (part == HGCalTypes::WaferHDRight) {
1469  int np[12][6] = {{5, 17, 18, 3, 4, 5},
1470  {0, 12, 19, 4, 5, 0},
1471  {1, 13, 20, 5, 0, 1},
1472  {2, 14, 21, 0, 1, 2},
1473  {3, 15, 22, 1, 2, 3},
1474  {4, 16, 23, 2, 3, 4},
1475  {1, 2, 3, 15, 22, 1},
1476  {0, 1, 2, 14, 21, 0},
1477  {5, 0, 1, 13, 20, 5},
1478  {4, 5, 0, 12, 19, 4},
1479  {3, 4, 5, 17, 18, 3},
1480  {2, 3, 4, 16, 23, 2}};
1481  for (int k = 0; k < 6; ++k) {
1482  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1483 #ifdef EDM_ML_DEBUG
1484  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1485 #endif
1486  }
1487  } else if (part == HGCalTypes::WaferHDFive) {
1488  int np[12][6] = {{0, 1, 2, 18, 17, 0},
1489  {1, 2, 3, 19, 12, 1},
1490  {2, 3, 4, 20, 13, 2},
1491  {3, 4, 5, 21, 14, 3},
1492  {4, 5, 0, 22, 15, 4},
1493  {5, 0, 1, 23, 16, 5},
1494  {0, 22, 15, 4, 5, 0},
1495  {5, 21, 14, 3, 4, 5},
1496  {4, 20, 13, 2, 3, 4},
1497  {3, 19, 12, 1, 2, 3},
1498  {2, 18, 17, 0, 1, 2},
1499  {1, 23, 16, 5, 0, 1}};
1500  for (int k = 0; k < 6; ++k) {
1501  xy.push_back(std::make_pair((xpos + dx[np[place][k]]), (ypos + dy[np[place][k]])));
1502 #ifdef EDM_ML_DEBUG
1503  edm::LogVerbatim("HGCalGeom") << k << ":" << np[place][k] << ":" << dx[np[place][k]] << ":" << dy[np[place][k]];
1504 #endif
1505  }
1506  }
1507 #ifdef EDM_ML_DEBUG
1508  edm::LogVerbatim("HGCalGeom") << "I/p: " << part << ":" << place << ":" << delX << ":" << delY << ":" << xpos << ":"
1509  << ypos << " O/p having " << xy.size() << " points:";
1510  std::ostringstream st1;
1511  for (unsigned int i = 0; i < xy.size(); ++i)
1512  st1 << " [" << i << "] " << xy[i].first << ":" << xy[i].second;
1513  edm::LogVerbatim("HGCalGeom") << st1.str();
1514 #endif
1515  return xy;
1516 }
static constexpr std::array< int, 3 > edgeWaferHDBottom
Definition: HGCalTypes.h:86
static constexpr std::array< int, 3 > edgeWaferLDFive
Definition: HGCalTypes.h:83
Log< level::Info, true > LogVerbatim
static constexpr int32_t WaferHalf2
Definition: HGCalTypes.h:43
static constexpr std::array< int, 3 > edgeWaferLDLeft
Definition: HGCalTypes.h:81
static constexpr int32_t WaferFive2
Definition: HGCalTypes.h:44
static constexpr std::array< int, 3 > edgeWaferLDTop
Definition: HGCalTypes.h:79
static constexpr std::array< int, 3 > edgeWaferHDLeft
Definition: HGCalTypes.h:87
static constexpr int k_OffsetRotation
Definition: HGCalTypes.h:91
static constexpr int32_t WaferSizeMax
Definition: HGCalTypes.h:76
static constexpr int32_t WaferLDThree
Definition: HGCalTypes.h:50
static constexpr int k_fourCorners
static constexpr std::array< int, 3 > edgeWaferLDThree
Definition: HGCalTypes.h:84
static std::vector< std::pair< double, double > > waferXY(int part, int orient, int zside, double delX, double delY, double xpos, double ypos)
static bool goodCell(int u, int v, int N, int type, int rotn)
static constexpr int32_t WaferOut
Definition: HGCalTypes.h:56
base
Main Program
Definition: newFWLiteAna.py:92
static constexpr int k_twoCorners
static constexpr int32_t WaferThree
Definition: HGCalTypes.h:42
static constexpr double c50
Definition: HGCalTypes.h:97
static constexpr int32_t WaferHDFive
Definition: HGCalTypes.h:55
static constexpr double c88
Definition: HGCalTypes.h:101
int zside(DetId const &)
static int getRotation(int zside, int type, int rotn)
static constexpr double c27
Definition: HGCalTypes.h:96
static constexpr double c10
Definition: HGCalTypes.h:102
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
static constexpr int32_t WaferSemi2
Definition: HGCalTypes.h:41
static constexpr int32_t WaferHDLeft
Definition: HGCalTypes.h:53
constexpr uint32_t mask
Definition: gpuClustering.h:24
static bool goodTypeMode(double xpos, double ypos, double delX, double delY, double rin, double rout, int part, int rotn, bool debug=false)
U second(std::pair< T, U > const &p)
static constexpr int32_t WaferFull
Definition: HGCalTypes.h:35
static constexpr int32_t WaferHalf
Definition: HGCalTypes.h:39
static constexpr int32_t WaferLDBottom
Definition: HGCalTypes.h:46
int np
Definition: AMPTWrapper.h:43
static constexpr int32_t WaferCorner1
Definition: HGCalTypes.h:14
T sqrt(T t)
Definition: SSEVec.h:19
static constexpr int32_t WaferCorner5
Definition: HGCalTypes.h:18
static constexpr int32_t WaferLDRight
Definition: HGCalTypes.h:48
static constexpr int32_t WaferCorner4
Definition: HGCalTypes.h:17
static constexpr int32_t WaferCornerMax
Definition: HGCalTypes.h:75
static constexpr int32_t WaferCorner2
Definition: HGCalTypes.h:15
static constexpr int32_t WaferLDFive
Definition: HGCalTypes.h:49
static constexpr int32_t WaferCorner0
Definition: HGCalTypes.h:13
static constexpr int32_t WaferLDLeft
Definition: HGCalTypes.h:47
static constexpr double c00
Definition: HGCalTypes.h:93
static constexpr int32_t WaferHDBottom
Definition: HGCalTypes.h:52
static constexpr int32_t WaferCorner3
Definition: HGCalTypes.h:16
static constexpr std::array< int, 3 > edgeWaferHDTop
Definition: HGCalTypes.h:85
static constexpr int32_t WaferHDRight
Definition: HGCalTypes.h:54
#define debug
Definition: HDRShower.cc:19
static constexpr int k_fiveCorners
static constexpr int32_t WaferChopTwoM
Definition: HGCalTypes.h:38
auto const good
min quality of good
static constexpr std::array< int, 3 > edgeWaferLDRight
Definition: HGCalTypes.h:82
part
Definition: HCALResponse.h:20
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 debug=false)
static constexpr double c77
Definition: HGCalTypes.h:100
static constexpr double c61
Definition: HGCalTypes.h:98
static constexpr int k_threeCorners
static constexpr int32_t WaferLDTop
Definition: HGCalTypes.h:45
static constexpr double c75
Definition: HGCalTypes.h:99
static constexpr double c22
Definition: HGCalTypes.h:94
static constexpr std::array< int, 3 > edgeWaferHDFive
Definition: HGCalTypes.h:89
static constexpr int32_t WaferHDTop
Definition: HGCalTypes.h:51
static constexpr int32_t WaferFive
Definition: HGCalTypes.h:36
static constexpr int32_t WaferSemi
Definition: HGCalTypes.h:40
static constexpr std::array< int, 3 > edgeWaferHDRight
Definition: HGCalTypes.h:88
static constexpr int k_allCorners
static constexpr std::array< int, 3 > edgeWaferLDBottom
Definition: HGCalTypes.h:80
static constexpr int32_t WaferChopTwo
Definition: HGCalTypes.h:37
static bool maskCell(int u, int v, int N, int ncor, int fcor, int corners)