40 bool validCell(
const unsigned)
const final;
86 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
92 l1tCellsMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellsMapping")),
93 l1tCellNeighborsMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellNeighborsMapping")),
94 l1tWaferNeighborsMapping_(conf.getParameter<
edm::FileInPath>(
"L1TWaferNeighborsMapping")),
95 l1tModulesMapping_(conf.getParameter<
edm::FileInPath>(
"L1TModulesMapping")) {}
119 <<
"HGCalTriggerGeometryHexImp2 geometry cannot be initialized with the V9 HGCAL geometry";
127 <<
"HGCalTriggerGeometryHexImp2 geometry cannot be initialized with the V9 HGCAL+Nose geometry";
134 int wafer_type = cell_det_id.
waferType();
135 unsigned cell = cell_det_id.
cell();
139 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: HGCal cell " << cell
140 <<
" is not mapped to any trigger cell for the wafer type " << wafer_type
141 <<
". The trigger cell mapping should be modified.\n";
143 unsigned trigger_cell = trigger_cell_itr->second;
157 unsigned wafer = cell_det_id.
wafer();
158 unsigned subdet = cell_det_id.
subdetId();
159 std::unordered_map<short, short>::const_iterator module_itr;
160 bool out_of_range_error =
false;
165 out_of_range_error =
true;
170 out_of_range_error =
true;
173 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet " << subdet <<
"\n";
176 if (out_of_range_error) {
177 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Wafer " << wafer
178 <<
" is not mapped to any trigger module for subdetector " << subdet
179 <<
". The module mapping should be modified. See "
180 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/"
181 "HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
183 unsigned module = module_itr->second;
194 HGCalDetId trigger_cell_det_id(trigger_cell_id);
195 unsigned wafer = trigger_cell_det_id.
wafer();
196 unsigned subdet = trigger_cell_det_id.
subdetId();
199 std::unordered_map<short, short>::const_iterator module_itr;
200 bool out_of_range_error =
false;
205 out_of_range_error =
true;
210 out_of_range_error =
true;
213 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet " << subdet <<
"\n";
216 if (out_of_range_error) {
217 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Wafer " << wafer
218 <<
" is not mapped to any trigger module for subdetector " << subdet
219 <<
". The module mapping should be modified. See "
220 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/"
221 "HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
223 unsigned module = module_itr->second;
225 trigger_cell_det_id.
zside(),
226 trigger_cell_det_id.
layer(),
234 const unsigned trigger_cell_id)
const {
235 HGCalDetId trigger_cell_det_id(trigger_cell_id);
236 unsigned subdet = trigger_cell_det_id.
subdetId();
239 int wafer_type = trigger_cell_det_id.
waferType();
240 unsigned trigger_cell = trigger_cell_det_id.
cell();
244 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
246 trigger_cell_det_id.
zside(),
247 trigger_cell_det_id.
layer(),
249 trigger_cell_det_id.
wafer(),
258 unsigned subdet = module_det_id.
subdetId();
262 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
272 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
276 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
283 module_det_id.
zside(),
284 module_det_id.
layer(),
289 cell_det_ids.emplace(cell_id.rawId());
296 const unsigned module_id)
const {
298 unsigned subdet = module_det_id.
subdetId();
302 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
312 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
316 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
323 module_det_id.
zside(),
324 module_det_id.
layer(),
329 cell_det_ids.emplace(cell_id.rawId());
336 const unsigned module_id)
const {
338 unsigned subdet = module_det_id.
subdetId();
342 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
352 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
357 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
364 module_det_id.
zside(),
365 module_det_id.
layer(),
370 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
373 return trigger_cell_det_ids;
377 const unsigned module_id)
const {
379 unsigned subdet = module_det_id.
subdetId();
383 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
393 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
398 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
405 module_det_id.
zside(),
406 module_det_id.
layer(),
411 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
414 return trigger_cell_det_ids;
418 const unsigned trigger_cell_id)
const {
419 HGCalDetId trigger_cell_det_id(trigger_cell_id);
420 unsigned wafer = trigger_cell_det_id.
wafer();
421 int wafer_type = trigger_cell_det_id.
waferType();
422 unsigned subdet = trigger_cell_det_id.
subdetId();
423 unsigned trigger_cell = trigger_cell_det_id.
cell();
428 std::unordered_map<short, std::vector<short>>::const_iterator surrounding_wafers_itr;
429 bool out_of_range_error =
false;
434 out_of_range_error =
true;
439 out_of_range_error =
true;
442 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer neighbours for subdet " << subdet <<
"\n";
445 if (out_of_range_error) {
446 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for wafer " << wafer
447 <<
" in subdetector " << subdet
448 <<
". The wafer neighbor mapping should be modified. \n";
450 const std::vector<short>& surrounding_wafers = surrounding_wafers_itr->second;
452 std::vector<int>
types;
453 types.reserve(surrounding_wafers.size() + 1);
454 types.emplace_back(wafer_type);
455 for (
const auto w : surrounding_wafers) {
463 types.emplace_back(wt);
470 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell "
471 << trigger_cell <<
" with wafer configuration "
472 << std::bitset<7>(trigger_cell_key >> 8)
473 <<
". The trigger cell neighbor mapping should be modified. \n";
475 const auto& neighbors = neighbors_itr->second;
477 neighbor_detids.reserve(neighbors.size());
478 for (
const auto& wafer_tc : neighbors) {
479 if (wafer_tc.first - 1 >= (
int)surrounding_wafers.size()) {
481 <<
"HGCalTriggerGeometry: Undefined wafer neighbor number " << wafer_tc.first <<
" for wafer " << wafer
482 <<
" and trigger cell " << trigger_cell <<
". The neighbor mapping files should be modified.";
484 int neighbor_wafer = (wafer_tc.first == 0 ? wafer : surrounding_wafers.at(wafer_tc.first - 1));
485 if (neighbor_wafer == -1)
489 trigger_cell_det_id.
zside(),
490 trigger_cell_det_id.
layer(),
495 neighbor_detids.emplace(neighbor_det_id.rawId());
498 return neighbor_detids;
509 if (cell_ids.empty())
511 for (
const auto& cell : cell_ids) {
517 return GlobalPoint(triggerCellVector / cell_ids.size());
524 if (cell_ids.empty())
526 for (
const auto& cell : cell_ids) {
532 return GlobalPoint(moduleVector / cell_ids.size());
539 if (!l1tModulesMappingStream.is_open()) {
540 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
545 for (; l1tModulesMappingStream >> subdet >> wafer >>
module;) {
566 <<
"Unsupported subdetector number (" << subdet <<
") in L1TModulesMapping file\n";
570 if (!l1tModulesMappingStream.eof())
571 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '" << wafer <<
" " <<
module <<
"' \n";
572 l1tModulesMappingStream.close();
575 if (!l1tCellsMappingStream.is_open()) {
576 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
580 short triggerCell = 0;
581 for (; l1tCellsMappingStream >> waferType >> cell >> triggerCell;) {
587 if (triggerCell + 1 > itr_insert.first->second)
588 itr_insert.first->second = triggerCell + 1;
590 if (!l1tCellsMappingStream.eof())
592 <<
"Error reading L1TCellsMapping'" << waferType <<
" " << cell <<
" " << triggerCell <<
"' \n";
593 l1tCellsMappingStream.close();
599 if (!l1tCellNeighborsMappingStream.is_open()) {
600 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
602 for (std::array<char, 512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512);) {
609 std::regex key_regex(
"\\(\\s*[01]{7}\\s*,\\s*\\d{1,3}\\s*\\)");
610 std::vector<std::string> key_tokens{std::sregex_token_iterator(
line.begin(),
line.end(), key_regex), {}};
611 if (key_tokens.size() != 1) {
612 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n"
613 <<
" Cannot find the trigger cell key in line:\n"
614 <<
" '" << &
buffer[0] <<
"'\n";
616 std::regex digits_regex(
"([01]{7})|(\\d{1,3})");
617 std::vector<std::string> type_tc{
618 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}};
620 int trigger_cell = std::stoi(type_tc[1]);
621 std::vector<int> wafer_types;
622 wafer_types.reserve(type_tc[0].
size());
624 for (
const char c : type_tc[0])
625 wafer_types.emplace_back((std::stoi(
std::string(&
c)) ? 1 : -1));
631 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d\\s*\\)");
632 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(
line.begin(),
line.end(), neighbors_regex),
634 if (neighbors_tokens.empty()) {
635 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n"
636 <<
" Cannot find any neighbor in line:\n"
637 <<
" '" << &
buffer[0] <<
"'\n";
640 for (
const auto& neighbor : neighbors_tokens) {
641 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
643 short neighbor_wafer(std::stoi(pair_neighbor[1]));
644 short neighbor_cell(std::stoi(pair_neighbor[0]));
645 itr_insert.first->second.emplace(neighbor_wafer, neighbor_cell);
648 if (!l1tCellNeighborsMappingStream.eof())
649 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
650 l1tCellNeighborsMappingStream.close();
654 if (!l1tWaferNeighborsMappingStream.is_open()) {
655 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TWaferNeighborsMapping file\n";
657 for (std::array<char, 512>
buffer; l1tWaferNeighborsMappingStream.getline(&
buffer[0], 512);) {
661 std::vector<std::string> tokens{std::sregex_token_iterator(
line.begin(),
line.end(),
delimiter, -1), {}};
662 if (tokens.size() != 8) {
664 <<
"Syntax error in the L1TWaferNeighborsMapping in line:\n"
665 <<
" '" << &
buffer[0] <<
"'\n"
666 <<
" A line should be composed of 8 integers separated by spaces:\n"
667 <<
" subdet waferid neighbor1 neighbor2 neighbor3 neighbor4 neighbor5 neighbor6\n";
669 short subdet(std::stoi(tokens[0]));
670 short wafer(std::stoi(tokens[1]));
672 std::unordered_map<short, std::vector<short>>* wafer_neighbors;
681 throw cms::Exception(
"BadGeometry") <<
"Unknown subdet " << subdet <<
" in L1TWaferNeighborsMapping:\n"
682 <<
" '" << &
buffer[0] <<
"'\n";
684 auto wafer_itr = wafer_neighbors->emplace(wafer, std::vector<short>());
685 for (
auto neighbor_itr = tokens.cbegin() + 2; neighbor_itr != tokens.cend(); ++neighbor_itr) {
686 wafer_itr.first->second.emplace_back(std::stoi(*neighbor_itr));
693 for (
unsigned layer = 1; layer <= n_layers_ee; layer++) {
695 unsigned wafer = wafer_module.first;
709 for (
unsigned layer = 1; layer <= n_layers_fh; layer++) {
711 unsigned wafer = wafer_module.first;
727 const std::vector<int>& wafer_types)
const {
728 unsigned packed_value = trigger_cell;
729 for (
unsigned i = 0;
i < wafer_types.size();
i++) {
732 if (wafer_types.at(
i) == 1)
733 packed_value += (0
x1 << (8 +
i));
757 bool is_valid =
false;
766 unsigned subdet = cell_det_id.
subdetId();
797 HGCalDetId trigger_cell_det_id(trigger_cell_id);
798 unsigned subdet = trigger_cell_det_id.
subdetId();
800 bool is_valid =
false;
801 for (
const auto cell_id :
cells) {
810 bool is_valid =
false;