CMS 3D CMS Logo

HGCalTriggerGeometryHexImp1.cc
Go to the documentation of this file.
2 
5 
6 #include <vector>
7 #include <iostream>
8 #include <fstream>
9 
11 
13 public:
15 
16  void initialize(const edm::ESHandle<CaloGeometry>&) final;
19  const edm::ESHandle<HGCalGeometry>&) final;
20 
21 private:
24 
25  void fillMaps();
27 };
28 
29 /*****************************************************************/
32  l1tCellsMapping_(conf.getParameter<edm::FileInPath>("L1TCellsMapping")),
33  l1tModulesMapping_(conf.getParameter<edm::FileInPath>("L1TModulesMapping"))
34 /*****************************************************************/
35 {}
36 
37 /*****************************************************************/
39 /*****************************************************************/
40 {
41  edm::LogWarning("HGCalTriggerGeometry") << "WARNING: This HGCal trigger geometry is incomplete.\n"
42  << "WARNING: There is no neighbor information.\n";
43 
44  setCaloGeometry(calo_geometry);
45  fillMaps();
47 }
48 
49 /*****************************************************************/
51  const edm::ESHandle<HGCalGeometry>& hgc_hsi_geometry,
52  const edm::ESHandle<HGCalGeometry>& hgc_hsc_geometry)
53 /*****************************************************************/
54 {
55  throw cms::Exception("BadGeometry")
56  << "HGCalTriggerGeometryHexImp1 geometry cannot be initialized with the V9 HGCAL geometry";
57 }
58 
59 /*****************************************************************/
61 /*****************************************************************/
62 {
63  //
64  // read module mapping file
65  std::unordered_map<short, short> wafer_to_module_ee;
66  std::unordered_map<short, short> wafer_to_module_fh;
67  std::unordered_map<short, std::map<short, short>> module_to_wafers_ee;
68  std::unordered_map<short, std::map<short, short>> module_to_wafers_fh;
69  std::ifstream l1tModulesMappingStream(l1tModulesMapping_.fullPath());
70  if (!l1tModulesMappingStream.is_open())
71  edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TModulesMapping file\n";
72  short subdet = 0;
73  short wafer = 0;
74  short module = 0;
75  for (; l1tModulesMappingStream >> subdet >> wafer >> module;) {
76  if (subdet == 3) {
77  wafer_to_module_ee.emplace(wafer, module);
78  auto itr_insert = module_to_wafers_ee.emplace(module, std::map<short, short>());
79  itr_insert.first->second.emplace(wafer, 0);
80  } else if (subdet == 4) {
81  wafer_to_module_fh.emplace(wafer, module);
82  auto itr_insert = module_to_wafers_fh.emplace(module, std::map<short, short>());
83  itr_insert.first->second.emplace(wafer, 0);
84  } else
85  edm::LogWarning("HGCalTriggerGeometry")
86  << "Unsupported subdetector number (" << subdet << ") in L1TModulesMapping file\n";
87  }
88  if (!l1tModulesMappingStream.eof())
89  edm::LogWarning("HGCalTriggerGeometry") << "Error reading L1TModulesMapping '" << wafer << " " << module << "' \n";
90  l1tModulesMappingStream.close();
91  // read trigger cell mapping file
92  std::map<std::pair<short, short>, short> cells_to_trigger_cells;
93  std::unordered_map<short, short> number_trigger_cells_in_wafers; // the map key is the wafer type
94  std::ifstream l1tCellsMappingStream(l1tCellsMapping_.fullPath());
95  if (!l1tCellsMappingStream.is_open())
96  edm::LogError("HGCalTriggerGeometry") << "Cannot open L1TCellsMapping file\n";
97  short waferType = 0;
98  short cell = 0;
99  short triggerCell = 0;
100  for (; l1tCellsMappingStream >> waferType >> cell >> triggerCell;) {
101  cells_to_trigger_cells.emplace(std::make_pair((waferType ? 1 : -1), cell), triggerCell);
102  auto itr_insert = number_trigger_cells_in_wafers.emplace((waferType ? 1 : -1), 0);
103  if (triggerCell + 1 > itr_insert.first->second)
104  itr_insert.first->second = triggerCell + 1;
105  }
106  if (!l1tCellsMappingStream.eof())
107  edm::LogWarning("HGCalTriggerGeometry")
108  << "Error reading L1TCellsMapping'" << waferType << " " << cell << " " << triggerCell << "' \n";
109  l1tCellsMappingStream.close();
110  // For each wafer compute the trigger cell offset according to the wafer position inside
111  // the module. The first wafer will have an offset equal to 0, the second an offset equal to the
112  // number of trigger cells in the first wafer, etc.
113  short offset = 0;
114  for (auto& module_wafers : module_to_wafers_ee) {
115  offset = 0;
116  for (auto& wafer_offset : module_wafers.second) {
117  wafer_offset.second = offset;
118  int wafer_type = (eeTopology().dddConstants().waferTypeT(wafer_offset.first) == 1 ? 1 : -1);
119  offset += number_trigger_cells_in_wafers.at(wafer_type);
120  }
121  }
122  for (auto& module_wafers : module_to_wafers_fh) {
123  offset = 0;
124  for (auto& wafer_offset : module_wafers.second) {
125  wafer_offset.second = offset;
126  int wafer_type = (fhTopology().dddConstants().waferTypeT(wafer_offset.first) == 1 ? 1 : -1);
127  offset += number_trigger_cells_in_wafers.at(wafer_type);
128  }
129  }
130  //
131  // Loop over HGC cells
132  // EE
133  for (const auto& id : eeGeometry()->getValidGeomDetIds()) {
134  if (id.rawId() == 0)
135  continue;
136  HGCalDetId waferDetId(id);
137  short module = wafer_to_module_ee[waferDetId.wafer()];
138  short triggercell_offset = module_to_wafers_ee.at(module).at(waferDetId.wafer());
139  int nCells = eeTopology().dddConstants().numberCellsHexagon(waferDetId.wafer());
140  for (int c = 0; c < nCells; c++) {
141  short triggerCellId = cells_to_trigger_cells[std::make_pair(waferDetId.waferType(), c)];
142  // Fill cell -> trigger cell mapping
143  HGCalDetId cellDetId(ForwardSubdetector(waferDetId.subdetId()),
144  waferDetId.zside(),
145  waferDetId.layer(),
146  waferDetId.waferType(),
147  waferDetId.wafer(),
148  c);
149  // The module id is used instead of the wafer id for the trigger cells
150  // Since there are several wafers per module, an offset is applied on the HGCalDetId::cell field
151  if (triggercell_offset + triggerCellId >= HGCalDetId::kHGCalCellMask)
152  edm::LogError("HGCalTriggerGeometry")
153  << "Trigger cell id requested with a cell field larger than available in HGCalDetId ("
154  << triggercell_offset + triggerCellId << " >= " << HGCalDetId::kHGCalCellMask << ")\n";
155  HGCalDetId triggerCellDetId(ForwardSubdetector(waferDetId.subdetId()),
156  waferDetId.zside(),
157  waferDetId.layer(),
158  waferDetId.waferType(),
159  module,
160  triggercell_offset + triggerCellId);
161  cells_to_trigger_cells_.emplace(cellDetId, triggerCellDetId);
162  // Fill trigger cell -> module mapping
163  HGCalDetId moduleDetId(ForwardSubdetector(waferDetId.subdetId()),
164  waferDetId.zside(),
165  waferDetId.layer(),
166  waferDetId.waferType(),
167  module,
169  trigger_cells_to_modules_.emplace(triggerCellDetId, moduleDetId);
170  }
171  }
172  // FH
173  for (const auto& id : fhGeometry()->getValidGeomDetIds()) {
174  if (id.rawId() == 0)
175  continue;
176  HGCalDetId waferDetId(id);
177  short module = wafer_to_module_fh[waferDetId.wafer()];
178  short triggercell_offset = module_to_wafers_fh.at(module).at(waferDetId.wafer());
179  int nCells = fhTopology().dddConstants().numberCellsHexagon(waferDetId.wafer());
180  for (int c = 0; c < nCells; c++) {
181  short triggerCellId = cells_to_trigger_cells[std::make_pair(waferDetId.waferType(), c)];
182  // Fill cell -> trigger cell mapping
183  HGCalDetId cellDetId(ForwardSubdetector(waferDetId.subdetId()),
184  waferDetId.zside(),
185  waferDetId.layer(),
186  waferDetId.waferType(),
187  waferDetId.wafer(),
188  c);
189  // The module id is used instead of the wafer id for the trigger cells
190  // Since there are several wafers per module, an offset is applied on the HGCalDetId::cell field
191  if (triggercell_offset + triggerCellId >= HGCalDetId::kHGCalCellMask)
192  edm::LogError("HGCalTriggerGeometry")
193  << "Trigger cell id requested with a cell field larger than available in HGCalDetId ("
194  << triggercell_offset + triggerCellId << " >= " << HGCalDetId::kHGCalCellMask << ")\n";
195  HGCalDetId triggerCellDetId(ForwardSubdetector(waferDetId.subdetId()),
196  waferDetId.zside(),
197  waferDetId.layer(),
198  waferDetId.waferType(),
199  module,
200  triggercell_offset + triggerCellId);
201  cells_to_trigger_cells_.emplace(cellDetId, triggerCellDetId);
202  // Fill trigger cell -> module mapping
203  HGCalDetId moduleDetId(ForwardSubdetector(waferDetId.subdetId()),
204  waferDetId.zside(),
205  waferDetId.layer(),
206  waferDetId.waferType(),
207  module,
209  trigger_cells_to_modules_.emplace(triggerCellDetId, moduleDetId);
210  }
211  }
212 }
213 
214 /*****************************************************************/
216 /*****************************************************************/
217 {
218  //
219  // Build trigger cells and fill map
221  // make list of cells in trigger cells
222  std::unordered_map<unsigned, list_cells> trigger_cells_to_cells;
223  for (const auto& cell_triggerCell : cells_to_trigger_cells_) {
224  unsigned cell = cell_triggerCell.first;
225  unsigned triggerCell = cell_triggerCell.second;
226  auto itr_exist = trigger_cells_to_cells.emplace(triggerCell, list_cells());
227  itr_exist.first->second.emplace(cell);
228  //trigger_cells_to_cells.at(triggerCell).emplace(cell);
229  }
230  for (const auto& triggerCell_cells : trigger_cells_to_cells) {
231  unsigned triggerCellId = triggerCell_cells.first;
232  list_cells cellIds = triggerCell_cells.second;
233  // Position: barycenter of the trigger cell.
234  Basic3DVector<float> triggerCellVector(0., 0., 0.);
235  for (const auto& cell : cellIds) {
236  HGCalDetId cellDetId(cell);
237  triggerCellVector += (cellDetId.subdetId() == ForwardSubdetector::HGCEE ? eeGeometry()->getPosition(cellDetId)
238  : fhGeometry()->getPosition(cellDetId))
239  .basicVector();
240  }
241  GlobalPoint triggerCellPoint(triggerCellVector / cellIds.size());
242  const auto& triggerCellToModuleItr = trigger_cells_to_modules_.find(triggerCellId);
243  unsigned moduleId = (triggerCellToModuleItr != trigger_cells_to_modules_.end()
244  ? triggerCellToModuleItr->second
245  : 0); // 0 if the trigger cell doesn't belong to a module
246  //unsigned moduleId = trigger_cells_to_modules_.at(triggercellId);
247  // FIXME: empty neighbours
248  trigger_cells_.emplace(triggerCellId,
249  std::make_unique<const HGCalTriggerGeometry::TriggerCell>(
250  triggerCellId, moduleId, triggerCellPoint, list_cells(), cellIds));
251  }
252  //
253  // Build modules and fill map
254  typedef HGCalTriggerGeometry::Module::list_type list_triggerCells;
255  typedef HGCalTriggerGeometry::Module::tc_map_type tc_map_to_cells;
256  // make list of trigger cells in modules
257  std::unordered_map<unsigned, list_triggerCells> modules_to_trigger_cells;
258  for (const auto& triggerCell_module : trigger_cells_to_modules_) {
259  unsigned triggerCell = triggerCell_module.first;
260  unsigned module = triggerCell_module.second;
261  auto itr_exist = modules_to_trigger_cells.emplace(module, list_triggerCells());
262  itr_exist.first->second.emplace(triggerCell);
263  //modules_to_trigger_cells.at(module).emplace(triggerCell);
264  }
265  for (const auto& module_triggerCell : modules_to_trigger_cells) {
266  unsigned moduleId = module_triggerCell.first;
267  list_triggerCells triggerCellIds = module_triggerCell.second;
268  tc_map_to_cells cellsInTriggerCells;
269  // Position: barycenter of the module, from trigger cell positions
270  Basic3DVector<float> moduleVector(0., 0., 0.);
271  for (const auto& triggerCell : triggerCellIds) {
272  const auto& cells_in_tc = trigger_cells_to_cells.at(triggerCell);
273  for (const unsigned cell : cells_in_tc) {
274  cellsInTriggerCells.emplace(triggerCell, cell);
275  }
276  moduleVector += trigger_cells_.at(triggerCell)->position().basicVector();
277  }
278  GlobalPoint modulePoint(moduleVector / triggerCellIds.size());
279  // FIXME: empty neighbours
280  modules_.emplace(moduleId,
281  std::make_unique<const HGCalTriggerGeometry::Module>(
282  moduleId, modulePoint, list_triggerCells(), triggerCellIds, cellsInTriggerCells));
283  }
284 }
285 
std::unordered_set< unsigned > list_type
std::unordered_multimap< unsigned, unsigned > tc_map_type
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
GlobalPoint getPosition(const DetId &id) const
ForwardSubdetector
void initialize(const edm::ESHandle< CaloGeometry > &) final
static const int kHGCalCellMask
Definition: HGCalDetId.h:13
int zside() const
get the z-side of the cell (1/-1)
Definition: HGCalDetId.h:51
int numberCellsHexagon(int wafer) const
const HGCalGeometry * fhGeometry() 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
int wafer() const
get the wafer #
Definition: HGCalDetId.h:42
void setCaloGeometry(const edm::ESHandle< CaloGeometry > &geom)
const HGCalDDDConstants & dddConstants() const
HLT enums.
std::string fullPath() const
Definition: FileInPath.cc:163
int waferType() const
get the wafer type
Definition: HGCalDetId.h:45
#define DEFINE_EDM_PLUGIN(factory, type, name)
HGCalTriggerGeometryHexImp1(const edm::ParameterSet &conf)
int waferTypeT(int wafer) const
Definition: vlib.h:208
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
Definition: HGCalDetId.h:48