84 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
89 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
90 unsigned packIetaIphi(
unsigned ieta,
unsigned iphi)
const;
91 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
92 void unpackIetaIphi(
unsigned ieta_iphi,
unsigned& ieta,
unsigned& iphi)
const;
104 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
106 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
130 unsigned trigger_layer = 1;
150 <<
"HGCalTriggerGeometryHexLayerBasedImp1 geometry cannot be initialized with the V9 HGCAL geometry";
157 unsigned wafer_trigger_cell = 0;
158 unsigned trigger_cell = 0;
164 unsigned ieta = cell_det_id.
ietaAbs();
165 unsigned iphi = cell_det_id.
iphi();
166 layer = cell_det_id.
depth();
168 zside = cell_det_id.
zside();
172 <<
"HGCalTriggerGeometry: Hcal cell ieta=" << ieta <<
", iphi=" << iphi
173 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
176 wafer_trigger_cell = 0;
183 layer = cell_det_id.
layer();
184 zside = cell_det_id.
zside();
185 unsigned wafer = cell_det_id.
wafer();
186 unsigned cell = cell_det_id.
cell();
190 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" in wafer " << wafer
191 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
194 wafer_trigger_cell = 0;
205 HGCalDetId trigger_cell_det_id(trigger_cell_id);
210 module = trigger_cell_det_id.
wafer();
217 << trigger_cell_det_id <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer()
218 <<
" is not mapped to any trigger module. The module mapping should be modified. See " 219 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for " 222 module = module_itr->second;
225 trigger_cell_det_id.
zside(),
226 trigger_cell_det_id.
layer(),
227 (trigger_cell_det_id.
waferType() == 1 ? 1 : 0),
234 const unsigned trigger_cell_id)
const {
235 HGCalDetId trigger_cell_det_id(trigger_cell_id);
239 unsigned subdet = trigger_cell_det_id.
subdetId();
240 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
241 unsigned trigger_cell = trigger_cell_det_id.
cell();
242 const auto& cell_range =
244 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
248 unsigned cell_det_id =
251 cell_det_ids.emplace(cell_det_id);
256 unsigned subdet = trigger_cell_det_id.
subdetId();
257 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
258 unsigned trigger_cell = trigger_cell_det_id.
cell();
260 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
264 unsigned wafer_type = (
detIdWaferType(subdet, wafer) == 1 ? 1 : 0);
266 trigger_cell_det_id.
zside(),
267 trigger_cell_det_id.
layer(),
273 cell_det_ids.emplace(cell_det_id);
280 const unsigned module_id)
const {
283 for (
auto trigger_cell_id : trigger_cells) {
285 cell_det_ids.insert(cells.begin(), cells.end());
291 const unsigned module_id)
const {
294 for (
auto trigger_cell_id : trigger_cells) {
296 cell_det_ids.insert(cells.begin(), cells.end());
302 const unsigned module_id)
const {
311 module_det_id.
zside(),
312 module_det_id.
layer(),
317 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
325 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
326 unsigned wafer = wafer_itr->second;
330 module_det_id.
zside(),
331 module_det_id.
layer(),
336 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
340 return trigger_cell_det_ids;
344 const unsigned module_id)
const {
353 module_det_id.
zside(),
354 module_det_id.
layer(),
359 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
367 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
368 unsigned wafer = wafer_itr->second;
372 module_det_id.
zside(),
373 module_det_id.
layer(),
378 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
382 return trigger_cell_det_ids;
386 const unsigned trigger_cell_id)
const {
387 HGCalDetId trigger_cell_det_id(trigger_cell_id);
392 unsigned trigger_cell = trigger_cell_det_id.
cell();
396 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
397 if (neighbors_itr == neighbors_map.end()) {
398 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " 399 << trigger_cell <<
" in module " << module
400 <<
". The trigger cell neighbor mapping should be modified. \n";
402 const auto& neighbors = neighbors_itr->second;
404 neighbor_detids.reserve(neighbors.size());
405 for (
const auto& module_tc : neighbors) {
407 trigger_cell_det_id.
zside(),
408 trigger_cell_det_id.
layer(),
413 neighbor_detids.emplace(neighbor_det_id.rawId());
416 return neighbor_detids;
426 for (
const auto& cell : cell_ids) {
433 for (
const auto& cell : cell_ids) {
440 return GlobalPoint(triggerCellVector / cell_ids.size());
450 for (
const auto& cell : cell_ids) {
457 for (
const auto& cell : cell_ids) {
464 return GlobalPoint(moduleVector / cell_ids.size());
471 if (!l1tModulesMappingStream.is_open()) {
472 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
474 short trigger_wafer = 0;
476 for (; l1tModulesMappingStream >> trigger_wafer >> module;) {
482 if (!l1tModulesMappingStream.eof())
484 <<
"Error reading L1TModulesMapping '" << trigger_wafer <<
" " << module <<
"' \n";
485 l1tModulesMappingStream.close();
488 if (!l1tCellsMappingStream.is_open()) {
489 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
495 short trigger_cell = 0;
496 for (; l1tCellsMappingStream >> subdet >> wafer >> cell >> trigger_wafer >> trigger_cell;) {
498 unsigned trigger_cell_key =
packWaferCellId(subdet, trigger_wafer, trigger_cell);
504 if (trigger_cell + 1 > itr_insert.first->second)
505 itr_insert.first->second = trigger_cell + 1;
507 if (!l1tCellsMappingStream.eof())
508 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping '" << subdet <<
" " << wafer <<
" " 509 << cell <<
" " << trigger_wafer <<
" " << trigger_cell <<
"' \n";
510 l1tCellsMappingStream.close();
513 if (!l1tCellsBHMappingStream.is_open()) {
514 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsBHMapping file\n";
520 for (; l1tCellsBHMappingStream >> ieta >> iphi >> trigger_wafer >> trigger_cell;) {
528 if (trigger_cell + 1 > itr_insert.first->second)
529 itr_insert.first->second = trigger_cell + 1;
531 if (!l1tCellsBHMappingStream.eof())
532 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsBHMapping '" << ieta <<
" " << iphi <<
" " 533 << trigger_wafer <<
" " << trigger_cell <<
"' \n";
534 l1tCellsBHMappingStream.close();
538 const edm::FileInPath&
file, std::unordered_map<
int, std::set<std::pair<short, short>>>& neighbors_map) {
540 std::ifstream l1tCellNeighborsMappingStream(file.
fullPath());
541 if (!l1tCellNeighborsMappingStream.is_open()) {
542 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
544 for (std::array<char, 512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512);) {
551 std::regex key_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
552 std::vector<std::string> key_tokens{std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}};
553 if (key_tokens.empty()) {
554 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 555 <<
" Cannot find the trigger cell key in line:\n" 556 <<
" '" << &
buffer[0] <<
"'\n";
558 std::regex digits_regex(
"\\d{1,3}");
559 std::vector<std::string> module_tc{
560 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}};
562 int module = std::stoi(module_tc[0]);
563 int trigger_cell = std::stoi(module_tc[1]);
569 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
570 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex),
572 if (neighbors_tokens.size() < 2) {
573 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 574 <<
" Cannot find any neighbor in line:\n" 575 <<
" '" << &
buffer[0] <<
"'\n";
577 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short, short>>());
579 for (
unsigned i = 1;
i < neighbors_tokens.size();
i++) {
580 const auto& neighbor = neighbors_tokens[
i];
581 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
583 short neighbor_module(std::stoi(pair_neighbor[0]));
584 short neighbor_cell(std::stoi(pair_neighbor[1]));
585 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
588 if (!l1tCellNeighborsMappingStream.eof())
589 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
590 l1tCellNeighborsMappingStream.close();
595 for (
unsigned layer = 1; layer <= n_layers_ee; layer++) {
597 unsigned wafer = wafer_module.first;
600 std::set<unsigned> trigger_cell_ids;
605 for (
unsigned trigger_cell : trigger_cell_ids) {
619 unsigned packed_value = 0;
620 const int kSubdetMask = 0x7;
628 unsigned packed_value = 0;
636 unsigned& cell)
const {
651 bool disconnected =
false;
671 HGCalDetId trigger_cell_det_id(trigger_cell_id);
672 unsigned subdet = trigger_cell_det_id.
subdetId();
675 for (
const auto cell_id : cells) {
703 unsigned packed_value = 0;
732 layer = detid.
layer();
746 "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_
void initialize(const edm::ESHandle< CaloGeometry > &) final
unsigned triggerLayer(const unsigned) const final
bool valid(const DetId &id) const override
static uint32_t kHcalEtaMask2
bool is_valid(const Digi &d)
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
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
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_
void setCaloGeometry(const edm::ESHandle< CaloGeometry > &geom)
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_
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 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.
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