19 virtual void reset()
override final;
80 bool validCellId(
unsigned subdet,
unsigned cell_id)
const;
126 int wafer_type = cell_det_id.
waferType();
127 unsigned cell = cell_det_id.
cell();
133 <<
"HGCalTriggerGeometry: HGCal cell " << cell <<
" is not mapped to any trigger cell for the wafer type " << wafer_type
134 <<
". The trigger cell mapping should be modified.\n";
136 unsigned trigger_cell = trigger_cell_itr->second;
146 unsigned wafer = cell_det_id.
wafer();
147 unsigned subdet = cell_det_id.
subdetId();
148 std::unordered_map<short, short>::const_iterator module_itr;
149 bool out_of_range_error =
false;
161 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
164 if(out_of_range_error)
167 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
168 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
170 unsigned module = module_itr->second;
178 HGCalDetId trigger_cell_det_id(trigger_cell_id);
179 unsigned wafer = trigger_cell_det_id.
wafer();
180 unsigned subdet = trigger_cell_det_id.
subdetId();
182 std::unordered_map<short, short>::const_iterator module_itr;
183 bool out_of_range_error =
false;
195 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer->module mapping for subdet "<<subdet<<
"\n";
198 if(out_of_range_error)
201 <<
"HGCalTriggerGeometry: Wafer " << wafer <<
" is not mapped to any trigger module for subdetector " << subdet
202 <<
". The module mapping should be modified. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/HGCALTriggerPrimitivesSimulation#Trigger_geometry for details.\n";
204 unsigned module = module_itr->second;
212 HGCalDetId trigger_cell_det_id(trigger_cell_id);
213 unsigned subdet = trigger_cell_det_id.
subdetId();
215 int wafer_type = trigger_cell_det_id.
waferType();
216 unsigned trigger_cell = trigger_cell_det_id.
cell();
220 for(
auto tc_c_itr=cell_range.first; tc_c_itr!=cell_range.second; tc_c_itr++)
233 unsigned subdet = module_det_id.
subdetId();
236 std::pair<std::unordered_multimap<short, short>::const_iterator,
237 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
247 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
251 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
254 if(wafer_type==0) wafer_type = module_det_id.
waferType();
259 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
270 unsigned subdet = module_det_id.
subdetId();
273 std::pair<std::unordered_multimap<short, short>::const_iterator,
274 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
284 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
288 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
291 if(wafer_type==0) wafer_type = module_det_id.
waferType();
296 if(
validCellId(subdet, cell_id)) cell_det_ids.emplace(cell_id.rawId());
307 unsigned subdet = module_det_id.
subdetId();
310 std::pair<std::unordered_multimap<short, short>::const_iterator,
311 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
321 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
326 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
329 if(wafer_type==0) wafer_type = module_det_id.
waferType();
334 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
337 return trigger_cell_det_ids;
345 unsigned subdet = module_det_id.
subdetId();
348 std::pair<std::unordered_multimap<short, short>::const_iterator,
349 std::unordered_multimap<short, short>::const_iterator> wafer_itrs;
359 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown module->wafers mapping for subdet "<<subdet<<
"\n";
364 for(
auto wafer_itr=wafer_itrs.first; wafer_itr!=wafer_itrs.second; wafer_itr++)
367 if(wafer_type==0) wafer_type = module_det_id.
waferType();
372 if(
validTriggerCell(trigger_cell_id)) trigger_cell_det_ids.emplace(trigger_cell_id.rawId());
375 return trigger_cell_det_ids;
384 HGCalDetId trigger_cell_det_id(trigger_cell_id);
385 unsigned wafer = trigger_cell_det_id.
wafer();
386 int wafer_type = trigger_cell_det_id.
waferType();
387 unsigned subdet = trigger_cell_det_id.
subdetId();
388 unsigned trigger_cell = trigger_cell_det_id.
cell();
392 std::unordered_map<short, std::vector<short>>::const_iterator surrounding_wafers_itr;
393 bool out_of_range_error =
false;
405 edm::LogError(
"HGCalTriggerGeometry") <<
"Unknown wafer neighbours for subdet "<<subdet<<
"\n";
408 if(out_of_range_error)
411 <<
"HGCalTriggerGeometry: Neighbors are not defined for wafer " << wafer <<
" in subdetector " << subdet
412 <<
". The wafer neighbor mapping should be modified. \n";
414 const std::vector<short>& surrounding_wafers = surrounding_wafers_itr->second;
416 std::vector<int>
types;
417 types.reserve(surrounding_wafers.size()+1);
418 types.emplace_back(wafer_type);
419 for(
const auto w : surrounding_wafers)
426 types.emplace_back(wt);
435 <<
"HGCalTriggerGeometry: Neighbors are not defined for trigger cell " << trigger_cell <<
" with wafer configuration " 436 << std::bitset<7>(trigger_cell_key >> 8) <<
". The trigger cell neighbor mapping should be modified. \n";
438 const auto& neighbors = neighbors_itr->second;
440 neighbor_detids.reserve(neighbors.size());
441 for(
const auto& wafer_tc : neighbors)
443 if(wafer_tc.first-1>=(
int)surrounding_wafers.size())
446 <<
"HGCalTriggerGeometry: Undefined wafer neighbor number "<<wafer_tc.first
447 <<
" for wafer " << wafer <<
" and trigger cell " << trigger_cell
448 <<
". The neighbor mapping files should be modified.";
450 int neighbor_wafer = (wafer_tc.first==0 ? wafer : surrounding_wafers.at(wafer_tc.first-1));
451 if(neighbor_wafer==-1)
continue;
452 int type = types.at(wafer_tc.first);
456 neighbor_detids.emplace(neighbor_det_id.rawId());
459 return neighbor_detids;
471 for(
const auto& cell : cell_ids)
476 return GlobalPoint( triggerCellVector/cell_ids.size() );
488 for(
const auto& cell : cell_ids)
493 return GlobalPoint( moduleVector/cell_ids.size() );
504 if(!l1tModulesMappingStream.is_open())
507 <<
"Cannot open HGCalTriggerGeometry L1TModulesMapping file\n";
512 for(; l1tModulesMappingStream>>subdet>>wafer>>
module; )
536 edm::LogWarning(
"HGCalTriggerGeometry") <<
"Unsupported subdetector number ("<<subdet<<
") in L1TModulesMapping file\n";
540 if(!l1tModulesMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TModulesMapping '"<<wafer<<
" "<<module<<
"' \n";
541 l1tModulesMappingStream.close();
544 if(!l1tCellsMappingStream.is_open())
547 <<
"Cannot open HGCalTriggerGeometry L1TCellsMapping file\n";
551 short triggerCell = 0;
552 for(; l1tCellsMappingStream>>waferType>>cell>>triggerCell; )
559 if(triggerCell+1 > itr_insert.first->second) itr_insert.first->second = triggerCell+1;
561 if(!l1tCellsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellsMapping'"<<waferType<<
" "<<cell<<
" "<<triggerCell<<
"' \n";
562 l1tCellsMappingStream.close();
571 if(!l1tCellNeighborsMappingStream.is_open())
574 <<
"Cannot open HGCalTriggerGeometry L1TCellNeighborsMapping file\n";
576 for(std::array<char,512>
buffer; l1tCellNeighborsMappingStream.getline(&
buffer[0], 512); )
584 std::regex key_regex(
"\\(\\s*[01]{7}\\s*,\\s*\\d{1,3}\\s*\\)");
585 std::vector<std::string> key_tokens {
586 std::sregex_token_iterator(line.begin(), line.end(), key_regex), {}
588 if(key_tokens.size()!=1)
591 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 592 <<
" Cannot find the trigger cell key in line:\n" 593 <<
" '"<<&
buffer[0]<<
"'\n";
595 std::regex digits_regex(
"([01]{7})|(\\d{1,3})");
596 std::vector<std::string> type_tc {
597 std::sregex_token_iterator(key_tokens[0].
begin(), key_tokens[0].
end(), digits_regex), {}
600 int trigger_cell = std::stoi(type_tc[1]);
601 std::vector<int> wafer_types;
602 wafer_types.reserve(type_tc[0].
size());
604 for(
const char c : type_tc[0]) wafer_types.emplace_back( (std::stoi(
std::string(&
c))?1:-1) );
610 std::regex neighbors_regex(
"\\(\\s*\\d{1,3}\\s*,\\s*\\d\\s*\\)");
611 std::vector<std::string> neighbors_tokens {
612 std::sregex_token_iterator(line.begin(), line.end(), neighbors_regex), {}
614 if(neighbors_tokens.size()==0)
617 <<
"Syntax error in the L1TCellNeighborsMapping:\n" 618 <<
" Cannot find any neighbor in line:\n" 619 <<
" '"<<&
buffer[0]<<
"'\n";
622 for(
const auto& neighbor : neighbors_tokens)
624 std::vector<std::string> pair_neighbor {
625 std::sregex_token_iterator(neighbor.begin(), neighbor.end(), digits_regex), {}
627 short neighbor_wafer(std::stoi(pair_neighbor[1]));
628 short neighbor_cell(std::stoi(pair_neighbor[0]));
629 itr_insert.first->second.emplace(neighbor_wafer, neighbor_cell);
632 if(!l1tCellNeighborsMappingStream.eof())
edm::LogWarning(
"HGCalTriggerGeometry") <<
"Error reading L1TCellNeighborsMapping'\n";
633 l1tCellNeighborsMappingStream.close();
637 if(!l1tWaferNeighborsMappingStream.is_open())
640 <<
"Cannot open HGCalTriggerGeometry L1TWaferNeighborsMapping file\n";
642 for(std::array<char,512>
buffer; l1tWaferNeighborsMappingStream.getline(&
buffer[0], 512); )
647 std::vector<std::string> tokens {
648 std::sregex_token_iterator(line.begin(), line.end(),
delimiter, -1), {}
653 <<
"Syntax error in the L1TWaferNeighborsMapping in line:\n" 654 <<
" '"<<&
buffer[0]<<
"'\n" 655 <<
" A line should be composed of 8 integers separated by spaces:\n" 656 <<
" subdet waferid neighbor1 neighbor2 neighbor3 neighbor4 neighbor5 neighbor6\n";
658 short subdet(std::stoi(tokens[0]));
659 short wafer(std::stoi(tokens[1]));
661 std::unordered_map<short, std::vector<short>>* wafer_neighbors;
672 <<
"Unknown subdet " << subdet <<
" in L1TWaferNeighborsMapping:\n" 673 <<
" '"<<&
buffer[0]<<
"'\n";
675 auto wafer_itr = wafer_neighbors->emplace(wafer, std::vector<short>());
676 for(
auto neighbor_itr=tokens.cbegin()+2; neighbor_itr!=tokens.cend(); ++neighbor_itr)
678 wafer_itr.first->second.emplace_back(std::stoi(*neighbor_itr));
689 for(
unsigned layer=1; layer<=n_layers_ee; layer++)
693 unsigned wafer = wafer_module.first;
706 for(
unsigned layer=1; layer<=n_layers_fh; layer++)
710 unsigned wafer = wafer_module.first;
728 unsigned packed_value = trigger_cell;
729 for(
unsigned i=0;
i<wafer_types.size();
i++)
733 if(wafer_types.at(
i)==1) packed_value += (0
x1<<(8+
i));
784 HGCalDetId trigger_cell_det_id(trigger_cell_id);
785 unsigned subdet = trigger_cell_det_id.
subdetId();
788 for(
const auto cell_id : cells)
821 "HGCalTriggerGeometryHexImp2");
const HGCalGeometry & eeGeometry() const
virtual geom_set getCellsFromTriggerCell(const unsigned) const override final
edm::FileInPath l1tWaferNeighborsMapping_
std::unordered_map< short, short > number_cells_in_wafers_
const HGCalGeometry & fhGeometry() const
std::unordered_map< short, short > number_trigger_cells_in_wafers_
bool is_valid(const Digi &d)
const HGCalTopology & eeTopology() const
virtual GlobalPoint getModulePosition(const unsigned) const override final
edm::FileInPath l1tModulesMapping_
Global3DPoint GlobalPoint
unsigned packTriggerCell(unsigned, const std::vector< int > &) const
virtual geom_ordered_set getOrderedCellsFromModule(const unsigned) const override final
GlobalPoint getPosition(const DetId &id) const
std::unordered_multimap< short, short > module_to_wafers_fh_
std::unordered_set< unsigned > invalid_triggercells_
edm::FileInPath l1tCellsMapping_
uint32_t rawId() const
get the raw id
bool validCellId(unsigned subdet, unsigned cell_id) const
static const int kHGCalCellMask
unsigned int layers(bool reco) const
int zside() const
get the z-side of the cell (1/-1)
std::unordered_map< short, std::vector< short > > wafer_neighbors_fh_
std::unordered_map< short, std::vector< short > > wafer_neighbors_ee_
virtual void reset() override final
std::unordered_multimap< short, short > module_to_wafers_ee_
virtual GlobalPoint getTriggerCellPosition(const unsigned) const override final
int wafer() const
get the wafer #
virtual unsigned getTriggerCellFromCell(const unsigned) const override final
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
void setCaloGeometry(const edm::ESHandle< CaloGeometry > &geom)
virtual geom_set getNeighborsFromTriggerCell(const unsigned) const override final
std::unordered_map< short, short > wafer_to_module_ee_
int cell() const
get the absolute value of the cell #'s in x and y
const HGCalDDDConstants & dddConstants() const
virtual unsigned getModuleFromCell(const unsigned) const override final
std::unordered_map< short, short > wafer_to_module_fh_
virtual bool disconnectedModule(const unsigned) const override final
std::set< unsigned > geom_ordered_set
virtual geom_ordered_set getOrderedTriggerCellsFromModule(const unsigned) const override final
std::unordered_set< unsigned > geom_set
virtual geom_set getTriggerCellsFromModule(const unsigned) const override final
std::string fullPath() const
int detIdWaferType(unsigned subdet, short wafer) const
int waferType() const
get the wafer type
#define DEFINE_EDM_PLUGIN(factory, type, name)
std::map< std::pair< short, short >, short > cells_to_trigger_cells_
virtual bool validTriggerCell(const unsigned) const override final
std::unordered_map< int, std::set< std::pair< short, short > > > trigger_cell_neighbors_
virtual unsigned getModuleFromTriggerCell(const unsigned) const override final
bool valid(const DetId &id) const override
Is this a valid cell id.
bool validTriggerCellFromCells(const unsigned) const
std::multimap< std::pair< short, short >, short > trigger_cells_to_cells_
virtual geom_set getCellsFromModule(const unsigned) const override final
virtual void initialize(const edm::ESHandle< CaloGeometry > &) override final
int waferTypeT(int wafer) const
edm::FileInPath l1tCellNeighborsMapping_
const HGCalTopology & fhTopology() const
int layer() const
get the layer #
void fillInvalidTriggerCells()
HGCalTriggerGeometryHexImp2(const edm::ParameterSet &conf)