CMS 3D CMS Logo

HGCalTopology.cc
Go to the documentation of this file.
8 
9 //#define EDM_ML_DEBUG
10 
12  int det) : hdcons_(hdcons) {
13 
15  layers_ = hdcons_.layers(true);
16  cells_ = hdcons_.maxCells(true);
20  waferMax_ = 2*waferOff_ + 1;
26  subdet_ = (ForwardSubdetector)(det);
28  types_ = 2;
29  } else if (det == (int)(DetId::Forward)) {
31  subdet_ = HFNose;
33  types_ = 3;
34  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
35  det_ = (DetId::Detector)(det);
38  types_ = 2;
39  } else {
40  det_ = (DetId::Detector)(det);
43  types_ = 3;
44  }
45  kSizeForDenseIndexing = (unsigned int)(2*kHGhalf_);
46 #ifdef EDM_ML_DEBUG
47  edm::LogVerbatim("HGCalGeom") << "HGCalTopology initialized for detector "
48  << det_ << ":" << subdet_ << " having "
49  << sectors_ << " Sectors, " << layers_
50  << " Layers from " << firstLay_ << ", "
51  << cells_ << " cells and total channels "
52  << kSizeForDenseIndexing << ":"
53  << (2*kHGeomHalf_) << std::endl;
54 #endif
55 }
56 
57 unsigned int HGCalTopology::allGeomModules() const {
58  return ((mode_ == HGCalGeometryMode::Trapezoid) ?
59  (unsigned int)(2*hdcons_.numberCells(true)) :
60  (unsigned int)(2*hdcons_.wafers()));
61 }
62 
63 std::vector<DetId> HGCalTopology::neighbors(const DetId& idin) const {
64  std::vector<DetId> ids;
68  HGCalDDDConstants::CellType celltype = hdcons_.cellType(id.iType,id.iCell1,
69  id.iCell2);
70 #ifdef EDM_ML_DEBUG
71  edm::LogVerbatim("HGCalGeom") << "Type:WaferU:WaferV " << id.iType << ":"
72  << id.iCell1 << ":" << id.iCell2
73  << " CellType " << celltype;
74 #endif
75  switch (celltype) {
77  // cell within the wafer
78 #ifdef EDM_ML_DEBUG
79  edm::LogVerbatim("HGCalGeom") << "Cell Type 0";
80 #endif
81  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
82  id.iCell1+1,id.iCell2);
83  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
84  id.iCell1,id.iCell2-1);
85  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
86  id.iCell1-1,id.iCell2-1);
87  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
88  id.iCell1-1,id.iCell2);
89  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
90  id.iCell1,id.iCell2+1);
91  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
92  id.iCell1+1,id.iCell2+1);
93  break;
94  }
96  // bottom left edge
97  int wu1(id.iSec1), wv1(id.iSec2-1);
98  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
99  int N1 = hdcons_.getUVMax(t1);
100  int v1 = hdcons_.modifyUV(id.iCell2,id.iType,t1);
101 #ifdef EDM_ML_DEBUG
102  edm::LogVerbatim("HGCalGeom") << "Cell Type 1 " << ":" << wu1 << ":"
103  << wv1 << ":" << t1 << ":" << N1 << ":"
104  << v1;
105 #endif
106  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
107  id.iCell1+1,id.iCell2);
108  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
109  id.iCell1,id.iCell2-1);
110  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,2*N1-1,v1+N1-1);
111  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,2*N1-1,v1+N1);
112  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
113  id.iCell1,id.iCell2+1);
114  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
115  id.iCell1+1,id.iCell2+1);
116  break;
117  }
119  // left edege
120  int wu1(id.iSec1+1), wv1(id.iSec2);
121  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
122  int N1 = hdcons_.getUVMax(t1);
123  int u1 = hdcons_.modifyUV(id.iCell1,id.iType,t1);
124 #ifdef EDM_ML_DEBUG
125  edm::LogVerbatim("HGCalGeom") << "Cell Type 2 " << ":" << wu1 << ":"
126  << wv1 << ":" << t1 << ":" << N1 << ":"
127  << u1;
128 #endif
129  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
130  id.iCell1+1,id.iCell2);
131  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1+N1, 2*N1-1);
132  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1+N1-1,2*N1-1);
133  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
134  id.iCell1-1,id.iCell2);
135  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
136  id.iCell1,id.iCell2+1);
137  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
138  id.iCell1+1,id.iCell2+1);
139  break;
140  }
142  // top left edge
143  int wu1(id.iSec1+1), wv1(id.iSec2+1);
144  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
145  int N1 = hdcons_.getUVMax(t1);
146  int v1 = hdcons_.modifyUV(id.iCell2,id.iType,t1);
147 #ifdef EDM_ML_DEBUG
148  edm::LogVerbatim("HGCalGeom") << "Cell Type 3 " << ":" << wu1 << ":"
149  << wv1 << ":" << t1 << ":" << N1 << ":"
150  << v1;
151 #endif
152  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,v1+1,v1+N1);
153  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,v1,v1+N1-1);
154  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
155  id.iCell1-1,id.iCell2-1);
156  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
157  id.iCell1-1,id.iCell2);
158  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
159  id.iCell1,id.iCell2+1);
160  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
161  id.iCell1+1,id.iCell2+1);
162  break;
163  }
165  // top right edge
166  int wu1(id.iSec1), wv1(id.iSec2+1);
167  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
168  int N1 = hdcons_.getUVMax(t1);
169  int v1 = hdcons_.modifyUV(id.iCell2,id.iType,t1);
170 #ifdef EDM_ML_DEBUG
171  edm::LogVerbatim("HGCalGeom") << "Cell Type 4 " << ":" << wu1 << ":"
172  << wv1 << ":" << t1 << ":" << N1 << ":"
173  << v1;
174 #endif
175  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,0,v1-N1);
176  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
177  id.iCell1,id.iCell2-1);
178  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
179  id.iCell1-1,id.iCell2-1);
180  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
181  id.iCell1-1,id.iCell2);
182  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
183  id.iCell1,id.iCell2+1);
184  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,0,v1-N1+1);
185  break;
186  }
188  // right edge
189  int wu1(id.iSec1-1), wv1(id.iSec2);
190  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
191  int N1 = hdcons_.getUVMax(t1);
192  int u1 = hdcons_.modifyUV(id.iCell1,id.iType,t1);
193 #ifdef EDM_ML_DEBUG
194  edm::LogVerbatim("HGCalGeom") << "Cell Type 5 " << ":" << wu1 << ":"
195  << wv1 << ":" << t1 << ":" << N1 << ":"
196  << u1;
197 #endif
198  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
199  id.iCell1+1,id.iCell2);
200  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
201  id.iCell1,id.iCell2-1);
202  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
203  id.iCell1-1,id.iCell2-1);
204  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
205  id.iCell1-1,id.iCell2);
206  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1-N1,0);
207  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1-N1+1,0);
208  break;
209  }
211  // bottom right edge
212  int wu1(id.iSec1-1), wv1(id.iSec2-1);
213  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
214  int N1 = hdcons_.getUVMax(t1);
215  int u1 = hdcons_.modifyUV(id.iCell1,id.iType,t1);
216 #ifdef EDM_ML_DEBUG
217  edm::LogVerbatim("HGCalGeom") << "Cell Type 6 " << ":" << wu1 << ":"
218  << wv1 << ":" << t1 << ":" << N1 << ":"
219  << u1;
220 #endif
221  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
222  id.iCell1+1,id.iCell2);
223  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
224  id.iCell1,id.iCell2-1);
225  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
226  id.iCell1-1,id.iCell2-1);
227  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1+N1-1,u1-1);
228  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1+N1,u1);
229  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
230  id.iCell1+1,id.iCell2+1);
231  break;
232  }
234  // bottom corner
235  int wu1(id.iSec1), wv1(id.iSec2-1);
236  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
237  int N1 = hdcons_.getUVMax(t1);
238  int v1 = hdcons_.modifyUV(id.iCell2,id.iType,t1);
239  int wu2(id.iSec1-1), wv2(id.iSec2-1);
240  int t2 = hdcons_.getTypeHex(id.iLay,wu2,wv2);
241  int N2 = hdcons_.getUVMax(t2);
242  int u2 = hdcons_.modifyUV(id.iCell1,id.iType,t2);
243 #ifdef EDM_ML_DEBUG
244  edm::LogVerbatim("HGCalGeom") << "Cell Type 11 " << ":" << wu1 << ":"
245  << wv1 << ":" << t1 << ":" << N1 << ":"
246  << v1 << ":" << t2 << ":" << N2 << ":"
247  << u2;
248 #endif
249  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
250  id.iCell1+1,id.iCell2);
251  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
252  id.iCell1,id.iCell2-1);
253  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,2*N1-1,v1+N1-1);
254  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,2*N1-1,v1+N1);
255  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,u2+N2,u2);
256  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
257  id.iCell1+1,id.iCell2+1);
258  break;
259  }
261  // bottom left corner
262  int wu1(id.iSec1+1), wv1(id.iSec2);
263  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
264  int N1 = hdcons_.getUVMax(t1);
265  int u1 = hdcons_.modifyUV(id.iCell1,id.iType,t1);
266  int wu2(id.iSec1), wv2(id.iSec2-1);
267  int t2 = hdcons_.getTypeHex(id.iLay,wu2,wv2);
268  int N2 = hdcons_.getUVMax(t2);
269  int v2 = hdcons_.modifyUV(id.iCell2,id.iType,t2);
270 #ifdef EDM_ML_DEBUG
271  edm::LogVerbatim("HGCalGeom") << "Cell Type 12 " << ":" << wu1 << ":"
272  << wv1 << ":" << t1 << ":" << N1 << ":"
273  << u1 << ":" << t2 << ":" << N2 << ":"
274  << v2;
275 #endif
276  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
277  id.iCell1+1,id.iCell2);
278  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1+N1,2*N1-1);
279  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,2*N2-1,v2+N2-1);
280  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,2*N2-1,v2+N2);
281  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
282  id.iCell1,id.iCell2+1);
283  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
284  id.iCell1+1,id.iCell2+1);
285  break;
286  }
288  // top left corner
289  int wu1(id.iSec1+1), wv1(id.iSec2+1);
290  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
291  int N1 = hdcons_.getUVMax(t1);
292  int v1 = hdcons_.modifyUV(id.iCell2,id.iType,t1);
293  int wu2(id.iSec1+1), wv2(id.iSec2);
294  int t2 = hdcons_.getTypeHex(id.iLay,wu2,wv2);
295  int N2 = hdcons_.getUVMax(t2);
296  int u2 = hdcons_.modifyUV(id.iCell1,id.iType,t2);
297 #ifdef EDM_ML_DEBUG
298  edm::LogVerbatim("HGCalGeom") << "Cell Type 13 " << ":" << wu1 << ":"
299  << wv1 << ":" << t1 << ":" << N1 << ":"
300  << v1 << ":" << t2 << ":" << N2 << ":"
301  << u2;
302 #endif
303  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,v1+1,N1+v1);
304  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,v1,N1+v1-1);
305  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,u2+N2-1,2*N2-1);
306  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
307  id.iCell1-1,id.iCell2);
308  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
309  id.iCell1,id.iCell2+1);
310  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
311  id.iCell1+1,id.iCell2+1);
312  break;
313  }
315  // top corner
316  int wu1(id.iSec1+1), wv1(id.iSec2+1);
317  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
318  int N1 = hdcons_.getUVMax(t1);
319  int v1 = hdcons_.modifyUV(id.iCell2,id.iType,t1);
320  int wu2(id.iSec1), wv2(id.iSec2+1);
321  int t2 = hdcons_.getTypeHex(id.iLay,wu2,wv2);
322  int N2 = hdcons_.getUVMax(t2);
323  int v2 = hdcons_.modifyUV(id.iCell2,id.iType,t2);
324 #ifdef EDM_ML_DEBUG
325  edm::LogVerbatim("HGCalGeom") << "Cell Type 14 " << ":" << wu1 << ":"
326  << wv1 << ":" << t1 << ":" << N1 << ":"
327  << v1 << ":" << t2 << ":" << N2 << ":"
328  << v2;
329 #endif
330  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,v1+1,v1+N1);
331  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,v1,v1+N1-1);
332  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
333  id.iCell1-1,id.iCell2-1);
334  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
335  id.iCell1-1,id.iCell2);
336  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
337  id.iCell1,id.iCell2+1);
338  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,0,v2-N2+1);
339  break;
340  }
342  // top right corner
343  int wu1(id.iSec1), wv1(id.iSec2+1);
344  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
345  int N1 = hdcons_.getUVMax(t1);
346  int v1 = hdcons_.modifyUV(id.iCell2,id.iType,t1);
347  int wu2(id.iSec1-1), wv2(id.iSec2);
348  int t2 = hdcons_.getTypeHex(id.iLay,wu2,wv2);
349  int N2 = hdcons_.getUVMax(t2);
350  int u2 = hdcons_.modifyUV(id.iCell1,id.iType,t2);
351 #ifdef EDM_ML_DEBUG
352  edm::LogVerbatim("HGCalGeom") << "Cell Type 15 " << ":" << wu1 << ":"
353  << wv1 << ":" << t1 << ":" << N1 << ":"
354  << v1 << ":" << t2 << ":" << N2 << ":"
355  << u2;
356 #endif
357  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,0,v1-N1);
358  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
359  id.iCell1,id.iCell2-1);
360  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
361  id.iCell1-1,id.iCell2-1);
362  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
363  id.iCell1-1,id.iCell2);
364  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,u2-N2,0);
365  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,u2-N2+1,0);
366  break;
367  }
369  // bottom right corner
370  int wu1(id.iSec1-1), wv1(id.iSec2-1);
371  int t1 = hdcons_.getTypeHex(id.iLay,wu1,wv1);
372  int N1 = hdcons_.getUVMax(t1);
373  int u1 = hdcons_.modifyUV(id.iCell1,id.iType,t1);
374  int wu2(id.iSec1-1), wv2(id.iSec2);
375  int t2 = hdcons_.getTypeHex(id.iLay,wu2,wv2);
376  int N2 = hdcons_.getUVMax(t2);
377  int u2 = hdcons_.modifyUV(id.iCell1,id.iType,t2);
378 #ifdef EDM_ML_DEBUG
379  edm::LogVerbatim("HGCalGeom") << "Cell Type 16 " << ":" << wu1 << ":"
380  << wv1 << ":" << t1 << ":" << N1 << ":"
381  << u1 << ":" << t2 << ":" << N2 << ":"
382  << u2;
383 #endif
384  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
385  id.iCell1+1,id.iCell2);
386  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
387  id.iCell1,id.iCell2-1);
388  addHGCSiliconId(ids,id.det,id.zSide,id.iType,id.iLay,id.iSec1,id.iSec2,
389  id.iCell1-1,id.iCell2-1);
390  addHGCSiliconId(ids,id.det,id.zSide,t1,id.iLay,wu1,wv1,u1+N1-1,u1-1);
391  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,u2-N2,0);
392  addHGCSiliconId(ids,id.det,id.zSide,t2,id.iLay,wu2,wv2,u2-N2+1,0);
393  break;
394  }
395  default:
396  // Not valid u, v
397  int N = hdcons_.getUVMax(id.iType);
398  edm::LogWarning("HGCalGeom") << "u:v " << id.iCell1 << ":" << id.iCell2
399  << " Tests " << (id.iCell1 > 2*N-1) << ":"
400  << (id.iCell2 > 2*N-1) << ":"
401  << (id.iCell2 >= (id.iCell1+N)) << ":"
402  << (id.iCell1 > (id.iCell2+N)) << " ERROR";
403  }
404  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
405  int iphi1 = (id.iCell1 > 1) ? id.iCell1-1 : hdcons_.getUVMax(id.iType);
406  int iphi2 = (id.iCell1 < hdcons_.getUVMax(id.iType)) ? id.iCell1+1 : 1;
407  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1-1,id.iCell1);
408  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1-1,iphi1);
409  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1,iphi1);
410  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1+1,iphi1);
411  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1+1,id.iCell1);
412  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1+1,iphi2);
413  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1,iphi2);
414  addHGCSCintillatorId(ids,id.zSide,id.iType,id.iLay,id.iSec1-1,iphi2);
415  }
416  return ids;
417 }
418 
419 
420 uint32_t HGCalTopology::detId2denseId(const DetId& idin) const {
421 
423  uint32_t idx;
424  if ((mode_ == HGCalGeometryMode::Hexagon) ||
426  int type = (id.iType > 0) ? 1 : 0;
427  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
428  ((((id.iCell1-1)*layers_+id.iLay-1)*sectors_+
429  id.iSec1)*types_+type));
430 #ifdef EDM_ML_DEBUG
431  edm::LogVerbatim("HGCalGeom") << "Input Hex " << id.zSide << ":" << id.iLay
432  << ":" << id.iSec1 << ":" << id.iCell1
433  << ":" << id.iType << " Constants "
434  << kHGeomHalf_ << ":" << layers_ << ":"
435  << sectors_ << ":" << types_<< " o/p "
436  << idx;
437 #endif
438  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
439  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
440  ((((id.iCell1-1)*layers_+id.iLay-firstLay_)*sectors_+
441  id.iSec1-1)*types_+id.iType));
442 #ifdef EDM_ML_DEBUG
443  edm::LogVerbatim("HGCalGeom") << "Input Trap " << id.zSide << ":" << id.iLay
444  << ":" << id.iSec1 << ":" << id.iCell1
445  << ":" << id.iType << " Constants "
446  << kHGeomHalf_ << ":" << layers_ << ":"
447  << sectors_ << ":" << types_<< " o/p "
448  << idx;
449 #endif
450  } else {
451  idx = (uint32_t)(((id.zSide > 0) ? kHGhalf_ : 0) +
452  (((((id.iCell1*cellMax_+id.iCell2)*layers_+
453  id.iLay-1)*waferMax_+id.iSec1+waferOff_)*
454  waferMax_+id.iSec2+waferOff_)*types_+id.iType));
455 #ifdef EDM_ML_DEBUG
456  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << id.zSide << ":" << id.iLay
457  << ":" << id.iSec1 << ":" << id.iSec2 << ":"
458  << id.iCell1 << ":" << id.iCell2 << ":"
459  << id.iType << " Constants " << kHGeomHalf_
460  << ":" << cellMax_ << ":" << layers_ << ":"
461  << waferMax_ << ":" << waferOff_ << ":"
462  << types_<< " o/p " << idx;
463 #endif
464  }
465  return idx;
466 }
467 
469 
471  if (validHashIndex(hi)) {
472  id.zSide = ((int)(hi)<kHGhalf_ ? -1 : 1);
473  int di = ((int)(hi)%kHGhalf_);
474  if ((mode_ == HGCalGeometryMode::Hexagon) ||
476  int type = (di%types_);
477  id.iType = (type == 0 ? -1 : 1);
478  id.iSec1 = (((di-type)/types_)%sectors_);
479  id.iLay = (((((di-type)/types_)-id.iSec1+1)/sectors_)%layers_+1);
480  id.iCell1= (((((di-type)/types_)-id.iSec1+1)/sectors_-id.iLay+1)/layers_+1);
481 #ifdef EDM_ML_DEBUG
482  edm::LogVerbatim("HGCalGeom") << "Input Hex " << hi << " o/p " << id.zSide
483  << ":" << id.iLay << ":" << id.iType
484  << ":" << id.iSec1 << ":" << id.iCell1;
485 #endif
486  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
487  int type = (di%types_);
488  id.iType = type;
489  id.iSec1 = (((di-type)/types_)%sectors_)+1;
490  id.iLay = (((((di-type)/types_)-id.iSec1+1)/sectors_)%layers_+firstLay_);
491  id.iCell1= (((((di-type)/types_)-id.iSec1+1)/sectors_-id.iLay+firstLay_)/layers_+1);
492 #ifdef EDM_ML_DEBUG
493  edm::LogVerbatim("HGCalGeom") << "Input Trap " << hi << " o/p " << id.zSide
494  << ":" << id.iLay << ":" << id.iType
495  << ":" << id.iSec1 << ":" << id.iCell1;
496 #endif
497  } else {
498  int type = (di%types_);
499  id.iType = type;
500  di = (di-type)/types_;
501  id.iSec2 = (di%waferMax_)-waferOff_;
502  di = (di-id.iSec2-waferOff_)/waferMax_;
503  id.iSec1 = (di%waferMax_)-waferOff_;
504  di = (di-id.iSec1-waferOff_)/waferMax_;
505  id.iLay = (di%layers_)+1;
506  di = (di-id.iLay+1)/layers_;
507  id.iCell2 = (di%cellMax_);
508  id.iCell1 = (di-id.iCell2)/cellMax_;
509 #ifdef EDM_ML_DEBUG
510  edm::LogVerbatim("HGCalGeom") << "Input Hex8 " << hi << " o/p " << id.zSide
511  << ":" << id.iLay << ":" << id.iType
512  << ":" << id.iSec1 << ":" << id.iSec2
513  << ":" << id.iCell1 << ":" << id.iCell2;
514 #endif
515  }
516  }
517  return encode(id);
518 }
519 
520 uint32_t HGCalTopology::detId2denseGeomId(const DetId& idin) const {
521 
523  uint32_t idx;
524  if ((mode_ == HGCalGeometryMode::Hexagon) ||
526  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
527  (id.iLay-1)*sectors_+id.iSec1);
528 #ifdef EDM_ML_DEBUG
529  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << id.zSide << ":"
530  << id.iLay << ":" << id.iSec1 << ":"
531  << id.iType << " Constants " << kHGeomHalf_
532  << ":" << layers_ << ":" << sectors_
533  << " o/p " << idx;
534 #endif
535  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
536  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
537  (((id.iLay-firstLay_)*sectors_+id.iSec1-1)*cellMax_+
538  id.iCell1-1));
539 #ifdef EDM_ML_DEBUG
540  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << id.zSide << ":"
541  << id.iLay << ":" << id.iSec1 << ":"
542  << id.iCell1 << ":" << id.iType
543  << " Constants " << kHGeomHalf_ << ":"
544  << layers_ << ":" << firstLay_ << ":"
545  << sectors_ << ":" << cellMax_
546  << " o/p " << idx;
547 #endif
548  } else {
549  idx = (uint32_t)(((id.zSide > 0) ? kHGeomHalf_ : 0) +
550  (((id.iLay-1)*waferMax_+id.iSec1+waferOff_)*waferMax_+
551  id.iSec2+waferOff_));
552 #ifdef EDM_ML_DEBUG
553  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << id.zSide << ":"
554  << id.iLay << ":" << id.iSec1 << ":"
555  << id.iSec2 << ":" << id.iType
556  << " Constants " << kHGeomHalf_ << ":"
557  << layers_ << ":" << waferMax_ << ":"
558  << waferOff_ << " o/p " << idx;
559 #endif
560  }
561  return idx;
562 }
563 
564 bool HGCalTopology::valid(const DetId& idin) const {
565 
567  bool flag;
568  if ((mode_ == HGCalGeometryMode::Hexagon) ||
570  flag = (idin.det() == det_ && idin.subdetId() == (int)(subdet_) &&
571  id.iCell1 >= 0 && id.iCell1 < cells_ && id.iLay > 0 &&
572  id.iLay <= layers_ && id.iSec1 >= 0 && id.iSec1 <= sectors_);
573  if (flag) flag = hdcons_.isValidHex(id.iLay,id.iSec1,id.iCell1,true);
574  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
575  flag = ((idin.det() == det_) &&
576  hdcons_.isValidTrap(id.iLay,id.iSec1,id.iCell1));
577  } else {
578  flag = ((idin.det() == det_) &&
579  hdcons_.isValidHex8(id.iLay,id.iSec1,id.iSec2,id.iCell1,id.iCell2));
580  }
581  return flag;
582 }
583 
584 DetId HGCalTopology::offsetBy(const DetId startId, int nrStepsX,
585  int nrStepsY ) const {
586 
587  if (startId.det() == DetId::Forward && startId.subdetId() == (int)(subdet_)){
588  DetId id = changeXY(startId,nrStepsX,nrStepsY);
589  if (valid(id)) return id;
590  }
591  return DetId(0);
592 }
593 
594 DetId HGCalTopology::switchZSide(const DetId startId) const {
595 
596  HGCalTopology::DecodedDetId id_ = decode(startId);
597  id_.zSide =-id_.zSide;
598  DetId id = encode(id_);
599  if (valid(id)) return id;
600  else return DetId(0);
601 }
602 
604 
606  if (hi < totalGeomModules()) {
607  id.zSide = ((int)(hi)<kHGeomHalf_ ? -1 : 1);
608  int di = ((int)(hi)%kHGeomHalf_);
609  if ((mode_ == HGCalGeometryMode::Hexagon) ||
611  id.iSec1 = (di%sectors_);
612  di = (di-id.iSec1)/sectors_;
613  id.iLay = (di%layers_)+1;
614  id.iType = ((di-id.iLay+1)/layers_ == 0) ? -1 : 1;
615 #ifdef EDM_ML_DEBUG
616  edm::LogVerbatim("HGCalGeom") << "Geom Hex I/P " << hi << " O/P "
617  << id.zSide << ":" << id.iType << ":"
618  << id.iLay << ":" << id.iSec1;
619 #endif
620  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
621  id.iCell1 = (di%cellMax_)+1;
622  di = (di-id.iCell1+1)/cellMax_;
623  id.iSec1 = (di%sectors_)+1;
624  di = (di-id.iSec1+1)/sectors_;
625  id.iLay = (di%layers_) + firstLay_;
626  id.iType = (di-id.iLay+firstLay_)/layers_;
627 #ifdef EDM_ML_DEBUG
628  edm::LogVerbatim("HGCalGeom") << "Geom Trap I/P " << hi << " O/P "
629  << id.zSide << ":" << id.iType << ":"
630  << id.iLay << ":" << id.iSec1 << ":"
631  << id.iCell1;
632 #endif
633  } else {
634  id.iSec2 = (di%waferMax_)-waferOff_;
635  di = (di-id.iSec2-waferOff_)/waferMax_;
636  id.iSec1 = (di%waferMax_)-waferOff_;
637  di = (di-id.iSec1-waferOff_)/waferMax_;
638  id.iLay = (di%layers_)+1;
639  id.iType = (di-id.iLay+1)/layers_;
640 #ifdef EDM_ML_DEBUG
641  edm::LogVerbatim("HGCalGeom") << "Geom Hex8 I/P " << hi << " O/P "
642  << id.zSide << ":" << id.iType << ":"
643  << id.iLay << ":" << id.iSec1 << ":"
644  << id.iSec2;
645 #endif
646  }
647  }
648  return id;
649 }
650 
651 void HGCalTopology::addHGCSCintillatorId(std::vector<DetId>& ids, int zside,
652  int type, int lay, int iradius,
653  int iphi) const {
654 #ifdef EDM_ML_DEBUG
655  edm::LogVerbatim("HGCalGeom") << "addHGCSCintillatorId " << zside << ":"
656  << type << ":" << lay << ":" << iradius << ":"
657  << iphi << " ==> Validity "
658  << hdcons_.isValidTrap(lay,iradius,iphi);
659 #endif
660  if (hdcons_.isValidTrap(lay,iradius,iphi)) {
661  HGCScintillatorDetId id(type,lay,zside*iradius,iphi);
662  ids.emplace_back(DetId(id));
663  }
664 }
665 
666 void HGCalTopology::addHGCSiliconId(std::vector<DetId>& ids, int det,int zside,
667  int type, int lay, int waferU, int waferV,
668  int cellU, int cellV) const {
669 #ifdef EDM_ML_DEBUG
670  edm::LogVerbatim("HGCalGeom") << "addHGCSiliconId " << det << ":" << zside
671  << ":" << type << ":" << lay << ":" << waferU
672  << ":" << waferV << ":" << cellU << ":"
673  << cellV << " ==> Validity "
674  << hdcons_.isValidHex8(lay,waferU,waferV,cellU,cellV);
675 #endif
676  if (hdcons_.isValidHex8(lay,waferU,waferV,cellU,cellV)) {
677  HGCSiliconDetId id((DetId::Detector)(det),zside,type,lay,waferU,waferV,
678  cellU,cellV);
679  ids.emplace_back(DetId(id));
680  }
681 }
682 
684 
686  if ((mode_ == HGCalGeometryMode::Hexagon) ||
688  HGCalDetId id(startId);
689  idx.iCell1 = id.cell();
690  idx.iCell2 = 0;
691  idx.iLay = id.layer();
692  idx.iSec1 = id.wafer();
693  idx.iSec2 = 0;
694  idx.iType = id.waferType();
695  idx.zSide = id.zside();
696  idx.det = id.subdetId();
697  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
698  HGCScintillatorDetId id(startId);
699  idx.iCell1 = id.iphi();
700  idx.iCell2 = 0;
701  idx.iLay = id.layer();
702  idx.iSec1 = id.ietaAbs();
703  idx.iSec2 = 0;
704  idx.iType = id.type();
705  idx.zSide = id.zside();
706  idx.det = (int)(id.subdet());
708  HFNoseDetId id(startId);
709  idx.iCell1 = id.cellU();
710  idx.iCell2 = id.cellV();
711  idx.iLay = id.layer();
712  idx.iSec1 = id.waferU();
713  idx.iSec2 = id.waferV();
714  idx.iType = id.type();
715  idx.zSide = id.zside();
716  idx.det = (int)(id.subdet());
717  } else {
718  HGCSiliconDetId id(startId);
719  idx.iCell1 = id.cellU();
720  idx.iCell2 = id.cellV();
721  idx.iLay = id.layer();
722  idx.iSec1 = id.waferU();
723  idx.iSec2 = id.waferV();
724  idx.iType = id.type();
725  idx.zSide = id.zside();
726  idx.det = (int)(id.subdet());
727  }
728  return idx;
729 }
730 
732 
733  DetId id;
736  id = HGCalDetId((ForwardSubdetector)(idx.det),idx.zSide,idx.iLay,((idx.iType > 0) ? 1 : 0),idx.iSec1,idx.iCell1).rawId();
737  } else if (mode_ == HGCalGeometryMode::Trapezoid) {
738  id = HGCScintillatorDetId(idx.iType,idx.iLay,idx.zSide*idx.iSec1,idx.iCell1).rawId();
740  id = HFNoseDetId(idx.zSide,idx.iType,idx.iLay,idx.iSec1,idx.iSec2,idx.iCell1,idx.iCell2).rawId();
741  } else {
742  id = HGCSiliconDetId((DetId::Detector)(idx.det),idx.zSide,idx.iType,idx.iLay,idx.iSec1,idx.iSec2,idx.iCell1,idx.iCell2).rawId();
743  }
744  return id;
745 }
746 
747 DetId HGCalTopology::changeXY(const DetId& id, int nrStepsX,
748  int nrStepsY ) const {
749 
750  return DetId();
751 }
752 
753 
754 DetId HGCalTopology::changeZ(const DetId& id, int nrStepsZ) const {
755 
756  return DetId();
757 }
758 
760 
type
Definition: HCALResponse.h:21
bool isValidTrap(int lay, int ieta, int iphi) const
bool validHashIndex(uint32_t ix) const
Definition: HGCalTopology.h:97
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:50
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
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:41
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:96
DecodedDetId decode(const DetId &id) const
Definition: DetId.h:18
#define N
Definition: blowfish.cc:9
Detector
Definition: DetId.h:26
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:39