CMS 3D CMS Logo

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