CMS 3D CMS Logo

HGCalTriggerGeometryV9Imp2.cc
Go to the documentation of this file.
2 
10 
11 #include <vector>
12 #include <iostream>
13 #include <fstream>
14 #include <regex>
15 
17 public:
19 
20  void initialize(const CaloGeometry*) final;
21  void initialize(const HGCalGeometry*, const HGCalGeometry*, const HGCalGeometry*) final;
22  void reset() final;
23 
24  unsigned getTriggerCellFromCell(const unsigned) const final;
25  unsigned getModuleFromCell(const unsigned) const final;
26  unsigned getModuleFromTriggerCell(const unsigned) const final;
27 
28  geom_set getCellsFromTriggerCell(const unsigned) const final;
29  geom_set getCellsFromModule(const unsigned) const final;
30  geom_set getTriggerCellsFromModule(const unsigned) const final;
31 
32  geom_ordered_set getOrderedCellsFromModule(const unsigned) const final;
33  geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final;
34 
35  geom_set getNeighborsFromTriggerCell(const unsigned) const final;
36 
37  unsigned getLinksInModule(const unsigned module_id) const final;
38  unsigned getModuleSize(const unsigned module_id) const final;
39 
40  GlobalPoint getTriggerCellPosition(const unsigned) const final;
41  GlobalPoint getModulePosition(const unsigned) const final;
42 
43  bool validTriggerCell(const unsigned) const final;
44  bool disconnectedModule(const unsigned) const final;
45  unsigned lastTriggerLayer() const final { return last_trigger_layer_; }
46  unsigned triggerLayer(const unsigned) const final;
47 
48 private:
49  // HSc trigger cell grouping
50  unsigned hSc_triggercell_size_ = 2;
51  unsigned hSc_module_size_ = 12; // in TC units (144 TC / panel = 36 e-links)
52  unsigned hSc_links_per_module_ = 1;
53  unsigned hSc_wafers_per_module_ = 3;
54 
57 
58  // module related maps
59  std::unordered_map<unsigned, unsigned> wafer_to_module_;
60  std::unordered_multimap<unsigned, unsigned> module_to_wafers_;
61  std::unordered_map<unsigned, unsigned> links_per_module_;
62 
63  // Disconnected modules and layers
64  std::unordered_set<unsigned> disconnected_modules_;
65  std::unordered_set<unsigned> disconnected_layers_;
66  std::vector<unsigned> trigger_layers_;
67  unsigned last_trigger_layer_ = 0;
68 
69  // layer offsets
70  unsigned heOffset_ = 0;
71  unsigned totalLayers_ = 0;
72 
73  void fillMaps();
74  bool validCellId(unsigned det, unsigned cell_id) const;
75  bool validTriggerCellFromCells(const unsigned) const;
76 
77  int detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const;
78  unsigned packWaferId(int waferU, int waferV) const;
79  unsigned packLayerWaferId(unsigned layer, int waferU, int waferV) const;
80  unsigned packLayerModuleId(unsigned layer, unsigned wafer) const;
81  void unpackWaferId(unsigned wafer, int& waferU, int& waferV) const;
82 
83  unsigned layerWithOffset(unsigned) const;
84 };
85 
88  hSc_triggercell_size_(conf.getParameter<unsigned>("ScintillatorTriggerCellSize")),
89  hSc_module_size_(conf.getParameter<unsigned>("ScintillatorModuleSize")),
90  hSc_links_per_module_(conf.getParameter<unsigned>("ScintillatorLinksPerModule")),
91  l1tModulesMapping_(conf.getParameter<edm::FileInPath>("L1TModulesMapping")),
92  l1tLinksMapping_(conf.getParameter<edm::FileInPath>("L1TLinksMapping")) {
93  const unsigned ntc_per_wafer = 48;
94  hSc_wafers_per_module_ = std::round(hSc_module_size_ * hSc_module_size_ / float(ntc_per_wafer));
97  }
98  std::vector<unsigned> tmp_vector = conf.getParameter<std::vector<unsigned>>("DisconnectedModules");
99  std::move(tmp_vector.begin(), tmp_vector.end(), std::inserter(disconnected_modules_, disconnected_modules_.end()));
100  tmp_vector = conf.getParameter<std::vector<unsigned>>("DisconnectedLayers");
101  std::move(tmp_vector.begin(), tmp_vector.end(), std::inserter(disconnected_layers_, disconnected_layers_.end()));
102 }
103 
105  wafer_to_module_.clear();
106  module_to_wafers_.clear();
107 }
108 
110  throw cms::Exception("BadGeometry")
111  << "HGCalTriggerGeometryV9Imp2 geometry cannot be initialized with the V7/V8 HGCAL geometry";
112 }
113 
115  const HGCalGeometry* hgc_hsi_geometry,
116  const HGCalGeometry* hgc_hsc_geometry) {
117  setEEGeometry(hgc_ee_geometry);
118  setHSiGeometry(hgc_hsi_geometry);
119  setHScGeometry(hgc_hsc_geometry);
122  trigger_layers_.resize(totalLayers_ + 1);
123  trigger_layers_[0] = 0; // layer number 0 doesn't exist
124  unsigned trigger_layer = 1;
125  for (unsigned layer = 1; layer < trigger_layers_.size(); layer++) {
126  if (disconnected_layers_.find(layer) == disconnected_layers_.end()) {
127  // Increase trigger layer number if the layer is not disconnected
128  trigger_layers_[layer] = trigger_layer;
129  trigger_layer++;
130  } else {
131  trigger_layers_[layer] = 0;
132  }
133  }
134  last_trigger_layer_ = trigger_layer - 1;
135  fillMaps();
136 }
137 
138 unsigned HGCalTriggerGeometryV9Imp2::getTriggerCellFromCell(const unsigned cell_id) const {
139  unsigned det = DetId(cell_id).det();
140  unsigned trigger_cell_id = 0;
141  // Scintillator
142  if (det == DetId::HGCalHSc) {
143  // Very rough mapping from cells to TC
144  HGCScintillatorDetId cell_sc_id(cell_id);
145  int ieta = ((cell_sc_id.ietaAbs() - 1) / hSc_triggercell_size_ + 1) * cell_sc_id.zside();
146  int iphi = (cell_sc_id.iphi() - 1) / hSc_triggercell_size_ + 1;
147  trigger_cell_id = HGCScintillatorDetId(cell_sc_id.type(), cell_sc_id.layer(), ieta, iphi);
148  }
149  // Silicon
150  else if (det == DetId::HGCalEE || det == DetId::HGCalHSi) {
151  HGCSiliconDetId cell_si_id(cell_id);
152  trigger_cell_id = HGCalTriggerDetId(
154  cell_si_id.zside(),
155  cell_si_id.type(),
156  cell_si_id.layer(),
157  cell_si_id.waferU(),
158  cell_si_id.waferV(),
159  cell_si_id.triggerCellU(),
160  cell_si_id.triggerCellV());
161  }
162  return trigger_cell_id;
163 }
164 
165 unsigned HGCalTriggerGeometryV9Imp2::getModuleFromCell(const unsigned cell_id) const {
167 }
168 
169 unsigned HGCalTriggerGeometryV9Imp2::getModuleFromTriggerCell(const unsigned trigger_cell_id) const {
170  unsigned det = DetId(trigger_cell_id).det();
171  unsigned module = 0;
172  unsigned subdet_old = 0;
173  int zside = 0;
174  unsigned tc_type = 1;
175  unsigned layer = 0;
176  unsigned module_id = 0;
177  // Scintillator
178  if (det == DetId::HGCalHSc) {
179  HGCScintillatorDetId trigger_cell_sc_id(trigger_cell_id);
180  tc_type = trigger_cell_sc_id.type();
181  layer = trigger_cell_sc_id.layer();
182  zside = trigger_cell_sc_id.zside();
183  int ietamin = hscTopology().dddConstants().getREtaRange(layer).first;
184  int ietamin_tc = ((ietamin - 1) / hSc_triggercell_size_ + 1);
185  int ieta = ((trigger_cell_sc_id.ietaAbs() - ietamin_tc) / hSc_module_size_ + 1) * zside;
186  int iphi = (trigger_cell_sc_id.iphi() - 1) / hSc_module_size_ + 1;
187  module_id = HGCScintillatorDetId(tc_type, layer, ieta, iphi);
188  }
189  // Silicon
190  else {
191  HGCalTriggerDetId trigger_cell_trig_id(trigger_cell_id);
192  unsigned subdet = trigger_cell_trig_id.subdet();
193  subdet_old =
195  layer = trigger_cell_trig_id.layer();
196  zside = trigger_cell_trig_id.zside();
198  int waferu = trigger_cell_trig_id.waferU();
199  int waferv = trigger_cell_trig_id.waferV();
200  unsigned layer_with_offset = layerWithOffset(trigger_cell_id);
201  auto module_itr = wafer_to_module_.find(packLayerWaferId(layer_with_offset, waferu, waferv));
202  if (module_itr == wafer_to_module_.end()) {
203  throw cms::Exception("BadGeometry")
204  << trigger_cell_trig_id << "HGCalTriggerGeometry: Wafer (" << waferu << "," << waferv
205  << ") is not mapped to any trigger module. The module mapping should be modified. \n";
206  }
207  module = module_itr->second;
208  }
209  module_id =
210  HGCalDetId((ForwardSubdetector)subdet_old, zside, layer, tc_type, module, HGCalDetId::kHGCalCellMask).rawId();
211  }
212  return module_id;
213 }
214 
216  const unsigned trigger_cell_id) const {
217  DetId trigger_cell_det_id(trigger_cell_id);
218  unsigned det = trigger_cell_det_id.det();
219  geom_set cell_det_ids;
220  // Scintillator
221  if (det == DetId::HGCalHSc) {
222  HGCScintillatorDetId trigger_cell_sc_id(trigger_cell_id);
223  int ieta0 = (trigger_cell_sc_id.ietaAbs() - 1) * hSc_triggercell_size_ + 1;
224  int iphi0 = (trigger_cell_sc_id.iphi() - 1) * hSc_triggercell_size_ + 1;
225  for (int ietaAbs = ieta0; ietaAbs < ieta0 + (int)hSc_triggercell_size_; ietaAbs++) {
226  int ieta = ietaAbs * trigger_cell_sc_id.zside();
227  for (int iphi = iphi0; iphi < iphi0 + (int)hSc_triggercell_size_; iphi++) {
228  unsigned cell_id = HGCScintillatorDetId(trigger_cell_sc_id.type(), trigger_cell_sc_id.layer(), ieta, iphi);
229  if (validCellId(DetId::HGCalHSc, cell_id))
230  cell_det_ids.emplace(cell_id);
231  }
232  }
233  }
234  // Silicon
235  else {
236  HGCalTriggerDetId trigger_cell_trig_id(trigger_cell_id);
237  unsigned subdet = trigger_cell_trig_id.subdet();
240  int layer = trigger_cell_trig_id.layer();
241  int zside = trigger_cell_trig_id.zside();
242  int type = trigger_cell_trig_id.type();
243  int waferu = trigger_cell_trig_id.waferU();
244  int waferv = trigger_cell_trig_id.waferV();
245  std::vector<int> cellus = trigger_cell_trig_id.cellU();
246  std::vector<int> cellvs = trigger_cell_trig_id.cellV();
247  for (unsigned ic = 0; ic < cellus.size(); ic++) {
248  HGCSiliconDetId cell_det_id(cell_det, zside, type, layer, waferu, waferv, cellus[ic], cellvs[ic]);
249  cell_det_ids.emplace(cell_det_id.rawId());
250  }
251  }
252  }
253  return cell_det_ids;
254 }
255 
257  geom_set cell_det_ids;
258  geom_set trigger_cells = getTriggerCellsFromModule(module_id);
259  for (auto trigger_cell_id : trigger_cells) {
260  geom_set cells = getCellsFromTriggerCell(trigger_cell_id);
261  cell_det_ids.insert(cells.begin(), cells.end());
262  }
263  return cell_det_ids;
264 }
265 
267  const unsigned module_id) const {
268  geom_ordered_set cell_det_ids;
269  geom_ordered_set trigger_cells = getOrderedTriggerCellsFromModule(module_id);
270  for (auto trigger_cell_id : trigger_cells) {
271  geom_set cells = getCellsFromTriggerCell(trigger_cell_id);
272  cell_det_ids.insert(cells.begin(), cells.end());
273  }
274  return cell_det_ids;
275 }
276 
278  const unsigned module_id) const {
279  DetId module_det_id(module_id);
280  unsigned det = module_det_id.det();
281  geom_set trigger_cell_det_ids;
282  // Scintillator
283  if (det == DetId::HGCalHSc) {
284  HGCScintillatorDetId module_sc_id(module_id);
285  int ietamin = hscTopology().dddConstants().getREtaRange(module_sc_id.layer()).first;
286  int ietamin_tc = ((ietamin - 1) / hSc_triggercell_size_ + 1);
287  int ieta0 = (module_sc_id.ietaAbs() - 1) * hSc_module_size_ + ietamin_tc;
288  int iphi0 = (module_sc_id.iphi() - 1) * hSc_module_size_ + 1;
289  for (int ietaAbs = ieta0; ietaAbs < ieta0 + (int)hSc_module_size_; ietaAbs++) {
290  int ieta = ietaAbs * module_sc_id.zside();
291  for (int iphi = iphi0; iphi < iphi0 + (int)hSc_module_size_; iphi++) {
292  unsigned trigger_cell_id = HGCScintillatorDetId(module_sc_id.type(), module_sc_id.layer(), ieta, iphi);
293  if (validTriggerCellFromCells(trigger_cell_id))
294  trigger_cell_det_ids.emplace(trigger_cell_id);
295  }
296  }
297  }
298  // Silicon
299  else {
300  HGCalDetId module_si_id(module_id);
301  unsigned module = module_si_id.wafer();
302  HGCSiliconDetIdToROC tc2roc;
303  auto wafer_itrs = module_to_wafers_.equal_range(packLayerModuleId(layerWithOffset(module_id), module));
304  // loop on the wafers included in the module
305  for (auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
306  int waferu = 0;
307  int waferv = 0;
308  unpackWaferId(wafer_itr->second, waferu, waferv);
310  HGCalTriggerSubdetector subdet =
313  unsigned layer = module_si_id.layer();
314  unsigned wafer_type = detIdWaferType(det, layer, waferu, waferv);
315  int nroc = (wafer_type == HGCSiliconDetId::HGCalFine ? 6 : 3);
316  // Loop on ROCs in wafer
317  for (int roc = 1; roc <= nroc; roc++) {
318  // loop on TCs in ROC
319  auto tc_uvs = tc2roc.getTriggerId(roc, wafer_type);
320  for (const auto& tc_uv : tc_uvs) {
321  HGCalTriggerDetId trigger_cell_id(
322  subdet, module_si_id.zside(), wafer_type, layer, waferu, waferv, tc_uv.first, tc_uv.second);
323  if (validTriggerCellFromCells(trigger_cell_id))
324  trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
325  }
326  }
327  }
328  }
329  return trigger_cell_det_ids;
330 }
331 
333  const unsigned module_id) const {
334  DetId module_det_id(module_id);
335  unsigned det = module_det_id.det();
336  geom_ordered_set trigger_cell_det_ids;
337  // Scintillator
338  if (det == DetId::HGCalHSc) {
339  HGCScintillatorDetId module_sc_id(module_id);
340  int ieta0 = (module_sc_id.ietaAbs() - 1) * hSc_module_size_ + 1;
341  int iphi0 = (module_sc_id.iphi() - 1) * hSc_module_size_ + 1;
342  for (int ietaAbs = ieta0; ietaAbs < ieta0 + (int)hSc_module_size_; ietaAbs++) {
343  int ieta = ietaAbs * module_sc_id.zside();
344  for (int iphi = iphi0; iphi < iphi0 + (int)hSc_module_size_; iphi++) {
345  unsigned trigger_cell_id = HGCScintillatorDetId(module_sc_id.type(), module_sc_id.layer(), ieta, iphi);
346  if (validTriggerCellFromCells(trigger_cell_id))
347  trigger_cell_det_ids.emplace(trigger_cell_id);
348  }
349  }
350  }
351  // EE or FH
352  else {
353  HGCalDetId module_si_id(module_id);
354  unsigned module = module_si_id.wafer();
355  HGCSiliconDetIdToROC tc2roc;
356  auto wafer_itrs = module_to_wafers_.equal_range(packLayerModuleId(layerWithOffset(module_id), module));
357  // loop on the wafers included in the module
358  for (auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
359  int waferu = 0;
360  int waferv = 0;
361  unpackWaferId(wafer_itr->second, waferu, waferv);
363  HGCalTriggerSubdetector subdet =
366  unsigned layer = module_si_id.layer();
367  unsigned wafer_type = detIdWaferType(det, layer, waferu, waferv);
368  int nroc = (wafer_type == HGCSiliconDetId::HGCalFine ? 6 : 3);
369  // Loop on ROCs in wafer
370  for (int roc = 1; roc <= nroc; roc++) {
371  // loop on TCs in ROC
372  auto tc_uvs = tc2roc.getTriggerId(roc, wafer_type);
373  for (const auto& tc_uv : tc_uvs) {
374  HGCalTriggerDetId trigger_cell_id(
375  subdet, module_si_id.zside(), wafer_type, layer, waferu, waferv, tc_uv.first, tc_uv.second);
376  trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
377  }
378  }
379  }
380  }
381  return trigger_cell_det_ids;
382 }
383 
385  const unsigned trigger_cell_id) const {
386  throw cms::Exception("FeatureNotImplemented") << "Neighbor search is not implemented in HGCalTriggerGeometryV9Imp2";
387 }
388 
389 unsigned HGCalTriggerGeometryV9Imp2::getLinksInModule(const unsigned module_id) const {
390  DetId module_det_id(module_id);
391  unsigned links = 0;
392  // Scintillator
393  if (module_det_id.det() == DetId::HGCalHSc) {
394  links = hSc_links_per_module_;
395  }
396  // Silicon
397  else {
398  HGCalDetId module_det_id_si(module_id);
399  unsigned module = module_det_id_si.wafer();
400  unsigned layer = layerWithOffset(module_id);
401  const unsigned sector0_mask = 0x7F;
402  module = (module & sector0_mask);
403  links = links_per_module_.at(packLayerModuleId(layer, module));
404  }
405  return links;
406 }
407 
408 unsigned HGCalTriggerGeometryV9Imp2::getModuleSize(const unsigned module_id) const {
409  DetId module_det_id(module_id);
410  unsigned nWafers = 1;
411  // Scintillator
412  if (module_det_id.det() == DetId::HGCalHSc) {
413  nWafers = hSc_wafers_per_module_;
414  }
415  // Silicon
416  else {
417  HGCalDetId module_det_id_si(module_id);
418  unsigned module = module_det_id_si.wafer();
419  unsigned layer = layerWithOffset(module_id);
420  nWafers = module_to_wafers_.count(packLayerModuleId(layer, module));
421  }
422  return nWafers;
423 }
424 
425 GlobalPoint HGCalTriggerGeometryV9Imp2::getTriggerCellPosition(const unsigned trigger_cell_det_id) const {
426  unsigned det = DetId(trigger_cell_det_id).det();
427  // Position: barycenter of the trigger cell.
428  Basic3DVector<float> triggerCellVector(0., 0., 0.);
429  const auto cell_ids = getCellsFromTriggerCell(trigger_cell_det_id);
430  // Scintillator
431  if (det == DetId::HGCalHSc) {
432  for (const auto& cell : cell_ids) {
433  triggerCellVector += hscGeometry()->getPosition(cell).basicVector();
434  }
435  }
436  // Silicon
437  else {
438  for (const auto& cell : cell_ids) {
439  HGCSiliconDetId cellDetId(cell);
440  triggerCellVector += (cellDetId.det() == DetId::HGCalEE ? eeGeometry()->getPosition(cellDetId)
441  : hsiGeometry()->getPosition(cellDetId))
442  .basicVector();
443  }
444  }
445  return GlobalPoint(triggerCellVector / cell_ids.size());
446 }
447 
448 GlobalPoint HGCalTriggerGeometryV9Imp2::getModulePosition(const unsigned module_det_id) const {
449  unsigned det = DetId(module_det_id).det();
450  // Position: barycenter of the module.
451  Basic3DVector<float> moduleVector(0., 0., 0.);
452  const auto cell_ids = getCellsFromModule(module_det_id);
453  // Scintillator
454  if (det == DetId::HGCalHSc) {
455  for (const auto& cell : cell_ids) {
456  moduleVector += hscGeometry()->getPosition(cell).basicVector();
457  }
458  }
459  // Silicon
460  else {
461  for (const auto& cell : cell_ids) {
462  HGCSiliconDetId cellDetId(cell);
463  moduleVector += (cellDetId.det() == DetId::HGCalEE ? eeGeometry()->getPosition(cellDetId)
464  : hsiGeometry()->getPosition(cellDetId))
465  .basicVector();
466  }
467  }
468  return GlobalPoint(moduleVector / cell_ids.size());
469 }
470 
472  // read module mapping file
473  std::ifstream l1tModulesMappingStream(l1tModulesMapping_.fullPath());
474  if (!l1tModulesMappingStream.is_open()) {
475  throw cms::Exception("MissingDataFile") << "Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
476  }
477  short waferu = 0;
478  short waferv = 0;
479  short module = 0;
480  short layer = 0;
481  for (; l1tModulesMappingStream >> layer >> waferu >> waferv >> module;) {
482  wafer_to_module_.emplace(packLayerWaferId(layer, waferu, waferv), module);
483  module_to_wafers_.emplace(packLayerModuleId(layer, module), packWaferId(waferu, waferv));
484  }
485  if (!l1tModulesMappingStream.eof()) {
486  throw cms::Exception("BadGeometryFile")
487  << "Error reading L1TModulesMapping '" << layer << " " << waferu << " " << waferv << " " << module << "' \n";
488  }
489  l1tModulesMappingStream.close();
490  // read links mapping file
491  std::ifstream l1tLinksMappingStream(l1tLinksMapping_.fullPath());
492  if (!l1tLinksMappingStream.is_open()) {
493  throw cms::Exception("MissingDataFile") << "Cannot open HGCalTriggerGeometry L1TLinksMapping file\n";
494  }
495  short links = 0;
496  for (; l1tLinksMappingStream >> layer >> module >> links;) {
497  if (module_to_wafers_.find(packLayerModuleId(layer, module)) == module_to_wafers_.end()) {
498  links = 0;
499  }
500  links_per_module_.emplace(packLayerModuleId(layer, module), links);
501  }
502  if (!l1tLinksMappingStream.eof()) {
503  throw cms::Exception("BadGeometryFile")
504  << "Error reading L1TLinksMapping '" << layer << " " << module << " " << links << "' \n";
505  }
506  l1tLinksMappingStream.close();
507 }
508 
509 unsigned HGCalTriggerGeometryV9Imp2::packWaferId(int waferU, int waferV) const {
510  unsigned packed_value = 0;
511  unsigned waferUsign = (waferU >= 0) ? 0 : 1;
512  unsigned waferVsign = (waferV >= 0) ? 0 : 1;
517  return packed_value;
518 }
519 
520 unsigned HGCalTriggerGeometryV9Imp2::packLayerWaferId(unsigned layer, int waferU, int waferV) const {
521  unsigned packed_value = 0;
522  unsigned subdet = ForwardSubdetector::HGCEE;
523  if (layer > heOffset_) {
524  layer -= heOffset_;
526  }
527  unsigned waferUsign = (waferU >= 0) ? 0 : 1;
528  unsigned waferVsign = (waferV >= 0) ? 0 : 1;
534  packed_value |= ((subdet & DetId::kSubdetMask) << DetId::kSubdetOffset);
535  return packed_value;
536 }
537 
538 unsigned HGCalTriggerGeometryV9Imp2::packLayerModuleId(unsigned layer, unsigned module) const {
539  unsigned packed_value = 0;
540  unsigned subdet = ForwardSubdetector::HGCEE;
541  if (layer > heOffset_) {
542  layer -= heOffset_;
544  }
545  packed_value |= ((layer & HGCalDetId::kHGCalLayerMask) << HGCalDetId::kHGCalLayerOffset);
546  packed_value |= ((module & HGCalDetId::kHGCalWaferMask) << HGCalDetId::kHGCalWaferOffset);
547  packed_value |= ((subdet & DetId::kSubdetMask) << DetId::kSubdetOffset);
548  return packed_value;
549 }
550 
551 void HGCalTriggerGeometryV9Imp2::unpackWaferId(unsigned wafer, int& waferU, int& waferV) const {
555  : waferUAbs);
557  : waferVAbs);
558 }
559 
560 bool HGCalTriggerGeometryV9Imp2::validTriggerCell(const unsigned trigger_cell_id) const {
561  return validTriggerCellFromCells(trigger_cell_id);
562 }
563 
564 bool HGCalTriggerGeometryV9Imp2::disconnectedModule(const unsigned module_id) const {
565  bool disconnected = false;
566  if (disconnected_modules_.find(HGCalDetId(module_id).wafer()) != disconnected_modules_.end())
567  disconnected = true;
568  if (disconnected_layers_.find(layerWithOffset(module_id)) != disconnected_layers_.end())
569  disconnected = true;
570  return disconnected;
571 }
572 
573 unsigned HGCalTriggerGeometryV9Imp2::triggerLayer(const unsigned id) const {
574  unsigned layer = layerWithOffset(id);
575  if (layer >= trigger_layers_.size())
576  return 0;
577  return trigger_layers_[layer];
578 }
579 
580 bool HGCalTriggerGeometryV9Imp2::validTriggerCellFromCells(const unsigned trigger_cell_id) const {
581  // Check the validity of a trigger cell with the
582  // validity of the cells. One valid cell in the
583  // trigger cell is enough to make the trigger cell
584  // valid.
585  const geom_set cells = getCellsFromTriggerCell(trigger_cell_id);
586  bool is_valid = false;
587  for (const auto cell_id : cells) {
588  unsigned det = DetId(cell_id).det();
589  is_valid |= validCellId(det, cell_id);
590  if (is_valid)
591  break;
592  }
593  return is_valid;
594 }
595 
596 bool HGCalTriggerGeometryV9Imp2::validCellId(unsigned subdet, unsigned cell_id) const {
597  bool is_valid = false;
598  switch (subdet) {
599  case DetId::HGCalEE:
600  is_valid = eeTopology().valid(cell_id);
601  break;
602  case DetId::HGCalHSi:
603  is_valid = hsiTopology().valid(cell_id);
604  break;
605  case DetId::HGCalHSc:
606  is_valid = hscTopology().valid(cell_id);
607  break;
608  default:
609  is_valid = false;
610  break;
611  }
612  return is_valid;
613 }
614 
615 int HGCalTriggerGeometryV9Imp2::detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const {
616  int wafer_type = 0;
617  switch (det) {
618  case DetId::HGCalEE:
619  wafer_type = eeTopology().dddConstants().getTypeHex(layer, waferU, waferV);
620  break;
621  case DetId::HGCalHSi:
622  wafer_type = hsiTopology().dddConstants().getTypeHex(layer, waferU, waferV);
623  break;
624  default:
625  break;
626  };
627  return wafer_type;
628 }
629 
630 unsigned HGCalTriggerGeometryV9Imp2::layerWithOffset(unsigned id) const {
631  unsigned det = DetId(id).det();
632  unsigned layer = 0;
633  if (det == DetId::HGCalTrigger) {
634  unsigned subdet = HGCalTriggerDetId(id).subdet();
636  layer = HGCalTriggerDetId(id).layer();
637  } else if (subdet == HGCalTriggerSubdetector::HGCalHSiTrigger) {
638  layer = heOffset_ + HGCalTriggerDetId(id).layer();
639  }
640  } else if (det == DetId::HGCalHSc) {
641  layer = heOffset_ + HGCScintillatorDetId(id).layer();
642  } else if (det == DetId::Forward) {
643  unsigned subdet = HGCalDetId(id).subdetId();
644  if (subdet == ForwardSubdetector::HGCEE) {
645  layer = HGCalDetId(id).layer();
646  } else if (subdet == ForwardSubdetector::HGCHEF || subdet == ForwardSubdetector::HGCHEB) {
647  layer = heOffset_ + HGCalDetId(id).layer();
648  }
649  }
650  return layer;
651 }
652 
HGCalTriggerSubdetector
unsigned getModuleFromCell(const unsigned) const final
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
static const int kHGCalWaferVOffset
bool validCellId(unsigned det, unsigned cell_id) const
geom_set getNeighborsFromTriggerCell(const unsigned) const final
unsigned lastTriggerLayer() const final
static const int kHGCalLayerOffset
Definition: HGCalDetId.h:16
unsigned packWaferId(int waferU, int waferV) const
HGCalTriggerSubdetector subdet() const
get the subdetector
int detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const
static const int kHGCalLayerMask
Definition: HGCalDetId.h:17
void setEEGeometry(const HGCalGeometry *geom)
unsigned triggerLayer(const unsigned) const final
bool is_valid(const Digi &d)
Definition: GenericDigi.h:64
GlobalPoint getTriggerCellPosition(const unsigned) const final
int waferU() const
std::vector< unsigned > trigger_layers_
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
static const int kHGCalWaferVSignOffset
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int getTypeHex(int layer, int waferU, int waferV) const
std::unordered_map< unsigned, unsigned > links_per_module_
int type() const
get the type
GlobalPoint getPosition(const DetId &id) const
int zside() const
get the z-side of the cell (1/-1)
std::unordered_map< unsigned, unsigned > wafer_to_module_
int zside() const
get the z-side of the cell (1/-1)
int zside(DetId const &)
unsigned getModuleSize(const unsigned module_id) const final
static const int kSubdetOffset
Definition: DetId.h:22
const HGCalTopology & hsiTopology() const
void setHSiGeometry(const HGCalGeometry *geom)
ForwardSubdetector
int type() const
get the type
unsigned getTriggerCellFromCell(const unsigned) const final
std::vector< std::pair< int, int > > getTriggerId(int roc, int type) const
int layer() const
get the layer #
static const int kHGCalCellMask
Definition: HGCalDetId.h:11
void initialize(const CaloGeometry *) final
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
Definition: HGCalDetId.h:49
static const int kSubdetMask
Definition: DetId.h:20
int type() const
get the type
geom_set getCellsFromModule(const unsigned) const final
int layer() const
get the layer #
void unpackWaferId(unsigned wafer, int &waferU, int &waferV) const
int waferV() const
std::unordered_set< unsigned > disconnected_modules_
unsigned packLayerModuleId(unsigned layer, unsigned wafer) const
geom_set getCellsFromTriggerCell(const unsigned) const final
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
HGCalTriggerGeometryV9Imp2(const edm::ParameterSet &conf)
std::vector< int > cellV() const
void setHScGeometry(const HGCalGeometry *geom)
geom_set getTriggerCellsFromModule(const unsigned) const final
int iphi() const
get the phi index
unsigned getLinksInModule(const unsigned module_id) const final
int wafer() const
get the wafer #
Definition: HGCalDetId.h:40
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
std::pair< int, int > getREtaRange(int lay) const
unsigned getModuleFromTriggerCell(const unsigned) const final
bool disconnectedModule(const unsigned) const final
static const int kHGCalLayerMask
const HGCalGeometry * hsiGeometry() const
GlobalPoint getModulePosition(const unsigned) const final
Definition: DetId.h:17
static const int kHGCalWaferVMask
static const int kHGCalWaferUSignMask
static const int kHGCalWaferUMask
const HGCalDDDConstants & dddConstants() const
Definition: HGCalTopology.h:96
const HGCalGeometry * hscGeometry() const
const HGCalTopology & hscTopology() const
static const int kHGCalWaferVSignMask
Detector
Definition: DetId.h:24
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
static const int kHGCalWaferOffset
Definition: HGCalDetId.h:12
std::set< unsigned > geom_ordered_set
static const int kHGCalLayerOffset
int layer() const
get the layer #
int triggerCellU() const
std::unordered_set< unsigned > disconnected_layers_
bool validTriggerCell(const unsigned) const final
std::vector< int > cellU() const
HLT enums.
int zside() const
get the z-side of the cell (1/-1)
std::unordered_set< unsigned > geom_set
std::unordered_multimap< unsigned, unsigned > module_to_wafers_
int triggerCellV() const
std::string fullPath() const
Definition: FileInPath.cc:163
unsigned layerWithOffset(unsigned) const
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned packLayerWaferId(unsigned layer, int waferU, int waferV) const
static const int kHGCalWaferUOffset
bool valid(const DetId &id) const override
Is this a valid cell id.
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
Definition: vlib.h:198
static const int kHGCalWaferUSignOffset
bool validTriggerCellFromCells(const unsigned) const
def move(src, dest)
Definition: eostools.py:511
int layer() const
get the layer #
Definition: HGCalDetId.h:46
static const int kHGCalWaferMask
Definition: HGCalDetId.h:13
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46