CMS 3D CMS Logo

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