84 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
117 <<
"HGCalTriggerGeometryHexImp2 geometry cannot be initialized with the V9 HGCAL geometry";
124 int wafer_type = cell_det_id.
waferType();
125 unsigned cell = cell_det_id.
cell();
129 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: HGCal cell " << cell
130 <<
" is not mapped to any trigger cell for the wafer type " << wafer_type
131 <<
". The trigger cell mapping should be modified.\n";
133 unsigned trigger_cell = trigger_cell_itr->second;
147 unsigned wafer = cell_det_id.
wafer();
148 unsigned subdet = cell_det_id.
subdetId();
149 std::unordered_map<short, short>::const_iterator module_itr;
150 bool out_of_range_error =
false;
155 out_of_range_error =
true;
160 out_of_range_error =
true;
163 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet " << subdet <<
"\n";
166 if (out_of_range_error) {
167 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Wafer " << wafer
168 <<
" is not mapped to any trigger module for subdetector " << subdet
169 <<
". The module mapping should be modified. See " 170 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/" 171 "HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
173 unsigned module = module_itr->second;
184 HGCalDetId trigger_cell_det_id(trigger_cell_id);
185 unsigned wafer = trigger_cell_det_id.
wafer();
186 unsigned subdet = trigger_cell_det_id.
subdetId();
189 std::unordered_map<short, short>::const_iterator module_itr;
190 bool out_of_range_error =
false;
195 out_of_range_error =
true;
200 out_of_range_error =
true;
203 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet " << subdet <<
"\n";
206 if (out_of_range_error) {
207 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Wafer " << wafer
208 <<
" is not mapped to any trigger module for subdetector " << subdet
209 <<
". The module mapping should be modified. See " 210 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/" 211 "HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
213 unsigned module = module_itr->second;
215 trigger_cell_det_id.
zside(),
216 trigger_cell_det_id.
layer(),
224 const unsigned trigger_cell_id)
const {
225 HGCalDetId trigger_cell_det_id(trigger_cell_id);
226 unsigned subdet = trigger_cell_det_id.
subdetId();
229 int wafer_type = trigger_cell_det_id.
waferType();
230 unsigned trigger_cell = trigger_cell_det_id.
cell();
234 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
236 trigger_cell_det_id.
zside(),
237 trigger_cell_det_id.
layer(),
239 trigger_cell_det_id.
wafer(),
248 unsigned subdet = module_det_id.
subdetId();
252 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
262 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
266 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
273 module_det_id.
zside(),
274 module_det_id.
layer(),
279 cell_det_ids.emplace(cell_id.rawId());
286 const unsigned module_id)
const {
288 unsigned subdet = module_det_id.
subdetId();
292 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
302 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
306 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
313 module_det_id.
zside(),
314 module_det_id.
layer(),
319 cell_det_ids.emplace(cell_id.rawId());
326 const unsigned module_id)
const {
328 unsigned subdet = module_det_id.
subdetId();
332 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
342 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
347 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
354 module_det_id.
zside(),
355 module_det_id.
layer(),
360 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
363 return trigger_cell_det_ids;
367 const unsigned module_id)
const {
369 unsigned subdet = module_det_id.
subdetId();
373 std::pair<std::unordered_multimap<short, short>::const_iterator, std::unordered_multimap<short, short>::const_iterator>
383 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet " << subdet <<
"\n";
388 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
395 module_det_id.
zside(),
396 module_det_id.
layer(),
401 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
404 return trigger_cell_det_ids;
408 const unsigned trigger_cell_id)
const {
409 HGCalDetId trigger_cell_det_id(trigger_cell_id);
410 unsigned wafer = trigger_cell_det_id.
wafer();
411 int wafer_type = trigger_cell_det_id.
waferType();
412 unsigned subdet = trigger_cell_det_id.
subdetId();
413 unsigned trigger_cell = trigger_cell_det_id.
cell();
418 std::unordered_map<short, std::vector<short>>::const_iterator surrounding_wafers_itr;
419 bool out_of_range_error =
false;
424 out_of_range_error =
true;
429 out_of_range_error =
true;
432 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer neighbours for subdet " << subdet <<
"\n";
435 if (out_of_range_error) {
436 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for wafer " << wafer
437 <<
" in subdetector " << subdet
438 <<
". The wafer neighbor mapping should be modified. \n";
440 const std::vector<short>& surrounding_wafers = surrounding_wafers_itr->second;
442 std::vector<int>
types;
443 types.reserve(surrounding_wafers.size() + 1);
444 types.emplace_back(wafer_type);
445 for (
const auto w : surrounding_wafers) {
453 types.emplace_back(wt);
460 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " 461 << trigger_cell <<
" with wafer configuration " 462 << std::bitset<7>(trigger_cell_key >> 8)
463 <<
". The trigger cell neighbor mapping should be modified. \n";
465 const auto& neighbors = neighbors_itr->second;
467 neighbor_detids.reserve(neighbors.size());
468 for (
const auto& wafer_tc : neighbors) {
469 if (wafer_tc.first - 1 >= (
int)surrounding_wafers.size()) {
471 <<
"HGCalTriggerGeometry: Undefined wafer neighbor number " << wafer_tc.first <<
" for wafer " << wafer
472 <<
" and trigger cell " << trigger_cell <<
". The neighbor mapping files should be modified.";
474 int neighbor_wafer = (wafer_tc.first == 0 ? wafer : surrounding_wafers.at(wafer_tc.first - 1));
475 if (neighbor_wafer == -1)
477 int type = types.at(wafer_tc.first);
479 trigger_cell_det_id.
zside(),
480 trigger_cell_det_id.
layer(),
485 neighbor_detids.emplace(neighbor_det_id.rawId());
488 return neighbor_detids;
499 if (cell_ids.empty())
501 for (
const auto& cell : cell_ids) {
507 return GlobalPoint(triggerCellVector / cell_ids.size());
514 if (cell_ids.empty())
516 for (
const auto& cell : cell_ids) {
522 return GlobalPoint(moduleVector / cell_ids.size());
529 if (!l1tModulesMappingStream.is_open()) {
530 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
535 for (; l1tModulesMappingStream >> subdet >> wafer >> module;) {
556 <<
"Unsupported subdetector number (" << subdet <<
") in L1TModulesMapping file\n";
560 if (!l1tModulesMappingStream.eof())
561 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '" << wafer <<
" " << module <<
"' \n";
562 l1tModulesMappingStream.close();
565 if (!l1tCellsMappingStream.is_open()) {
566 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
570 short triggerCell = 0;
571 for (; l1tCellsMappingStream >> waferType >> cell >> triggerCell;) {
577 if (triggerCell + 1 > itr_insert.first->second)
578 itr_insert.first->second = triggerCell + 1;
580 if (!l1tCellsMappingStream.eof())
582 <<
"Error reading L1TCellsMapping'" << waferType <<
" " << cell <<
" " << triggerCell <<
"' \n";
583 l1tCellsMappingStream.close();
589 if (!l1tCellNeighborsMappingStream.is_open()) {
590 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
592 for (std::array<char, 512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512);) {
599 std::regex key_regex(
"\\(\\s*[01]{7}\\s*,\\s*\\d{1,3}\\s*\\)");
600 std::vector<std::string> key_tokens{std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}};
601 if (key_tokens.size() != 1) {
602 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 603 <<
" Cannot find the trigger cell key in line:\n" 604 <<
" '" << &
buffer[0] <<
"'\n";
606 std::regex digits_regex(
"([01]{7})|(\\d{1,3})");
607 std::vector<std::string> type_tc{
608 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}};
610 int trigger_cell = std::stoi(type_tc[1]);
611 std::vector<int> wafer_types;
612 wafer_types.reserve(type_tc[0].
size());
614 for (
const char c : type_tc[0])
615 wafer_types.emplace_back((std::stoi(
std::string(&
c)) ? 1 : -1));
621 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d\\s*\\)");
622 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex),
624 if (neighbors_tokens.empty()) {
625 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 626 <<
" Cannot find any neighbor in line:\n" 627 <<
" '" << &
buffer[0] <<
"'\n";
630 for (
const auto& neighbor : neighbors_tokens) {
631 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
633 short neighbor_wafer(std::stoi(pair_neighbor[1]));
634 short neighbor_cell(std::stoi(pair_neighbor[0]));
635 itr_insert.first->second.emplace(neighbor_wafer, neighbor_cell);
638 if (!l1tCellNeighborsMappingStream.eof())
639 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
640 l1tCellNeighborsMappingStream.close();
644 if (!l1tWaferNeighborsMappingStream.is_open()) {
645 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TWaferNeighborsMapping file\n";
647 for (std::array<char, 512>
buffer; l1tWaferNeighborsMappingStream.getline(&
buffer[0], 512);) {
651 std::vector<std::string> tokens{std::sregex_token_iterator(line.begin(), line.end(),
delimiter, -1), {}};
652 if (tokens.size() != 8) {
654 <<
"Syntax error in the L1TWaferNeighborsMapping in line:\n" 655 <<
" '" << &
buffer[0] <<
"'\n" 656 <<
" A line should be composed of 8 integers separated by spaces:\n" 657 <<
" subdet waferid neighbor1 neighbor2 neighbor3 neighbor4 neighbor5 neighbor6\n";
659 short subdet(std::stoi(tokens[0]));
660 short wafer(std::stoi(tokens[1]));
662 std::unordered_map<short, std::vector<short>>* wafer_neighbors;
671 throw cms::Exception(
"BadGeometry") <<
"Unknown subdet " << subdet <<
" in L1TWaferNeighborsMapping:\n" 672 <<
" '" << &
buffer[0] <<
"'\n";
674 auto wafer_itr = wafer_neighbors->emplace(wafer, std::vector<short>());
675 for (
auto neighbor_itr = tokens.cbegin() + 2; neighbor_itr != tokens.cend(); ++neighbor_itr) {
676 wafer_itr.first->second.emplace_back(std::stoi(*neighbor_itr));
683 for (
unsigned layer = 1; layer <= n_layers_ee; layer++) {
685 unsigned wafer = wafer_module.first;
699 for (
unsigned layer = 1; layer <= n_layers_fh; layer++) {
701 unsigned wafer = wafer_module.first;
717 const std::vector<int>& wafer_types)
const {
718 unsigned packed_value = trigger_cell;
719 for (
unsigned i = 0;
i < wafer_types.size();
i++) {
722 if (wafer_types.at(
i) == 1)
723 packed_value += (0
x1 << (8 +
i));
761 HGCalDetId trigger_cell_det_id(trigger_cell_id);
762 unsigned subdet = trigger_cell_det_id.
subdetId();
765 for (
const auto cell_id : cells) {
edm::FileInPath l1tWaferNeighborsMapping_
std::unordered_map< short, short > number_cells_in_wafers_
std::unordered_map< short, short > number_trigger_cells_in_wafers_
bool is_valid(const Digi &d)
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
edm::FileInPath l1tModulesMapping_
Global3DPoint GlobalPoint
constexpr uint32_t rawId() const
get the raw id
unsigned packTriggerCell(unsigned, const std::vector< int > &) const
void initialize(const CaloGeometry *) final
std::multimap< std::pair< short, short >, short > trigger_cells_to_cells_
GlobalPoint getPosition(const DetId &id) const
std::unordered_multimap< short, short > module_to_wafers_fh_
std::unordered_set< unsigned > invalid_triggercells_
edm::FileInPath l1tCellsMapping_
GlobalPoint getTriggerCellPosition(const unsigned) const final
unsigned getLinksInModule(const unsigned module_id) const final
geom_set getNeighborsFromTriggerCell(const unsigned) const final
bool disconnectedModule(const unsigned) const final
bool validCellId(unsigned subdet, unsigned cell_id) const
static const int kHGCalCellMask
unsigned getTriggerCellFromCell(const unsigned) const final
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
const HGCalGeometry * fhGeometry() const
std::unordered_map< short, std::vector< short > > wafer_neighbors_fh_
std::unordered_map< short, std::vector< short > > wafer_neighbors_ee_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
std::unordered_multimap< short, short > module_to_wafers_ee_
std::map< std::pair< short, short >, short > cells_to_trigger_cells_
int wafer() const
get the wafer #
unsigned lastTriggerLayer() const final
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_
geom_set getCellsFromModule(const unsigned) const final
std::unordered_map< short, short > wafer_to_module_ee_
geom_set getCellsFromTriggerCell(const unsigned) const final
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
unsigned getModuleFromCell(const unsigned) const final
void setCaloGeometry(const CaloGeometry *geom)
int cell() const
get the absolute value of the cell #'s in x and y
const HGCalDDDConstants & dddConstants() const
unsigned getModuleSize(const unsigned module_id) const final
std::unordered_map< short, short > wafer_to_module_fh_
std::set< unsigned > geom_ordered_set
bool validTriggerCell(const unsigned) const final
std::unordered_set< unsigned > geom_set
std::string fullPath() const
int detIdWaferType(unsigned subdet, short wafer) const
int waferType() const
get the wafer type
geom_set getTriggerCellsFromModule(const unsigned) const final
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned getModuleFromTriggerCell(const unsigned) const final
unsigned triggerLayer(const unsigned) const final
bool valid(const DetId &id) const override
Is this a valid cell id.
bool validTriggerCellFromCells(const unsigned) const
int waferTypeT(int wafer) const
GlobalPoint getModulePosition(const unsigned) const final
edm::FileInPath l1tCellNeighborsMapping_
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
void fillInvalidTriggerCells()
HGCalTriggerGeometryHexImp2(const edm::ParameterSet &conf)