CMS 3D CMS Logo

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