70 typedef std::unordered_map<int, std::set<std::pair<short, short>>>
neighbor_map;
88 bool validCellId(
unsigned det,
unsigned cell_id)
const;
91 int detIdWaferType(
unsigned det,
unsigned layer,
short waferU,
short waferV)
const;
92 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
94 unsigned packCellId(
unsigned type,
unsigned cellU,
unsigned cellV)
const;
96 unsigned packIetaIphi(
unsigned ieta,
unsigned iphi)
const;
97 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
98 void unpackWaferId(
unsigned wafer,
int& waferU,
int& waferV)
const;
99 void unpackCellId(
unsigned cell,
unsigned& cellU,
unsigned& cellV)
const;
100 void unpackIetaIphi(
unsigned ieta_iphi,
unsigned& ieta,
unsigned& iphi)
const;
113 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
115 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
136 <<
"HGCalTriggerGeometryV9Imp1 geometry cannot be initialized with the V7/V8 HGCAL geometry";
149 unsigned trigger_layer = 1;
166 unsigned det =
DetId(cell_id).
det();
169 unsigned tc_type = 1;
171 unsigned wafer_trigger_cell = 0;
172 unsigned trigger_cell = 0;
176 unsigned ieta = cell_det_id.
ietaAbs();
177 unsigned iphi = cell_det_id.
iphi();
178 tc_type = cell_det_id.
type();
179 layer = cell_det_id.
layer();
181 zside = cell_det_id.
zside();
185 <<
"HGCalTriggerGeometry: scintillator cell ieta=" << ieta <<
", iphi=" << iphi
186 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
189 wafer_trigger_cell = 0;
196 layer = cell_det_id.
layer();
197 zside = cell_det_id.
zside();
199 int waferu = cell_det_id.
waferU();
200 int waferv = cell_det_id.
waferV();
201 unsigned cellu = cell_det_id.
cellU();
202 unsigned cellv = cell_det_id.
cellV();
206 <<
"HGCalTriggerGeometry: HGCal cell " << cellu <<
"," << cellv <<
" in wafer type " << type
207 <<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
212 <<
"HGCalTriggerGeometry: Wafer " << waferu <<
"," << waferv
213 <<
" is not mapped to any trigger wafer ID. The wafer mapping should be modified.\n";
215 trigger_cell = trigger_cell_itr->second;
216 wafer_trigger_cell = wafer_trigger_cell_itr->second;
228 HGCalDetId trigger_cell_det_id(trigger_cell_id);
233 module = trigger_cell_det_id.
wafer();
240 << trigger_cell_det_id <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer()
241 <<
" is not mapped to any trigger module. The module mapping should be modified. See " 242 "https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for " 245 module = module_itr->second;
248 trigger_cell_det_id.
zside(),
249 trigger_cell_det_id.
layer(),
257 const unsigned trigger_cell_id)
const {
258 HGCalDetId trigger_cell_det_id(trigger_cell_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();
263 unsigned layer = trigger_cell_det_id.
layer();
267 const auto& cell_range =
269 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
275 cell_det_ids.emplace(cell_det_id);
284 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Trigger wafer ID " << trigger_wafer
285 <<
" is not mapped to any wafer. The wafer mapping should be modified.\n";
292 for (
auto tc_c_itr = cell_range.first; tc_c_itr != cell_range.second; tc_c_itr++) {
296 unsigned cell_det_id =
297 HGCSiliconDetId(det, trigger_cell_det_id.
zside(), wafer_type, layer, waferu, waferv, cellu, cellv).rawId();
299 cell_det_ids.emplace(cell_det_id);
308 for (
auto trigger_cell_id : trigger_cells) {
310 cell_det_ids.insert(cells.begin(), cells.end());
316 const unsigned module_id)
const {
319 for (
auto trigger_cell_id : trigger_cells) {
321 cell_det_ids.insert(cells.begin(), cells.end());
327 const unsigned module_id)
const {
336 module_det_id.
zside(),
337 module_det_id.
layer(),
342 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
349 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
350 unsigned wafer = wafer_itr->second;
358 unsigned layer = module_det_id.
layer();
363 module_det_id.
zside(),
364 module_det_id.
layer(),
369 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
373 return trigger_cell_det_ids;
377 const unsigned module_id)
const {
386 module_det_id.
zside(),
387 module_det_id.
layer(),
392 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
399 for (
auto wafer_itr = wafer_itrs.first; wafer_itr != wafer_itrs.second; wafer_itr++) {
400 unsigned wafer = wafer_itr->second;
408 unsigned layer = module_det_id.
layer();
413 module_det_id.
zside(),
414 module_det_id.
layer(),
419 trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
423 return trigger_cell_det_ids;
427 const unsigned trigger_cell_id)
const {
428 HGCalDetId trigger_cell_det_id(trigger_cell_id);
430 const auto& neighbors_map =
433 unsigned layer = trigger_cell_det_id.
layer();
438 unsigned trigger_cell = trigger_cell_det_id.
cell();
444 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
445 if (neighbors_itr == neighbors_map.end()) {
446 throw cms::Exception(
"BadGeometry") <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " 447 << trigger_cell <<
" in module " << module
448 <<
". The trigger cell neighbor mapping should be modified. \n";
450 const auto& neighbors = neighbors_itr->second;
452 neighbor_detids.reserve(neighbors.size());
453 for (
const auto& module_tc : neighbors) {
455 trigger_cell_det_id.
zside(),
461 neighbor_detids.emplace(neighbor_det_id.rawId());
464 return neighbor_detids;
474 for (
const auto& cell : cell_ids) {
481 for (
const auto& cell : cell_ids) {
488 return GlobalPoint(triggerCellVector / cell_ids.size());
498 for (
const auto& cell : cell_ids) {
505 for (
const auto& cell : cell_ids) {
512 return GlobalPoint(moduleVector / cell_ids.size());
519 if (!l1tModulesMappingStream.is_open()) {
520 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
522 short trigger_wafer = 0;
524 for (; l1tModulesMappingStream >> trigger_wafer >> module;) {
528 if (!l1tModulesMappingStream.eof()) {
530 <<
"Error reading L1TModulesMapping '" << trigger_wafer <<
" " << module <<
"' \n";
532 l1tModulesMappingStream.close();
535 if (!l1tCellsMappingStream.is_open()) {
536 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
541 short trigger_cell = 0;
542 for (; l1tCellsMappingStream >> type >> cellu >> cellv >> trigger_cell;) {
543 unsigned cell_key =
packCellId(type, cellu, cellv);
544 unsigned trigger_cell_key =
packCellId(type, trigger_cell);
550 if (trigger_cell + 1 > itr_insert.first->second)
551 itr_insert.first->second = trigger_cell + 1;
553 if (!l1tCellsMappingStream.eof()) {
555 <<
"Error reading L1TCellsMapping '" << type <<
" " << cellu <<
" " << cellv <<
" " << trigger_cell <<
"' \n";
557 l1tCellsMappingStream.close();
560 if (!l1tCellsSciMappingStream.is_open()) {
561 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellsSciMapping file\n";
567 for (; l1tCellsSciMappingStream >> ieta >> iphi >> trigger_wafer >> trigger_cell;) {
575 if (trigger_cell + 1 > itr_insert.first->second)
576 itr_insert.first->second = trigger_cell + 1;
578 if (!l1tCellsSciMappingStream.eof()) {
579 throw cms::Exception(
"BadGeometryFile") <<
"Error reading L1TCellsSciMapping '" << ieta <<
" " << iphi <<
" " 580 << trigger_wafer <<
" " << trigger_cell <<
"' \n";
582 l1tCellsSciMappingStream.close();
585 if (!l1tWafersMappingStream.is_open()) {
586 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TWafersMapping file\n";
591 for (; l1tWafersMappingStream >> waferu >> waferv >> trigger_wafer;) {
597 if (!l1tWafersMappingStream.eof()) {
599 <<
"Error reading L1TWafersMapping '" << waferu <<
" " << waferv <<
" " << trigger_wafer <<
"' \n";
601 l1tWafersMappingStream.close();
608 std::ifstream l1tCellNeighborsMappingStream(file.
fullPath());
609 if (!l1tCellNeighborsMappingStream.is_open()) {
610 throw cms::Exception(
"MissingDataFile") <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
612 const unsigned line_size = 512;
613 for (std::array<char, line_size>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], line_size);) {
621 std::regex key_regex(scintillator ?
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)" 622 :
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
623 std::vector<std::string> key_tokens{std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}};
624 if (key_tokens.empty()) {
625 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 626 <<
" Cannot find the trigger cell key in line:\n" 627 <<
" '" << &
buffer[0] <<
"'\n";
629 std::regex digits_regex(
"\\d{1,3}");
630 std::vector<std::string> module_tc{
631 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}};
633 unsigned map_key = 0;
635 int type = std::stoi(module_tc[0]);
636 int module = std::stoi(module_tc[1]);
637 int trigger_cell = std::stoi(module_tc[2]);
640 int module = std::stoi(module_tc[0]);
641 int trigger_cell = std::stoi(module_tc[1]);
648 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
649 std::vector<std::string> neighbors_tokens{std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex),
651 if ((scintillator && neighbors_tokens.empty()) || (!scintillator && neighbors_tokens.size() < 2)) {
652 throw cms::Exception(
"BadGeometry") <<
"Syntax error in the L1TCellNeighborsMapping:\n" 653 <<
" Cannot find any neighbor in line:\n" 654 <<
" '" << &
buffer[0] <<
"'\n";
656 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short, short>>());
658 unsigned first_element = (scintillator ? 0 : 1);
659 for (
unsigned i = first_element;
i < neighbors_tokens.size();
i++) {
660 const auto& neighbor = neighbors_tokens[
i];
661 std::vector<std::string> pair_neighbor{std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex),
663 short neighbor_module(std::stoi(pair_neighbor[0]));
664 short neighbor_cell(std::stoi(pair_neighbor[1]));
665 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
668 if (!l1tCellNeighborsMappingStream.eof()) {
669 throw cms::Exception(
"BadGeometryFile") <<
"Error reading L1TCellNeighborsMapping'\n";
671 l1tCellNeighborsMappingStream.close();
676 for (
unsigned layer = 1; layer <= n_layers_ee; layer++) {
683 unsigned trigger_wafer = waferuv_wafer.second;
686 for (
int zside : {-1, 1}) {
700 for (
int zside : {-1, 1}) {
717 for (
unsigned layer = first_layer_hsc; layer <= first_layer_hsc + n_layers_hsc; layer++) {
720 unsigned trigger_wafer = module_ncells.first;
722 for (
int trigger_cell = 1; trigger_cell < module_ncells.second; trigger_cell++) {
723 for (
int zside : {-1, 1}) {
738 unsigned packed_value = 0;
739 const int kSubdetMask = 0x7;
747 unsigned packed_value = 0;
754 unsigned packed_value = 0;
762 unsigned packed_value = 0;
763 unsigned waferUabs =
std::abs(waferU);
764 unsigned waferVabs =
std::abs(waferV);
765 unsigned waferUsign = (waferU >= 0) ? 0 : 1;
766 unsigned waferVsign = (waferV >= 0) ? 0 : 1;
775 unsigned packed_value = 0;
810 bool disconnected =
false;
830 HGCalDetId trigger_cell_det_id(trigger_cell_id);
831 unsigned subdet = trigger_cell_det_id.
subdetId();
834 for (
const auto cell_id : cells) {
862 unsigned packed_value = 0;
870 unsigned trigger_cell)
const {
871 unsigned packed_value = 0;
898 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
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 kHGCalTypeMask
bool is_valid(const Digi &d)
bool validTriggerCell(const unsigned) const 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
void initialize(const edm::ESHandle< CaloGeometry > &) final
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
std::unordered_map< unsigned, unsigned > wafer_to_module_
const HGCalTopology & hsiTopology() const
void setEEGeometry(const edm::ESHandle< HGCalGeometry > &geom)
std::unordered_map< int, std::set< std::pair< short, short > > > neighbor_map
static const int kHGCalCellVOffset
unsigned packTriggerCellWithType(unsigned, unsigned, unsigned) 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
edm::FileInPath l1tCellsMapping_
static const int kHGCalTypeOffset
static const int kHGCalCellOffset
static const int kHGCalCellMask
std::unordered_set< unsigned > disconnected_modules_
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 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 unpackCellId(unsigned cell, unsigned &cellU, unsigned &cellV) const
static const int kHGCalRadiusOffset
Abs< T >::type abs(const T &t)
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
void setHScGeometry(const edm::ESHandle< HGCalGeometry > &geom)
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
std::string fullPath() const
int waferType() const
get the wafer type
bool disconnectedModule(const unsigned) const final
#define DEFINE_EDM_PLUGIN(factory, type, name)
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
void setHSiGeometry(const edm::ESHandle< HGCalGeometry > &geom)
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