41 bool validCell(
const unsigned)
const final;
89 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
94 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
96 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
104 l1tCellsMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellsMapping")),
105 l1tCellsBHMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellsBHMapping")),
106 l1tModulesMapping_(conf.getParameter<
edm::FileInPath>(
"L1TModulesMapping")),
107 l1tCellNeighborsMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellNeighborsMapping")),
108 l1tCellNeighborsBHMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellNeighborsBHMapping")) {
109 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
111 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
135 unsigned trigger_layer = 1;
156 <<
"HGCalTriggerGeometryHexLayerBasedImp1 geometry cannot be initialized with the V9 HGCAL geometry";
164 <<
"HGCalTriggerGeometryHexLayerBasedImp1 geometry cannot be initialized with the V9 HGCAL+Nose geometry";
171 unsigned wafer_trigger_cell = 0;
172 unsigned trigger_cell = 0;
186 <<
"HGCalTriggerGeometry: Hcal cell ieta=" <<
ieta <<
", iphi=" <<
iphi
187 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
190 wafer_trigger_cell = 0;
199 unsigned wafer = cell_det_id.
wafer();
200 unsigned cell = cell_det_id.
cell();
204 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" in wafer " << wafer
205 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
208 wafer_trigger_cell = 0;
219 HGCalDetId trigger_cell_det_id(trigger_cell_id);
231 << trigger_cell_det_id <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer()
232 <<
" is not mapped to any trigger module. The module mapping should be modified. See "
233 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for "
236 module = module_itr->second;
239 trigger_cell_det_id.
zside(),
240 trigger_cell_det_id.
layer(),
241 (trigger_cell_det_id.
waferType() == 1 ? 1 : 0),
248 const unsigned trigger_cell_id)
const {
249 HGCalDetId trigger_cell_det_id(trigger_cell_id);
253 unsigned subdet = trigger_cell_det_id.
subdetId();
254 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
255 unsigned trigger_cell = trigger_cell_det_id.
cell();
256 const auto& cell_range =
258 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
262 unsigned cell_det_id =
265 cell_det_ids.emplace(cell_det_id);
270 unsigned subdet = trigger_cell_det_id.
subdetId();
271 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
272 unsigned trigger_cell = trigger_cell_det_id.
cell();
274 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
278 unsigned wafer_type = (
detIdWaferType(subdet, wafer) == 1 ? 1 : 0);
280 trigger_cell_det_id.
zside(),
281 trigger_cell_det_id.
layer(),
287 cell_det_ids.emplace(cell_det_id);
294 const unsigned module_id)
const {
297 for (
auto trigger_cell_id : trigger_cells) {
299 cell_det_ids.insert(
cells.begin(),
cells.end());
305 const unsigned module_id)
const {
308 for (
auto trigger_cell_id : trigger_cells) {
310 cell_det_ids.insert(
cells.begin(),
cells.end());
316 const unsigned module_id)
const {
325 module_det_id.
zside(),
326 module_det_id.
layer(),
331 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
339 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
340 unsigned wafer = wafer_itr->second;
344 module_det_id.
zside(),
345 module_det_id.
layer(),
350 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
354 return trigger_cell_det_ids;
358 const unsigned module_id)
const {
367 module_det_id.
zside(),
368 module_det_id.
layer(),
373 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
381 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
382 unsigned wafer = wafer_itr->second;
386 module_det_id.
zside(),
387 module_det_id.
layer(),
392 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
396 return trigger_cell_det_ids;
400 const unsigned trigger_cell_id)
const {
401 HGCalDetId trigger_cell_det_id(trigger_cell_id);
406 unsigned trigger_cell = trigger_cell_det_id.
cell();
410 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
411 if (neighbors_itr == neighbors_map.end()) {
412 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell "
413 << trigger_cell <<
" in module " <<
module
414 <<
". The trigger cell neighbor mapping should be modified. \n";
416 const auto& neighbors = neighbors_itr->second;
418 neighbor_detids.reserve(neighbors.size());
419 for (
const auto& module_tc : neighbors) {
421 trigger_cell_det_id.
zside(),
422 trigger_cell_det_id.
layer(),
427 neighbor_detids.emplace(neighbor_det_id.rawId());
430 return neighbor_detids;
444 for (
const auto& cell : cell_ids) {
451 for (
const auto& cell : cell_ids) {
458 return GlobalPoint(triggerCellVector / cell_ids.size());
468 for (
const auto& cell : cell_ids) {
475 for (
const auto& cell : cell_ids) {
482 return GlobalPoint(moduleVector / cell_ids.size());
489 if (!l1tModulesMappingStream.is_open()) {
490 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
492 short trigger_wafer = 0;
494 for (; l1tModulesMappingStream >> trigger_wafer >>
module;) {
500 if (!l1tModulesMappingStream.eof())
502 <<
"Error reading L1TModulesMapping '" << trigger_wafer <<
" " <<
module <<
"' \n";
503 l1tModulesMappingStream.close();
506 if (!l1tCellsMappingStream.is_open()) {
507 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
513 short trigger_cell = 0;
514 for (; l1tCellsMappingStream >> subdet >> wafer >> cell >> trigger_wafer >> trigger_cell;) {
516 unsigned trigger_cell_key =
packWaferCellId(subdet, trigger_wafer, trigger_cell);
522 if (trigger_cell + 1 > itr_insert.first->second)
523 itr_insert.first->second = trigger_cell + 1;
525 if (!l1tCellsMappingStream.eof())
526 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping '" << subdet <<
" " << wafer <<
" "
527 << cell <<
" " << trigger_wafer <<
" " << trigger_cell <<
"' \n";
528 l1tCellsMappingStream.close();
531 if (!l1tCellsBHMappingStream.is_open()) {
532 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsBHMapping file\n";
538 for (; l1tCellsBHMappingStream >>
ieta >>
iphi >> trigger_wafer >> trigger_cell;) {
546 if (trigger_cell + 1 > itr_insert.first->second)
547 itr_insert.first->second = trigger_cell + 1;
549 if (!l1tCellsBHMappingStream.eof())
551 << trigger_wafer <<
" " << trigger_cell <<
"' \n";
552 l1tCellsBHMappingStream.close();
556 const edm::FileInPath&
file, std::unordered_map<
int, std::set<std::pair<short, short>>>& neighbors_map) {
558 std::ifstream l1tCellNeighborsMappingStream(
file.fullPath());
559 if (!l1tCellNeighborsMappingStream.is_open()) {
560 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
562 for (std::array<char, 512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512);) {
569 std::regex key_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
570 std::vector<std::string> key_tokens{std::sregex_token_iterator(
line.begin(),
line.end(), key_regex), {}};
571 if (key_tokens.empty()) {
572 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n"
573 <<
" Cannot find the trigger cell key in line:\n"
574 <<
" '" << &
buffer[0] <<
"'\n";
576 std::regex digits_regex(
"\\d{1,3}");
577 std::vector<std::string> module_tc{
578 std::sregex_token_iterator(key_tokens[0].begin(), key_tokens[0].
end(), digits_regex), {}};
580 int module = std::stoi(module_tc[0]);
581 int trigger_cell = std::stoi(module_tc[1]);
587 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
588 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(
line.begin(),
line.end(), neighbors_regex),
590 if (neighbors_tokens.size() < 2) {
591 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n"
592 <<
" Cannot find any neighbor in line:\n"
593 <<
" '" << &
buffer[0] <<
"'\n";
595 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short, short>>());
597 for (
unsigned i = 1;
i < neighbors_tokens.size();
i++) {
598 const auto& neighbor = neighbors_tokens[
i];
599 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
601 short neighbor_module(std::stoi(pair_neighbor[0]));
602 short neighbor_cell(std::stoi(pair_neighbor[1]));
603 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
606 if (!l1tCellNeighborsMappingStream.eof())
607 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
608 l1tCellNeighborsMappingStream.close();
615 unsigned wafer = wafer_module.first;
618 std::set<unsigned> trigger_cell_ids;
623 for (
unsigned trigger_cell : trigger_cell_ids) {
637 unsigned packed_value = 0;
638 const int kSubdetMask = 0x7;
646 unsigned packed_value = 0;
654 unsigned& cell)
const {
665 bool is_valid =
false;
674 unsigned subdet = cell_det_id.
subdetId();
695 bool disconnected =
false;
715 HGCalDetId trigger_cell_det_id(trigger_cell_id);
716 unsigned subdet = trigger_cell_det_id.
subdetId();
718 bool is_valid =
false;
719 for (
const auto cell_id :
cells) {
728 bool is_valid =
false;
747 unsigned packed_value = 0;
790 "HGCalTriggerGeometryHexLayerBasedImp1");