CMS 3D CMS Logo

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