77 typedef std::unordered_map<int, std::set<std::pair<short, short>>>
neighbor_map;
96 bool validCellId(
unsigned det,
unsigned cell_id)
const;
99 int detIdWaferType(
unsigned det,
unsigned layer,
short waferU,
short waferV)
const;
100 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
102 unsigned packWaferId(
int waferU,
int waferV)
const;
103 unsigned packCellId(
unsigned type,
unsigned cellU,
unsigned cellV)
const;
106 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
107 void unpackLayerWaferId(
unsigned layer_wafer,
unsigned& layer,
unsigned& wafer)
const;
108 void unpackWaferId(
unsigned wafer,
int& waferU,
int& waferV)
const;
109 void unpackCellId(
unsigned cell,
unsigned& cellU,
unsigned& cellV)
const;
126 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
128 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
149 <<
"HGCalTriggerGeometryV9Imp1 geometry cannot be initialized with the V7/V8 HGCAL geometry";
162 unsigned trigger_layer = 1;
180 unsigned det =
DetId(cell_id).
det();
183 unsigned tc_type = 1;
185 unsigned wafer_trigger_cell = 0;
186 unsigned trigger_cell = 0;
192 tc_type = cell_det_id.
type();
193 layer = cell_det_id.
layer();
195 zside = cell_det_id.
zside();
199 <<
"HGCalTriggerGeometry: scintillator cell ieta=" << ieta <<
", iphi=" << iphi
200 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
203 wafer_trigger_cell = 0;
210 layer = cell_det_id.
layer();
211 zside = cell_det_id.
zside();
213 int waferu = cell_det_id.
waferU();
214 int waferv = cell_det_id.
waferV();
215 unsigned cellu = cell_det_id.
cellU();
216 unsigned cellv = cell_det_id.
cellV();
220 <<
"HGCalTriggerGeometry: HGCal cell " << cellu <<
"," << cellv <<
" in wafer type " << type
221 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
226 <<
"HGCalTriggerGeometry: Wafer " << waferu <<
"," << waferv
227 <<
" is not mapped to any trigger wafer ID. The wafer mapping should be modified.\n";
229 trigger_cell = trigger_cell_itr->second;
230 wafer_trigger_cell = wafer_trigger_cell_itr->second;
242 HGCalDetId trigger_cell_det_id(trigger_cell_id);
247 module = trigger_cell_det_id.
wafer();
255 << trigger_cell_det_id <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer()
256 <<
" is not mapped to any trigger module. The module mapping should be modified. See " 257 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for " 260 module = module_itr->second;
263 trigger_cell_det_id.
zside(),
264 trigger_cell_det_id.
layer(),
272 const unsigned trigger_cell_id)
const {
273 HGCalDetId trigger_cell_det_id(trigger_cell_id);
275 unsigned subdet = trigger_cell_det_id.
subdetId();
276 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
277 unsigned trigger_cell = trigger_cell_det_id.
cell();
278 unsigned layer = trigger_cell_det_id.
layer();
282 const auto& cell_range =
284 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
290 cell_det_ids.emplace(cell_det_id);
299 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Trigger wafer ID " << trigger_wafer
300 <<
" is not mapped to any wafer. The wafer mapping should be modified.\n";
307 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
311 unsigned cell_det_id =
312 HGCSiliconDetId(det, trigger_cell_det_id.
zside(), wafer_type, layer, waferu, waferv, cellu, cellv).rawId();
314 cell_det_ids.emplace(cell_det_id);
323 for (
auto trigger_cell_id : trigger_cells) {
325 cell_det_ids.insert(cells.begin(), cells.end());
331 const unsigned module_id)
const {
334 for (
auto trigger_cell_id : trigger_cells) {
336 cell_det_ids.insert(cells.begin(), cells.end());
342 const unsigned module_id)
const {
346 unsigned layer = module_det_id.
layer();
352 module_det_id.
zside(),
358 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
365 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
366 unsigned wafer = wafer_itr->second;
378 module_det_id.
zside(),
384 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
388 return trigger_cell_det_ids;
392 const unsigned module_id)
const {
396 unsigned layer = module_det_id.
layer();
402 module_det_id.
zside(),
408 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
415 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
416 unsigned wafer = wafer_itr->second;
428 module_det_id.
zside(),
434 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
438 return trigger_cell_det_ids;
442 const unsigned trigger_cell_id)
const {
443 HGCalDetId trigger_cell_det_id(trigger_cell_id);
445 const auto& neighbors_map =
448 unsigned layer = trigger_cell_det_id.
layer();
453 unsigned trigger_cell = trigger_cell_det_id.
cell();
459 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
460 if (neighbors_itr == neighbors_map.end()) {
461 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " 462 << trigger_cell <<
" in module " << module
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& module_tc : neighbors) {
470 trigger_cell_det_id.
zside(),
476 neighbor_detids.emplace(neighbor_det_id.rawId());
479 return neighbor_detids;
493 const unsigned sector0_mask = 0x7F;
494 module = (module & sector0_mask);
504 unsigned nWafers = 1;
523 for (
const auto& cell : cell_ids) {
529 for (
const auto& cell : cell_ids) {
536 return GlobalPoint(triggerCellVector / cell_ids.size());
546 for (
const auto& cell : cell_ids) {
552 for (
const auto& cell : cell_ids) {
559 return GlobalPoint(moduleVector / cell_ids.size());
566 if (!l1tModulesMappingStream.is_open()) {
567 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
569 short trigger_wafer = 0;
572 for (; l1tModulesMappingStream >> layer >> trigger_wafer >> module;) {
576 if (!l1tModulesMappingStream.eof()) {
578 <<
"Error reading L1TModulesMapping '" << layer <<
" " << trigger_wafer <<
" " << module <<
"' \n";
580 l1tModulesMappingStream.close();
583 if (!l1tLinksMappingStream.is_open()) {
584 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TLinksMapping file\n";
587 for (; l1tLinksMappingStream >> layer >> module >>
links;) {
590 <<
"Error reading L1TLinksMapping: (" << layer <<
"," << module <<
") is not defined in the module file \n";
594 if (!l1tLinksMappingStream.eof()) {
596 <<
"Error reading L1TLinksMapping '" << layer <<
" " << module <<
" " << links <<
"' \n";
598 l1tLinksMappingStream.close();
601 if (!l1tCellsMappingStream.is_open()) {
602 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
607 short trigger_cell = 0;
608 for (; l1tCellsMappingStream >> type >> cellu >> cellv >> trigger_cell;) {
609 unsigned cell_key =
packCellId(type, cellu, cellv);
610 unsigned trigger_cell_key =
packCellId(type, trigger_cell);
616 if (trigger_cell + 1 > itr_insert.first->second)
617 itr_insert.first->second = trigger_cell + 1;
619 if (!l1tCellsMappingStream.eof()) {
621 <<
"Error reading L1TCellsMapping '" << type <<
" " << cellu <<
" " << cellv <<
" " << trigger_cell <<
"' \n";
623 l1tCellsMappingStream.close();
626 if (!l1tCellsSciMappingStream.is_open()) {
627 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsSciMapping file\n";
633 for (; l1tCellsSciMappingStream >> ieta >> iphi >> trigger_wafer >> trigger_cell;) {
641 if (trigger_cell + 1 > itr_insert.first->second)
642 itr_insert.first->second = trigger_cell + 1;
644 if (!l1tCellsSciMappingStream.eof()) {
645 throw cms::Exception(
"BadGeometryFile") <<
"Error reading L1TCellsSciMapping '" << ieta <<
" " << iphi <<
" " 646 << trigger_wafer <<
" " << trigger_cell <<
"' \n";
648 l1tCellsSciMappingStream.close();
651 if (!l1tWafersMappingStream.is_open()) {
652 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TWafersMapping file\n";
657 for (; l1tWafersMappingStream >> waferu >> waferv >> trigger_wafer;) {
663 if (!l1tWafersMappingStream.eof()) {
665 <<
"Error reading L1TWafersMapping '" << waferu <<
" " << waferv <<
" " << trigger_wafer <<
"' \n";
667 l1tWafersMappingStream.close();
674 std::ifstream l1tCellNeighborsMappingStream(file.
fullPath());
675 if (!l1tCellNeighborsMappingStream.is_open()) {
676 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
678 const unsigned line_size = 512;
679 for (std::array<char, line_size>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], line_size);) {
687 std::regex key_regex(scintillator ?
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)" 688 :
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
689 std::vector<std::string> key_tokens{std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}};
690 if (key_tokens.empty()) {
691 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 692 <<
" Cannot find the trigger cell key in line:\n" 693 <<
" '" << &
buffer[0] <<
"'\n";
695 std::regex digits_regex(
"\\d{1,3}");
696 std::vector<std::string> module_tc{
697 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}};
699 unsigned map_key = 0;
701 int type = std::stoi(module_tc[0]);
702 int module = std::stoi(module_tc[1]);
703 int trigger_cell = std::stoi(module_tc[2]);
706 int module = std::stoi(module_tc[0]);
707 int trigger_cell = std::stoi(module_tc[1]);
714 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
715 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex),
717 if ((scintillator && neighbors_tokens.empty()) || (!scintillator && neighbors_tokens.size() < 2)) {
718 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 719 <<
" Cannot find any neighbor in line:\n" 720 <<
" '" << &
buffer[0] <<
"'\n";
722 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short, short>>());
724 unsigned first_element = (scintillator ? 0 : 1);
725 for (
unsigned i = first_element;
i < neighbors_tokens.size();
i++) {
726 const auto& neighbor = neighbors_tokens[
i];
727 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
729 short neighbor_module(std::stoi(pair_neighbor[0]));
730 short neighbor_cell(std::stoi(pair_neighbor[1]));
731 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
734 if (!l1tCellNeighborsMappingStream.eof()) {
735 throw cms::Exception(
"BadGeometryFile") <<
"Error reading L1TCellNeighborsMapping'\n";
737 l1tCellNeighborsMappingStream.close();
742 for (
unsigned layer = 1; layer <= n_layers_ee; layer++) {
749 unsigned trigger_wafer = waferuv_wafer.second;
752 for (
int zside : {-1, 1}) {
766 for (
int zside : {-1, 1}) {
783 for (
unsigned layer = first_layer_hsc; layer <= first_layer_hsc + n_layers_hsc; layer++) {
786 unsigned trigger_wafer = module_ncells.first;
788 for (
int trigger_cell = 1; trigger_cell < module_ncells.second; trigger_cell++) {
789 for (
int zside : {-1, 1}) {
804 unsigned packed_value = 0;
805 const int kSubdetMask = 0x7;
813 unsigned packed_value = 0;
826 unsigned packed_value = 0;
833 unsigned packed_value = 0;
841 unsigned packed_value = 0;
842 unsigned waferUabs =
std::abs(waferU);
843 unsigned waferVabs =
std::abs(waferV);
844 unsigned waferUsign = (waferU >= 0) ? 0 : 1;
845 unsigned waferVsign = (waferV >= 0) ? 0 : 1;
854 unsigned packed_value = 0;
897 bool disconnected =
false;
917 HGCalDetId trigger_cell_det_id(trigger_cell_id);
918 unsigned subdet = trigger_cell_det_id.
subdetId();
921 for (
const auto cell_id : cells) {
949 unsigned packed_value = 0;
957 unsigned trigger_cell)
const {
958 unsigned packed_value = 0;
985 layer = detid.
layer();
int detIdWaferType(unsigned det, unsigned layer, short waferU, short waferV) const
T getParameter(std::string const &) const
unsigned packCellId(unsigned type, unsigned cellU, unsigned cellV) const
static const int kHGCalWaferVOffset
void fillInvalidTriggerCells()
edm::FileInPath l1tWafersMapping_
GlobalPoint getTriggerCellPosition(const unsigned) const final
unsigned getModuleFromCell(const unsigned) const final
int getTypeTrap(int layer) const
std::unordered_set< unsigned > disconnected_layers_
GlobalPoint getModulePosition(const unsigned) const final
static const int kHGCalLayerOffset
std::unordered_map< unsigned, unsigned > cells_to_trigger_cells_sci_
neighbor_map trigger_cell_neighbors_sci_
std::unordered_multimap< unsigned, unsigned > trigger_cells_to_cells_
static const int kHGCalLayerMask
void setEEGeometry(const HGCalGeometry *geom)
static const int kHGCalTypeMask
bool is_valid(const Digi &d)
bool validTriggerCell(const unsigned) const final
void initialize(const CaloGeometry *) final
const HGCalGeometry * eeGeometry() const
const HGCalTopology & eeTopology() const
static const int kHGCalWaferVSignOffset
unsigned getModuleFromTriggerCell(const unsigned) const final
std::unordered_map< unsigned, unsigned > cells_to_trigger_cells_
std::unordered_map< unsigned, unsigned short > number_trigger_cells_in_wafers_
static const int kHGCalCellUMask
std::vector< unsigned > trigger_layers_
unsigned packWaferId(int waferU, int waferV) const
Global3DPoint GlobalPoint
constexpr uint32_t rawId() const
get the raw id
int getTypeHex(int layer, int waferU, int waferV) const
geom_set getCellsFromModule(const unsigned) const final
static const int kHGCalWaferTypeOffset
int type() const
get the type
edm::FileInPath l1tCellNeighborsSciMapping_
GlobalPoint getPosition(const DetId &id) const
int zside() const
get the z-side of the cell (1/-1)
bool validCellId(unsigned det, unsigned cell_id) const
unsigned hSc_wafers_per_module_
std::unordered_map< unsigned, unsigned > wafer_to_module_
static const int kSubdetOffset
const HGCalTopology & hsiTopology() const
unsigned lastTriggerLayer() const final
void setHSiGeometry(const HGCalGeometry *geom)
std::unordered_map< int, std::set< std::pair< short, short > > > neighbor_map
static const int kHGCalCellVOffset
unsigned packTriggerCellWithType(unsigned, unsigned, unsigned) const
unsigned packLayerWaferId(unsigned layer, unsigned wafer) const
void unpackIetaIphi(unsigned ieta_iphi, unsigned &ieta, unsigned &iphi) const
int cellU() const
get the cell #'s in u,v or in x,y
unsigned getLinksInModule(const unsigned module_id) const final
edm::FileInPath l1tCellsMapping_
static const int kHGCalTypeOffset
static const int kHGCalCellOffset
std::unordered_map< unsigned, unsigned > links_per_module_
static const int kHGCalCellMask
std::unordered_set< unsigned > disconnected_modules_
unsigned getModuleSize(const unsigned module_id) const final
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
std::unordered_multimap< unsigned, unsigned > module_to_wafers_
static const int kHGCalCellVMask
static const int kSubdetMask
static const int kHGCalWaferTypeMask
void unpackWaferCellId(unsigned wafer_cell, unsigned &wafer, unsigned &cell) const
int type() const
get the type
int layer() const
get the layer #
edm::FileInPath l1tCellNeighborsMapping_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
void unpackLayerWaferId(unsigned layer_wafer, unsigned &layer, unsigned &wafer) const
void unpackCellId(unsigned cell, unsigned &cellU, unsigned &cellV) const
static const int kHGCalRadiusOffset
Abs< T >::type abs(const T &t)
void setHScGeometry(const HGCalGeometry *geom)
int iphi() const
get the phi index
int wafer() const
get the wafer #
unsigned packIetaIphi(unsigned ieta, unsigned iphi) const
geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const final
unsigned packWaferCellId(unsigned subdet, unsigned wafer, unsigned cell) const
const HGCalGeometry * hsiGeometry() const
geom_ordered_set getOrderedCellsFromModule(const unsigned) const final
std::unordered_multimap< unsigned, unsigned > trigger_cells_to_cells_sci_
static const int kHGCalRadiusMask
static const int kHGCalWaferVMask
static const int kHGCalWaferUSignMask
unsigned layerWithOffset(unsigned) const
static const int kHGCalWaferUMask
edm::FileInPath l1tModulesMapping_
int cell() const
get the absolute value of the cell #'s in x and y
const HGCalDDDConstants & dddConstants() const
std::unordered_map< unsigned, unsigned short > number_trigger_cells_in_wafers_sci_
const HGCalGeometry * hscGeometry() const
const HGCalTopology & hscTopology() const
static const int kHGCalWaferVSignMask
void unpackWaferId(unsigned wafer, int &waferU, int &waferV) const
unsigned packTriggerCell(unsigned, unsigned) const
void fillNeighborMap(const edm::FileInPath &, neighbor_map &, bool)
static const int kHGCalCellUOffset
bool validTriggerCellFromCells(const unsigned) const
static const int kHGCalWaferOffset
std::set< unsigned > geom_ordered_set
static const int kHGCalPhiMask
int layer() const
get the layer #
std::unordered_map< unsigned, unsigned > wafers_to_wafers_old_
int zside() const
get the z-side of the cell (1/-1)
edm::FileInPath l1tCellsSciMapping_
neighbor_map trigger_cell_neighbors_
std::unordered_set< unsigned > geom_set
geom_set getTriggerCellsFromModule(const unsigned) const final
edm::FileInPath l1tLinksMapping_
std::string fullPath() const
unsigned hSc_links_per_module_
int waferType() const
get the wafer type
bool disconnectedModule(const unsigned) const final
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned last_trigger_layer_
HGCalTriggerGeometryV9Imp1(const edm::ParameterSet &conf)
static const int kHGCalWaferUOffset
bool valid(const DetId &id) const override
Is this a valid cell id.
static const int kHGCalPhiOffset
const BasicVectorType & basicVector() const
std::unordered_map< unsigned, unsigned > wafers_old_to_wafers_
static const int kHGCalWaferUSignOffset
int layer() const
get the layer #
geom_set getNeighborsFromTriggerCell(const unsigned) const final
static const int kHGCalWaferMask
unsigned triggerLayer(const unsigned) const final
std::unordered_set< unsigned > invalid_triggercells_
constexpr Detector det() const
get the detector field from this detid
unsigned getTriggerCellFromCell(const unsigned) const final
geom_set getCellsFromTriggerCell(const unsigned) const final