File indexing completed on 2024-04-06 12:25:41
0001 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0002 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0003
0004 #include "KernelHelpers.h"
0005
0006 namespace ALPAKA_ACCELERATOR_NAMESPACE::ecal::reconstruction {
0007
0008 namespace internal::barrel {
0009
0010 ALPAKA_FN_ACC ALPAKA_FN_INLINE bool positiveZ(uint32_t id) { return id & 0x10000; }
0011
0012 ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ietaAbs(uint32_t id) { return (id >> 9) & 0x7F; }
0013
0014 ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iphi(uint32_t id) { return id & 0x1FF; }
0015
0016 ALPAKA_FN_ACC int dccFromSm(int ism) {
0017 int idcc = 9 + ism;
0018 if (ism > 18)
0019 idcc -= 18;
0020 else
0021 idcc += 18;
0022 return idcc;
0023 }
0024
0025 ALPAKA_FN_ACC int sm(int ieta, int iphi) {
0026 if (iphi > 360)
0027 iphi -= 360;
0028 int ism = (iphi - 1) / 20 + 1;
0029 if (ieta < 0)
0030 ism += 18;
0031 return ism;
0032 }
0033
0034 ALPAKA_FN_ACC int dcc(int ieta, int iphi) {
0035 int const ism = sm(ieta, iphi);
0036 return dccFromSm(ism);
0037 }
0038
0039 ALPAKA_FN_ACC int lm_channel(int iX, int iY) {
0040 static const int idx_[] = {
0041
0042
0043 1, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8,
0044 1, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8,
0045 1, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9,
0046 1, 3, 3, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 9, 9, 9, 9
0047
0048
0049 };
0050
0051 constexpr int iym = 4;
0052 constexpr int ixm = 17;
0053 int const il = iym - iY + 1;
0054 int const ic = iX;
0055 int const ii = il * ixm + ic;
0056 if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int))) {
0057 return -1;
0058 };
0059 return idx_[ii];
0060 }
0061
0062 ALPAKA_FN_ACC int localCoord_x(int ieta) {
0063 int iz = 1;
0064 if (ieta < 0) {
0065 iz = -1;
0066 }
0067 ieta *= iz;
0068 int ix = ieta - 1;
0069
0070 return ix;
0071 }
0072
0073 ALPAKA_FN_ACC int localCoord_y(int ieta, int iphi) {
0074 if (iphi > 360) {
0075 iphi -= 360;
0076 }
0077 int iy = (iphi - 1) % 20;
0078 if (ieta < 0) {
0079 iy = 19 - iy;
0080 }
0081
0082 return iy;
0083 }
0084
0085 ALPAKA_FN_ACC int lmmod(int ieta, int iphi) {
0086 int const ix = localCoord_x(ieta);
0087 int const iy = localCoord_y(ieta, iphi);
0088
0089 return lm_channel(ix / 5, iy / 5);
0090 }
0091
0092 ALPAKA_FN_ACC int side(int ieta, int iphi) {
0093 int const ilmmod = lmmod(ieta, iphi);
0094 return (ilmmod % 2 == 0) ? 1 : 0;
0095 }
0096
0097 }
0098
0099 ALPAKA_FN_ACC uint32_t hashedIndexEB(uint32_t id) {
0100 using namespace internal::barrel;
0101 return (EBDetId::MAX_IETA + (positiveZ(id) ? ietaAbs(id) - 1 : -ietaAbs(id))) * EBDetId::MAX_IPHI + iphi(id) - 1;
0102 }
0103
0104
0105
0106
0107
0108 ALPAKA_FN_ACC int32_t laserMonitoringRegionEB(uint32_t id) {
0109 using namespace internal::barrel;
0110
0111 int ieta;
0112 if (positiveZ(id)) {
0113 ieta = ietaAbs(id);
0114 } else {
0115 ieta = -ietaAbs(id);
0116 }
0117
0118 int const idcc = dcc(ieta, (int)(iphi(id)));
0119 int const ism = idcc - 9;
0120
0121 int const iside = side(ieta, (int)(iphi(id)));
0122
0123 return (1 + 2 * (ism - 1) + iside);
0124 }
0125
0126 namespace internal::endcap {
0127
0128 ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id) { return (id >> 7) & 0x7F; }
0129
0130 ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id) { return id & 0x7F; }
0131
0132 ALPAKA_FN_ACC ALPAKA_FN_INLINE bool positiveZ(uint32_t id) { return id & 0x4000; }
0133
0134
0135 ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kxf[] = {
0136 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,
0137 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,
0138 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,
0139 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,
0140 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,
0141 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,
0142 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,
0143 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};
0144
0145 ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kdi[] = {
0146 0, 10, 20, 30, 40, 50, 60, 75, 90, 105, 120, 145, 170, 195, 220, 245, 270,
0147 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 605, 640, 675, 710, 747, 784, 821,
0148 858, 895, 932, 969, 1006, 1043, 1080, 1122, 1164, 1206, 1248, 1290, 1332, 1374, 1416, 1458, 1500,
0149 1545, 1590, 1635, 1680, 1725, 1770, 1815, 1860, 1905, 1950, 1995, 2040, 2085, 2130, 2175, 2220, 2265,
0150 2310, 2355, 2400, 2447, 2494, 2541, 2588, 2635, 2682, 2729, 2776, 2818, 2860, 2903, 2946, 2988, 3030,
0151 3071, 3112, 3152, 3192, 3232, 3272, 3311, 3350, 3389, 3428, 3467, 3506, 3545, 3584, 3623, 3662, 3701,
0152 3740, 3779, 3818, 3857, 3896, 3935, 3974, 4013, 4052, 4092, 4132, 4172, 4212, 4253, 4294, 4336, 4378,
0153 4421, 4464, 4506, 4548, 4595, 4642, 4689, 4736, 4783, 4830, 4877, 4924, 4969, 5014, 5059, 5104, 5149,
0154 5194, 5239, 5284, 5329, 5374, 5419, 5464, 5509, 5554, 5599, 5644, 5689, 5734, 5779, 5824, 5866, 5908,
0155 5950, 5992, 6034, 6076, 6118, 6160, 6202, 6244, 6281, 6318, 6355, 6392, 6429, 6466, 6503, 6540, 6577,
0156 6614, 6649, 6684, 6719, 6754, 6784, 6814, 6844, 6874, 6904, 6934, 6964, 6994, 7024, 7054, 7079, 7104,
0157 7129, 7154, 7179, 7204, 7219, 7234, 7249, 7264, 7274, 7284, 7294, 7304, 7314};
0158
0159 ALPAKA_FN_ACC int quadrant(int iX, int iY) {
0160 bool const near = iX >= 11;
0161 bool const far = !near;
0162 bool const top = iY >= 11;
0163 bool const bot = !top;
0164
0165 int iquad = 0;
0166 if (near && top)
0167 iquad = 1;
0168 else if (far && top)
0169 iquad = 2;
0170 else if (far && bot)
0171 iquad = 3;
0172 else
0173 iquad = 4;
0174
0175 return iquad;
0176 }
0177
0178 ALPAKA_FN_ACC int sector(int iX, int iY) {
0179
0180
0181
0182
0183
0184
0185
0186 static const int idx_[] = {
0187
0188
0189 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 9, 9, 9, 0, 0, 0, 0, 0, 0, 0,
0190 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0,
0191 0, 0, 0, 2, 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, 5, 5, 5, 6, 6, 6, 0, 0, 0, 0,
0208 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0
0209
0210
0211 };
0212
0213 constexpr int iym = 20;
0214 constexpr int ixm = 20;
0215 int const il = iym - iY;
0216 int const ic = iX - 1;
0217 int const ii = il * ixm + ic;
0218
0219 if (ii < 0 || ii > (int)(sizeof(idx_) / sizeof(int)) || idx_[ii] == 0) {
0220 return -1;
0221 };
0222 return idx_[ii];
0223 }
0224
0225 }
0226
0227 ALPAKA_FN_ACC uint32_t hashedIndexEE(uint32_t id) {
0228 using namespace internal::endcap;
0229
0230 const uint32_t jx(ix(id));
0231 const uint32_t jd(2 * (iy(id) - 1) + (jx - 1) / 50);
0232 return ((positiveZ(id) ? EEDetId::kEEhalf : 0) + kdi[jd] + jx - kxf[jd]);
0233 }
0234
0235
0236
0237
0238
0239
0240 ALPAKA_FN_ACC int32_t laserMonitoringRegionEE(uint32_t id) {
0241 using namespace internal::endcap;
0242
0243
0244 uint32_t const iX = (ix(id) - 1) / 5 + 1;
0245 uint32_t const iY = (iy(id) - 1) / 5 + 1;
0246
0247
0248
0249
0250
0251
0252 int const iz = positiveZ(id) ? 1 : -1;
0253
0254 int const iquad = quadrant(iX, iY);
0255 int const isect = sector(iX, iY);
0256 if (isect < 0)
0257 return -1;
0258
0259 int ilmr = 0;
0260 ilmr = isect - 6;
0261 if (ilmr <= 0)
0262 ilmr += 9;
0263 if (ilmr == 9)
0264 ilmr++;
0265 else if (ilmr == 8 && iquad == 4)
0266 ilmr++;
0267 if (iz == +1)
0268 ilmr += 72;
0269 else
0270 ilmr += 82;
0271
0272 return ilmr;
0273 }
0274
0275 }