File indexing completed on 2024-07-31 22:58:41
0001 #ifndef RecoParticleFlow_PFRecHitProducer_interface_alpaka_CalorimeterDefinitions_h
0002 #define RecoParticleFlow_PFRecHitProducer_interface_alpaka_CalorimeterDefinitions_h
0003
0004 #include <limits>
0005
0006 #include "DataFormats/DetId/interface/DetId.h"
0007 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0008 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0009 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0010 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
0011 #include "DataFormats/HcalRecHit/interface/HBHERecHit.h"
0012 #include "DataFormats/ParticleFlowReco/interface/CaloRecHitHostCollection.h"
0013 #include "DataFormats/ParticleFlowReco/interface/alpaka/CaloRecHitDeviceCollection.h"
0014 #include "RecoParticleFlow/PFRecHitProducer/interface/PFRecHitTopologyHostCollection.h"
0015 #include "RecoParticleFlow/PFRecHitProducer/interface/alpaka/PFRecHitParamsDeviceCollection.h"
0016 #include "RecoParticleFlow/PFRecHitProducer/interface/alpaka/PFRecHitTopologyDeviceCollection.h"
0017
0018 #include "DataFormats/HcalRecHit/interface/HcalRecHitHostCollection.h"
0019 #include "DataFormats/HcalRecHit/interface/alpaka/HcalRecHitDeviceCollection.h"
0020
0021
0022 class PFRecHitHCALParamsRecord;
0023 class PFRecHitHCALTopologyRecord;
0024 class EcalPFRecHitThresholdsRcd;
0025 class PFRecHitECALTopologyRecord;
0026
0027
0028
0029
0030
0031
0032
0033 namespace ALPAKA_ACCELERATOR_NAMESPACE::particleFlowRecHitProducer {
0034
0035
0036 constexpr inline uint32_t getSubdet(uint32_t detId) { return DetId(detId).subdetId(); }
0037
0038 struct HCAL {
0039 using CaloRecHitType = HBHERecHit;
0040 using CaloRecHitSoATypeHost = hcal::RecHitHostCollection;
0041 using CaloRecHitSoATypeDevice = hcal::RecHitDeviceCollection;
0042 using ParameterType = reco::PFRecHitHCALParamsDeviceCollection;
0043 using ParameterRecordType = PFRecHitHCALParamsRecord;
0044 using TopologyTypeHost = reco::PFRecHitHCALTopologyHostCollection;
0045 using TopologyTypeDevice = reco::PFRecHitHCALTopologyDeviceCollection;
0046 using TopologyRecordType = PFRecHitHCALTopologyRecord;
0047
0048 static constexpr DetId::Detector kDetectorId = DetId::Detector::Hcal;
0049 static constexpr int kSubdetectorBarrelId = HcalSubdetector::HcalBarrel;
0050 static constexpr int kSubdetectorEndcapId = HcalSubdetector::HcalEndcap;
0051
0052 static constexpr uint32_t kMaxDepthHB = 4;
0053 static constexpr uint32_t kMaxDepthHE = 7;
0054 static constexpr uint32_t kFirstHBRing = 1;
0055 static constexpr uint32_t kLastHBRing = 16;
0056 static constexpr uint32_t kFirstHERing = 16;
0057 static constexpr uint32_t kLastHERing = 29;
0058 static constexpr uint32_t kMaxIPhi = 72;
0059 static constexpr uint32_t kSizeBarrel = kMaxDepthHB * (kLastHBRing - kFirstHBRing + 1) * kMaxIPhi * 2;
0060 static constexpr uint32_t kSizeEndcap = kMaxDepthHE * (kLastHERing - kFirstHERing + 1) * kMaxIPhi * 2;
0061 static constexpr uint32_t kSize = kSizeBarrel + kSizeEndcap;
0062
0063 static constexpr bool detIdInRange(uint32_t detId) {
0064 return detId != 0 && DetId(detId).det() == DetId::Detector::Hcal &&
0065 (getSubdet(detId) == HcalSubdetector::HcalBarrel || getSubdet(detId) == HcalSubdetector::HcalEndcap);
0066 }
0067
0068 static constexpr uint32_t getDepth(uint32_t detId) { return HcalDetId(detId).depth(); }
0069 static constexpr uint32_t getIetaAbs(uint32_t detId) { return HcalDetId(detId).ietaAbs(); }
0070 static constexpr uint32_t getIphi(uint32_t detId) { return HcalDetId(detId).iphi(); }
0071 static constexpr int getZside(uint32_t detId) { return HcalDetId(detId).zside(); }
0072
0073
0074 static constexpr uint32_t detId2denseIdHB(uint32_t detId) {
0075 const uint32_t nEtaHB = (kLastHBRing - kFirstHBRing + 1);
0076 const uint32_t ip = getIphi(detId);
0077 const uint32_t ie = getIetaAbs(detId);
0078 const uint32_t dp = getDepth(detId);
0079 const int zn = getZside(detId);
0080 uint32_t retval = (dp - 1) + kMaxDepthHB * (ip - 1);
0081 if (zn > 0)
0082 retval += kMaxDepthHB * kMaxIPhi * (ie * zn - kFirstHBRing);
0083 else
0084 retval += kMaxDepthHB * kMaxIPhi * (ie * zn + kLastHBRing + nEtaHB);
0085
0086 return retval;
0087 }
0088
0089
0090 static constexpr uint32_t detId2denseIdHE(uint32_t detId) {
0091 const uint32_t nEtaHE = (kLastHERing - kFirstHERing + 1);
0092 const uint32_t ip = getIphi(detId);
0093 const uint32_t ie = getIetaAbs(detId);
0094 const uint32_t dp = getDepth(detId);
0095 const int zn = getZside(detId);
0096 uint32_t retval = (dp - 1) + kMaxDepthHE * (ip - 1);
0097 if (zn > 0)
0098 retval += kMaxDepthHE * kMaxIPhi * (ie * zn - kFirstHERing);
0099 else
0100 retval += kMaxDepthHE * kMaxIPhi * (ie * zn + kLastHERing + nEtaHE);
0101
0102 return retval + kSizeBarrel;
0103 }
0104
0105 static constexpr uint32_t kInvalidDenseId = std::numeric_limits<uint32_t>::max();
0106
0107 static constexpr uint32_t detId2denseId(uint32_t detId) {
0108 const uint32_t subdet = getSubdet(detId);
0109 if (subdet == HcalBarrel)
0110 return detId2denseIdHB(detId);
0111 if (subdet == HcalEndcap)
0112 return detId2denseIdHE(detId);
0113
0114 printf("invalid Hcal detId: %u\n", detId);
0115 return kInvalidDenseId;
0116 }
0117 };
0118
0119 struct ECAL {
0120 using CaloRecHitType = EcalRecHit;
0121 using CaloRecHitSoATypeHost = reco::CaloRecHitHostCollection;
0122 using CaloRecHitSoATypeDevice = reco::CaloRecHitDeviceCollection;
0123 using ParameterType = reco::PFRecHitECALParamsDeviceCollection;
0124 using ParameterRecordType = EcalPFRecHitThresholdsRcd;
0125 using TopologyTypeHost = reco::PFRecHitECALTopologyHostCollection;
0126 using TopologyTypeDevice = reco::PFRecHitECALTopologyDeviceCollection;
0127 using TopologyRecordType = PFRecHitECALTopologyRecord;
0128
0129 static constexpr DetId::Detector kDetectorId = DetId::Detector::Ecal;
0130 static constexpr int kSubdetectorBarrelId = EcalSubdetector::EcalBarrel;
0131 static constexpr int kSubdetectorEndcapId = EcalSubdetector::EcalEndcap;
0132
0133 using Flags = EcalRecHit::Flags;
0134
0135
0136 struct Barrel {
0137 static constexpr int kMaxIEta = 85;
0138 static constexpr int kMaxIPhi = 360;
0139 static constexpr int kSize = 2 * kMaxIPhi * kMaxIEta;
0140
0141 static constexpr int ietaAbs(uint32_t detId) { return (detId >> 9) & 0x7F; }
0142 static constexpr int iphi(uint32_t detId) { return detId & 0x1FF; }
0143 static constexpr bool positiveZ(uint32_t detId) { return detId & 0x10000; }
0144 static constexpr uint32_t denseIndex(uint32_t detId) {
0145 return (kMaxIEta + (positiveZ(detId) ? ietaAbs(detId) - 1 : -ietaAbs(detId))) * kMaxIPhi + iphi(detId) - 1;
0146 }
0147 };
0148
0149
0150 struct Endcap {
0151 static constexpr uint32_t kEEhalf = 7324;
0152 static constexpr uint32_t kSize = kEEhalf * 2;
0153
0154 static constexpr int ix(uint32_t detId) { return (detId >> 7) & 0x7F; }
0155 static constexpr int iy(uint32_t detId) { return detId & 0x7F; }
0156 static constexpr bool positiveZ(uint32_t detId) { return detId & 0x4000; }
0157
0158 static constexpr uint32_t denseIndex(uint32_t detId) {
0159 const unsigned short kxf[] = {
0160 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,
0161 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,
0162 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,
0163 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,
0164 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,
0165 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,
0166 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,
0167 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};
0168
0169 const unsigned short kdi[] = {
0170 0, 10, 20, 30, 40, 50, 60, 75, 90, 105, 120, 145, 170, 195, 220, 245, 270,
0171 300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 605, 640, 675, 710, 747, 784, 821,
0172 858, 895, 932, 969, 1006, 1043, 1080, 1122, 1164, 1206, 1248, 1290, 1332, 1374, 1416, 1458, 1500,
0173 1545, 1590, 1635, 1680, 1725, 1770, 1815, 1860, 1905, 1950, 1995, 2040, 2085, 2130, 2175, 2220, 2265,
0174 2310, 2355, 2400, 2447, 2494, 2541, 2588, 2635, 2682, 2729, 2776, 2818, 2860, 2903, 2946, 2988, 3030,
0175 3071, 3112, 3152, 3192, 3232, 3272, 3311, 3350, 3389, 3428, 3467, 3506, 3545, 3584, 3623, 3662, 3701,
0176 3740, 3779, 3818, 3857, 3896, 3935, 3974, 4013, 4052, 4092, 4132, 4172, 4212, 4253, 4294, 4336, 4378,
0177 4421, 4464, 4506, 4548, 4595, 4642, 4689, 4736, 4783, 4830, 4877, 4924, 4969, 5014, 5059, 5104, 5149,
0178 5194, 5239, 5284, 5329, 5374, 5419, 5464, 5509, 5554, 5599, 5644, 5689, 5734, 5779, 5824, 5866, 5908,
0179 5950, 5992, 6034, 6076, 6118, 6160, 6202, 6244, 6281, 6318, 6355, 6392, 6429, 6466, 6503, 6540, 6577,
0180 6614, 6649, 6684, 6719, 6754, 6784, 6814, 6844, 6874, 6904, 6934, 6964, 6994, 7024, 7054, 7079, 7104,
0181 7129, 7154, 7179, 7204, 7219, 7234, 7249, 7264, 7274, 7284, 7294, 7304, 7314};
0182
0183 const uint32_t jx = ix(detId);
0184 const uint32_t jd = 2 * (iy(detId) - 1) + (jx - 1) / 50;
0185 return ((positiveZ(detId) ? kEEhalf : 0) + kdi[jd] + jx - kxf[jd]);
0186 }
0187 };
0188
0189 static constexpr bool checkFlag(uint32_t flagBits, int flag) { return flagBits & (0x1 << flag); }
0190
0191 static constexpr uint32_t kInvalidDenseId = std::numeric_limits<uint32_t>::max();
0192
0193 static constexpr uint32_t detId2denseId(uint32_t detId) {
0194 const uint32_t subdet = getSubdet(detId);
0195 if (subdet == EcalBarrel)
0196 return Barrel::denseIndex(detId);
0197 if (subdet == EcalEndcap)
0198 return Barrel::kSize + Endcap::denseIndex(detId);
0199
0200 printf("invalid Ecal detId: %u\n", detId);
0201 return kInvalidDenseId;
0202 }
0203
0204 static constexpr bool detIdInRange(uint32_t detId) {
0205 return detId != 0 && DetId(detId).det() == DetId::Detector::Ecal &&
0206 (getSubdet(detId) == EcalSubdetector::EcalBarrel || getSubdet(detId) == EcalSubdetector::EcalEndcap);
0207 }
0208
0209 static constexpr int getZside(uint32_t detId) {
0210 return ((getSubdet(detId) == EcalSubdetector::EcalBarrel) ? Barrel::positiveZ(detId) : Endcap::positiveZ(detId))
0211 ? (1)
0212 : (-1);
0213 }
0214
0215 static constexpr uint32_t kSize = Barrel::kSize + Endcap::kSize;
0216 };
0217
0218 }
0219
0220 #endif