83 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
88 unsigned packWaferCellId(
unsigned subdet,
unsigned wafer,
unsigned cell)
const;
89 unsigned packIetaIphi(
unsigned ieta,
unsigned iphi)
const;
90 void unpackWaferCellId(
unsigned wafer_cell,
unsigned& wafer,
unsigned& cell)
const;
91 void unpackIetaIphi(
unsigned ieta_iphi,
unsigned& ieta,
unsigned& iphi)
const;
106 std::vector<unsigned> tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedModules");
108 tmp_vector = conf.
getParameter<std::vector<unsigned>>(
"DisconnectedLayers");
137 unsigned trigger_layer = 0;
165 unsigned wafer_trigger_cell = 0;
166 unsigned trigger_cell = 0;
172 unsigned ieta = cell_det_id.
ietaAbs();
173 unsigned iphi = cell_det_id.
iphi();
174 layer = cell_det_id.
depth();
176 zside = cell_det_id.
zside();
181 <<
"HGCalTriggerGeometry: Hcal cell ieta=" << ieta <<
", iphi="<<iphi<<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
184 wafer_trigger_cell = 0;
192 layer = cell_det_id.
layer();
193 zside = cell_det_id.
zside();
194 unsigned wafer = cell_det_id.
wafer();
195 unsigned cell = cell_det_id.
cell();
200 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" in wafer "<<wafer<<
" is not mapped to any trigger cell. The trigger cell mapping should be modified.\n";
203 wafer_trigger_cell = 0;
221 HGCalDetId trigger_cell_det_id(trigger_cell_id);
227 module = trigger_cell_det_id.
wafer();
236 <<trigger_cell_det_id
237 <<
"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";
239 module = module_itr->second;
248 HGCalDetId trigger_cell_det_id(trigger_cell_id);
253 unsigned subdet = trigger_cell_det_id.
subdetId();
254 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
255 unsigned trigger_cell = trigger_cell_det_id.
cell();
257 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
263 if(
validCellId(subdet, cell_det_id)) cell_det_ids.emplace(cell_det_id);
269 unsigned subdet = trigger_cell_det_id.
subdetId();
270 unsigned trigger_wafer = trigger_cell_det_id.
wafer();
271 unsigned trigger_cell = trigger_cell_det_id.
cell();
273 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
280 if(
validCellId(subdet, cell_det_id)) cell_det_ids.emplace(cell_det_id);
292 for(
auto trigger_cell_id : trigger_cells)
295 cell_det_ids.insert(cells.begin(), cells.end());
306 for(
auto trigger_cell_id : trigger_cells)
309 cell_det_ids.insert(cells.begin(), cells.end());
328 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
337 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
339 unsigned wafer = wafer_itr->second;
344 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
348 return trigger_cell_det_ids;
365 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
374 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
376 unsigned wafer = wafer_itr->second;
381 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
385 return trigger_cell_det_ids;
394 HGCalDetId trigger_cell_det_id(trigger_cell_id);
398 unsigned trigger_cell = trigger_cell_det_id.
cell();
402 auto neighbors_itr = neighbors_map.find(trigger_cell_key);
403 if(neighbors_itr==neighbors_map.end())
406 <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " << trigger_cell <<
" in module " 407 << module <<
". The trigger cell neighbor mapping should be modified. \n";
409 const auto& neighbors = neighbors_itr->second;
411 neighbor_detids.reserve(neighbors.size());
412 for(
const auto& module_tc : neighbors)
417 neighbor_detids.emplace(neighbor_det_id.rawId());
420 return neighbor_detids;
435 for(
const auto& cell : cell_ids)
444 for(
const auto& cell : cell_ids)
450 return GlobalPoint( triggerCellVector/cell_ids.size() );
465 for(
const auto& cell : cell_ids)
474 for(
const auto& cell : cell_ids)
480 return GlobalPoint( moduleVector/cell_ids.size() );
491 if(!l1tModulesMappingStream.is_open())
494 <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
496 short trigger_wafer = 0;
498 for(; l1tModulesMappingStream>>trigger_wafer>>
module; )
505 if(!l1tModulesMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '"<<trigger_wafer<<
" "<<module<<
"' \n";
506 l1tModulesMappingStream.close();
509 if(!l1tCellsMappingStream.is_open())
512 <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
518 short trigger_cell = 0;
519 for(; l1tCellsMappingStream>>subdet>>wafer>>cell>>trigger_wafer>>trigger_cell; )
522 unsigned trigger_cell_key =
packWaferCellId(subdet,trigger_wafer,trigger_cell);
528 if(trigger_cell+1 > itr_insert.first->second) itr_insert.first->second = trigger_cell+1;
530 if(!l1tCellsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping '"<<subdet<<
" "<<wafer<<
" "<<cell<<
" "<<trigger_wafer<<
" "<<trigger_cell<<
"' \n";
531 l1tCellsMappingStream.close();
534 if(!l1tCellsBHMappingStream.is_open())
537 <<
"Cannot open HGCalTriggerGeometry L1TCellsBHMapping file\n";
543 for(; l1tCellsBHMappingStream>>ieta>>iphi>>trigger_wafer>>trigger_cell; )
552 if(trigger_cell+1 > itr_insert.first->second) itr_insert.first->second = trigger_cell+1;
554 if(!l1tCellsBHMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsBHMapping '"<<ieta<<
" "<<iphi<<
" "<<trigger_wafer<<
" "<<trigger_cell<<
"' \n";
555 l1tCellsBHMappingStream.close();
564 std::ifstream l1tCellNeighborsMappingStream(file.
fullPath());
565 if(!l1tCellNeighborsMappingStream.is_open())
568 <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
570 for(std::array<char,512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512); )
578 std::regex key_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
579 std::vector<std::string> key_tokens {
580 std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}
582 if(key_tokens.empty())
585 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 586 <<
" Cannot find the trigger cell key in line:\n" 587 <<
" '"<<&
buffer[0]<<
"'\n";
589 std::regex digits_regex(
"\\d{1,3}");
590 std::vector<std::string> module_tc {
591 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}
594 int module = std::stoi(module_tc[0]);
595 int trigger_cell = std::stoi(module_tc[1]);
601 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d{1,3}\\s*\\)");
602 std::vector<std::string> neighbors_tokens {
603 std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex), {}
605 if(neighbors_tokens.size()<2)
608 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 609 <<
" Cannot find any neighbor in line:\n" 610 <<
" '"<<&
buffer[0]<<
"'\n";
612 auto itr_insert = neighbors_map.emplace(map_key, std::set<std::pair<short,short>>());
614 for(
unsigned i=1;
i<neighbors_tokens.size();
i++)
616 const auto& neighbor = neighbors_tokens[
i];
617 std::vector<std::string> pair_neighbor {
618 std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex), {}
620 short neighbor_module(std::stoi(pair_neighbor[0]));
621 short neighbor_cell(std::stoi(pair_neighbor[1]));
622 itr_insert.first->second.emplace(neighbor_module, neighbor_cell);
625 if(!l1tCellNeighborsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
626 l1tCellNeighborsMappingStream.close();
637 for(
unsigned layer=1; layer<=n_layers_ee; layer++)
641 unsigned wafer = wafer_module.first;
645 std::set<unsigned> trigger_cell_ids;
650 for(
unsigned trigger_cell : trigger_cell_ids)
667 unsigned packed_value = 0;
668 const int kSubdetMask = 0x7;
680 unsigned packed_value = 0;
714 bool disconnected =
false;
737 HGCalDetId trigger_cell_det_id(trigger_cell_id);
738 unsigned subdet = trigger_cell_det_id.
subdetId();
741 for(
const auto cell_id : cells)
777 unsigned packed_value = 0;
815 layer = detid.
layer();
831 "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
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
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_
uint32_t rawId() const
get the raw id
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_
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
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
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
static const int kHcalPhiMask2
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
int getMaxDepth(const int &type) const
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
static const int kHcalEtaOffset2
geom_set getCellsFromTriggerCell(const unsigned) const final
unsigned layerWithOffset(unsigned) const
std::unordered_set< unsigned > geom_set
static const int kHcalEtaMask2
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