87 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
92 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
94 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
107 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
109 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
133 unsigned trigger_layer = 1;
154 <<
"HGCalTriggerGeometryHexLayerBasedImp1 geometry cannot be initialized with the V9 HGCAL geometry";
161 unsigned wafer_trigger_cell = 0;
162 unsigned trigger_cell = 0;
170 layer = cell_det_id.
depth();
172 zside = cell_det_id.
zside();
176 <<
"HGCalTriggerGeometry: Hcal cell ieta=" << ieta <<
", iphi=" << iphi
177 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
180 wafer_trigger_cell = 0;
187 layer = cell_det_id.
layer();
188 zside = cell_det_id.
zside();
189 unsigned wafer = cell_det_id.
wafer();
190 unsigned cell = cell_det_id.
cell();
194 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" in wafer " << wafer
195 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
198 wafer_trigger_cell = 0;
209 HGCalDetId trigger_cell_det_id(trigger_cell_id);
214 module = trigger_cell_det_id.
wafer();
221 << trigger_cell_det_id <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer()
222 <<
" is not mapped to any trigger module. The module mapping should be modified. See " 223 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for " 226 module = module_itr->second;
229 trigger_cell_det_id.
zside(),
230 trigger_cell_det_id.
layer(),
231 (trigger_cell_det_id.
waferType() == 1 ? 1 : 0),
238 const unsigned trigger_cell_id)
const {
239 HGCalDetId trigger_cell_det_id(trigger_cell_id);
243 unsigned subdet = trigger_cell_det_id.
subdetId();
244 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
245 unsigned trigger_cell = trigger_cell_det_id.
cell();
246 const auto& cell_range =
248 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
252 unsigned cell_det_id =
255 cell_det_ids.emplace(cell_det_id);
260 unsigned subdet = trigger_cell_det_id.
subdetId();
261 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
262 unsigned trigger_cell = trigger_cell_det_id.
cell();
264 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
268 unsigned wafer_type = (
detIdWaferType(subdet, wafer) == 1 ? 1 : 0);
270 trigger_cell_det_id.
zside(),
271 trigger_cell_det_id.
layer(),
277 cell_det_ids.emplace(cell_det_id);
284 const unsigned module_id)
const {
287 for (
auto trigger_cell_id : trigger_cells) {
289 cell_det_ids.insert(cells.begin(), cells.end());
295 const unsigned module_id)
const {
298 for (
auto trigger_cell_id : trigger_cells) {
300 cell_det_ids.insert(cells.begin(), cells.end());
306 const unsigned module_id)
const {
315 module_det_id.
zside(),
316 module_det_id.
layer(),
321 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
329 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
330 unsigned wafer = wafer_itr->second;
334 module_det_id.
zside(),
335 module_det_id.
layer(),
340 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
344 return trigger_cell_det_ids;
348 const unsigned module_id)
const {
357 module_det_id.
zside(),
358 module_det_id.
layer(),
363 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
371 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
372 unsigned wafer = wafer_itr->second;
376 module_det_id.
zside(),
377 module_det_id.
layer(),
382 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
386 return trigger_cell_det_ids;
390 const unsigned trigger_cell_id)
const {
391 HGCalDetId trigger_cell_det_id(trigger_cell_id);
396 unsigned trigger_cell = trigger_cell_det_id.
cell();
400 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
401 if (neighbors_itr == neighbors_map.end()) {
402 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " 403 << trigger_cell <<
" in module " << module
404 <<
". The trigger cell neighbor mapping should be modified. \n";
406 const auto& neighbors = neighbors_itr->second;
408 neighbor_detids.reserve(neighbors.size());
409 for (
const auto& module_tc : neighbors) {
411 trigger_cell_det_id.
zside(),
412 trigger_cell_det_id.
layer(),
417 neighbor_detids.emplace(neighbor_det_id.rawId());
420 return neighbor_detids;
434 for (
const auto& cell : cell_ids) {
441 for (
const auto& cell : cell_ids) {
448 return GlobalPoint(triggerCellVector / cell_ids.size());
458 for (
const auto& cell : cell_ids) {
465 for (
const auto& cell : cell_ids) {
472 return GlobalPoint(moduleVector / cell_ids.size());
479 if (!l1tModulesMappingStream.is_open()) {
480 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
482 short trigger_wafer = 0;
484 for (; l1tModulesMappingStream >> trigger_wafer >> module;) {
490 if (!l1tModulesMappingStream.eof())
492 <<
"Error reading L1TModulesMapping '" << trigger_wafer <<
" " << module <<
"' \n";
493 l1tModulesMappingStream.close();
496 if (!l1tCellsMappingStream.is_open()) {
497 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
503 short trigger_cell = 0;
504 for (; l1tCellsMappingStream >> subdet >> wafer >> cell >> trigger_wafer >> trigger_cell;) {
506 unsigned trigger_cell_key =
packWaferCellId(subdet, trigger_wafer, trigger_cell);
512 if (trigger_cell + 1 > itr_insert.first->second)
513 itr_insert.first->second = trigger_cell + 1;
515 if (!l1tCellsMappingStream.eof())
516 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping '" << subdet <<
" " << wafer <<
" " 517 << cell <<
" " << trigger_wafer <<
" " << trigger_cell <<
"' \n";
518 l1tCellsMappingStream.close();
521 if (!l1tCellsBHMappingStream.is_open()) {
522 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsBHMapping file\n";
528 for (; l1tCellsBHMappingStream >> ieta >> iphi >> trigger_wafer >> trigger_cell;) {
536 if (trigger_cell + 1 > itr_insert.first->second)
537 itr_insert.first->second = trigger_cell + 1;
539 if (!l1tCellsBHMappingStream.eof())
540 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsBHMapping '" << ieta <<
" " << iphi <<
" " 541 << trigger_wafer <<
" " << trigger_cell <<
"' \n";
542 l1tCellsBHMappingStream.close();
546 const edm::FileInPath&
file, std::unordered_map<
int, std::set<std::pair<short, short>>>& neighbors_map) {
548 std::ifstream l1tCellNeighborsMappingStream(file.
fullPath());
549 if (!l1tCellNeighborsMappingStream.is_open()) {
550 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
552 for (std::array<char, 512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512);) {
559 std::regex key_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
560 std::vector<std::string> key_tokens{std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}};
561 if (key_tokens.empty()) {
562 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 563 <<
" Cannot find the trigger cell key in line:\n" 564 <<
" '" << &
buffer[0] <<
"'\n";
566 std::regex digits_regex(
"\\d{1,3}");
567 std::vector<std::string> module_tc{
568 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}};
570 int module = std::stoi(module_tc[0]);
571 int trigger_cell = std::stoi(module_tc[1]);
577 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
578 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex),
580 if (neighbors_tokens.size() < 2) {
581 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 582 <<
" Cannot find any neighbor in line:\n" 583 <<
" '" << &
buffer[0] <<
"'\n";
585 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short, short>>());
587 for (
unsigned i = 1;
i < neighbors_tokens.size();
i++) {
588 const auto& neighbor = neighbors_tokens[
i];
589 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
591 short neighbor_module(std::stoi(pair_neighbor[0]));
592 short neighbor_cell(std::stoi(pair_neighbor[1]));
593 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
596 if (!l1tCellNeighborsMappingStream.eof())
597 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
598 l1tCellNeighborsMappingStream.close();
603 for (
unsigned layer = 1; layer <= n_layers_ee; layer++) {
605 unsigned wafer = wafer_module.first;
608 std::set<unsigned> trigger_cell_ids;
613 for (
unsigned trigger_cell : trigger_cell_ids) {
627 unsigned packed_value = 0;
628 const int kSubdetMask = 0x7;
636 unsigned packed_value = 0;
644 unsigned& cell)
const {
659 bool disconnected =
false;
679 HGCalDetId trigger_cell_det_id(trigger_cell_id);
680 unsigned subdet = trigger_cell_det_id.
subdetId();
683 for (
const auto cell_id : cells) {
711 unsigned packed_value = 0;
740 layer = detid.
layer();
754 "HGCalTriggerGeometryHexLayerBasedImp1");
std::unordered_set< unsigned > disconnected_modules_
T getParameter(std::string const &) const
HGCalTriggerGeometryHexLayerBasedImp1(const edm::ParameterSet &conf)
std::unordered_multimap< unsigned, unsigned > module_to_wafers_
const HcalDDDRecConstants * dddConstants() const
void fillInvalidTriggerCells()
edm::FileInPath l1tCellNeighborsBHMapping_
unsigned triggerLayer(const unsigned) const final
bool valid(const DetId &id) const override
static uint32_t kHcalEtaMask2
bool is_valid(const Digi &d)
unsigned lastTriggerLayer() const final
int zside() const
get the z-side of the cell (1/-1)
std::unordered_multimap< unsigned, unsigned > trigger_cells_to_cells_
std::unordered_map< unsigned, unsigned short > number_trigger_cells_in_wafers_bh_
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
int detIdWaferType(unsigned subdet, short wafer) const
Global3DPoint GlobalPoint
constexpr uint32_t rawId() const
get the raw id
edm::FileInPath l1tCellsBHMapping_
static const int kHGCalWaferTypeOffset
GlobalPoint getPosition(const DetId &id) const
unsigned packIetaIphi(unsigned ieta, unsigned iphi) const
std::vector< unsigned > trigger_layers_
std::unordered_map< unsigned, unsigned > cells_to_trigger_cells_
edm::FileInPath l1tModulesMapping_
bool validCellId(unsigned subdet, unsigned cell_id) const
unsigned getModuleFromTriggerCell(const unsigned) const final
unsigned getLinksInModule(const unsigned module_id) const final
void fillNeighborMaps(const edm::FileInPath &, std::unordered_map< int, std::set< std::pair< short, short >>> &)
std::unordered_map< unsigned, unsigned short > number_trigger_cells_in_wafers_
void unpackWaferCellId(unsigned wafer_cell, unsigned &wafer, unsigned &cell) const
static const int kHGCalCellOffset
static const int kHGCalCellMask
int depth() const
get the tower depth
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
const HcalTopology & bhTopology() const
void unpackIetaIphi(unsigned ieta_iphi, unsigned &ieta, unsigned &iphi) const
unsigned packWaferCellId(unsigned subdet, unsigned wafer, unsigned cell) const
bool disconnectedModule(const unsigned) const final
std::unordered_map< unsigned, unsigned > cells_to_trigger_cells_bh_
std::unordered_set< unsigned > invalid_triggercells_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
geom_set getCellsFromModule(const unsigned) const final
GlobalPoint getTriggerCellPosition(const unsigned) const final
void initialize(const CaloGeometry *) final
unsigned packTriggerCell(unsigned, unsigned) const
int wafer() const
get the wafer #
bool validTriggerCell(const unsigned) const final
GlobalPoint getPosition(const DetId &id) const
edm::FileInPath l1tCellNeighborsMapping_
const HcalGeometry * bhGeometry() const
int ietaAbs() const
get the absolute value of the cell ieta
int iphi() const
get the cell iphi
std::unordered_map< unsigned, unsigned > wafer_to_module_
void setCaloGeometry(const CaloGeometry *geom)
int cell() const
get the absolute value of the cell #'s in x and y
const HGCalDDDConstants & dddConstants() const
static uint32_t kHcalPhiMask2
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_bh_
int getMaxDepth(const int &type) const
static uint32_t kHcalEtaOffset2
geom_set getNeighborsFromTriggerCell(const unsigned) const final
static const int kHGCalWaferOffset
std::unordered_multimap< unsigned, unsigned > trigger_cells_to_cells_bh_
std::set< unsigned > geom_ordered_set
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
bool validTriggerCellFromCells(const unsigned) const
GlobalPoint getModulePosition(const unsigned) const final
geom_set getCellsFromTriggerCell(const unsigned) const final
unsigned layerWithOffset(unsigned) const
std::unordered_set< unsigned > geom_set
unsigned last_trigger_layer_
unsigned getModuleFromCell(const unsigned) const final
std::string fullPath() const
edm::FileInPath l1tCellsMapping_
int waferType() const
get the wafer type
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::unordered_set< unsigned > disconnected_layers_
bool valid(const DetId &id) const override
Is this a valid cell id.
unsigned getModuleSize(const unsigned module_id) const final
const BasicVectorType & basicVector() const
int waferTypeT(int wafer) const
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
geom_set getTriggerCellsFromModule(const unsigned) const final
static const int kHGCalWaferMask