CMS 3D CMS Logo

CalorimeterDefinitions.h
Go to the documentation of this file.
1 #ifndef RecoParticleFlow_PFRecHitProducer_interface_alpaka_CalorimeterDefinitions_h
2 #define RecoParticleFlow_PFRecHitProducer_interface_alpaka_CalorimeterDefinitions_h
3 
4 #include <limits>
5 
17 
20 
21 // Forward declaration of EventSetup records, to avoid propagating the dependency on framework headers to device code
26 
27 // This file defines two structs:
28 // 1) ALPAKA_ACCELERATOR_NAMESPACE::particleFlowRecHitProducer::HCAL
29 // 2) ALPAKA_ACCELERATOR_NAMESPACE::particleFlowRecHitProducer::ECAL
30 // These are used as template arguments of the PFRecHitSoAProducer class and
31 // related classes. This allows to specialise behaviour for the two calorimeter
32 // types.
34 
35  // Get subdetector encoded in detId to narrow the range of reference table values to search
36  constexpr inline uint32_t getSubdet(uint32_t detId) { return DetId(detId).subdetId(); }
37 
38  struct HCAL {
47 
48  static constexpr DetId::Detector kDetectorId = DetId::Detector::Hcal;
51 
52  static constexpr uint32_t kMaxDepthHB = 4;
53  static constexpr uint32_t kMaxDepthHE = 7;
54  static constexpr uint32_t kFirstHBRing = 1;
55  static constexpr uint32_t kLastHBRing = 16;
56  static constexpr uint32_t kFirstHERing = 16;
57  static constexpr uint32_t kLastHERing = 29;
58  static constexpr uint32_t kMaxIPhi = 72;
61  static constexpr uint32_t kSize = kSizeBarrel + kSizeEndcap; // maximum possible HCAL denseId (=23328)
62 
63  static constexpr bool detIdInRange(uint32_t detId) {
64  return detId != 0 && DetId(detId).det() == DetId::Detector::Hcal &&
66  }
67 
68  static constexpr uint32_t getDepth(uint32_t detId) { return HcalDetId(detId).depth(); }
69  static constexpr uint32_t getIetaAbs(uint32_t detId) { return HcalDetId(detId).ietaAbs(); }
70  static constexpr uint32_t getIphi(uint32_t detId) { return HcalDetId(detId).iphi(); }
71  static constexpr int getZside(uint32_t detId) { return HcalDetId(detId).zside(); }
72 
73  // https://cmssdt.cern.ch/lxr/source/Geometry/CaloTopology/src/HcalTopology.cc#1170
74  static constexpr uint32_t detId2denseIdHB(uint32_t detId) {
75  const uint32_t nEtaHB = (kLastHBRing - kFirstHBRing + 1);
76  const uint32_t ip = getIphi(detId);
77  const uint32_t ie = getIetaAbs(detId);
78  const uint32_t dp = getDepth(detId);
79  const int zn = getZside(detId);
80  uint32_t retval = (dp - 1) + kMaxDepthHB * (ip - 1);
81  if (zn > 0)
82  retval += kMaxDepthHB * kMaxIPhi * (ie * zn - kFirstHBRing);
83  else
84  retval += kMaxDepthHB * kMaxIPhi * (ie * zn + kLastHBRing + nEtaHB);
85 
86  return retval;
87  }
88 
89  // https://cmssdt.cern.ch/lxr/source/Geometry/CaloTopology/src/HcalTopology.cc#1189
90  static constexpr uint32_t detId2denseIdHE(uint32_t detId) {
91  const uint32_t nEtaHE = (kLastHERing - kFirstHERing + 1);
92  const uint32_t ip = getIphi(detId);
93  const uint32_t ie = getIetaAbs(detId);
94  const uint32_t dp = getDepth(detId);
95  const int zn = getZside(detId);
96  uint32_t retval = (dp - 1) + kMaxDepthHE * (ip - 1);
97  if (zn > 0)
98  retval += kMaxDepthHE * kMaxIPhi * (ie * zn - kFirstHERing);
99  else
100  retval += kMaxDepthHE * kMaxIPhi * (ie * zn + kLastHERing + nEtaHE);
101 
102  return retval + kSizeBarrel;
103  }
104 
106 
107  static constexpr uint32_t detId2denseId(uint32_t detId) {
108  const uint32_t subdet = getSubdet(detId);
109  if (subdet == HcalBarrel)
110  return detId2denseIdHB(detId);
111  if (subdet == HcalEndcap)
112  return detId2denseIdHE(detId);
113 
114  printf("invalid Hcal detId: %u\n", detId);
115  return kInvalidDenseId;
116  }
117  };
118 
119  struct ECAL {
128 
129  static constexpr DetId::Detector kDetectorId = DetId::Detector::Ecal;
132 
134 
135  // https://cmssdt.cern.ch/lxr/source/DataFormats/EcalDetId/interface/EBDetId.h
136  struct Barrel {
137  static constexpr int kMaxIEta = 85;
138  static constexpr int kMaxIPhi = 360;
139  static constexpr int kSize = 2 * kMaxIPhi * kMaxIEta;
140 
141  static constexpr int ietaAbs(uint32_t detId) { return (detId >> 9) & 0x7F; }
142  static constexpr int iphi(uint32_t detId) { return detId & 0x1FF; }
143  static constexpr bool positiveZ(uint32_t detId) { return detId & 0x10000; }
144  static constexpr uint32_t denseIndex(uint32_t detId) {
145  return (kMaxIEta + (positiveZ(detId) ? ietaAbs(detId) - 1 : -ietaAbs(detId))) * kMaxIPhi + iphi(detId) - 1;
146  }
147  };
148 
149  // https://cmssdt.cern.ch/lxr/source/DataFormats/EcalDetId/interface/EEDetId.h
150  struct Endcap {
151  static constexpr uint32_t kEEhalf = 7324;
152  static constexpr uint32_t kSize = kEEhalf * 2;
153 
154  static constexpr int ix(uint32_t detId) { return (detId >> 7) & 0x7F; }
155  static constexpr int iy(uint32_t detId) { return detId & 0x7F; }
156  static constexpr bool positiveZ(uint32_t detId) { return detId & 0x4000; }
157 
158  static constexpr uint32_t denseIndex(uint32_t detId) {
159  const unsigned short kxf[] = {
160  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,
161  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,
162  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,
163  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,
164  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,
165  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,
166  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,
167  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};
168 
169  const unsigned short kdi[] = {
170  0, 10, 20, 30, 40, 50, 60, 75, 90, 105, 120, 145, 170, 195, 220, 245, 270,
171  300, 330, 360, 390, 420, 450, 480, 510, 540, 570, 605, 640, 675, 710, 747, 784, 821,
172  858, 895, 932, 969, 1006, 1043, 1080, 1122, 1164, 1206, 1248, 1290, 1332, 1374, 1416, 1458, 1500,
173  1545, 1590, 1635, 1680, 1725, 1770, 1815, 1860, 1905, 1950, 1995, 2040, 2085, 2130, 2175, 2220, 2265,
174  2310, 2355, 2400, 2447, 2494, 2541, 2588, 2635, 2682, 2729, 2776, 2818, 2860, 2903, 2946, 2988, 3030,
175  3071, 3112, 3152, 3192, 3232, 3272, 3311, 3350, 3389, 3428, 3467, 3506, 3545, 3584, 3623, 3662, 3701,
176  3740, 3779, 3818, 3857, 3896, 3935, 3974, 4013, 4052, 4092, 4132, 4172, 4212, 4253, 4294, 4336, 4378,
177  4421, 4464, 4506, 4548, 4595, 4642, 4689, 4736, 4783, 4830, 4877, 4924, 4969, 5014, 5059, 5104, 5149,
178  5194, 5239, 5284, 5329, 5374, 5419, 5464, 5509, 5554, 5599, 5644, 5689, 5734, 5779, 5824, 5866, 5908,
179  5950, 5992, 6034, 6076, 6118, 6160, 6202, 6244, 6281, 6318, 6355, 6392, 6429, 6466, 6503, 6540, 6577,
180  6614, 6649, 6684, 6719, 6754, 6784, 6814, 6844, 6874, 6904, 6934, 6964, 6994, 7024, 7054, 7079, 7104,
181  7129, 7154, 7179, 7204, 7219, 7234, 7249, 7264, 7274, 7284, 7294, 7304, 7314};
182 
183  const uint32_t jx = ix(detId);
184  const uint32_t jd = 2 * (iy(detId) - 1) + (jx - 1) / 50;
185  return ((positiveZ(detId) ? kEEhalf : 0) + kdi[jd] + jx - kxf[jd]);
186  }
187  };
188 
189  static constexpr bool checkFlag(uint32_t flagBits, int flag) { return flagBits & (0x1 << flag); }
190 
192 
193  static constexpr uint32_t detId2denseId(uint32_t detId) {
194  const uint32_t subdet = getSubdet(detId);
195  if (subdet == EcalBarrel)
196  return Barrel::denseIndex(detId);
197  if (subdet == EcalEndcap)
199 
200  printf("invalid Ecal detId: %u\n", detId);
201  return kInvalidDenseId;
202  }
203 
204  static constexpr bool detIdInRange(uint32_t detId) {
205  return detId != 0 && DetId(detId).det() == DetId::Detector::Ecal &&
207  }
208 
209  static constexpr int getZside(uint32_t detId) {
211  ? (1)
212  : (-1);
213  }
214 
215  static constexpr uint32_t kSize = Barrel::kSize + Endcap::kSize; // maximum possible ECAL denseId (=75848)
216  };
217 
218 } // namespace ALPAKA_ACCELERATOR_NAMESPACE::particleFlowRecHitProducer
219 
220 #endif // RecoParticleFlow_PFRecHitProducer_interface_alpaka_CalorimeterDefinitions_h
PortableHostCollection< CaloRecHitSoA > CaloRecHitHostCollection
PortableCollection<::reco::PFRecHitECALTopologySoA > PFRecHitECALTopologyDeviceCollection
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
PortableHostCollection< PFRecHitHCALTopologySoA > PFRecHitHCALTopologyHostCollection
PortableCollection<::reco::PFRecHitECALParamsSoA > PFRecHitECALParamsDeviceCollection
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
reco::PFRecHitHCALTopologyDeviceCollection TopologyTypeDevice
static constexpr bool checkFlag(uint32_t flagBits, int flag)
PortableHostCollection< HcalRecHitSoA > RecHitHostCollection
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
PortableCollection<::reco::PFRecHitHCALTopologySoA > PFRecHitHCALTopologyDeviceCollection
Definition: HCAL.py:1
Definition: DetId.h:17
Detector
Definition: DetId.h:24
ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kdi[]
PortableCollection<::reco::CaloRecHitSoA > CaloRecHitDeviceCollection
PortableCollection<::reco::PFRecHitHCALParamsSoA > PFRecHitHCALParamsDeviceCollection
ALPAKA_STATIC_ACC_MEM_CONSTANT const unsigned short kxf[]
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
PortableHostCollection< PFRecHitECALTopologySoA > PFRecHitECALTopologyHostCollection
PortableCollection< HcalRecHitSoA > RecHitDeviceCollection
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164