CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SimplePixelTopology.h
Go to the documentation of this file.
1 #ifndef Geometry_CommonTopologies_SimplePixelTopology_h
2 #define Geometry_CommonTopologies_SimplePixelTopology_h
3 
4 #include <array>
5 #include <cstdint>
6 #include <type_traits>
7 
8 namespace pixelTopology {
9  template <class Function, std::size_t... Indices>
10  constexpr auto map_to_array_helper(Function f, std::index_sequence<Indices...>)
11  -> std::array<std::invoke_result_t<Function, std::size_t>, sizeof...(Indices)> {
12  return {{f(Indices)...}};
13  }
14 
15  template <int N, class Function>
16  constexpr auto map_to_array(Function f) -> std::array<std::invoke_result_t<Function, std::size_t>, N> {
17  return map_to_array_helper(f, std::make_index_sequence<N>{});
18  }
19 
20  constexpr auto maxNumberOfLadders = 160;
21  constexpr uint32_t maxLayers = 28;
22 
23  struct AverageGeometry {
24  //
31  float endCapZ[2]; // just for pos and neg Layer1
32  };
33 
34  constexpr inline uint16_t localY(uint16_t py, uint16_t n) {
35  auto roc = py / n;
36  auto shift = 2 * roc;
37  auto yInRoc = py - n * roc;
38  if (yInRoc > 0)
39  shift += 1;
40  return py + shift;
41  }
42 
43 } // namespace pixelTopology
44 
45 namespace phase1PixelTopology {
46 
47  constexpr uint16_t numberOfModulesInBarrel = 1184;
48  constexpr uint16_t numberOfModulesInLadder = 8;
50 
51  constexpr uint16_t numRowsInRoc = 80;
52  constexpr uint16_t numColsInRoc = 52;
53  constexpr uint16_t lastRowInRoc = numRowsInRoc - 1;
54  constexpr uint16_t lastColInRoc = numColsInRoc - 1;
55 
56  constexpr uint16_t numRowsInModule = 2 * numRowsInRoc;
57  constexpr uint16_t numColsInModule = 8 * numColsInRoc;
58  constexpr uint16_t lastRowInModule = numRowsInModule - 1;
59  constexpr uint16_t lastColInModule = numColsInModule - 1;
60 
61  constexpr int16_t xOffset = -81;
62  constexpr int16_t yOffset = -54 * 4;
63 
64  constexpr uint16_t pixelThickness = 285;
65  constexpr uint16_t pixelPitchX = 100;
66  constexpr uint16_t pixelPitchY = 150;
67 
68  constexpr uint32_t numPixsInModule = uint32_t(numRowsInModule) * uint32_t(numColsInModule);
69 
70  constexpr uint32_t numberOfModules = 1856;
71  constexpr uint32_t numberOfLayers = 10;
72 #ifdef __CUDA_ARCH__
74 #endif
75  constexpr uint32_t layerStart[numberOfLayers + 1] = {0,
76  96,
77  320,
78  672, // barrel
79  1184,
80  1296,
81  1408, // positive endcap
82  1520,
83  1632,
84  1744, // negative endcap
86  constexpr char const* layerName[numberOfLayers] = {
87  "BL1",
88  "BL2",
89  "BL3",
90  "BL4", // barrel
91  "E+1",
92  "E+2",
93  "E+3", // positive endcap
94  "E-1",
95  "E-2",
96  "E-3" // negative endcap
97  };
98 
99  constexpr uint16_t findMaxModuleStride() {
100  bool go = true;
101  int n = 2;
102  while (go) {
103  for (uint8_t i = 1; i < std::size(layerStart); ++i) {
104  if (layerStart[i] % n != 0) {
105  go = false;
106  break;
107  }
108  }
109  if (!go)
110  break;
111  n *= 2;
112  }
113  return n / 2;
114  }
115 
116  constexpr uint16_t maxModuleStride = findMaxModuleStride();
117 
118  constexpr uint8_t findLayer(uint32_t detId, uint8_t sl = 0) {
119  for (uint8_t i = sl; i < std::size(layerStart); ++i)
120  if (detId < layerStart[i + 1])
121  return i;
122  return std::size(layerStart);
123  }
124 
125  constexpr uint8_t findLayerFromCompact(uint32_t detId) {
126  detId *= maxModuleStride;
127  for (uint8_t i = 0; i < std::size(layerStart); ++i)
128  if (detId < layerStart[i + 1])
129  return i;
130  return std::size(layerStart);
131  }
132 
134 #ifdef __CUDA_ARCH__
135  __device__
136 #endif
137  constexpr std::array<uint8_t, layerIndexSize>
138  layer = pixelTopology::map_to_array<layerIndexSize>(findLayerFromCompact);
139 
140  constexpr uint8_t getLayer(uint32_t detId) {
142  }
143 
144  constexpr bool validateLayerIndex() {
145  bool res = true;
146  for (auto i = 0U; i < numberOfModules; ++i) {
147  auto j = i / maxModuleStride;
148  res &= (layer[j] < numberOfLayers);
149  res &= (i >= layerStart[layer[j]]);
150  res &= (i < layerStart[layer[j] + 1]);
151  }
152  return res;
153  }
154 
155  static_assert(validateLayerIndex(), "layer from detIndex algo is buggy");
156 
157  // this is for the ROC n<512 (upgrade 1024)
158  constexpr inline uint16_t divu52(uint16_t n) {
159  n = n >> 2;
160  uint16_t q = (n >> 1) + (n >> 4);
161  q = q + (q >> 4) + (q >> 5);
162  q = q >> 3;
163  uint16_t r = n - q * 13;
164  return q + ((r + 3) >> 4);
165  }
166 
167  constexpr inline bool isEdgeX(uint16_t px) { return (px == 0) | (px == lastRowInModule); }
168 
169  constexpr inline bool isEdgeY(uint16_t py) { return (py == 0) | (py == lastColInModule); }
170 
171  constexpr inline uint16_t toRocX(uint16_t px) { return (px < numRowsInRoc) ? px : px - numRowsInRoc; }
172 
173  constexpr inline uint16_t toRocY(uint16_t py) {
174  auto roc = divu52(py);
175  return py - 52 * roc;
176  }
177 
178  constexpr inline bool isBigPixX(uint16_t px) { return (px == 79) | (px == 80); }
179 
180  constexpr inline bool isBigPixY(uint16_t py) {
181  auto ly = toRocY(py);
182  return (ly == 0) | (ly == lastColInRoc);
183  }
184 
185  constexpr inline uint16_t localX(uint16_t px) {
186  auto shift = 0;
187  if (px > lastRowInRoc)
188  shift += 1;
189  if (px > numRowsInRoc)
190  shift += 1;
191  return px + shift;
192  }
193 
194  constexpr inline uint16_t localY(uint16_t py) {
195  auto roc = divu52(py);
196  auto shift = 2 * roc;
197  auto yInRoc = py - 52 * roc;
198  if (yInRoc > 0)
199  shift += 1;
200  return py + shift;
201  }
202 
203 } // namespace phase1PixelTopology
204 
205 namespace phase2PixelTopology {
206 
207  constexpr uint32_t numberOfModulesInBarrel = 756;
208  constexpr uint32_t numberOfModulesInLadder = 9;
210 
211  constexpr uint32_t numberOfModules = 3892;
212  constexpr uint8_t numberOfLayers = 28;
213 
214  constexpr uint32_t layerStart[numberOfLayers + 1] = {0,
215  108,
216  324,
217  504, //Barrel
218  756,
219  864,
220  972,
221  1080,
222  1188,
223  1296,
224  1404,
225  1512,
226  1620,
227  1796,
228  1972,
229  2148, //Fp
230  2324,
231  2432,
232  2540,
233  2648,
234  2756,
235  2864,
236  2972,
237  3080,
238  3188,
239  3364,
240  3540,
241  3716, //Np
243 
244  constexpr uint16_t findMaxModuleStride() {
245  bool go = true;
246  int n = 2;
247  while (go) {
248  for (uint8_t i = 1; i < numberOfLayers + 1; ++i) {
249  if (layerStart[i] % n != 0) {
250  go = false;
251  break;
252  }
253  }
254  if (!go)
255  break;
256  n *= 2;
257  }
258  return n / 2;
259  }
260 
261  constexpr uint16_t maxModuleStride = findMaxModuleStride();
262 
263  constexpr uint8_t findLayerFromCompact(uint32_t detId) {
264  detId *= maxModuleStride;
265  for (uint8_t i = 0; i < numberOfLayers + 1; ++i)
266  if (detId < layerStart[i + 1])
267  return i;
268  return numberOfLayers + 1;
269  }
270 
272  constexpr std::array<uint8_t, layerIndexSize> layer =
273  pixelTopology::map_to_array<layerIndexSize>(findLayerFromCompact);
274 
275  constexpr bool validateLayerIndex() {
276  bool res = true;
277  for (auto i = 0U; i < numberOfModules; ++i) {
278  auto j = i / maxModuleStride;
279  res &= (layer[j] < numberOfLayers);
280  res &= (i >= layerStart[layer[j]]);
281  res &= (i < layerStart[layer[j] + 1]);
282  }
283  return res;
284  }
285 
286  static_assert(validateLayerIndex(), "phase2 layer from detIndex algo is buggy");
287 
288 } // namespace phase2PixelTopology
289 
290 #endif // Geometry_CommonTopologies_SimplePixelTopology_h
constexpr uint16_t maxModuleStride
constexpr uint16_t lastRowInModule
constexpr uint16_t divu52(uint16_t n)
constexpr uint16_t pixelPitchY
constexpr char const * layerName[numberOfLayers]
constexpr auto maxNumberOfLadders
constexpr uint32_t numberOfModulesInBarrel
constexpr uint32_t numberOfLayers
constexpr uint32_t layerStart[numberOfLayers+1]
constexpr uint32_t maxLayers
constexpr uint16_t numRowsInRoc
float ladderMinZ[maxNumberOfLadders]
constexpr uint16_t localY(uint16_t py)
constexpr bool validateLayerIndex()
constexpr uint32_t numberOfModules
constexpr uint16_t lastColInModule
constexpr uint16_t numColsInModule
constexpr uint16_t numberOfLaddersInBarrel
constexpr uint16_t numRowsInModule
constexpr uint16_t lastColInRoc
constexpr std::array< uint8_t, layerIndexSize > layer
float ladderR[maxNumberOfLadders]
constexpr uint16_t findMaxModuleStride()
constexpr uint32_t layerIndexSize
constexpr uint16_t pixelPitchX
constexpr auto map_to_array(Function f) -> std::array< std::invoke_result_t< Function, std::size_t >, N >
float ladderMaxZ[maxNumberOfLadders]
Indices
Definition: EdmEventSize.cc:28
constexpr uint16_t numColsInRoc
constexpr bool isEdgeY(uint16_t py)
constexpr uint8_t getLayer(uint32_t detId)
constexpr bool isBigPixY(uint16_t py)
constexpr bool validateLayerIndex()
constexpr uint32_t numberOfLaddersInBarrel
constexpr bool isEdgeX(uint16_t px)
constexpr uint16_t lastRowInRoc
constexpr auto map_to_array_helper(Function f, std::index_sequence< Indices...>) -> std::array< std::invoke_result_t< Function, std::size_t >, sizeof...(Indices)>
constexpr uint32_t numberOfModules
#define N
Definition: blowfish.cc:9
constexpr bool isBigPixX(uint16_t px)
constexpr int16_t xOffset
constexpr uint16_t maxModuleStride
constexpr uint16_t localX(uint16_t px)
constexpr uint16_t pixelThickness
constexpr std::array< uint8_t, layerIndexSize > layer
constexpr uint16_t localY(uint16_t py, uint16_t n)
constexpr uint8_t findLayerFromCompact(uint32_t detId)
constexpr uint8_t numberOfLayers
constexpr uint16_t numberOfModulesInBarrel
float ladderY[maxNumberOfLadders]
constexpr uint16_t layerIndexSize
constexpr uint32_t layerStart[numberOfLayers+1]
float ladderZ[maxNumberOfLadders]
static unsigned int const shift
constexpr uint32_t numPixsInModule
float ladderX[maxNumberOfLadders]
#define __device__
constexpr uint16_t numberOfModulesInLadder
constexpr uint32_t numberOfModulesInLadder
constexpr int16_t yOffset
tuple size
Write out results.
constexpr uint8_t findLayerFromCompact(uint32_t detId)
constexpr uint16_t toRocX(uint16_t px)
constexpr uint8_t findLayer(uint32_t detId, uint8_t sl=0)
constexpr uint16_t findMaxModuleStride()
constexpr uint16_t toRocY(uint16_t py)