CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HGCalTriggerGeometryV9Imp2.cc
Go to the documentation of this file.
10 
11 #include "oneapi/tbb/concurrent_unordered_set.h"
12 #include <fstream>
13 #include <iostream>
14 #include <regex>
15 #include <vector>
16 
18 public:
20 
21  void initialize(const HGCalGeometry*, const HGCalGeometry*, const HGCalGeometry*) final;
22  void initialize(const HGCalGeometry*, const HGCalGeometry*, const HGCalGeometry*, const HGCalGeometry*) final;
23  void reset() final;
24 
25  unsigned getTriggerCellFromCell(const unsigned) const final;
26  unsigned getModuleFromCell(const unsigned) const final;
27  unsigned getModuleFromTriggerCell(const unsigned) const final;
28 
29  geom_set getCellsFromTriggerCell(const unsigned) const final;
30  geom_set getCellsFromModule(const unsigned) const final;
31  geom_set getTriggerCellsFromModule(const unsigned) const final;
32 
33  geom_ordered_set getOrderedCellsFromModule(const unsigned) const final;
34  geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final;
35 
36  geom_set getNeighborsFromTriggerCell(const unsigned) const final;
37 
38  geom_set getStage1FpgasFromStage2Fpga(const unsigned) const final;
39  geom_set getStage2FpgasFromStage1Fpga(const unsigned) const final;
40 
41  geom_set getStage1LinksFromStage2Fpga(const unsigned) const final;
42  unsigned getStage1FpgaFromStage1Link(const unsigned) const final;
43  unsigned getStage2FpgaFromStage1Link(const unsigned) const final;
44  geom_set getStage1LinksFromStage1Fpga(const unsigned) const final;
45  geom_set getLpgbtsFromStage1Fpga(const unsigned) const final;
46  unsigned getStage1FpgaFromLpgbt(const unsigned) const final;
47  geom_set getModulesFromLpgbt(const unsigned) const final;
48  geom_set getLpgbtsFromModule(const unsigned) const final;
49  unsigned getStage1FpgaFromModule(const unsigned module_id) const final;
50 
51  unsigned getLinksInModule(const unsigned module_id) const final;
52  unsigned getModuleSize(const unsigned module_id) const final;
53 
54  GlobalPoint getTriggerCellPosition(const unsigned) const final;
55  GlobalPoint getModulePosition(const unsigned) const final;
56 
57  bool validCell(const unsigned) const final;
58  bool validTriggerCell(const unsigned) const final;
59  bool disconnectedModule(const unsigned) const final;
60  unsigned lastTriggerLayer() const final { return last_trigger_layer_; }
61  unsigned triggerLayer(const unsigned) const final;
62 
63 private:
64  // HSc trigger cell grouping
65  unsigned hSc_triggercell_size_ = 2;
66  unsigned hSc_module_size_ = 12; // in TC units (144 TC / panel = 36 e-links)
67  unsigned hSc_links_per_module_ = 1;
68  unsigned hSc_wafers_per_module_ = 3;
69 
70  unsigned sector0_mask_ = 0x7f; // 7 bits to encode module number in 60deg sector
71 
72  edm::FileInPath l1tModulesMapping_;
73  edm::FileInPath l1tLinksMapping_;
74 
75  // module related maps
76  std::unordered_map<unsigned, unsigned> wafer_to_module_;
77  std::unordered_multimap<unsigned, unsigned> module_to_wafers_;
78  std::unordered_map<unsigned, unsigned> links_per_module_;
79  mutable tbb::concurrent_unordered_set<unsigned> cache_missing_wafers_;
80 
81  // Disconnected modules and layers
82  std::unordered_set<unsigned> disconnected_modules_;
83  std::unordered_set<unsigned> disconnected_layers_;
84  std::vector<unsigned> trigger_layers_;
85  std::vector<unsigned> trigger_nose_layers_;
86  unsigned last_trigger_layer_ = 0;
87 
88  // layer offsets
89  unsigned heOffset_ = 0;
90  unsigned noseLayers_ = 0;
91  unsigned totalLayers_ = 0;
92 
93  void fillMaps();
94  bool validCellId(unsigned det, unsigned cell_id) const;
95  bool validTriggerCellFromCells(const unsigned) const;
96 
97  int detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const;
98  unsigned packWaferId(int waferU, int waferV) const;
99  unsigned packLayerWaferId(unsigned layer, int waferU, int waferV) const;
100  unsigned packLayerModuleId(unsigned layer, unsigned wafer) const;
101  void unpackWaferId(unsigned wafer, int& waferU, int& waferV) const;
102 
103  unsigned layerWithOffset(unsigned) const;
104 };
105 
107  : HGCalTriggerGeometryBase(conf),
108  hSc_triggercell_size_(conf.getParameter<unsigned>("ScintillatorTriggerCellSize")),
109  hSc_module_size_(conf.getParameter<unsigned>("ScintillatorModuleSize")),
110  hSc_links_per_module_(conf.getParameter<unsigned>("ScintillatorLinksPerModule")),
111  l1tModulesMapping_(conf.getParameter<edm::FileInPath>("L1TModulesMapping")),
112  l1tLinksMapping_(conf.getParameter<edm::FileInPath>("L1TLinksMapping")) {
113  const unsigned ntc_per_wafer = 48;
114  hSc_wafers_per_module_ = std::round(hSc_module_size_ * hSc_module_size_ / float(ntc_per_wafer));
115  if (ntc_per_wafer * hSc_wafers_per_module_ < hSc_module_size_ * hSc_module_size_) {
116  hSc_wafers_per_module_++;
117  }
118  std::vector<unsigned> tmp_vector = conf.getParameter<std::vector<unsigned>>("DisconnectedModules");
119  std::move(tmp_vector.begin(), tmp_vector.end(), std::inserter(disconnected_modules_, disconnected_modules_.end()));
120  tmp_vector = conf.getParameter<std::vector<unsigned>>("DisconnectedLayers");
121  std::move(tmp_vector.begin(), tmp_vector.end(), std::inserter(disconnected_layers_, disconnected_layers_.end()));
122 }
123 
125  wafer_to_module_.clear();
126  module_to_wafers_.clear();
127  cache_missing_wafers_.clear();
128 }
129 
131  const HGCalGeometry* hgc_hsi_geometry,
132  const HGCalGeometry* hgc_hsc_geometry) {
133  setEEGeometry(hgc_ee_geometry);
134  setHSiGeometry(hgc_hsi_geometry);
135  setHScGeometry(hgc_hsc_geometry);
138  trigger_layers_.resize(totalLayers_ + 1);
139  trigger_layers_[0] = 0; // layer number 0 doesn't exist
140  unsigned trigger_layer = 1;
141  for (unsigned layer = 1; layer < trigger_layers_.size(); layer++) {
142  if (disconnected_layers_.find(layer) == disconnected_layers_.end()) {
143  // Increase trigger layer number if the layer is not disconnected
144  trigger_layers_[layer] = trigger_layer;
145  trigger_layer++;
146  } else {
147  trigger_layers_[layer] = 0;
148  }
149  }
150  last_trigger_layer_ = trigger_layer - 1;
151  fillMaps();
152 }
153 
155  const HGCalGeometry* hgc_hsi_geometry,
156  const HGCalGeometry* hgc_hsc_geometry,
157  const HGCalGeometry* hgc_nose_geometry) {
158  setEEGeometry(hgc_ee_geometry);
159  setHSiGeometry(hgc_hsi_geometry);
160  setHScGeometry(hgc_hsc_geometry);
161  setNoseGeometry(hgc_nose_geometry);
162 
165 
166  trigger_layers_.resize(totalLayers_ + 1);
167  trigger_layers_[0] = 0; // layer number 0 doesn't exist
168  unsigned trigger_layer = 1;
169  for (unsigned layer = 1; layer < trigger_layers_.size(); layer++) {
170  if (disconnected_layers_.find(layer) == disconnected_layers_.end()) {
171  // Increase trigger layer number if the layer is not disconnected
172  trigger_layers_[layer] = trigger_layer;
173  trigger_layer++;
174  } else {
175  trigger_layers_[layer] = 0;
176  }
177  }
178  last_trigger_layer_ = trigger_layer - 1;
179  fillMaps();
180 
182 
183  trigger_nose_layers_.resize(noseLayers_ + 1);
184  trigger_nose_layers_[0] = 0; // layer number 0 doesn't exist
185  unsigned trigger_nose_layer = 1;
186  for (unsigned layer = 1; layer < trigger_nose_layers_.size(); layer++) {
187  trigger_nose_layers_[layer] = trigger_nose_layer;
188  trigger_nose_layer++;
189  }
190 }
191 
192 unsigned HGCalTriggerGeometryV9Imp2::getTriggerCellFromCell(const unsigned cell_id) const {
193  unsigned det = DetId(cell_id).det();
194  unsigned trigger_cell_id = 0;
195  // Scintillator
196  if (det == DetId::HGCalHSc) {
197  // Very rough mapping from cells to TC
198  HGCScintillatorDetId cell_sc_id(cell_id);
199  int ieta = ((cell_sc_id.ietaAbs() - 1) / hSc_triggercell_size_ + 1) * cell_sc_id.zside();
200  int iphi = (cell_sc_id.iphi() - 1) / hSc_triggercell_size_ + 1;
201  trigger_cell_id = HGCScintillatorDetId(cell_sc_id.type(), cell_sc_id.layer(), ieta, iphi);
202  }
203  // HFNose
204  else if (det == DetId::Forward && DetId(cell_id).subdetId() == ForwardSubdetector::HFNose) {
205  HFNoseDetId cell_nose_id(cell_id);
207  cell_nose_id.zside(),
208  cell_nose_id.type(),
209  cell_nose_id.layer(),
210  cell_nose_id.waferU(),
211  cell_nose_id.waferV(),
212  cell_nose_id.triggerCellU(),
213  cell_nose_id.triggerCellV());
214  }
215  // Silicon
216  else if (det == DetId::HGCalEE || det == DetId::HGCalHSi) {
217  HGCSiliconDetId cell_si_id(cell_id);
218  trigger_cell_id = HGCalTriggerDetId(
220  cell_si_id.zside(),
221  cell_si_id.type(),
222  cell_si_id.layer(),
223  cell_si_id.waferU(),
224  cell_si_id.waferV(),
225  cell_si_id.triggerCellU(),
226  cell_si_id.triggerCellV());
227  }
228  return trigger_cell_id;
229 }
230 
231 unsigned HGCalTriggerGeometryV9Imp2::getModuleFromCell(const unsigned cell_id) const {
233 }
234 
235 unsigned HGCalTriggerGeometryV9Imp2::getModuleFromTriggerCell(const unsigned trigger_cell_id) const {
236  unsigned det = DetId(trigger_cell_id).det();
237  unsigned module = 0;
238  unsigned subdet_old = 0;
239  int zside = 0;
240  unsigned tc_type = 1;
241  unsigned layer = 0;
242  unsigned module_id = 0;
243  // Scintillator
244  if (det == DetId::HGCalHSc) {
245  HGCScintillatorDetId trigger_cell_sc_id(trigger_cell_id);
246  tc_type = trigger_cell_sc_id.type();
247  layer = trigger_cell_sc_id.layer();
248  zside = trigger_cell_sc_id.zside();
249  int ietamin = hscTopology().dddConstants().getREtaRange(layer).first;
250  int ietamin_tc = ((ietamin - 1) / hSc_triggercell_size_ + 1);
251  int ieta = ((trigger_cell_sc_id.ietaAbs() - ietamin_tc) / hSc_module_size_ + 1) * zside;
252  int iphi = (trigger_cell_sc_id.iphi() - 1) / hSc_module_size_ + 1;
253  module_id = HGCScintillatorDetId(tc_type, layer, ieta, iphi);
254  }
255  // HFNose
256  else if (det == DetId::HGCalTrigger and
257  HGCalTriggerDetId(trigger_cell_id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
258  HFNoseTriggerDetId trigger_cell_trig_id(trigger_cell_id);
259  tc_type = trigger_cell_trig_id.type();
260  layer = trigger_cell_trig_id.layer();
261  zside = trigger_cell_trig_id.zside();
262  int waferu = trigger_cell_trig_id.waferU();
263  int waferv = trigger_cell_trig_id.waferV();
264 
266  module_id = hfn.getModule(HFNoseDetId(zside, layer, tc_type, waferu, waferv, 0, 0)).rawId();
267  }
268  // Silicon
269  else {
270  HGCalTriggerDetId trigger_cell_trig_id(trigger_cell_id);
271  unsigned subdet = trigger_cell_trig_id.subdet();
272  subdet_old =
274  layer = trigger_cell_trig_id.layer();
275  zside = trigger_cell_trig_id.zside();
277  int waferu = trigger_cell_trig_id.waferU();
278  int waferv = trigger_cell_trig_id.waferV();
279  unsigned layer_with_offset = layerWithOffset(trigger_cell_id);
280  unsigned packed_wafer = packLayerWaferId(layer_with_offset, waferu, waferv);
281  auto module_itr = wafer_to_module_.find(packed_wafer);
282  if (module_itr == wafer_to_module_.end()) {
283  // return missing modules as disconnected (id=0)
284  module = 0;
285  auto insert_itr = cache_missing_wafers_.emplace(packed_wafer);
286  if (insert_itr.second) {
287  edm::LogWarning("HGCalTriggerGeometry")
288  << "Found missing wafer (layer=" << layer_with_offset << " u=" << waferu << " v=" << waferv
289  << ") in trigger modules mapping";
290  }
291  } else {
292  module = module_itr->second;
293  }
294  }
295  module_id =
296  HGCalDetId((ForwardSubdetector)subdet_old, zside, layer, tc_type, module, HGCalDetId::kHGCalCellMask).rawId();
297  }
298  return module_id;
299 }
300 
302  const unsigned trigger_cell_id) const {
303  DetId trigger_cell_det_id(trigger_cell_id);
304  unsigned det = trigger_cell_det_id.det();
305  geom_set cell_det_ids;
306  // Scintillator
307  if (det == DetId::HGCalHSc) {
308  HGCScintillatorDetId trigger_cell_sc_id(trigger_cell_id);
309  int ieta0 = (trigger_cell_sc_id.ietaAbs() - 1) * hSc_triggercell_size_ + 1;
310  int iphi0 = (trigger_cell_sc_id.iphi() - 1) * hSc_triggercell_size_ + 1;
311  for (int ietaAbs = ieta0; ietaAbs < ieta0 + (int)hSc_triggercell_size_; ietaAbs++) {
312  int ieta = ietaAbs * trigger_cell_sc_id.zside();
313  for (int iphi = iphi0; iphi < iphi0 + (int)hSc_triggercell_size_; iphi++) {
314  unsigned cell_id = HGCScintillatorDetId(trigger_cell_sc_id.type(), trigger_cell_sc_id.layer(), ieta, iphi);
315  if (validCellId(DetId::HGCalHSc, cell_id))
316  cell_det_ids.emplace(cell_id);
317  }
318  }
319  }
320  // HFNose
321  else if (det == DetId::HGCalTrigger and
322  HGCalTriggerDetId(trigger_cell_id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
323  HFNoseTriggerDetId trigger_cell_nose_id(trigger_cell_id);
324  int layer = trigger_cell_nose_id.layer();
325  int zside = trigger_cell_nose_id.zside();
326  int type = trigger_cell_nose_id.type();
327  int waferu = trigger_cell_nose_id.waferU();
328  int waferv = trigger_cell_nose_id.waferV();
329  std::vector<int> cellus = trigger_cell_nose_id.cellU();
330  std::vector<int> cellvs = trigger_cell_nose_id.cellV();
331  for (unsigned ic = 0; ic < cellus.size(); ic++) {
332  HFNoseDetId cell_det_id(zside, type, layer, waferu, waferv, cellus[ic], cellvs[ic]);
333  cell_det_ids.emplace(cell_det_id);
334  }
335  }
336  // Silicon
337  else {
338  HGCalTriggerDetId trigger_cell_trig_id(trigger_cell_id);
339  unsigned subdet = trigger_cell_trig_id.subdet();
342  int layer = trigger_cell_trig_id.layer();
343  int zside = trigger_cell_trig_id.zside();
344  int type = trigger_cell_trig_id.type();
345  int waferu = trigger_cell_trig_id.waferU();
346  int waferv = trigger_cell_trig_id.waferV();
347  std::vector<int> cellus = trigger_cell_trig_id.cellU();
348  std::vector<int> cellvs = trigger_cell_trig_id.cellV();
349  for (unsigned ic = 0; ic < cellus.size(); ic++) {
350  HGCSiliconDetId cell_det_id(cell_det, zside, type, layer, waferu, waferv, cellus[ic], cellvs[ic]);
351  cell_det_ids.emplace(cell_det_id);
352  }
353  }
354  }
355  return cell_det_ids;
356 }
357 
359  geom_set cell_det_ids;
360  geom_set trigger_cells = getTriggerCellsFromModule(module_id);
361  for (auto trigger_cell_id : trigger_cells) {
362  geom_set cells = getCellsFromTriggerCell(trigger_cell_id);
363  cell_det_ids.insert(cells.begin(), cells.end());
364  }
365  return cell_det_ids;
366 }
367 
369  const unsigned module_id) const {
370  geom_ordered_set cell_det_ids;
371  geom_ordered_set trigger_cells = getOrderedTriggerCellsFromModule(module_id);
372  for (auto trigger_cell_id : trigger_cells) {
373  geom_set cells = getCellsFromTriggerCell(trigger_cell_id);
374  cell_det_ids.insert(cells.begin(), cells.end());
375  }
376  return cell_det_ids;
377 }
378 
380  const unsigned module_id) const {
381  DetId module_det_id(module_id);
382  unsigned det = module_det_id.det();
383  geom_set trigger_cell_det_ids;
384  // Scintillator
385  if (det == DetId::HGCalHSc) {
386  HGCScintillatorDetId module_sc_id(module_id);
387  int ietamin = hscTopology().dddConstants().getREtaRange(module_sc_id.layer()).first;
388  int ietamin_tc = ((ietamin - 1) / hSc_triggercell_size_ + 1);
389  int ieta0 = (module_sc_id.ietaAbs() - 1) * hSc_module_size_ + ietamin_tc;
390  int iphi0 = (module_sc_id.iphi() - 1) * hSc_module_size_ + 1;
391  for (int ietaAbs = ieta0; ietaAbs < ieta0 + (int)hSc_module_size_; ietaAbs++) {
392  int ieta = ietaAbs * module_sc_id.zside();
393  for (int iphi = iphi0; iphi < iphi0 + (int)hSc_module_size_; iphi++) {
394  unsigned trigger_cell_id = HGCScintillatorDetId(module_sc_id.type(), module_sc_id.layer(), ieta, iphi);
395  if (validTriggerCellFromCells(trigger_cell_id))
396  trigger_cell_det_ids.emplace(trigger_cell_id);
397  }
398  }
399  }
400  // HFNose
401  else if (det == DetId::Forward && module_det_id.subdetId() == ForwardSubdetector::HFNose) {
402  HFNoseDetId module_nose_id(module_id);
404  std::vector<HFNoseTriggerDetId> ids = hfn.getTriggerDetIds(module_nose_id);
405  for (auto const& idx : ids) {
406  if (validTriggerCellFromCells(idx.rawId()))
407  trigger_cell_det_ids.emplace(idx);
408  }
409  }
410  // Silicon
411  else {
412  HGCalDetId module_si_id(module_id);
413  unsigned module = module_si_id.wafer();
414  HGCSiliconDetIdToROC tc2roc;
415  auto wafer_itrs = module_to_wafers_.equal_range(packLayerModuleId(layerWithOffset(module_id), module));
416  // loop on the wafers included in the module
417  for (auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
418  int waferu = 0;
419  int waferv = 0;
420  unpackWaferId(wafer_itr->second, waferu, waferv);
422  HGCalTriggerSubdetector subdet =
425  unsigned layer = module_si_id.layer();
426  unsigned wafer_type = detIdWaferType(det, layer, waferu, waferv);
427  int nroc = (wafer_type == HGCSiliconDetId::HGCalFine ? 6 : 3);
428  // Loop on ROCs in wafer
429  for (int roc = 1; roc <= nroc; roc++) {
430  // loop on TCs in ROC
431  auto tc_uvs = tc2roc.getTriggerId(roc, wafer_type);
432  for (const auto& tc_uv : tc_uvs) {
433  HGCalTriggerDetId trigger_cell_id(
434  subdet, module_si_id.zside(), wafer_type, layer, waferu, waferv, tc_uv.first, tc_uv.second);
435  if (validTriggerCellFromCells(trigger_cell_id.rawId()))
436  trigger_cell_det_ids.emplace(trigger_cell_id);
437  }
438  }
439  }
440  }
441 
442  return trigger_cell_det_ids;
443 }
444 
446  const unsigned module_id) const {
447  DetId module_det_id(module_id);
448  unsigned det = module_det_id.det();
449  geom_ordered_set trigger_cell_det_ids;
450  // Scintillator
451  if (det == DetId::HGCalHSc) {
452  HGCScintillatorDetId module_sc_id(module_id);
453  int ieta0 = (module_sc_id.ietaAbs() - 1) * hSc_module_size_ + 1;
454  int iphi0 = (module_sc_id.iphi() - 1) * hSc_module_size_ + 1;
455  for (int ietaAbs = ieta0; ietaAbs < ieta0 + (int)hSc_module_size_; ietaAbs++) {
456  int ieta = ietaAbs * module_sc_id.zside();
457  for (int iphi = iphi0; iphi < iphi0 + (int)hSc_module_size_; iphi++) {
458  unsigned trigger_cell_id = HGCScintillatorDetId(module_sc_id.type(), module_sc_id.layer(), ieta, iphi);
459  if (validTriggerCellFromCells(trigger_cell_id))
460  trigger_cell_det_ids.emplace(trigger_cell_id);
461  }
462  }
463  }
464  // HFNose
465  else if (det == DetId::Forward && DetId(module_det_id).subdetId() == ForwardSubdetector::HFNose) {
466  HFNoseDetId module_nose_id(module_id);
468  std::vector<HFNoseTriggerDetId> ids = hfn.getTriggerDetIds(module_nose_id);
469  for (auto const& idx : ids) {
470  if (validTriggerCellFromCells(idx.rawId()))
471  trigger_cell_det_ids.emplace(idx);
472  }
473  }
474  // EE or FH
475  else {
476  HGCalDetId module_si_id(module_id);
477  unsigned module = module_si_id.wafer();
478  HGCSiliconDetIdToROC tc2roc;
479  auto wafer_itrs = module_to_wafers_.equal_range(packLayerModuleId(layerWithOffset(module_id), module));
480  // loop on the wafers included in the module
481  for (auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
482  int waferu = 0;
483  int waferv = 0;
484  unpackWaferId(wafer_itr->second, waferu, waferv);
486  HGCalTriggerSubdetector subdet =
489  unsigned layer = module_si_id.layer();
490  unsigned wafer_type = detIdWaferType(det, layer, waferu, waferv);
491  int nroc = (wafer_type == HGCSiliconDetId::HGCalFine ? 6 : 3);
492  // Loop on ROCs in wafer
493  for (int roc = 1; roc <= nroc; roc++) {
494  // loop on TCs in ROC
495  auto tc_uvs = tc2roc.getTriggerId(roc, wafer_type);
496  for (const auto& tc_uv : tc_uvs) {
497  HGCalTriggerDetId trigger_cell_id(
498  subdet, module_si_id.zside(), wafer_type, layer, waferu, waferv, tc_uv.first, tc_uv.second);
499  trigger_cell_det_ids.emplace(trigger_cell_id);
500  }
501  }
502  }
503  }
504  return trigger_cell_det_ids;
505 }
506 
508  const unsigned trigger_cell_id) const {
509  throw cms::Exception("FeatureNotImplemented") << "Neighbor search is not implemented in HGCalTriggerGeometryV9Imp2";
510 }
511 
512 unsigned HGCalTriggerGeometryV9Imp2::getLinksInModule(const unsigned module_id) const {
513  DetId module_det_id(module_id);
514  unsigned links = 0;
515  // Scintillator
516  if (module_det_id.det() == DetId::HGCalHSc) {
517  links = hSc_links_per_module_;
518  } else if (module_det_id.det() == DetId::Forward && module_det_id.subdetId() == ForwardSubdetector::HFNose) {
519  links = 1;
520  }
521  // TO ADD HFNOSE : getLinksInModule
522  // Silicon
523  else {
524  HGCalDetId module_det_id_si(module_id);
525  unsigned module = module_det_id_si.wafer();
526  unsigned layer = layerWithOffset(module_id);
527  module = (module & sector0_mask_);
528  links = links_per_module_.at(packLayerModuleId(layer, module));
529  }
530  return links;
531 }
532 
533 unsigned HGCalTriggerGeometryV9Imp2::getModuleSize(const unsigned module_id) const {
534  DetId module_det_id(module_id);
535  unsigned nWafers = 1;
536  // Scintillator
537  if (module_det_id.det() == DetId::HGCalHSc) {
538  nWafers = hSc_wafers_per_module_;
539  }
540  // Check for HFNOSE : getModuleSize
541  // Silicon
542  else {
543  HGCalDetId module_det_id_si(module_id);
544  unsigned module = module_det_id_si.wafer();
545  unsigned layer = layerWithOffset(module_id);
546  nWafers = module_to_wafers_.count(packLayerModuleId(layer, module));
547  }
548  return nWafers;
549 }
550 
551 GlobalPoint HGCalTriggerGeometryV9Imp2::getTriggerCellPosition(const unsigned trigger_cell_det_id) const {
552  unsigned det = DetId(trigger_cell_det_id).det();
553  // Position: barycenter of the trigger cell.
554  Basic3DVector<float> triggerCellVector(0., 0., 0.);
555  const auto cell_ids = getCellsFromTriggerCell(trigger_cell_det_id);
556  // Scintillator
557  if (det == DetId::HGCalHSc) {
558  for (const auto& cell : cell_ids) {
559  triggerCellVector += hscGeometry()->getPosition(cell).basicVector();
560  }
561  }
562  // HFNose
563  else if (det == DetId::HGCalTrigger and
564  HGCalTriggerDetId(trigger_cell_det_id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
565  for (const auto& cell : cell_ids) {
566  HFNoseDetId cellDetId(cell);
567  triggerCellVector += noseGeometry()->getPosition(cellDetId).basicVector();
568  }
569  }
570  // Silicon
571  else {
572  for (const auto& cell : cell_ids) {
573  HGCSiliconDetId cellDetId(cell);
574  triggerCellVector += (cellDetId.det() == DetId::HGCalEE ? eeGeometry()->getPosition(cellDetId)
575  : hsiGeometry()->getPosition(cellDetId))
576  .basicVector();
577  }
578  }
579  return GlobalPoint(triggerCellVector / cell_ids.size());
580 }
581 
582 GlobalPoint HGCalTriggerGeometryV9Imp2::getModulePosition(const unsigned module_det_id) const {
583  unsigned det = DetId(module_det_id).det();
584  // Position: barycenter of the module.
585  Basic3DVector<float> moduleVector(0., 0., 0.);
586  const auto cell_ids = getCellsFromModule(module_det_id);
587  // Scintillator
588  if (det == DetId::HGCalHSc) {
589  for (const auto& cell : cell_ids) {
590  moduleVector += hscGeometry()->getPosition(cell).basicVector();
591  }
592  }
593  // HFNose
594  else if (det == DetId::Forward && DetId(module_det_id).subdetId() == ForwardSubdetector::HFNose) {
595  for (const auto& cell : cell_ids) {
596  HFNoseDetId cellDetId(cell);
597  moduleVector += noseGeometry()->getPosition(cellDetId).basicVector();
598  }
599  } // Silicon
600  else {
601  for (const auto& cell : cell_ids) {
602  HGCSiliconDetId cellDetId(cell);
603  moduleVector += (cellDetId.det() == DetId::HGCalEE ? eeGeometry()->getPosition(cellDetId)
604  : hsiGeometry()->getPosition(cellDetId))
605  .basicVector();
606  }
607  }
608 
609  return GlobalPoint(moduleVector / cell_ids.size());
610 }
611 
613  // read module mapping file
614  std::ifstream l1tModulesMappingStream(l1tModulesMapping_.fullPath());
615  if (!l1tModulesMappingStream.is_open()) {
616  throw cms::Exception("MissingDataFile") << "Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
617  }
618 
619  short waferu = 0;
620  short waferv = 0;
621  short module = 0;
622  short layer = 0;
623  for (; l1tModulesMappingStream >> layer >> waferu >> waferv >> module;) {
624  wafer_to_module_.emplace(packLayerWaferId(layer, waferu, waferv), module);
625  module_to_wafers_.emplace(packLayerModuleId(layer, module), packWaferId(waferu, waferv));
626  }
627  if (!l1tModulesMappingStream.eof()) {
628  throw cms::Exception("BadGeometryFile")
629  << "Error reading L1TModulesMapping '" << layer << " " << waferu << " " << waferv << " " << module << "' \n";
630  }
631  l1tModulesMappingStream.close();
632  // read links mapping file
633  std::ifstream l1tLinksMappingStream(l1tLinksMapping_.fullPath());
634  if (!l1tLinksMappingStream.is_open()) {
635  throw cms::Exception("MissingDataFile") << "Cannot open HGCalTriggerGeometry L1TLinksMapping file\n";
636  }
637  short links = 0;
638  const short max_modules_60deg_sector = 127;
639  for (; l1tLinksMappingStream >> layer >> module >> links;) {
640  if (module_to_wafers_.find(packLayerModuleId(layer, module)) == module_to_wafers_.end()) {
641  links = 0;
642  }
643  if (module > max_modules_60deg_sector)
644  sector0_mask_ = 0xff; // Use 8 bits to encode module number in 120deg sector
645  links_per_module_.emplace(packLayerModuleId(layer, module), links);
646  }
647  if (!l1tLinksMappingStream.eof()) {
648  throw cms::Exception("BadGeometryFile")
649  << "Error reading L1TLinksMapping '" << layer << " " << module << " " << links << "' \n";
650  }
651  l1tLinksMappingStream.close();
652 }
653 
655  unsigned packed_value = 0;
656  unsigned waferUsign = (waferU >= 0) ? 0 : 1;
657  unsigned waferVsign = (waferV >= 0) ? 0 : 1;
662  return packed_value;
663 }
664 
666  unsigned packed_value = 0;
667  unsigned subdet = ForwardSubdetector::HGCEE;
668  if (layer > heOffset_) {
669  layer -= heOffset_;
671  }
672  unsigned waferUsign = (waferU >= 0) ? 0 : 1;
673  unsigned waferVsign = (waferV >= 0) ? 0 : 1;
679  packed_value |= ((subdet & DetId::kSubdetMask) << DetId::kSubdetOffset);
680  return packed_value;
681 }
682 
683 unsigned HGCalTriggerGeometryV9Imp2::packLayerModuleId(unsigned layer, unsigned module) const {
684  unsigned packed_value = 0;
685  unsigned subdet = ForwardSubdetector::HGCEE;
686  if (layer > heOffset_) {
687  layer -= heOffset_;
689  }
690  packed_value |= ((layer & HGCalDetId::kHGCalLayerMask) << HGCalDetId::kHGCalLayerOffset);
691  packed_value |= ((module & HGCalDetId::kHGCalWaferMask) << HGCalDetId::kHGCalWaferOffset);
692  packed_value |= ((subdet & DetId::kSubdetMask) << DetId::kSubdetOffset);
693  return packed_value;
694 }
695 
696 void HGCalTriggerGeometryV9Imp2::unpackWaferId(unsigned wafer, int& waferU, int& waferV) const {
700  : waferUAbs);
702  : waferVAbs);
703 }
704 
705 bool HGCalTriggerGeometryV9Imp2::validTriggerCell(const unsigned trigger_cell_id) const {
706  return validTriggerCellFromCells(trigger_cell_id);
707 }
708 
709 bool HGCalTriggerGeometryV9Imp2::disconnectedModule(const unsigned module_id) const {
710  bool disconnected = false;
711  if (disconnected_modules_.find(HGCalDetId(module_id).wafer()) != disconnected_modules_.end())
712  disconnected = true;
713  if (disconnected_layers_.find(layerWithOffset(module_id)) != disconnected_layers_.end())
714  disconnected = true;
715  return disconnected;
716 }
717 
718 unsigned HGCalTriggerGeometryV9Imp2::triggerLayer(const unsigned id) const {
719  unsigned layer = layerWithOffset(id);
720 
721  if (DetId(id).det() == DetId::HGCalTrigger and
723  if (layer >= trigger_nose_layers_.size())
724  return 0;
725  return trigger_nose_layers_[layer];
726  }
727  if (layer >= trigger_layers_.size())
728  return 0;
729  return trigger_layers_[layer];
730 }
731 
732 bool HGCalTriggerGeometryV9Imp2::validCell(unsigned cell_id) const {
733  bool is_valid = false;
734  unsigned det = DetId(cell_id).det();
735  switch (det) {
736  case DetId::HGCalEE:
737  is_valid = eeTopology().valid(cell_id);
738  break;
739  case DetId::HGCalHSi:
740  is_valid = hsiTopology().valid(cell_id);
741  break;
742  case DetId::HGCalHSc:
743  is_valid = hscTopology().valid(cell_id);
744  break;
745  case DetId::Forward:
746  is_valid = noseTopology().valid(cell_id);
747  break;
748  default:
749  is_valid = false;
750  break;
751  }
752  return is_valid;
753 }
754 
755 bool HGCalTriggerGeometryV9Imp2::validTriggerCellFromCells(const unsigned trigger_cell_id) const {
756  // Check the validity of a trigger cell with the
757  // validity of the cells. One valid cell in the
758  // trigger cell is enough to make the trigger cell
759  // valid.
760  const geom_set cells = getCellsFromTriggerCell(trigger_cell_id);
761  bool is_valid = false;
762  for (const auto cell_id : cells) {
763  unsigned det = DetId(cell_id).det();
764  is_valid |= validCellId(det, cell_id);
765  if (is_valid)
766  break;
767  }
768  return is_valid;
769 }
770 
771 bool HGCalTriggerGeometryV9Imp2::validCellId(unsigned subdet, unsigned cell_id) const {
772  bool is_valid = false;
773  switch (subdet) {
774  case DetId::HGCalEE:
775  is_valid = eeTopology().valid(cell_id);
776  break;
777  case DetId::HGCalHSi:
778  is_valid = hsiTopology().valid(cell_id);
779  break;
780  case DetId::HGCalHSc:
781  is_valid = hscTopology().valid(cell_id);
782  break;
783  case DetId::Forward:
784  is_valid = noseTopology().valid(cell_id);
785  break;
786  default:
787  is_valid = false;
788  break;
789  }
790  return is_valid;
791 }
792 
793 int HGCalTriggerGeometryV9Imp2::detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const {
794  int wafer_type = 0;
795  switch (det) {
796  case DetId::HGCalEE:
797  wafer_type = eeTopology().dddConstants().getTypeHex(layer, waferU, waferV);
798  break;
799  case DetId::HGCalHSi:
800  wafer_type = hsiTopology().dddConstants().getTypeHex(layer, waferU, waferV);
801  break;
802  default:
803  break;
804  };
805  return wafer_type;
806 }
807 
808 unsigned HGCalTriggerGeometryV9Imp2::layerWithOffset(unsigned id) const {
809  unsigned det = DetId(id).det();
810  unsigned layer = 0;
811 
812  if (det == DetId::HGCalTrigger) {
813  unsigned subdet = HGCalTriggerDetId(id).subdet();
815  layer = HGCalTriggerDetId(id).layer();
816  } else if (subdet == HGCalTriggerSubdetector::HGCalHSiTrigger) {
817  layer = heOffset_ + HGCalTriggerDetId(id).layer();
818  } else if (subdet == HGCalTriggerSubdetector::HFNoseTrigger) {
819  layer = HFNoseTriggerDetId(id).layer();
820  }
821  } else if (det == DetId::HGCalHSc) {
822  layer = heOffset_ + HGCScintillatorDetId(id).layer();
823  } else if (det == DetId::Forward) {
824  unsigned subdet = HGCalDetId(id).subdetId();
825  if (subdet == ForwardSubdetector::HGCEE) {
826  layer = HGCalDetId(id).layer();
827  } else if (subdet == ForwardSubdetector::HGCHEF || subdet == ForwardSubdetector::HGCHEB) {
828  layer = heOffset_ + HGCalDetId(id).layer();
829  } else if (subdet == ForwardSubdetector::HFNose) {
830  layer = HFNoseDetId(id).layer();
831  }
832  }
833  return layer;
834 }
835 
837  geom_set stage1_ids;
838  return stage1_ids;
839 }
840 
842  geom_set stage2_ids;
843  return stage2_ids;
844 }
845 
847  geom_set stage1link_ids;
848  return stage1link_ids;
849 }
850 
852  unsigned stage1_id = 0;
853  return stage1_id;
854 }
855 
857  unsigned stage2_id = 0;
858  return stage2_id;
859 }
860 
862  geom_set stage1link_ids;
863  return stage1link_ids;
864 }
865 
867  geom_set lpgbt_ids;
868  return lpgbt_ids;
869 }
870 
872  unsigned stage1_id = 0;
873  return stage1_id;
874 }
875 
878  return modules;
879 }
880 
882  geom_set lpgbt_ids;
883  return lpgbt_ids;
884 }
885 
887  unsigned stage1_id = 0;
888  return stage1_id;
889 }
890 
HGCalTriggerSubdetector
geom_set getStage2FpgasFromStage1Fpga(const unsigned) const final
unsigned triggerLayer(const unsigned) const final
static const int kHGCalWaferVOffset
unsigned getModuleFromCell(const unsigned) const final
bool validCellId(unsigned det, unsigned cell_id) const
bool validTriggerCell(const unsigned) const final
int triggerCellU() const
Definition: HFNoseDetId.h:87
static const int kHGCalLayerOffset
Definition: HGCalDetId.h:16
unsigned packWaferId(int waferU, int waferV) const
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
int zside() const
get the z-side of the cell (1/-1)
Definition: HFNoseDetId.h:53
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)
int type() const
get the type
Definition: HFNoseDetId.h:50
unsigned lastTriggerLayer() const final
int32_t waferU(const int32_t index)
tbb::concurrent_unordered_set< unsigned > cache_missing_wafers_
int waferU() const
std::vector< unsigned > trigger_layers_
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
static const int kHGCalWaferVSignOffset
geom_set getNeighborsFromTriggerCell(const unsigned) const final
bool valid(const DetId &id) const override
Is this a valid cell id.
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
geom_set getModulesFromLpgbt(const unsigned) const final
geom_set getLpgbtsFromModule(const unsigned) const final
std::unordered_map< unsigned, unsigned > links_per_module_
int type() const
get/set the type
std::vector< int > cellV() 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)
static const HFNoseDetId getModule(HFNoseDetId const &id)
int zside(DetId const &)
static const int kSubdetOffset
Definition: DetId.h:22
const HGCalTopology & hsiTopology() const
void setHSiGeometry(const HGCalGeometry *geom)
ForwardSubdetector
std::vector< HFNoseTriggerDetId > getTriggerDetIds(HFNoseDetId const &id) const
int type() const
get the type
void setNoseGeometry(const HGCalGeometry *geom)
constexpr std::array< uint8_t, layerIndexSize > layer
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
const HGCalGeometry * noseGeometry() const
int type() const
get the type
unsigned getStage1FpgaFromLpgbt(const unsigned) const final
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
Definition: HGCalDetId.h:49
GlobalPoint getModulePosition(const unsigned) const final
static const int kSubdetMask
Definition: DetId.h:20
unsigned getModuleSize(const unsigned module_id) const final
int waferV() const
Definition: HFNoseDetId.h:78
int layer() const
get the layer #
Definition: HFNoseDetId.h:56
int type() const
get the type
unsigned getModuleFromTriggerCell(const unsigned) const final
int waferU() const
Definition: HFNoseDetId.h:75
int layer() const
get the layer #
void unpackWaferId(unsigned wafer, int &waferU, int &waferV) const
int zside() const
get the z-side of the cell (1/-1)
int waferV() const
def move
Definition: eostools.py:511
std::unordered_set< unsigned > disconnected_modules_
unsigned packLayerModuleId(unsigned layer, unsigned wafer) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
unsigned getTriggerCellFromCell(const unsigned) const final
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)
int iphi() const
get the phi index
geom_set getStage1LinksFromStage2Fpga(const unsigned) const final
int wafer() const
get the wafer #
Definition: HGCalDetId.h:40
std::pair< int, int > getREtaRange(int lay) const
std::vector< unsigned > trigger_nose_layers_
unsigned getStage2FpgaFromStage1Link(const unsigned) const final
static const int kHGCalLayerMask
geom_set getLpgbtsFromStage1Fpga(const unsigned) const final
const HGCalGeometry * hsiGeometry() const
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
Definition: DetId.h:17
std::vector< int > cellU() const
static const int kHGCalWaferVMask
static const int kHGCalWaferUSignMask
static const int kHGCalWaferUMask
bool validCell(const unsigned) const final
unsigned getStage1FpgaFromModule(const unsigned module_id) const final
const HGCalDDDConstants & dddConstants() const
Definition: HGCalTopology.h:98
unsigned getStage1FpgaFromStage1Link(const unsigned) const final
const HGCalGeometry * hscGeometry() const
const HGCalTopology & hscTopology() const
static const int kHGCalWaferVSignMask
Detector
Definition: DetId.h:24
GlobalPoint getTriggerCellPosition(const unsigned) const final
static const int kHGCalWaferOffset
Definition: HGCalDetId.h:12
std::set< unsigned > geom_ordered_set
int layer() const
get the layer #
geom_set getStage1FpgasFromStage2Fpga(const unsigned) const final
static const int kHGCalLayerOffset
int layer() const
get the layer #
int triggerCellU() const
std::unordered_set< unsigned > disconnected_layers_
std::vector< int > cellU() const
int zside() const
get the z-side of the cell (1/-1)
std::unordered_set< unsigned > geom_set
GlobalPoint getPosition(const DetId &id, bool debug=false) const
std::unordered_multimap< unsigned, unsigned > module_to_wafers_
int32_t waferV(const int32_t index)
geom_set getStage1LinksFromStage1Fpga(const unsigned) const final
const HGCalTopology & noseTopology() const
int triggerCellV() const
std::string fullPath() const
Definition: FileInPath.cc:161
unsigned layerWithOffset(unsigned) const
void initialize(const HGCalGeometry *, const HGCalGeometry *, const HGCalGeometry *) final
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned packLayerWaferId(unsigned layer, int waferU, int waferV) const
static const int kHGCalWaferUOffset
Log< level::Warning, false > LogWarning
geom_set getCellsFromTriggerCell(const unsigned) const final
const BasicVectorType & basicVector() const
Definition: PV3DBase.h:53
static const int kHGCalWaferUSignOffset
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
geom_set getTriggerCellsFromModule(const unsigned) const final
geom_set getCellsFromModule(const unsigned) const final
bool validTriggerCellFromCells(const unsigned) const
int layer() const
get the layer #
Definition: HGCalDetId.h:46
bool disconnectedModule(const unsigned) const final
tuple module
Definition: callgraph.py:69
static const int kHGCalWaferMask
Definition: HGCalDetId.h:13
int triggerCellV() const
Definition: HFNoseDetId.h:94
unsigned getLinksInModule(const unsigned module_id) const final
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46