CMS 3D CMS Logo

KernelHelpers.dev.cc
Go to the documentation of this file.
3 
4 #include "KernelHelpers.h"
5 
7 
8  namespace internal::barrel {
9 
10  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool positiveZ(uint32_t id) { return id & 0x10000; }
11 
12  ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ietaAbs(uint32_t id) { return (id >> 9) & 0x7F; }
13 
14  ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iphi(uint32_t id) { return id & 0x1FF; }
15 
16  ALPAKA_FN_ACC int dccFromSm(int ism) {
17  int idcc = 9 + ism;
18  if (ism > 18)
19  idcc -= 18;
20  else
21  idcc += 18;
22  return idcc;
23  }
24 
25  ALPAKA_FN_ACC int sm(int ieta, int iphi) {
26  if (iphi > 360)
27  iphi -= 360;
28  int ism = (iphi - 1) / 20 + 1;
29  if (ieta < 0)
30  ism += 18;
31  return ism;
32  }
33 
34  ALPAKA_FN_ACC int dcc(int ieta, int iphi) {
35  int const ism = sm(ieta, iphi);
36  return dccFromSm(ism);
37  }
38 
39  ALPAKA_FN_ACC int lm_channel(int iX, int iY) {
40  static const int idx_[] = {
41  // clang-format off
42  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
43  1, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, // 3
44  1, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, // 2
45  1, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9, // 1
46  1, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9 // 0
47  // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
48  // clang-format on
49  };
50 
51  constexpr int iym = 4;
52  constexpr int ixm = 17;
53  int const il = iym - iY + 1;
54  int const ic = iX;
55  int const ii = il * ixm + ic;
56  if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int))) {
57  return -1;
58  };
59  return idx_[ii];
60  }
61 
62  ALPAKA_FN_ACC int localCoord_x(int ieta) {
63  int iz = 1;
64  if (ieta < 0) {
65  iz = -1;
66  }
67  ieta *= iz;
68  int ix = ieta - 1;
69 
70  return ix;
71  }
72 
73  ALPAKA_FN_ACC int localCoord_y(int ieta, int iphi) {
74  if (iphi > 360) {
75  iphi -= 360;
76  }
77  int iy = (iphi - 1) % 20;
78  if (ieta < 0) {
79  iy = 19 - iy;
80  }
81 
82  return iy;
83  }
84 
85  ALPAKA_FN_ACC int lmmod(int ieta, int iphi) {
86  int const ix = localCoord_x(ieta);
87  int const iy = localCoord_y(ieta, iphi);
88 
89  return lm_channel(ix / 5, iy / 5);
90  }
91 
92  ALPAKA_FN_ACC int side(int ieta, int iphi) {
93  int const ilmmod = lmmod(ieta, iphi);
94  return (ilmmod % 2 == 0) ? 1 : 0;
95  }
96 
97  } // namespace internal::barrel
98 
99  ALPAKA_FN_ACC uint32_t hashedIndexEB(uint32_t id) {
100  using namespace internal::barrel;
101  return (EBDetId::MAX_IETA + (positiveZ(id) ? ietaAbs(id) - 1 : -ietaAbs(id))) * EBDetId::MAX_IPHI + iphi(id) - 1;
102  }
103 
104  //
105  // https://cmssdt.cern.ch/lxr/source/CalibCalorimetry/EcalLaserAnalyzer/src/MEEBGeom.cc
106  // function: "lmr"
107 
108  ALPAKA_FN_ACC int32_t laserMonitoringRegionEB(uint32_t id) {
109  using namespace internal::barrel;
110 
111  int ieta;
112  if (positiveZ(id)) {
113  ieta = ietaAbs(id);
114  } else {
115  ieta = -ietaAbs(id);
116  }
117 
118  int const idcc = dcc(ieta, (int)(iphi(id)));
119  int const ism = idcc - 9;
120 
121  int const iside = side(ieta, (int)(iphi(id)));
122 
123  return (1 + 2 * (ism - 1) + iside);
124  }
125 
126  namespace internal::endcap {
127 
128  ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id) { return (id >> 7) & 0x7F; }
129 
130  ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id) { return id & 0x7F; }
131 
132  ALPAKA_FN_ACC ALPAKA_FN_INLINE bool positiveZ(uint32_t id) { return id & 0x4000; }
133 
134  // these constants come from EE Det Id
135  ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kxf[] = {
136  41, 51, 41, 51, 41, 51, 36, 51, 36, 51, 26, 51, 26, 51, 26, 51, 21, 51, 21, 51, 21, 51, 21, 51, 21,
137  51, 16, 51, 16, 51, 14, 51, 14, 51, 14, 51, 14, 51, 14, 51, 9, 51, 9, 51, 9, 51, 9, 51, 9, 51,
138  6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 4, 51, 4, 51, 4,
139  51, 4, 51, 4, 56, 1, 58, 1, 59, 1, 60, 1, 61, 1, 61, 1, 62, 1, 62, 1, 62, 1, 62, 1, 62,
140  1, 62, 1, 62, 1, 62, 1, 62, 1, 62, 1, 61, 1, 61, 1, 60, 1, 59, 1, 58, 4, 56, 4, 51, 4,
141  51, 4, 51, 4, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51, 6, 51,
142  9, 51, 9, 51, 9, 51, 9, 51, 9, 51, 14, 51, 14, 51, 14, 51, 14, 51, 14, 51, 16, 51, 16, 51, 21,
143  51, 21, 51, 21, 51, 21, 51, 21, 51, 26, 51, 26, 51, 26, 51, 36, 51, 36, 51, 41, 51, 41, 51, 41, 51};
144 
145  ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kdi[] = {
146  0, 10, 20, 30, 40, 50, 60, 75, 90, 105, 120, 145, 170, 195, 220, 245, 270,
147  300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 605, 640, 675, 710, 747, 784, 821,
148  858, 895, 932, 969, 1006, 1043, 1080, 1122, 1164, 1206, 1248, 1290, 1332, 1374, 1416, 1458, 1500,
149  1545, 1590, 1635, 1680, 1725, 1770, 1815, 1860, 1905, 1950, 1995, 2040, 2085, 2130, 2175, 2220, 2265,
150  2310, 2355, 2400, 2447, 2494, 2541, 2588, 2635, 2682, 2729, 2776, 2818, 2860, 2903, 2946, 2988, 3030,
151  3071, 3112, 3152, 3192, 3232, 3272, 3311, 3350, 3389, 3428, 3467, 3506, 3545, 3584, 3623, 3662, 3701,
152  3740, 3779, 3818, 3857, 3896, 3935, 3974, 4013, 4052, 4092, 4132, 4172, 4212, 4253, 4294, 4336, 4378,
153  4421, 4464, 4506, 4548, 4595, 4642, 4689, 4736, 4783, 4830, 4877, 4924, 4969, 5014, 5059, 5104, 5149,
154  5194, 5239, 5284, 5329, 5374, 5419, 5464, 5509, 5554, 5599, 5644, 5689, 5734, 5779, 5824, 5866, 5908,
155  5950, 5992, 6034, 6076, 6118, 6160, 6202, 6244, 6281, 6318, 6355, 6392, 6429, 6466, 6503, 6540, 6577,
156  6614, 6649, 6684, 6719, 6754, 6784, 6814, 6844, 6874, 6904, 6934, 6964, 6994, 7024, 7054, 7079, 7104,
157  7129, 7154, 7179, 7204, 7219, 7234, 7249, 7264, 7274, 7284, 7294, 7304, 7314};
158 
159  ALPAKA_FN_ACC int quadrant(int iX, int iY) {
160  bool const near = iX >= 11;
161  bool const far = !near;
162  bool const top = iY >= 11;
163  bool const bot = !top;
164 
165  int iquad = 0;
166  if (near && top)
167  iquad = 1;
168  else if (far && top)
169  iquad = 2;
170  else if (far && bot)
171  iquad = 3;
172  else
173  iquad = 4;
174 
175  return iquad;
176  }
177 
178  ALPAKA_FN_ACC int sector(int iX, int iY) {
179  // Y (towards the surface)
180  // T
181  // |
182  // |
183  // |
184  // o---------| X (towards center of LHC)
185  //
186  static const int idx_[] = {
187  // clang-format off
188  // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
189  0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0, // 20
190  0, 0, 0, 0, 1, 1, 1, 1, 1, 1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4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 0, 0, 0, // 3
207  0, 0, 0, 0, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 0, 0, 0, 0, // 2
208  0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0 // 1
209  // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
210  // clang-format on
211  };
212 
213  constexpr int iym = 20;
214  constexpr int ixm = 20;
215  int const il = iym - iY;
216  int const ic = iX - 1;
217  int const ii = il * ixm + ic;
218 
219  if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int)) || idx_[ii] == 0) {
220  return -1;
221  };
222  return idx_[ii];
223  }
224 
225  } // namespace internal::endcap
226 
227  ALPAKA_FN_ACC uint32_t hashedIndexEE(uint32_t id) {
228  using namespace internal::endcap;
229 
230  const uint32_t jx(ix(id));
231  const uint32_t jd(2 * (iy(id) - 1) + (jx - 1) / 50);
232  return ((positiveZ(id) ? EEDetId::kEEhalf : 0) + kdi[jd] + jx - kxf[jd]);
233  }
234 
235  //
236  // https://cmssdt.cern.ch/lxr/source/CalibCalorimetry/EcalLaserAnalyzer/src/MEEEGeom.cc
237  // https://github.com/cms-sw/cmssw/blob/master/CalibCalorimetry/EcalLaserCorrection/src/EcalLaserDbService.cc
238  //
239 
240  ALPAKA_FN_ACC int32_t laserMonitoringRegionEE(uint32_t id) {
241  using namespace internal::endcap;
242 
243  // SuperCrysCoord
244  uint32_t const iX = (ix(id) - 1) / 5 + 1;
245  uint32_t const iY = (iy(id) - 1) / 5 + 1;
246 
247  // Correct convention
248  // * @param iz iz/zside index: -1 for EE-, +1 for EE+
249  // https://github.com/cms-sw/cmssw/blob/master/DataFormats/EcalDetId/interface/EEDetId.h#L68-L71
250  // zside in https://github.com/cms-sw/cmssw/blob/master/CalibCalorimetry/EcalLaserCorrection/src/EcalLaserDbService.cc#L63
251  //
252  int const iz = positiveZ(id) ? 1 : -1;
253 
254  int const iquad = quadrant(iX, iY);
255  int const isect = sector(iX, iY);
256  if (isect < 0)
257  return -1;
258 
259  int ilmr = 0;
260  ilmr = isect - 6;
261  if (ilmr <= 0)
262  ilmr += 9;
263  if (ilmr == 9)
264  ilmr++;
265  else if (ilmr == 8 && iquad == 4)
266  ilmr++;
267  if (iz == +1)
268  ilmr += 72;
269  else
270  ilmr += 82;
271 
272  return ilmr;
273  }
274 
275 } // namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction
ALPAKA_FN_ACC int32_t laserMonitoringRegionEE(uint32_t id)
ALPAKA_FN_ACC ALPAKA_FN_INLINE bool positiveZ(uint32_t id)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iphi(uint32_t id)
ALPAKA_FN_ACC uint32_t hashedIndexEB(uint32_t id)
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ietaAbs(uint32_t id)
ALPAKA_FN_ACC int32_t laserMonitoringRegionEB(uint32_t id)
ALPAKA_FN_ACC uint32_t hashedIndexEE(uint32_t id)
ALPAKA_FN_ACC ALPAKA_FN_INLINE bool positiveZ(uint32_t id)
ii
Definition: cuy.py:589
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
static const int MAX_IPHI
Definition: EBDetId.h:137
static const int MAX_IETA
Definition: EBDetId.h:136
ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kdi[]
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:49
ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kxf[]