CMS 3D CMS Logo

HGCalTopology.cc
Go to the documentation of this file.
11 
12 //#define EDM_ML_DEBUG
13 
14 HGCalTopology::HGCalTopology(const HGCalDDDConstants& hdcons, int det) : hdcons_(hdcons) {
16  layers_ = hdcons_.layers(true);
17  cells_ = hdcons_.maxCells(true);
21  waferMax_ = 2 * waferOff_ + 1;
24  if (waferHexagon6()) {
26  subdet_ = (ForwardSubdetector)(det);
28  types_ = 2;
29  } else if (det == static_cast<int>(DetId::Forward)) {
31  subdet_ = HFNose;
33  types_ = 3;
34  } else if (tileTrapezoid()) {
35  det_ = (DetId::Detector)(det);
38  types_ = 3;
39  } else {
40  det_ = (DetId::Detector)(det);
43  types_ = 3;
44  }
46  kSizeForDenseIndexing = static_cast<unsigned int>(2 * kHGhalf_);
47 #ifdef EDM_ML_DEBUG
48  edm::LogVerbatim("HGCalGeom") << "HGCalTopology initialized for detector " << det << ":" << det_ << ":" << subdet_
49  << " having " << sectors_ << " Sectors, " << layers_ << " Layers from " << firstLay_
50  << ", " << cells_ << " cells and total channels " << kSizeForDenseIndexing << ":"
51  << (2 * kHGeomHalf_);
52 #endif
53 }
54 
55 unsigned int HGCalTopology::allGeomModules() const {
56  return (tileTrapezoid() ? (unsigned int)(2 * hdcons_.numberCells(true)) : (unsigned int)(2 * hdcons_.wafers()));
57 }
58 
59 std::vector<DetId> HGCalTopology::neighbors(const DetId& idin) const {
60  std::vector<DetId> ids;
62  if (waferHexagon8()) {
63  int celltype = hdcons_.cellType(
64  id.iType, id.iCell1, id.iCell2, id.zSide, 1, -1); // Temporary fix - later for v17 define fwd back and orient
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("HGCalGeom") << "Type:WaferU:WaferV " << id.iType << ":" << id.iCell1 << ":" << id.iCell2
67  << " CellType " << celltype;
68 #endif
69  switch (celltype) {
70  case (HGCalCell::centralCell): {
71  // cell within the wafer
72 #ifdef EDM_ML_DEBUG
73  edm::LogVerbatim("HGCalGeom") << "Cell Type 0";
74 #endif
75  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
76  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
77  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
78  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
79  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
80  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
81  break;
82  }
84  // bottom left edge
85  int wu1(id.iSec1), wv1(id.iSec2 - 1);
86  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
87  int N1 = hdcons_.getUVMax(t1);
88  int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
89 #ifdef EDM_ML_DEBUG
90  edm::LogVerbatim("HGCalGeom") << "Cell Type 1 "
91  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1;
92 #endif
93  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
94  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
95  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1 - 1);
96  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1);
97  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
98  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
99  break;
100  }
101  case (HGCalCell::leftEdge): {
102  // left edege
103  int wu1(id.iSec1 + 1), wv1(id.iSec2);
104  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
105  int N1 = hdcons_.getUVMax(t1);
106  int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
107 #ifdef EDM_ML_DEBUG
108  edm::LogVerbatim("HGCalGeom") << "Cell Type 2 "
109  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1;
110 #endif
111  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
112  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1, 2 * N1 - 1);
113  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1 - 1, 2 * N1 - 1);
114  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
115  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
116  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
117  break;
118  }
119  case (HGCalCell::topLeftEdge): {
120  // top left edge
121  int wu1(id.iSec1 + 1), wv1(id.iSec2 + 1);
122  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
123  int N1 = hdcons_.getUVMax(t1);
124  int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
125 #ifdef EDM_ML_DEBUG
126  edm::LogVerbatim("HGCalGeom") << "Cell Type 3 "
127  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1;
128 #endif
129  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1 + 1, v1 + N1);
130  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1, v1 + N1 - 1);
131  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
132  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
133  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
134  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
135  break;
136  }
137  case (HGCalCell::topRightEdge): {
138  // top right edge
139  int wu1(id.iSec1), wv1(id.iSec2 + 1);
140  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
141  int N1 = hdcons_.getUVMax(t1);
142  int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("HGCalGeom") << "Cell Type 4 "
145  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1;
146 #endif
147  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 0, v1 - N1);
148  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
149  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
150  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
151  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
152  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 0, v1 - N1 + 1);
153  break;
154  }
155  case (HGCalCell::rightEdge): {
156  // right edge
157  int wu1(id.iSec1 - 1), wv1(id.iSec2);
158  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
159  int N1 = hdcons_.getUVMax(t1);
160  int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
161 #ifdef EDM_ML_DEBUG
162  edm::LogVerbatim("HGCalGeom") << "Cell Type 5 "
163  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1;
164 #endif
165  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
166  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
167  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
168  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
169  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 - N1, 0);
170  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 - N1 + 1, 0);
171  break;
172  }
174  // bottom right edge
175  int wu1(id.iSec1 - 1), wv1(id.iSec2 - 1);
176  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
177  int N1 = hdcons_.getUVMax(t1);
178  int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
179 #ifdef EDM_ML_DEBUG
180  edm::LogVerbatim("HGCalGeom") << "Cell Type 6 "
181  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1;
182 #endif
183  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
184  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
185  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
186  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1 - 1, u1 - 1);
187  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1, u1);
188  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
189  break;
190  }
191  case (HGCalCell::bottomCorner): {
192  // bottom corner
193  int wu1(id.iSec1), wv1(id.iSec2 - 1);
194  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
195  int N1 = hdcons_.getUVMax(t1);
196  int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
197  int wu2(id.iSec1 - 1), wv2(id.iSec2 - 1);
198  int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
199  int N2 = hdcons_.getUVMax(t2);
200  int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
201 #ifdef EDM_ML_DEBUG
202  edm::LogVerbatim("HGCalGeom") << "Cell Type 11 "
203  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
204  << ":" << N2 << ":" << u2;
205 #endif
206  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
207  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
208  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1 - 1);
209  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 2 * N1 - 1, v1 + N1);
210  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 + N2, u2);
211  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
212  break;
213  }
215  // bottom left corner
216  int wu1(id.iSec1 + 1), wv1(id.iSec2);
217  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
218  int N1 = hdcons_.getUVMax(t1);
219  int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
220  int wu2(id.iSec1), wv2(id.iSec2 - 1);
221  int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
222  int N2 = hdcons_.getUVMax(t2);
223  int v2 = hdcons_.modifyUV(id.iCell2, id.iType, t2);
224 #ifdef EDM_ML_DEBUG
225  edm::LogVerbatim("HGCalGeom") << "Cell Type 12 "
226  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1 << ":" << t2
227  << ":" << N2 << ":" << v2;
228 #endif
229  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
230  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1, 2 * N1 - 1);
231  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, 2 * N2 - 1, v2 + N2 - 1);
232  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, 2 * N2 - 1, v2 + N2);
233  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
234  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
235  break;
236  }
237  case (HGCalCell::topLeftCorner): {
238  // top left corner
239  int wu1(id.iSec1 + 1), wv1(id.iSec2 + 1);
240  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
241  int N1 = hdcons_.getUVMax(t1);
242  int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
243  int wu2(id.iSec1 + 1), wv2(id.iSec2);
244  int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
245  int N2 = hdcons_.getUVMax(t2);
246  int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
247 #ifdef EDM_ML_DEBUG
248  edm::LogVerbatim("HGCalGeom") << "Cell Type 13 "
249  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
250  << ":" << N2 << ":" << u2;
251 #endif
252  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1 + 1, N1 + v1);
253  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1, N1 + v1 - 1);
254  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 + N2 - 1, 2 * N2 - 1);
255  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
256  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
257  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2 + 1);
258  break;
259  }
260  case (HGCalCell::topCorner): {
261  // top corner
262  int wu1(id.iSec1 + 1), wv1(id.iSec2 + 1);
263  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
264  int N1 = hdcons_.getUVMax(t1);
265  int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
266  int wu2(id.iSec1), wv2(id.iSec2 + 1);
267  int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
268  int N2 = hdcons_.getUVMax(t2);
269  int v2 = hdcons_.modifyUV(id.iCell2, id.iType, t2);
270 #ifdef EDM_ML_DEBUG
271  edm::LogVerbatim("HGCalGeom") << "Cell Type 14 "
272  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
273  << ":" << N2 << ":" << v2;
274 #endif
275  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1 + 1, v1 + N1);
276  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, v1, v1 + N1 - 1);
277  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
278  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
279  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 + 1);
280  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, 0, v2 - N2 + 1);
281  break;
282  }
283  case (HGCalCell::topRightCorner): {
284  // top right corner
285  int wu1(id.iSec1), wv1(id.iSec2 + 1);
286  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
287  int N1 = hdcons_.getUVMax(t1);
288  int v1 = hdcons_.modifyUV(id.iCell2, id.iType, t1);
289  int wu2(id.iSec1 - 1), wv2(id.iSec2);
290  int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
291  int N2 = hdcons_.getUVMax(t2);
292  int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
293 #ifdef EDM_ML_DEBUG
294  edm::LogVerbatim("HGCalGeom") << "Cell Type 15 "
295  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << v1 << ":" << t2
296  << ":" << N2 << ":" << u2;
297 #endif
298  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, 0, v1 - N1);
299  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
300  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
301  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2);
302  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2, 0);
303  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2 + 1, 0);
304  break;
305  }
307  // bottom right corner
308  int wu1(id.iSec1 - 1), wv1(id.iSec2 - 1);
309  int t1 = hdcons_.getTypeHex(id.iLay, wu1, wv1);
310  int N1 = hdcons_.getUVMax(t1);
311  int u1 = hdcons_.modifyUV(id.iCell1, id.iType, t1);
312  int wu2(id.iSec1 - 1), wv2(id.iSec2);
313  int t2 = hdcons_.getTypeHex(id.iLay, wu2, wv2);
314  int N2 = hdcons_.getUVMax(t2);
315  int u2 = hdcons_.modifyUV(id.iCell1, id.iType, t2);
316 #ifdef EDM_ML_DEBUG
317  edm::LogVerbatim("HGCalGeom") << "Cell Type 16 "
318  << ":" << wu1 << ":" << wv1 << ":" << t1 << ":" << N1 << ":" << u1 << ":" << t2
319  << ":" << N2 << ":" << u2;
320 #endif
321  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 + 1, id.iCell2);
322  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2 - 1);
323  addHGCSiliconId(ids, id.det, id.zSide, id.iType, id.iLay, id.iSec1, id.iSec2, id.iCell1 - 1, id.iCell2 - 1);
324  addHGCSiliconId(ids, id.det, id.zSide, t1, id.iLay, wu1, wv1, u1 + N1 - 1, u1 - 1);
325  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2, 0);
326  addHGCSiliconId(ids, id.det, id.zSide, t2, id.iLay, wu2, wv2, u2 - N2 + 1, 0);
327  break;
328  }
329  default:
330  // Not valid u, v
331  int N = hdcons_.getUVMax(id.iType);
332  edm::LogWarning("HGCalGeom") << "u:v " << id.iCell1 << ":" << id.iCell2 << " Tests " << (id.iCell1 > 2 * N - 1)
333  << ":" << (id.iCell2 > 2 * N - 1) << ":" << (id.iCell2 >= (id.iCell1 + N)) << ":"
334  << (id.iCell1 > (id.iCell2 + N)) << " ERROR";
335  }
336  } else if (tileTrapezoid()) {
337  int iphi1 = (id.iCell1 > 1) ? id.iCell1 - 1 : hdcons_.getUVMax(id.iType);
338  int iphi2 = (id.iCell1 < hdcons_.getUVMax(id.iType)) ? id.iCell1 + 1 : 1;
339  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 - 1, id.iCell1);
340  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 - 1, iphi1);
341  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1, iphi1);
342  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 + 1, iphi1);
343  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 + 1, id.iCell1);
344  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 + 1, iphi2);
345  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1, iphi2);
346  addHGCSCintillatorId(ids, id.zSide, id.iType, id.iLay, id.iSec1 - 1, iphi2);
347  }
348  return ids;
349 }
350 
351 uint32_t HGCalTopology::detId2denseId(const DetId& idin) const {
353  uint32_t idx;
354  if (waferHexagon6()) {
355  int type = (id.iType > 0) ? 1 : 0;
356  idx = (uint32_t)(((id.zSide > 0) ? kHGhalfType_ : 0) +
357  ((((id.iCell1 - 1) * layers_ + id.iLay - 1) * sectors_ + id.iSec1) * types_ + type));
358 #ifdef EDM_ML_DEBUG
359  edm::LogVerbatim("HGCalGeom") << "Input Hex " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iCell1
360  << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_ << ":"
361  << sectors_ << ":" << types_ << " o/p " << idx;
362 #endif
363  } else if (tileTrapezoid()) {
364  idx =
365  (uint32_t)(((id.zSide > 0) ? kHGhalfType_ : 0) +
366  ((((id.iCell1 - 1) * layers_ + id.iLay - firstLay_) * sectors_ + id.iSec1 - 1) * types_ + id.iType));
367 #ifdef EDM_ML_DEBUG
368  edm::LogVerbatim("HGCalGeom") << "Input Trap " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iCell1
369  << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_ << ":"
370  << sectors_ << ":" << types_ << " o/p " << idx;
371 #endif
372  } else {
373  idx =
374  (uint32_t)(((id.zSide > 0) ? kHGhalfType_ : 0) +
375  (((((id.iCell1 * cellMax_ + id.iCell2) * layers_ + id.iLay - 1) * waferMax_ + id.iSec1 + waferOff_) *
376  waferMax_ +
377  id.iSec2 + waferOff_) *
378  types_ +
379  id.iType));
380 #ifdef EDM_ML_DEBUG
381  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iSec2
382  << ":" << id.iCell1 << ":" << id.iCell2 << ":" << id.iType << " Constants "
383  << kHGeomHalf_ << ":" << cellMax_ << ":" << layers_ << ":" << waferMax_ << ":"
384  << waferOff_ << ":" << types_ << " o/p " << idx;
385 #endif
386  }
387  return idx;
388 }
389 
392  if (validHashIndex(hi)) {
393  id.zSide = (static_cast<int>(hi) < kHGhalfType_ ? -1 : 1);
394  int di = (static_cast<int>(hi) % kHGhalfType_);
395  if (waferHexagon6()) {
396  int type = (di % types_);
397  id.iType = (type == 0 ? -1 : 1);
398  id.iSec1 = (((di - type) / types_) % sectors_);
399  id.iLay = (((((di - type) / types_) - id.iSec1 + 1) / sectors_) % layers_ + 1);
400  id.iCell1 = (((((di - type) / types_) - id.iSec1 + 1) / sectors_ - id.iLay + 1) / layers_ + 1);
401 #ifdef EDM_ML_DEBUG
402  edm::LogVerbatim("HGCalGeom") << "Input Hex " << hi << " o/p " << id.zSide << ":" << id.iLay << ":" << id.iType
403  << ":" << id.iSec1 << ":" << id.iCell1;
404 #endif
405  } else if (tileTrapezoid()) {
406  int type = (di % types_);
407  id.iType = type;
408  id.iSec1 = (((di - type) / types_) % sectors_) + 1;
409  id.iLay = (((((di - type) / types_) - id.iSec1 + 1) / sectors_) % layers_ + firstLay_);
410  id.iCell1 = (((((di - type) / types_) - id.iSec1 + 1) / sectors_ - id.iLay + firstLay_) / layers_ + 1);
411 #ifdef EDM_ML_DEBUG
412  edm::LogVerbatim("HGCalGeom") << "Input Trap " << hi << " o/p " << id.zSide << ":" << id.iLay << ":" << id.iType
413  << ":" << id.iSec1 << ":" << id.iCell1;
414 #endif
415  } else {
416  int type = (di % types_);
417  id.iType = type;
418  di = (di - type) / types_;
419  id.iSec2 = (di % waferMax_) - waferOff_;
420  di = (di - id.iSec2 - waferOff_) / waferMax_;
421  id.iSec1 = (di % waferMax_) - waferOff_;
422  di = (di - id.iSec1 - waferOff_) / waferMax_;
423  id.iLay = (di % layers_) + 1;
424  di = (di - id.iLay + 1) / layers_;
425  id.iCell2 = (di % cellMax_);
426  id.iCell1 = (di - id.iCell2) / cellMax_;
427 #ifdef EDM_ML_DEBUG
428  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << hi << " o/p " << id.zSide << ":" << id.iLay << ":" << id.iType
429  << ":" << id.iSec1 << ":" << id.iSec2 << ":" << id.iCell1 << ":" << id.iCell2;
430 #endif
431  }
432  }
433  return encode(id);
434 }
435 
436 uint32_t HGCalTopology::detId2denseGeomId(const DetId& idin) const {
438  uint32_t idx;
439  if (waferHexagon6()) {
440  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) + (id.iLay - 1) * sectors_ + id.iSec1);
441 #ifdef EDM_ML_DEBUG
442  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":" << id.iType
443  << " Constants " << kHGeomHalf_ << ":" << layers_ << ":" << sectors_ << " o/p "
444  << idx;
445 #endif
446  } else if (tileTrapezoid()) {
447  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
448  (((id.iLay - firstLay_) * sectors_ + id.iSec1 - 1) * cellMax_ + id.iCell1 - 1));
449 #ifdef EDM_ML_DEBUG
450  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":"
451  << id.iCell1 << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_
452  << ":" << firstLay_ << ":" << sectors_ << ":" << cellMax_ << " o/p " << idx;
453 #endif
454  } else {
455  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
456  (((id.iLay - 1) * waferMax_ + id.iSec1 + waferOff_) * waferMax_ + id.iSec2 + waferOff_));
457 #ifdef EDM_ML_DEBUG
458  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << id.zSide << ":" << id.iLay << ":" << id.iSec1 << ":"
459  << id.iSec2 << ":" << id.iType << " Constants " << kHGeomHalf_ << ":" << layers_
460  << ":" << waferMax_ << ":" << waferOff_ << " o/p " << idx;
461 #endif
462  }
463  return idx;
464 }
465 
466 bool HGCalTopology::valid(const DetId& idin) const {
468  bool flag;
469  if (waferHexagon6()) {
470  flag = (idin.det() == det_ && idin.subdetId() == static_cast<int>(subdet_) && id.iCell1 >= 0 &&
471  id.iCell1 < cells_ && id.iLay > 0 && id.iLay <= layers_ && id.iSec1 >= 0 && id.iSec1 <= sectors_);
472  if (flag)
473  flag = hdcons_.isValidHex(id.iLay, id.iSec1, id.iCell1, true);
474  } else if (tileTrapezoid()) {
475  flag = ((idin.det() == det_) && hdcons_.isValidTrap(id.zSide, id.iLay, id.iSec1, id.iCell1));
476  } else {
477  flag = ((idin.det() == det_) && hdcons_.isValidHex8(id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, false));
478  }
479  return flag;
480 }
481 
482 bool HGCalTopology::valid(const DetId& idin, int cornerMin) const {
483  if (waferHexagon8()) {
485  bool mask = (cornerMin < HGCalTypes::WaferCornerMin) ? false : hdcons_.maskCell(idin, cornerMin);
486  bool flag = ((idin.det() == det_) &&
488  id.iLay, id.iSec1, id.iSec2, id.iCell1, id.iCell2, (cornerMin >= HGCalTypes::WaferCornerMin)));
489  return (flag && (!mask));
490  } else {
491  return valid(idin);
492  }
493 }
494 
495 bool HGCalTopology::validModule(const DetId& idin, int cornerMin) const {
496  if (idin.det() != det_) {
497  return false;
498  } else if ((idin.det() == DetId::HGCalEE) || (idin.det() == DetId::HGCalHSi)) {
500  return hdcons_.isValidHex8(id.iLay, id.iSec1, id.iSec2, (cornerMin >= HGCalTypes::WaferCornerMin));
501  } else {
502  return valid(idin);
503  }
504 }
505 
506 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const {
507  if (startId.det() == DetId::Forward && startId.subdetId() == static_cast<int>(subdet_)) {
508  DetId id = changeXY(startId, nrStepsX, nrStepsY);
509  if (valid(id))
510  return id;
511  }
512  return DetId(0);
513 }
514 
515 DetId HGCalTopology::switchZSide(const DetId startId) const {
516  HGCalTopology::DecodedDetId id_ = decode(startId);
517  id_.zSide = -id_.zSide;
518  DetId id = encode(id_);
519  if (valid(id))
520  return id;
521  else
522  return DetId(0);
523 }
524 
527  if (hi < totalGeomModules()) {
528  id.zSide = (static_cast<int>(hi) < kHGeomHalf_ ? -1 : 1);
529  int di = (static_cast<int>(hi) % kHGeomHalf_);
530  if (waferHexagon6()) {
531  id.iSec1 = (di % sectors_);
532  di = (di - id.iSec1) / sectors_;
533  id.iLay = (di % layers_) + 1;
534  id.iType = ((di - id.iLay + 1) / layers_ == 0) ? -1 : 1;
535 #ifdef EDM_ML_DEBUG
536  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << hi << " O/P " << id.zSide << ":" << id.iType << ":" << id.iLay
537  << ":" << id.iSec1;
538 #endif
539  } else if (tileTrapezoid()) {
540  id.iCell1 = (di % cellMax_) + 1;
541  di = (di - id.iCell1 + 1) / cellMax_;
542  id.iSec1 = (di % sectors_) + 1;
543  di = (di - id.iSec1 + 1) / sectors_;
544  id.iLay = (di % layers_) + firstLay_;
545  id.iType = (di - id.iLay + firstLay_) / layers_;
546 #ifdef EDM_ML_DEBUG
547  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << hi << " O/P " << id.zSide << ":" << id.iType << ":"
548  << id.iLay << ":" << id.iSec1 << ":" << id.iCell1;
549 #endif
550  } else {
551  id.iSec2 = (di % waferMax_) - waferOff_;
552  di = (di - id.iSec2 - waferOff_) / waferMax_;
553  id.iSec1 = (di % waferMax_) - waferOff_;
554  di = (di - id.iSec1 - waferOff_) / waferMax_;
555  id.iLay = (di % layers_) + 1;
556  id.iType = (di - id.iLay + 1) / layers_;
557 #ifdef EDM_ML_DEBUG
558  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << hi << " O/P " << id.zSide << ":" << id.iType << ":"
559  << id.iLay << ":" << id.iSec1 << ":" << id.iSec2;
560 #endif
561  }
562  }
563  return id;
564 }
565 
567  std::vector<DetId>& ids, int zside, int type, int lay, int iradius, int iphi) const {
568 #ifdef EDM_ML_DEBUG
569  edm::LogVerbatim("HGCalGeom") << "addHGCSCintillatorId " << zside << ":" << type << ":" << lay << ":" << iradius
570  << ":" << iphi << " ==> Validity " << hdcons_.isValidTrap(zside, lay, iradius, iphi);
571 #endif
572  if (hdcons_.isValidTrap(zside, lay, iradius, iphi)) {
573  HGCScintillatorDetId id(type, lay, zside * iradius, iphi);
574  ids.emplace_back(DetId(id));
575  }
576 }
577 
579  std::vector<DetId>& ids, int det, int zside, int type, int lay, int waferU, int waferV, int cellU, int cellV) const {
580 #ifdef EDM_ML_DEBUG
581  edm::LogVerbatim("HGCalGeom") << "addHGCSiliconId " << det << ":" << zside << ":" << type << ":" << lay << ":"
582  << waferU << ":" << waferV << ":" << cellU << ":" << cellV << " ==> Validity "
583  << hdcons_.isValidHex8(lay, waferU, waferV, cellU, cellV, false);
584 #endif
585  if (hdcons_.isValidHex8(lay, waferU, waferV, cellU, cellV, false)) {
586  if (det == static_cast<int>(ForwardSubdetector::HFNose)) {
587  HFNoseDetId id(DetId::Forward, zside, type, lay, waferU, waferV, cellU, cellV);
588  ids.emplace_back(DetId(id));
589  } else {
590  HGCSiliconDetId id((DetId::Detector)(det), zside, type, lay, waferU, waferV, cellU, cellV);
591  ids.emplace_back(DetId(id));
592  }
593  }
594 }
595 
598  if (waferHexagon6()) {
599  HGCalDetId id(startId);
600  idx.iCell1 = id.cell();
601  idx.iCell2 = 0;
602  idx.iLay = id.layer();
603  idx.iSec1 = id.wafer();
604  idx.iSec2 = 0;
605  idx.iType = id.waferType();
606  idx.zSide = id.zside();
607  idx.det = id.subdetId();
608  } else if (tileTrapezoid()) {
609  HGCScintillatorDetId id(startId);
610  idx.iCell1 = id.iphi();
611  idx.iCell2 = 0;
612  idx.iLay = id.layer();
613  idx.iSec1 = id.ietaAbs();
614  idx.iSec2 = 0;
615  idx.iType = id.type();
616  idx.zSide = id.zside();
617  idx.det = static_cast<int>(id.subdet());
619  HFNoseDetId id(startId);
620  idx.iCell1 = id.cellU();
621  idx.iCell2 = id.cellV();
622  idx.iLay = id.layer();
623  idx.iSec1 = id.waferU();
624  idx.iSec2 = id.waferV();
625  idx.iType = id.type();
626  idx.zSide = id.zside();
627  idx.det = static_cast<int>(id.subdet());
628  } else {
629  HGCSiliconDetId id(startId);
630  idx.iCell1 = id.cellU();
631  idx.iCell2 = id.cellV();
632  idx.iLay = id.layer();
633  idx.iSec1 = id.waferU();
634  idx.iSec2 = id.waferV();
635  idx.iType = id.type();
636  idx.zSide = id.zside();
637  idx.det = static_cast<int>(id.subdet());
638  }
639  return idx;
640 }
641 
643  DetId id;
644 #ifdef EDM_ML_DEBUG
645  edm::LogVerbatim("HGCalGeomX") << "Encode " << idx.det << ":" << idx.zSide << ":" << idx.iType << ":" << idx.iLay
646  << ":" << idx.iSec1 << ":" << idx.iSec2 << ":" << idx.iCell1 << ":" << idx.iCell2;
647 #endif
648  if (waferHexagon6()) {
649  id =
650  HGCalDetId((ForwardSubdetector)(idx.det), idx.zSide, idx.iLay, ((idx.iType > 0) ? 1 : 0), idx.iSec1, idx.iCell1)
651  .rawId();
652  } else if (tileTrapezoid()) {
653  HGCScintillatorDetId hid(idx.iType, idx.iLay, idx.zSide * idx.iSec1, idx.iCell1);
654  std::pair<int, int> typm = hdcons_.tileType(hid.layer(), hid.ring(), 0);
655  if (typm.first >= 0) {
656  hid.setType(typm.first);
657  hid.setSiPM(typm.second);
658  }
659  id = hid.rawId();
661  id = HFNoseDetId(idx.zSide, idx.iType, idx.iLay, idx.iSec1, idx.iSec2, idx.iCell1, idx.iCell2).rawId();
662  } else {
663  id = HGCSiliconDetId(
664  (DetId::Detector)(idx.det), idx.zSide, idx.iType, idx.iLay, idx.iSec1, idx.iSec2, idx.iCell1, idx.iCell2)
665  .rawId();
666  }
667  return id;
668 }
669 
670 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX, int nrStepsY) const { return DetId(); }
671 
672 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const { return DetId(); }
673 
675 
bool maskCell(const DetId &id, int corners) const
Log< level::Info, true > LogVerbatim
unsigned int totalGeomModules() const
Definition: HGCalTopology.h:93
HGCalGeometryMode::GeometryMode mode_
static constexpr int32_t topCorner
Definition: HGCalCell.h:62
bool tileTrapezoid() const
int32_t waferU(const int32_t index)
DetId changeXY(const DetId &id, int nrStepsX, int nrStepsY) const
move the nagivator along x, y
bool isValidHex(int lay, int mod, int cell, bool reco) const
bool valid(const DetId &id) const override
Is this a valid cell id.
bool waferHexagon6() const
static constexpr int32_t leftEdge
Definition: HGCalCell.h:54
int zside(DetId const &)
int firstLayer() const
HGCalGeometryMode::GeometryMode geomMode() const
int32_t cellType(int type, int waferU, int waferV, int iz, int fwdBack, int orient) const
ForwardSubdetector
bool isValidHex8(int lay, int waferU, int waferV, bool fullAndPart) const
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
DetId::Detector det_
static constexpr int32_t topLeftCorner
Definition: HGCalCell.h:61
int getTypeHex(int layer, int waferU, int waferV) const
int maxCells(bool reco) const
Definition: EPCuts.h:4
bool validHashIndex(uint32_t ix) const
Definition: HGCalTopology.h:89
static constexpr int32_t bottomLeftCorner
Definition: HGCalCell.h:60
virtual uint32_t detId2denseGeomId(const DetId &id) const
int getUVMax(int type) const
DecodedDetId decode(const DetId &id) const
static constexpr int32_t topRightCorner
Definition: HGCalCell.h:63
bool isValidTrap(int zside, int lay, int ieta, int iphi) const
static constexpr int32_t bottomRightEdge
Definition: HGCalCell.h:58
bool validModule(const DetId &id, int cornerMin) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
unsigned int layers(bool reco) const
uint32_t detId2denseId(const DetId &id) const override
Dense indexing.
std::pair< int, int > tileType(int layer, int ring, int phi) const
ForwardSubdetector subdet_
const HGCalDDDConstants & hdcons_
static constexpr int32_t bottomLeftEdge
Definition: HGCalCell.h:53
DetId offsetBy(const DetId startId, int nrStepsX, int nrStepsY) const
void addHGCSCintillatorId(std::vector< DetId > &ids, int zside, int type, int lay, int iradius, int iphi) const
add DetId of Scintillator and Silicon type if valid
Definition: DetId.h:17
static constexpr int32_t bottomRightCorner
Definition: HGCalCell.h:64
#define N
Definition: blowfish.cc:9
DetId switchZSide(const DetId startId) const
static constexpr int32_t centralCell
Definition: HGCalCell.h:52
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int numberCells(bool reco) const
DetId encode(const DecodedDetId &id_) const
Detector
Definition: DetId.h:24
DetId changeZ(const DetId &id, int nrStepsZ) const
move the nagivator along z
std::vector< DetId > neighbors(const DetId &id) const
static constexpr int32_t topRightEdge
Definition: HGCalCell.h:56
bool waferHexagon8() const
void addHGCSiliconId(std::vector< DetId > &ids, int det, int zside, int type, int lay, int waferU, int waferV, int cellU, int cellV) const
constexpr void setType(int type)
#define TYPELOOKUP_DATA_REG(_dataclass_)
Definition: typelookup.h:102
constexpr int layer() const
get the layer #
int32_t waferV(const int32_t index)
static constexpr int32_t rightEdge
Definition: HGCalCell.h:57
static constexpr int32_t bottomCorner
Definition: HGCalCell.h:59
unsigned int kSizeForDenseIndexing
constexpr void setSiPM(int sipm)
constexpr int ring() const
get the eta index
DetId denseId2detId(uint32_t denseId) const override
static constexpr int32_t WaferCornerMin
Definition: HGCalTypes.h:76
int modifyUV(int uv, int type1, int type2) const
Log< level::Warning, false > LogWarning
unsigned int allGeomModules() const
HGCalTopology(const HGCalDDDConstants &hdcons, int subdet)
create a new Topology
DecodedDetId geomDenseId2decId(const uint32_t &hi) const
static constexpr int32_t topLeftEdge
Definition: HGCalCell.h:55