42 bool validCell(
const unsigned)
const final;
80 typedef std::unordered_map<int, std::set<std::pair<short, short>>>
neighbor_map;
99 bool validCellId(
unsigned det,
unsigned cell_id)
const;
102 int detIdWaferType(
unsigned det,
unsigned layer,
short waferU,
short waferV)
const;
103 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
105 unsigned packWaferId(
int waferU,
int waferV)
const;
106 unsigned packCellId(
unsigned type,
unsigned cellU,
unsigned cellV)
const;
109 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
110 void unpackLayerWaferId(
unsigned layer_wafer,
unsigned& layer,
unsigned& wafer)
const;
111 void unpackWaferId(
unsigned wafer,
int& waferU,
int& waferV)
const;
112 void unpackCellId(
unsigned cell,
unsigned& cellU,
unsigned& cellV)
const;
120 l1tCellsMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellsMapping")),
121 l1tCellsSciMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellsSciMapping")),
122 l1tWafersMapping_(conf.getParameter<
edm::FileInPath>(
"L1TWafersMapping")),
123 l1tModulesMapping_(conf.getParameter<
edm::FileInPath>(
"L1TModulesMapping")),
124 l1tLinksMapping_(conf.getParameter<
edm::FileInPath>(
"L1TLinksMapping")),
125 l1tCellNeighborsMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellNeighborsMapping")),
126 l1tCellNeighborsSciMapping_(conf.getParameter<
edm::FileInPath>(
"L1TCellNeighborsSciMapping")),
127 hSc_links_per_module_(conf.getParameter<unsigned>(
"ScintillatorLinksPerModule")),
128 hSc_wafers_per_module_(conf.getParameter<unsigned>(
"ScintillatorWafersPerModule")) {
129 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
131 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
152 <<
"HGCalTriggerGeometryV9Imp1 geometry cannot be initialized with the V7/V8 HGCAL geometry";
165 unsigned trigger_layer = 1;
186 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometryV9Imp1 geometry cannot be initialized with the "
187 "HFNose geometry; use HGCalTriggerGeometryV9Imp2";
191 unsigned det =
DetId(cell_id).
det();
194 unsigned tc_type = 1;
196 unsigned wafer_trigger_cell = 0;
197 unsigned trigger_cell = 0;
203 tc_type = cell_det_id.
type();
204 layer = cell_det_id.
layer();
210 <<
"HGCalTriggerGeometry: scintillator cell ieta=" <<
ieta <<
", iphi=" <<
iphi
211 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
214 wafer_trigger_cell = 0;
221 layer = cell_det_id.
layer();
224 int waferu = cell_det_id.
waferU();
225 int waferv = cell_det_id.
waferV();
226 unsigned cellu = cell_det_id.
cellU();
227 unsigned cellv = cell_det_id.
cellV();
231 <<
"HGCalTriggerGeometry: HGCal cell " << cellu <<
"," << cellv <<
" in wafer type " <<
type
232 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
237 <<
"HGCalTriggerGeometry: Wafer " << waferu <<
"," << waferv
238 <<
" is not mapped to any trigger wafer ID. The wafer mapping should be modified.\n";
240 trigger_cell = trigger_cell_itr->second;
241 wafer_trigger_cell = wafer_trigger_cell_itr->second;
253 HGCalDetId trigger_cell_det_id(trigger_cell_id);
266 << trigger_cell_det_id <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer()
267 <<
" is not mapped to any trigger module. The module mapping should be modified. See "
268 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for "
271 module = module_itr->second;
274 trigger_cell_det_id.
zside(),
275 trigger_cell_det_id.
layer(),
283 const unsigned trigger_cell_id)
const {
284 HGCalDetId trigger_cell_det_id(trigger_cell_id);
286 unsigned subdet = trigger_cell_det_id.
subdetId();
287 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
288 unsigned trigger_cell = trigger_cell_det_id.
cell();
289 unsigned layer = trigger_cell_det_id.
layer();
293 const auto& cell_range =
295 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
301 cell_det_ids.emplace(cell_det_id);
310 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Trigger wafer ID " << trigger_wafer
311 <<
" is not mapped to any wafer. The wafer mapping should be modified.\n";
318 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
322 unsigned cell_det_id =
323 HGCSiliconDetId(det, trigger_cell_det_id.
zside(), wafer_type, layer, waferu, waferv, cellu, cellv).rawId();
325 cell_det_ids.emplace(cell_det_id);
334 for (
auto trigger_cell_id : trigger_cells) {
336 cell_det_ids.insert(
cells.begin(),
cells.end());
342 const unsigned module_id)
const {
345 for (
auto trigger_cell_id : trigger_cells) {
347 cell_det_ids.insert(
cells.begin(),
cells.end());
353 const unsigned module_id)
const {
357 unsigned layer = module_det_id.
layer();
363 module_det_id.
zside(),
369 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
376 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
377 unsigned wafer = wafer_itr->second;
389 module_det_id.
zside(),
395 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
399 return trigger_cell_det_ids;
403 const unsigned module_id)
const {
407 unsigned layer = module_det_id.
layer();
413 module_det_id.
zside(),
419 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
426 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
427 unsigned wafer = wafer_itr->second;
439 module_det_id.
zside(),
445 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
449 return trigger_cell_det_ids;
453 const unsigned trigger_cell_id)
const {
454 HGCalDetId trigger_cell_det_id(trigger_cell_id);
456 const auto& neighbors_map =
459 unsigned layer = trigger_cell_det_id.
layer();
464 unsigned trigger_cell = trigger_cell_det_id.
cell();
470 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
471 if (neighbors_itr == neighbors_map.end()) {
472 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell "
473 << trigger_cell <<
" in module " <<
module
474 <<
". The trigger cell neighbor mapping should be modified. \n";
476 const auto& neighbors = neighbors_itr->second;
478 neighbor_detids.reserve(neighbors.size());
479 for (
const auto& module_tc : neighbors) {
481 trigger_cell_det_id.
zside(),
487 neighbor_detids.emplace(neighbor_det_id.rawId());
490 return neighbor_detids;
504 const unsigned sector0_mask = 0x7F;
515 unsigned nWafers = 1;
534 for (
const auto& cell : cell_ids) {
540 for (
const auto& cell : cell_ids) {
547 return GlobalPoint(triggerCellVector / cell_ids.size());
557 for (
const auto& cell : cell_ids) {
563 for (
const auto& cell : cell_ids) {
570 return GlobalPoint(moduleVector / cell_ids.size());
577 if (!l1tModulesMappingStream.is_open()) {
578 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
580 short trigger_wafer = 0;
583 for (; l1tModulesMappingStream >> layer >> trigger_wafer >>
module;) {
587 if (!l1tModulesMappingStream.eof()) {
589 <<
"Error reading L1TModulesMapping '" << layer <<
" " << trigger_wafer <<
" " <<
module <<
"' \n";
591 l1tModulesMappingStream.close();
594 if (!l1tLinksMappingStream.is_open()) {
595 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TLinksMapping file\n";
598 for (; l1tLinksMappingStream >> layer >>
module >>
links;) {
601 <<
"Error reading L1TLinksMapping: (" << layer <<
"," <<
module <<
") is not defined in the module file \n";
605 if (!l1tLinksMappingStream.eof()) {
607 <<
"Error reading L1TLinksMapping '" << layer <<
" " <<
module <<
" " <<
links <<
"' \n";
609 l1tLinksMappingStream.close();
612 if (!l1tCellsMappingStream.is_open()) {
613 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
618 short trigger_cell = 0;
619 for (; l1tCellsMappingStream >>
type >> cellu >> cellv >> trigger_cell;) {
627 if (trigger_cell + 1 > itr_insert.first->second)
628 itr_insert.first->second = trigger_cell + 1;
630 if (!l1tCellsMappingStream.eof()) {
632 <<
"Error reading L1TCellsMapping '" <<
type <<
" " << cellu <<
" " << cellv <<
" " << trigger_cell <<
"' \n";
634 l1tCellsMappingStream.close();
637 if (!l1tCellsSciMappingStream.is_open()) {
638 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsSciMapping file\n";
644 for (; l1tCellsSciMappingStream >>
ieta >>
iphi >> trigger_wafer >> trigger_cell;) {
652 if (trigger_cell + 1 > itr_insert.first->second)
653 itr_insert.first->second = trigger_cell + 1;
655 if (!l1tCellsSciMappingStream.eof()) {
656 throw cms::Exception(
"BadGeometryFile") <<
"Error reading L1TCellsSciMapping '" <<
ieta <<
" " <<
iphi <<
" "
657 << trigger_wafer <<
" " << trigger_cell <<
"' \n";
659 l1tCellsSciMappingStream.close();
662 if (!l1tWafersMappingStream.is_open()) {
663 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TWafersMapping file\n";
668 for (; l1tWafersMappingStream >> waferu >> waferv >> trigger_wafer;) {
674 if (!l1tWafersMappingStream.eof()) {
676 <<
"Error reading L1TWafersMapping '" << waferu <<
" " << waferv <<
" " << trigger_wafer <<
"' \n";
678 l1tWafersMappingStream.close();
685 std::ifstream l1tCellNeighborsMappingStream(
file.fullPath());
686 if (!l1tCellNeighborsMappingStream.is_open()) {
687 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
689 const unsigned line_size = 512;
690 for (std::array<char, line_size>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], line_size);) {
698 std::regex key_regex(scintillator ?
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)"
699 :
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
700 std::vector<std::string> key_tokens{std::sregex_token_iterator(
line.begin(),
line.end(), key_regex), {}};
701 if (key_tokens.empty()) {
702 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n"
703 <<
" Cannot find the trigger cell key in line:\n"
704 <<
" '" << &
buffer[0] <<
"'\n";
706 std::regex digits_regex(
"\\d{1,3}");
707 std::vector<std::string> module_tc{
708 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}};
710 unsigned map_key = 0;
712 int type = std::stoi(module_tc[0]);
713 int module = std::stoi(module_tc[1]);
714 int trigger_cell = std::stoi(module_tc[2]);
717 int module = std::stoi(module_tc[0]);
718 int trigger_cell = std::stoi(module_tc[1]);
725 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
726 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(
line.begin(),
line.end(), neighbors_regex),
728 if ((scintillator && neighbors_tokens.empty()) || (!scintillator && neighbors_tokens.size() < 2)) {
729 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n"
730 <<
" Cannot find any neighbor in line:\n"
731 <<
" '" << &
buffer[0] <<
"'\n";
733 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short, short>>());
735 unsigned first_element = (scintillator ? 0 : 1);
736 for (
unsigned i = first_element;
i < neighbors_tokens.size();
i++) {
737 const auto& neighbor = neighbors_tokens[
i];
738 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
740 short neighbor_module(std::stoi(pair_neighbor[0]));
741 short neighbor_cell(std::stoi(pair_neighbor[1]));
742 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
745 if (!l1tCellNeighborsMappingStream.eof()) {
746 throw cms::Exception(
"BadGeometryFile") <<
"Error reading L1TCellNeighborsMapping'\n";
748 l1tCellNeighborsMappingStream.close();
753 for (
unsigned layer = 1; layer <= n_layers_ee; layer++) {
760 unsigned trigger_wafer = waferuv_wafer.second;
763 for (
int zside : {-1, 1}) {
777 for (
int zside : {-1, 1}) {
794 for (
unsigned layer = first_layer_hsc; layer <= first_layer_hsc + n_layers_hsc; layer++) {
797 unsigned trigger_wafer = module_ncells.first;
799 for (
int trigger_cell = 1; trigger_cell < module_ncells.second; trigger_cell++) {
800 for (
int zside : {-1, 1}) {
815 unsigned packed_value = 0;
816 const int kSubdetMask = 0x7;
824 unsigned packed_value = 0;
837 unsigned packed_value = 0;
844 unsigned packed_value = 0;
852 unsigned packed_value = 0;
853 unsigned waferUabs =
std::abs(waferU);
854 unsigned waferVabs =
std::abs(waferV);
855 unsigned waferUsign = (waferU >= 0) ? 0 : 1;
856 unsigned waferVsign = (waferV >= 0) ? 0 : 1;
865 unsigned packed_value = 0;
904 bool is_valid =
false;
905 unsigned det =
DetId(cell_id).
det();
931 bool disconnected =
false;
951 HGCalDetId trigger_cell_det_id(trigger_cell_id);
952 unsigned subdet = trigger_cell_det_id.
subdetId();
954 bool is_valid =
false;
955 for (
const auto cell_id :
cells) {
964 bool is_valid =
false;
983 unsigned packed_value = 0;
991 unsigned trigger_cell)
const {
992 unsigned packed_value = 0;
1019 layer = detid.
layer();