86 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
91 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
92 unsigned packIetaIphi(
unsigned ieta,
unsigned iphi)
const;
93 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
94 void unpackIetaIphi(
unsigned ieta_iphi,
unsigned& ieta,
unsigned& iphi)
const;
109 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
111 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
140 unsigned trigger_layer = 0;
169 <<
"HGCalTriggerGeometryHexLayerBasedImp1 geometry cannot be initialized with the V9 HGCAL geometry";
179 unsigned wafer_trigger_cell = 0;
180 unsigned trigger_cell = 0;
186 unsigned ieta = cell_det_id.
ietaAbs();
187 unsigned iphi = cell_det_id.
iphi();
188 layer = cell_det_id.
depth();
190 zside = cell_det_id.
zside();
195 <<
"HGCalTriggerGeometry: Hcal cell ieta=" << ieta <<
", iphi="<<iphi<<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
198 wafer_trigger_cell = 0;
206 layer = cell_det_id.
layer();
207 zside = cell_det_id.
zside();
208 unsigned wafer = cell_det_id.
wafer();
209 unsigned cell = cell_det_id.
cell();
214 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" in wafer "<<wafer<<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
217 wafer_trigger_cell = 0;
235 HGCalDetId trigger_cell_det_id(trigger_cell_id);
241 module = trigger_cell_det_id.
wafer();
250 <<trigger_cell_det_id
251 <<
"HGCalTriggerGeometry: Wafer " << trigger_cell_det_id.
wafer() <<
" is not mapped to any trigger module. The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
253 module = module_itr->second;
262 HGCalDetId trigger_cell_det_id(trigger_cell_id);
267 unsigned subdet = trigger_cell_det_id.
subdetId();
268 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
269 unsigned trigger_cell = trigger_cell_det_id.
cell();
271 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
277 if(
validCellId(subdet, cell_det_id)) cell_det_ids.emplace(cell_det_id);
283 unsigned subdet = trigger_cell_det_id.
subdetId();
284 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
285 unsigned trigger_cell = trigger_cell_det_id.
cell();
287 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
294 if(
validCellId(subdet, cell_det_id)) cell_det_ids.emplace(cell_det_id);
306 for(
auto trigger_cell_id : trigger_cells)
309 cell_det_ids.insert(cells.begin(), cells.end());
320 for(
auto trigger_cell_id : trigger_cells)
323 cell_det_ids.insert(cells.begin(), cells.end());
342 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
351 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
353 unsigned wafer = wafer_itr->second;
358 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
362 return trigger_cell_det_ids;
379 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
388 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
390 unsigned wafer = wafer_itr->second;
395 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
399 return trigger_cell_det_ids;
408 HGCalDetId trigger_cell_det_id(trigger_cell_id);
412 unsigned trigger_cell = trigger_cell_det_id.
cell();
416 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
417 if(neighbors_itr==neighbors_map.end())
420 <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " << trigger_cell <<
" in module " 421 << module <<
". The trigger cell neighbor mapping should be modified. \n";
423 const auto& neighbors = neighbors_itr->second;
425 neighbor_detids.reserve(neighbors.size());
426 for(
const auto& module_tc : neighbors)
431 neighbor_detids.emplace(neighbor_det_id.rawId());
434 return neighbor_detids;
449 for(
const auto& cell : cell_ids)
458 for(
const auto& cell : cell_ids)
464 return GlobalPoint( triggerCellVector/cell_ids.size() );
479 for(
const auto& cell : cell_ids)
488 for(
const auto& cell : cell_ids)
494 return GlobalPoint( moduleVector/cell_ids.size() );
505 if(!l1tModulesMappingStream.is_open())
508 <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
510 short trigger_wafer = 0;
512 for(; l1tModulesMappingStream>>trigger_wafer>>module; )
519 if(!l1tModulesMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '"<<trigger_wafer<<
" "<<module<<
"' \n";
520 l1tModulesMappingStream.close();
523 if(!l1tCellsMappingStream.is_open())
526 <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
532 short trigger_cell = 0;
533 for(; l1tCellsMappingStream>>subdet>>wafer>>cell>>trigger_wafer>>trigger_cell; )
536 unsigned trigger_cell_key =
packWaferCellId(subdet,trigger_wafer,trigger_cell);
542 if(trigger_cell+1 > itr_insert.first->second) itr_insert.first->second = trigger_cell+1;
544 if(!l1tCellsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping '"<<subdet<<
" "<<wafer<<
" "<<cell<<
" "<<trigger_wafer<<
" "<<trigger_cell<<
"' \n";
545 l1tCellsMappingStream.close();
548 if(!l1tCellsBHMappingStream.is_open())
551 <<
"Cannot open HGCalTriggerGeometry L1TCellsBHMapping file\n";
557 for(; l1tCellsBHMappingStream>>ieta>>iphi>>trigger_wafer>>trigger_cell; )
566 if(trigger_cell+1 > itr_insert.first->second) itr_insert.first->second = trigger_cell+1;
568 if(!l1tCellsBHMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsBHMapping '"<<ieta<<
" "<<iphi<<
" "<<trigger_wafer<<
" "<<trigger_cell<<
"' \n";
569 l1tCellsBHMappingStream.close();
578 std::ifstream l1tCellNeighborsMappingStream(file.
fullPath());
579 if(!l1tCellNeighborsMappingStream.is_open())
582 <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
584 for(std::array<char,512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512); )
592 std::regex key_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
593 std::vector<std::string> key_tokens {
594 std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}
596 if(key_tokens.empty())
599 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 600 <<
" Cannot find the trigger cell key in line:\n" 601 <<
" '"<<&
buffer[0]<<
"'\n";
603 std::regex digits_regex(
"\\d{1,3}");
604 std::vector<std::string> module_tc {
605 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}
608 int module = std::stoi(module_tc[0]);
609 int trigger_cell = std::stoi(module_tc[1]);
615 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
616 std::vector<std::string> neighbors_tokens {
617 std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex), {}
619 if(neighbors_tokens.size()<2)
622 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 623 <<
" Cannot find any neighbor in line:\n" 624 <<
" '"<<&
buffer[0]<<
"'\n";
626 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short,short>>());
628 for(
unsigned i=1;
i<neighbors_tokens.size();
i++)
630 const auto& neighbor = neighbors_tokens[
i];
631 std::vector<std::string> pair_neighbor {
632 std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex), {}
634 short neighbor_module(std::stoi(pair_neighbor[0]));
635 short neighbor_cell(std::stoi(pair_neighbor[1]));
636 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
639 if(!l1tCellNeighborsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
640 l1tCellNeighborsMappingStream.close();
651 for(
unsigned layer=1; layer<=n_layers_ee; layer++)
655 unsigned wafer = wafer_module.first;
659 std::set<unsigned> trigger_cell_ids;
664 for(
unsigned trigger_cell : trigger_cell_ids)
681 unsigned packed_value = 0;
682 const int kSubdetMask = 0x7;
694 unsigned packed_value = 0;
728 bool disconnected =
false;
751 HGCalDetId trigger_cell_det_id(trigger_cell_id);
752 unsigned subdet = trigger_cell_det_id.
subdetId();
755 for(
const auto cell_id : cells)
791 unsigned packed_value = 0;
829 layer = detid.
layer();
845 "HGCalTriggerGeometryHexLayerBasedImp1");
std::unordered_set< unsigned > disconnected_modules_
T getParameter(std::string const &) const
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_
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
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_bh_
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
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
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
geom_set getTriggerCellsFromModule(const unsigned) const final
static const int kHGCalWaferMask