forked from cms-patatrack/pixeltrack-standalone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphase1PixelTopology.h
174 lines (145 loc) · 5.46 KB
/
phase1PixelTopology.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#ifndef Geometry_TrackerGeometryBuilder_phase1PixelTopology_h
#define Geometry_TrackerGeometryBuilder_phase1PixelTopology_h
#include <cstdint>
#include <array>
namespace phase1PixelTopology {
constexpr uint16_t numRowsInRoc = 80;
constexpr uint16_t numColsInRoc = 52;
constexpr uint16_t lastRowInRoc = numRowsInRoc - 1;
constexpr uint16_t lastColInRoc = numColsInRoc - 1;
constexpr uint16_t numRowsInModule = 2 * numRowsInRoc;
constexpr uint16_t numColsInModule = 8 * numColsInRoc;
constexpr uint16_t lastRowInModule = numRowsInModule - 1;
constexpr uint16_t lastColInModule = numColsInModule - 1;
constexpr int16_t xOffset = -81;
constexpr int16_t yOffset = -54 * 4;
constexpr uint32_t numPixsInModule = uint32_t(numRowsInModule) * uint32_t(numColsInModule);
constexpr uint32_t numberOfModules = 1856;
constexpr uint32_t numberOfLayers = 10;
constexpr uint32_t layerStart[numberOfLayers + 1] = {0,
96,
320,
672, // barrel
1184,
1296,
1408, // positive endcap
1520,
1632,
1744, // negative endcap
numberOfModules};
constexpr char const* layerName[numberOfLayers] = {
"BL1",
"BL2",
"BL3",
"BL4", // barrel
"E+1",
"E+2",
"E+3", // positive endcap
"E-1",
"E-2",
"E-3" // negative endcap
};
constexpr uint32_t numberOfModulesInBarrel = 1184;
constexpr uint32_t numberOfLaddersInBarrel = numberOfModulesInBarrel / 8;
template <class Function, std::size_t... Indices>
constexpr auto map_to_array_helper(Function f, std::index_sequence<Indices...>)
-> std::array<typename std::result_of<Function(std::size_t)>::type, sizeof...(Indices)> {
return {{f(Indices)...}};
}
template <int N, class Function>
constexpr auto map_to_array(Function f) -> std::array<typename std::result_of<Function(std::size_t)>::type, N> {
return map_to_array_helper(f, std::make_index_sequence<N>{});
}
constexpr uint32_t findMaxModuleStride() {
bool go = true;
int n = 2;
while (go) {
for (uint8_t i = 1; i < 11; ++i) {
if (layerStart[i] % n != 0) {
go = false;
break;
}
}
if (!go)
break;
n *= 2;
}
return n / 2;
}
constexpr uint32_t maxModuleStride = findMaxModuleStride();
constexpr uint8_t findLayer(uint32_t detId) {
for (uint8_t i = 0; i < 11; ++i)
if (detId < layerStart[i + 1])
return i;
return 11;
}
constexpr uint8_t findLayerFromCompact(uint32_t detId) {
detId *= maxModuleStride;
for (uint8_t i = 0; i < 11; ++i)
if (detId < layerStart[i + 1])
return i;
return 11;
}
constexpr uint32_t layerIndexSize = numberOfModules / maxModuleStride;
constexpr std::array<uint8_t, layerIndexSize> layer = map_to_array<layerIndexSize>(findLayerFromCompact);
constexpr bool validateLayerIndex() {
bool res = true;
for (auto i = 0U; i < numberOfModules; ++i) {
auto j = i / maxModuleStride;
res &= (layer[j] < 10);
res &= (i >= layerStart[layer[j]]);
res &= (i < layerStart[layer[j] + 1]);
}
return res;
}
static_assert(validateLayerIndex(), "layer from detIndex algo is buggy");
// this is for the ROC n<512 (upgrade 1024)
constexpr inline uint16_t divu52(uint16_t n) {
n = n >> 2;
uint16_t q = (n >> 1) + (n >> 4);
q = q + (q >> 4) + (q >> 5);
q = q >> 3;
uint16_t r = n - q * 13;
return q + ((r + 3) >> 4);
}
constexpr inline bool isEdgeX(uint16_t px) { return (px == 0) | (px == lastRowInModule); }
constexpr inline bool isEdgeY(uint16_t py) { return (py == 0) | (py == lastColInModule); }
constexpr inline uint16_t toRocX(uint16_t px) { return (px < numRowsInRoc) ? px : px - numRowsInRoc; }
constexpr inline uint16_t toRocY(uint16_t py) {
auto roc = divu52(py);
return py - 52 * roc;
}
constexpr inline bool isBigPixX(uint16_t px) { return (px == 79) | (px == 80); }
constexpr inline bool isBigPixY(uint16_t py) {
auto ly = toRocY(py);
return (ly == 0) | (ly == lastColInRoc);
}
constexpr inline uint16_t localX(uint16_t px) {
auto shift = 0;
if (px > lastRowInRoc)
shift += 1;
if (px > numRowsInRoc)
shift += 1;
return px + shift;
}
constexpr inline uint16_t localY(uint16_t py) {
auto roc = divu52(py);
auto shift = 2 * roc;
auto yInRoc = py - 52 * roc;
if (yInRoc > 0)
shift += 1;
return py + shift;
}
//FIXME move it elsewhere?
struct AverageGeometry {
static constexpr auto numberOfLaddersInBarrel = phase1PixelTopology::numberOfLaddersInBarrel;
float ladderZ[numberOfLaddersInBarrel];
float ladderX[numberOfLaddersInBarrel];
float ladderY[numberOfLaddersInBarrel];
float ladderR[numberOfLaddersInBarrel];
float ladderMinZ[numberOfLaddersInBarrel];
float ladderMaxZ[numberOfLaddersInBarrel];
float endCapZ[2]; // just for pos and neg Layer1
};
} // namespace phase1PixelTopology
#endif // Geometry_TrackerGeometryBuilder_phase1PixelTopology_h